Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb85030

Browse files
committed
Fix contrib/btree_gist to handle collations properly.
Make use of the collation attached to the index column, instead ofhard-wiring DEFAULT_COLLATION_OID. (Note: in theory this could requirereindexing btree_gist indexes on textual columns, but I rather doubt anyonehas one with a non-default declared collation as yet.)
1 parentae20bf1 commitbb85030

File tree

7 files changed

+219
-187
lines changed

7 files changed

+219
-187
lines changed

‎contrib/btree_gist/btree_bit.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,51 @@ Datumgbt_bit_same(PG_FUNCTION_ARGS);
2929
/* define for comparison */
3030

3131
staticbool
32-
gbt_bitgt(constvoid*a,constvoid*b)
32+
gbt_bitgt(constvoid*a,constvoid*b,Oidcollation)
3333
{
34-
return (DatumGetBool(DirectFunctionCall2(bitgt,PointerGetDatum(a),PointerGetDatum(b))));
34+
returnDatumGetBool(DirectFunctionCall2(bitgt,
35+
PointerGetDatum(a),
36+
PointerGetDatum(b)));
3537
}
3638

3739
staticbool
38-
gbt_bitge(constvoid*a,constvoid*b)
40+
gbt_bitge(constvoid*a,constvoid*b,Oidcollation)
3941
{
40-
return (DatumGetBool(DirectFunctionCall2(bitge,PointerGetDatum(a),PointerGetDatum(b))));
42+
returnDatumGetBool(DirectFunctionCall2(bitge,
43+
PointerGetDatum(a),
44+
PointerGetDatum(b)));
4145
}
4246

4347
staticbool
44-
gbt_biteq(constvoid*a,constvoid*b)
48+
gbt_biteq(constvoid*a,constvoid*b,Oidcollation)
4549
{
46-
return (DatumGetBool(DirectFunctionCall2(biteq,PointerGetDatum(a),PointerGetDatum(b))));
50+
returnDatumGetBool(DirectFunctionCall2(biteq,
51+
PointerGetDatum(a),
52+
PointerGetDatum(b)));
4753
}
4854

4955
staticbool
50-
gbt_bitle(constvoid*a,constvoid*b)
56+
gbt_bitle(constvoid*a,constvoid*b,Oidcollation)
5157
{
52-
return (DatumGetBool(DirectFunctionCall2(bitle,PointerGetDatum(a),PointerGetDatum(b))));
58+
returnDatumGetBool(DirectFunctionCall2(bitle,
59+
PointerGetDatum(a),
60+
PointerGetDatum(b)));
5361
}
5462

5563
staticbool
56-
gbt_bitlt(constvoid*a,constvoid*b)
64+
gbt_bitlt(constvoid*a,constvoid*b,Oidcollation)
5765
{
58-
return (DatumGetBool(DirectFunctionCall2(bitlt,PointerGetDatum(a),PointerGetDatum(b))));
66+
returnDatumGetBool(DirectFunctionCall2(bitlt,
67+
PointerGetDatum(a),
68+
PointerGetDatum(b)));
5969
}
6070

6171
staticint32
62-
gbt_bitcmp(constbytea*a,constbytea*b)
72+
gbt_bitcmp(constvoid*a,constvoid*b,Oidcollation)
6373
{
64-
return
65-
(DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b))));
74+
returnDatumGetInt32(DirectFunctionCall2(byteacmp,
75+
PointerGetDatum(a),
76+
PointerGetDatum(b)));
6677
}
6778

6879

@@ -134,20 +145,22 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
134145

135146
/* Oidsubtype = PG_GETARG_OID(3); */
136147
bool*recheck= (bool*)PG_GETARG_POINTER(4);
137-
boolretval= FALSE;
148+
boolretval;
138149
GBT_VARKEY*key= (GBT_VARKEY*)DatumGetPointer(entry->key);
139150
GBT_VARKEY_Rr=gbt_var_key_readable(key);
140151

141152
/* All cases served by this function are exact */
142153
*recheck= false;
143154

144155
if (GIST_LEAF(entry))
145-
retval=gbt_var_consistent(&r,query,&strategy, TRUE,&tinfo);
156+
retval=gbt_var_consistent(&r,query,strategy,PG_GET_COLLATION(),
157+
TRUE,&tinfo);
146158
else
147159
{
148160
bytea*q=gbt_bit_xfrm((bytea*)query);
149161

150-
retval=gbt_var_consistent(&r, (void*)q,&strategy, FALSE,&tinfo);
162+
retval=gbt_var_consistent(&r,q,strategy,PG_GET_COLLATION(),
163+
FALSE,&tinfo);
151164
}
152165
PG_RETURN_BOOL(retval);
153166
}
@@ -160,7 +173,8 @@ gbt_bit_union(PG_FUNCTION_ARGS)
160173
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
161174
int32*size= (int*)PG_GETARG_POINTER(1);
162175

163-
PG_RETURN_POINTER(gbt_var_union(entryvec,size,&tinfo));
176+
PG_RETURN_POINTER(gbt_var_union(entryvec,size,PG_GET_COLLATION(),
177+
&tinfo));
164178
}
165179

166180

@@ -170,7 +184,8 @@ gbt_bit_picksplit(PG_FUNCTION_ARGS)
170184
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
171185
GIST_SPLITVEC*v= (GIST_SPLITVEC*)PG_GETARG_POINTER(1);
172186

173-
gbt_var_picksplit(entryvec,v,&tinfo);
187+
gbt_var_picksplit(entryvec,v,PG_GET_COLLATION(),
188+
&tinfo);
174189
PG_RETURN_POINTER(v);
175190
}
176191

@@ -181,7 +196,8 @@ gbt_bit_same(PG_FUNCTION_ARGS)
181196
Datumd2=PG_GETARG_DATUM(1);
182197
bool*result= (bool*)PG_GETARG_POINTER(2);
183198

184-
PG_RETURN_POINTER(gbt_var_same(result,d1,d2,&tinfo));
199+
*result=gbt_var_same(d1,d2,PG_GET_COLLATION(),&tinfo);
200+
PG_RETURN_POINTER(result);
185201
}
186202

187203

@@ -192,5 +208,6 @@ gbt_bit_penalty(PG_FUNCTION_ARGS)
192208
GISTENTRY*n= (GISTENTRY*)PG_GETARG_POINTER(1);
193209
float*result= (float*)PG_GETARG_POINTER(2);
194210

195-
PG_RETURN_POINTER(gbt_var_penalty(result,o,n,&tinfo));
211+
PG_RETURN_POINTER(gbt_var_penalty(result,o,n,PG_GET_COLLATION(),
212+
&tinfo));
196213
}

‎contrib/btree_gist/btree_bytea.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,51 @@ Datumgbt_bytea_same(PG_FUNCTION_ARGS);
2727
/* define for comparison */
2828

2929
staticbool
30-
gbt_byteagt(constvoid*a,constvoid*b)
30+
gbt_byteagt(constvoid*a,constvoid*b,Oidcollation)
3131
{
32-
return (DatumGetBool(DirectFunctionCall2(byteagt,PointerGetDatum(a),PointerGetDatum(b))));
32+
returnDatumGetBool(DirectFunctionCall2(byteagt,
33+
PointerGetDatum(a),
34+
PointerGetDatum(b)));
3335
}
3436

3537
staticbool
36-
gbt_byteage(constvoid*a,constvoid*b)
38+
gbt_byteage(constvoid*a,constvoid*b,Oidcollation)
3739
{
38-
return (DatumGetBool(DirectFunctionCall2(byteage,PointerGetDatum(a),PointerGetDatum(b))));
40+
returnDatumGetBool(DirectFunctionCall2(byteage,
41+
PointerGetDatum(a),
42+
PointerGetDatum(b)));
3943
}
4044

4145
staticbool
42-
gbt_byteaeq(constvoid*a,constvoid*b)
46+
gbt_byteaeq(constvoid*a,constvoid*b,Oidcollation)
4347
{
44-
return (DatumGetBool(DirectFunctionCall2(byteaeq,PointerGetDatum(a),PointerGetDatum(b))));
48+
returnDatumGetBool(DirectFunctionCall2(byteaeq,
49+
PointerGetDatum(a),
50+
PointerGetDatum(b)));
4551
}
4652

4753
staticbool
48-
gbt_byteale(constvoid*a,constvoid*b)
54+
gbt_byteale(constvoid*a,constvoid*b,Oidcollation)
4955
{
50-
return (DatumGetBool(DirectFunctionCall2(byteale,PointerGetDatum(a),PointerGetDatum(b))));
56+
returnDatumGetBool(DirectFunctionCall2(byteale,
57+
PointerGetDatum(a),
58+
PointerGetDatum(b)));
5159
}
5260

5361
staticbool
54-
gbt_bytealt(constvoid*a,constvoid*b)
62+
gbt_bytealt(constvoid*a,constvoid*b,Oidcollation)
5563
{
56-
return (DatumGetBool(DirectFunctionCall2(bytealt,PointerGetDatum(a),PointerGetDatum(b))));
64+
returnDatumGetBool(DirectFunctionCall2(bytealt,
65+
PointerGetDatum(a),
66+
PointerGetDatum(b)));
5767
}
5868

59-
6069
staticint32
61-
gbt_byteacmp(constbytea*a,constbytea*b)
70+
gbt_byteacmp(constvoid*a,constvoid*b,Oidcollation)
6271
{
63-
return
64-
(DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b))));
72+
returnDatumGetInt32(DirectFunctionCall2(byteacmp,
73+
PointerGetDatum(a),
74+
PointerGetDatum(b)));
6575
}
6676

6777

@@ -111,7 +121,8 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
111121
/* All cases served by this function are exact */
112122
*recheck= false;
113123

114-
retval=gbt_var_consistent(&r,query,&strategy,GIST_LEAF(entry),&tinfo);
124+
retval=gbt_var_consistent(&r,query,strategy,PG_GET_COLLATION(),
125+
GIST_LEAF(entry),&tinfo);
115126
PG_RETURN_BOOL(retval);
116127
}
117128

@@ -123,7 +134,8 @@ gbt_bytea_union(PG_FUNCTION_ARGS)
123134
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
124135
int32*size= (int*)PG_GETARG_POINTER(1);
125136

126-
PG_RETURN_POINTER(gbt_var_union(entryvec,size,&tinfo));
137+
PG_RETURN_POINTER(gbt_var_union(entryvec,size,PG_GET_COLLATION(),
138+
&tinfo));
127139
}
128140

129141

@@ -133,7 +145,8 @@ gbt_bytea_picksplit(PG_FUNCTION_ARGS)
133145
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
134146
GIST_SPLITVEC*v= (GIST_SPLITVEC*)PG_GETARG_POINTER(1);
135147

136-
gbt_var_picksplit(entryvec,v,&tinfo);
148+
gbt_var_picksplit(entryvec,v,PG_GET_COLLATION(),
149+
&tinfo);
137150
PG_RETURN_POINTER(v);
138151
}
139152

@@ -144,7 +157,8 @@ gbt_bytea_same(PG_FUNCTION_ARGS)
144157
Datumd2=PG_GETARG_DATUM(1);
145158
bool*result= (bool*)PG_GETARG_POINTER(2);
146159

147-
PG_RETURN_POINTER(gbt_var_same(result,d1,d2,&tinfo));
160+
*result=gbt_var_same(d1,d2,PG_GET_COLLATION(),&tinfo);
161+
PG_RETURN_POINTER(result);
148162
}
149163

150164

@@ -155,5 +169,6 @@ gbt_bytea_penalty(PG_FUNCTION_ARGS)
155169
GISTENTRY*n= (GISTENTRY*)PG_GETARG_POINTER(1);
156170
float*result= (float*)PG_GETARG_POINTER(2);
157171

158-
PG_RETURN_POINTER(gbt_var_penalty(result,o,n,&tinfo));
172+
PG_RETURN_POINTER(gbt_var_penalty(result,o,n,PG_GET_COLLATION(),
173+
&tinfo));
159174
}

‎contrib/btree_gist/btree_numeric.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,51 @@ Datumgbt_numeric_same(PG_FUNCTION_ARGS);
3232
/* define for comparison */
3333

3434
staticbool
35-
gbt_numeric_gt(constvoid*a,constvoid*b)
35+
gbt_numeric_gt(constvoid*a,constvoid*b,Oidcollation)
3636
{
37-
return (DatumGetBool(DirectFunctionCall2(numeric_gt,PointerGetDatum(a),PointerGetDatum(b))));
37+
returnDatumGetBool(DirectFunctionCall2(numeric_gt,
38+
PointerGetDatum(a),
39+
PointerGetDatum(b)));
3840
}
3941

4042
staticbool
41-
gbt_numeric_ge(constvoid*a,constvoid*b)
43+
gbt_numeric_ge(constvoid*a,constvoid*b,Oidcollation)
4244
{
43-
return (DatumGetBool(DirectFunctionCall2(numeric_ge,PointerGetDatum(a),PointerGetDatum(b))));
45+
returnDatumGetBool(DirectFunctionCall2(numeric_ge,
46+
PointerGetDatum(a),
47+
PointerGetDatum(b)));
4448
}
4549

4650
staticbool
47-
gbt_numeric_eq(constvoid*a,constvoid*b)
51+
gbt_numeric_eq(constvoid*a,constvoid*b,Oidcollation)
4852
{
49-
return (DatumGetBool(DirectFunctionCall2(numeric_eq,PointerGetDatum(a),PointerGetDatum(b))));
53+
returnDatumGetBool(DirectFunctionCall2(numeric_eq,
54+
PointerGetDatum(a),
55+
PointerGetDatum(b)));
5056
}
5157

5258
staticbool
53-
gbt_numeric_le(constvoid*a,constvoid*b)
59+
gbt_numeric_le(constvoid*a,constvoid*b,Oidcollation)
5460
{
55-
return (DatumGetBool(DirectFunctionCall2(numeric_le,PointerGetDatum(a),PointerGetDatum(b))));
61+
returnDatumGetBool(DirectFunctionCall2(numeric_le,
62+
PointerGetDatum(a),
63+
PointerGetDatum(b)));
5664
}
5765

5866
staticbool
59-
gbt_numeric_lt(constvoid*a,constvoid*b)
67+
gbt_numeric_lt(constvoid*a,constvoid*b,Oidcollation)
6068
{
61-
return (DatumGetBool(DirectFunctionCall2(numeric_lt,PointerGetDatum(a),PointerGetDatum(b))));
69+
returnDatumGetBool(DirectFunctionCall2(numeric_lt,
70+
PointerGetDatum(a),
71+
PointerGetDatum(b)));
6272
}
6373

64-
6574
staticint32
66-
gbt_numeric_cmp(constbytea*a,constbytea*b)
75+
gbt_numeric_cmp(constvoid*a,constvoid*b,Oidcollation)
6776
{
68-
return
69-
(DatumGetInt32(DirectFunctionCall2(numeric_cmp,PointerGetDatum(a),PointerGetDatum(b))));
77+
returnDatumGetInt32(DirectFunctionCall2(numeric_cmp,
78+
PointerGetDatum(a),
79+
PointerGetDatum(b)));
7080
}
7181

7282

@@ -116,7 +126,8 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
116126
/* All cases served by this function are exact */
117127
*recheck= false;
118128

119-
retval=gbt_var_consistent(&r,query,&strategy,GIST_LEAF(entry),&tinfo);
129+
retval=gbt_var_consistent(&r,query,strategy,PG_GET_COLLATION(),
130+
GIST_LEAF(entry),&tinfo);
120131
PG_RETURN_BOOL(retval);
121132
}
122133

@@ -128,7 +139,8 @@ gbt_numeric_union(PG_FUNCTION_ARGS)
128139
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
129140
int32*size= (int*)PG_GETARG_POINTER(1);
130141

131-
PG_RETURN_POINTER(gbt_var_union(entryvec,size,&tinfo));
142+
PG_RETURN_POINTER(gbt_var_union(entryvec,size,PG_GET_COLLATION(),
143+
&tinfo));
132144
}
133145

134146

@@ -139,7 +151,8 @@ gbt_numeric_same(PG_FUNCTION_ARGS)
139151
Datumd2=PG_GETARG_DATUM(1);
140152
bool*result= (bool*)PG_GETARG_POINTER(2);
141153

142-
PG_RETURN_POINTER(gbt_var_same(result,d1,d2,&tinfo));
154+
*result=gbt_var_same(d1,d2,PG_GET_COLLATION(),&tinfo);
155+
PG_RETURN_POINTER(result);
143156
}
144157

145158

@@ -163,7 +176,7 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
163176

164177
rk=gbt_var_key_readable(org);
165178
uni=PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
166-
gbt_var_bin_union(&uni,newe,&tinfo);
179+
gbt_var_bin_union(&uni,newe,PG_GET_COLLATION(),&tinfo);
167180
ok=gbt_var_key_readable(org);
168181
uk=gbt_var_key_readable((GBT_VARKEY*)DatumGetPointer(uni));
169182

@@ -224,6 +237,7 @@ gbt_numeric_picksplit(PG_FUNCTION_ARGS)
224237
GistEntryVector*entryvec= (GistEntryVector*)PG_GETARG_POINTER(0);
225238
GIST_SPLITVEC*v= (GIST_SPLITVEC*)PG_GETARG_POINTER(1);
226239

227-
gbt_var_picksplit(entryvec,v,&tinfo);
240+
gbt_var_picksplit(entryvec,v,PG_GET_COLLATION(),
241+
&tinfo);
228242
PG_RETURN_POINTER(v);
229243
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp