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

Commit592c88a

Browse files
committed
Remove the aggregate form of ts_rewrite(), since it doesn't work as desired
if there are zero rows to aggregate over, and the API seems both conceptuallyand notationally ugly anyway. We should look for something that improveson the tsquery-and-text-SELECT version (which is also pretty ugly but atleast it works...), but it seems that will take query infrastructure thatdoesn't exist today. (Hm, I wonder if there's anything in or near SQL2003window functions that would help?) Per discussion.
1 parent07d0a37 commit592c88a

File tree

8 files changed

+48
-214
lines changed

8 files changed

+48
-214
lines changed

‎doc/src/sgml/textsearch.sgml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/textsearch.sgml,v 1.24 2007/10/23 20:46:12 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/textsearch.sgml,v 1.25 2007/10/24 02:24:47 tgl Exp $ -->
22

33
<chapter id="textsearch">
44
<title id="textsearch-title">Full Text Search</title>
@@ -1456,33 +1456,6 @@ SELECT ts_rewrite('a &amp; b'::tsquery, 'a'::tsquery, 'c'::tsquery);
14561456
</listitem>
14571457
</varlistentry>
14581458

1459-
<varlistentry>
1460-
1461-
<term>
1462-
<synopsis>
1463-
ts_rewrite(ARRAY[<replaceable class="PARAMETER">query</replaceable> <type>tsquery</>, <replaceable class="PARAMETER">target</replaceable> <type>tsquery</>, <replaceable class="PARAMETER">substitute</replaceable> <type>tsquery</>]) returns <type>tsquery</>
1464-
</synopsis>
1465-
</term>
1466-
1467-
<listitem>
1468-
<para>
1469-
Aggregate form. XXX if we choose not to remove this, it needs to
1470-
be documented better. Note it is not listed in
1471-
textsearch-functions-table at the moment.
1472-
1473-
<programlisting>
1474-
CREATE TABLE aliases (t tsquery PRIMARY KEY, s tsquery);
1475-
INSERT INTO aliases VALUES('a', 'c');
1476-
1477-
SELECT ts_rewrite(ARRAY['a &amp; b'::tsquery, t,s]) FROM aliases;
1478-
ts_rewrite
1479-
------------
1480-
'b' &amp; 'c'
1481-
</programlisting>
1482-
</para>
1483-
</listitem>
1484-
</varlistentry>
1485-
14861459
<varlistentry>
14871460

14881461
<term>

‎src/backend/utils/adt/tsquery_rewrite.c

Lines changed: 3 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.5 2007/10/23 01:44:39 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.6 2007/10/24 02:24:47 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -250,135 +250,7 @@ findsubquery(QTNode *root, QTNode *ex, QTNode *subs, bool *isfind)
250250
}
251251

