pgsql: Avoid assertion failure if a setop leaf query contains setops.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid assertion failure if a setop leaf query contains setops.
Date: 2024-11-20 17:04:01
Message-ID: E1tDo7V-002kHe-HW@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 topmost
Query, so that leaf queries do not contain any setOperations.
However, it cannot thus flatten a subquery that also contains
WITH, ORDER BY, FOR UPDATE, or LIMIT. I (tgl) forgot that in
commit 07b4c48b6 and wrote an assertion in rule deparsing that
a leaf's setOperations would always be empty.

If it were nonempty then we would want to parenthesize the subquery
to ensure that the output represents the setop nesting correctly
(e.g. UNION below INTERSECT had better get parenthesized). So
rather than just removing the faulty Assert, let's change it into
an additional case to check to decide whether to add parens. We
don't expect that the additional case will ever fire, but it's
cheap insurance.

Man Zeng and Tom Lane

Discussion: https://postgr.es/m/tencent_7ABF9B1F23B0C77606FC5FE3@qq.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/94131cd53c1552efe85c3e8120356c22cd658163

Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2024-11-20 18:37:29 pgsql: Refine nbtree = redundancy preprocessing comment.
Previous Message Fujii Masao 2024-11-20 14:54:51 pgsql: file_fdw: Add REJECT_LIMIT option to file_fdw.