diff options
author | Tom Lane | 2009-06-03 18:42:13 +0000 |
---|---|---|
committer | Tom Lane | 2009-06-03 18:42:13 +0000 |
commit | e0e73d60a00f0d71d80349036f80da79b042a84b (patch) | |
tree | ed47cef3e4cd3cef285eb37df95b42849a284e95 | |
parent | 6fba39e7ab1392d4b2a992f183372e656b19dfe4 (diff) |
Fix tsquerysel() to not fail on an empty TSQuery. Per report from
Tatsuo Ishii.
-rw-r--r-- | src/backend/tsearch/ts_selfuncs.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/tsearch/ts_selfuncs.c b/src/backend/tsearch/ts_selfuncs.c index ddfdf38f45..8d8aab6f18 100644 --- a/src/backend/tsearch/ts_selfuncs.c +++ b/src/backend/tsearch/ts_selfuncs.c @@ -146,19 +146,23 @@ static Selectivity tsquerysel(VariableStatData *vardata, Datum constval) { Selectivity selec; + TSQuery query; + + /* The caller made sure the const is a TSQuery, so get it now */ + query = DatumGetTSQuery(constval); + + /* Empty query matches nothing */ + if (query->size == 0) + return (Selectivity) 0.0; if (HeapTupleIsValid(vardata->statsTuple)) { - TSQuery query; Form_pg_statistic stats; Datum *values; int nvalues; float4 *numbers; int nnumbers; - /* The caller made sure the const is a TSQuery, so get it now */ - query = DatumGetTSQuery(constval); - stats = (Form_pg_statistic) GETSTRUCT(vardata->statsTuple); /* MCELEM will be an array of TEXT elements for a tsvector column */ |