1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Allow GIN's extractQuery method to signal that nothing can satisfy the query.

In this case extractQuery should returns -1 as nentries. This changes
prototype of extractQuery method to use int32* instead of uint32* for
nentries argument.
Based on that gincostestimate may see two corner cases: nothing will be found
or seqscan should be used.

Per proposal at http://archives.postgresql.org/pgsql-hackers/2007-01/msg01581.php

PS tsearch_core patch should be sightly modified to support changes, but I'm
waiting a verdict about reviewing of tsearch_core patch.
This commit is contained in:
Teodor Sigaev
2007-01-31 15:09:45 +00:00
parent 147a3ce149
commit d4c6da1527
11 changed files with 199 additions and 29 deletions

View File

@ -6,7 +6,7 @@ Datum ginint4_queryextract(PG_FUNCTION_ARGS);
Datum
ginint4_queryextract(PG_FUNCTION_ARGS)
{
uint32 *nentries = (uint32 *) PG_GETARG_POINTER(1);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = PG_GETARG_UINT16(2);
Datum *res = NULL;
@ -57,6 +57,19 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
}
}
if ( nentries == 0 )
{
switch( strategy )
{
case BooleanSearchStrategy:
case RTOverlapStrategyNumber:
*nentries = -1; /* nobody can be found */
break;
default: /* require fullscan: GIN can't find void arrays */
break;
}
}
PG_RETURN_POINTER(res);
}

View File

@ -21,7 +21,7 @@ Datum
gin_extract_tsvector(PG_FUNCTION_ARGS)
{
tsvector *vector = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
uint32 *nentries = (uint32 *) PG_GETARG_POINTER(1);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
*nentries = 0;
@ -30,7 +30,7 @@ gin_extract_tsvector(PG_FUNCTION_ARGS)
int i;
WordEntry *we = ARRPTR(vector);
*nentries = (uint32) vector->size;
*nentries = (int32) vector->size;
entries = (Datum *) palloc(sizeof(Datum) * vector->size);
for (i = 0; i < vector->size; i++)
@ -58,7 +58,7 @@ Datum
gin_extract_tsquery(PG_FUNCTION_ARGS)
{
QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
uint32 *nentries = (uint32 *) PG_GETARG_POINTER(1);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = DatumGetUInt16(PG_GETARG_DATUM(2));
Datum *entries = NULL;
@ -99,6 +99,8 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
}
}
else
*nentries = -1; /* nothing can be found */
PG_FREE_IF_COPY(query, 0);
PG_RETURN_POINTER(entries);