diff options
author | Michael Paquier | 2012-05-09 07:19:01 +0000 |
---|---|---|
committer | Michael Paquier | 2012-05-09 07:22:24 +0000 |
commit | 0f8478de35f787e224ee9c572e712cb849c2d664 (patch) | |
tree | 4784ae7a3bc429dcd8cedc39ec931a15708282e8 | |
parent | 0278e7f0bb730697d5eefcbc2c8658c411ff2cff (diff) |
Block the use of system columns as MODULO/HASH columns
Those system columns are only used by local nodes, so it doesn't
make sense to use them as distribution key. This fix avoids a crash
that curiously only appeared when a CREATE TABLE using a system
column as distribution key was launched manually via psql, even if
a test is present in regressions.
Per report of Sutou Takayuki
-rw-r--r-- | src/backend/catalog/heap.c | 14 | ||||
-rw-r--r-- | src/test/regress/expected/xc_misc.out | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 67a8fcb8a9..4afe2f3523 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -995,9 +995,12 @@ AddRelationDistribution(Oid relid, switch (distributeby->disttype) { case DISTTYPE_HASH: - /* User specified hash column, validate */ + /* + * Validate user-specified hash column. + * System columns cannot be used. + */ attnum = get_attnum(relid, distributeby->colname); - if (!attnum) + if (attnum <= 0 && attnum >= -(int) lengthof(SysAtt)) { ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION), @@ -1015,9 +1018,12 @@ AddRelationDistribution(Oid relid, break; case DISTTYPE_MODULO: - /* User specified modulo column, validate */ + /* + * Validate user specified modulo column. + * System columns cannot be used. + */ attnum = get_attnum(relid, distributeby->colname); - if (!attnum) + if (attnum <= 0 && attnum >= -(int) lengthof(SysAtt)) { ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION), diff --git a/src/test/regress/expected/xc_misc.out b/src/test/regress/expected/xc_misc.out index 4d5ccd30dc..b6af82aa2f 100644 --- a/src/test/regress/expected/xc_misc.out +++ b/src/test/regress/expected/xc_misc.out @@ -99,7 +99,7 @@ select get_unified_node_name(xc_node_id),* from t1 order by xc_node_id; create table t2(a int , xc_node_id int) distribute by modulo(a); ERROR: column name "xc_node_id" conflicts with a system column name create table t2(a int , b int) distribute by modulo(xc_node_id); -ERROR: Column xc_node_id is not modulo distributable data type +ERROR: Invalid distribution column specified drop table t1; -- Test an SQL function with multiple statements in it including a utility statement. create table my_tab1 (a int); |