Reject SELECT ... GROUP BY GROUPING SETS (()) FOR UPDATE.
This case should be disallowed, just as FOR UPDATE with a plain GROUP BY is disallowed; FOR UPDATE only makes sense when each row of the query result can be identified with a single table row. However, we missed teaching CheckSelectLocking() to check groupingSets as well as groupClause, so that it would allow degenerate grouping sets. That resulted in a bad plan and a null-pointer dereference in the executor. Looking around for other instances of the same bug, the only one I found was in examine_simple_variable(). That'd just lead to silly estimates, but it should be fixed too. Per private report from Yaoguang Chen. Back-patch to all supported branches.
This commit is contained in:
parent
d250568121
commit
e5b0fffa17
@ -2688,7 +2688,7 @@ CheckSelectLocking(Query *qry, LockClauseStrength strength)
|
|||||||
translator: %s is a SQL row locking clause such as FOR UPDATE */
|
translator: %s is a SQL row locking clause such as FOR UPDATE */
|
||||||
errmsg("%s is not allowed with DISTINCT clause",
|
errmsg("%s is not allowed with DISTINCT clause",
|
||||||
LCS_asString(strength))));
|
LCS_asString(strength))));
|
||||||
if (qry->groupClause != NIL)
|
if (qry->groupClause != NIL || qry->groupingSets != NIL)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
/*------
|
/*------
|
||||||
|
@ -5150,7 +5150,8 @@ examine_simple_variable(PlannerInfo *root, Var *var,
|
|||||||
* of learning something even with it.
|
* of learning something even with it.
|
||||||
*/
|
*/
|
||||||
if (subquery->setOperations ||
|
if (subquery->setOperations ||
|
||||||
subquery->groupClause)
|
subquery->groupClause ||
|
||||||
|
subquery->groupingSets)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -50,6 +50,11 @@ select distinct on (foobar) * from pg_database;
|
|||||||
ERROR: column "foobar" does not exist
|
ERROR: column "foobar" does not exist
|
||||||
LINE 1: select distinct on (foobar) * from pg_database;
|
LINE 1: select distinct on (foobar) * from pg_database;
|
||||||
^
|
^
|
||||||
|
-- grouping with FOR UPDATE
|
||||||
|
select null from pg_database group by datname for update;
|
||||||
|
ERROR: FOR UPDATE is not allowed with GROUP BY clause
|
||||||
|
select null from pg_database group by grouping sets (()) for update;
|
||||||
|
ERROR: FOR UPDATE is not allowed with GROUP BY clause
|
||||||
--
|
--
|
||||||
-- DELETE
|
-- DELETE
|
||||||
-- missing relation name (this had better not wildcard!)
|
-- missing relation name (this had better not wildcard!)
|
||||||
|
@ -37,6 +37,10 @@ select * from pg_database where pg_database.datname = nonesuch;
|
|||||||
-- bad attribute name in select distinct on
|
-- bad attribute name in select distinct on
|
||||||
select distinct on (foobar) * from pg_database;
|
select distinct on (foobar) * from pg_database;
|
||||||
|
|
||||||
|
-- grouping with FOR UPDATE
|
||||||
|
select null from pg_database group by datname for update;
|
||||||
|
select null from pg_database group by grouping sets (()) for update;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- DELETE
|
-- DELETE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user