From e0d043b94d131b1e46d14775f897e7bad05e1bc8 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 20 Mar 2003 18:59:18 +0000 Subject: [PATCH] please apply attached patch to current CVS. btree_gist now supports int2 ! Thanks Janko Richter for contribution. --- contrib/btree_gist/Makefile | 7 ++- contrib/btree_gist/README.btree_gist | 4 +- contrib/btree_gist/btree_gist.sql.in | 83 ++++++++++++++++++++++++++-- contrib/btree_gist/btree_num.c.in | 6 ++ 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/contrib/btree_gist/Makefile b/contrib/btree_gist/Makefile index d132396574..97d54d708d 100644 --- a/contrib/btree_gist/Makefile +++ b/contrib/btree_gist/Makefile @@ -4,15 +4,18 @@ top_builddir = ../.. include $(top_builddir)/src/Makefile.global MODULE_big = btree_gist -OBJS= btree_common.o btree_int4.o btree_int8.o btree_float4.o btree_float8.o btree_ts.o +OBJS= btree_common.o btree_int2.o btree_int4.o btree_int8.o btree_float4.o btree_float8.o btree_ts.o DATA_built = btree_gist.sql DOCS = README.btree_gist REGRESS = btree_gist -EXTRA_CLEAN = btree_int4.c btree_int8.c btree_float4.c btree_float8.c +EXTRA_CLEAN = btree_int2.c btree_int4.c btree_int8.c btree_float4.c btree_float8.c include $(top_srcdir)/contrib/contrib-global.mk +btree_int2.c: btree_num.c.in + sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_INT2,g;s,__BTREE_GIST_TYPE__,int16,g;s,__BTREE_GIST_TYPE2__,int2,g' < $< > $@ + btree_int4.c: btree_num.c.in sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_INT4,g;s,__BTREE_GIST_TYPE__,int32,g;s,__BTREE_GIST_TYPE2__,int4,g' < $< > $@ diff --git a/contrib/btree_gist/README.btree_gist b/contrib/btree_gist/README.btree_gist index ec0e3cc9b6..83b8437601 100644 --- a/contrib/btree_gist/README.btree_gist +++ b/contrib/btree_gist/README.btree_gist @@ -1,4 +1,4 @@ -This is B-Tree implementation using GiST for int4, int8, float4, float8 +This is B-Tree implementation using GiST for int2, int4, int8, float4, float8 timestamp types. All work was done by Teodor Sigaev (teodor@stack.net) and Oleg Bartunov @@ -6,7 +6,7 @@ All work was done by Teodor Sigaev (teodor@stack.net) and Oleg Bartunov for additional information. NEWS: - Feb 5, 2003 - btree_gist now support int8, float4, float8 ! + Feb 5, 2003 - btree_gist now support int2, int8, float4, float8 ! Thank Janko Richter for contribution. diff --git a/contrib/btree_gist/btree_gist.sql.in b/contrib/btree_gist/btree_gist.sql.in index 20bd46b5fa..4f0b1291df 100644 --- a/contrib/btree_gist/btree_gist.sql.in +++ b/contrib/btree_gist/btree_gist.sql.in @@ -3,6 +3,23 @@ SET search_path = public; SET autocommit TO 'on'; +-- create type of int2 key +CREATE FUNCTION int2key_in(cstring) +RETURNS int2key +AS 'MODULE_PATHNAME' +LANGUAGE 'c' WITH (isstrict); + +CREATE FUNCTION int2key_out(int2key) +RETURNS cstring +AS 'MODULE_PATHNAME' +LANGUAGE 'c' WITH (isstrict); + +CREATE TYPE int2key ( +INTERNALLENGTH = 4, +INPUT = int2key_in, +OUTPUT = int2key_out +); + -- create type of int4 key CREATE FUNCTION int4key_in(cstring) RETURNS int4key @@ -72,6 +89,67 @@ INPUT = float8key_in, OUTPUT = float8key_out ); +-- +-- +-- +-- int2 ops +-- +-- +-- +-- define the GiST support methods +CREATE FUNCTION gint2_consistent(internal,int2,int2) +RETURNS bool +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +CREATE FUNCTION gint2_compress(internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +CREATE FUNCTION btree_decompress(internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +CREATE FUNCTION gint2_penalty(internal,internal,internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE 'C' WITH (isstrict); + +CREATE FUNCTION gint2_picksplit(internal, internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +CREATE FUNCTION gint2_union(bytea, internal) +RETURNS int4 +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +CREATE FUNCTION gint2_same(internal, internal, internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; + +-- Create the operator class +CREATE OPERATOR CLASS gist_int2_ops +DEFAULT FOR TYPE int2 USING gist +AS + OPERATOR 1 < , + OPERATOR 2 <= , + OPERATOR 3 = , + OPERATOR 4 >= , + OPERATOR 5 > , + FUNCTION 1 gint2_consistent (internal, int2, int2), + FUNCTION 2 gint2_union (bytea, internal), + FUNCTION 3 gint2_compress (internal), + FUNCTION 4 btree_decompress (internal), + FUNCTION 5 gint2_penalty (internal, internal, internal), + FUNCTION 6 gint2_picksplit (internal, internal), + FUNCTION 7 gint2_same (internal, internal, internal), + STORAGE int2key; + -- -- -- @@ -90,11 +168,6 @@ RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE 'C'; -CREATE FUNCTION btree_decompress(internal) -RETURNS internal -AS 'MODULE_PATHNAME' -LANGUAGE 'C'; - CREATE FUNCTION gint4_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' diff --git a/contrib/btree_gist/btree_num.c.in b/contrib/btree_gist/btree_num.c.in index 04e496eb0a..6dbbedc9b7 100644 --- a/contrib/btree_gist/btree_num.c.in +++ b/contrib/btree_gist/btree_num.c.in @@ -51,6 +51,9 @@ g__BTREE_GIST_TYPE2___compress(PG_FUNCTION_ARGS) if (entry->leafkey) { __BTREE_GIST_TYPE__KEY *r = ( __BTREE_GIST_TYPE__KEY * ) palloc(sizeof(__BTREE_GIST_TYPE__KEY)); + #ifdef BTREE_GIST_INT2 + int16 leaf = DatumGetInt16(entry->key); + #endif #ifdef BTREE_GIST_INT4 int32 leaf = DatumGetInt32(entry->key); #endif @@ -80,6 +83,9 @@ Datum g__BTREE_GIST_TYPE2___consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + #ifdef BTREE_GIST_INT2 + int16 query = PG_GETARG_INT16(1); + #endif #ifdef BTREE_GIST_INT4 int32 query = PG_GETARG_INT32(1); #endif