Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs
Date: 2025-10-02 20:32:18
Message-ID: CAApHDvpVYC43mi8atZ2Q39emK45xh7AaXetMJE9gJyV6sge_mg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 3 Oct 2025 at 04:18, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> 0001's change in is_dummy_rel() seems like a complete hack, especially
> since you didn't bother to change the adjacent comment. Why is that
> necessary?

build_setop_child_paths() wraps the child inputs in SubqueryScanPaths,
so we need to see through those.

An alternative way would be to propagate those during build_setop_child_paths()

--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -523,6 +523,13 @@ build_setop_child_paths(PlannerInfo *root, RelOptInfo *rel,
bool is_sorted;
int presorted_keys;

+ /* If the input rel is dummy, propagate that to this query level */
+ if (is_dummy_rel(final_rel))
+ {
+ mark_dummy_rel(rel);
+ continue;
+ }
+

As attached.

> v2 LGTM otherwise.

Thanks

David

Attachment Content-Type Size
v3-0001-Teach-UNION-planner-to-remove-dummy-inputs.patch application/octet-stream 6.7 KB
v3-0002-Teach-planner-to-short-circuit-EXCEPT-INTERSECT-w.patch application/octet-stream 7.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-10-02 20:42:43 Re: disallow big-endian on aarch64
Previous Message Tomas Vondra 2025-10-02 20:29:39 Re: disallow big-endian on aarch64