mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Improve EXPLAIN's display of SubPlan nodes and output parameters.
Historically we've printed SubPlan expression nodes as "(SubPlan N)", which is pretty uninformative. Trying to reproduce the original SQL for the subquery is still as impractical as before, and would be mighty verbose as well. However, we can still do better than that. Displaying the "testexpr" when present, and adding a keyword to indicate the SubLinkType, goes a long way toward showing what's really going on. In addition, this patch gets rid of EXPLAIN's use of "$n" to represent subplan and initplan output Params. Instead we now print "(SubPlan N).colX" or "(InitPlan N).colX" to represent the X'th output column of that subplan. This eliminates confusion with the use of "$n" to represent PARAM_EXTERN Params, and it's useful for the first part of this change because it eliminates needing some other indication of which subplan is referenced by a SubPlan that has a testexpr. In passing, this adds simple regression test coverage of the ROWCOMPARE_SUBLINK code paths, which were entirely unburdened by testing before. Tom Lane and Dean Rasheed, reviewed by Aleksander Alekseev. Thanks to Chantal Keller for raising the question of whether this area couldn't be improved. Discussion: https://postgr.es/m/2838538.1705692747@sss.pgh.pa.us
This commit is contained in:
@ -3062,10 +3062,10 @@ select exists(select 1 from pg_enum), sum(c1) from ft1;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------
|
||||
Foreign Scan
|
||||
Output: $0, (sum(ft1.c1))
|
||||
Output: (InitPlan 1).col1, (sum(ft1.c1))
|
||||
Relations: Aggregate on (public.ft1)
|
||||
Remote SQL: SELECT sum("C 1") FROM "S 1"."T 1"
|
||||
InitPlan 1 (returns $0)
|
||||
InitPlan 1
|
||||
-> Seq Scan on pg_catalog.pg_enum
|
||||
(6 rows)
|
||||
|
||||
@ -3080,8 +3080,8 @@ select exists(select 1 from pg_enum), sum(c1) from ft1 group by 1;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------
|
||||
GroupAggregate
|
||||
Output: $0, sum(ft1.c1)
|
||||
InitPlan 1 (returns $0)
|
||||
Output: (InitPlan 1).col1, sum(ft1.c1)
|
||||
InitPlan 1
|
||||
-> Seq Scan on pg_catalog.pg_enum
|
||||
-> Foreign Scan on public.ft1
|
||||
Output: ft1.c1
|
||||
@ -3305,10 +3305,10 @@ select sum(c1) filter (where (c1 / c1) * random() <= 1) from ft1 group by c2 ord
|
||||
|
||||
explain (verbose, costs off)
|
||||
select sum(c2) filter (where c2 in (select c2 from ft1 where c2 < 5)) from ft1;
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------
|
||||
Aggregate
|
||||
Output: sum(ft1.c2) FILTER (WHERE (hashed SubPlan 1))
|
||||
Output: sum(ft1.c2) FILTER (WHERE (ANY (ft1.c2 = (hashed SubPlan 1).col1)))
|
||||
-> Foreign Scan on public.ft1
|
||||
Output: ft1.c2
|
||||
Remote SQL: SELECT c2 FROM "S 1"."T 1"
|
||||
@ -6171,9 +6171,9 @@ UPDATE ft2 AS target SET (c2, c7) = (
|
||||
Update on public.ft2 target
|
||||
Remote SQL: UPDATE "S 1"."T 1" SET c2 = $2, c7 = $3 WHERE ctid = $1
|
||||
-> Foreign Scan on public.ft2 target
|
||||
Output: $1, $2, (SubPlan 1 (returns $1,$2)), target.ctid, target.*
|
||||
Output: (SubPlan 1).col1, (SubPlan 1).col2, (rescan SubPlan 1), target.ctid, target.*
|
||||
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8, ctid FROM "S 1"."T 1" WHERE (("C 1" > 1100)) FOR UPDATE
|
||||
SubPlan 1 (returns $1,$2)
|
||||
SubPlan 1
|
||||
-> Foreign Scan on public.ft2 src
|
||||
Output: (src.c2 * 10), src.c7
|
||||
Remote SQL: SELECT c2, c7 FROM "S 1"."T 1" WHERE (($1::integer = "C 1"))
|
||||
@ -11685,9 +11685,9 @@ SELECT * FROM local_tbl t1 LEFT JOIN (SELECT *, (SELECT count(*) FROM async_pt W
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------
|
||||
Nested Loop Left Join
|
||||
Output: t1.a, t1.b, t1.c, async_pt.a, async_pt.b, async_pt.c, ($0)
|
||||
Output: t1.a, t1.b, t1.c, async_pt.a, async_pt.b, async_pt.c, ((InitPlan 1).col1)
|
||||
Join Filter: (t1.a = async_pt.a)
|
||||
InitPlan 1 (returns $0)
|
||||
InitPlan 1
|
||||
-> Aggregate
|
||||
Output: count(*)
|
||||
-> Append
|
||||
@ -11699,10 +11699,10 @@ SELECT * FROM local_tbl t1 LEFT JOIN (SELECT *, (SELECT count(*) FROM async_pt W
|
||||
Output: t1.a, t1.b, t1.c
|
||||
-> Append
|
||||
-> Async Foreign Scan on public.async_p1 async_pt_1
|
||||
Output: async_pt_1.a, async_pt_1.b, async_pt_1.c, $0
|
||||
Output: async_pt_1.a, async_pt_1.b, async_pt_1.c, (InitPlan 1).col1
|
||||
Remote SQL: SELECT a, b, c FROM public.base_tbl1 WHERE ((a < 3000))
|
||||
-> Async Foreign Scan on public.async_p2 async_pt_2
|
||||
Output: async_pt_2.a, async_pt_2.b, async_pt_2.c, $0
|
||||
Output: async_pt_2.a, async_pt_2.b, async_pt_2.c, (InitPlan 1).col1
|
||||
Remote SQL: SELECT a, b, c FROM public.base_tbl2 WHERE ((a < 3000))
|
||||
(20 rows)
|
||||
|
||||
@ -11713,7 +11713,7 @@ SELECT * FROM local_tbl t1 LEFT JOIN (SELECT *, (SELECT count(*) FROM async_pt W
|
||||
Nested Loop Left Join (actual rows=1 loops=1)
|
||||
Join Filter: (t1.a = async_pt.a)
|
||||
Rows Removed by Join Filter: 399
|
||||
InitPlan 1 (returns $0)
|
||||
InitPlan 1
|
||||
-> Aggregate (actual rows=1 loops=1)
|
||||
-> Append (actual rows=400 loops=1)
|
||||
-> Async Foreign Scan on async_p1 async_pt_4 (actual rows=200 loops=1)
|
||||
@ -11936,11 +11936,11 @@ CREATE FOREIGN TABLE foreign_tbl2 () INHERITS (foreign_tbl)
|
||||
SERVER loopback OPTIONS (table_name 'base_tbl');
|
||||
EXPLAIN (VERBOSE, COSTS OFF)
|
||||
SELECT a FROM base_tbl WHERE (a, random() > 0) IN (SELECT a, random() > 0 FROM foreign_tbl);
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------------
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------
|
||||
Seq Scan on public.base_tbl
|
||||
Output: base_tbl.a
|
||||
Filter: (SubPlan 1)
|
||||
Filter: (ANY ((base_tbl.a = (SubPlan 1).col1) AND ((random() > '0'::double precision) = (SubPlan 1).col2)))
|
||||
SubPlan 1
|
||||
-> Result
|
||||
Output: base_tbl.a, (random() > '0'::double precision)
|
||||
|
Reference in New Issue
Block a user