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

Commitd4c6da1

Browse files
committed
Allow GIN's extractQuery method to signal that nothing can satisfy the query.
In this case extractQuery should returns -1 as nentries. This changesprototype of extractQuery method to use int32* instead of uint32* fornentries argument.Based on that gincostestimate may see two corner cases: nothing will be foundor seqscan should be used.Per proposal athttp://archives.postgresql.org/pgsql-hackers/2007-01/msg01581.phpPS tsearch_core patch should be sightly modified to support changes, but I'mwaiting a verdict about reviewing of tsearch_core patch.
1 parent147a3ce commitd4c6da1

File tree

11 files changed

+199
-29
lines changed

11 files changed

+199
-29
lines changed

‎contrib/intarray/_int_gin.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Datumginint4_queryextract(PG_FUNCTION_ARGS);
66
Datum
77
ginint4_queryextract(PG_FUNCTION_ARGS)
88
{
9-
uint32*nentries= (uint32*)PG_GETARG_POINTER(1);
9+
int32*nentries= (int32*)PG_GETARG_POINTER(1);
1010
StrategyNumberstrategy=PG_GETARG_UINT16(2);
1111
Datum*res=NULL;
1212

@@ -57,6 +57,19 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
5757
}
5858
}
5959

60+
if (nentries==0 )
61+
{
62+
switch(strategy )
63+
{
64+
caseBooleanSearchStrategy:
65+
caseRTOverlapStrategyNumber:
66+
*nentries=-1;/* nobody can be found */
67+
break;
68+
default:/* require fullscan: GIN can't find void arrays */
69+
break;
70+
}
71+
}
72+
6073
PG_RETURN_POINTER(res);
6174
}
6275

