postgresql/src/include/nodes
Tom Lane 2762792952 Convert SetOp to read its inputs as outerPlan and innerPlan.
The original design for set operations involved appending the two
input relations into one and adding a flag column that allows
distinguishing which side each row came from.  Then the SetOp node
pries them apart again based on the flag.  This is bizarre.  The
only apparent reason to do it is that when sorting, we'd only need
one Sort node not two.  But since sorting is at least O(N log N),
sorting all the data is actually worse than sorting each side
separately --- plus, we have no chance of taking advantage of
presorted input.  On top of that, adding the flag column frequently
requires an additional projection step that adds cycles, and then
the Append node isn't free either.  Let's get rid of all of that
and make the SetOp node have two separate children, using the
existing outerPlan/innerPlan infrastructure.

This initial patch re-implements nodeSetop.c and does a bare minimum
of work on the planner side to generate correctly-shaped plans.
In particular, I've tried not to change the cost estimates here,
so that the visible changes in the regression test results will only
involve removal of useless projection steps and not any changes in
whether to use sorted vs hashed mode.

For SORTED mode, we combine successive identical tuples from each
input into groups, and then merge-join the groups.  The tuple
comparisons now use SortSupport instead of simple equality, but
the group-formation part should involve roughly the same number of
tuple comparisons as before.  The cross-comparisons between left and
right groups probably add to that, but I'm not sure to quantify how
many more comparisons we might need.

For HASHED mode, nodeSetop's logic is almost the same as before,
just refactored into two separate loops instead of one loop that
has an assumption that it will see all the left-hand inputs first.

In both modes, I added early-exit logic to not bother reading the
right-hand relation if the left-hand input is empty, since neither
INTERSECT nor EXCEPT modes can produce any output if the left input
is empty.  This could have been done before in the hashed mode, but
not in sorted mode.  Sorted mode can also stop as soon as it exhausts
the left input; any remaining right-hand tuples cannot have matches.

Also, this patch adds some infrastructure for detecting whether
child plan nodes all output the same type of tuple table slot.
If they do, the hash table logic can use slightly more efficient
code based on assuming that that's the input slot type it will see.
We'll make use of that infrastructure in other plan node types later.

Patch by me; thanks to Richard Guo and David Rowley for review.

Discussion: https://postgr.es/m/1850138.1731549611@sss.pgh.pa.us
2024-12-19 16:23:45 -05:00
..
.gitignore Automatically generate node support functions 2022-07-09 08:53:59 +02:00
bitmapset.h Move some bitmap logic out of bitmapset.c 2024-03-06 14:30:16 +07:00
execnodes.h Convert SetOp to read its inputs as outerPlan and innerPlan. 2024-12-19 16:23:45 -05:00
extensible.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
lockoptions.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
makefuncs.h Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
memnodes.h Add path column to pg_backend_memory_contexts view 2024-07-25 15:03:28 +12:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
miscnodes.h Improve ThrowErrorData() comments for use with soft errors. 2024-10-17 14:56:44 -07:00
multibitmapset.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
nodeFuncs.h Introduce an RTE for the grouping step 2024-09-10 12:35:34 +09:00
nodes.h Convert node test compile-time settings into run-time parameters 2024-08-01 10:09:18 +02:00
params.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
parsenodes.h Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
pathnodes.h Convert SetOp to read its inputs as outerPlan and innerPlan. 2024-12-19 16:23:45 -05:00
pg_list.h Add type cast to foreach_internal's loop variable. 2024-10-15 16:20:49 -05:00
plannodes.h Convert SetOp to read its inputs as outerPlan and innerPlan. 2024-12-19 16:23:45 -05:00
primnodes.h SQL/JSON: Fix some oversights in commit b6e1157e7 2024-10-20 12:20:55 +09:00
print.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
queryjumble.h revert: Transform OR clauses to ANY expression 2024-04-10 02:28:09 +03:00
readfuncs.h Convert node test compile-time settings into run-time parameters 2024-08-01 10:09:18 +02:00
replnodes.h Allow setting failover property in the replication command. 2024-01-29 09:37:23 +05:30
subscripting.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
supportnodes.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
tidbitmap.h Bitmap Table Scans use unified TBMIterator 2024-12-18 18:43:39 -05:00
value.h Update copyright for 2024 2024-01-03 20:49:05 -05:00