Fix EXPLAIN's column alias output for mismatched child tables.

If an inheritance/partitioning parent table is assigned some column
alias names in the query, EXPLAIN mapped those aliases onto the
child tables' columns by physical position, resulting in bogus output
if a child table's columns aren't one-for-one with the parent's.

To fix, make expand_single_inheritance_child() generate a correctly
re-mapped column alias list, rather than just copying the parent
RTE's alias node.  (We have to fill the alias field, not just
adjust the eref field, because ruleutils.c will ignore eref in
favor of looking at the real column names.)

This means that child tables will now always have alias fields in
plan rtables, where before they might not have.  That results in
a rather substantial set of regression test output changes:
EXPLAIN will now always show child tables with aliases that match
the parent table (usually with "_N" appended for uniqueness).
But that seems like a net positive for understandability, since
the parent alias corresponds to something that actually appeared
in the original query, while the child table names didn't.
(Note that this does not change anything for cases where an explicit
table alias was written in the query for the parent table; it
just makes cases without such aliases behave similarly to that.)
Hence, while we could avoid these subsidiary changes if we made
inherit.c more complicated, we choose not to.

Discussion: https://postgr.es/m/12424.1575168015@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2019-12-02 19:08:10 -05:00
parent ce76c0ba53
commit 55a1954da1
16 changed files with 2072 additions and 1982 deletions

View File

@ -6260,10 +6260,10 @@ UPDATE rw_view SET b = b + 5;
QUERY PLAN
----------------------------------------------------------------------------------------
Update on public.parent_tbl
Foreign Update on public.foreign_tbl
Foreign Update on public.foreign_tbl parent_tbl_1
Remote SQL: UPDATE public.child_tbl SET b = $2 WHERE ctid = $1 RETURNING a, b
-> Foreign Scan on public.foreign_tbl
Output: foreign_tbl.a, (foreign_tbl.b + 5), foreign_tbl.ctid
-> Foreign Scan on public.foreign_tbl parent_tbl_1
Output: parent_tbl_1.a, (parent_tbl_1.b + 5), parent_tbl_1.ctid
Remote SQL: SELECT a, b, ctid FROM public.child_tbl WHERE ((a < b)) FOR UPDATE
(6 rows)
@ -6275,10 +6275,10 @@ UPDATE rw_view SET b = b + 15;
QUERY PLAN
----------------------------------------------------------------------------------------
Update on public.parent_tbl
Foreign Update on public.foreign_tbl
Foreign Update on public.foreign_tbl parent_tbl_1
Remote SQL: UPDATE public.child_tbl SET b = $2 WHERE ctid = $1 RETURNING a, b
-> Foreign Scan on public.foreign_tbl
Output: foreign_tbl.a, (foreign_tbl.b + 15), foreign_tbl.ctid
-> Foreign Scan on public.foreign_tbl parent_tbl_1
Output: parent_tbl_1.a, (parent_tbl_1.b + 15), parent_tbl_1.ctid
Remote SQL: SELECT a, b, ctid FROM public.child_tbl WHERE ((a < b)) FOR UPDATE
(6 rows)
@ -7066,8 +7066,8 @@ select * from bar where f1 in (select f1 from foo) for update;
-> Append
-> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid
-> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.ctid, bar2.*, bar2.tableoid
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.f1, bar_1.f2, bar_1.ctid, bar_1.*, bar_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
-> Hash
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
@ -7077,8 +7077,8 @@ select * from bar where f1 in (select f1 from foo) for update;
-> Append
-> Seq Scan on public.foo
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
-> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.f1, foo2.*, foo2.tableoid
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.ctid, foo_1.f1, foo_1.*, foo_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(23 rows)
@ -7104,8 +7104,8 @@ select * from bar where f1 in (select f1 from foo) for share;
-> Append
-> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid
-> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.ctid, bar2.*, bar2.tableoid
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.f1, bar_1.f2, bar_1.ctid, bar_1.*, bar_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR SHARE
-> Hash
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
@ -7115,8 +7115,8 @@ select * from bar where f1 in (select f1 from foo) for share;
-> Append
-> Seq Scan on public.foo
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
-> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.f1, foo2.*, foo2.tableoid
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.ctid, foo_1.f1, foo_1.*, foo_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(23 rows)
@ -7132,11 +7132,11 @@ select * from bar where f1 in (select f1 from foo) for share;
-- Check UPDATE with inherited target and an inherited source table
explain (verbose, costs off)
update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
QUERY PLAN
---------------------------------------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------------------------------
Update on public.bar
Update on public.bar
Foreign Update on public.bar2
Foreign Update on public.bar2 bar_1
Remote SQL: UPDATE public.loct2 SET f2 = $2 WHERE ctid = $1
-> Hash Join
Output: bar.f1, (bar.f2 + 100), bar.ctid, foo.ctid, foo.*, foo.tableoid
@ -7152,15 +7152,15 @@ update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
-> Append
-> Seq Scan on public.foo
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
-> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.f1, foo2.*, foo2.tableoid
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.ctid, foo_1.f1, foo_1.*, foo_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
-> Hash Join
Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, foo.ctid, foo.*, foo.tableoid
Output: bar_1.f1, (bar_1.f2 + 100), bar_1.f3, bar_1.ctid, foo.ctid, foo.*, foo.tableoid
Inner Unique: true
Hash Cond: (bar2.f1 = foo.f1)
-> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.f3, bar2.ctid
Hash Cond: (bar_1.f1 = foo.f1)
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.f1, bar_1.f2, bar_1.f3, bar_1.ctid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
-> Hash
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
@ -7170,8 +7170,8 @@ update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
-> Append
-> Seq Scan on public.foo
Output: foo.ctid, foo.f1, foo.*, foo.tableoid
-> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.f1, foo2.*, foo2.tableoid
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.ctid, foo_1.f1, foo_1.*, foo_1.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(39 rows)
@ -7197,7 +7197,7 @@ where bar.f1 = ss.f1;
--------------------------------------------------------------------------------------
Update on public.bar
Update on public.bar
Foreign Update on public.bar2
Foreign Update on public.bar2 bar_1
Remote SQL: UPDATE public.loct2 SET f2 = $2 WHERE ctid = $1
-> Hash Join
Output: bar.f1, (bar.f2 + 100), bar.ctid, (ROW(foo.f1))
@ -7205,26 +7205,26 @@ where bar.f1 = ss.f1;
-> Append
-> Seq Scan on public.foo
Output: ROW(foo.f1), foo.f1
-> Foreign Scan on public.foo2
Output: ROW(foo2.f1), foo2.f1
-> Foreign Scan on public.foo2 foo_1
Output: ROW(foo_1.f1), foo_1.f1
Remote SQL: SELECT f1 FROM public.loct1
-> Seq Scan on public.foo foo_1
Output: ROW((foo_1.f1 + 3)), (foo_1.f1 + 3)
-> Foreign Scan on public.foo2 foo2_1
Output: ROW((foo2_1.f1 + 3)), (foo2_1.f1 + 3)
-> Seq Scan on public.foo foo_2
Output: ROW((foo_2.f1 + 3)), (foo_2.f1 + 3)
-> Foreign Scan on public.foo2 foo_3
Output: ROW((foo_3.f1 + 3)), (foo_3.f1 + 3)
Remote SQL: SELECT f1 FROM public.loct1
-> Hash
Output: bar.f1, bar.f2, bar.ctid
-> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid
-> Merge Join
Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, (ROW(foo.f1))
Merge Cond: (bar2.f1 = foo.f1)
Output: bar_1.f1, (bar_1.f2 + 100), bar_1.f3, bar_1.ctid, (ROW(foo.f1))
Merge Cond: (bar_1.f1 = foo.f1)
-> Sort
Output: bar2.f1, bar2.f2, bar2.f3, bar2.ctid
Sort Key: bar2.f1
-> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.f3, bar2.ctid
Output: bar_1.f1, bar_1.f2, bar_1.f3, bar_1.ctid
Sort Key: bar_1.f1
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.f1, bar_1.f2, bar_1.f3, bar_1.ctid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
-> Sort
Output: (ROW(foo.f1)), foo.f1
@ -7232,13 +7232,13 @@ where bar.f1 = ss.f1;
-> Append
-> Seq Scan on public.foo
Output: ROW(foo.f1), foo.f1
-> Foreign Scan on public.foo2
Output: ROW(foo2.f1), foo2.f1
-> Foreign Scan on public.foo2 foo_1
Output: ROW(foo_1.f1), foo_1.f1
Remote SQL: SELECT f1 FROM public.loct1
-> Seq Scan on public.foo foo_1
Output: ROW((foo_1.f1 + 3)), (foo_1.f1 + 3)
-> Foreign Scan on public.foo2 foo2_1
Output: ROW((foo2_1.f1 + 3)), (foo2_1.f1 + 3)
-> Seq Scan on public.foo foo_2
Output: ROW((foo_2.f1 + 3)), (foo_2.f1 + 3)
-> Foreign Scan on public.foo2 foo_3
Output: ROW((foo_3.f1 + 3)), (foo_3.f1 + 3)
Remote SQL: SELECT f1 FROM public.loct1
(45 rows)
@ -7288,8 +7288,8 @@ explain (verbose, costs off)
Sort Key: foo.f1
-> Index Scan using i_foo_f1 on public.foo
Output: foo.f1, foo.f2
-> Foreign Scan on public.foo2
Output: foo2.f1, foo2.f2
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.f1, foo_1.f2
Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC NULLS LAST
-> Index Only Scan using i_loct1_f1 on public.loct1
Output: loct1.f1
@ -7328,8 +7328,8 @@ explain (verbose, costs off)
Sort Key: foo.f1
-> Index Scan using i_foo_f1 on public.foo
Output: foo.f1, foo.f2
-> Foreign Scan on public.foo2
Output: foo2.f1, foo2.f2
-> Foreign Scan on public.foo2 foo_1
Output: foo_1.f1, foo_1.f2
Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC NULLS LAST
-> Index Only Scan using i_loct1_f1 on public.loct1
Output: loct1.f1
@ -7371,11 +7371,11 @@ delete from foo where f1 < 5 returning *;
Delete on public.foo
Output: foo.f1, foo.f2
Delete on public.foo
Foreign Delete on public.foo2
Foreign Delete on public.foo2 foo_1
-> Index Scan using i_foo_f1 on public.foo
Output: foo.ctid
Index Cond: (foo.f1 < 5)
-> Foreign Delete on public.foo2
-> Foreign Delete on public.foo2 foo_1
Remote SQL: DELETE FROM public.loct1 WHERE ((f1 < 5)) RETURNING f1, f2
(9 rows)
@ -7396,10 +7396,10 @@ update bar set f2 = f2 + 100 returning *;
Update on public.bar
Output: bar.f1, bar.f2
Update on public.bar
Foreign Update on public.bar2
Foreign Update on public.bar2 bar_1
-> Seq Scan on public.bar
Output: bar.f1, (bar.f2 + 100), bar.ctid
-> Foreign Update on public.bar2
-> Foreign Update on public.bar2 bar_1
Remote SQL: UPDATE public.loct2 SET f2 = (f2 + 100) RETURNING f1, f2
(8 rows)
@ -7427,12 +7427,12 @@ update bar set f2 = f2 + 100;
--------------------------------------------------------------------------------------------------------
Update on public.bar
Update on public.bar
Foreign Update on public.bar2
Foreign Update on public.bar2 bar_1
Remote SQL: UPDATE public.loct2 SET f1 = $2, f2 = $3, f3 = $4 WHERE ctid = $1 RETURNING f1, f2, f3
-> Seq Scan on public.bar
Output: bar.f1, (bar.f2 + 100), bar.ctid
-> Foreign Scan on public.bar2
Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, bar2.*
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.f1, (bar_1.f2 + 100), bar_1.f3, bar_1.ctid, bar_1.*
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
(9 rows)
@ -7455,13 +7455,13 @@ delete from bar where f2 < 400;
---------------------------------------------------------------------------------------------
Delete on public.bar
Delete on public.bar
Foreign Delete on public.bar2
Foreign Delete on public.bar2 bar_1
Remote SQL: DELETE FROM public.loct2 WHERE ctid = $1 RETURNING f1, f2, f3
-> Seq Scan on public.bar
Output: bar.ctid
Filter: (bar.f2 < 400)
-> Foreign Scan on public.bar2
Output: bar2.ctid, bar2.*
-> Foreign Scan on public.bar2 bar_1
Output: bar_1.ctid, bar_1.*
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 WHERE ((f2 < 400)) FOR UPDATE
(10 rows)
@ -7499,7 +7499,7 @@ update parent set b = parent.b || remt2.b from remt2 where parent.a = remt2.a re
Update on public.parent
Output: parent.a, parent.b, remt2.a, remt2.b
Update on public.parent
Foreign Update on public.remt1
Foreign Update on public.remt1 parent_1
-> Nested Loop
Output: parent.a, (parent.b || remt2.b), parent.ctid, remt2.*, remt2.a, remt2.b
Join Filter: (parent.a = remt2.a)
@ -7526,7 +7526,7 @@ delete from parent using remt2 where parent.a = remt2.a returning parent;
Delete on public.parent
Output: parent.*
Delete on public.parent
Foreign Delete on public.remt1
Foreign Delete on public.remt1 parent_1
-> Nested Loop
Output: parent.ctid, remt2.*
Join Filter: (parent.a = remt2.a)
@ -7753,14 +7753,14 @@ update utrtest set a = 1 where a = 1 or a = 2 returning *;
QUERY PLAN
----------------------------------------------------------------------------------------------
Update on public.utrtest
Output: remp.a, remp.b
Foreign Update on public.remp
Update on public.locp
-> Foreign Update on public.remp
Output: utrtest_1.a, utrtest_1.b
Foreign Update on public.remp utrtest_1
Update on public.locp utrtest_2
-> Foreign Update on public.remp utrtest_1
Remote SQL: UPDATE public.loct SET a = 1 WHERE (((a = 1) OR (a = 2))) RETURNING a, b
-> Seq Scan on public.locp
Output: 1, locp.b, locp.ctid
Filter: ((locp.a = 1) OR (locp.a = 2))
-> Seq Scan on public.locp utrtest_2
Output: 1, utrtest_2.b, utrtest_2.ctid
Filter: ((utrtest_2.a = 1) OR (utrtest_2.a = 2))
(9 rows)
-- The new values are concatenated with ' triggered !'
@ -7775,14 +7775,14 @@ insert into utrtest values (2, 'qux');
-- Check case where the foreign partition isn't a subplan target rel
explain (verbose, costs off)
update utrtest set a = 1 where a = 2 returning *;
QUERY PLAN
--------------------------------------
QUERY PLAN
------------------------------------------------
Update on public.utrtest
Output: locp.a, locp.b
Update on public.locp
-> Seq Scan on public.locp
Output: 1, locp.b, locp.ctid
Filter: (locp.a = 2)
Output: utrtest_1.a, utrtest_1.b
Update on public.locp utrtest_1
-> Seq Scan on public.locp utrtest_1
Output: 1, utrtest_1.b, utrtest_1.ctid
Filter: (utrtest_1.a = 2)
(6 rows)
-- The new values are concatenated with ' triggered !'
@ -7805,13 +7805,13 @@ update utrtest set a = 1 returning *;
QUERY PLAN
-----------------------------------------------------------------
Update on public.utrtest
Output: remp.a, remp.b
Foreign Update on public.remp
Update on public.locp
-> Foreign Update on public.remp
Output: utrtest_1.a, utrtest_1.b
Foreign Update on public.remp utrtest_1
Update on public.locp utrtest_2
-> Foreign Update on public.remp utrtest_1
Remote SQL: UPDATE public.loct SET a = 1 RETURNING a, b
-> Seq Scan on public.locp
Output: 1, locp.b, locp.ctid
-> Seq Scan on public.locp utrtest_2
Output: 1, utrtest_2.b, utrtest_2.ctid
(8 rows)
update utrtest set a = 1 returning *;
@ -7827,28 +7827,28 @@ insert into utrtest values (2, 'qux');
-- with a non-direct modification plan
explain (verbose, costs off)
update utrtest set a = 1 from (values (1), (2)) s(x) where a = s.x returning *;
QUERY PLAN
------------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------
Update on public.utrtest
Output: remp.a, remp.b, "*VALUES*".column1
Foreign Update on public.remp
Output: utrtest_1.a, utrtest_1.b, "*VALUES*".column1
Foreign Update on public.remp utrtest_1
Remote SQL: UPDATE public.loct SET a = $2 WHERE ctid = $1 RETURNING a, b
Update on public.locp
Update on public.locp utrtest_2
-> Hash Join
Output: 1, remp.b, remp.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (remp.a = "*VALUES*".column1)
-> Foreign Scan on public.remp
Output: remp.b, remp.ctid, remp.a
Output: 1, utrtest_1.b, utrtest_1.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (utrtest_1.a = "*VALUES*".column1)
-> Foreign Scan on public.remp utrtest_1
Output: utrtest_1.b, utrtest_1.ctid, utrtest_1.a
Remote SQL: SELECT a, b, ctid FROM public.loct FOR UPDATE
-> Hash
Output: "*VALUES*".*, "*VALUES*".column1
-> Values Scan on "*VALUES*"
Output: "*VALUES*".*, "*VALUES*".column1
-> Hash Join
Output: 1, locp.b, locp.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (locp.a = "*VALUES*".column1)
-> Seq Scan on public.locp
Output: locp.b, locp.ctid, locp.a
Output: 1, utrtest_2.b, utrtest_2.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (utrtest_2.a = "*VALUES*".column1)
-> Seq Scan on public.locp utrtest_2
Output: utrtest_2.b, utrtest_2.ctid, utrtest_2.a
-> Hash
Output: "*VALUES*".*, "*VALUES*".column1
-> Values Scan on "*VALUES*"
@ -7880,12 +7880,12 @@ update utrtest set a = 3 returning *;
QUERY PLAN
-----------------------------------------------------------------
Update on public.utrtest
Output: locp.a, locp.b
Update on public.locp
Foreign Update on public.remp
-> Seq Scan on public.locp
Output: 3, locp.b, locp.ctid
-> Foreign Update on public.remp
Output: utrtest_1.a, utrtest_1.b
Update on public.locp utrtest_1
Foreign Update on public.remp utrtest_2
-> Seq Scan on public.locp utrtest_1
Output: 3, utrtest_1.b, utrtest_1.ctid
-> Foreign Update on public.remp utrtest_2
Remote SQL: UPDATE public.loct SET a = 3 RETURNING a, b
(8 rows)
@ -7894,27 +7894,27 @@ ERROR: cannot route tuples into foreign table to be updated "remp"
-- with a non-direct modification plan
explain (verbose, costs off)
update utrtest set a = 3 from (values (2), (3)) s(x) where a = s.x returning *;
QUERY PLAN
------------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------
Update on public.utrtest
Output: locp.a, locp.b, "*VALUES*".column1
Update on public.locp
Foreign Update on public.remp
Output: utrtest_1.a, utrtest_1.b, "*VALUES*".column1
Update on public.locp utrtest_1
Foreign Update on public.remp utrtest_2
Remote SQL: UPDATE public.loct SET a = $2 WHERE ctid = $1 RETURNING a, b
-> Hash Join
Output: 3, locp.b, locp.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (locp.a = "*VALUES*".column1)
-> Seq Scan on public.locp
Output: locp.b, locp.ctid, locp.a
Output: 3, utrtest_1.b, utrtest_1.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (utrtest_1.a = "*VALUES*".column1)
-> Seq Scan on public.locp utrtest_1
Output: utrtest_1.b, utrtest_1.ctid, utrtest_1.a
-> Hash
Output: "*VALUES*".*, "*VALUES*".column1
-> Values Scan on "*VALUES*"
Output: "*VALUES*".*, "*VALUES*".column1
-> Hash Join
Output: 3, remp.b, remp.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (remp.a = "*VALUES*".column1)
-> Foreign Scan on public.remp
Output: remp.b, remp.ctid, remp.a
Output: 3, utrtest_2.b, utrtest_2.ctid, "*VALUES*".*, "*VALUES*".column1
Hash Cond: (utrtest_2.a = "*VALUES*".column1)
-> Foreign Scan on public.remp utrtest_2
Output: utrtest_2.b, utrtest_2.ctid, utrtest_2.a
Remote SQL: SELECT a, b, ctid FROM public.loct FOR UPDATE
-> Hash
Output: "*VALUES*".*, "*VALUES*".column1
@ -8506,8 +8506,8 @@ SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10)
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Foreign Scan
Output: t1.a, ftprt2_p1.b, ftprt2_p1.c
Relations: (public.ftprt1_p1 t1) LEFT JOIN (public.ftprt2_p1)
Output: t1.a, fprt2.b, fprt2.c
Relations: (public.ftprt1_p1 t1) LEFT JOIN (public.ftprt2_p1 fprt2)
Remote SQL: SELECT r5.a, r6.b, r6.c FROM (public.fprt1_p1 r5 LEFT JOIN public.fprt2_p1 r6 ON (((r5.a = r6.b)) AND ((r5.b = r6.a)) AND ((r6.a < 10)))) WHERE ((r5.a < 10)) ORDER BY r5.a ASC NULLS LAST, r6.b ASC NULLS LAST, r6.c ASC NULLS LAST
(4 rows)
@ -8584,21 +8584,21 @@ SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t
-- with PHVs, partitionwise join selected but no join pushdown
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
QUERY PLAN
------------------------------------------------------
QUERY PLAN
-----------------------------------------------------------
Sort
Sort Key: ftprt1_p1.a, ftprt2_p1.b
Sort Key: fprt1.a, fprt2.b
-> Append
-> Hash Full Join
Hash Cond: (ftprt1_p1.a = ftprt2_p1.b)
-> Foreign Scan on ftprt1_p1
Hash Cond: (fprt1.a = fprt2.b)
-> Foreign Scan on ftprt1_p1 fprt1
-> Hash
-> Foreign Scan on ftprt2_p1
-> Foreign Scan on ftprt2_p1 fprt2
-> Hash Full Join
Hash Cond: (ftprt1_p2.a = ftprt2_p2.b)
-> Foreign Scan on ftprt1_p2
Hash Cond: (fprt1_1.a = fprt2_1.b)
-> Foreign Scan on ftprt1_p2 fprt1_1
-> Hash
-> Foreign Scan on ftprt2_p2
-> Foreign Scan on ftprt2_p2 fprt2_1
(13 rows)
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
@ -8672,34 +8672,34 @@ ANALYZE fpagg_tab_p3;
SET enable_partitionwise_aggregate TO false;
EXPLAIN (COSTS OFF)
SELECT a, sum(b), min(b), count(*) FROM pagg_tab GROUP BY a HAVING avg(b) < 22 ORDER BY 1;
QUERY PLAN
-------------------------------------------------------
QUERY PLAN
-----------------------------------------------------------
Sort
Sort Key: fpagg_tab_p1.a
Sort Key: pagg_tab.a
-> HashAggregate
Group Key: fpagg_tab_p1.a
Filter: (avg(fpagg_tab_p1.b) < '22'::numeric)
Group Key: pagg_tab.a
Filter: (avg(pagg_tab.b) < '22'::numeric)
-> Append
-> Foreign Scan on fpagg_tab_p1
-> Foreign Scan on fpagg_tab_p2
-> Foreign Scan on fpagg_tab_p3
-> Foreign Scan on fpagg_tab_p1 pagg_tab
-> Foreign Scan on fpagg_tab_p2 pagg_tab_1
-> Foreign Scan on fpagg_tab_p3 pagg_tab_2
(9 rows)
-- Plan with partitionwise aggregates is enabled
SET enable_partitionwise_aggregate TO true;
EXPLAIN (COSTS OFF)
SELECT a, sum(b), min(b), count(*) FROM pagg_tab GROUP BY a HAVING avg(b) < 22 ORDER BY 1;
QUERY PLAN
-------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------
Sort
Sort Key: fpagg_tab_p1.a
Sort Key: pagg_tab.a
-> Append
-> Foreign Scan
Relations: Aggregate on (public.fpagg_tab_p1)
Relations: Aggregate on (public.fpagg_tab_p1 pagg_tab)
-> Foreign Scan
Relations: Aggregate on (public.fpagg_tab_p2)
Relations: Aggregate on (public.fpagg_tab_p2 pagg_tab_1)
-> Foreign Scan
Relations: Aggregate on (public.fpagg_tab_p3)
Relations: Aggregate on (public.fpagg_tab_p3 pagg_tab_2)
(9 rows)
SELECT a, sum(b), min(b), count(*) FROM pagg_tab GROUP BY a HAVING avg(b) < 22 ORDER BY 1;
@ -8760,23 +8760,23 @@ SELECT a, count(t1) FROM pagg_tab t1 GROUP BY a HAVING avg(b) < 22 ORDER BY 1;
-- When GROUP BY clause does not match with PARTITION KEY.
EXPLAIN (COSTS OFF)
SELECT b, avg(a), max(a), count(*) FROM pagg_tab GROUP BY b HAVING sum(a) < 700 ORDER BY 1;
QUERY PLAN
------------------------------------------------------
QUERY PLAN
-----------------------------------------------------------------
Sort
Sort Key: fpagg_tab_p1.b
Sort Key: pagg_tab.b
-> Finalize HashAggregate
Group Key: fpagg_tab_p1.b
Filter: (sum(fpagg_tab_p1.a) < 700)
Group Key: pagg_tab.b
Filter: (sum(pagg_tab.a) < 700)
-> Append
-> Partial HashAggregate
Group Key: fpagg_tab_p1.b
-> Foreign Scan on fpagg_tab_p1
Group Key: pagg_tab.b
-> Foreign Scan on fpagg_tab_p1 pagg_tab
-> Partial HashAggregate
Group Key: fpagg_tab_p2.b
-> Foreign Scan on fpagg_tab_p2
Group Key: pagg_tab_1.b
-> Foreign Scan on fpagg_tab_p2 pagg_tab_1
-> Partial HashAggregate
Group Key: fpagg_tab_p3.b
-> Foreign Scan on fpagg_tab_p3
Group Key: pagg_tab_2.b
-> Foreign Scan on fpagg_tab_p3 pagg_tab_2
(15 rows)
-- Clean-up

View File

@ -421,10 +421,13 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
RangeTblEntry *childrte;
Index childRTindex;
AppendRelInfo *appinfo;
TupleDesc child_tupdesc;
List *parent_colnames;
List *child_colnames;
/*
* Build an RTE for the child, and attach to query's rangetable list. We
* copy most fields of the parent's RTE, but replace relation OID,
* copy most scalar fields of the parent's RTE, but replace relation OID,
* relkind, and inh for the child. Also, set requiredPerms to zero since
* all required permissions checks are done on the original RTE. Likewise,
* set the child's securityQuals to empty, because we only want to apply
@ -432,10 +435,14 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
* individual children may have. (This is an intentional choice to make
* inherited RLS work like regular permissions checks.) The parent
* securityQuals will be propagated to children along with other base
* restriction clauses, so we don't need to do it here.
* restriction clauses, so we don't need to do it here. Other
* infrastructure of the parent RTE has to be translated to match the
* child table's column ordering, which we do below, so a "flat" copy is
* sufficient to start with.
*/
childrte = copyObject(parentrte);
*childrte_p = childrte;
childrte = makeNode(RangeTblEntry);
memcpy(childrte, parentrte, sizeof(RangeTblEntry));
Assert(parentrte->rtekind == RTE_RELATION); /* else this is dubious */
childrte->relid = childOID;
childrte->relkind = childrel->rd_rel->relkind;
/* A partitioned child will need to be expanded further. */
@ -448,8 +455,11 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
childrte->inh = false;
childrte->requiredPerms = 0;
childrte->securityQuals = NIL;
/* Link not-yet-fully-filled child RTE into data structures */
parse->rtable = lappend(parse->rtable, childrte);
childRTindex = list_length(parse->rtable);
*childrte_p = childrte;
*childRTindex_p = childRTindex;
/*
@ -459,10 +469,57 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
parentRTindex, childRTindex);
root->append_rel_list = lappend(root->append_rel_list, appinfo);
/* tablesample is probably null, but copy it */
childrte->tablesample = copyObject(parentrte->tablesample);
/*
* Construct an alias clause for the child, which we can also use as eref.
* This is important so that EXPLAIN will print the right column aliases
* for child-table columns. (Since ruleutils.c doesn't have any easy way
* to reassociate parent and child columns, we must get the child column
* aliases right to start with. Note that setting childrte->alias forces
* ruleutils.c to use these column names, which it otherwise would not.)
*/
child_tupdesc = RelationGetDescr(childrel);
parent_colnames = parentrte->eref->colnames;
child_colnames = NIL;
for (int cattno = 0; cattno < child_tupdesc->natts; cattno++)
{
Form_pg_attribute att = TupleDescAttr(child_tupdesc, cattno);
const char *attname;
if (att->attisdropped)
{
/* Always insert an empty string for a dropped column */
attname = "";
}
else if (appinfo->parent_colnos[cattno] > 0 &&
appinfo->parent_colnos[cattno] <= list_length(parent_colnames))
{
/* Duplicate the query-assigned name for the parent column */
attname = strVal(list_nth(parent_colnames,
appinfo->parent_colnos[cattno] - 1));
}
else
{
/* New column, just use its real name */
attname = NameStr(att->attname);
}
child_colnames = lappend(child_colnames, makeString(pstrdup(attname)));
}
/*
* We just duplicate the parent's table alias name for each child. If the
* plan gets printed, ruleutils.c has to sort out unique table aliases to
* use, which it can handle.
*/
childrte->alias = childrte->eref = makeAlias(parentrte->eref->aliasname,
child_colnames);
/*
* Translate the column permissions bitmaps to the child's attnums (we
* have to build the translated_vars list before we can do this). But if
* this is the parent table, we can leave copyObject's result alone.
* this is the parent table, we can just duplicate the parent's bitmaps.
*
* Note: we need to do this even though the executor won't run any
* permissions checks on the child RTE. The insertedCols/updatedCols
@ -479,6 +536,13 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
childrte->extraUpdatedCols = translate_col_privs(parentrte->extraUpdatedCols,
appinfo->translated_vars);
}
else
{
childrte->selectedCols = bms_copy(parentrte->selectedCols);
childrte->insertedCols = bms_copy(parentrte->insertedCols);
childrte->updatedCols = bms_copy(parentrte->updatedCols);
childrte->extraUpdatedCols = bms_copy(parentrte->extraUpdatedCols);
}
/*
* Store the RTE and appinfo in the respective PlannerInfo arrays, which

View File

@ -998,8 +998,8 @@ insert into minmaxtest2 values(15), (16);
insert into minmaxtest3 values(17), (18);
explain (costs off)
select min(f1), max(f1) from minmaxtest;
QUERY PLAN
----------------------------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------------------
Result
InitPlan 1 (returns $0)
-> Limit
@ -1007,22 +1007,22 @@ explain (costs off)
Sort Key: minmaxtest.f1
-> Index Only Scan using minmaxtesti on minmaxtest
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest1i on minmaxtest1
-> Index Only Scan using minmaxtest1i on minmaxtest1 minmaxtest_1
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest2i on minmaxtest2
-> Index Only Scan Backward using minmaxtest2i on minmaxtest2 minmaxtest_2
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest3i on minmaxtest3
-> Index Only Scan using minmaxtest3i on minmaxtest3 minmaxtest_3
InitPlan 2 (returns $1)
-> Limit
-> Merge Append
Sort Key: minmaxtest_1.f1 DESC
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_1
Sort Key: minmaxtest_4.f1 DESC
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_4
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest1_1
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest_5
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest2i on minmaxtest2 minmaxtest2_1
-> Index Only Scan using minmaxtest2i on minmaxtest2 minmaxtest_6
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest3i on minmaxtest3 minmaxtest3_1
-> Index Only Scan Backward using minmaxtest3i on minmaxtest3 minmaxtest_7
(23 rows)
select min(f1), max(f1) from minmaxtest;
@ -1034,8 +1034,8 @@ select min(f1), max(f1) from minmaxtest;
-- DISTINCT doesn't do anything useful here, but it shouldn't fail
explain (costs off)
select distinct min(f1), max(f1) from minmaxtest;
QUERY PLAN
----------------------------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------------------
Unique
InitPlan 1 (returns $0)
-> Limit
@ -1043,22 +1043,22 @@ explain (costs off)
Sort Key: minmaxtest.f1
-> Index Only Scan using minmaxtesti on minmaxtest
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest1i on minmaxtest1
-> Index Only Scan using minmaxtest1i on minmaxtest1 minmaxtest_1
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest2i on minmaxtest2
-> Index Only Scan Backward using minmaxtest2i on minmaxtest2 minmaxtest_2
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest3i on minmaxtest3
-> Index Only Scan using minmaxtest3i on minmaxtest3 minmaxtest_3
InitPlan 2 (returns $1)
-> Limit
-> Merge Append
Sort Key: minmaxtest_1.f1 DESC
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_1
Sort Key: minmaxtest_4.f1 DESC
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_4
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest1_1
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest_5
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan using minmaxtest2i on minmaxtest2 minmaxtest2_1
-> Index Only Scan using minmaxtest2i on minmaxtest2 minmaxtest_6
Index Cond: (f1 IS NOT NULL)
-> Index Only Scan Backward using minmaxtest3i on minmaxtest3 minmaxtest3_1
-> Index Only Scan Backward using minmaxtest3i on minmaxtest3 minmaxtest_7
-> Sort
Sort Key: ($0), ($1)
-> Result
@ -1156,7 +1156,7 @@ explain (costs off) select * from t1 group by a,b,c,d;
Group Key: t1.a, t1.b, t1.c, t1.d
-> Append
-> Seq Scan on t1
-> Seq Scan on t1c
-> Seq Scan on t1c t1_1
(5 rows)
-- Okay to remove columns if we're only querying the parent.
@ -1179,13 +1179,13 @@ create temp table p_t1_1 partition of p_t1 for values in(1);
create temp table p_t1_2 partition of p_t1 for values in(2);
-- Ensure we can remove non-PK columns for partitioned tables.
explain (costs off) select * from p_t1 group by a,b,c,d;
QUERY PLAN
---------------------------------
QUERY PLAN
---------------------------------------
HashAggregate
Group Key: p_t1_1.a, p_t1_1.b
Group Key: p_t1.a, p_t1.b
-> Append
-> Seq Scan on p_t1_1
-> Seq Scan on p_t1_2
-> Seq Scan on p_t1_1 p_t1
-> Seq Scan on p_t1_2 p_t1_1
(5 rows)
drop table t1 cascade;

View File

@ -542,9 +542,9 @@ explain (costs off) select * from nv_parent where d between '2011-08-01' and '20
Append
-> Seq Scan on nv_parent
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
-> Seq Scan on nv_child_2010
-> Seq Scan on nv_child_2010 nv_parent_1
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
-> Seq Scan on nv_child_2011
-> Seq Scan on nv_child_2011 nv_parent_2
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
(7 rows)
@ -555,9 +555,9 @@ explain (costs off) select * from nv_parent where d between '2011-08-01'::date a
Append
-> Seq Scan on nv_parent
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
-> Seq Scan on nv_child_2010
-> Seq Scan on nv_child_2010 nv_parent_1
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
-> Seq Scan on nv_child_2011
-> Seq Scan on nv_child_2011 nv_parent_2
Filter: ((d >= '08-01-2011'::date) AND (d <= '08-31-2011'::date))
(7 rows)
@ -567,11 +567,11 @@ explain (costs off) select * from nv_parent where d between '2009-08-01'::date a
Append
-> Seq Scan on nv_parent
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
-> Seq Scan on nv_child_2010
-> Seq Scan on nv_child_2010 nv_parent_1
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
-> Seq Scan on nv_child_2011
-> Seq Scan on nv_child_2011 nv_parent_2
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
-> Seq Scan on nv_child_2009
-> Seq Scan on nv_child_2009 nv_parent_3
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
(9 rows)
@ -583,9 +583,9 @@ explain (costs off) select * from nv_parent where d between '2009-08-01'::date a
Append
-> Seq Scan on nv_parent
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
-> Seq Scan on nv_child_2010
-> Seq Scan on nv_child_2010 nv_parent_1
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
-> Seq Scan on nv_child_2009
-> Seq Scan on nv_child_2009 nv_parent_2
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
(7 rows)

View File

@ -1332,17 +1332,17 @@ analyze patest1;
analyze patest2;
explain (costs off)
select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
QUERY PLAN
--------------------------------------------------
QUERY PLAN
------------------------------------------------------------
Nested Loop
-> Limit
-> Seq Scan on int4_tbl
-> Append
-> Index Scan using patest0i on patest0
Index Cond: (id = int4_tbl.f1)
-> Index Scan using patest1i on patest1
-> Index Scan using patest1i on patest1 patest0_1
Index Cond: (id = int4_tbl.f1)
-> Index Scan using patest2i on patest2
-> Index Scan using patest2i on patest2 patest0_2
Index Cond: (id = int4_tbl.f1)
(10 rows)
@ -1357,17 +1357,17 @@ select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
drop index patest2i;
explain (costs off)
select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
QUERY PLAN
--------------------------------------------------
QUERY PLAN
------------------------------------------------------------
Nested Loop
-> Limit
-> Seq Scan on int4_tbl
-> Append
-> Index Scan using patest0i on patest0
Index Cond: (id = int4_tbl.f1)
-> Index Scan using patest1i on patest1
-> Index Scan using patest1i on patest1 patest0_1
Index Cond: (id = int4_tbl.f1)
-> Seq Scan on patest2
-> Seq Scan on patest2 patest0_2
Filter: (int4_tbl.f1 = id)
(10 rows)
@ -1415,12 +1415,12 @@ explain (verbose, costs off) select * from matest0 order by 1-id;
-> Append
-> Seq Scan on public.matest0
Output: matest0.id, matest0.name
-> Seq Scan on public.matest1
Output: matest1.id, matest1.name
-> Seq Scan on public.matest2
Output: matest2.id, matest2.name
-> Seq Scan on public.matest3
Output: matest3.id, matest3.name
-> Seq Scan on public.matest1 matest0_1
Output: matest0_1.id, matest0_1.name
-> Seq Scan on public.matest2 matest0_2
Output: matest0_2.id, matest0_2.name
-> Seq Scan on public.matest3 matest0_3
Output: matest0_3.id, matest0_3.name
(14 rows)
select * from matest0 order by 1-id;
@ -1435,19 +1435,19 @@ select * from matest0 order by 1-id;
(6 rows)
explain (verbose, costs off) select min(1-id) from matest0;
QUERY PLAN
----------------------------------------
QUERY PLAN
--------------------------------------------------
Aggregate
Output: min((1 - matest0.id))
-> Append
-> Seq Scan on public.matest0
Output: matest0.id
-> Seq Scan on public.matest1
Output: matest1.id
-> Seq Scan on public.matest2
Output: matest2.id
-> Seq Scan on public.matest3
Output: matest3.id
-> Seq Scan on public.matest1 matest0_1
Output: matest0_1.id
-> Seq Scan on public.matest2 matest0_2
Output: matest0_2.id
-> Seq Scan on public.matest3 matest0_3
Output: matest0_3.id
(11 rows)
select min(1-id) from matest0;
@ -1460,21 +1460,21 @@ reset enable_indexscan;
set enable_seqscan = off; -- plan with fewest seqscans should be merge
set enable_parallel_append = off; -- Don't let parallel-append interfere
explain (verbose, costs off) select * from matest0 order by 1-id;
QUERY PLAN
------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------
Merge Append
Sort Key: ((1 - matest0.id))
-> Index Scan using matest0i on public.matest0
Output: matest0.id, matest0.name, (1 - matest0.id)
-> Index Scan using matest1i on public.matest1
Output: matest1.id, matest1.name, (1 - matest1.id)
-> Index Scan using matest1i on public.matest1 matest0_1
Output: matest0_1.id, matest0_1.name, (1 - matest0_1.id)
-> Sort
Output: matest2.id, matest2.name, ((1 - matest2.id))
Sort Key: ((1 - matest2.id))
-> Seq Scan on public.matest2
Output: matest2.id, matest2.name, (1 - matest2.id)
-> Index Scan using matest3i on public.matest3
Output: matest3.id, matest3.name, (1 - matest3.id)
Output: matest0_2.id, matest0_2.name, ((1 - matest0_2.id))
Sort Key: ((1 - matest0_2.id))
-> Seq Scan on public.matest2 matest0_2
Output: matest0_2.id, matest0_2.name, (1 - matest0_2.id)
-> Index Scan using matest3i on public.matest3 matest0_3
Output: matest0_3.id, matest0_3.name, (1 - matest0_3.id)
(13 rows)
select * from matest0 order by 1-id;
@ -1489,8 +1489,8 @@ select * from matest0 order by 1-id;
(6 rows)
explain (verbose, costs off) select min(1-id) from matest0;
QUERY PLAN
--------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------
Result
Output: $0
InitPlan 1 (returns $0)
@ -1503,19 +1503,19 @@ explain (verbose, costs off) select min(1-id) from matest0;
-> Index Scan using matest0i on public.matest0
Output: matest0.id, (1 - matest0.id)
Index Cond: ((1 - matest0.id) IS NOT NULL)
-> Index Scan using matest1i on public.matest1
Output: matest1.id, (1 - matest1.id)
Index Cond: ((1 - matest1.id) IS NOT NULL)
-> Index Scan using matest1i on public.matest1 matest0_1
Output: matest0_1.id, (1 - matest0_1.id)
Index Cond: ((1 - matest0_1.id) IS NOT NULL)
-> Sort
Output: matest2.id, ((1 - matest2.id))
Sort Key: ((1 - matest2.id))
-> Bitmap Heap Scan on public.matest2
Output: matest2.id, (1 - matest2.id)
Filter: ((1 - matest2.id) IS NOT NULL)
Output: matest0_2.id, ((1 - matest0_2.id))
Sort Key: ((1 - matest0_2.id))
-> Bitmap Heap Scan on public.matest2 matest0_2
Output: matest0_2.id, (1 - matest0_2.id)
Filter: ((1 - matest0_2.id) IS NOT NULL)
-> Bitmap Index Scan on matest2_pkey
-> Index Scan using matest3i on public.matest3
Output: matest3.id, (1 - matest3.id)
Index Cond: ((1 - matest3.id) IS NOT NULL)
-> Index Scan using matest3i on public.matest3 matest0_3
Output: matest0_3.id, (1 - matest0_3.id)
Index Cond: ((1 - matest0_3.id) IS NOT NULL)
(25 rows)
select min(1-id) from matest0;
@ -1780,30 +1780,30 @@ create table part_ab_cd partition of list_parted for values in ('ab', 'cd');
create table part_ef_gh partition of list_parted for values in ('ef', 'gh');
create table part_null_xy partition of list_parted for values in (null, 'xy');
explain (costs off) select * from list_parted;
QUERY PLAN
--------------------------------
QUERY PLAN
----------------------------------------------
Append
-> Seq Scan on part_ab_cd
-> Seq Scan on part_ef_gh
-> Seq Scan on part_null_xy
-> Seq Scan on part_ab_cd list_parted
-> Seq Scan on part_ef_gh list_parted_1
-> Seq Scan on part_null_xy list_parted_2
(4 rows)
explain (costs off) select * from list_parted where a is null;
QUERY PLAN
--------------------------
Seq Scan on part_null_xy
QUERY PLAN
--------------------------------------
Seq Scan on part_null_xy list_parted
Filter: (a IS NULL)
(2 rows)
explain (costs off) select * from list_parted where a is not null;
QUERY PLAN
---------------------------------
QUERY PLAN
----------------------------------------------
Append
-> Seq Scan on part_ab_cd
-> Seq Scan on part_ab_cd list_parted
Filter: (a IS NOT NULL)
-> Seq Scan on part_ef_gh
-> Seq Scan on part_ef_gh list_parted_1
Filter: (a IS NOT NULL)
-> Seq Scan on part_null_xy
-> Seq Scan on part_null_xy list_parted_2
Filter: (a IS NOT NULL)
(7 rows)
@ -1811,23 +1811,23 @@ explain (costs off) select * from list_parted where a in ('ab', 'cd', 'ef');
QUERY PLAN
----------------------------------------------------------
Append
-> Seq Scan on part_ab_cd
-> Seq Scan on part_ab_cd list_parted
Filter: ((a)::text = ANY ('{ab,cd,ef}'::text[]))
-> Seq Scan on part_ef_gh
-> Seq Scan on part_ef_gh list_parted_1
Filter: ((a)::text = ANY ('{ab,cd,ef}'::text[]))
(5 rows)
explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd');
QUERY PLAN
---------------------------------------------------------------------------------
Seq Scan on part_ab_cd
Seq Scan on part_ab_cd list_parted
Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
(2 rows)
explain (costs off) select * from list_parted where a = 'ab';
QUERY PLAN
------------------------------------
Seq Scan on part_ab_cd
Seq Scan on part_ab_cd list_parted
Filter: ((a)::text = 'ab'::text)
(2 rows)
@ -1849,41 +1849,41 @@ create table part_40_inf_ab partition of part_40_inf for values in ('ab');
create table part_40_inf_cd partition of part_40_inf for values in ('cd');
create table part_40_inf_null partition of part_40_inf for values in (null);
explain (costs off) select * from range_list_parted;
QUERY PLAN
------------------------------------
QUERY PLAN
--------------------------------------------------------
Append
-> Seq Scan on part_1_10_ab
-> Seq Scan on part_1_10_cd
-> Seq Scan on part_10_20_ab
-> Seq Scan on part_10_20_cd
-> Seq Scan on part_21_30_ab
-> Seq Scan on part_21_30_cd
-> Seq Scan on part_40_inf_ab
-> Seq Scan on part_40_inf_cd
-> Seq Scan on part_40_inf_null
-> Seq Scan on part_1_10_ab range_list_parted
-> Seq Scan on part_1_10_cd range_list_parted_1
-> Seq Scan on part_10_20_ab range_list_parted_2
-> Seq Scan on part_10_20_cd range_list_parted_3
-> Seq Scan on part_21_30_ab range_list_parted_4
-> Seq Scan on part_21_30_cd range_list_parted_5
-> Seq Scan on part_40_inf_ab range_list_parted_6
-> Seq Scan on part_40_inf_cd range_list_parted_7
-> Seq Scan on part_40_inf_null range_list_parted_8
(10 rows)
explain (costs off) select * from range_list_parted where a = 5;
QUERY PLAN
--------------------------------
QUERY PLAN
----------------------------------------------------
Append
-> Seq Scan on part_1_10_ab
-> Seq Scan on part_1_10_ab range_list_parted
Filter: (a = 5)
-> Seq Scan on part_1_10_cd
-> Seq Scan on part_1_10_cd range_list_parted_1
Filter: (a = 5)
(5 rows)
explain (costs off) select * from range_list_parted where b = 'ab';
QUERY PLAN
------------------------------------
QUERY PLAN
------------------------------------------------------
Append
-> Seq Scan on part_1_10_ab
-> Seq Scan on part_1_10_ab range_list_parted
Filter: (b = 'ab'::bpchar)
-> Seq Scan on part_10_20_ab
-> Seq Scan on part_10_20_ab range_list_parted_1
Filter: (b = 'ab'::bpchar)
-> Seq Scan on part_21_30_ab
-> Seq Scan on part_21_30_ab range_list_parted_2
Filter: (b = 'ab'::bpchar)
-> Seq Scan on part_40_inf_ab
-> Seq Scan on part_40_inf_ab range_list_parted_3
Filter: (b = 'ab'::bpchar)
(9 rows)
@ -1891,11 +1891,11 @@ explain (costs off) select * from range_list_parted where a between 3 and 23 and
QUERY PLAN
-----------------------------------------------------------------
Append
-> Seq Scan on part_1_10_ab
-> Seq Scan on part_1_10_ab range_list_parted
Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
-> Seq Scan on part_10_20_ab
-> Seq Scan on part_10_20_ab range_list_parted_1
Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
-> Seq Scan on part_21_30_ab
-> Seq Scan on part_21_30_ab range_list_parted_2
Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
(7 rows)
@ -1909,45 +1909,45 @@ explain (costs off) select * from range_list_parted where a is null;
/* Should only select rows from the null-accepting partition */
explain (costs off) select * from range_list_parted where b is null;
QUERY PLAN
------------------------------
Seq Scan on part_40_inf_null
QUERY PLAN
------------------------------------------------
Seq Scan on part_40_inf_null range_list_parted
Filter: (b IS NULL)
(2 rows)
explain (costs off) select * from range_list_parted where a is not null and a < 67;
QUERY PLAN
------------------------------------------------
QUERY PLAN
--------------------------------------------------------
Append
-> Seq Scan on part_1_10_ab
-> Seq Scan on part_1_10_ab range_list_parted
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_1_10_cd
-> Seq Scan on part_1_10_cd range_list_parted_1
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_10_20_ab
-> Seq Scan on part_10_20_ab range_list_parted_2
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_10_20_cd
-> Seq Scan on part_10_20_cd range_list_parted_3
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_21_30_ab
-> Seq Scan on part_21_30_ab range_list_parted_4
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_21_30_cd
-> Seq Scan on part_21_30_cd range_list_parted_5
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_40_inf_ab
-> Seq Scan on part_40_inf_ab range_list_parted_6
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_40_inf_cd
-> Seq Scan on part_40_inf_cd range_list_parted_7
Filter: ((a IS NOT NULL) AND (a < 67))
-> Seq Scan on part_40_inf_null
-> Seq Scan on part_40_inf_null range_list_parted_8
Filter: ((a IS NOT NULL) AND (a < 67))
(19 rows)
explain (costs off) select * from range_list_parted where a >= 30;
QUERY PLAN
------------------------------------
QUERY PLAN
--------------------------------------------------------
Append
-> Seq Scan on part_40_inf_ab
-> Seq Scan on part_40_inf_ab range_list_parted
Filter: (a >= 30)
-> Seq Scan on part_40_inf_cd
-> Seq Scan on part_40_inf_cd range_list_parted_1
Filter: (a >= 30)
-> Seq Scan on part_40_inf_null
-> Seq Scan on part_40_inf_null range_list_parted_2
Filter: (a >= 30)
(7 rows)
@ -1964,12 +1964,12 @@ create table mcrparted3 partition of mcrparted for values from (11, 1, 1) to (20
create table mcrparted4 partition of mcrparted for values from (20, 10, 10) to (20, 20, 20);
create table mcrparted5 partition of mcrparted for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue);
explain (costs off) select * from mcrparted where a = 0; -- scans mcrparted0, mcrparted_def
QUERY PLAN
---------------------------------
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted0
-> Seq Scan on mcrparted0 mcrparted
Filter: (a = 0)
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_1
Filter: (a = 0)
(5 rows)
@ -1977,9 +1977,9 @@ explain (costs off) select * from mcrparted where a = 10 and abs(b) < 5; -- scan
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted1
-> Seq Scan on mcrparted1 mcrparted
Filter: ((a = 10) AND (abs(b) < 5))
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_1
Filter: ((a = 10) AND (abs(b) < 5))
(5 rows)
@ -1987,72 +1987,72 @@ explain (costs off) select * from mcrparted where a = 10 and abs(b) = 5; -- scan
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted1
-> Seq Scan on mcrparted1 mcrparted
Filter: ((a = 10) AND (abs(b) = 5))
-> Seq Scan on mcrparted2
-> Seq Scan on mcrparted2 mcrparted_1
Filter: ((a = 10) AND (abs(b) = 5))
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_2
Filter: ((a = 10) AND (abs(b) = 5))
(7 rows)
explain (costs off) select * from mcrparted where abs(b) = 5; -- scans all partitions
QUERY PLAN
---------------------------------
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted0
-> Seq Scan on mcrparted0 mcrparted
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted1
-> Seq Scan on mcrparted1 mcrparted_1
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted2
-> Seq Scan on mcrparted2 mcrparted_2
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted3
-> Seq Scan on mcrparted3 mcrparted_3
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted4
-> Seq Scan on mcrparted4 mcrparted_4
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted5
-> Seq Scan on mcrparted5 mcrparted_5
Filter: (abs(b) = 5)
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_6
Filter: (abs(b) = 5)
(15 rows)
explain (costs off) select * from mcrparted where a > -1; -- scans all partitions
QUERY PLAN
-------------------------------------
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted0
-> Seq Scan on mcrparted0 mcrparted
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted1
-> Seq Scan on mcrparted1 mcrparted_1
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted2
-> Seq Scan on mcrparted2 mcrparted_2
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted3
-> Seq Scan on mcrparted3 mcrparted_3
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted4
-> Seq Scan on mcrparted4 mcrparted_4
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted5
-> Seq Scan on mcrparted5 mcrparted_5
Filter: (a > '-1'::integer)
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_6
Filter: (a > '-1'::integer)
(15 rows)
explain (costs off) select * from mcrparted where a = 20 and abs(b) = 10 and c > 10; -- scans mcrparted4
QUERY PLAN
-----------------------------------------------------
Seq Scan on mcrparted4
Seq Scan on mcrparted4 mcrparted
Filter: ((c > 10) AND (a = 20) AND (abs(b) = 10))
(2 rows)
explain (costs off) select * from mcrparted where a = 20 and c > 20; -- scans mcrparted3, mcrparte4, mcrparte5, mcrparted_def
QUERY PLAN
-----------------------------------------
QUERY PLAN
---------------------------------------------
Append
-> Seq Scan on mcrparted3
-> Seq Scan on mcrparted3 mcrparted
Filter: ((c > 20) AND (a = 20))
-> Seq Scan on mcrparted4
-> Seq Scan on mcrparted4 mcrparted_1
Filter: ((c > 20) AND (a = 20))
-> Seq Scan on mcrparted5
-> Seq Scan on mcrparted5 mcrparted_2
Filter: ((c > 20) AND (a = 20))
-> Seq Scan on mcrparted_def
-> Seq Scan on mcrparted_def mcrparted_3
Filter: ((c > 20) AND (a = 20))
(9 rows)
@ -2063,16 +2063,16 @@ create table parted_minmax1 partition of parted_minmax for values from (1) to (1
create index parted_minmax1i on parted_minmax1 (a, b);
insert into parted_minmax values (1,'12345');
explain (costs off) select min(a), max(a) from parted_minmax where b = '12345';
QUERY PLAN
-------------------------------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------------------
Result
InitPlan 1 (returns $0)
-> Limit
-> Index Only Scan using parted_minmax1i on parted_minmax1
-> Index Only Scan using parted_minmax1i on parted_minmax1 parted_minmax
Index Cond: ((a IS NOT NULL) AND (b = '12345'::text))
InitPlan 2 (returns $1)
-> Limit
-> Index Only Scan Backward using parted_minmax1i on parted_minmax1 parted_minmax1_1
-> Index Only Scan Backward using parted_minmax1i on parted_minmax1 parted_minmax_1
Index Cond: ((a IS NOT NULL) AND (b = '12345'::text))
(9 rows)
@ -2088,45 +2088,45 @@ drop table parted_minmax;
create index mcrparted_a_abs_c_idx on mcrparted (a, abs(b), c);
-- MergeAppend must be used when a default partition exists
explain (costs off) select * from mcrparted order by a, abs(b), c;
QUERY PLAN
-------------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------------
Merge Append
Sort Key: mcrparted0.a, (abs(mcrparted0.b)), mcrparted0.c
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4
-> Index Scan using mcrparted5_a_abs_c_idx on mcrparted5
-> Index Scan using mcrparted_def_a_abs_c_idx on mcrparted_def
Sort Key: mcrparted.a, (abs(mcrparted.b)), mcrparted.c
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4 mcrparted_4
-> Index Scan using mcrparted5_a_abs_c_idx on mcrparted5 mcrparted_5
-> Index Scan using mcrparted_def_a_abs_c_idx on mcrparted_def mcrparted_6
(9 rows)
drop table mcrparted_def;
-- Append is used for a RANGE partitioned table with no default
-- and no subpartitions
explain (costs off) select * from mcrparted order by a, abs(b), c;
QUERY PLAN
-------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------
Append
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4
-> Index Scan using mcrparted5_a_abs_c_idx on mcrparted5
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4 mcrparted_4
-> Index Scan using mcrparted5_a_abs_c_idx on mcrparted5 mcrparted_5
(7 rows)
-- Append is used with subpaths in reverse order with backwards index scans
explain (costs off) select * from mcrparted order by a desc, abs(b) desc, c desc;
QUERY PLAN
----------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------
Append
-> Index Scan Backward using mcrparted5_a_abs_c_idx on mcrparted5
-> Index Scan Backward using mcrparted4_a_abs_c_idx on mcrparted4
-> Index Scan Backward using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan Backward using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan Backward using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan Backward using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan Backward using mcrparted5_a_abs_c_idx on mcrparted5 mcrparted_5
-> Index Scan Backward using mcrparted4_a_abs_c_idx on mcrparted4 mcrparted_4
-> Index Scan Backward using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
-> Index Scan Backward using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
-> Index Scan Backward using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
-> Index Scan Backward using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
(7 rows)
-- check that Append plan is used containing a MergeAppend for sub-partitions
@ -2136,18 +2136,18 @@ create table mcrparted5 partition of mcrparted for values from (20, 20, 20) to (
create table mcrparted5a partition of mcrparted5 for values in(20);
create table mcrparted5_def partition of mcrparted5 default;
explain (costs off) select * from mcrparted order by a, abs(b), c;
QUERY PLAN
---------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------------
Append
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4 mcrparted_4
-> Merge Append
Sort Key: mcrparted5a.a, (abs(mcrparted5a.b)), mcrparted5a.c
-> Index Scan using mcrparted5a_a_abs_c_idx on mcrparted5a
-> Index Scan using mcrparted5_def_a_abs_c_idx on mcrparted5_def
Sort Key: mcrparted_5.a, (abs(mcrparted_5.b)), mcrparted_5.c
-> Index Scan using mcrparted5a_a_abs_c_idx on mcrparted5a mcrparted_5
-> Index Scan using mcrparted5_def_a_abs_c_idx on mcrparted5_def mcrparted_6
(10 rows)
drop table mcrparted5_def;
@ -2155,30 +2155,30 @@ drop table mcrparted5_def;
-- into the main Append when the sub-partition is unordered but contains
-- just a single sub-partition.
explain (costs off) select a, abs(b) from mcrparted order by a, abs(b), c;
QUERY PLAN
---------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------
Append
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4
-> Index Scan using mcrparted5a_a_abs_c_idx on mcrparted5a
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
-> Index Scan using mcrparted4_a_abs_c_idx on mcrparted4 mcrparted_4
-> Index Scan using mcrparted5a_a_abs_c_idx on mcrparted5a mcrparted_5
(7 rows)
-- check that Append is used when the sub-partitioned tables are pruned
-- during planning.
explain (costs off) select * from mcrparted where a < 20 order by a, abs(b), c;
QUERY PLAN
-------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------
Append
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0
-> Index Scan using mcrparted0_a_abs_c_idx on mcrparted0 mcrparted
Index Cond: (a < 20)
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
Index Cond: (a < 20)
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
Index Cond: (a < 20)
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
Index Cond: (a < 20)
(9 rows)
@ -2188,11 +2188,11 @@ create table mclparted2 partition of mclparted for values in(2);
create index on mclparted (a);
-- Ensure an Append is used for a list partition with an order by.
explain (costs off) select * from mclparted order by a;
QUERY PLAN
------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------
Append
-> Index Only Scan using mclparted1_a_idx on mclparted1
-> Index Only Scan using mclparted2_a_idx on mclparted2
-> Index Only Scan using mclparted1_a_idx on mclparted1 mclparted
-> Index Only Scan using mclparted2_a_idx on mclparted2 mclparted_1
(3 rows)
-- Ensure a MergeAppend is used when a partition exists with interleaved
@ -2200,14 +2200,14 @@ explain (costs off) select * from mclparted order by a;
create table mclparted3_5 partition of mclparted for values in(3,5);
create table mclparted4 partition of mclparted for values in(4);
explain (costs off) select * from mclparted order by a;
QUERY PLAN
----------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------
Merge Append
Sort Key: mclparted1.a
-> Index Only Scan using mclparted1_a_idx on mclparted1
-> Index Only Scan using mclparted2_a_idx on mclparted2
-> Index Only Scan using mclparted3_5_a_idx on mclparted3_5
-> Index Only Scan using mclparted4_a_idx on mclparted4
Sort Key: mclparted.a
-> Index Only Scan using mclparted1_a_idx on mclparted1 mclparted
-> Index Only Scan using mclparted2_a_idx on mclparted2 mclparted_1
-> Index Only Scan using mclparted3_5_a_idx on mclparted3_5 mclparted_2
-> Index Only Scan using mclparted4_a_idx on mclparted4 mclparted_3
(6 rows)
drop table mclparted;
@ -2219,19 +2219,19 @@ create index on mcrparted2 (a, abs(b), c);
create index on mcrparted3 (a, abs(b), c);
create index on mcrparted4 (a, abs(b), c);
explain (costs off) select * from mcrparted where a < 20 order by a, abs(b), c limit 1;
QUERY PLAN
-------------------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------------
Limit
-> Append
-> Sort
Sort Key: mcrparted0.a, (abs(mcrparted0.b)), mcrparted0.c
-> Seq Scan on mcrparted0
Sort Key: mcrparted.a, (abs(mcrparted.b)), mcrparted.c
-> Seq Scan on mcrparted0 mcrparted
Filter: (a < 20)
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted_1
Index Cond: (a < 20)
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_2
Index Cond: (a < 20)
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3
-> Index Scan using mcrparted3_a_abs_c_idx on mcrparted3 mcrparted_3
Index Cond: (a < 20)
(12 rows)
@ -2239,12 +2239,12 @@ set enable_bitmapscan = 0;
-- Ensure Append node can be used when the partition is ordered by some
-- pathkeys which were deemed redundant.
explain (costs off) select * from mcrparted where a = 10 order by a, abs(b), c;
QUERY PLAN
-------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------
Append
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1
-> Index Scan using mcrparted1_a_abs_c_idx on mcrparted1 mcrparted
Index Cond: (a = 10)
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2
-> Index Scan using mcrparted2_a_abs_c_idx on mcrparted2 mcrparted_1
Index Cond: (a = 10)
(5 rows)
@ -2256,11 +2256,11 @@ create table bool_lp_true partition of bool_lp for values in(true);
create table bool_lp_false partition of bool_lp for values in(false);
create index on bool_lp (b);
explain (costs off) select * from bool_lp order by b;
QUERY PLAN
------------------------------------------------------------------
QUERY PLAN
--------------------------------------------------------------------------
Append
-> Index Only Scan using bool_lp_false_b_idx on bool_lp_false
-> Index Only Scan using bool_lp_true_b_idx on bool_lp_true
-> Index Only Scan using bool_lp_false_b_idx on bool_lp_false bool_lp
-> Index Only Scan using bool_lp_true_b_idx on bool_lp_true bool_lp_1
(3 rows)
drop table bool_lp;
@ -2272,42 +2272,42 @@ create table bool_rp_false_2k partition of bool_rp for values from (false,1000)
create table bool_rp_true_2k partition of bool_rp for values from (true,1000) to (true,2000);
create index on bool_rp (b,a);
explain (costs off) select * from bool_rp where b = true order by b,a;
QUERY PLAN
------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------
Append
-> Index Only Scan using bool_rp_true_1k_b_a_idx on bool_rp_true_1k
-> Index Only Scan using bool_rp_true_1k_b_a_idx on bool_rp_true_1k bool_rp
Index Cond: (b = true)
-> Index Only Scan using bool_rp_true_2k_b_a_idx on bool_rp_true_2k
-> Index Only Scan using bool_rp_true_2k_b_a_idx on bool_rp_true_2k bool_rp_1
Index Cond: (b = true)
(5 rows)
explain (costs off) select * from bool_rp where b = false order by b,a;
QUERY PLAN
--------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------
Append
-> Index Only Scan using bool_rp_false_1k_b_a_idx on bool_rp_false_1k
-> Index Only Scan using bool_rp_false_1k_b_a_idx on bool_rp_false_1k bool_rp
Index Cond: (b = false)
-> Index Only Scan using bool_rp_false_2k_b_a_idx on bool_rp_false_2k
-> Index Only Scan using bool_rp_false_2k_b_a_idx on bool_rp_false_2k bool_rp_1
Index Cond: (b = false)
(5 rows)
explain (costs off) select * from bool_rp where b = true order by a;
QUERY PLAN
------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------
Append
-> Index Only Scan using bool_rp_true_1k_b_a_idx on bool_rp_true_1k
-> Index Only Scan using bool_rp_true_1k_b_a_idx on bool_rp_true_1k bool_rp
Index Cond: (b = true)
-> Index Only Scan using bool_rp_true_2k_b_a_idx on bool_rp_true_2k
-> Index Only Scan using bool_rp_true_2k_b_a_idx on bool_rp_true_2k bool_rp_1
Index Cond: (b = true)
(5 rows)
explain (costs off) select * from bool_rp where b = false order by a;
QUERY PLAN
--------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------
Append
-> Index Only Scan using bool_rp_false_1k_b_a_idx on bool_rp_false_1k
-> Index Only Scan using bool_rp_false_1k_b_a_idx on bool_rp_false_1k bool_rp
Index Cond: (b = false)
-> Index Only Scan using bool_rp_false_2k_b_a_idx on bool_rp_false_2k
-> Index Only Scan using bool_rp_false_2k_b_a_idx on bool_rp_false_2k bool_rp_1
Index Cond: (b = false)
(5 rows)
@ -2319,19 +2319,19 @@ create table range_parted1 partition of range_parted for values from (0,0) to (1
create table range_parted2 partition of range_parted for values from (10,10) to (20,20);
create index on range_parted (a,b,c);
explain (costs off) select * from range_parted order by a,b,c;
QUERY PLAN
----------------------------------------------------------------------
QUERY PLAN
-------------------------------------------------------------------------------------
Append
-> Index Only Scan using range_parted1_a_b_c_idx on range_parted1
-> Index Only Scan using range_parted2_a_b_c_idx on range_parted2
-> Index Only Scan using range_parted1_a_b_c_idx on range_parted1 range_parted
-> Index Only Scan using range_parted2_a_b_c_idx on range_parted2 range_parted_1
(3 rows)
explain (costs off) select * from range_parted order by a desc,b desc,c desc;
QUERY PLAN
-------------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------------------
Append
-> Index Only Scan Backward using range_parted2_a_b_c_idx on range_parted2
-> Index Only Scan Backward using range_parted1_a_b_c_idx on range_parted1
-> Index Only Scan Backward using range_parted2_a_b_c_idx on range_parted2 range_parted_1
-> Index Only Scan Backward using range_parted1_a_b_c_idx on range_parted1 range_parted
(3 rows)
drop table range_parted;

File diff suppressed because it is too large Load Diff

View File

@ -145,34 +145,34 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM prt1 t1 RIGHT JOIN prt2 t2 ON t1.a = t2.b WHE
-- full outer join, with placeholder vars
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT 50 phv, * FROM prt1 WHERE prt1.b = 0) t1 FULL JOIN (SELECT 75 phv, * FROM prt2 WHERE prt2.a = 0) t2 ON (t1.a = t2.b) WHERE t1.phv = t1.a OR t2.phv = t2.b ORDER BY t1.a, t2.b;
QUERY PLAN
------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------
Sort
Sort Key: prt1_p1.a, prt2_p1.b
Sort Key: prt1.a, prt2.b
-> Append
-> Hash Full Join
Hash Cond: (prt1_p1.a = prt2_p1.b)
Filter: (((50) = prt1_p1.a) OR ((75) = prt2_p1.b))
-> Seq Scan on prt1_p1
Hash Cond: (prt1.a = prt2.b)
Filter: (((50) = prt1.a) OR ((75) = prt2.b))
-> Seq Scan on prt1_p1 prt1
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p1
-> Seq Scan on prt2_p1 prt2
Filter: (a = 0)
-> Hash Full Join
Hash Cond: (prt1_p2.a = prt2_p2.b)
Filter: (((50) = prt1_p2.a) OR ((75) = prt2_p2.b))
-> Seq Scan on prt1_p2
Hash Cond: (prt1_1.a = prt2_1.b)
Filter: (((50) = prt1_1.a) OR ((75) = prt2_1.b))
-> Seq Scan on prt1_p2 prt1_1
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p2
-> Seq Scan on prt2_p2 prt2_1
Filter: (a = 0)
-> Hash Full Join
Hash Cond: (prt1_p3.a = prt2_p3.b)
Filter: (((50) = prt1_p3.a) OR ((75) = prt2_p3.b))
-> Seq Scan on prt1_p3
Hash Cond: (prt1_2.a = prt2_2.b)
Filter: (((50) = prt1_2.a) OR ((75) = prt2_2.b))
-> Seq Scan on prt1_p3 prt1_2
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p3
-> Seq Scan on prt2_p3 prt2_2
Filter: (a = 0)
(27 rows)
@ -211,19 +211,19 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 LEFT JO
QUERY PLAN
-----------------------------------------------------------
Sort
Sort Key: prt1_p1.a, prt2_p2.b
Sort Key: prt1.a, prt2.b
-> Hash Right Join
Hash Cond: (prt2_p2.b = prt1_p1.a)
Hash Cond: (prt2.b = prt1.a)
-> Append
-> Seq Scan on prt2_p2
-> Seq Scan on prt2_p2 prt2
Filter: (b > 250)
-> Seq Scan on prt2_p3
-> Seq Scan on prt2_p3 prt2_1
Filter: (b > 250)
-> Hash
-> Append
-> Seq Scan on prt1_p1
-> Seq Scan on prt1_p1 prt1
Filter: ((a < 450) AND (b = 0))
-> Seq Scan on prt1_p2
-> Seq Scan on prt1_p2 prt1_1
Filter: ((a < 450) AND (b = 0))
(15 rows)
@ -244,23 +244,23 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 LEFT JO
-- Currently we can't do partitioned join if nullable-side partitions are pruned
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1 WHERE a < 450) t1 FULL JOIN (SELECT * FROM prt2 WHERE b > 250) t2 ON t1.a = t2.b WHERE t1.b = 0 OR t2.a = 0 ORDER BY t1.a, t2.b;
QUERY PLAN
------------------------------------------------------
QUERY PLAN
----------------------------------------------------
Sort
Sort Key: prt1_p1.a, prt2_p2.b
Sort Key: prt1.a, prt2.b
-> Hash Full Join
Hash Cond: (prt1_p1.a = prt2_p2.b)
Filter: ((prt1_p1.b = 0) OR (prt2_p2.a = 0))
Hash Cond: (prt1.a = prt2.b)
Filter: ((prt1.b = 0) OR (prt2.a = 0))
-> Append
-> Seq Scan on prt1_p1
-> Seq Scan on prt1_p1 prt1
Filter: (a < 450)
-> Seq Scan on prt1_p2
-> Seq Scan on prt1_p2 prt1_1
Filter: (a < 450)
-> Hash
-> Append
-> Seq Scan on prt2_p2
-> Seq Scan on prt2_p2 prt2
Filter: (b > 250)
-> Seq Scan on prt2_p3
-> Seq Scan on prt2_p3 prt2_1
Filter: (b > 250)
(16 rows)
@ -466,48 +466,48 @@ EXPLAIN (COSTS OFF)
SELECT a, b FROM prt1 FULL JOIN prt2 p2(b,a,c) USING(a,b)
WHERE a BETWEEN 490 AND 510
GROUP BY 1, 2 ORDER BY 1, 2;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Group
Group Key: (COALESCE(prt1_p1.a, p2.a)), (COALESCE(prt1_p1.b, p2.b))
Group Key: (COALESCE(prt1.a, p2.a)), (COALESCE(prt1.b, p2.b))
-> Merge Append
Sort Key: (COALESCE(prt1_p1.a, p2.a)), (COALESCE(prt1_p1.b, p2.b))
Sort Key: (COALESCE(prt1.a, p2.a)), (COALESCE(prt1.b, p2.b))
-> Group
Group Key: (COALESCE(prt1_p1.a, p2.a)), (COALESCE(prt1_p1.b, p2.b))
Group Key: (COALESCE(prt1.a, p2.a)), (COALESCE(prt1.b, p2.b))
-> Sort
Sort Key: (COALESCE(prt1_p1.a, p2.a)), (COALESCE(prt1_p1.b, p2.b))
Sort Key: (COALESCE(prt1.a, p2.a)), (COALESCE(prt1.b, p2.b))
-> Merge Full Join
Merge Cond: ((prt1_p1.a = p2.a) AND (prt1_p1.b = p2.b))
Filter: ((COALESCE(prt1_p1.a, p2.a) >= 490) AND (COALESCE(prt1_p1.a, p2.a) <= 510))
Merge Cond: ((prt1.a = p2.a) AND (prt1.b = p2.b))
Filter: ((COALESCE(prt1.a, p2.a) >= 490) AND (COALESCE(prt1.a, p2.a) <= 510))
-> Sort
Sort Key: prt1_p1.a, prt1_p1.b
-> Seq Scan on prt1_p1
Sort Key: prt1.a, prt1.b
-> Seq Scan on prt1_p1 prt1
-> Sort
Sort Key: p2.a, p2.b
-> Seq Scan on prt2_p1 p2
-> Group
Group Key: (COALESCE(prt1_p2.a, p2_1.a)), (COALESCE(prt1_p2.b, p2_1.b))
Group Key: (COALESCE(prt1_1.a, p2_1.a)), (COALESCE(prt1_1.b, p2_1.b))
-> Sort
Sort Key: (COALESCE(prt1_p2.a, p2_1.a)), (COALESCE(prt1_p2.b, p2_1.b))
Sort Key: (COALESCE(prt1_1.a, p2_1.a)), (COALESCE(prt1_1.b, p2_1.b))
-> Merge Full Join
Merge Cond: ((prt1_p2.a = p2_1.a) AND (prt1_p2.b = p2_1.b))
Filter: ((COALESCE(prt1_p2.a, p2_1.a) >= 490) AND (COALESCE(prt1_p2.a, p2_1.a) <= 510))
Merge Cond: ((prt1_1.a = p2_1.a) AND (prt1_1.b = p2_1.b))
Filter: ((COALESCE(prt1_1.a, p2_1.a) >= 490) AND (COALESCE(prt1_1.a, p2_1.a) <= 510))
-> Sort
Sort Key: prt1_p2.a, prt1_p2.b
-> Seq Scan on prt1_p2
Sort Key: prt1_1.a, prt1_1.b
-> Seq Scan on prt1_p2 prt1_1
-> Sort
Sort Key: p2_1.a, p2_1.b
-> Seq Scan on prt2_p2 p2_1
-> Group
Group Key: (COALESCE(prt1_p3.a, p2_2.a)), (COALESCE(prt1_p3.b, p2_2.b))
Group Key: (COALESCE(prt1_2.a, p2_2.a)), (COALESCE(prt1_2.b, p2_2.b))
-> Sort
Sort Key: (COALESCE(prt1_p3.a, p2_2.a)), (COALESCE(prt1_p3.b, p2_2.b))
Sort Key: (COALESCE(prt1_2.a, p2_2.a)), (COALESCE(prt1_2.b, p2_2.b))
-> Merge Full Join
Merge Cond: ((prt1_p3.a = p2_2.a) AND (prt1_p3.b = p2_2.b))
Filter: ((COALESCE(prt1_p3.a, p2_2.a) >= 490) AND (COALESCE(prt1_p3.a, p2_2.a) <= 510))
Merge Cond: ((prt1_2.a = p2_2.a) AND (prt1_2.b = p2_2.b))
Filter: ((COALESCE(prt1_2.a, p2_2.a) >= 490) AND (COALESCE(prt1_2.a, p2_2.a) <= 510))
-> Sort
Sort Key: prt1_p3.a, prt1_p3.b
-> Seq Scan on prt1_p3
Sort Key: prt1_2.a, prt1_2.b
-> Seq Scan on prt1_p3 prt1_2
-> Sort
Sort Key: p2_2.a, p2_2.b
-> Seq Scan on prt2_p3 p2_2
@ -754,49 +754,49 @@ SELECT t1.a, t1.c, t2.b, t2.c, t3.a + t3.b, t3.c FROM (prt1 t1 LEFT JOIN prt2 t2
-- make sure these go to null as expected
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.phv, t2.b, t2.phv, t3.a + t3.b, t3.phv FROM ((SELECT 50 phv, * FROM prt1 WHERE prt1.b = 0) t1 FULL JOIN (SELECT 75 phv, * FROM prt2 WHERE prt2.a = 0) t2 ON (t1.a = t2.b)) FULL JOIN (SELECT 50 phv, * FROM prt1_e WHERE prt1_e.c = 0) t3 ON (t1.a = (t3.a + t3.b)/2) WHERE t1.a = t1.phv OR t2.b = t2.phv OR (t3.a + t3.b)/2 = t3.phv ORDER BY t1.a, t2.b, t3.a + t3.b;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------------------------------
Sort
Sort Key: prt1_p1.a, prt2_p1.b, ((prt1_e_p1.a + prt1_e_p1.b))
Sort Key: prt1.a, prt2.b, ((prt1_e.a + prt1_e.b))
-> Append
-> Hash Full Join
Hash Cond: (prt1_p1.a = ((prt1_e_p1.a + prt1_e_p1.b) / 2))
Filter: ((prt1_p1.a = (50)) OR (prt2_p1.b = (75)) OR (((prt1_e_p1.a + prt1_e_p1.b) / 2) = (50)))
Hash Cond: (prt1.a = ((prt1_e.a + prt1_e.b) / 2))
Filter: ((prt1.a = (50)) OR (prt2.b = (75)) OR (((prt1_e.a + prt1_e.b) / 2) = (50)))
-> Hash Full Join
Hash Cond: (prt1_p1.a = prt2_p1.b)
-> Seq Scan on prt1_p1
Hash Cond: (prt1.a = prt2.b)
-> Seq Scan on prt1_p1 prt1
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p1
-> Seq Scan on prt2_p1 prt2
Filter: (a = 0)
-> Hash
-> Seq Scan on prt1_e_p1
-> Seq Scan on prt1_e_p1 prt1_e
Filter: (c = 0)
-> Hash Full Join
Hash Cond: (prt1_p2.a = ((prt1_e_p2.a + prt1_e_p2.b) / 2))
Filter: ((prt1_p2.a = (50)) OR (prt2_p2.b = (75)) OR (((prt1_e_p2.a + prt1_e_p2.b) / 2) = (50)))
Hash Cond: (prt1_1.a = ((prt1_e_1.a + prt1_e_1.b) / 2))
Filter: ((prt1_1.a = (50)) OR (prt2_1.b = (75)) OR (((prt1_e_1.a + prt1_e_1.b) / 2) = (50)))
-> Hash Full Join
Hash Cond: (prt1_p2.a = prt2_p2.b)
-> Seq Scan on prt1_p2
Hash Cond: (prt1_1.a = prt2_1.b)
-> Seq Scan on prt1_p2 prt1_1
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p2
-> Seq Scan on prt2_p2 prt2_1
Filter: (a = 0)
-> Hash
-> Seq Scan on prt1_e_p2
-> Seq Scan on prt1_e_p2 prt1_e_1
Filter: (c = 0)
-> Hash Full Join
Hash Cond: (prt1_p3.a = ((prt1_e_p3.a + prt1_e_p3.b) / 2))
Filter: ((prt1_p3.a = (50)) OR (prt2_p3.b = (75)) OR (((prt1_e_p3.a + prt1_e_p3.b) / 2) = (50)))
Hash Cond: (prt1_2.a = ((prt1_e_2.a + prt1_e_2.b) / 2))
Filter: ((prt1_2.a = (50)) OR (prt2_2.b = (75)) OR (((prt1_e_2.a + prt1_e_2.b) / 2) = (50)))
-> Hash Full Join
Hash Cond: (prt1_p3.a = prt2_p3.b)
-> Seq Scan on prt1_p3
Hash Cond: (prt1_2.a = prt2_2.b)
-> Seq Scan on prt1_p3 prt1_2
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_p3
-> Seq Scan on prt2_p3 prt2_2
Filter: (a = 0)
-> Hash
-> Seq Scan on prt1_e_p3
-> Seq Scan on prt1_e_p3 prt1_e_2
Filter: (c = 0)
(42 rows)
@ -1064,22 +1064,22 @@ SELECT t1.a, t2.b FROM (SELECT * FROM prt1 WHERE a < 450) t1 LEFT JOIN (SELECT *
QUERY PLAN
-----------------------------------------------------------
Sort
Sort Key: prt1_p1.a, prt2_p2.b
Sort Key: prt1.a, prt2.b
-> Merge Left Join
Merge Cond: (prt1_p1.a = prt2_p2.b)
Merge Cond: (prt1.a = prt2.b)
-> Sort
Sort Key: prt1_p1.a
Sort Key: prt1.a
-> Append
-> Seq Scan on prt1_p1
-> Seq Scan on prt1_p1 prt1
Filter: ((a < 450) AND (b = 0))
-> Seq Scan on prt1_p2
-> Seq Scan on prt1_p2 prt1_1
Filter: ((a < 450) AND (b = 0))
-> Sort
Sort Key: prt2_p2.b
Sort Key: prt2.b
-> Append
-> Seq Scan on prt2_p2
-> Seq Scan on prt2_p2 prt2
Filter: (b > 250)
-> Seq Scan on prt2_p3
-> Seq Scan on prt2_p3 prt2_1
Filter: (b > 250)
(18 rows)
@ -1150,31 +1150,31 @@ INSERT INTO prt2_m SELECT i, i, i % 25 FROM generate_series(0, 599, 3) i;
ANALYZE prt2_m;
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1_m WHERE prt1_m.c = 0) t1 FULL JOIN (SELECT * FROM prt2_m WHERE prt2_m.c = 0) t2 ON (t1.a = (t2.b + t2.a)/2 AND t2.b = (t1.a + t1.b)/2) ORDER BY t1.a, t2.b;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
Sort
Sort Key: prt1_m_p1.a, prt2_m_p1.b
Sort Key: prt1_m.a, prt2_m.b
-> Append
-> Hash Full Join
Hash Cond: ((prt1_m_p1.a = ((prt2_m_p1.b + prt2_m_p1.a) / 2)) AND (((prt1_m_p1.a + prt1_m_p1.b) / 2) = prt2_m_p1.b))
-> Seq Scan on prt1_m_p1
Hash Cond: ((prt1_m.a = ((prt2_m.b + prt2_m.a) / 2)) AND (((prt1_m.a + prt1_m.b) / 2) = prt2_m.b))
-> Seq Scan on prt1_m_p1 prt1_m
Filter: (c = 0)
-> Hash
-> Seq Scan on prt2_m_p1
-> Seq Scan on prt2_m_p1 prt2_m
Filter: (c = 0)
-> Hash Full Join
Hash Cond: ((prt1_m_p2.a = ((prt2_m_p2.b + prt2_m_p2.a) / 2)) AND (((prt1_m_p2.a + prt1_m_p2.b) / 2) = prt2_m_p2.b))
-> Seq Scan on prt1_m_p2
Hash Cond: ((prt1_m_1.a = ((prt2_m_1.b + prt2_m_1.a) / 2)) AND (((prt1_m_1.a + prt1_m_1.b) / 2) = prt2_m_1.b))
-> Seq Scan on prt1_m_p2 prt1_m_1
Filter: (c = 0)
-> Hash
-> Seq Scan on prt2_m_p2
-> Seq Scan on prt2_m_p2 prt2_m_1
Filter: (c = 0)
-> Hash Full Join
Hash Cond: ((prt1_m_p3.a = ((prt2_m_p3.b + prt2_m_p3.a) / 2)) AND (((prt1_m_p3.a + prt1_m_p3.b) / 2) = prt2_m_p3.b))
-> Seq Scan on prt1_m_p3
Hash Cond: ((prt1_m_2.a = ((prt2_m_2.b + prt2_m_2.a) / 2)) AND (((prt1_m_2.a + prt1_m_2.b) / 2) = prt2_m_2.b))
-> Seq Scan on prt1_m_p3 prt1_m_2
Filter: (c = 0)
-> Hash
-> Seq Scan on prt2_m_p3
-> Seq Scan on prt2_m_p3 prt2_m_2
Filter: (c = 0)
(24 rows)
@ -1659,38 +1659,38 @@ SELECT t1.a, t1.c, t2.b, t2.c FROM prt1_l t1 RIGHT JOIN prt2_l t2 ON t1.a = t2.b
-- full join
EXPLAIN (COSTS OFF)
SELECT t1.a, t1.c, t2.b, t2.c FROM (SELECT * FROM prt1_l WHERE prt1_l.b = 0) t1 FULL JOIN (SELECT * FROM prt2_l WHERE prt2_l.a = 0) t2 ON (t1.a = t2.b AND t1.c = t2.c) ORDER BY t1.a, t2.b;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
QUERY PLAN
----------------------------------------------------------------------------------------------------
Sort
Sort Key: prt1_l_p1.a, prt2_l_p1.b
Sort Key: prt1_l.a, prt2_l.b
-> Append
-> Hash Full Join
Hash Cond: ((prt1_l_p1.a = prt2_l_p1.b) AND ((prt1_l_p1.c)::text = (prt2_l_p1.c)::text))
-> Seq Scan on prt1_l_p1
Hash Cond: ((prt1_l.a = prt2_l.b) AND ((prt1_l.c)::text = (prt2_l.c)::text))
-> Seq Scan on prt1_l_p1 prt1_l
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_l_p1
-> Seq Scan on prt2_l_p1 prt2_l
Filter: (a = 0)
-> Hash Full Join
Hash Cond: ((prt1_l_p2_p1.a = prt2_l_p2_p1.b) AND ((prt1_l_p2_p1.c)::text = (prt2_l_p2_p1.c)::text))
-> Seq Scan on prt1_l_p2_p1
Hash Cond: ((prt1_l_1.a = prt2_l_1.b) AND ((prt1_l_1.c)::text = (prt2_l_1.c)::text))
-> Seq Scan on prt1_l_p2_p1 prt1_l_1
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_l_p2_p1
-> Seq Scan on prt2_l_p2_p1 prt2_l_1
Filter: (a = 0)
-> Hash Full Join
Hash Cond: ((prt1_l_p2_p2.a = prt2_l_p2_p2.b) AND ((prt1_l_p2_p2.c)::text = (prt2_l_p2_p2.c)::text))
-> Seq Scan on prt1_l_p2_p2
Hash Cond: ((prt1_l_2.a = prt2_l_2.b) AND ((prt1_l_2.c)::text = (prt2_l_2.c)::text))
-> Seq Scan on prt1_l_p2_p2 prt1_l_2
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_l_p2_p2
-> Seq Scan on prt2_l_p2_p2 prt2_l_2
Filter: (a = 0)
-> Hash Full Join
Hash Cond: ((prt1_l_p3_p1.a = prt2_l_p3_p1.b) AND ((prt1_l_p3_p1.c)::text = (prt2_l_p3_p1.c)::text))
-> Seq Scan on prt1_l_p3_p1
Hash Cond: ((prt1_l_3.a = prt2_l_3.b) AND ((prt1_l_3.c)::text = (prt2_l_3.c)::text))
-> Seq Scan on prt1_l_p3_p1 prt1_l_3
Filter: (b = 0)
-> Hash
-> Seq Scan on prt2_l_p3_p1
-> Seq Scan on prt2_l_p3_p1 prt2_l_3
Filter: (a = 0)
(31 rows)
@ -1819,11 +1819,11 @@ WHERE EXISTS (
QUERY PLAN
---------------------------------------------------------------
Delete on prt1_l
Delete on prt1_l_p1
Delete on prt1_l_p3_p1
Delete on prt1_l_p3_p2
Delete on prt1_l_p1 prt1_l_1
Delete on prt1_l_p3_p1 prt1_l_2
Delete on prt1_l_p3_p2 prt1_l_3
-> Nested Loop Semi Join
-> Seq Scan on prt1_l_p1
-> Seq Scan on prt1_l_p1 prt1_l_1
Filter: (c IS NULL)
-> Nested Loop
-> Seq Scan on int4_tbl
@ -1831,7 +1831,7 @@ WHERE EXISTS (
-> Limit
-> Seq Scan on int8_tbl
-> Nested Loop Semi Join
-> Seq Scan on prt1_l_p3_p1
-> Seq Scan on prt1_l_p3_p1 prt1_l_2
Filter: (c IS NULL)
-> Nested Loop
-> Seq Scan on int4_tbl
@ -1839,7 +1839,7 @@ WHERE EXISTS (
-> Limit
-> Seq Scan on int8_tbl int8_tbl_1
-> Nested Loop Semi Join
-> Seq Scan on prt1_l_p3_p2
-> Seq Scan on prt1_l_p3_p2 prt1_l_3
Filter: (c IS NULL)
-> Nested Loop
-> Seq Scan on int4_tbl

File diff suppressed because it is too large Load Diff

View File

@ -664,9 +664,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1;
Append
-> Seq Scan on t1
Filter: ((a % 2) = 0)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a % 2) = 0)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a % 2) = 0)
(7 rows)
@ -691,9 +691,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
Append
-> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (((a % 2) = 0) AND f_leak(b))
(7 rows)
@ -714,9 +714,9 @@ EXPLAIN (COSTS OFF) SELECT *, t1 FROM t1;
Append
-> Seq Scan on t1
Filter: ((a % 2) = 0)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a % 2) = 0)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a % 2) = 0)
(7 rows)
@ -737,9 +737,9 @@ EXPLAIN (COSTS OFF) SELECT *, t1 FROM t1;
Append
-> Seq Scan on t1
Filter: ((a % 2) = 0)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a % 2) = 0)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a % 2) = 0)
(7 rows)
@ -761,9 +761,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 FOR SHARE;
-> Append
-> Seq Scan on t1
Filter: ((a % 2) = 0)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a % 2) = 0)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a % 2) = 0)
(8 rows)
@ -789,9 +789,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b) FOR SHARE;
-> Append
-> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (((a % 2) = 0) AND f_leak(b))
(8 rows)
@ -851,9 +851,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
Append
-> Seq Scan on t1
Filter: f_leak(b)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: f_leak(b)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: f_leak(b)
(7 rows)
@ -893,9 +893,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
Append
-> Seq Scan on t1
Filter: f_leak(b)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: f_leak(b)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: f_leak(b)
(7 rows)
@ -985,17 +985,17 @@ NOTICE: f_leak => my first satire
(4 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
------------------------------------------------------------
Append
InitPlan 1 (returns $0)
-> Index Scan using uaccount_pkey on uaccount
Index Cond: (pguser = CURRENT_USER)
-> Seq Scan on part_document_fiction
-> Seq Scan on part_document_fiction part_document
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_satire
-> Seq Scan on part_document_satire part_document_1
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_nonfiction
-> Seq Scan on part_document_nonfiction part_document_2
Filter: ((dlevel <= $0) AND f_leak(dtitle))
(10 rows)
@ -1027,17 +1027,17 @@ NOTICE: f_leak => awesome technology book
(10 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
------------------------------------------------------------
Append
InitPlan 1 (returns $0)
-> Index Scan using uaccount_pkey on uaccount
Index Cond: (pguser = CURRENT_USER)
-> Seq Scan on part_document_fiction
-> Seq Scan on part_document_fiction part_document
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_satire
-> Seq Scan on part_document_satire part_document_1
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_nonfiction
-> Seq Scan on part_document_nonfiction part_document_2
Filter: ((dlevel <= $0) AND f_leak(dtitle))
(10 rows)
@ -1059,7 +1059,7 @@ NOTICE: f_leak => awesome science fiction
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
--------------------------------------------------------------
Seq Scan on part_document_fiction
Seq Scan on part_document_fiction part_document
Filter: ((cid < 55) AND (dlevel <= $0) AND f_leak(dtitle))
InitPlan 1 (returns $0)
-> Index Scan using uaccount_pkey on uaccount
@ -1137,7 +1137,7 @@ NOTICE: f_leak => awesome science fiction
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
--------------------------------------------------------------
Seq Scan on part_document_fiction
Seq Scan on part_document_fiction part_document
Filter: ((cid < 55) AND (dlevel <= $0) AND f_leak(dtitle))
InitPlan 1 (returns $0)
-> Index Scan using uaccount_pkey on uaccount
@ -1174,17 +1174,17 @@ NOTICE: f_leak => awesome technology book
(11 rows)
EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
------------------------------------------------------------
Append
InitPlan 1 (returns $0)
-> Index Scan using uaccount_pkey on uaccount
Index Cond: (pguser = CURRENT_USER)
-> Seq Scan on part_document_fiction
-> Seq Scan on part_document_fiction part_document
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_satire
-> Seq Scan on part_document_satire part_document_1
Filter: ((dlevel <= $0) AND f_leak(dtitle))
-> Seq Scan on part_document_nonfiction
-> Seq Scan on part_document_nonfiction part_document_2
Filter: ((dlevel <= $0) AND f_leak(dtitle))
(10 rows)
@ -1229,11 +1229,11 @@ EXPLAIN (COSTS OFF) SELECT * FROM part_document WHERE f_leak(dtitle);
QUERY PLAN
---------------------------------------------------------------
Append
-> Seq Scan on part_document_fiction
-> Seq Scan on part_document_fiction part_document
Filter: ((dauthor = CURRENT_USER) AND f_leak(dtitle))
-> Seq Scan on part_document_satire
-> Seq Scan on part_document_satire part_document_1
Filter: ((dauthor = CURRENT_USER) AND f_leak(dtitle))
-> Seq Scan on part_document_nonfiction
-> Seq Scan on part_document_nonfiction part_document_2
Filter: ((dauthor = CURRENT_USER) AND f_leak(dtitle))
(7 rows)
@ -1511,9 +1511,9 @@ EXPLAIN (COSTS OFF) EXECUTE p1(2);
Append
-> Seq Scan on t1
Filter: ((a <= 2) AND ((a % 2) = 0))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a <= 2) AND ((a % 2) = 0))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a <= 2) AND ((a % 2) = 0))
(7 rows)
@ -1553,9 +1553,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM t1 WHERE f_leak(b);
Append
-> Seq Scan on t1
Filter: f_leak(b)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: f_leak(b)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: f_leak(b)
(7 rows)
@ -1572,14 +1572,14 @@ EXECUTE p1(2);
(6 rows)
EXPLAIN (COSTS OFF) EXECUTE p1(2);
QUERY PLAN
--------------------------
QUERY PLAN
---------------------------
Append
-> Seq Scan on t1
Filter: (a <= 2)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (a <= 2)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (a <= 2)
(7 rows)
@ -1593,14 +1593,14 @@ EXECUTE p2(2);
(3 rows)
EXPLAIN (COSTS OFF) EXECUTE p2(2);
QUERY PLAN
-------------------------
QUERY PLAN
---------------------------
Append
-> Seq Scan on t1
Filter: (a = 2)
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (a = 2)
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (a = 2)
(7 rows)
@ -1621,9 +1621,9 @@ EXPLAIN (COSTS OFF) EXECUTE p2(2);
Append
-> Seq Scan on t1
Filter: ((a = 2) AND ((a % 2) = 0))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: ((a = 2) AND ((a % 2) = 0))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a = 2) AND ((a % 2) = 0))
(7 rows)
@ -1636,13 +1636,13 @@ EXPLAIN (COSTS OFF) UPDATE t1 SET b = b || b WHERE f_leak(b);
-----------------------------------------------
Update on t1
Update on t1
Update on t2
Update on t3
Update on t2 t1_1
Update on t3 t1_2
-> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (((a % 2) = 0) AND f_leak(b))
(10 rows)
@ -1726,20 +1726,20 @@ WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
-----------------------------------------------------------------
Update on t1
Update on t1
Update on t2 t2_1
Update on t3
Update on t2 t1_1
Update on t3 t1_2
-> Nested Loop
-> Seq Scan on t1
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
-> Nested Loop
-> Seq Scan on t2 t2_1
-> Seq Scan on t2 t1_1
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
-> Nested Loop
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
Filter: ((a = 3) AND ((a % 2) = 1) AND f_leak(b))
@ -1758,9 +1758,9 @@ WHERE t1.a = 3 and t2.a = 3 AND f_leak(t1.b) AND f_leak(t2.b);
-> Append
-> Seq Scan on t1
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2 t2_1
-> Seq Scan on t2 t1_1
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: ((a = 3) AND ((a % 2) = 0) AND f_leak(b))
(11 rows)
@ -1884,13 +1884,13 @@ EXPLAIN (COSTS OFF) DELETE FROM t1 WHERE f_leak(b);
-----------------------------------------------
Delete on t1
Delete on t1
Delete on t2
Delete on t3
Delete on t2 t1_1
Delete on t3 t1_2
-> Seq Scan on t1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t2
-> Seq Scan on t2 t1_1
Filter: (((a % 2) = 0) AND f_leak(b))
-> Seq Scan on t3
-> Seq Scan on t3 t1_2
Filter: (((a % 2) = 0) AND f_leak(b))
(10 rows)

View File

@ -14,18 +14,18 @@ set max_parallel_workers_per_gather=4;
-- Parallel Append with partial-subplans
explain (costs off)
select round(avg(aa)), sum(aa) from a_star;
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
--------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 3
-> Partial Aggregate
-> Parallel Append
-> Parallel Seq Scan on d_star
-> Parallel Seq Scan on f_star
-> Parallel Seq Scan on e_star
-> Parallel Seq Scan on b_star
-> Parallel Seq Scan on c_star
-> Parallel Seq Scan on d_star a_star_3
-> Parallel Seq Scan on f_star a_star_5
-> Parallel Seq Scan on e_star a_star_4
-> Parallel Seq Scan on b_star a_star_1
-> Parallel Seq Scan on c_star a_star_2
-> Parallel Seq Scan on a_star
(11 rows)
@ -40,18 +40,18 @@ alter table c_star set (parallel_workers = 0);
alter table d_star set (parallel_workers = 0);
explain (costs off)
select round(avg(aa)), sum(aa) from a_star;
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
--------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 3
-> Partial Aggregate
-> Parallel Append
-> Seq Scan on d_star
-> Seq Scan on c_star
-> Parallel Seq Scan on f_star
-> Parallel Seq Scan on e_star
-> Parallel Seq Scan on b_star
-> Seq Scan on d_star a_star_3
-> Seq Scan on c_star a_star_2
-> Parallel Seq Scan on f_star a_star_5
-> Parallel Seq Scan on e_star a_star_4
-> Parallel Seq Scan on b_star a_star_1
-> Parallel Seq Scan on a_star
(11 rows)
@ -68,18 +68,18 @@ alter table e_star set (parallel_workers = 0);
alter table f_star set (parallel_workers = 0);
explain (costs off)
select round(avg(aa)), sum(aa) from a_star;
QUERY PLAN
--------------------------------------------
QUERY PLAN
-----------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 3
-> Partial Aggregate
-> Parallel Append
-> Seq Scan on d_star
-> Seq Scan on f_star
-> Seq Scan on e_star
-> Seq Scan on b_star
-> Seq Scan on c_star
-> Seq Scan on d_star a_star_3
-> Seq Scan on f_star a_star_5
-> Seq Scan on e_star a_star_4
-> Seq Scan on b_star a_star_1
-> Seq Scan on c_star a_star_2
-> Seq Scan on a_star
(11 rows)
@ -99,19 +99,19 @@ alter table f_star reset (parallel_workers);
set enable_parallel_append to off;
explain (costs off)
select round(avg(aa)), sum(aa) from a_star;
QUERY PLAN
-----------------------------------------------------
QUERY PLAN
--------------------------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 1
-> Partial Aggregate
-> Append
-> Parallel Seq Scan on a_star
-> Parallel Seq Scan on b_star
-> Parallel Seq Scan on c_star
-> Parallel Seq Scan on d_star
-> Parallel Seq Scan on e_star
-> Parallel Seq Scan on f_star
-> Parallel Seq Scan on b_star a_star_1
-> Parallel Seq Scan on c_star a_star_2
-> Parallel Seq Scan on d_star a_star_3
-> Parallel Seq Scan on e_star a_star_4
-> Parallel Seq Scan on f_star a_star_5
(11 rows)
select round(avg(aa)), sum(aa) from a_star a4;

View File

@ -200,11 +200,11 @@ explain (costs off)
-> Append
-> Sample Scan on person
Sampling: bernoulli ('100'::real)
-> Sample Scan on emp
-> Sample Scan on emp person_1
Sampling: bernoulli ('100'::real)
-> Sample Scan on student
-> Sample Scan on student person_2
Sampling: bernoulli ('100'::real)
-> Sample Scan on stud_emp
-> Sample Scan on stud_emp person_3
Sampling: bernoulli ('100'::real)
(10 rows)
@ -319,12 +319,12 @@ create table parted_sample_1 partition of parted_sample for values in (1);
create table parted_sample_2 partition of parted_sample for values in (2);
explain (costs off)
select * from parted_sample tablesample bernoulli (100);
QUERY PLAN
-------------------------------------------
QUERY PLAN
------------------------------------------------------
Append
-> Sample Scan on parted_sample_1
-> Sample Scan on parted_sample_1 parted_sample
Sampling: bernoulli ('100'::real)
-> Sample Scan on parted_sample_2
-> Sample Scan on parted_sample_2 parted_sample_1
Sampling: bernoulli ('100'::real)
(5 rows)

View File

@ -751,15 +751,15 @@ explain (costs off)
UNION ALL
SELECT ab FROM t2) t
ORDER BY 1 LIMIT 8;
QUERY PLAN
------------------------------------------------
QUERY PLAN
-----------------------------------------------------
Limit
-> Merge Append
Sort Key: ((t1.a || t1.b))
-> Index Scan using t1_ab_idx on t1
-> Index Scan using t1c_ab_idx on t1c
-> Index Scan using t1c_ab_idx on t1c t1_1
-> Index Scan using t2_pkey on t2
-> Index Scan using t2c_pkey on t2c
-> Index Scan using t2c_pkey on t2c t2_1
(7 rows)
SELECT * FROM
@ -798,8 +798,8 @@ select event_id
Sort Key: events.event_id
-> Index Scan using events_pkey on events
-> Sort
Sort Key: events_child.event_id
-> Seq Scan on events_child
Sort Key: events_1.event_id
-> Seq Scan on events_child events_1
-> Index Scan using other_events_pkey on other_events
(7 rows)

View File

@ -1548,28 +1548,28 @@ INSERT INTO other_tbl_parent VALUES (7),(200);
INSERT INTO other_tbl_child VALUES (8),(100);
EXPLAIN (costs off)
UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
QUERY PLAN
--------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------
Update on base_tbl_parent
Update on base_tbl_parent
Update on base_tbl_child
Update on base_tbl_child base_tbl_parent_1
-> Hash Join
Hash Cond: (other_tbl_parent.id = base_tbl_parent.a)
-> Append
-> Seq Scan on other_tbl_parent
-> Seq Scan on other_tbl_child
-> Seq Scan on other_tbl_child other_tbl_parent_1
-> Hash
-> Seq Scan on base_tbl_parent
-> Merge Join
Merge Cond: (base_tbl_child.a = other_tbl_parent.id)
Merge Cond: (base_tbl_parent_1.a = other_tbl_parent.id)
-> Sort
Sort Key: base_tbl_child.a
-> Seq Scan on base_tbl_child
Sort Key: base_tbl_parent_1.a
-> Seq Scan on base_tbl_child base_tbl_parent_1
-> Sort
Sort Key: other_tbl_parent.id
-> Append
-> Seq Scan on other_tbl_parent
-> Seq Scan on other_tbl_child
-> Seq Scan on other_tbl_child other_tbl_parent_1
(20 rows)
UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
@ -2284,37 +2284,37 @@ UPDATE v1 SET a=100 WHERE snoop(a) AND leakproof(a) AND a < 7 AND a != 6;
---------------------------------------------------------------------------------------------------------------------------
Update on public.t1
Update on public.t1
Update on public.t11
Update on public.t12
Update on public.t111
Update on public.t11 t1_1
Update on public.t12 t1_2
Update on public.t111 t1_3
-> Index Scan using t1_a_idx on public.t1
Output: 100, t1.b, t1.c, t1.ctid
Index Cond: ((t1.a > 5) AND (t1.a < 7))
Filter: ((t1.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1.a) AND leakproof(t1.a))
SubPlan 1
-> Append
-> Seq Scan on public.t12 t12_1
-> Seq Scan on public.t12
Filter: (t12.a = t1.a)
-> Seq Scan on public.t111 t12_1
Filter: (t12_1.a = t1.a)
-> Seq Scan on public.t111 t111_1
Filter: (t111_1.a = t1.a)
SubPlan 2
-> Append
-> Seq Scan on public.t12 t12_2
Output: t12_2.a
-> Seq Scan on public.t111 t111_2
Output: t111_2.a
-> Index Scan using t11_a_idx on public.t11
Output: 100, t11.b, t11.c, t11.d, t11.ctid
Index Cond: ((t11.a > 5) AND (t11.a < 7))
Filter: ((t11.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t11.a) AND leakproof(t11.a))
-> Index Scan using t12_a_idx on public.t12
Output: 100, t12.b, t12.c, t12.e, t12.ctid
Index Cond: ((t12.a > 5) AND (t12.a < 7))
Filter: ((t12.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t12.a) AND leakproof(t12.a))
-> Index Scan using t111_a_idx on public.t111
Output: 100, t111.b, t111.c, t111.d, t111.e, t111.ctid
Index Cond: ((t111.a > 5) AND (t111.a < 7))
Filter: ((t111.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t111.a) AND leakproof(t111.a))
-> Seq Scan on public.t111 t12_3
Output: t12_3.a
-> Index Scan using t11_a_idx on public.t11 t1_1
Output: 100, t1_1.b, t1_1.c, t1_1.d, t1_1.ctid
Index Cond: ((t1_1.a > 5) AND (t1_1.a < 7))
Filter: ((t1_1.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_1.a) AND leakproof(t1_1.a))
-> Index Scan using t12_a_idx on public.t12 t1_2
Output: 100, t1_2.b, t1_2.c, t1_2.e, t1_2.ctid
Index Cond: ((t1_2.a > 5) AND (t1_2.a < 7))
Filter: ((t1_2.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_2.a) AND leakproof(t1_2.a))
-> Index Scan using t111_a_idx on public.t111 t1_3
Output: 100, t1_3.b, t1_3.c, t1_3.d, t1_3.e, t1_3.ctid
Index Cond: ((t1_3.a > 5) AND (t1_3.a < 7))
Filter: ((t1_3.a <> 6) AND (alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_3.a) AND leakproof(t1_3.a))
(33 rows)
UPDATE v1 SET a=100 WHERE snoop(a) AND leakproof(a) AND a < 7 AND a != 6;
@ -2334,37 +2334,37 @@ UPDATE v1 SET a=a+1 WHERE snoop(a) AND leakproof(a) AND a = 8;
---------------------------------------------------------------------------------------------------------
Update on public.t1
Update on public.t1
Update on public.t11
Update on public.t12
Update on public.t111
Update on public.t11 t1_1
Update on public.t12 t1_2
Update on public.t111 t1_3
-> Index Scan using t1_a_idx on public.t1
Output: (t1.a + 1), t1.b, t1.c, t1.ctid
Index Cond: ((t1.a > 5) AND (t1.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1.a) AND leakproof(t1.a))
SubPlan 1
-> Append
-> Seq Scan on public.t12 t12_1
-> Seq Scan on public.t12
Filter: (t12.a = t1.a)
-> Seq Scan on public.t111 t12_1
Filter: (t12_1.a = t1.a)
-> Seq Scan on public.t111 t111_1
Filter: (t111_1.a = t1.a)
SubPlan 2
-> Append
-> Seq Scan on public.t12 t12_2
Output: t12_2.a
-> Seq Scan on public.t111 t111_2
Output: t111_2.a
-> Index Scan using t11_a_idx on public.t11
Output: (t11.a + 1), t11.b, t11.c, t11.d, t11.ctid
Index Cond: ((t11.a > 5) AND (t11.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t11.a) AND leakproof(t11.a))
-> Index Scan using t12_a_idx on public.t12
Output: (t12.a + 1), t12.b, t12.c, t12.e, t12.ctid
Index Cond: ((t12.a > 5) AND (t12.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t12.a) AND leakproof(t12.a))
-> Index Scan using t111_a_idx on public.t111
Output: (t111.a + 1), t111.b, t111.c, t111.d, t111.e, t111.ctid
Index Cond: ((t111.a > 5) AND (t111.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t111.a) AND leakproof(t111.a))
-> Seq Scan on public.t111 t12_3
Output: t12_3.a
-> Index Scan using t11_a_idx on public.t11 t1_1
Output: (t1_1.a + 1), t1_1.b, t1_1.c, t1_1.d, t1_1.ctid
Index Cond: ((t1_1.a > 5) AND (t1_1.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_1.a) AND leakproof(t1_1.a))
-> Index Scan using t12_a_idx on public.t12 t1_2
Output: (t1_2.a + 1), t1_2.b, t1_2.c, t1_2.e, t1_2.ctid
Index Cond: ((t1_2.a > 5) AND (t1_2.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_2.a) AND leakproof(t1_2.a))
-> Index Scan using t111_a_idx on public.t111 t1_3
Output: (t1_3.a + 1), t1_3.b, t1_3.c, t1_3.d, t1_3.e, t1_3.ctid
Index Cond: ((t1_3.a > 5) AND (t1_3.a = 8))
Filter: ((alternatives: SubPlan 1 or hashed SubPlan 2) AND snoop(t1_3.a) AND leakproof(t1_3.a))
(33 rows)
UPDATE v1 SET a=a+1 WHERE snoop(a) AND leakproof(a) AND a = 8;

View File

@ -310,29 +310,29 @@ ALTER TABLE part_b_10_b_20 ATTACH PARTITION part_c_1_100 FOR VALUES FROM (1) TO
-- The order of subplans should be in bound order
EXPLAIN (costs off) UPDATE range_parted set c = c - 50 WHERE c > 97;
QUERY PLAN
-------------------------------------
QUERY PLAN
-------------------------------------------------
Update on range_parted
Update on part_a_1_a_10
Update on part_a_10_a_20
Update on part_b_1_b_10
Update on part_c_1_100
Update on part_d_1_15
Update on part_d_15_20
Update on part_b_20_b_30
-> Seq Scan on part_a_1_a_10
Update on part_a_1_a_10 range_parted_1
Update on part_a_10_a_20 range_parted_2
Update on part_b_1_b_10 range_parted_3
Update on part_c_1_100 range_parted_4
Update on part_d_1_15 range_parted_5
Update on part_d_15_20 range_parted_6
Update on part_b_20_b_30 range_parted_7
-> Seq Scan on part_a_1_a_10 range_parted_1
Filter: (c > '97'::numeric)
-> Seq Scan on part_a_10_a_20
-> Seq Scan on part_a_10_a_20 range_parted_2
Filter: (c > '97'::numeric)
-> Seq Scan on part_b_1_b_10
-> Seq Scan on part_b_1_b_10 range_parted_3
Filter: (c > '97'::numeric)
-> Seq Scan on part_c_1_100
-> Seq Scan on part_c_1_100 range_parted_4
Filter: (c > '97'::numeric)
-> Seq Scan on part_d_1_15
-> Seq Scan on part_d_1_15 range_parted_5
Filter: (c > '97'::numeric)
-> Seq Scan on part_d_15_20
-> Seq Scan on part_d_15_20 range_parted_6
Filter: (c > '97'::numeric)
-> Seq Scan on part_b_20_b_30
-> Seq Scan on part_b_20_b_30 range_parted_7
Filter: (c > '97'::numeric)
(22 rows)

View File

@ -2185,9 +2185,9 @@ DELETE FROM a USING wcte WHERE aa = q2;
----------------------------------------------------
Delete on public.a
Delete on public.a
Delete on public.b
Delete on public.c
Delete on public.d
Delete on public.b a_1
Delete on public.c a_2
Delete on public.d a_3
CTE wcte
-> Insert on public.int8_tbl
Output: int8_tbl.q2
@ -2201,24 +2201,24 @@ DELETE FROM a USING wcte WHERE aa = q2;
-> CTE Scan on wcte
Output: wcte.*, wcte.q2
-> Nested Loop
Output: b.ctid, wcte.*
Join Filter: (b.aa = wcte.q2)
-> Seq Scan on public.b
Output: b.ctid, b.aa
Output: a_1.ctid, wcte.*
Join Filter: (a_1.aa = wcte.q2)
-> Seq Scan on public.b a_1
Output: a_1.ctid, a_1.aa
-> CTE Scan on wcte
Output: wcte.*, wcte.q2
-> Nested Loop
Output: c.ctid, wcte.*
Join Filter: (c.aa = wcte.q2)
-> Seq Scan on public.c
Output: c.ctid, c.aa
Output: a_2.ctid, wcte.*
Join Filter: (a_2.aa = wcte.q2)
-> Seq Scan on public.c a_2
Output: a_2.ctid, a_2.aa
-> CTE Scan on wcte
Output: wcte.*, wcte.q2
-> Nested Loop
Output: d.ctid, wcte.*
Join Filter: (d.aa = wcte.q2)
-> Seq Scan on public.d
Output: d.ctid, d.aa
Output: a_3.ctid, wcte.*
Join Filter: (a_3.aa = wcte.q2)
-> Seq Scan on public.d a_3
Output: a_3.ctid, a_3.aa
-> CTE Scan on wcte
Output: wcte.*, wcte.q2
(38 rows)

View File

@ -202,8 +202,13 @@ CREATE TABLE part (a INT, b INT) PARTITION BY LIST (a);
CREATE TABLE part_p1 PARTITION OF part FOR VALUES IN (-2,-1,0,1,2);
CREATE TABLE part_p2 PARTITION OF part DEFAULT PARTITION BY RANGE(a);
CREATE TABLE part_p2_p1 PARTITION OF part_p2 DEFAULT;
CREATE TABLE part_rev (b INT, c INT, a INT);
ALTER TABLE part ATTACH PARTITION part_rev FOR VALUES IN (3); -- fail
ALTER TABLE part_rev DROP COLUMN c;
ALTER TABLE part ATTACH PARTITION part_rev FOR VALUES IN (3); -- now it's ok
INSERT INTO part VALUES (-1,-1), (1,1), (2,NULL), (NULL,-2),(NULL,NULL);
EXPLAIN (COSTS OFF) SELECT tableoid::regclass as part, a, b FROM part WHERE a IS NULL ORDER BY 1, 2, 3;
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM part p(x) ORDER BY x;
--
-- some more cases