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

Commitfea81ae

Browse files
committed
Avoid assertion failure if a setop leaf query contains setops.
Ordinarily transformSetOperationTree will collect all UNION/INTERSECT/EXCEPT steps into the setOperations tree of the topmostQuery, so that leaf queries do not contain any setOperations.However, it cannot thus flatten a subquery that also containsWITH, ORDER BY, FOR UPDATE, or LIMIT. I (tgl) forgot that incommit07b4c48 and wrote an assertion in rule deparsing thata leaf's setOperations would always be empty.If it were nonempty then we would want to parenthesize the subqueryto ensure that the output represents the setop nesting correctly(e.g. UNION below INTERSECT had better get parenthesized). Sorather than just removing the faulty Assert, let's change it intoan additional case to check to decide whether to add parens. Wedon't expect that the additional case will ever fire, but it'scheap insurance.Man Zeng and Tom LaneDiscussion:https://postgr.es/m/tencent_7ABF9B1F23B0C77606FC5FE3@qq.com
1 parent6fc3c58 commitfea81ae

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6169,13 +6169,19 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context)
61696169
Query*subquery=rte->subquery;
61706170

61716171
Assert(subquery!=NULL);
6172-
Assert(subquery->setOperations==NULL);
6173-
/* Need parens if WITH, ORDER BY, FOR UPDATE, or LIMIT; see gram.y */
6172+
6173+
/*
6174+
* We need parens if WITH, ORDER BY, FOR UPDATE, or LIMIT; see gram.y.
6175+
* Also add parens if the leaf query contains its own set operations.
6176+
* (That shouldn't happen unless one of the other clauses is also
6177+
* present, see transformSetOperationTree; but let's be safe.)
6178+
*/
61746179
need_paren= (subquery->cteList||
61756180
subquery->sortClause||
61766181
subquery->rowMarks||
61776182
subquery->limitOffset||
6178-
subquery->limitCount);
6183+
subquery->limitCount||
6184+
subquery->setOperations);
61796185
if (need_paren)
61806186
appendStringInfoChar(buf,'(');
61816187
get_query_def(subquery,buf,context->namespaces,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp