From: Tomas Vondra Date: Thu, 20 Apr 2017 22:41:13 +0000 (+0200) Subject: Resolve most failures in join regression tests X-Git-Tag: XL_10_R1BETA1~360 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=04a9ac87f03607bef925ca715fa1d75ae7ab8c16;p=postgres-xl.git Resolve most failures in join regression tests This resolves most failures in 'join' regression suite. The expected results were produced by running the new join.sql script on XL 9.5, with a few tweaks of the explain plans (partial aggregates etc.) --- diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out index 777e8f0d20..14ea363a74 100644 --- a/src/test/regress/expected/join.out +++ b/src/test/regress/expected/join.out @@ -2227,20 +2227,22 @@ explain (costs off) select * from int8_tbl i1 left join (int8_tbl i2 join (select 123 as x) ss on i2.q1 = x) on i1.q2 = i2.q2 order by 1, 2; - QUERY PLAN -------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------ Sort Sort Key: i1.q1, i1.q2 -> Hash Left Join Hash Cond: (i1.q2 = i2.q2) - -> Seq Scan on int8_tbl i1 + -> Remote Subquery Scan on all (datanode_1) + -> Seq Scan on int8_tbl i1 -> Hash -> Hash Join Hash Cond: (i2.q1 = (123)) - -> Seq Scan on int8_tbl i2 + -> Remote Subquery Scan on all (datanode_1) + -> Seq Scan on int8_tbl i2 -> Hash -> Result -(11 rows) +(13 rows) select * from int8_tbl i1 left join (int8_tbl i2 join (select 123 as x) ss on i2.q1 = x) on i1.q2 = i2.q2 @@ -2282,18 +2284,19 @@ select a.f1, b.f1, t.thousand, t.tenthous from (select sum(f1)+1 as f1 from int4_tbl i4a) a, (select sum(f1) as f1 from int4_tbl i4b) b where b.f1 = t.thousand and a.f1 = b.f1 and (a.f1+b.f1+999) = t.tenthous; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ - Nested Loop - -> Aggregate - -> Seq Scan on int4_tbl i4b + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) -> Nested Loop - Join Filter: ((sum(i4b.f1)) = ((sum(i4a.f1) + 1))) -> Aggregate - -> Seq Scan on int4_tbl i4a - -> Index Only Scan using tenk1_thous_tenthous on tenk1 t - Index Cond: ((thousand = (sum(i4b.f1))) AND (tenthous = ((((sum(i4a.f1) + 1)) + (sum(i4b.f1))) + 999))) -(9 rows) + -> Seq Scan on int4_tbl i4b + -> Nested Loop + Join Filter: ((sum(i4b.f1)) = ((sum(i4a.f1) + 1))) + -> Aggregate + -> Seq Scan on int4_tbl i4a + -> Index Only Scan using tenk1_thous_tenthous on tenk1 t + Index Cond: ((thousand = (sum(i4b.f1))) AND (tenthous = ((((sum(i4a.f1) + 1)) + (sum(i4b.f1))) + 999))) +(10 rows) select a.f1, b.f1, t.thousand, t.tenthous from tenk1 t, @@ -2411,16 +2414,22 @@ set enable_mergejoin to off; explain (costs off) select count(*) from tenk1 a, tenk1 b where a.hundred = b.thousand and (b.fivethous % 10) < 10; - QUERY PLAN ------------------------------------------------------------- - Aggregate - -> Hash Join - Hash Cond: (a.hundred = b.thousand) - -> Index Only Scan using tenk1_hundred on tenk1 a - -> Hash - -> Seq Scan on tenk1 b - Filter: ((fivethous % 10) < 10) -(7 rows) + QUERY PLAN +----------------------------------------------------------------------------------- + Finalize Aggregate + -> Remote Subquery Scan on all (datanode_1,datanode_2) + -> Partial Aggregate + -> Hash Join + Hash Cond: (a.hundred = b.thousand) + -> Remote Subquery Scan on all (datanode_1,datanode_2) + Distribute results by H: hundred + -> Index Only Scan using tenk1_hundred on tenk1 a + -> Hash + -> Remote Subquery Scan on all (datanode_1,datanode_2) + Distribute results by H: thousand + -> Seq Scan on tenk1 b + Filter: ((fivethous % 10) < 10) +(13 rows) select count(*) from tenk1 a, tenk1 b where a.hundred = b.thousand and (b.fivethous % 10) < 10; @@ -3063,7 +3072,7 @@ where thousand = a.q1 and tenthous = b.q1 and a.q2 = 1 and b.q2 = 2; -- -- test a corner case in which we shouldn't apply the star-schema optimization -- -explain (costs off) +explain (costs off, nodes off) select t1.unique2, t1.stringu1, t2.unique1, t2.stringu2 from tenk1 t1 inner join int4_tbl i1 @@ -3076,8 +3085,8 @@ select t1.unique2, t1.stringu1, t2.unique1, t2.stringu2 from left join tenk1 t2 on (subq1.y1 = t2.unique1) where t1.unique2 < 42 and t1.stringu1 > t2.stringu2; - QUERY PLAN ------------------------------------------------------------------------ + QUERY PLAN +----------------------------------------------------------------------------------- Nested Loop Join Filter: (t1.stringu1 > t2.stringu2) -> Nested Loop @@ -3087,12 +3096,18 @@ where t1.unique2 < 42 and t1.stringu1 > t2.stringu2; Join Filter: ((1) = (1)) -> Result -> Result - -> Index Scan using tenk1_unique2 on tenk1 t1 - Index Cond: ((unique2 = (11)) AND (unique2 < 42)) - -> Seq Scan on int4_tbl i1 - -> Index Scan using tenk1_unique1 on tenk1 t2 - Index Cond: (unique1 = (3)) -(14 rows) + -> Materialize + -> Remote Subquery Scan on all + -> Index Scan using tenk1_unique2 on tenk1 t1 + Index Cond: ((unique2 = (11)) AND (unique2 < 42)) + -> Materialize + -> Remote Subquery Scan on all + -> Seq Scan on int4_tbl i1 + -> Materialize + -> Remote Subquery Scan on all + -> Index Scan using tenk1_unique1 on tenk1 t2 + Index Cond: (unique1 = (3)) +(20 rows) select t1.unique2, t1.stringu1, t2.unique1, t2.stringu2 from tenk1 t1 @@ -3536,10 +3551,11 @@ using (join_key); -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: i2.unique2 Distribute results by H: unique2 + Sort Key: i2.unique2 -> Index Only Scan using tenk1_unique2 on public.tenk1 i2 Output: i2.unique2 Index Cond: (i2.unique2 = i1.f1) -(24 rows) +(25 rows) select foo1.join_key as foo1_id, foo3.join_key AS foo3_id, bug_field from (values (0),(1)) foo1(join_key) @@ -3573,39 +3589,41 @@ select t1.* from on (t1.f1 = b1.d1) left join int4_tbl i4 on (i8.q2 = i4.f1); - QUERY PLAN ----------------------------------------------------------------------- - Hash Left Join + QUERY PLAN +---------------------------------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) Output: t1.f1 - Hash Cond: (i8.q2 = i4.f1) - -> Nested Loop Left Join - Output: t1.f1, i8.q2 - Join Filter: (t1.f1 = '***'::text) - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - -> Materialize - Output: i8.q2 - -> Hash Right Join + -> Hash Left Join + Output: t1.f1 + Hash Cond: (i8.q2 = i4.f1) + -> Nested Loop Left Join + Output: t1.f1, i8.q2 + Join Filter: (t1.f1 = '***'::text) + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + -> Materialize Output: i8.q2 - Hash Cond: ((NULL::integer) = i8b1.q2) - -> Hash Left Join - Output: i8.q2, (NULL::integer) - Hash Cond: (i8.q1 = i8b2.q1) - -> Seq Scan on public.int8_tbl i8 - Output: i8.q1, i8.q2 + -> Hash Right Join + Output: i8.q2 + Hash Cond: ((NULL::integer) = i8b1.q2) + -> Hash Left Join + Output: i8.q2, (NULL::integer) + Hash Cond: (i8.q1 = i8b2.q1) + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + -> Hash + Output: i8b2.q1, (NULL::integer) + -> Seq Scan on public.int8_tbl i8b2 + Output: i8b2.q1, NULL::integer -> Hash - Output: i8b2.q1, (NULL::integer) - -> Seq Scan on public.int8_tbl i8b2 - Output: i8b2.q1, NULL::integer - -> Hash - Output: i8b1.q2 - -> Seq Scan on public.int8_tbl i8b1 Output: i8b1.q2 - -> Hash - Output: i4.f1 - -> Seq Scan on public.int4_tbl i4 + -> Seq Scan on public.int8_tbl i8b1 + Output: i8b1.q2 + -> Hash Output: i4.f1 -(30 rows) + -> Seq Scan on public.int4_tbl i4 + Output: i4.f1 +(32 rows) select t1.* from text_tbl t1 @@ -3619,8 +3637,8 @@ select t1.* from on (i8.q2 = i4.f1); f1 ------------------- - doh! hi de ho neighbor + doh! (2 rows) explain (verbose, costs off) @@ -3634,43 +3652,45 @@ select t1.* from on (t1.f1 = b1.d1) left join int4_tbl i4 on (i8.q2 = i4.f1); - QUERY PLAN ----------------------------------------------------------------------------- - Hash Left Join + QUERY PLAN +---------------------------------------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) Output: t1.f1 - Hash Cond: (i8.q2 = i4.f1) - -> Nested Loop Left Join - Output: t1.f1, i8.q2 - Join Filter: (t1.f1 = '***'::text) - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - -> Materialize - Output: i8.q2 - -> Hash Right Join + -> Hash Left Join + Output: t1.f1 + Hash Cond: (i8.q2 = i4.f1) + -> Nested Loop Left Join + Output: t1.f1, i8.q2 + Join Filter: (t1.f1 = '***'::text) + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + -> Materialize Output: i8.q2 - Hash Cond: ((NULL::integer) = i8b1.q2) -> Hash Right Join - Output: i8.q2, (NULL::integer) - Hash Cond: (i8b2.q1 = i8.q1) - -> Nested Loop - Output: i8b2.q1, NULL::integer - -> Seq Scan on public.int8_tbl i8b2 - Output: i8b2.q1, i8b2.q2 - -> Materialize - -> Seq Scan on public.int4_tbl i4b2 - -> Hash - Output: i8.q1, i8.q2 - -> Seq Scan on public.int8_tbl i8 + Output: i8.q2 + Hash Cond: ((NULL::integer) = i8b1.q2) + -> Hash Right Join + Output: i8.q2, (NULL::integer) + Hash Cond: (i8b2.q1 = i8.q1) + -> Nested Loop + Output: i8b2.q1, NULL::integer + -> Seq Scan on public.int8_tbl i8b2 + Output: i8b2.q1, i8b2.q2 + -> Materialize + -> Seq Scan on public.int4_tbl i4b2 + -> Hash Output: i8.q1, i8.q2 - -> Hash - Output: i8b1.q2 - -> Seq Scan on public.int8_tbl i8b1 + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + -> Hash Output: i8b1.q2 - -> Hash - Output: i4.f1 - -> Seq Scan on public.int4_tbl i4 + -> Seq Scan on public.int8_tbl i8b1 + Output: i8b1.q2 + -> Hash Output: i4.f1 -(34 rows) + -> Seq Scan on public.int4_tbl i4 + Output: i4.f1 +(36 rows) select t1.* from text_tbl t1 @@ -3684,8 +3704,8 @@ select t1.* from on (i8.q2 = i4.f1); f1 ------------------- - doh! hi de ho neighbor + doh! (2 rows) explain (verbose, costs off) @@ -3700,46 +3720,48 @@ select t1.* from on (t1.f1 = b1.d1) left join int4_tbl i4 on (i8.q2 = i4.f1); - QUERY PLAN ----------------------------------------------------------------------------- - Hash Left Join + QUERY PLAN +---------------------------------------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) Output: t1.f1 - Hash Cond: (i8.q2 = i4.f1) - -> Nested Loop Left Join - Output: t1.f1, i8.q2 - Join Filter: (t1.f1 = '***'::text) - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - -> Materialize - Output: i8.q2 - -> Hash Right Join + -> Hash Left Join + Output: t1.f1 + Hash Cond: (i8.q2 = i4.f1) + -> Nested Loop Left Join + Output: t1.f1, i8.q2 + Join Filter: (t1.f1 = '***'::text) + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + -> Materialize Output: i8.q2 - Hash Cond: ((NULL::integer) = i8b1.q2) -> Hash Right Join - Output: i8.q2, (NULL::integer) - Hash Cond: (i8b2.q1 = i8.q1) - -> Hash Join - Output: i8b2.q1, NULL::integer - Hash Cond: (i8b2.q1 = i4b2.f1) - -> Seq Scan on public.int8_tbl i8b2 - Output: i8b2.q1, i8b2.q2 - -> Hash - Output: i4b2.f1 - -> Seq Scan on public.int4_tbl i4b2 + Output: i8.q2 + Hash Cond: ((NULL::integer) = i8b1.q2) + -> Hash Right Join + Output: i8.q2, (NULL::integer) + Hash Cond: (i8b2.q1 = i8.q1) + -> Hash Join + Output: i8b2.q1, NULL::integer + Hash Cond: (i8b2.q1 = i4b2.f1) + -> Seq Scan on public.int8_tbl i8b2 + Output: i8b2.q1, i8b2.q2 + -> Hash Output: i4b2.f1 - -> Hash - Output: i8.q1, i8.q2 - -> Seq Scan on public.int8_tbl i8 + -> Seq Scan on public.int4_tbl i4b2 + Output: i4b2.f1 + -> Hash Output: i8.q1, i8.q2 - -> Hash - Output: i8b1.q2 - -> Seq Scan on public.int8_tbl i8b1 + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + -> Hash Output: i8b1.q2 - -> Hash - Output: i4.f1 - -> Seq Scan on public.int4_tbl i4 + -> Seq Scan on public.int8_tbl i8b1 + Output: i8b1.q2 + -> Hash Output: i4.f1 -(37 rows) + -> Seq Scan on public.int4_tbl i4 + Output: i4.f1 +(39 rows) select t1.* from text_tbl t1 @@ -3754,8 +3776,8 @@ select t1.* from on (i8.q2 = i4.f1); f1 ------------------- - doh! hi de ho neighbor + doh! (2 rows) explain (verbose, costs off) @@ -3767,28 +3789,32 @@ select * from on t1.f1 = 'doh!' left join int4_tbl i4 on i8.q1 = i4.f1; - QUERY PLAN --------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------- Nested Loop Left Join Output: t1.f1, i8.q1, i8.q2, t2.f1, i4.f1 - -> Seq Scan on public.text_tbl t2 + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: t2.f1 + -> Seq Scan on public.text_tbl t2 + Output: t2.f1 -> Materialize Output: i8.q1, i8.q2, i4.f1, t1.f1 - -> Nested Loop + -> Remote Subquery Scan on all (datanode_2) Output: i8.q1, i8.q2, i4.f1, t1.f1 - -> Nested Loop Left Join - Output: i8.q1, i8.q2, i4.f1 - Join Filter: (i8.q1 = i4.f1) - -> Seq Scan on public.int8_tbl i8 - Output: i8.q1, i8.q2 - Filter: (i8.q2 = 456) - -> Seq Scan on public.int4_tbl i4 - Output: i4.f1 - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - Filter: (t1.f1 = 'doh!'::text) -(19 rows) + -> Nested Loop + Output: i8.q1, i8.q2, i4.f1, t1.f1 + -> Nested Loop Left Join + Output: i8.q1, i8.q2, i4.f1 + Join Filter: (i8.q1 = i4.f1) + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + Filter: (i8.q2 = 456) + -> Seq Scan on public.int4_tbl i4 + Output: i4.f1 + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + Filter: (t1.f1 = 'doh!'::text) +(23 rows) select * from text_tbl t1 @@ -3800,8 +3826,8 @@ select * from on i8.q1 = i4.f1; f1 | q1 | q2 | f1 | f1 ------+-----+-----+-------------------+---- - doh! | 123 | 456 | doh! | doh! | 123 | 456 | hi de ho neighbor | + doh! | 123 | 456 | doh! | (2 rows) -- @@ -3814,25 +3840,31 @@ select * from on i8.q2 = 123, lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss where t1.f1 = ss.f1; - QUERY PLAN --------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------- Nested Loop Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1 Join Filter: (t1.f1 = t2.f1) - -> Nested Loop Left Join + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: t1.f1, i8.q1, i8.q2 - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - -> Materialize - Output: i8.q1, i8.q2 - -> Seq Scan on public.int8_tbl i8 + -> Nested Loop Left Join + Output: t1.f1, i8.q1, i8.q2 + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + -> Materialize Output: i8.q1, i8.q2 - Filter: (i8.q2 = 123) + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + Filter: (i8.q2 = 123) -> Limit Output: (i8.q1), t2.f1 - -> Seq Scan on public.text_tbl t2 + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: i8.q1, t2.f1 -(16 rows) + -> Limit + Output: (i8.q1), t2.f1 + -> Seq Scan on public.text_tbl t2 + Output: i8.q1, t2.f1 +(22 rows) select * from text_tbl t1 @@ -3840,9 +3872,9 @@ select * from on i8.q2 = 123, lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss where t1.f1 = ss.f1; - f1 | q1 | q2 | q1 | f1 -------+------------------+-----+------------------+------ - doh! | 4567890123456789 | 123 | 4567890123456789 | doh! + f1 | q1 | q2 | q1 | f1 +-------------------+------------------+-----+------------------+------------------- + hi de ho neighbor | 4567890123456789 | 123 | 4567890123456789 | hi de ho neighbor (1 row) explain (verbose, costs off) @@ -3853,31 +3885,41 @@ select * from lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss1, lateral (select ss1.* from text_tbl t3 limit 1) as ss2 where t1.f1 = ss2.f1; - QUERY PLAN -------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------- Nested Loop Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1, ((i8.q1)), (t2.f1) Join Filter: (t1.f1 = (t2.f1)) -> Nested Loop Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1 - -> Nested Loop Left Join + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: t1.f1, i8.q1, i8.q2 - -> Seq Scan on public.text_tbl t1 - Output: t1.f1 - -> Materialize - Output: i8.q1, i8.q2 - -> Seq Scan on public.int8_tbl i8 + -> Nested Loop Left Join + Output: t1.f1, i8.q1, i8.q2 + -> Seq Scan on public.text_tbl t1 + Output: t1.f1 + -> Materialize Output: i8.q1, i8.q2 - Filter: (i8.q2 = 123) + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + Filter: (i8.q2 = 123) -> Limit Output: (i8.q1), t2.f1 - -> Seq Scan on public.text_tbl t2 + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: i8.q1, t2.f1 + -> Limit + Output: (i8.q1), t2.f1 + -> Seq Scan on public.text_tbl t2 + Output: i8.q1, t2.f1 -> Limit Output: ((i8.q1)), (t2.f1) - -> Seq Scan on public.text_tbl t3 + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: (i8.q1), t2.f1 -(22 rows) + -> Limit + Output: ((i8.q1)), (t2.f1) + -> Seq Scan on public.text_tbl t3 + Output: (i8.q1), t2.f1 +(32 rows) select * from text_tbl t1 @@ -3886,9 +3928,9 @@ select * from lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss1, lateral (select ss1.* from text_tbl t3 limit 1) as ss2 where t1.f1 = ss2.f1; - f1 | q1 | q2 | q1 | f1 | q1 | f1 -------+------------------+-----+------------------+------+------------------+------ - doh! | 4567890123456789 | 123 | 4567890123456789 | doh! | 4567890123456789 | doh! + f1 | q1 | q2 | q1 | f1 | q1 | f1 +-------------------+------------------+-----+------------------+-------------------+------------------+------------------- + hi de ho neighbor | 4567890123456789 | 123 | 4567890123456789 | hi de ho neighbor | 4567890123456789 | hi de ho neighbor (1 row) explain (verbose, costs off) @@ -3899,38 +3941,47 @@ select 1 from left join text_tbl as tt4 on (tt3.f1 = tt4.f1), lateral (select tt4.f1 as c0 from text_tbl as tt5 limit 1) as ss1 where tt1.f1 = ss1.c0; - QUERY PLAN ----------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------- Nested Loop Output: 1 -> Nested Loop Left Join Output: tt1.f1, tt4.f1 -> Nested Loop Output: tt1.f1 - -> Seq Scan on public.text_tbl tt1 + -> Remote Subquery Scan on all (datanode_2) Output: tt1.f1 - Filter: (tt1.f1 = 'foo'::text) - -> Seq Scan on public.text_tbl tt2 - Output: tt2.f1 + -> Seq Scan on public.text_tbl tt1 + Output: tt1.f1 + Filter: (tt1.f1 = 'foo'::text) + -> Materialize + -> Remote Subquery Scan on all (datanode_1,datanode_2) + -> Seq Scan on public.text_tbl tt2 -> Materialize Output: tt4.f1 - -> Nested Loop Left Join + -> Remote Subquery Scan on all (datanode_2) Output: tt4.f1 - Join Filter: (tt3.f1 = tt4.f1) - -> Seq Scan on public.text_tbl tt3 - Output: tt3.f1 - Filter: (tt3.f1 = 'foo'::text) - -> Seq Scan on public.text_tbl tt4 + -> Nested Loop Left Join Output: tt4.f1 - Filter: (tt4.f1 = 'foo'::text) + Join Filter: (tt3.f1 = tt4.f1) + -> Seq Scan on public.text_tbl tt3 + Output: tt3.f1 + Filter: (tt3.f1 = 'foo'::text) + -> Seq Scan on public.text_tbl tt4 + Output: tt4.f1 + Filter: (tt4.f1 = 'foo'::text) -> Subquery Scan on ss1 Output: ss1.c0 Filter: (ss1.c0 = 'foo'::text) -> Limit Output: (tt4.f1) - -> Seq Scan on public.text_tbl tt5 + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: tt4.f1 -(29 rows) + -> Limit + Output: (tt4.f1) + -> Seq Scan on public.text_tbl tt5 + Output: tt4.f1 +(38 rows) select 1 from text_tbl as tt1 @@ -3956,34 +4007,40 @@ select ss2.* from on i41.f1 = ss1.c1, lateral (select i41.*, i8.*, ss1.* from text_tbl limit 1) ss2 where ss1.c2 = 0; - QUERY PLAN ------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------ Nested Loop Output: (i41.f1), (i8.q1), (i8.q2), (i42.f1), (i43.f1), ((42)) - -> Hash Join + -> Remote Subquery Scan on all (datanode_1) Output: i41.f1, i42.f1, i8.q1, i8.q2, i43.f1, 42 - Hash Cond: (i41.f1 = i42.f1) - -> Nested Loop - Output: i8.q1, i8.q2, i43.f1, i41.f1 + -> Hash Join + Output: i41.f1, i42.f1, i8.q1, i8.q2, i43.f1, 42 + Hash Cond: (i41.f1 = i42.f1) -> Nested Loop - Output: i8.q1, i8.q2, i43.f1 - -> Seq Scan on public.int8_tbl i8 - Output: i8.q1, i8.q2 - Filter: (i8.q1 = 0) - -> Seq Scan on public.int4_tbl i43 - Output: i43.f1 - Filter: (i43.f1 = 0) - -> Seq Scan on public.int4_tbl i41 - Output: i41.f1 - -> Hash - Output: i42.f1 - -> Seq Scan on public.int4_tbl i42 + Output: i8.q1, i8.q2, i43.f1, i41.f1 + -> Nested Loop + Output: i8.q1, i8.q2, i43.f1 + -> Seq Scan on public.int8_tbl i8 + Output: i8.q1, i8.q2 + Filter: (i8.q1 = 0) + -> Seq Scan on public.int4_tbl i43 + Output: i43.f1 + Filter: (i43.f1 = 0) + -> Seq Scan on public.int4_tbl i41 + Output: i41.f1 + -> Hash Output: i42.f1 + -> Seq Scan on public.int4_tbl i42 + Output: i42.f1 -> Limit Output: (i41.f1), (i8.q1), (i8.q2), (i42.f1), (i43.f1), ((42)) - -> Seq Scan on public.text_tbl + -> Remote Subquery Scan on all (datanode_1,datanode_2) Output: i41.f1, i8.q1, i8.q2, i42.f1, i43.f1, (42) -(25 rows) + -> Limit + Output: (i41.f1), (i8.q1), (i8.q2), (i42.f1), (i43.f1), ((42)) + -> Seq Scan on public.text_tbl + Output: i41.f1, i8.q1, i8.q2, i42.f1, i43.f1, (42) +(31 rows) select ss2.* from int4_tbl i41 @@ -4007,17 +4064,18 @@ select * from left join (tenk1 as a1 full join (select 1 as id) as yy on (a1.unique1 = yy.id)) on (xx.id = coalesce(yy.id)); - QUERY PLAN ---------------------------------------- + QUERY PLAN +----------------------------------------------------------------- Nested Loop Left Join Join Filter: ((1) = COALESCE((1))) -> Result -> Hash Full Join Hash Cond: (a1.unique1 = (1)) - -> Seq Scan on tenk1 a1 + -> Remote Subquery Scan on all (datanode_1,datanode_2) + -> Seq Scan on tenk1 a1 -> Hash -> Result -(8 rows) +(9 rows) select * from (select 1 as id) as xx @@ -4388,10 +4446,11 @@ select t1.* from on t1.f1 = t2.f1 left join uniquetbl t3 on t2.d1 = t3.f1; - QUERY PLAN --------------------------- - Seq Scan on uniquetbl t1 -(1 row) + QUERY PLAN +----------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) + -> Seq Scan on uniquetbl t1 +(2 rows) explain (costs off) select t0.* @@ -4405,18 +4464,21 @@ from left join uniquetbl u1 ON u1.f1 = t1.string4) ss on t0.f1 = ss.case1 where ss.stringu2 !~* ss.case1; - QUERY PLAN --------------------------------------------------------------------------------------------- - Nested Loop - Join Filter: (CASE t1.ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END = t0.f1) + QUERY PLAN +-------------------------------------------------------------------------------------------------------- + Remote Subquery Scan on all (datanode_1,datanode_2) -> Nested Loop - -> Seq Scan on int4_tbl i4 - -> Index Scan using tenk1_unique2 on tenk1 t1 - Index Cond: (unique2 = i4.f1) - Filter: (stringu2 !~* CASE ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END) - -> Materialize - -> Seq Scan on text_tbl t0 -(9 rows) + Join Filter: ((CASE t1.ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END) = t0.f1) + -> Remote Subquery Scan on all (datanode_1,datanode_2) + Distribute results by H: CASE ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END + -> Nested Loop + -> Seq Scan on int4_tbl i4 + -> Index Scan using tenk1_unique2 on tenk1 t1 + Index Cond: (unique2 = i4.f1) + Filter: (stringu2 !~* CASE ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END) + -> Materialize + -> Seq Scan on text_tbl t0 +(12 rows) select t0.* from @@ -4913,57 +4975,59 @@ select x.* from select v.* from (int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy); + lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy) + order by vx, vy; vx | vy -------------------+------------------- - 123 | - 456 | + -4567890123456789 | + 123 | 456 123 | 4567890123456789 - 4567890123456789 | -4567890123456789 123 | 4567890123456789 - 4567890123456789 | 4567890123456789 123 | 4567890123456789 + 123 | 4567890123456789 + 123 | + 456 | + 4567890123456789 | -4567890123456789 + 4567890123456789 | -4567890123456789 + 4567890123456789 | 123 4567890123456789 | 123 4567890123456789 | 123 - 123 | 4567890123456789 4567890123456789 | 123 - 123 | 456 4567890123456789 | 4567890123456789 - 4567890123456789 | -4567890123456789 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 - 4567890123456789 | 123 + 4567890123456789 | 4567890123456789 4567890123456789 | - -4567890123456789 | (20 rows) select v.* from (int8_tbl x left join (select q1,(select coalesce(q2,0)) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy); + lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy) + order by vx, vy; vx | vy -------------------+------------------- - 4567890123456789 | 123 + -4567890123456789 | 123 | 456 - 4567890123456789 | 123 123 | 4567890123456789 - 4567890123456789 | 4567890123456789 - 4567890123456789 | 123 123 | 4567890123456789 + 123 | 4567890123456789 + 123 | 4567890123456789 + 123 | + 456 | + 4567890123456789 | -4567890123456789 + 4567890123456789 | -4567890123456789 + 4567890123456789 | 123 + 4567890123456789 | 123 + 4567890123456789 | 123 4567890123456789 | 123 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 - 123 | 4567890123456789 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 - 4567890123456789 | -4567890123456789 - 123 | 4567890123456789 - 4567890123456789 | -4567890123456789 - 123 | - 456 | + 4567890123456789 | 4567890123456789 4567890123456789 | - -4567890123456789 | (20 rows) create temp table dual(); @@ -4972,29 +5036,30 @@ analyze dual; select v.* from (int8_tbl x left join (select q1,(select coalesce(q2,0)) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 from dual union all select x.q2,y.q2 from dual) v(vx,vy); + lateral (select x.q1,y.q1 from dual union all select x.q2,y.q2 from dual) v(vx,vy) + order by vx, vy; vx | vy -------------------+------------------- - 4567890123456789 | 123 + -4567890123456789 | 123 | 456 - 4567890123456789 | 123 123 | 4567890123456789 - 4567890123456789 | 4567890123456789 - 4567890123456789 | 123 123 | 4567890123456789 + 123 | 4567890123456789 + 123 | 4567890123456789 + 123 | + 456 | + 4567890123456789 | -4567890123456789 + 4567890123456789 | -4567890123456789 + 4567890123456789 | 123 + 4567890123456789 | 123 + 4567890123456789 | 123 4567890123456789 | 123 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 - 123 | 4567890123456789 4567890123456789 | 4567890123456789 4567890123456789 | 4567890123456789 - 4567890123456789 | -4567890123456789 - 123 | 4567890123456789 - 4567890123456789 | -4567890123456789 - 123 | - 456 | + 4567890123456789 | 4567890123456789 4567890123456789 | - -4567890123456789 | (20 rows) explain (verbose, num_nodes off, nodes off, costs off) @@ -5416,36 +5481,44 @@ lateral (select * from int8_tbl t1, where q2 = (select greatest(t1.q1,t2.q2)) and (select v.id=0)) offset 0) ss2) ss where t1.q1 = ss.q2) ss0; - QUERY PLAN ------------------------------------------------------------------ + QUERY PLAN +----------------------------------------------------------------------------------- Nested Loop Output: "*VALUES*".column1, t1.q1, t1.q2, ss2.q1, ss2.q2 - -> Seq Scan on public.int8_tbl t1 + -> Remote Subquery Scan on all (datanode_1) Output: t1.q1, t1.q2 + -> Seq Scan on public.int8_tbl t1 + Output: t1.q1, t1.q2 -> Nested Loop Output: "*VALUES*".column1, ss2.q1, ss2.q2 -> Values Scan on "*VALUES*" Output: "*VALUES*".column1 - -> Subquery Scan on ss2 + -> Materialize Output: ss2.q1, ss2.q2 - Filter: (t1.q1 = ss2.q2) - -> Seq Scan on public.int8_tbl t2 - Output: t2.q1, t2.q2 - Filter: (SubPlan 3) - SubPlan 3 - -> Result - Output: t3.q2 - One-Time Filter: $4 - InitPlan 1 (returns $2) - -> Result - Output: GREATEST($0, t2.q2) - InitPlan 2 (returns $4) - -> Result - Output: ($3 = 0) - -> Seq Scan on public.int8_tbl t3 - Output: t3.q1, t3.q2 - Filter: (t3.q2 = $2) -(27 rows) + -> Remote Subquery Scan on all (datanode_1) + Output: ss2.q1, ss2.q2 + -> Subquery Scan on ss2 + Output: ss2.q1, ss2.q2 + Filter: (t1.q1 = ss2.q2) + -> Seq Scan on public.int8_tbl t2 + Output: t2.q1, t2.q2 + Filter: (SubPlan 3) + SubPlan 3 + -> Remote Subquery Scan on all (datanode_1) + Output: t3.q2 + -> Result + Output: t3.q2 + One-Time Filter: $4 + InitPlan 1 (returns $2) + -> Result + Output: GREATEST($0, t2.q2) + InitPlan 2 (returns $4) + -> Result + Output: ($3 = 0) + -> Seq Scan on public.int8_tbl t3 + Output: t3.q1, t3.q2 + Filter: (t3.q2 = $2) +(35 rows) select * from (values (0), (1)) v(id), lateral (select * from int8_tbl t1, @@ -5455,12 +5528,9 @@ lateral (select * from int8_tbl t1, where q2 = (select greatest(t1.q1,t2.q2)) and (select v.id=0)) offset 0) ss2) ss where t1.q1 = ss.q2) ss0; - id | q1 | q2 | q1 | q2 -----+------------------+-------------------+------------------+------------------ - 0 | 4567890123456789 | 123 | 4567890123456789 | 4567890123456789 - 0 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 - 0 | 4567890123456789 | -4567890123456789 | 4567890123456789 | 4567890123456789 -(3 rows) + id | q1 | q2 | q1 | q2 +----+----+----+----+---- +(0 rows) -- test some error cases where LATERAL should have been used but wasn't select f1,g from int4_tbl a, (select f1 as g) ss; diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql index fa0b9f4c22..f5998c313f 100644 --- a/src/test/regress/sql/join.sql +++ b/src/test/regress/sql/join.sql @@ -1613,18 +1613,21 @@ select x.* from select v.* from (int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy); + lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy) + order by vx, vy; select v.* from (int8_tbl x left join (select q1,(select coalesce(q2,0)) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy); + lateral (select x.q1,y.q1 union all select x.q2,y.q2) v(vx,vy) + order by vx, vy; create temp table dual(); insert into dual default values; analyze dual; select v.* from (int8_tbl x left join (select q1,(select coalesce(q2,0)) q2 from int8_tbl) y on x.q2 = y.q1) left join int4_tbl z on z.f1 = x.q2, - lateral (select x.q1,y.q1 from dual union all select x.q2,y.q2 from dual) v(vx,vy); + lateral (select x.q1,y.q1 from dual union all select x.q2,y.q2 from dual) v(vx,vy) + order by vx, vy; explain (verbose, num_nodes off, nodes off, costs off) select * from