Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1103033

Browse files
committed
Reject SELECT ... GROUP BY GROUPING SETS (()) FOR UPDATE.
This case should be disallowed, just as FOR UPDATE with a plainGROUP BY is disallowed; FOR UPDATE only makes sense when each rowof the query result can be identified with a single table row.However, we missed teaching CheckSelectLocking() to checkgroupingSets as well as groupClause, so that it would allowdegenerate grouping sets. That resulted in a bad plan anda null-pointer dereference in the executor.Looking around for other instances of the same bug, the only oneI found was in examine_simple_variable(). That'd just lead tosilly estimates, but it should be fixed too.Per private report from Yaoguang Chen.Back-patch to all supported branches.
1 parenteb89cb4 commit1103033

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

‎src/backend/parser/analyze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ CheckSelectLocking(Query *qry, LockClauseStrength strength)
30193019
translator: %s is a SQL row locking clause such as FOR UPDATE */
30203020
errmsg("%s is not allowed with DISTINCT clause",
30213021
LCS_asString(strength))));
3022-
if (qry->groupClause!=NIL)
3022+
if (qry->groupClause!=NIL||qry->groupingSets!=NIL)
30233023
ereport(ERROR,
30243024
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
30253025
/*------

‎src/backend/utils/adt/selfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5497,7 +5497,8 @@ examine_simple_variable(PlannerInfo *root, Var *var,
54975497
* of learning something even with it.
54985498
*/
54995499
if (subquery->setOperations||
5500-
subquery->groupClause)
5500+
subquery->groupClause||
5501+
subquery->groupingSets)
55015502
return;
55025503

55035504
/*

‎src/test/regress/expected/errors.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ select distinct on (foobar) * from pg_database;
5050
ERROR: column "foobar" does not exist
5151
LINE 1: select distinct on (foobar) * from pg_database;
5252
^
53+
-- grouping with FOR UPDATE
54+
select null from pg_database group by datname for update;
55+
ERROR: FOR UPDATE is not allowed with GROUP BY clause
56+
select null from pg_database group by grouping sets (()) for update;
57+
ERROR: FOR UPDATE is not allowed with GROUP BY clause
5358
--
5459
-- DELETE
5560
-- missing relation name (this had better not wildcard!)

‎src/test/regress/sql/errors.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ select * from pg_database where pg_database.datname = nonesuch;
3737
-- bad attribute name in select distinct on
3838
select distincton (foobar)*from pg_database;
3939

40+
-- grouping with FOR UPDATE
41+
selectnullfrom pg_databasegroup by datname forupdate;
42+
selectnullfrom pg_databasegroup by grouping sets (()) forupdate;
43+
4044

4145
--
4246
-- DELETE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp