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

Commitae20bf1

Browse files
committed
Make GIN and GIST pass the index collation to all their support functions.
Experimentation with contrib/btree_gist shows that the majority of the GISTsupport functions potentially need collation information. Safest policyseems to be to pass it to all of them, instead of making assumptions aboutwhich ones could possibly need it.
1 parent474ff21 commitae20bf1

File tree

8 files changed

+82
-50
lines changed

8 files changed

+82
-50
lines changed

‎src/backend/access/gin/ginget.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ callConsistentFn(GinState *ginstate, GinScanKey key)
5656
key->recheckCurItem= true;
5757

5858
returnDatumGetBool(FunctionCall8Coll(&ginstate->consistentFn[key->attnum-1],
59-
ginstate->compareCollation[key->attnum-1],
59+
ginstate->supportCollation[key->attnum-1],
6060
PointerGetDatum(key->entryRes),
6161
UInt16GetDatum(key->strategy),
6262
key->query,
@@ -252,7 +252,7 @@ collectMatchBitmap(GinBtreeData *btree, GinBtreeStack *stack,
252252
*----------
253253
*/
254254
cmp=DatumGetInt32(FunctionCall4Coll(&btree->ginstate->comparePartialFn[attnum-1],
255-
btree->ginstate->compareCollation[attnum-1],
255+
btree->ginstate->supportCollation[attnum-1],
256256
scanEntry->queryKey,
257257
idatum,
258258
UInt16GetDatum(scanEntry->strategy),
@@ -1178,7 +1178,7 @@ matchPartialInPendingList(GinState *ginstate, Page page,
11781178
*----------
11791179
*/
11801180
cmp=DatumGetInt32(FunctionCall4Coll(&ginstate->comparePartialFn[entry->attnum-1],
1181-
ginstate->compareCollation[entry->attnum-1],
1181+
ginstate->supportCollation[entry->attnum-1],
11821182
entry->queryKey,
11831183
datum[off-1],
11841184
UInt16GetDatum(entry->strategy),

‎src/backend/access/gin/ginscan.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,15 @@ ginNewScanKey(IndexScanDesc scan)
305305

306306
/* OK to call the extractQueryFn */
307307
queryValues= (Datum*)
308-
DatumGetPointer(FunctionCall7(&so->ginstate.extractQueryFn[skey->sk_attno-1],
309-
skey->sk_argument,
310-
PointerGetDatum(&nQueryValues),
311-
UInt16GetDatum(skey->sk_strategy),
312-
PointerGetDatum(&partial_matches),
313-
PointerGetDatum(&extra_data),
314-
PointerGetDatum(&nullFlags),
315-
PointerGetDatum(&searchMode)));
308+
DatumGetPointer(FunctionCall7Coll(&so->ginstate.extractQueryFn[skey->sk_attno-1],
309+
so->ginstate.supportCollation[skey->sk_attno-1],
310+
skey->sk_argument,
311+
PointerGetDatum(&nQueryValues),
312+
UInt16GetDatum(skey->sk_strategy),
313+
PointerGetDatum(&partial_matches),
314+
PointerGetDatum(&extra_data),
315+
PointerGetDatum(&nullFlags),
316+
PointerGetDatum(&searchMode)));
316317

317318
/*
318319
* If bogus searchMode is returned, treat as GIN_SEARCH_MODE_ALL; note

‎src/backend/access/gin/ginutil.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ initGinState(GinState *state, Relation index)
9393
* while doing comparisons. However, we may have a collatable storage
9494
* type for a noncollatable indexed data type (for instance, hstore
9595
* uses text index entries). If there's no index collation then
96-
* specify default collation in case thecomparison function needs
97-
* collation. This is harmless if thecomparison function doesn't
96+
* specify default collation in case thesupport functions need
97+
* collation. This is harmless if thesupport functions don't
9898
* care about collation, so we just do it unconditionally. (We could
9999
* alternatively call get_typcollation, but that seems like expensive
100100
* overkill --- there aren't going to be any cases where a GIN storage
101101
* type has a nondefault collation.)
102102
*/
103103
if (OidIsValid(index->rd_indcollation[i]))
104-
state->compareCollation[i]=index->rd_indcollation[i];
104+
state->supportCollation[i]=index->rd_indcollation[i];
105105
else
106-
state->compareCollation[i]=DEFAULT_COLLATION_OID;
106+
state->supportCollation[i]=DEFAULT_COLLATION_OID;
107107
}
108108
}
109109

@@ -293,7 +293,7 @@ ginCompareEntries(GinState *ginstate, OffsetNumber attnum,
293293

294294
/* both not null, so safe to call the compareFn */
295295
returnDatumGetInt32(FunctionCall2Coll(&ginstate->compareFn[attnum-1],
296-
ginstate->compareCollation[attnum-1],
296+
ginstate->supportCollation[attnum-1],
297297
a,b));
298298
}
299299

@@ -399,10 +399,11 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
399399
/* OK, call the opclass's extractValueFn */
400400
nullFlags=NULL;/* in case extractValue doesn't set it */
401401
entries= (Datum*)
402-
DatumGetPointer(FunctionCall3(&ginstate->extractValueFn[attnum-1],
403-
value,
404-
PointerGetDatum(nentries),
405-
PointerGetDatum(&nullFlags)));
402+
DatumGetPointer(FunctionCall3Coll(&ginstate->extractValueFn[attnum-1],
403+
ginstate->supportCollation[attnum-1],
404+
value,
405+
PointerGetDatum(nentries),
406+
PointerGetDatum(&nullFlags)));
406407

407408
/*
408409
* Generate a placeholder if the item contained no keys.
@@ -453,7 +454,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
453454
}
454455

455456
arg.cmpDatumFunc=&ginstate->compareFn[attnum-1];
456-
arg.collation=ginstate->compareCollation[attnum-1];
457+
arg.collation=ginstate->supportCollation[attnum-1];
457458
arg.haveDups= false;
458459
qsort_arg(keydata,*nentries,sizeof(keyEntryData),
459460
cmpEntries, (void*)&arg);

‎src/backend/access/gist/gist.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include"access/genam.h"
1818
#include"access/gist_private.h"
1919
#include"catalog/index.h"
20+
#include"catalog/pg_collation.h"
2021
#include"miscadmin.h"
2122
#include"storage/bufmgr.h"
2223
#include"storage/indexfsm.h"
@@ -1394,6 +1395,22 @@ initGISTstate(GISTSTATE *giststate, Relation index)
13941395
CurrentMemoryContext);
13951396
else
13961397
giststate->distanceFn[i].fn_oid=InvalidOid;
1398+
1399+
/*
1400+
* If the index column has a specified collation, we should honor that
1401+
* while doing comparisons. However, we may have a collatable storage
1402+
* type for a noncollatable indexed data type. If there's no index
1403+
* collation then specify default collation in case the support
1404+
* functions need collation. This is harmless if the support
1405+
* functions don't care about collation, so we just do it
1406+
* unconditionally. (We could alternatively call get_typcollation,
1407+
* but that seems like expensive overkill --- there aren't going to be
1408+
* any cases where a GIST storage type has a nondefault collation.)
1409+
*/
1410+
if (OidIsValid(index->rd_indcollation[i]))
1411+
giststate->supportCollation[i]=index->rd_indcollation[i];
1412+
else
1413+
giststate->supportCollation[i]=DEFAULT_COLLATION_OID;
13971414
}
13981415
}
13991416

‎src/backend/access/gist/gistsplit.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,18 @@ genericPickSplit(GISTSTATE *giststate, GistEntryVector *entryvec, GIST_SPLITVEC
325325
evec->n=v->spl_nleft;
326326
memcpy(evec->vector,entryvec->vector+FirstOffsetNumber,
327327
sizeof(GISTENTRY)*evec->n);
328-
v->spl_ldatum=FunctionCall2(&giststate->unionFn[attno],
329-
PointerGetDatum(evec),
330-
PointerGetDatum(&nbytes));
328+
v->spl_ldatum=FunctionCall2Coll(&giststate->unionFn[attno],
329+
giststate->supportCollation[attno],
330+
PointerGetDatum(evec),
331+
PointerGetDatum(&nbytes));
331332

332333
evec->n=v->spl_nright;
333334
memcpy(evec->vector,entryvec->vector+FirstOffsetNumber+v->spl_nleft,
334335
sizeof(GISTENTRY)*evec->n);
335-
v->spl_rdatum=FunctionCall2(&giststate->unionFn[attno],
336-
PointerGetDatum(evec),
337-
PointerGetDatum(&nbytes));
336+
v->spl_rdatum=FunctionCall2Coll(&giststate->unionFn[attno],
337+
giststate->supportCollation[attno],
338+
PointerGetDatum(evec),
339+
PointerGetDatum(&nbytes));
338340
}
339341

340342
/*
@@ -361,9 +363,10 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, int attno, GistSplitVec
361363
sv->spl_ldatum=v->spl_lattr[attno];
362364
sv->spl_rdatum=v->spl_rattr[attno];
363365

364-
FunctionCall2(&giststate->picksplitFn[attno],
365-
PointerGetDatum(entryvec),
366-
PointerGetDatum(sv));
366+
FunctionCall2Coll(&giststate->picksplitFn[attno],
367+
giststate->supportCollation[attno],
368+
PointerGetDatum(entryvec),
369+
PointerGetDatum(sv));
367370

368371
if (sv->spl_nleft==0||sv->spl_nright==0)
369372
{

‎src/backend/access/gist/gistutil.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startke
207207
}
208208

209209
/* Make union and store in attr array */
210-
attr[i]=FunctionCall2(&giststate->unionFn[i],
211-
PointerGetDatum(evec),
212-
PointerGetDatum(&attrsize));
210+
attr[i]=FunctionCall2Coll(&giststate->unionFn[i],
211+
giststate->supportCollation[i],
212+
PointerGetDatum(evec),
213+
PointerGetDatum(&attrsize));
213214

214215
isnull[i]= FALSE;
215216
}
@@ -271,9 +272,10 @@ gistMakeUnionKey(GISTSTATE *giststate, int attno,
271272
}
272273

273274
*dstisnull= FALSE;
274-
*dst=FunctionCall2(&giststate->unionFn[attno],
275-
PointerGetDatum(evec),
276-
PointerGetDatum(&dstsize));
275+
*dst=FunctionCall2Coll(&giststate->unionFn[attno],
276+
giststate->supportCollation[attno],
277+
PointerGetDatum(evec),
278+
PointerGetDatum(&dstsize));
277279
}
278280
}
279281

@@ -282,9 +284,10 @@ gistKeyIsEQ(GISTSTATE *giststate, int attno, Datum a, Datum b)
282284
{
283285
boolresult;
284286

285-
FunctionCall3(&giststate->equalFn[attno],
286-
a,b,
287-
PointerGetDatum(&result));
287+
FunctionCall3Coll(&giststate->equalFn[attno],
288+
giststate->supportCollation[attno],
289+
a,b,
290+
PointerGetDatum(&result));
288291
returnresult;
289292
}
290293

@@ -442,8 +445,9 @@ gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e,
442445

443446
gistentryinit(*e,k,r,pg,o,l);
444447
dep= (GISTENTRY*)
445-
DatumGetPointer(FunctionCall1(&giststate->decompressFn[nkey],
446-
PointerGetDatum(e)));
448+
DatumGetPointer(FunctionCall1Coll(&giststate->decompressFn[nkey],
449+
giststate->supportCollation[nkey],
450+
PointerGetDatum(e)));
447451
/* decompressFn may just return the given pointer */
448452
if (dep!=e)
449453
gistentryinit(*e,dep->key,dep->rel,dep->page,dep->offset,
@@ -468,8 +472,9 @@ gistcentryinit(GISTSTATE *giststate, int nkey,
468472

469473
gistentryinit(*e,k,r,pg,o,l);
470474
cep= (GISTENTRY*)
471-
DatumGetPointer(FunctionCall1(&giststate->compressFn[nkey],
472-
PointerGetDatum(e)));
475+
DatumGetPointer(FunctionCall1Coll(&giststate->compressFn[nkey],
476+
giststate->supportCollation[nkey],
477+
PointerGetDatum(e)));
473478
/* compressFn may just return the given pointer */
474479
if (cep!=e)
475480
gistentryinit(*e,cep->key,cep->rel,cep->page,cep->offset,
@@ -519,11 +524,13 @@ gistpenalty(GISTSTATE *giststate, int attno,
519524
{
520525
floatpenalty=0.0;
521526

522-
if (giststate->penaltyFn[attno].fn_strict== FALSE|| (isNullOrig== FALSE&&isNullAdd== FALSE))
523-
FunctionCall3(&giststate->penaltyFn[attno],
524-
PointerGetDatum(orig),
525-
PointerGetDatum(add),
526-
PointerGetDatum(&penalty));
527+
if (giststate->penaltyFn[attno].fn_strict== FALSE||
528+
(isNullOrig== FALSE&&isNullAdd== FALSE))
529+
FunctionCall3Coll(&giststate->penaltyFn[attno],
530+
giststate->supportCollation[attno],
531+
PointerGetDatum(orig),
532+
PointerGetDatum(add),
533+
PointerGetDatum(&penalty));
527534
elseif (isNullOrig&&isNullAdd)
528535
penalty=0.0;
529536
else

‎src/include/access/gin_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ typedef struct GinState
303303
FmgrInfocomparePartialFn[INDEX_MAX_KEYS];/* optional method */
304304
/* canPartialMatch[i] is true if comparePartialFn[i] is valid */
305305
boolcanPartialMatch[INDEX_MAX_KEYS];
306-
/* Collations tosupply to thecompareFns and comparePartialFns */
307-
OidcompareCollation[INDEX_MAX_KEYS];
306+
/* Collations topass to thesupport functions */
307+
OidsupportCollation[INDEX_MAX_KEYS];
308308
}GinState;
309309

310310
/* XLog stuff */

‎src/include/access/gist_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ typedef struct GISTSTATE
4141
FmgrInfoequalFn[INDEX_MAX_KEYS];
4242
FmgrInfodistanceFn[INDEX_MAX_KEYS];
4343

44+
/* Collations to pass to the support functions */
45+
OidsupportCollation[INDEX_MAX_KEYS];
46+
4447
TupleDesctupdesc;
4548
}GISTSTATE;
4649

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp