Skip to content

Commit

Permalink
Checking ao table while looking for column to prevent finding invalid…
Browse files Browse the repository at this point in the history
… system columns

add check for ao table while looking for column

add tests

add comments
  • Loading branch information
kooooootb committed Mar 2, 2024
1 parent a599c44 commit 1a802a1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/backend/parser/parse_relation.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,20 @@ GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
return NULL; /* keep compiler quiet */
}

static bool
IsAppendOptimizedByOid(Oid relid)
{
Relation rel;
bool result;

rel = heap_open(relid, NoLock);

result = RelationIsAppendOptimized(rel);
heap_close(rel, NoLock);

return result;
}

/*
* scanRTEForColumn
* Search the column names of a single RTE for the given name.
Expand Down Expand Up @@ -603,6 +617,12 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname,
Gp_role != GP_ROLE_UTILITY)
return result;

/* In GPDB tables that have append-optimized storage system columns are not
* stored in tuples, so we check it here
*/
if (IsAppendOptimizedByOid(rte->relid))
return result;

/* quick check to see if name could be a system column */
attnum = specialAttNum(colname);

Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/input/appendonly.source
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,8 @@ insert into fix_ao_truncate_last_sequence select 1, 1 from generate_series(1, 5)
select count(*) from fix_ao_truncate_last_sequence;
abort;

-- Check if system columns in ao table can be selected
DROP TABLE IF EXISTS ttt_ao;
CREATE TABLE ttt (id int) WITH (appendonly=true) DISTRIBUTED BY (id);
INSERT INTO ttt VALUES(1);
SELECT xmin FROM ttt;
9 changes: 9 additions & 0 deletions src/test/regress/output/appendonly.source
Original file line number Diff line number Diff line change
Expand Up @@ -1706,3 +1706,12 @@ select count(*) from fix_ao_truncate_last_sequence;
(1 row)

abort;

-- Check if system columns in ao table can be selected
DROP TABLE IF EXISTS ttt_ao;
CREATE TABLE ttt (id int) WITH (appendonly=true) DISTRIBUTED BY (id);
INSERT INTO ttt VALUES(1);
SELECT xmin FROM ttt;
ERROR: column "xmin" does not exist
LINE 1: select xmin from ttt;
^

0 comments on commit 1a802a1

Please sign in to comment.