Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5477da5

Browse files
committed
Merge commit '8322d6c44e528c25796d13c4eb4d0323c5541b75' into PGPROEE10
2 parents cafb8fd + 8322d6c commit 5477da5

File tree

9 files changed

+134
-40
lines changed

9 files changed

+134
-40
lines changed

contrib/rum/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

contrib/rum/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);

contrib/rum/src/rum.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,6 @@ extern Datum FunctionCall10Coll(FmgrInfo *flinfo, Oid collation,
10611061
#if PG_VERSION_NUM >= 110000
10621062
#define RumContextCreate(parent, name) \
10631063
AllocSetContextCreateExtended(parent, name, \
1064-
MEMCONTEXT_COPY_NAME, \
10651064
ALLOCSET_DEFAULT_MINSIZE, \
10661065
ALLOCSET_DEFAULT_INITSIZE, \
10671066
ALLOCSET_DEFAULT_MAXSIZE)

contrib/rum/src/rum_arr_utils.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ typedef struct SimpleArray
102102
} SimpleArray;
103103

104104

105+
#if PG_VERSION_NUM < 110000
106+
#define SearchSysCacheList(A, B, C, D, E) \
107+
SearchSysCacheList(A, B, C, D, E, 0)
108+
#endif
109+
110+
105111
float8 RumArraySimilarityThreshold = RUM_SIMILARITY_THRESHOLD_DEFAULT;
106112
int RumArraySimilarityFunction = RUM_SIMILARITY_FUNCTION_DEFAULT;
107113

@@ -563,7 +569,7 @@ getAMProc(Oid amOid, Oid typid)
563569
*/
564570
catlist = SearchSysCacheList(CASTSOURCETARGET, 1,
565571
ObjectIdGetDatum(typid),
566-
0, 0, 0);
572+
0, 0);
567573
for (i = 0; i < catlist->n_members; i++)
568574
{
569575
HeapTuple tuple = &catlist->members[i]->tuple;

contrib/rum/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 */

contrib/rum/src/ruminsert.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ typedef struct
3232
BuildAccumulator accum;
3333
} RumBuildState;
3434

35+
#if PG_VERSION_NUM >= 110000
36+
#define IndexBuildHeapScan(A, B, C, D, E, F) \
37+
IndexBuildHeapScan(A, B, C, D, E, F, NULL)
38+
#endif
39+
3540
/*
3641
* Creates new posting tree with one page, containing the given TIDs.
3742
* Returns the page number (which will be the root of this posting tree).
@@ -196,6 +201,8 @@ RumFormTuple(RumState * rumstate,
196201
{
197202
itup = repalloc(itup, newsize);
198203

204+
memset((char *) itup + IndexTupleSize(itup),
205+
0, newsize - IndexTupleSize(itup));
199206
/* set new size in tuple header */
200207
itup->t_info &= ~INDEX_SIZE_MASK;
201208
itup->t_info |= newsize;

contrib/rum/src/rumsort.c

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ bool optimize_bounded_sort = true;
162162
#define LogicalTapeRewindForWrite(x, y) LogicalTapeRewind((x), (y), true)
163163
#endif
164164

165+
#if PG_VERSION_NUM >= 110000
166+
#define RUM_SORT_START(INT1, INT2, INT3, INT4, INT5) \
167+
TRACE_POSTGRESQL_SORT_START(INT1, INT2, INT3, INT4, INT5, false)
168+
#else
169+
#define RUM_SORT_START(INT1, INT2, INT3, INT4, INT5) \
170+
TRACE_POSTGRESQL_SORT_START(INT1, INT2, INT3, INT4, INT5)
171+
#endif
172+
173+
#if PG_VERSION_NUM >= 110000
174+
#define LogicalTapeSetCreate(X) LogicalTapeSetCreate(X, NULL, NULL, 1)
175+
#define LogicalTapeFreeze(X, Y) LogicalTapeFreeze(X, Y, NULL)
176+
#endif
177+
165178
/*
166179
* The objects we actually sort are SortTuple structs. These contain
167180
* a pointer to the tuple proper (might be a MinimalTuple or IndexTuple),
@@ -963,11 +976,11 @@ rum_tuplesort_begin_heap(TupleDesc tupDesc,
963976

964977
state->nKeys = nkeys;
965978

966-
TRACE_POSTGRESQL_SORT_START(HEAP_SORT,
967-
false, /* no unique check */
968-
nkeys,
969-
workMem,
970-
randomAccess);
979+
RUM_SORT_START(HEAP_SORT,
980+
false, /* no unique check */
981+
nkeys,
982+
workMem,
983+
randomAccess);
971984

972985
state->comparetup = comparetup_heap;
973986
state->copytup = copytup_heap;
@@ -1025,11 +1038,11 @@ rum_tuplesort_begin_cluster(TupleDesc tupDesc,
10251038

10261039
state->nKeys = RelationGetNumberOfAttributes(indexRel);
10271040

1028-
TRACE_POSTGRESQL_SORT_START(CLUSTER_SORT,
1029-
false, /* no unique check */
1030-
state->nKeys,
1031-
workMem,
1032-
randomAccess);
1041+
RUM_SORT_START(CLUSTER_SORT,
1042+
false, /* no unique check */
1043+
state->nKeys,
1044+
workMem,
1045+
randomAccess);
10331046

10341047
state->comparetup = comparetup_cluster;
10351048
state->copytup = copytup_cluster;
@@ -1085,11 +1098,11 @@ rum_tuplesort_begin_index_btree(Relation heapRel,
10851098

10861099
state->nKeys = RelationGetNumberOfAttributes(indexRel);
10871100

1088-
TRACE_POSTGRESQL_SORT_START(INDEX_SORT,
1089-
enforceUnique,
1090-
state->nKeys,
1091-
workMem,
1092-
randomAccess);
1101+
RUM_SORT_START(INDEX_SORT,
1102+
enforceUnique,
1103+
state->nKeys,
1104+
workMem,
1105+
randomAccess);
10931106

10941107
state->comparetup = comparetup_index_btree;
10951108
state->copytup = copytup_index;
@@ -1162,11 +1175,11 @@ rum_tuplesort_begin_rum(int workMem, int nKeys, bool randomAccess,
11621175

11631176
state->nKeys = nKeys;
11641177

1165-
TRACE_POSTGRESQL_SORT_START(INDEX_SORT,
1166-
false, /* no unique check */
1167-
state->nKeys,
1168-
workMem,
1169-
randomAccess);
1178+
RUM_SORT_START(INDEX_SORT,
1179+
false, /* no unique check */
1180+
state->nKeys,
1181+
workMem,
1182+
randomAccess);
11701183

11711184
state->comparetup = comparetup_rum;
11721185
state->copytup = copytup_rum;
@@ -1195,11 +1208,11 @@ rum_tuplesort_begin_rumitem(int workMem, FmgrInfo *cmp)
11951208
"begin rumitem sort: workMem = %d", workMem);
11961209
#endif
11971210

1198-
TRACE_POSTGRESQL_SORT_START(INDEX_SORT,
1199-
false, /* no unique check */
1200-
2,
1201-
workMem,
1202-
false);
1211+
RUM_SORT_START(INDEX_SORT,
1212+
false, /* no unique check */
1213+
2,
1214+
workMem,
1215+
false);
12031216

12041217
state->cmp = cmp;
12051218
state->comparetup = comparetup_rumitem;
@@ -1236,11 +1249,11 @@ rum_tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation,
12361249

12371250
state->nKeys = 1; /* always a one-column sort */
12381251

1239-
TRACE_POSTGRESQL_SORT_START(DATUM_SORT,
1240-
false, /* no unique check */
1241-
1,
1242-
workMem,
1243-
randomAccess);
1252+
RUM_SORT_START(DATUM_SORT,
1253+
false, /* no unique check */
1254+
1,
1255+
workMem,
1256+
randomAccess);
12441257

12451258
state->comparetup = comparetup_datum;
12461259
state->copytup = copytup_datum;
@@ -3430,7 +3443,11 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
34303443
int32 compare;
34313444

34323445
/* Compare the leading sort key, if it's simple */
3446+
#if PG_VERSION_NUM >= 110000
3447+
if (state->indexInfo->ii_IndexAttrNumbers[0] != 0)
3448+
#else
34333449
if (state->indexInfo->ii_KeyAttrNumbers[0] != 0)
3450+
#endif
34343451
{
34353452
compare = inlineApplySortFunction(&scanKey->sk_func, scanKey->sk_flags,
34363453
scanKey->sk_collation,
@@ -3459,7 +3476,11 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
34593476

34603477
for (; nkey < state->nKeys; nkey++, scanKey++)
34613478
{
3479+
#if PG_VERSION_NUM >= 110000
3480+
AttrNumber attno = state->indexInfo->ii_IndexAttrNumbers[nkey];
3481+
#else
34623482
AttrNumber attno = state->indexInfo->ii_KeyAttrNumbers[nkey];
3483+
#endif
34633484
Datum datum1,
34643485
datum2;
34653486
bool isnull1,
@@ -3525,15 +3546,20 @@ static void
35253546
copytup_cluster(RumTuplesortstate *state, SortTuple *stup, void *tup)
35263547
{
35273548
HeapTuple tuple = (HeapTuple) tup;
3549+
#if PG_VERSION_NUM >= 110000
3550+
AttrNumber attno = state->indexInfo->ii_IndexAttrNumbers[0];
3551+
#else
3552+
AttrNumber attno = state->indexInfo->ii_KeyAttrNumbers[0];
3553+
#endif
35283554

35293555
/* copy the tuple into sort storage */
35303556
tuple = heap_copytuple(tuple);
35313557
stup->tuple = (void *) tuple;
35323558
USEMEM(state, GetMemoryChunkSpace(tuple));
35333559
/* set up first-column key value, if it's a simple column */
3534-
if (state->indexInfo->ii_KeyAttrNumbers[0] != 0)
3560+
if (attno != 0)
35353561
stup->datum1 = heap_getattr(tuple,
3536-
state->indexInfo->ii_KeyAttrNumbers[0],
3562+
attno,
35373563
state->tupDesc,
35383564
&stup->isnull1);
35393565
}
@@ -3565,6 +3591,11 @@ readtup_cluster(RumTuplesortstate *state, SortTuple *stup,
35653591
{
35663592
unsigned int t_len = tuplen - sizeof(ItemPointerData) - sizeof(int);
35673593
HeapTuple tuple = (HeapTuple) palloc(t_len + HEAPTUPLESIZE);
3594+
#if PG_VERSION_NUM >= 110000
3595+
AttrNumber attno = state->indexInfo->ii_IndexAttrNumbers[0];
3596+
#else
3597+
AttrNumber attno = state->indexInfo->ii_KeyAttrNumbers[0];
3598+
#endif
35683599

35693600
USEMEM(state, GetMemoryChunkSpace(tuple));
35703601
/* Reconstruct the HeapTupleData header */
@@ -3582,9 +3613,9 @@ readtup_cluster(RumTuplesortstate *state, SortTuple *stup,
35823613
&tuplen, sizeof(tuplen));
35833614
stup->tuple = (void *) tuple;
35843615
/* set up first-column key value, if it's a simple column */
3585-
if (state->indexInfo->ii_KeyAttrNumbers[0] != 0)
3616+
if (attno != 0)
35863617
stup->datum1 = heap_getattr(tuple,
3587-
state->indexInfo->ii_KeyAttrNumbers[0],
3618+
attno,
35883619
state->tupDesc,
35893620
&stup->isnull1);
35903621
}

contrib/rum/src/rumvacuum.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ RumFormTuple(RumState * rumstate,
182182
{
183183
itup = repalloc(itup, newsize);
184184

185+
memset((char *) itup + IndexTupleSize(itup),
186+
0, newsize - IndexTupleSize(itup));
185187
/* set new size in tuple header */
186188
itup->t_info &= ~INDEX_SIZE_MASK;
187189
itup->t_info |= newsize;

contrib/rum/t/001_wal.pl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ sub test_index_replay
1313
{
1414
my ($test_name) = @_;
1515

16+
# Check server version
17+
my $server_version = $node_master->safe_psql("postgres", "SELECT current_setting('server_version_num');") + 0;
18+
1619
# Wait for standby to catch up
1720
my $applname = $node_standby->name;
18-
my $caughtup_query =
19-
"SELECT pg_current_wal_lsn() <= write_lsn FROM pg_stat_replication WHERE application_name = '$applname';";
21+
my $caughtup_query;
22+
23+
if ($server_version < 100000)
24+
{
25+
$caughtup_query =
26+
"SELECT pg_current_xlog_location() <= write_location FROM pg_stat_replication WHERE application_name = '$applname';";
27+
}
28+
else
29+
{
30+
$caughtup_query =
31+
"SELECT pg_current_wal_lsn() <= write_lsn FROM pg_stat_replication WHERE application_name = '$applname';";
32+
}
2033
$node_master->poll_query_until('postgres', $caughtup_query)
2134
or die "Timed out while waiting for standby 1 to catch up";
2235

0 commit comments

Comments
 (0)