‎contrib/tsearch2/ginidx.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Datum
2121
gin_extract_tsvector(PG_FUNCTION_ARGS)
2222
{
2323
tsvector*vector= (tsvector*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
24-
uint32*nentries= (uint32*)PG_GETARG_POINTER(1);
24+
int32*nentries= (int32*)PG_GETARG_POINTER(1);
2525
Datum*entries=NULL;
2626

2727
*nentries=0;
@@ -30,7 +30,7 @@ gin_extract_tsvector(PG_FUNCTION_ARGS)
3030
inti;
3131
WordEntry*we=ARRPTR(vector);
3232

33-
*nentries= (uint32)vector->size;
33+
*nentries= (int32)vector->size;
3434
entries= (Datum*)palloc(sizeof(Datum)*vector->size);
3535

3636
for (i=0;i<vector->size;i++)
@@ -58,7 +58,7 @@ Datum
5858
gin_extract_tsquery(PG_FUNCTION_ARGS)
5959
{
6060
QUERYTYPE*query= (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
61-
uint32*nentries= (uint32*)PG_GETARG_POINTER(1);
61+
int32*nentries= (int32*)PG_GETARG_POINTER(1);
6262
StrategyNumberstrategy=DatumGetUInt16(PG_GETARG_DATUM(2));
6363
Datum*entries=NULL;
6464

@@ -99,6 +99,8 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
9999
}
100100

101101
}
102+
else
103+
*nentries=-1;/* nothing can be found */
102104

103105
PG_FREE_IF_COPY(query,0);
104106
PG_RETURN_POINTER(entries);

‎doc/src/sgml/gin.sgml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/gin.sgml,v 2.7 2006/12/01 23:46:46 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/gin.sgml,v 2.8 2007/01/31 15:09:45 teodor Exp $ -->
22

33
<chapter id="GIN">
44
<title>GIN Indexes</title>
@@ -77,7 +77,7 @@
7777
</varlistentry>
7878

7979
<varlistentry>
80-
<term>Datum* extractValue(Datum inputValue,uint32 *nkeys)</term>
80+
<term>Datum* extractValue(Datum inputValue,int32 *nkeys)</term>
8181
<listitem>
8282
<para>
8383
Returns an array of keys given a value to be indexed. The
@@ -87,7 +87,7 @@
8787
</varlistentry>
8888

8989
<varlistentry>
90-
<term>Datum* extractQuery(Datum query,uint32 *nkeys,
90+
<term>Datum* extractQuery(Datum query,int32 *nkeys,
9191
StrategyNumber n)</term>
9292
<listitem>
9393
<para>
@@ -100,6 +100,12 @@
100100
to consult <literal>n</> to determine the data type of
101101
<literal>query</> and the key values that need to be extracted.
102102
The number of returned keys must be stored into <literal>*nkeys</>.
103+
If number of keys is equal to zero then <function>extractQuery</>
104+
should store 0 or -1 into <literal>*nkeys</>. 0 means that any
105+
row matches the <literal>query</> and sequence scan should be
106+
produced. -1 means nothing can satisfy <literal>query</>.
107+
Choice of value should be based on semantics meaning of operation with
108+
given strategy number.
103109
</para>
104110
</listitem>
105111
</varlistentry>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginarrayproc.c,v 1.8 2007/01/05 22:19:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginarrayproc.c,v 1.9 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include"postgres.h"
@@ -38,7 +38,7 @@ Datum
3838
ginarrayextract(PG_FUNCTION_ARGS)
3939
{
4040
ArrayType*array;
41-
uint32*nentries= (uint32*)PG_GETARG_POINTER(1);
41+
int32*nentries= (int32*)PG_GETARG_POINTER(1);
4242
Datum*entries=NULL;
4343
int16elmlen;
4444
boolelmbyval;
@@ -60,6 +60,21 @@ ginarrayextract(PG_FUNCTION_ARGS)
6060
elmlen,elmbyval,elmalign,
6161
&entries,NULL, (int*)nentries);
6262

63+
if (*nentries==0&&PG_NARGS()==3 )
64+
{
65+
switch(PG_GETARG_UINT16(2) )
66+
{
67+
caseGinOverlapStrategy:
68+
*nentries=-1;/* nobody can be found */
69+
break;
70+
caseGinContainsStrategy:
71+
caseGinContainedStrategy:
72+
caseGinEqualStrategy:
73+
default:/* require fullscan: GIN can't find void arrays */
74+
break;
75+
}
76+
}
77+
6378
/* we should not free array, entries[i] points into it */
6479
PG_RETURN_POINTER(entries);
6580
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.7 2007/01/05 22:19:21 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.8 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -191,13 +191,13 @@ ginChooseElem(BuildAccumulator *accum, ItemPointer heapptr, Datum *entries, uint
191191
* next middle on left part and middle of right part.
192192
*/
193193
void
194-
ginInsertRecordBA(BuildAccumulator*accum,ItemPointerheapptr,Datum*entries,uint32nentry)
194+
ginInsertRecordBA(BuildAccumulator*accum,ItemPointerheapptr,Datum*entries,int32nentry)
195195
{
196196
uint32i,
197197
nbit=0,
198198
offset;
199199

200-
if (nentry==0)
200+
if (nentry<=0)
201201
return;
202202

203203
i=nentry-1;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.5 2007/01/05 22:19:21 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.6 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -420,6 +420,7 @@ scanGetItem(IndexScanDesc scan, ItemPointerData *item)
420420
}
421421

422422
#defineGinIsNewKey(s)( ((GinScanOpaque) scan->opaque)->keys == NULL )
423+
#defineGinIsVoidRes(s)( ((GinScanOpaque) scan->opaque)->isVoidRes == true )
423424

424425
Datum
425426
gingetmulti(PG_FUNCTION_ARGS)
@@ -432,10 +433,13 @@ gingetmulti(PG_FUNCTION_ARGS)
432433
if (GinIsNewKey(scan))
433434
newScanKey(scan);
434435

435-
startScan(scan);
436-
437436
*returned_tids=0;
438437

438+
if (GinIsVoidRes(scan))
439+
PG_RETURN_BOOL(false);
440+
441+
startScan(scan);
442+
439443
do
440444
{
441445
if (scanGetItem(scan,tids+*returned_tids))
@@ -462,6 +466,9 @@ gingettuple(PG_FUNCTION_ARGS)
462466
if (GinIsNewKey(scan))
463467
newScanKey(scan);
464468

469+
if (GinIsVoidRes(scan))
470+
PG_RETURN_BOOL(false);
471+
465472
startScan(scan);
466473
res=scanGetItem(scan,&scan->xs_ctup.t_self);
467474
stopScan(scan);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.6 2007/01/05 22:19:21 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.7 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -203,7 +203,7 @@ static uint32
203203
ginHeapTupleBulkInsert(GinBuildState*buildstate,Datumvalue,ItemPointerheapptr)
204204
{
205205
Datum*entries;
206-
uint32nentries;
206+
int32nentries;
207207
MemoryContextoldCtx;
208208

209209
oldCtx=MemoryContextSwitchTo(buildstate->funcCtx);
@@ -356,7 +356,7 @@ static uint32
356356
ginHeapTupleInsert(Relationindex,GinState*ginstate,Datumvalue,ItemPointeritem)
357357
{
358358
Datum*entries;
359-
uint32i,
359+
int32i,
360360
nentries;
361361

362362
entries=extractEntriesSU(ginstate,value,&nentries);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/ginscan.c,v 1.8 2007/01/05 22:19:21 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/ginscan.c,v 1.9 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -145,10 +145,12 @@ newScanKey(IndexScanDesc scan)
145145
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146146
errmsg("GIN indexes do not support whole-index scans")));
147147

148+
so->isVoidRes= false;
149+
148150
for (i=0;i<scan->numberOfKeys;i++)
149151
{
150152
Datum*entryValues;
151-
uint32nEntryValues;
153+
int32nEntryValues;
152154

153155
if (scankey[i].sk_flags&SK_ISNULL)
154156
elog(ERROR,"Gin doesn't support NULL as scan key");
@@ -162,6 +164,15 @@ newScanKey(IndexScanDesc scan)
162164
UInt16GetDatum(scankey[i].sk_strategy)
163165
)
164166
);
167+
if (nEntryValues<0 )
168+
{
169+
/*
170+
* extractQueryFn signals that nothing will be found,
171+
* so we can just set isVoidRes flag...
172+
*/
173+
so->isVoidRes= true;
174+
break;
175+
}
165176
if (entryValues==NULL||nEntryValues==0)
166177
/* full scan... */
167178
continue;
@@ -173,7 +184,7 @@ newScanKey(IndexScanDesc scan)
173184

174185
so->nkeys=nkeys;
175186

176-
if (so->nkeys==0)
187+
if (so->nkeys==0&& !so->isVoidRes)
177188
ereport(ERROR,
178189
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
179190
errmsg("GIN index does not support search with void query")));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.9 2007/01/05 22:19:21 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.10 2007/01/31 15:09:45 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -148,7 +148,7 @@ cmpEntries(const Datum *a, const Datum *b, cmpEntriesData *arg)
148148
}
149149

150150
Datum*
151-
extractEntriesS(GinState*ginstate,Datumvalue,uint32*nentries,
151+
extractEntriesS(GinState*ginstate,Datumvalue,int32*nentries,
152152
bool*needUnique)
153153
{
154154
Datum*entries;
@@ -178,7 +178,7 @@ extractEntriesS(GinState *ginstate, Datum value, uint32 *nentries,
178178

179179

180180
Datum*
181-
extractEntriesSU(GinState*ginstate,Datumvalue,uint32*nentries)
181+
extractEntriesSU(GinState*ginstate,Datumvalue,int32*nentries)
182182
{
183183
boolneedUnique;
184184
Datum*entries=extractEntriesS(ginstate,value,nentries,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp