Skip to content

Commit 8821cae

Browse files
author
Artur Zakirov
committed
Check additional information attribute in index.
We perform this check during rumbuild() and ruminsert(). We can't do it during index creation because of we don't know which attribute should store additional information.
1 parent 8427ad0 commit 8821cae

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

expected/rum.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ 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);
77
\copy test_rum(t) from 'data/rum.data';
8+
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_timestamp_ops);
9+
ERROR: additional information attribute "a" is not found in index
810
SET enable_seqscan=off;
911
explain (costs off)
1012
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');

rum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumKey * item,
870870
{
871871
attr = rumstate->addAttrs[attnum - 1];
872872

873+
Assert(attr);
874+
873875
if (attr->attbyval)
874876
{
875877
/* do not use aligment for pass-by-value types */
@@ -949,6 +951,8 @@ rumDataPageLeafReadPointer(Pointer ptr, OffsetNumber attnum, RumKey * item,
949951
{
950952
attr = rumstate->addAttrs[attnum - 1];
951953

954+
Assert(attr);
955+
952956
if (!attr->attbyval)
953957
ptr = (Pointer) att_align_pointer(ptr, attr->attalign, attr->attlen,
954958
ptr);

rumdatapage.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ rumPlaceToDataPageLeaf(Pointer ptr, OffsetNumber attnum,
236236
if (!item->addInfoIsNull)
237237
{
238238
attr = rumstate->addAttrs[attnum - 1];
239+
Assert(attr);
240+
239241
ptr = rumDatumWrite(ptr, item->addInfo, attr->attbyval, attr->attalign,
240242
attr->attlen, attr->attstorage);
241243
}
@@ -293,6 +295,8 @@ rumCheckPlaceToDataPageLeaf(OffsetNumber attnum,
293295
if (!item->addInfoIsNull)
294296
{
295297
attr = rumstate->addAttrs[attnum - 1];
298+
Assert(attr);
299+
296300
size = rumComputeDatumSize(size, item->addInfo, attr->attbyval,
297301
attr->attalign, attr->attlen, attr->attstorage);
298302
}

rumfast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ processPendingPage(BuildAccumulator *accum, KeyArray *ka,
658658
if (OidIsValid(accum->rumstate->addInfoTypeOid[curattnum - 1]))
659659
{
660660
Form_pg_attribute attr = accum->rumstate->addAttrs[curattnum - 1];
661+
Assert(attr);
661662

662663
if (accum->rumstate->oneCol)
663664
addInfo = index_getattr(itup, 2,

ruminsert.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,13 @@ rumHeapTupleBulkInsert(RumBuildState * buildstate, OffsetNumber attnum,
511511
MemoryContextSwitchTo(oldCtx);
512512
for (i = 0; i < nentries; i++)
513513
{
514-
if (attr && !addInfoIsNull[i])
514+
if (!addInfoIsNull[i])
515515
{
516+
/* Check existance of additional information attribute in index */
517+
if (!attr)
518+
elog(ERROR, "additional information attribute \"%s\" is not found in index",
519+
NameStr(buildstate->rumstate.origTupdesc->attrs[attnum - 1]->attname));
520+
516521
addInfo[i] = datumCopy(addInfo[i], attr->attbyval, attr->attlen);
517522
}
518523
}
@@ -767,6 +772,11 @@ rumHeapTupleInsert(RumState * rumstate, OffsetNumber attnum,
767772
{
768773
RumKey insert_item;
769774

775+
/* Check existance of additional information attribute in index */
776+
if (!addInfoIsNull[i] && !rumstate->addAttrs[attnum - 1])
777+
elog(ERROR, "additional information attribute \"%s\" is not found in index",
778+
NameStr(rumstate->origTupdesc->attrs[attnum - 1]->attname));
779+
770780
insert_item.iptr = *item;
771781
insert_item.addInfo = addInfo[i];
772782
insert_item.addInfoIsNull = addInfoIsNull[i];

sql/rum.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
1010

1111
\copy test_rum(t) from 'data/rum.data';
1212

13+
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_timestamp_ops);
14+
1315
SET enable_seqscan=off;
1416

1517
explain (costs off)

0 commit comments

Comments
 (0)