Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 42d0698

Browse files
committed
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
1 parent 1a321f2 commit 42d0698

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+18198
-2951
lines changed

contrib/btree_gist/Makefile

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@ subdir = contrib/btree_gist
33
top_builddir = ../..
44
include $(top_builddir)/src/Makefile.global
55

6-
MODULE_big = btree_gist
7-
OBJS= btree_common.o btree_int2.o btree_int4.o btree_int8.o btree_float4.o btree_float8.o btree_ts.o
8-
DATA_built = btree_gist.sql
9-
DOCS = README.btree_gist
10-
REGRESS = btree_gist
6+
MODULE_big = btree_gist
117

12-
EXTRA_CLEAN = btree_int2.c btree_int4.c btree_int8.c btree_float4.c btree_float8.c
8+
OBJS = btree_gist.o btree_utils_num.o btree_utils_var.o btree_int2.o btree_int4.o btree_int8.o \
9+
btree_float4.o btree_float8.o btree_cash.o btree_oid.o btree_ts.o btree_time.o \
10+
btree_date.o btree_interval.o btree_macaddr.o btree_inet.o btree_text.o \
11+
btree_bytea.o btree_bit.o btree_numeric.o
1312

14-
include $(top_srcdir)/contrib/contrib-global.mk
15-
16-
btree_int2.c: btree_num.c.in
17-
sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_INT2,g;s,__BTREE_GIST_TYPE__,int16,g;s,__BTREE_GIST_TYPE2__,int2,g' < $< > $@
18-
19-
btree_int4.c: btree_num.c.in
20-
sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_INT4,g;s,__BTREE_GIST_TYPE__,int32,g;s,__BTREE_GIST_TYPE2__,int4,g' < $< > $@
13+
DATA_built = btree_gist.sql
14+
DOCS = README.btree_gist
2115

22-
btree_int8.c: btree_num.c.in
23-
sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_INT8,g;s,__BTREE_GIST_TYPE__,int64,g;s,__BTREE_GIST_TYPE2__,int8,g' < $< > $@
16+
REGRESS = init int2 int4 int8 float4 float8 cash oid timestamp timestamptz time timetz \
17+
date interval macaddr inet cidr text varchar char bytea bit varbit numeric
2418

25-
btree_float4.c: btree_num.c.in
26-
sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_FLOAT4,g;s,__BTREE_GIST_TYPE__,float4,g;s,__BTREE_GIST_TYPE2__,float4,g' < $< > $@
27-
28-
btree_float8.c: btree_num.c.in
29-
sed 's,__DEFINE_BTREE_TYPE_HERE__,BTREE_GIST_FLOAT8,g;s,__BTREE_GIST_TYPE__,float8,g;s,__BTREE_GIST_TYPE2__,float8,g' < $< > $@
19+
include $(top_srcdir)/contrib/contrib-global.mk

contrib/btree_gist/README.btree_gist

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
This is B-Tree implementation using GiST for int2, int4, int8, float4, float8
2-
timestamp types.
2+
timestamp with/without time zone, time with/without time zone, date,
3+
interval, oid, money and macaddr, char, varchar/text, bytea, numeric,
4+
bit, varbit, inet/cidr types.
35

4-
All work was done by Teodor Sigaev (teodor@stack.net) and Oleg Bartunov
5-
(oleg@sai.msu.su). See http://www.sai.msu.su/~megera/postgres/gist
6-
for additional information.
6+
All work was done by Teodor Sigaev (teodor@stack.net) , Oleg Bartunov
7+
(oleg@sai.msu.su), Janko Richter (jankorichter@yahoo.de).
8+
See http://www.sai.msu.su/~megera/postgres/gist for additional
9+
information.
710

811
NEWS:
9-
Feb 5, 2003 - btree_gist now support int2, int8, float4, float8 !
10-
Thank Janko Richter <jankorichter@yahoo.de> for
11-
contribution.
12+
13+
Apr 17, 2004 - Performance optimizing
14+
15+
Jan 21, 2004 - add support for bytea, numeric, bit, varbit, inet/cidr
16+
17+
Jan 17, 2004 - Reorganizing code and add support for char, varchar/text
18+
19+
Jan 10, 2004 - btree_gist now support oid , timestamp with time zone ,
20+
time with and without time zone, date , interval
21+
money, macaddr
22+
23+
Feb 5, 2003 - btree_gist now support int2, int8, float4, float8
1224

1325
NOTICE:
14-
This version will works only with postgresql version 7.3 and above
26+
This version will works only with postgresql version 7.4 and above
1527
because of changes in interface of function calling and in system
1628
tables.
29+
30+
If you want to index varchar attributes, you have to index using
31+
the function text(<varchar>):
32+
Example:
33+
CREATE TABLE test ( a varchar(23) );
34+
CREATE INDEX testidx ON test USING GIST ( text(a) );
35+
1736

1837
INSTALLATION:
1938

