Ban ROWNUM when creating index.

This commit is contained in:
zhouxiongjia
2020-09-03 20:19:11 +08:00
parent 1f17263be3
commit 47f2cb5c01
3 changed files with 17 additions and 0 deletions

View File

@ -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")));
}

View File

@ -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;

View File

@ -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;