Skip to content

Commit 7280fab

Browse files
committed
Fix bug #4814 (wrong subscript in consistent-function call), and add some
minimal regression test coverage for matchPartialInPendingList().
1 parent 2c39ab1 commit 7280fab

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

src/backend/access/gin/ginget.c

Lines changed: 8 additions & 7 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.25 2009/04/05 11:32:01 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.26 2009/05/19 02:48:26 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -820,10 +820,11 @@ scanGetCandidate(IndexScanDesc scan, pendingPosition *pos)
820820
}
821821

822822
/*
823-
* Scan page from current tuple (off) up to the first event:
824-
* - tuple's attribute number is not equal to entry's attrnum
825-
* - reach of last tuple
823+
* Scan page from current tuple (off) up till the first of:
826824
* - match is found (then returns true)
825+
* - no later match is possible
826+
* - tuple's attribute number is not equal to entry's attrnum
827+
* - reach end of page
827828
*/
828829
static bool
829830
matchPartialInPendingList(GinState *ginstate, Page page,
@@ -849,13 +850,13 @@ matchPartialInPendingList(GinState *ginstate, Page page,
849850
}
850851

851852
/*----------
852-
* Check of partial match.
853+
* Check partial match.
853854
* case cmp == 0 => match
854-
* case cmp > 0 => not match and finish scan
855+
* case cmp > 0 => not match and end scan (no later match possible)
855856
* case cmp < 0 => not match and continue scan
856857
*----------
857858
*/
858-
cmp = DatumGetInt32(FunctionCall4(&ginstate->comparePartialFn[attrnum],
859+
cmp = DatumGetInt32(FunctionCall4(&ginstate->comparePartialFn[attrnum-1],
859860
value,
860861
datum[off-1],
861862
UInt16GetDatum(strategy),

src/test/regress/expected/tsearch.out

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ to_tsquery('english', 'sea&foo'), 'HighlightAll=true');
624624
<body>
625625
<b>Sea</b> view wow <u><b>foo</b> bar</u> <i>qq</i>
626626
<a href="http://www.google.com/foo.bar.html" target="_blank">YES &nbsp;</a>
627-
ff-bg
627+
ff-bg
628628
<script>
629629
document.write(15);
630630
</script>
@@ -1027,3 +1027,37 @@ SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
10271027
1
10281028
(1 row)
10291029

1030+
-- test finding items in GIN's pending list
1031+
create temp table pendtest (ts tsvector);
1032+
create index pendtest_idx on pendtest using gin(ts);
1033+
insert into pendtest values (to_tsvector('Lore ipsam'));
1034+
insert into pendtest values (to_tsvector('Lore ipsum'));
1035+
select * from pendtest where 'ipsu:*'::tsquery @@ ts;
1036+
ts
1037+
--------------------
1038+
'ipsum':2 'lore':1
1039+
(1 row)
1040+
1041+
select * from pendtest where 'ipsa:*'::tsquery @@ ts;
1042+
ts
1043+
--------------------
1044+
'ipsam':2 'lore':1
1045+
(1 row)
1046+
1047+
select * from pendtest where 'ips:*'::tsquery @@ ts;
1048+
ts
1049+
--------------------
1050+
'ipsam':2 'lore':1
1051+
'ipsum':2 'lore':1
1052+
(2 rows)
1053+
1054+
select * from pendtest where 'ipt:*'::tsquery @@ ts;
1055+
ts
1056+
----
1057+
(0 rows)
1058+
1059+
select * from pendtest where 'ipi:*'::tsquery @@ ts;
1060+
ts
1061+
----
1062+
(0 rows)
1063+

src/test/regress/sql/tsearch.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,14 @@ SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
361361
INSERT INTO test_tsvector (t) VALUES ('345 qwerty');
362362

363363
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
364+
365+
-- test finding items in GIN's pending list
366+
create temp table pendtest (ts tsvector);
367+
create index pendtest_idx on pendtest using gin(ts);
368+
insert into pendtest values (to_tsvector('Lore ipsam'));
369+
insert into pendtest values (to_tsvector('Lore ipsum'));
370+
select * from pendtest where 'ipsu:*'::tsquery @@ ts;
371+
select * from pendtest where 'ipsa:*'::tsquery @@ ts;
372+
select * from pendtest where 'ips:*'::tsquery @@ ts;
373+
select * from pendtest where 'ipt:*'::tsquery @@ ts;
374+
select * from pendtest where 'ipi:*'::tsquery @@ ts;

0 commit comments

Comments
 (0)