252252
Datum
253-
ts_rewrite_accum(PG_FUNCTION_ARGS)
254-
{
255-
TSQueryacc;
256-
ArrayType*qa;
257-
TSQueryq;
258-
QTNode*qex=NULL,
259-
*subs=NULL,
260-
*acctree=NULL;
261-
boolisfind= false;
262-
Datum*elemsp;
263-
intnelemsp;
264-
MemoryContextaggcontext;
265-
MemoryContextoldcontext;
266-
267-
aggcontext= ((AggState*)fcinfo->context)->aggcontext;
268-
269-
if (PG_ARGISNULL(0)||PG_GETARG_POINTER(0)==NULL)
270-
{
271-
acc= (TSQuery)MemoryContextAlloc(aggcontext,HDRSIZETQ);
272-
SET_VARSIZE(acc,HDRSIZETQ);
273-
acc->size=0;
274-
}
275-
else
276-
acc=PG_GETARG_TSQUERY(0);
277-
278-
if (PG_ARGISNULL(1)||PG_GETARG_POINTER(1)==NULL)
279-
PG_RETURN_TSQUERY(acc);
280-
else
281-
qa=PG_GETARG_ARRAYTYPE_P_COPY(1);
282-
283-
if (ARR_NDIM(qa)!=1)
284-
elog(ERROR,"array must be one-dimensional, not %d dimensions",
285-
ARR_NDIM(qa));
286-
if (ArrayGetNItems(ARR_NDIM(qa),ARR_DIMS(qa))!=3)
287-
elog(ERROR,"array must have three elements");
288-
if (ARR_ELEMTYPE(qa)!=TSQUERYOID)
289-
elog(ERROR,"array must contain tsquery elements");
290-
291-
deconstruct_array(qa,TSQUERYOID,-1, false,'i',&elemsp,NULL,&nelemsp);
292-
293-
q=DatumGetTSQuery(elemsp[0]);
294-
if (q->size==0)
295-
{
296-
pfree(elemsp);
297-
PG_RETURN_POINTER(acc);
298-
}
299-
300-
if (!acc->size)
301-
{
302-
if (VARSIZE(acc)>HDRSIZETQ)
303-
{
304-
pfree(elemsp);
305-
PG_RETURN_POINTER(acc);
306-
}
307-
else
308-
acctree=QT2QTN(GETQUERY(q),GETOPERAND(q));
309-
}
310-
else
311-
acctree=QT2QTN(GETQUERY(acc),GETOPERAND(acc));
312-
313-
QTNTernary(acctree);
314-
QTNSort(acctree);
315-
316-
q=DatumGetTSQuery(elemsp[1]);
317-
if (q->size==0)
318-
{
319-
pfree(elemsp);
320-
PG_RETURN_POINTER(acc);
321-
}
322-
qex=QT2QTN(GETQUERY(q),GETOPERAND(q));
323-
QTNTernary(qex);
324-
QTNSort(qex);
325-
326-
q=DatumGetTSQuery(elemsp[2]);
327-
if (q->size)
328-
subs=QT2QTN(GETQUERY(q),GETOPERAND(q));
329-
330-
acctree=findsubquery(acctree,qex,subs,&isfind);
331-
332-
if (isfind|| !acc->size)
333-
{
334-
/* pfree( acc ); do not pfree(p), because nodeAgg.c will */
335-
if (acctree)
336-
{
337-
QTNBinary(acctree);
338-
oldcontext=MemoryContextSwitchTo(aggcontext);
339-
acc=QTN2QT(acctree);
340-
MemoryContextSwitchTo(oldcontext);
341-
}
342-
else
343-
{
344-
acc= (TSQuery)MemoryContextAlloc(aggcontext,HDRSIZETQ);
345-
SET_VARSIZE(acc,HDRSIZETQ);
346-
acc->size=0;
347-
}
348-
}
349-
350-
pfree(elemsp);
351-
QTNFree(qex);
352-
QTNFree(subs);
353-
QTNFree(acctree);
354-
355-
PG_RETURN_TSQUERY(acc);
356-
}
357-
358-
Datum
359-
ts_rewrite_finish(PG_FUNCTION_ARGS)
360-
{
361-
TSQueryacc=PG_GETARG_TSQUERY(0);
362-
TSQueryrewrited;
363-
364-
if (acc==NULL||PG_ARGISNULL(0)||acc->size==0)
365-
{
366-
rewrited= (TSQuery)palloc(HDRSIZETQ);
367-
SET_VARSIZE(rewrited,HDRSIZETQ);
368-
rewrited->size=0;
369-
}
370-
else
371-
{
372-
rewrited= (TSQuery)palloc(VARSIZE(acc));
373-
memcpy(rewrited,acc,VARSIZE(acc));
374-
pfree(acc);
375-
}
376-
377-
PG_RETURN_POINTER(rewrited);
378-
}
379-
380-
Datum
381-
tsquery_rewrite(PG_FUNCTION_ARGS)
253+
tsquery_rewrite_query(PG_FUNCTION_ARGS)
382254
{
383255
TSQueryquery=PG_GETARG_TSQUERY_COPY(0);
384256
text*in=PG_GETARG_TEXT_P(1);
@@ -505,7 +377,7 @@ tsquery_rewrite(PG_FUNCTION_ARGS)
505377
}
506378

