aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-06-01 11:12:56 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-06-01 11:12:56 -0400
commitdc272157a8aa1764aa92c013a2813d300f6ca32a (patch)
treea259fe7965c162b39a9a81c4d9c7412ceb8b345c /src/backend
parentfe194f731fbf6ea0d8c08bdd41edd0a2db52a643 (diff)
downloadpostgresql-dc272157a8aa1764aa92c013a2813d300f6ca32a.tar.gz
postgresql-dc272157a8aa1764aa92c013a2813d300f6ca32a.zip
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.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/parser/analyze.c2
-rw-r--r--src/backend/utils/adt/selfuncs.c3
2 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 5eb3ec3e205..f491d937397 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -2693,7 +2693,7 @@ CheckSelectLocking(Query *qry, LockClauseStrength strength)
translator: %s is a SQL row locking clause such as FOR UPDATE */
errmsg("%s is not allowed with DISTINCT clause",
LCS_asString(strength))));
- if (qry->groupClause != NIL)
+ if (qry->groupClause != NIL || qry->groupingSets != NIL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/*------
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 2240636e6c4..33d6ee714a8 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -5227,7 +5227,8 @@ examine_simple_variable(PlannerInfo *root, Var *var,
* of learning something even with it.
*/
if (subquery->setOperations ||
- subquery->groupClause)
+ subquery->groupClause ||
+ subquery->groupingSets)
return;
/*