contrib/btree_gist/btree_bit.c

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#include "btree_gist.h"
2+
#include "btree_utils_var.h"
3+
#include "utils/builtins.h"
4+
#include "utils/varbit.h"
5+
6+
7+
/*
8+
** Bit ops
9+
*/
10+
PG_FUNCTION_INFO_V1(gbt_bit_compress);
11+
PG_FUNCTION_INFO_V1(gbt_bit_union);
12+
PG_FUNCTION_INFO_V1(gbt_bit_picksplit);
13+
PG_FUNCTION_INFO_V1(gbt_bit_consistent);
14+
PG_FUNCTION_INFO_V1(gbt_bit_penalty);
15+
PG_FUNCTION_INFO_V1(gbt_bit_same);
16+
17+
Datum gbt_bit_compress(PG_FUNCTION_ARGS);
18+
Datum gbt_bit_union(PG_FUNCTION_ARGS);
19+
Datum gbt_bit_picksplit(PG_FUNCTION_ARGS);
20+
Datum gbt_bit_consistent(PG_FUNCTION_ARGS);
21+
Datum gbt_bit_penalty(PG_FUNCTION_ARGS);
22+
Datum gbt_bit_same(PG_FUNCTION_ARGS);
23+
24+
25+
26+
/* define for comparison */
27+
28+
static bool gbt_bitgt (const void *a, const void *b)
29+
{
30+
return ( DatumGetBool(DirectFunctionCall2( bitgt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
31+
}
32+
33+
static bool gbt_bitge (const void *a, const void *b)
34+
{
35+
return ( DatumGetBool(DirectFunctionCall2( bitge ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
36+
}
37+
38+
static bool gbt_biteq (const void *a, const void *b)
39+
{
40+
return ( DatumGetBool(DirectFunctionCall2( biteq ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
41+
}
42+
43+
static bool gbt_bitle (const void *a, const void *b)
44+
{
45+
return ( DatumGetBool(DirectFunctionCall2( bitle ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
46+
}
47+
48+
static bool gbt_bitlt (const void *a, const void *b)
49+
{
50+
return ( DatumGetBool(DirectFunctionCall2( bitlt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
51+
}
52+
53+
static int32 gbt_bitcmp ( const bytea * a , const bytea * b )
54+
{
55+
return
56+
( DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b) ) ) );
57+
}
58+
59+
60+
static bytea *
61+
gbt_bit_xfrm ( bytea * leaf )
62+
{
63+
bytea * out = leaf;
64+
int s = VARBITBYTES(leaf) + VARHDRSZ;
65+
66+
out = palloc ( s );
67+
VARATT_SIZEP(out) = s;
68+
memcpy ( (void*)VARDATA(out), (void*)VARBITS(leaf), VARBITBYTES(leaf) );
69+
return out;
70+
}
71+
72+
73+
74+
75+
static GBT_VARKEY * gbt_bit_l2n ( GBT_VARKEY * leaf )
76+
{
77+
78+
GBT_VARKEY *out = leaf ;
79+
GBT_VARKEY_R r = gbt_var_key_readable ( leaf );
80+
bytea *o ;
81+
82+
o = gbt_bit_xfrm (r.lower);
83+
r.upper = r.lower = o;
84+
out = gbt_var_key_copy( &r, TRUE );
85+
pfree(o);
86+
87+
return out;
88+
89+
}
90+
91+
static const gbtree_vinfo tinfo =
92+
{
93+
gbt_t_bit,
94+
FALSE,
95+
TRUE,
96+
gbt_bitgt,
97+
gbt_bitge,
98+
gbt_biteq,
99+
gbt_bitle,
100+
gbt_bitlt,
101+
gbt_bitcmp,
102+
gbt_bit_l2n
103+
};
104+
105+
106+
/**************************************************
107+
* Bit ops
108+
**************************************************/
109+
110+
Datum
111+
gbt_bit_compress (PG_FUNCTION_ARGS)
112+
{
113+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
114+
PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
115+
}
116+
117+
Datum
118+
gbt_bit_consistent(PG_FUNCTION_ARGS)
119+
{
120+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
121+
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
122+
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
123+
void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) );
124+
void *query = ( void * ) DatumGetByteaP ( PG_GETARG_DATUM(1) );
125+
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
126+
bool retval = FALSE;
127+
GBT_VARKEY_R r = gbt_var_key_readable ( key );
128+
129+
if ( GIST_LEAF(entry) )
130+
{
131+
retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo );
132+
} else {
133+
bytea * q = gbt_bit_xfrm ( ( bytea * ) query );
134+
retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
135+
pfree(q);
136+
}
137+
138+
if ( ktst != key ){
139+
pfree ( key );
140+
}
141+
if ( qtst != query ){
142+
pfree ( query );
143+
}
144+
PG_RETURN_BOOL(retval);
145+
}
146+
147+
148+
149+
Datum
150+
gbt_bit_union(PG_FUNCTION_ARGS)
151+
{
152+
GistEntryVector * entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
153+
int32 * size = (int *) PG_GETARG_POINTER(1);
154+
PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
155+
}
156+
157+
158+
Datum
159+
gbt_bit_picksplit(PG_FUNCTION_ARGS)
160+
{
161+
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
162+
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
163+
gbt_var_picksplit ( entryvec, v, &tinfo );
164+
PG_RETURN_POINTER(v);
165+
}
166+
167+
Datum
168+
gbt_bit_same(PG_FUNCTION_ARGS)
169+
{
170+
Datum d1 = PG_GETARG_DATUM(0);
171+
Datum d2 = PG_GETARG_DATUM(1);
172+
bool *result = (bool *) PG_GETARG_POINTER(2);
173+
PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
174+
}
175+
176+
177+
Datum
178+
gbt_bit_penalty(PG_FUNCTION_ARGS)
179+
{
180+
float *result = (float *) PG_GETARG_POINTER(2);
181+
GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0);
182+
GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1);
183+
PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
184+
}
185+

0 commit comments

Comments
 (0)