507379
Datum
508-
tsquery_rewrite_query(PG_FUNCTION_ARGS)
380+
tsquery_rewrite(PG_FUNCTION_ARGS)
509381
{
510382
TSQueryquery=PG_GETARG_TSQUERY_COPY(0);
511383
TSQueryex=PG_GETARG_TSQUERY(1);

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.436 2007/10/23 20:46:12 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.437 2007/10/24 02:24:47 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200710231
56+
#defineCATALOG_VERSION_NO200710232
5757

5858
#endif

‎src/include/catalog/pg_aggregate.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_aggregate.h,v 1.63 2007/08/21 01:11:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_aggregate.h,v 1.64 2007/10/24 02:24:47 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -226,9 +226,6 @@ DATA(insert ( 2243 bitor -01560_null_ ));
226226
/* xml */
227227
DATA(insert (2901xmlconcat2-0142_null_ ));
228228

229-
/* text search */
230-
DATA(insert (3688ts_rewrite_accumts_rewrite_finish03615_null_ ));
231-
232229
/*
233230
* prototypes for functions in pg_aggregate.c
234231
*/

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.476 2007/10/19 22:01:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.477 2007/10/24 02:24:47 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -4258,15 +4258,9 @@ DESCR("number of nodes");
42584258
DATA(insertOID=3673 (querytreePGNSPPGUID1210fftfi125"3615"_null__null__null_tsquerytree-_null__null_ ));
42594259
DESCR("show real useful query for GiST index");
42604260

4261-
DATA(insertOID=3684 (ts_rewritePGNSPPGUID1210fftfi33615"3615 3615 3615"_null__null__null_tsquery_rewrite_query-_null__null_ ));
4261+
DATA(insertOID=3684 (ts_rewritePGNSPPGUID1210fftfi33615"3615 3615 3615"_null__null__null_tsquery_rewrite-_null__null_ ));
42624262
DESCR("rewrite tsquery");
4263-
DATA(insertOID=3685 (ts_rewritePGNSPPGUID1210fftfv23615"3615 25"_null__null__null_tsquery_rewrite-_null__null_ ));
4264-
DESCR("rewrite tsquery");
4265-
DATA(insertOID=3686 (ts_rewrite_accumPGNSPPGUID1210ffffi23615"3615 3645"_null__null__null_ts_rewrite_accum-_null__null_ ));
4266-
DESCR("rewrite tsquery accumulator");
4267-
DATA(insertOID=3687 (ts_rewrite_finishPGNSPPGUID1210fftfi13615"3615"_null__null__null_ts_rewrite_finish-_null__null_ ));
4268-
DESCR("rewrite tsquery finish");
4269-
DATA(insertOID=3688 (ts_rewritePGNSPPGUID1210tfffi13615"3645"_null__null__null_aggregate_dummy-_null__null_ ));
4263+
DATA(insertOID=3685 (ts_rewritePGNSPPGUID1210fftfv23615"3615 25"_null__null__null_tsquery_rewrite_query-_null__null_ ));
42704264
DESCR("rewrite tsquery");
42714265

42724266
DATA(insertOID=3695 (gtsquery_compressPGNSPPGUID1210fftfi12281"2281"_null__null__null_gtsquery_compress-_null__null_ ));

‎src/include/tsearch/ts_type.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
77
*
8-
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.6 2007/09/11 16:01:40 teodor Exp $
8+
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.7 2007/10/24 02:24:49 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -285,8 +285,6 @@ extern Datum tsquery_not(PG_FUNCTION_ARGS);
285285

286286
externDatumtsquery_rewrite(PG_FUNCTION_ARGS);
287287
externDatumtsquery_rewrite_query(PG_FUNCTION_ARGS);
288-
externDatumts_rewrite_accum(PG_FUNCTION_ARGS);
289-
externDatumts_rewrite_finish(PG_FUNCTION_ARGS);
290288

291289
externDatumtsq_mcontains(PG_FUNCTION_ARGS);
292290
externDatumtsq_mcontained(PG_FUNCTION_ARGS);

‎src/test/regress/expected/tsearch.out

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -676,25 +676,25 @@ SELECT ts_rewrite('moscow & hotel', 'SELECT keyword, sample FROM test_tsquery'::
676676
'hotel' & ( 'moskva' | 'moscow' )
677677
(1 row)
678678

679-
SELECT ts_rewrite('bar &new & qq & foo & york', 'SELECT keyword, sample FROM test_tsquery'::text );
679+
SELECT ts_rewrite('bar & new & qq & foo & york', 'SELECT keyword, sample FROM test_tsquery'::text );
680680
ts_rewrite
681681
-------------------------------------------------------------------------------------
682682
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
683683
(1 row)
684684

685-
SELECT ts_rewrite(ARRAY['moscow', keyword, sample] )FROM test_tsquery;
685+
SELECT ts_rewrite( 'moscow','SELECTkeyword, sampleFROM test_tsquery');
686686
ts_rewrite
687687
---------------------
688688
'moskva' | 'moscow'
689689
(1 row)
690690

691-
SELECT ts_rewrite(ARRAY['moscow & hotel', keyword, sample] )FROM test_tsquery;
691+
SELECT ts_rewrite( 'moscow & hotel','SELECTkeyword, sampleFROM test_tsquery');
692692
ts_rewrite
693693
-----------------------------------
694-
( 'moskva' | 'moscow' ) & 'hotel'
694+
'hotel' &( 'moskva' | 'moscow' )
695695
(1 row)
696696

697-
SELECT ts_rewrite(ARRAY['bar &new & qq & foo & york', keyword, sample] )FROM test_tsquery;
697+
SELECT ts_rewrite( 'bar & new & qq & foo & york','SELECTkeyword, sampleFROM test_tsquery');
698698
ts_rewrite
699699
-------------------------------------------------------------------------------------
700700
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
@@ -723,37 +723,37 @@ SELECT keyword FROM test_tsquery WHERE keyword <@ 'moscow';
723723
'moscow'
724724
(1 row)
725725

726-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow') AS query WHERE keyword <@ query;
726+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow') AS query;
727727
ts_rewrite
728728
---------------------
729729
'moskva' | 'moscow'
730730
(1 row)
731731

732-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow & hotel') AS query WHERE keyword <@ query;
732+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow & hotel') AS query;
733733
ts_rewrite
734734
-----------------------------------
735-
( 'moskva' | 'moscow' ) & 'hotel'
735+
'hotel' &( 'moskva' | 'moscow' )
736736
(1 row)
737737

738-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'bar & new & qq & foo & york') AS query WHERE keyword <@ query;
738+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'bar & new & qq & foo & york') AS query;
739739
ts_rewrite
740740
-------------------------------------------------------------------------------------
741741
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
742742
(1 row)
743743

744-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow') AS query WHERE query @> keyword;
744+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow') AS query;
745745
ts_rewrite
746746
---------------------
747747
'moskva' | 'moscow'
748748
(1 row)
749749

750-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow & hotel') AS query WHERE query @> keyword;
750+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow & hotel') AS query;
751751
ts_rewrite
752752
-----------------------------------
753-
( 'moskva' | 'moscow' ) & 'hotel'
753+
'hotel' &( 'moskva' | 'moscow' )
754754
(1 row)
755755

756-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'bar &new & qq & foo & york') AS query WHERE query @> keyword;
756+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'bar & new & qq & foo & york') AS query;
757757
ts_rewrite
758758
-------------------------------------------------------------------------------------
759759
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
@@ -784,37 +784,37 @@ SELECT keyword FROM test_tsquery WHERE keyword <@ 'moscow';
784784
'moscow'
785785
(1 row)
786786

787-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow') AS query WHERE keyword <@ query;
787+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow') AS query;
788788
ts_rewrite
789789
---------------------
790790
'moskva' | 'moscow'
791791
(1 row)
792792

793-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow & hotel') AS query WHERE keyword <@ query;
793+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow & hotel') AS query;
794794
ts_rewrite
795795
-----------------------------------
796-
( 'moskva' | 'moscow' ) & 'hotel'
796+
'hotel' &( 'moskva' | 'moscow' )
797797
(1 row)
798798

799-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'bar &new & qq & foo & york') AS query WHERE keyword <@ query;
799+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'bar & new & qq & foo & york') AS query;
800800
ts_rewrite
801801
-------------------------------------------------------------------------------------
802802
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
803803
(1 row)
804804

805-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow') AS query WHERE query @> keyword;
805+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow') AS query;
806806
ts_rewrite
807807
---------------------
808808
'moskva' | 'moscow'
809809
(1 row)
810810

811-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'moscow & hotel') AS query WHERE query @> keyword;
811+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'moscow & hotel') AS query;
812812
ts_rewrite
813813
-----------------------------------
814-
( 'moskva' | 'moscow' ) & 'hotel'
814+
'hotel' &( 'moskva' | 'moscow' )
815815
(1 row)
816816

817-
SELECT ts_rewrite(ARRAY[query, keyword, sample] )FROM test_tsquery,to_tsquery('english', 'bar & new & qq & foo & york') AS query WHERE query @> keyword;
817+
SELECT ts_rewrite( query,'SELECTkeyword, sampleFROM test_tsquery' ) FROMto_tsquery('english', 'bar & new & qq & foo & york') AS query;
818818
ts_rewrite
819819
-------------------------------------------------------------------------------------
820820
'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp