mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Improve planner's handling of SetOp plans.
Remove the code for inserting flag columns in the inputs of a SetOp. That was the only reason why there would be resjunk columns in a set-operations plan tree, so we can get rid of some code that supported that, too. Get rid of choose_hashed_setop() in favor of building Paths for the hashed and sorted alternatives, and letting them fight it out within add_path(). Remove set_operation_ordered_results_useful(), which was giving wrong answers due to examining the wrong ancestor node: we need to examine the immediate SetOperationStmt parent not the topmost node. Instead make each caller of recurse_set_operations() pass down the relevant parent node. (This thinko seems to have led only to wasted planning cycles and possibly-inferior plans, not wrong query answers. Perhaps we should back-patch it, but I'm not doing so right now.) Teach generate_nonunion_paths() to consider pre-sorted inputs for sorted SetOps, rather than always generating a Sort node. Patch by me; thanks to Richard Guo and David Rowley for review. Discussion: https://postgr.es/m/1850138.1731549611@sss.pgh.pa.us
This commit is contained in:
@@ -638,8 +638,11 @@ select sum(ss.tst::int) from
|
||||
where o.ten = 0;
|
||||
|
||||
--
|
||||
-- Test rescan of a SetOp node
|
||||
-- Test rescan of a hashed SetOp node
|
||||
--
|
||||
begin;
|
||||
set local enable_sort = off;
|
||||
|
||||
explain (costs off)
|
||||
select count(*) from
|
||||
onek o cross join lateral (
|
||||
@@ -657,6 +660,33 @@ select count(*) from
|
||||
) ss
|
||||
where o.ten = 1;
|
||||
|
||||
rollback;
|
||||
|
||||
--
|
||||
-- Test rescan of a sorted SetOp node
|
||||
--
|
||||
begin;
|
||||
set local enable_hashagg = off;
|
||||
|
||||
explain (costs off)
|
||||
select count(*) from
|
||||
onek o cross join lateral (
|
||||
select * from onek i1 where i1.unique1 = o.unique1
|
||||
except
|
||||
select * from onek i2 where i2.unique1 = o.unique2
|
||||
) ss
|
||||
where o.ten = 1;
|
||||
|
||||
select count(*) from
|
||||
onek o cross join lateral (
|
||||
select * from onek i1 where i1.unique1 = o.unique1
|
||||
except
|
||||
select * from onek i2 where i2.unique1 = o.unique2
|
||||
) ss
|
||||
where o.ten = 1;
|
||||
|
||||
rollback;
|
||||
|
||||
--
|
||||
-- Test rescan of a RecursiveUnion node
|
||||
--
|
||||
|
||||
@@ -134,10 +134,15 @@ select count(*) from
|
||||
select count(*) from
|
||||
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
|
||||
|
||||
-- this query will prefer a sorted setop unless we force it.
|
||||
set enable_indexscan to off;
|
||||
|
||||
explain (costs off)
|
||||
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
|
||||
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
|
||||
|
||||
reset enable_indexscan;
|
||||
|
||||
-- the hashed implementation is sensitive to child plans' tuple slot types
|
||||
explain (costs off)
|
||||
select * from int8_tbl intersect select q2, q1 from int8_tbl order by 1, 2;
|
||||
@@ -162,6 +167,10 @@ explain (costs off)
|
||||
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
|
||||
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
|
||||
|
||||
explain (costs off)
|
||||
select f1 from int4_tbl union all
|
||||
(select unique1 from tenk1 union select unique2 from tenk1);
|
||||
|
||||
reset enable_hashagg;
|
||||
|
||||
-- non-hashable type
|
||||
|
||||
Reference in New Issue
Block a user