Skip to content

Commit a734979

Browse files
committed
Fix tsquerysel() to not fail on an empty TSQuery. Per report from
Tatsuo Ishii.
1 parent a7a7f5c commit a734979

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/tsearch/ts_selfuncs.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/ts_selfuncs.c,v 1.2 2009/01/01 17:23:48 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/ts_selfuncs.c,v 1.3 2009/06/03 18:42:13 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -146,19 +146,23 @@ static Selectivity
146146
tsquerysel(VariableStatData *vardata, Datum constval)
147147
{
148148
Selectivity selec;
149+
TSQuery query;
150+
151+
/* The caller made sure the const is a TSQuery, so get it now */
152+
query = DatumGetTSQuery(constval);
153+
154+
/* Empty query matches nothing */
155+
if (query->size == 0)
156+
return (Selectivity) 0.0;
149157

150158
if (HeapTupleIsValid(vardata->statsTuple))
151159
{
152-
TSQuery query;
153160
Form_pg_statistic stats;
154161
Datum *values;
155162
int nvalues;
156163
float4 *numbers;
157164
int nnumbers;
158165

159-
/* The caller made sure the const is a TSQuery, so get it now */
160-
query = DatumGetTSQuery(constval);
161-
162166
stats = (Form_pg_statistic) GETSTRUCT(vardata->statsTuple);
163167

164168
/* MCELEM will be an array of TEXT elements for a tsvector column */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy