Skip to content

Commit 97441e1

Browse files
committed
PGPRO-1572: Fix crash on empty table using index scan
1 parent d874e22 commit 97441e1

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

expected/rum.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ CREATE TRIGGER tsvectorupdate
44
BEFORE UPDATE OR INSERT ON test_rum
55
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
66
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
7+
-- Check empty table using index scan
8+
SELECT
9+
a <=> to_tsquery('pg_catalog.english', 'way & (go | half)'),
10+
rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')),
11+
*
12+
FROM test_rum
13+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)') limit 2;
14+
?column? | rum_ts_distance | t | a
15+
----------+-----------------+---+---
16+
(0 rows)
17+
18+
-- Fill the table with data
719
\copy test_rum(t) from 'data/rum.data';
820
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_addon_ops);
921
ERROR: additional information attribute "a" is not found in index

sql/rum.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ BEFORE UPDATE OR INSERT ON test_rum
77
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
88
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
99

10+
-- Check empty table using index scan
11+
SELECT
12+
a <=> to_tsquery('pg_catalog.english', 'way & (go | half)'),
13+
rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')),
14+
*
15+
FROM test_rum
16+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)') limit 2;
17+
18+
-- Fill the table with data
1019
\copy test_rum(t) from 'data/rum.data';
1120

1221
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_addon_ops);

src/rumget.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,17 @@ startScanEntry(RumState * rumstate, RumScanEntry entry, Snapshot snapshot)
609609
(entry->queryCategory == RUM_CAT_EMPTY_QUERY &&
610610
entry->scanWithAddInfo))
611611
{
612-
IndexTuple itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, stackEntry->off));
612+
IndexTuple itup;
613+
ItemId itemid = PageGetItemId(page, stackEntry->off);
614+
615+
/*
616+
* We don't want to crash if line pointer is not used.
617+
*/
618+
if (entry->queryCategory == RUM_CAT_EMPTY_QUERY &&
619+
!ItemIdHasStorage(itemid))
620+
goto endScanEntry;
621+
622+
itup = (IndexTuple) PageGetItem(page, itemid);
613623

614624
if (RumIsPostingTree(itup))
615625
{
@@ -689,6 +699,7 @@ startScanEntry(RumState * rumstate, RumScanEntry entry, Snapshot snapshot)
689699
SCAN_ENTRY_GET_KEY(entry, rumstate, itup);
690700
}
691701

702+
endScanEntry:
692703
if (needUnlock)
693704
LockBuffer(stackEntry->buffer, RUM_UNLOCK);
694705
if (entry->stack == NULL)
@@ -2043,8 +2054,12 @@ scanGetItemFull(IndexScanDesc scan, RumItem *advancePast,
20432054
*/
20442055
entry = so->entries[0];
20452056

2057+
if (entry->isFinished)
2058+
return false;
2059+
20462060
entryGetItem(&so->rumstate, entry, &nextEntryList, scan->xs_snapshot);
2047-
if (entry->isFinished == true)
2061+
2062+
if (entry->isFinished)
20482063
return false;
20492064

20502065
/* Fill outerAddInfo */

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