From 47f2cb5c01c7b40a9c6cba57360ea5accea8bd78 Mon Sep 17 00:00:00 2001 From: zhouxiongjia <719216473@qq.com> Date: Thu, 3 Sep 2020 20:19:11 +0800 Subject: [PATCH] Ban ROWNUM when creating index. --- src/common/backend/parser/parse_utilcmd.cpp | 1 + src/test/regress/expected/create_index.out | 12 ++++++++++++ src/test/regress/sql/create_index.sql | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/common/backend/parser/parse_utilcmd.cpp b/src/common/backend/parser/parse_utilcmd.cpp index 1aaa60f6f..2040dbd18 100644 --- a/src/common/backend/parser/parse_utilcmd.cpp +++ b/src/common/backend/parser/parse_utilcmd.cpp @@ -3265,6 +3265,7 @@ IndexStmt* transformIndexStmt(Oid relid, IndexStmt* stmt, const char* queryStrin * consistency with what transformWhereClause() checks for the * predicate. DefineIndex() will make more checks. */ + ExcludeRownumExpr(pstate, (Node*)ielem->expr); if (expression_returns_set(ielem->expr)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("index expression cannot return a set"))); } diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index d9eb20283..cb594d0bf 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2721,6 +2721,18 @@ explain (costs off) select /*+ rows(t_rep_table #100000) */ * from t_hash_tabl Index Cond: (a = t_hash_table.a) (4 rows) +create index test0 on t_rep_table(rownum); +ERROR: specified ROWNUM is not allowed here. +LINE 1: create index test0 on t_rep_table(rownum); + ^ +create index test0 on t_rep_table(sin(a), sin(rownum)); +ERROR: specified ROWNUM is not allowed here. +LINE 1: create index test0 on t_rep_table(sin(a), sin(rownum)); + ^ +create index test0 on t_rep_table(sin(a), sin(rownum+1)); +ERROR: specified ROWNUM is not allowed here. +LINE 1: create index test0 on t_rep_table(sin(a), sin(rownum+1)); + ^ drop index idx_rep_table; drop table t_hash_table; drop table t_rep_table; diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index 690e47ce4..25c9bf2b5 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -956,6 +956,10 @@ create index idx_rep_table on t_rep_table(a); explain (costs off) select /*+ rows(t_rep_table #100000) */ * from t_hash_table where t_hash_table.a in (select a from t_rep_table); explain (costs off) select /*+ rows(t_rep_table #100000) */ * from t_hash_table where '1' = '0' or t_hash_table.a in (select a from t_rep_table); +create index test0 on t_rep_table(rownum); +create index test0 on t_rep_table(sin(a), sin(rownum)); +create index test0 on t_rep_table(sin(a), sin(rownum+1)); + drop index idx_rep_table; drop table t_hash_table; drop table t_rep_table;