diff --git a/src/backend/gporca/libgpopt/src/operators/CPhysicalInnerIndexNLJoin.cpp b/src/backend/gporca/libgpopt/src/operators/CPhysicalInnerIndexNLJoin.cpp index 3b55aa7f00c..7ddf43be0ac 100644 --- a/src/backend/gporca/libgpopt/src/operators/CPhysicalInnerIndexNLJoin.cpp +++ b/src/backend/gporca/libgpopt/src/operators/CPhysicalInnerIndexNLJoin.cpp @@ -17,6 +17,7 @@ #include "gpopt/base/CDistributionSpecHashed.h" #include "gpopt/base/CDistributionSpecNonSingleton.h" #include "gpopt/base/CDistributionSpecReplicated.h" +#include "gpopt/exception.h" #include "gpopt/operators/CExpressionHandle.h" #include "gpopt/operators/CPredicateUtils.h" @@ -118,6 +119,13 @@ CPhysicalInnerIndexNLJoin::Ped(CMemoryPool *mp, CExpressionHandle &exprhdl, CEnfdDistribution::EDistributionMatching dmatch = Edm(prppInput, child_index, pdrgpdpCtxt, ulDistrReq); + // FIXME: nestloop with inner index scan may produce wrong plan, see + // issue https://github.com/cloudberrydb/cloudberrydb/issues/567 + // Fallback to postgres optimizer to avoid wrong plan. We should + // fix this issue and remove the following exception. + GPOS_RAISE(gpopt::ExmaGPOPT, gpopt::ExmiUnsupportedOp, + GPOS_WSZ_LIT("Fallback: InnerIndexNestLoopJoin may have wrong plan")); + if (1 == child_index) { // inner (index-scan side) is requested for Any distribution, diff --git a/src/test/regress/expected/aggregates_optimizer.out b/src/test/regress/expected/aggregates_optimizer.out index 87d3dd7ee53..c11ead43317 100644 --- a/src/test/regress/expected/aggregates_optimizer.out +++ b/src/test/regress/expected/aggregates_optimizer.out @@ -1346,31 +1346,39 @@ explain (costs off) select a,c from t1 group by a,c,d; explain (costs off) select * from t1 inner join t2 on t1.a = t2.x and t1.b = t2.y group by t1.a,t1.b,t1.c,t1.d,t2.x,t2.y,t2.z; - QUERY PLAN -------------------------------------------------------- +INFO: GPORCA failed to produce a plan, falling back to planner +DETAIL: Operator Fallback: InnerIndexNestLoopJoin may have wrong plan not supported + QUERY PLAN +------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on t1 - -> Index Scan using t2_pkey on t2 - Index Cond: ((x = t1.a) AND (y = t1.b)) - Optimizer: Pivotal Optimizer (GPORCA) -(7 rows) + -> HashAggregate + Group Key: t1.a, t1.b, t2.x, t2.y + -> Hash Join + Hash Cond: ((t2.x = t1.a) AND (t2.y = t1.b)) + -> Seq Scan on t2 + -> Hash + -> Seq Scan on t1 + Optimizer: Postgres query optimizer +(9 rows) -- Test case where t1 can be optimized but not t2 explain (costs off) select t1.*,t2.x,t2.z from t1 inner join t2 on t1.a = t2.x and t1.b = t2.y group by t1.a,t1.b,t1.c,t1.d,t2.x,t2.z; - QUERY PLAN -------------------------------------------------------- +INFO: GPORCA failed to produce a plan, falling back to planner +DETAIL: Operator Fallback: InnerIndexNestLoopJoin may have wrong plan not supported + QUERY PLAN +------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on t1 - -> Index Scan using t2_pkey on t2 - Index Cond: ((x = t1.a) AND (y = t1.b)) - Optimizer: Pivotal Optimizer (GPORCA) -(7 rows) + -> HashAggregate + Group Key: t1.a, t1.b, t2.x, t2.z + -> Hash Join + Hash Cond: ((t2.x = t1.a) AND (t2.y = t1.b)) + -> Seq Scan on t2 + -> Hash + -> Seq Scan on t1 + Optimizer: Postgres query optimizer +(9 rows) -- Cannot optimize when PK is deferrable explain (costs off) select * from t3 group by a,b,c; diff --git a/src/test/regress/expected/bfv_index_optimizer.out b/src/test/regress/expected/bfv_index_optimizer.out index 79d79e94792..b9ea7a31778 100644 --- a/src/test/regress/expected/bfv_index_optimizer.out +++ b/src/test/regress/expected/bfv_index_optimizer.out @@ -127,213 +127,89 @@ explain SELECT count(*) FROM bfv_tab2_facttable1 ft, bfv_tab2_dimdate dt, bfv_tab2_dimtabl1 dt1 WHERE ft.wk_id = dt.wk_id AND ft.id = dt1.id; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- - Aggregate (cost=0.00..1250.34 rows=1 width=8) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1250.34 rows=7 width=1) - -> Hash Join (cost=0.00..1250.34 rows=3 width=1) - Hash Cond: (bfv_tab2_dimdate.wk_id = bfv_tab2_facttable1_1_prt_2.wk_id) - -> Seq Scan on bfv_tab2_dimdate (cost=0.00..431.00 rows=4 width=2) - -> Hash (cost=819.34..819.34 rows=3 width=2) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..819.34 rows=3 width=2) - Hash Key: bfv_tab2_facttable1_1_prt_2.wk_id - -> Nested Loop (cost=0.00..819.34 rows=3 width=2) - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) (cost=0.00..431.00 rows=7 width=4) - -> Seq Scan on bfv_tab2_dimtabl1 (cost=0.00..431.00 rows=3 width=4) - -> Append (cost=0.00..388.34 rows=1 width=2) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_2 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_2_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_3 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_3_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_4 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_4_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_5 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_5_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_6 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_6_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_7 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_7_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_8 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_8_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_9 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_9_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_10 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_10_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_11 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_11_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_12 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_12_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_13 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_13_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_14 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_14_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_15 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_15_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_16 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_16_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_17 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_17_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_18 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_18_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_19 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_19_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_20 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_20_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_21 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_21_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_dflt (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_dflt_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - Optimizer: Pivotal Optimizer (GPORCA) -(98 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Aggregate (cost=23.80..23.81 rows=1 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.28..23.79 rows=3 width=0) + -> Hash Join (cost=2.28..23.74 rows=1 width=0) + Hash Cond: (ft.wk_id = dt.wk_id) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=1.20..22.65 rows=2 width=2) + Hash Key: ft.wk_id + -> Hash Join (cost=1.20..22.60 rows=2 width=2) + Hash Cond: (ft.id = dt1.id) + -> Append (cost=0.00..21.32 rows=21 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_2 ft_1 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_3 ft_2 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_4 ft_3 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_5 ft_4 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_6 ft_5 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_7 ft_6 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_8 ft_7 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_9 ft_8 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_10 ft_9 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_11 ft_10 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_12 ft_11 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_13 ft_12 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_14 ft_13 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_15 ft_14 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_16 ft_15 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_17 ft_16 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_18 ft_17 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_19 ft_18 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_20 ft_19 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_21 ft_20 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_dflt ft_21 (cost=0.00..1.01 rows=1 width=6) + -> Hash (cost=1.12..1.12 rows=7 width=4) + -> Broadcast Motion 3:3 (slice3; segments: 3) (cost=0.00..1.12 rows=7 width=4) + -> Seq Scan on bfv_tab2_dimtabl1 dt1 (cost=0.00..1.02 rows=2 width=4) + -> Hash (cost=1.03..1.03 rows=3 width=2) + -> Seq Scan on bfv_tab2_dimdate dt (cost=0.00..1.03 rows=3 width=2) + Optimizer: Postgres query optimizer +(36 rows) explain SELECT count(*) FROM bfv_tab2_facttable1 ft, bfv_tab2_dimdate dt, bfv_tab2_dimtabl1 dt1 WHERE ft.wk_id = dt.wk_id AND ft.id = dt1.id; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- - Aggregate (cost=0.00..1250.34 rows=1 width=8) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1250.34 rows=7 width=1) - -> Hash Join (cost=0.00..1250.34 rows=3 width=1) - Hash Cond: (bfv_tab2_dimdate.wk_id = bfv_tab2_facttable1_1_prt_2.wk_id) - -> Seq Scan on bfv_tab2_dimdate (cost=0.00..431.00 rows=4 width=2) - -> Hash (cost=819.34..819.34 rows=3 width=2) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..819.34 rows=3 width=2) - Hash Key: bfv_tab2_facttable1_1_prt_2.wk_id - -> Nested Loop (cost=0.00..819.34 rows=3 width=2) - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) (cost=0.00..431.00 rows=7 width=4) - -> Seq Scan on bfv_tab2_dimtabl1 (cost=0.00..431.00 rows=3 width=4) - -> Append (cost=0.00..388.34 rows=1 width=2) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_2 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_2_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_3 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_3_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_4 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_4_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_5 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_5_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_6 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_6_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_7 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_7_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_8 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_8_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_9 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_9_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_10 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_10_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_11 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_11_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_12 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_12_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_13 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_13_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_14 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_14_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_15 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_15_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_16 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_16_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_17 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_17_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_18 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_18_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_19 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_19_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_20 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_20_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_21 (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_21_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Heap Scan on bfv_tab2_facttable1_1_prt_dflt (cost=0.00..388.34 rows=1 width=2) - Recheck Cond: (id = bfv_tab2_dimtabl1.id) - -> Bitmap Index Scan on bfv_tab2_facttable1_1_prt_dflt_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bfv_tab2_dimtabl1.id) - Optimizer: Pivotal Optimizer (GPORCA) -(98 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + Aggregate (cost=23.80..23.81 rows=1 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.28..23.79 rows=3 width=0) + -> Hash Join (cost=2.28..23.74 rows=1 width=0) + Hash Cond: (ft.wk_id = dt.wk_id) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=1.20..22.65 rows=2 width=2) + Hash Key: ft.wk_id + -> Hash Join (cost=1.20..22.60 rows=2 width=2) + Hash Cond: (ft.id = dt1.id) + -> Append (cost=0.00..21.32 rows=21 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_2 ft_1 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_3 ft_2 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_4 ft_3 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_5 ft_4 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_6 ft_5 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_7 ft_6 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_8 ft_7 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_9 ft_8 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_10 ft_9 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_11 ft_10 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_12 ft_11 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_13 ft_12 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_14 ft_13 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_15 ft_14 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_16 ft_15 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_17 ft_16 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_18 ft_17 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_19 ft_18 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_20 ft_19 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_21 ft_20 (cost=0.00..1.01 rows=1 width=6) + -> Seq Scan on bfv_tab2_facttable1_1_prt_dflt ft_21 (cost=0.00..1.01 rows=1 width=6) + -> Hash (cost=1.12..1.12 rows=7 width=4) + -> Broadcast Motion 3:3 (slice3; segments: 3) (cost=0.00..1.12 rows=7 width=4) + -> Seq Scan on bfv_tab2_dimtabl1 dt1 (cost=0.00..1.02 rows=2 width=4) + -> Hash (cost=1.03..1.03 rows=3 width=2) + -> Seq Scan on bfv_tab2_dimdate dt (cost=0.00..1.03 rows=3 width=2) + Optimizer: Postgres query optimizer +(36 rows) -- start_ignore create language plpython3u; @@ -641,17 +517,16 @@ set seq_page_cost=10000000; set enable_indexscan=on; set enable_nestloop=on; explain select * from nestloop_x as x, nestloop_y as y where x.i + x.j < y.j; - QUERY PLAN ------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..551.01 rows=56 width=16) - -> Nested Loop (cost=0.00..551.01 rows=19 width=16) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.00 rows=20 width=8) - -> Seq Scan on nestloop_x (cost=0.00..431.00 rows=7 width=8) - -> Index Scan using nestloop_y_idx on nestloop_y (cost=0.00..120.01 rows=1 width=8) - Index Cond: (j > (nestloop_x.i + nestloop_x.j)) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.17..407971033.00 rows=2471070000 width=16) + -> Nested Loop (cost=0.17..375023433.00 rows=823690000 width=16) + -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..340001435.00 rows=86100 width=8) + -> Seq Scan on nestloop_x x (cost=0.00..340000287.00 rows=28700 width=8) + -> Index Scan using nestloop_y_idx on nestloop_y y (cost=0.17..311.09 rows=9567 width=8) + Index Cond: (j > (x.i + x.j)) + Optimizer: Postgres query optimizer +(7 rows) select * from nestloop_x as x, nestloop_y as y where x.i + x.j < y.j; i | j | i | j @@ -668,17 +543,16 @@ select * from nestloop_x as x, nestloop_y as y where x.i + x.j < y.j; (9 rows) explain select * from nestloop_x as x, nestloop_y as y where y.j > x.i + x.j + 2; - QUERY PLAN ------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..551.01 rows=56 width=16) - -> Nested Loop (cost=0.00..551.01 rows=19 width=16) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.00 rows=20 width=8) - -> Seq Scan on nestloop_x (cost=0.00..431.00 rows=7 width=8) - -> Index Scan using nestloop_y_idx on nestloop_y (cost=0.00..120.01 rows=1 width=8) - Index Cond: (j > ((nestloop_x.i + nestloop_x.j) + 2)) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.17..407971248.25 rows=2471070000 width=16) + -> Nested Loop (cost=0.17..375023648.25 rows=823690000 width=16) + -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..340001435.00 rows=86100 width=8) + -> Seq Scan on nestloop_x x (cost=0.00..340000287.00 rows=28700 width=8) + -> Index Scan using nestloop_y_idx on nestloop_y y (cost=0.17..311.10 rows=9567 width=8) + Index Cond: (j > ((x.i + x.j) + 2)) + Optimizer: Postgres query optimizer +(7 rows) select * from nestloop_x as x, nestloop_y as y where y.j > x.i + x.j + 2; i | j | i | j diff --git a/src/test/regress/expected/co_nestloop_idxscan_optimizer.out b/src/test/regress/expected/co_nestloop_idxscan_optimizer.out index 5ed4940b1f6..efd5eef89fe 100644 --- a/src/test/regress/expected/co_nestloop_idxscan_optimizer.out +++ b/src/test/regress/expected/co_nestloop_idxscan_optimizer.out @@ -27,16 +27,14 @@ create index foo_id_idx on co_nestloop_idxscan.foo(id); explain select f.id from co_nestloop_idxscan.foo f, co_nestloop_idxscan.bar b where f.id = b.id; QUERY PLAN ------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..499.13 rows=1 width=8) - -> Nested Loop (cost=0.00..499.13 rows=1 width=8) - Join Filter: true - -> Seq Scan on bar (cost=0.00..431.00 rows=1 width=8) - -> Bitmap Heap Scan on foo (cost=0.00..68.13 rows=1 width=8) - Recheck Cond: (id = bar.id) - -> Bitmap Index Scan on foo_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bar.id) - Optimizer: Pivotal Optimizer (GPORCA) version 3.72.0 -(9 rows) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.02..510.33 rows=6 width=8) + -> Hash Join (cost=1.02..510.25 rows=2 width=8) + Hash Cond: (f.id = b.id) + -> Seq Scan on foo f (cost=0.00..509.17 rows=17 width=8) + -> Hash (cost=1.01..1.01 rows=1 width=8) + -> Seq Scan on bar b (cost=0.00..1.01 rows=1 width=8) + Optimizer: Postgres query optimizer +(7 rows) select f.id from co_nestloop_idxscan.foo f, co_nestloop_idxscan.bar b where f.id = b.id; id @@ -51,16 +49,15 @@ set enable_nestloop=on; explain select f.id from co_nestloop_idxscan.foo f, co_nestloop_idxscan.bar b where f.id = b.id; QUERY PLAN ------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..499.13 rows=1 width=8) - -> Nested Loop (cost=0.00..499.13 rows=1 width=8) - Join Filter: true - -> Seq Scan on bar (cost=0.00..431.00 rows=1 width=8) - -> Bitmap Heap Scan on foo (cost=0.00..68.13 rows=1 width=8) - Recheck Cond: (id = bar.id) - -> Bitmap Index Scan on foo_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bar.id) - Optimizer: Pivotal Optimizer (GPORCA) version 3.72.0 -(9 rows) + Gather Motion 3:1 (slice1; segments: 3) (cost=8.15..13.26 rows=6 width=8) + -> Nested Loop (cost=8.15..13.18 rows=2 width=8) + -> Seq Scan on bar b (cost=0.00..1.01 rows=1 width=8) + -> Bitmap Heap Scan on foo f (cost=8.15..12.16 rows=1 width=8) + Recheck Cond: (id = b.id) + -> Bitmap Index Scan on foo_id_idx (cost=0.00..8.15 rows=1 width=0) + Index Cond: (id = b.id) + Optimizer: Postgres query optimizer +(8 rows) select f.id from co_nestloop_idxscan.foo f, co_nestloop_idxscan.bar b where f.id = b.id; id @@ -76,16 +73,15 @@ set enable_seqscan = off; explain select f.id from co_nestloop_idxscan.bar b, co_nestloop_idxscan.foo f where f.id = b.id; QUERY PLAN ------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..499.13 rows=1 width=8) - -> Nested Loop (cost=0.00..499.13 rows=1 width=8) - Join Filter: true - -> Seq Scan on bar (cost=0.00..431.00 rows=1 width=8) - -> Bitmap Heap Scan on foo (cost=0.00..68.13 rows=1 width=8) - Recheck Cond: (id = bar.id) - -> Bitmap Index Scan on foo_id_idx (cost=0.00..0.00 rows=0 width=0) - Index Cond: (id = bar.id) - Optimizer: Pivotal Optimizer (GPORCA) version 3.72.0 -(9 rows) + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000008.15..10000000013.26 rows=6 width=8) + -> Nested Loop (cost=10000000008.15..10000000013.18 rows=2 width=8) + -> Seq Scan on bar b (cost=10000000000.00..10000000001.01 rows=1 width=8) + -> Bitmap Heap Scan on foo f (cost=8.15..12.16 rows=1 width=8) + Recheck Cond: (id = b.id) + -> Bitmap Index Scan on foo_id_idx (cost=0.00..8.15 rows=1 width=0) + Index Cond: (id = b.id) + Optimizer: Postgres query optimizer +(8 rows) select f.id from co_nestloop_idxscan.foo f, co_nestloop_idxscan.bar b where f.id = b.id; id diff --git a/src/test/regress/expected/dpe_optimizer.out b/src/test/regress/expected/dpe_optimizer.out index 8bdf7df10e7..02acec2bf8d 100644 --- a/src/test/regress/expected/dpe_optimizer.out +++ b/src/test/regress/expected/dpe_optimizer.out @@ -76,28 +76,27 @@ analyze t1; -- Simple positive cases -- explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(18 rows) select * from t, pt where tid = ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -123,28 +122,27 @@ select * from t, pt where tid = ptid; (18 rows) explain (costs off, timing off, summary off, analyze) select * from t, pt where tid + 1 = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (never executed) - Index Cond: (ptid = (t.tid + 1)) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = (t.tid + 1)) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (actual rows=2 loops=2) - Index Cond: (ptid = (t.tid + 1)) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = (t.tid + 1)) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = (t.tid + 1)) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = (t.tid + 1)) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = (t.tid + 1)) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (never executed) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(18 rows) select * from t, pt where tid + 1 = ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -170,29 +168,28 @@ select * from t, pt where tid + 1 = ptid; (18 rows) explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid and t1 = 'hello' || tid; - QUERY PLAN -------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - Filter: (t1 = ('hello'::text || (tid)::text)) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(20 rows) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Filter: (t1 = ('hello'::text || (tid)::text)) + Optimizer: Postgres query optimizer +(19 rows) select * from t, pt where tid = ptid and t1 = 'hello' || tid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -218,34 +215,27 @@ select * from t, pt where tid = ptid and t1 = 'hello' || tid; (18 rows) explain (costs off, timing off, summary off, analyze) select * from t, pt where t1 = pt1 and ptid = tid; - QUERY PLAN ------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=2 loops=1) - -> Nested Loop (actual rows=2 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=1 loops=2) - -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 (actual rows=0 loops=2) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 (actual rows=0 loops=2) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 (never executed) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 (never executed) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 (never executed) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data (never executed) - Index Cond: (pt1 = t.t1) - Filter: ((pt1 = t.t1) AND (ptid = t.tid)) - Optimizer: Pivotal Optimizer (GPORCA) -(25 rows) + -> Hash Join (actual rows=2 loops=1) + Hash Cond: ((pt.pt1 = t.t1) AND (pt.ptid = t.tid)) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(18 rows) select * from t, pt where t1 = pt1 and ptid = tid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -258,35 +248,28 @@ select * from t, pt where t1 = pt1 and ptid = tid; -- in and exists clauses -- explain (costs off, timing off, summary off, analyze) select * from pt where ptid in (select tid from t where t1 = 'hello' || tid); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Hash Join (actual rows=8 loops=1) - Hash Cond: (pt_1_prt_2.ptid = t.tid) - Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Hash Semi Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 524288 buckets. -> Append (actual rows=8 loops=1) Partition Selectors: $0 - -> Seq Scan on pt_1_prt_2 (actual rows=5 loops=1) - -> Seq Scan on pt_1_prt_3 (actual rows=3 loops=1) - -> Seq Scan on pt_1_prt_4 (never executed) - -> Seq Scan on pt_1_prt_5 (never executed) - -> Seq Scan on pt_1_prt_6 (never executed) - -> Seq Scan on pt_1_prt_junk_data (never executed) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) -> Hash (actual rows=2 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2049kB + Buckets: 524288 Batches: 1 Memory Usage: 4097kB -> Partition Selector (selector id: $0) (actual rows=2 loops=1) -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> GroupAggregate (actual rows=2 loops=1) - Group Key: t.tid - -> Sort (actual rows=2 loops=1) - Sort Key: t.tid - Sort Method: quicksort Memory: 150kB - -> Redistribute Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) - Hash Key: t.tid - -> Seq Scan on t (actual rows=2 loops=1) - Filter: (t1 = ('hello'::text || (tid)::text)) - Optimizer: Pivotal Optimizer (GPORCA) -(25 rows) + -> Seq Scan on t (actual rows=2 loops=1) + Filter: (t1 = ('hello'::text || (tid)::text)) + Optimizer: Postgres query optimizer +(19 rows) select * from pt where ptid in (select tid from t where t1 = 'hello' || tid); dist | pt1 | pt2 | pt3 | ptid @@ -315,35 +298,28 @@ select * from pt where ptid in (select tid from t where t1 = 'hello' || tid); -- Known_opt_diff: MPP-21320 -- end_ignore explain (costs off, timing off, summary off, analyze) select * from pt where exists (select 1 from t where tid = ptid and t1 = 'hello' || tid); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Hash Join (actual rows=8 loops=1) - Hash Cond: (pt_1_prt_2.ptid = t.tid) - Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Hash Semi Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 524288 buckets. -> Append (actual rows=8 loops=1) Partition Selectors: $0 - -> Seq Scan on pt_1_prt_2 (actual rows=5 loops=1) - -> Seq Scan on pt_1_prt_3 (actual rows=3 loops=1) - -> Seq Scan on pt_1_prt_4 (never executed) - -> Seq Scan on pt_1_prt_5 (never executed) - -> Seq Scan on pt_1_prt_6 (never executed) - -> Seq Scan on pt_1_prt_junk_data (never executed) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) -> Hash (actual rows=2 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2049kB + Buckets: 524288 Batches: 1 Memory Usage: 4097kB -> Partition Selector (selector id: $0) (actual rows=2 loops=1) -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> GroupAggregate (actual rows=2 loops=1) - Group Key: t.tid - -> Sort (actual rows=2 loops=1) - Sort Key: t.tid - Sort Method: quicksort Memory: 150kB - -> Redistribute Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) - Hash Key: t.tid - -> Seq Scan on t (actual rows=2 loops=1) - Filter: (t1 = ('hello'::text || (tid)::text)) - Optimizer: Pivotal Optimizer (GPORCA) -(25 rows) + -> Seq Scan on t (actual rows=2 loops=1) + Filter: (t1 = ('hello'::text || (tid)::text)) + Optimizer: Postgres query optimizer +(19 rows) select * from pt where exists (select 1 from t where tid = ptid and t1 = 'hello' || tid); dist | pt1 | pt2 | pt3 | ptid @@ -372,30 +348,29 @@ select * from pt where exists (select 1 from t where tid = ptid and t1 = 'hello' -- group-by on top -- explain (costs off, timing off, summary off, analyze) select count(*) from t, pt where tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------- Finalize Aggregate (actual rows=1 loops=1) -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=3 loops=1) -> Partial Aggregate (actual rows=1 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(21 rows) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 524288 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 524288 Batches: 1 Memory Usage: 4097kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(20 rows) select count(*) from t, pt where tid = ptid; count @@ -407,34 +382,33 @@ select count(*) from t, pt where tid = ptid; -- window function on top -- explain (costs off, timing off, summary off, analyze) select *, rank() over (order by ptid,pt1) from t, pt where tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------- WindowAgg (actual rows=18 loops=1) - Order By: pt_1_prt_2.ptid, pt_1_prt_2.pt1 + Order By: pt.ptid, pt.pt1 -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - Merge Key: pt_1_prt_2.ptid, pt_1_prt_2.pt1 + Merge Key: pt.ptid, pt.pt1 -> Sort (actual rows=8 loops=1) - Sort Key: pt_1_prt_2.ptid, pt_1_prt_2.pt1 - Sort Method: quicksort Memory: 152kB - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(25 rows) + Sort Key: pt.ptid, pt.pt1 + Sort Method: quicksort Memory: 76kB + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 131072 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(24 rows) select *, rank() over (order by ptid,pt1) from t, pt where tid = ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid | rank @@ -465,46 +439,44 @@ select *, rank() over (order by ptid,pt1) from t, pt where tid = ptid; explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid union all select * from t, pt where tid + 2 = ptid; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=36 loops=1) -> Append (actual rows=14 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - -> Nested Loop (actual rows=7 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t t_1 (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 pt_1_prt_2_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 pt_1_prt_3_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 pt_1_prt_4_1 (actual rows=2 loops=2) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 pt_1_prt_5_1 (actual rows=2 loops=2) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 pt_1_prt_6_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data pt_1_prt_junk_data_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - Optimizer: Pivotal Optimizer (GPORCA) -(37 rows) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 131072 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + -> Hash Join (actual rows=7 loops=1) + Hash Cond: (pt_7.ptid = (t_1.tid + 2)) + Extra Text: (seg0) Hash chain length 1.0 avg, 1 max, using 2 of 131072 buckets. + -> Append (actual rows=7 loops=1) + Partition Selectors: $1 + -> Seq Scan on pt_1_prt_2 pt_8 (never executed) + -> Seq Scan on pt_1_prt_3 pt_9 (never executed) + -> Seq Scan on pt_1_prt_4 pt_10 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_11 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt_12 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_13 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $1) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t t_1 (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(35 rows) select * from t, pt where tid = ptid union all @@ -557,47 +529,47 @@ explain (costs off, timing off, summary off, analyze) select count(*) from union all select * from t, pt where tid + 2 = ptid ) foo; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- Finalize Aggregate (actual rows=1 loops=1) -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=3 loops=1) -> Partial Aggregate (actual rows=1 loops=1) -> Append (actual rows=14 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - -> Nested Loop (actual rows=7 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t t_1 (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 pt_1_prt_2_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 pt_1_prt_3_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 pt_1_prt_4_1 (actual rows=2 loops=2) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 pt_1_prt_5_1 (actual rows=2 loops=2) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 pt_1_prt_6_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data pt_1_prt_junk_data_1 (never executed) - Index Cond: (ptid = (t_1.tid + 2)) - Optimizer: Pivotal Optimizer (GPORCA) + -> Subquery Scan on "*SELECT* 1" (actual rows=8 loops=1) + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + -> Subquery Scan on "*SELECT* 2" (actual rows=7 loops=1) + -> Hash Join (actual rows=7 loops=1) + Hash Cond: (pt_7.ptid = (t_1.tid + 2)) + Extra Text: (seg0) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=7 loops=1) + Partition Selectors: $1 + -> Seq Scan on pt_1_prt_2 pt_8 (never executed) + -> Seq Scan on pt_1_prt_3 pt_9 (never executed) + -> Seq Scan on pt_1_prt_4 pt_10 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_11 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt_12 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_13 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $1) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t t_1 (actual rows=2 loops=1) + Optimizer: Postgres query optimizer (39 rows) select count(*) from @@ -617,28 +589,24 @@ set enable_hashjoin=off; set enable_nestloop=on; set enable_mergejoin=off; explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) -> Nested Loop (actual rows=8 loops=1) - Join Filter: true + Join Filter: (t.tid = pt.ptid) + Rows Removed by Join Filter: 30 -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Materialize (actual rows=20 loops=2) + -> Append (actual rows=20 loops=1) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_4 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt_5 (actual rows=4 loops=1) + -> Seq Scan on pt_1_prt_junk_data pt_6 (actual rows=3 loops=1) + Optimizer: Postgres query optimizer +(15 rows) select * from t, pt where tid = ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -675,30 +643,29 @@ set enable_hashjoin=off; -- Known_opt_diff: MPP-21322 -- end_ignore explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid and pt1 = 'hello0'; - QUERY PLAN ------------------------------------------------------------------------------------------------------------- - Hash Join (actual rows=1 loops=1) - Hash Cond: (t.tid = pt_1_prt_2.ptid) - Extra Text: Hash chain length 1.0 avg, 1 max, using 1 of 262144 buckets. - -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Hash (actual rows=1 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2049kB - -> Gather Motion 3:1 (slice2; segments: 3) (actual rows=1 loops=1) + QUERY PLAN +----------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (actual rows=1 loops=1) + -> Nested Loop (actual rows=1 loops=1) + Join Filter: (t.tid = pt.ptid) + Rows Removed by Join Filter: 1 + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + -> Materialize (actual rows=1 loops=2) -> Append (actual rows=1 loops=1) - -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 (actual rows=1 loops=1) + -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 pt_1 (actual rows=1 loops=1) Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 (never executed) + -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 pt_2 (never executed) Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 (never executed) + -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 pt_3 (never executed) Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 (never executed) + -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 pt_4 (never executed) Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 (never executed) + -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 pt_5 (never executed) Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data (never executed) + -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data pt_6 (never executed) Index Cond: (pt1 = 'hello0'::text) - Optimizer: Pivotal Optimizer (GPORCA) + Optimizer: Postgres query optimizer (21 rows) select * from t, pt where tid = ptid and pt1 = 'hello0'; @@ -715,28 +682,24 @@ set enable_indexscan=on; set enable_seqscan=off; set enable_hashjoin=off; explain (costs off, timing off, summary off, analyze) select * from t, pt where tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) -> Nested Loop (actual rows=8 loops=1) - Join Filter: true + Join Filter: (t.tid = pt.ptid) + Rows Removed by Join Filter: 30 -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Materialize (actual rows=20 loops=2) + -> Append (actual rows=20 loops=1) + -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 pt_4 (actual rows=5 loops=1) + -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 pt_5 (actual rows=4 loops=1) + -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data pt_6 (actual rows=3 loops=1) + Optimizer: Postgres query optimizer +(15 rows) select * from t, pt where tid = ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -769,28 +732,25 @@ set enable_seqscan=on; set enable_hashjoin=on; set enable_nestloop=off; explain (costs off, timing off, summary off, analyze) select * from t, pt where t1 = pt1; - QUERY PLAN ------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=2 loops=1) - -> Nested Loop (actual rows=2 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=1 loops=2) - -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 (actual rows=0 loops=2) - Index Cond: (pt1 = t.t1) - -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 (actual rows=0 loops=2) - Index Cond: (pt1 = t.t1) - -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 (never executed) - Index Cond: (pt1 = t.t1) - -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 (never executed) - Index Cond: (pt1 = t.t1) - -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 (never executed) - Index Cond: (pt1 = t.t1) - -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data (never executed) - Index Cond: (pt1 = t.t1) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Hash Join (actual rows=2 loops=1) + Hash Cond: (pt.pt1 = t.t1) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 262144 buckets. + -> Append (actual rows=20 loops=1) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_4 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt_5 (actual rows=4 loops=1) + -> Seq Scan on pt_1_prt_junk_data pt_6 (actual rows=3 loops=1) + -> Hash (actual rows=2 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer +(16 rows) select * from t, pt where t1 = pt1; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -800,28 +760,24 @@ select * from t, pt where t1 = pt1; (2 rows) explain (costs off, timing off, summary off, analyze) select * from t, pt where tid < ptid; - QUERY PLAN --------------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=81 loops=1) -> Nested Loop (actual rows=31 loops=1) - Join Filter: true + Join Filter: (t.tid < pt.ptid) + Rows Removed by Join Filter: 9 -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) -> Seq Scan on t (actual rows=2 loops=1) - -> Append (actual rows=16 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (never executed) - Index Cond: (ptid > t.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid > t.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (actual rows=5 loops=2) - Index Cond: (ptid > t.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (actual rows=5 loops=2) - Index Cond: (ptid > t.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (actual rows=4 loops=2) - Index Cond: (ptid > t.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (actual rows=3 loops=2) - Index Cond: (ptid > t.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(19 rows) + -> Materialize (actual rows=20 loops=2) + -> Append (actual rows=20 loops=1) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_4 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt_5 (actual rows=4 loops=1) + -> Seq Scan on pt_1_prt_junk_data pt_6 (actual rows=3 loops=1) + Optimizer: Postgres query optimizer +(15 rows) select * from t, pt where tid < ptid; dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -918,34 +874,33 @@ reset enable_nestloop; -- -- one of the joined tables can be used for partition elimination, the other can not explain (costs off, timing off, summary off, analyze) select * from t, t1, pt where t1.t2 = t.t2 and t1.tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------------- - Hash Join (actual rows=36 loops=1) - Hash Cond: (t1.t2 = t.t2) - Extra Text: Hash chain length 2.0 avg, 2 max, using 1 of 262144 buckets. - -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=18 loops=1) - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t1 (actual rows=1 loops=1) - -> Append (actual rows=4 loops=2) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=2 loops=2) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (actual rows=2 loops=2) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t1.tid) - -> Hash (actual rows=2 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2049kB - -> Gather Motion 3:1 (slice3; segments: 3) (actual rows=2 loops=1) - -> Seq Scan on t (actual rows=2 loops=1) - Optimizer: Pivotal Optimizer (GPORCA) + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (actual rows=36 loops=1) + -> Hash Join (actual rows=16 loops=1) + Hash Cond: (t1.t2 = t.t2) + Extra Text: (seg1) Hash chain length 2.0 avg, 2 max, using 1 of 131072 buckets. + -> Hash Join (actual rows=8 loops=1) + Hash Cond: (pt.ptid = t1.tid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 2 of 131072 buckets. + -> Append (actual rows=8 loops=1) + Partition Selectors: $0 + -> Seq Scan on pt_1_prt_2 pt_1 (never executed) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + -> Hash (actual rows=2 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $0) (actual rows=2 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t1 (actual rows=1 loops=1) + -> Hash (actual rows=2 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=2 loops=1) + -> Seq Scan on t (actual rows=2 loops=1) + Optimizer: Postgres query optimizer (25 rows) select * from t, t1, pt where t1.t2 = t.t2 and t1.tid = ptid; @@ -998,38 +953,35 @@ insert into t1 select i, -100, 'dummy' from generate_series(1,10) i; analyze t; analyze t1; explain (costs off, timing off, summary off, analyze) select * from t, t1, pt where t1.tid = ptid and t.tid = ptid; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=9 loops=1) - -> Hash Join (actual rows=9 loops=1) - Hash Cond: (t.tid = pt_1_prt_2.ptid) - Extra Text: (seg1) Hash chain length 9.0 avg, 9 max, using 1 of 262144 buckets. - -> Redistribute Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=1) - Hash Key: t.tid - -> Seq Scan on t (actual rows=5 loops=1) - -> Hash (actual rows=9 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2049kB - -> Redistribute Motion 3:3 (slice3; segments: 3) (actual rows=9 loops=1) - Hash Key: pt_1_prt_2.ptid - -> Nested Loop (actual rows=8 loops=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice4; segments: 3) (actual rows=12 loops=1) - -> Seq Scan on t1 (actual rows=6 loops=1) - -> Append (actual rows=1 loops=12) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=0 loops=12) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (actual rows=0 loops=12) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t1.tid) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t1.tid) - Optimizer: Pivotal Optimizer (GPORCA) -(28 rows) + -> Hash Join (actual rows=3 loops=1) + Hash Cond: (pt.ptid = t1.tid) + Extra Text: (seg0) Hash chain length 4.0 avg, 10 max, using 3 of 131072 buckets. + -> Hash Join (actual rows=3 loops=1) + Hash Cond: (pt.ptid = t.tid) + Extra Text: (seg0) Hash chain length 4.0 avg, 10 max, using 3 of 131072 buckets. + -> Append (actual rows=6 loops=1) + Partition Selectors: $0, $1 + -> Seq Scan on pt_1_prt_2 pt_1 (never executed) + -> Seq Scan on pt_1_prt_3 pt_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt_6 (actual rows=3 loops=1) + -> Hash (actual rows=12 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $0) (actual rows=12 loops=1) + -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=12 loops=1) + -> Seq Scan on t (actual rows=5 loops=1) + -> Hash (actual rows=12 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $1) (actual rows=12 loops=1) + -> Broadcast Motion 3:3 (slice3; segments: 3) (actual rows=12 loops=1) + -> Seq Scan on t1 (actual rows=6 loops=1) + Optimizer: Postgres query optimizer +(26 rows) select * from t, t1, pt where t1.tid = ptid and t.tid = ptid; dist | tid | t1 | t2 | dist | tid | t1 | t2 | dist | pt1 | pt2 | pt3 | ptid @@ -1054,58 +1006,43 @@ begin; set local from_collapse_limit = 1; set local join_collapse_limit = 1; explain (costs off, timing off, summary off, analyze) select * from t1 inner join (select pt1.*, pt2.ptid as ptid2 from pt as pt1, pt as pt2 WHERE pt1.ptid <= pt2.ptid and pt1.dist = pt2.dist ) as ptx ON t1.dist = ptx.dist and t1.tid = ptx.ptid and t1.tid = ptx.ptid2; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=2 loops=1) - -> Nested Loop (actual rows=1 loops=1) - Join Filter: true - -> Nested Loop (actual rows=1 loops=1) - Join Filter: true - -> Seq Scan on t1 (actual rows=1 loops=1) - -> Append (actual rows=1 loops=1) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 (never executed) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 (actual rows=1 loops=1) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - Rows Removed by Filter: 2 - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 (actual rows=1 loops=1) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - Rows Removed by Filter: 1 - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 (never executed) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 (never executed) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data (never executed) - Index Cond: (ptid = t1.tid) - Filter: ((ptid = t1.tid) AND (t1.dist = dist)) - -> Append (actual rows=1 loops=1) - -> Index Scan using pt_1_prt_2_ptid_idx on pt_1_prt_2 pt_1_prt_2_1 (never executed) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - -> Index Scan using pt_1_prt_3_ptid_idx on pt_1_prt_3 pt_1_prt_3_1 (actual rows=1 loops=1) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - Rows Removed by Filter: 2 - -> Index Scan using pt_1_prt_4_ptid_idx on pt_1_prt_4 pt_1_prt_4_1 (actual rows=1 loops=1) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - Rows Removed by Filter: 1 - -> Index Scan using pt_1_prt_5_ptid_idx on pt_1_prt_5 pt_1_prt_5_1 (never executed) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - -> Index Scan using pt_1_prt_6_ptid_idx on pt_1_prt_6 pt_1_prt_6_1 (never executed) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - -> Index Scan using pt_1_prt_junk_data_ptid_idx on pt_1_prt_junk_data pt_1_prt_junk_data_1 (never executed) - Index Cond: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid)) - Filter: ((ptid <= pt_1_prt_2.ptid) AND (ptid = pt_1_prt_2.ptid) AND (dist = pt_1_prt_2.dist)) - Optimizer: Pivotal Optimizer (GPORCA) -(49 rows) + -> Hash Join (actual rows=1 loops=1) + Hash Cond: ((pt1.dist = t1.dist) AND (pt1.ptid = t1.tid)) + Join Filter: ((t1.tid <= pt2.ptid) AND (pt1.ptid <= t1.tid)) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 1 of 131072 buckets. + -> Hash Join (actual rows=3 loops=1) + Hash Cond: ((pt1.dist = pt2.dist) AND (pt1.ptid = pt2.ptid)) + Join Filter: (pt1.ptid <= pt2.ptid) + Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 14 of 262144 buckets. + -> Append (actual rows=3 loops=1) + Partition Selectors: $0, $1 + -> Seq Scan on pt_1_prt_2 pt1_1 (never executed) + -> Seq Scan on pt_1_prt_3 pt1_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt1_3 (actual rows=2 loops=1) + -> Seq Scan on pt_1_prt_5 pt1_4 (never executed) + -> Seq Scan on pt_1_prt_6 pt1_5 (never executed) + -> Seq Scan on pt_1_prt_junk_data pt1_6 (never executed) + -> Hash (actual rows=14 loops=1) + Buckets: 262144 Batches: 1 Memory Usage: 2049kB + -> Partition Selector (selector id: $0) (actual rows=14 loops=1) + -> Append (actual rows=14 loops=1) + Partition Selectors: $2 + -> Seq Scan on pt_1_prt_2 pt2_1 (never executed) + -> Seq Scan on pt_1_prt_3 pt2_2 (actual rows=3 loops=1) + -> Seq Scan on pt_1_prt_4 pt2_3 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_5 pt2_4 (actual rows=5 loops=1) + -> Seq Scan on pt_1_prt_6 pt2_5 (actual rows=4 loops=1) + -> Seq Scan on pt_1_prt_junk_data pt2_6 (actual rows=3 loops=1) + -> Hash (actual rows=1 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 1025kB + -> Partition Selector (selector id: $2) (actual rows=1 loops=1) + -> Partition Selector (selector id: $1) (actual rows=1 loops=1) + -> Seq Scan on t1 (actual rows=1 loops=1) + Optimizer: Postgres query optimizer +(34 rows) rollback; -- @@ -1113,43 +1050,44 @@ rollback; -- not projection capable. -- explain (costs off, timing off, summary off, analyze) select * from pt, pt1 where pt.ptid = pt1.ptid and pt.pt1 = 'hello0' order by pt1.dist; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=9 loops=1) - Merge Key: pt1_1_prt_2.dist + Merge Key: pt1.dist -> Sort (actual rows=5 loops=1) - Sort Key: pt1_1_prt_2.dist - Sort Method: quicksort Memory: 150kB + Sort Key: pt1.dist + Sort Method: quicksort Memory: 75kB -> Hash Join (actual rows=5 loops=1) - Hash Cond: (pt1_1_prt_2.ptid = pt_1_prt_2.ptid) + Hash Cond: (pt1.ptid = pt.ptid) Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 1 of 131072 buckets. -> Append (actual rows=5 loops=1) Partition Selectors: $0 - -> Seq Scan on pt1_1_prt_2 (actual rows=5 loops=1) - -> Seq Scan on pt1_1_prt_3 (never executed) - -> Seq Scan on pt1_1_prt_4 (never executed) - -> Seq Scan on pt1_1_prt_5 (never executed) - -> Seq Scan on pt1_1_prt_6 (never executed) - -> Seq Scan on pt1_1_prt_junk_data (never executed) + -> Seq Scan on pt1_1_prt_2 pt1_1 (actual rows=5 loops=1) + -> Seq Scan on pt1_1_prt_3 pt1_2 (never executed) + -> Seq Scan on pt1_1_prt_4 pt1_3 (never executed) + -> Seq Scan on pt1_1_prt_5 pt1_4 (never executed) + -> Seq Scan on pt1_1_prt_6 pt1_5 (never executed) + -> Seq Scan on pt1_1_prt_junk_data pt1_6 (never executed) -> Hash (actual rows=1 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 1025kB -> Partition Selector (selector id: $0) (actual rows=1 loops=1) -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) - -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 (actual rows=1 loops=1) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data (never executed) - Index Cond: (pt1 = 'hello0'::text) - Optimizer: Pivotal Optimizer (GPORCA) -(33 rows) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=1 loops=1) + Filter: (pt1 = 'hello0'::text) + Rows Removed by Filter: 4 + -> Seq Scan on pt_1_prt_3 pt_2 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + Filter: (pt1 = 'hello0'::text) + Optimizer: Postgres query optimizer +(35 rows) select * from pt, pt1 where pt.ptid = pt1.ptid and pt.pt1 = 'hello0' order by pt1.dist; dist | pt1 | pt2 | pt3 | ptid | dist | pt1 | pt2 | pt3 | ptid @@ -1166,42 +1104,42 @@ select * from pt, pt1 where pt.ptid = pt1.ptid and pt.pt1 = 'hello0' order by pt (9 rows) explain (costs off, timing off, summary off, analyze) select count(*) from pt, pt1 where pt.ptid = pt1.ptid and pt.pt1 = 'hello0'; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------- Finalize Aggregate (actual rows=1 loops=1) -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=3 loops=1) -> Partial Aggregate (actual rows=1 loops=1) -> Hash Join (actual rows=5 loops=1) - Hash Cond: (pt1_1_prt_2.ptid = pt_1_prt_2.ptid) + Hash Cond: (pt1.ptid = pt.ptid) Extra Text: (seg1) Hash chain length 1.0 avg, 1 max, using 1 of 524288 buckets. -> Append (actual rows=5 loops=1) Partition Selectors: $0 - -> Seq Scan on pt1_1_prt_2 (actual rows=5 loops=1) - -> Seq Scan on pt1_1_prt_3 (never executed) - -> Seq Scan on pt1_1_prt_4 (never executed) - -> Seq Scan on pt1_1_prt_5 (never executed) - -> Seq Scan on pt1_1_prt_6 (never executed) - -> Seq Scan on pt1_1_prt_junk_data (never executed) + -> Seq Scan on pt1_1_prt_2 pt1_1 (actual rows=5 loops=1) + -> Seq Scan on pt1_1_prt_3 pt1_2 (never executed) + -> Seq Scan on pt1_1_prt_4 pt1_3 (never executed) + -> Seq Scan on pt1_1_prt_5 pt1_4 (never executed) + -> Seq Scan on pt1_1_prt_6 pt1_5 (never executed) + -> Seq Scan on pt1_1_prt_junk_data pt1_6 (never executed) -> Hash (actual rows=1 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4097kB -> Partition Selector (selector id: $0) (actual rows=1 loops=1) -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=1 loops=1) - -> Result (actual rows=1 loops=1) - -> Append (actual rows=1 loops=1) - -> Index Scan using pt_1_prt_2_pt1_idx on pt_1_prt_2 (actual rows=1 loops=1) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_3_pt1_idx on pt_1_prt_3 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_4_pt1_idx on pt_1_prt_4 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_5_pt1_idx on pt_1_prt_5 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_6_pt1_idx on pt_1_prt_6 (never executed) - Index Cond: (pt1 = 'hello0'::text) - -> Index Scan using pt_1_prt_junk_data_pt1_idx on pt_1_prt_junk_data (never executed) - Index Cond: (pt1 = 'hello0'::text) - Optimizer: Pivotal Optimizer (GPORCA) -(32 rows) + -> Append (actual rows=1 loops=1) + -> Seq Scan on pt_1_prt_2 pt_1 (actual rows=1 loops=1) + Filter: (pt1 = 'hello0'::text) + Rows Removed by Filter: 4 + -> Seq Scan on pt_1_prt_3 pt_2 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_4 pt_3 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_5 pt_4 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_6 pt_5 (never executed) + Filter: (pt1 = 'hello0'::text) + -> Seq Scan on pt_1_prt_junk_data pt_6 (never executed) + Filter: (pt1 = 'hello0'::text) + Optimizer: Postgres query optimizer +(33 rows) select count(*) from pt, pt1 where pt.ptid = pt1.ptid and pt.pt1 = 'hello0'; count @@ -2978,28 +2916,30 @@ set enable_seqscan=off; -- force_explain explain (analyze, timing off, summary off) select * from pt, t where t.dist = pt.dist and t.tid = pt.ptid order by t.tid, t.sk; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.10 rows=98 width=24) (actual rows=5 loops=1) - Merge Key: t.tid, t.sk - -> Sort (cost=0.00..862.09 rows=33 width=24) (actual rows=2 loops=1) - Sort Key: t.tid, t.sk - Sort Method: quicksort Memory: 150kB - -> Hash Join (cost=0.00..862.05 rows=33 width=24) (actual rows=2 loops=1) - Hash Cond: ((pt1.dist = t.dist) AND (pt1.ptid = t.tid)) - Extra Text: (seg0) Hash chain length 1.0 avg, 1 max, using 36 of 262144 buckets. - -> Append (cost=0.00..431.00 rows=33 width=12) (actual rows=36 loops=1) - Partition Selectors: $0 - -> Seq Scan on pt1 (cost=0.00..431.00 rows=33 width=12) (actual rows=1 loops=1) - -> Seq Scan on pt2 (cost=0.00..431.00 rows=33 width=12) (actual rows=1 loops=1) - -> Seq Scan on pt3 (cost=0.00..431.00 rows=33 width=12) (never executed) - -> Seq Scan on pt4 (cost=0.00..431.00 rows=33 width=12) (never executed) - -> Seq Scan on pt5 (cost=0.00..431.00 rows=33 width=12) (actual rows=1 loops=1) - -> Seq Scan on ptdefault (cost=0.00..431.00 rows=33 width=12) (actual rows=35 loops=1) - -> Hash (cost=431.00..431.00 rows=33 width=12) (actual rows=37 loops=1) - Buckets: 262144 Batches: 1 Memory Usage: 2050kB - -> Partition Selector (selector id: $0) (cost=0.00..431.00 rows=33 width=12) (actual rows=37 loops=1) - -> Seq Scan on t (cost=0.00..431.00 rows=33 width=12) (actual rows=37 loops=1) - Optimizer: Pivotal Optimizer (GPORCA) -(20 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000008.18..10000000014.83 rows=7 width=24) (actual rows=5 loops=1) + Merge Key: pt.ptid, t.sk + -> Incremental Sort (cost=10000000008.18..10000000014.74 rows=2 width=24) (actual rows=2 loops=1) + Sort Key: pt.ptid, t.sk + Presorted Key: pt.ptid + Full-sort Groups: 1 Sort Method: quicksort Average Memory: 25kB Peak Memory: 25kB + -> Merge Join (cost=10000000003.00..10000000014.64 rows=2 width=24) (actual rows=2 loops=1) + Merge Cond: (pt.ptid = t.tid) + Join Filter: (pt.dist = t.dist) + -> Merge Append (cost=0.85..446.48 rows=39 width=12) (actual rows=3 loops=1) + Sort Key: pt.ptid + -> Index Scan using pt1_ptid_sk_idx on pt1 pt_1 (cost=0.12..8.14 rows=1 width=12) (actual rows=1 loops=1) + -> Index Scan using pt2_ptid_sk_idx on pt2 pt_2 (cost=0.12..8.14 rows=1 width=12) (actual rows=1 loops=1) + -> Index Scan using pt3_ptid_sk_idx on pt3 pt_3 (cost=0.12..8.14 rows=1 width=12) (never executed) + -> Index Scan using pt4_ptid_sk_idx on pt4 pt_4 (cost=0.12..8.14 rows=1 width=12) (never executed) + -> Index Scan using pt5_ptid_sk_idx on pt5 pt_5 (cost=0.12..8.14 rows=1 width=12) (actual rows=1 loops=1) + -> Index Scan using ptdefault_ptid_sk_idx on ptdefault pt_6 (cost=0.14..405.00 rows=34 width=12) (actual rows=2 loops=1) + -> Sort (cost=10000000002.15..10000000002.23 rows=33 width=12) (actual rows=19 loops=2) + Sort Key: t.tid + Sort Method: quicksort Memory: 79kB + -> Partition Selector (selector id: $0) (cost=10000000000.00..10000000001.33 rows=33 width=12) (actual rows=37 loops=1) + -> Seq Scan on t (cost=10000000000.00..10000000001.33 rows=33 width=12) (actual rows=37 loops=1) + Optimizer: Postgres query optimizer +(23 rows) diff --git a/src/test/regress/expected/equivclass_optimizer.out b/src/test/regress/expected/equivclass_optimizer.out index 66f795a51da..b4416dfe9b6 100644 --- a/src/test/regress/expected/equivclass_optimizer.out +++ b/src/test/regress/expected/equivclass_optimizer.out @@ -151,12 +151,12 @@ explain (costs off) ------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on ec2 - -> Index Scan using ec1_pkey on ec1 - Index Cond: ((ff = ec2.x1) AND (ff = '42'::bigint)) - Optimizer: Pivotal Optimizer (GPORCA) + Join Filter: (ec1.ff = ec2.x1) + -> Broadcast Motion 1:3 (slice2; segments: 1) + -> Index Scan using ec1_pkey on ec1 + Index Cond: ((ff = '42'::bigint) AND (ff = '42'::bigint)) + -> Seq Scan on ec2 + Optimizer: Postgres query optimizer (8 rows) explain (costs off) @@ -179,13 +179,13 @@ explain (costs off) --------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on ec2 - Filter: ('42'::bigint = x1) - -> Index Scan using ec1_pkey on ec1 - Index Cond: (ff = ec2.x1) - Optimizer: Pivotal Optimizer (GPORCA) version 3.9.0 + Join Filter: (ec1.ff = ec2.x1) + -> Broadcast Motion 1:3 (slice2; segments: 1) + -> Index Scan using ec1_pkey on ec1 + Index Cond: (ff = '42'::bigint) + -> Seq Scan on ec2 + Filter: ('42'::bigint = x1) + Optimizer: Postgres query optimizer (9 rows) explain (costs off) @@ -194,14 +194,13 @@ explain (costs off) --------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on ec2 - Filter: (x1 = '42'::int8alias1) - -> Index Scan using ec1_pkey on ec1 - Index Cond: (ff = ec2.x1) - Optimizer: Pivotal Optimizer (GPORCA) version 3.9.0 -(9 rows) + -> Index Scan using ec1_pkey on ec1 + Index Cond: (ff = '42'::int8alias1) + -> Seq Scan on ec2 + Filter: (x1 = '42'::int8alias1) + Optimizer: Postgres query optimizer +(8 rows) explain (costs off) select * from ec1, ec2 where ff = x1 and x1 = '42'::int8alias2; @@ -209,14 +208,13 @@ explain (costs off) --------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) -> Seq Scan on ec2 Filter: (x1 = '42'::int8alias2) -> Index Scan using ec1_pkey on ec1 Index Cond: (ff = ec2.x1) - Optimizer: Pivotal Optimizer (GPORCA) version 3.9.0 -(9 rows) + Optimizer: Postgres query optimizer +(8 rows) create index ec1_expr1 on ec1((ff + 1)); create index ec1_expr2 on ec1((ff + 2 + 1)); diff --git a/src/test/regress/expected/gporca.out b/src/test/regress/expected/gporca.out index 002e2120ffc..7fee59be1cc 100644 --- a/src/test/regress/expected/gporca.out +++ b/src/test/regress/expected/gporca.out @@ -14228,3 +14228,105 @@ SELECT gp_segment_id, * FROM result_tab; DROP TABLE IF EXISTS dist_tab_a; DROP TABLE IF EXISTS dist_tab_b; DROP TABLE IF EXISTS result_tab; +--- Test if orca can produce correct plan for inner index nl join +CREATE TABLE t_clientinstrumentind2 ( + tradingday text, + client_id INT, + instrumentid text, + PRIMARY KEY (tradingday, client_id, instrumentid) +) +DISTRIBUTED BY (tradingday, client_id, instrumentid) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2020', appendonly=false) +); +CREATE TABLE t_clientproductind2 ( + tradingday character varying(8), + productid TEXT, + clientid INT, + exchangegroup TEXT, + customertype INT , + PRIMARY KEY (tradingday, productid, clientid, exchangegroup, customertype) +) +DISTRIBUTED BY (tradingday, productid, clientid, exchangegroup, customertype) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2020', appendonly=false) +); +INSERT INTO t_clientinstrumentind2 (tradingday, client_id, instrumentid) VALUES +('20190715', 54982370, 'al1908'), +('20190715', 54982370, 'rb2001'), +('20190715', 54982370, 'cu1909'), +('20190715', 54982370, 'cu1908'), +('20190715', 54982370, 'zn1908'), +('20190715', 54982370, 'pb1908'); +INSERT INTO t_clientproductind2 (tradingday, productid, clientid, exchangegroup, customertype) VALUES +('20190715', 'cu_f', 54982370, 'SHFE', 1), +('20190715', 'rb_f', 54982370, 'SHFE', 1), +('20190715', 'al_f', 54982370, 'SHFE', 1), +('20190715', 'zn_f', 54982370, 'SHFE', 1), +('20190715', 'pb_f', 54982370, 'SHFE', 1); +SET optimizer_enable_hashjoin = OFF; +-- FIXME: orca can't produce correct plan, we fallback this query to +-- postgres optimizer for workaround. See issue 567 +EXPLAIN (COSTS OFF) +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + -> Hash Join + Hash Cond: (t.tradingday = (t_1.tradingday)::text) + -> HashAggregate + Group Key: t.tradingday + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: t.tradingday + -> Bitmap Heap Scan on t_clientinstrumentind_2_prt_p2019 t + Recheck Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text)) + -> Bitmap Index Scan on t_clientinstrumentind_2_prt_p2019_pkey + Index Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text)) + -> Hash + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: t_1.tradingday + -> HashAggregate + Group Key: t_1.tradingday + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: t_1.tradingday + -> Bitmap Heap Scan on t_clientproductind_2_prt_p2019 t_1 + Recheck Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text)) + -> Bitmap Index Scan on t_clientproductind_2_prt_p2019_pkey + Index Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text)) + Optimizer: Postgres query optimizer +(23 rows) + +RESET optimizer_enable_hashjoin; +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; + tradingday | ins_spaninsarbitrageratio | tradingday | prod_spaninsarbitrageratio +------------+---------------------------+------------+---------------------------- + 20190715 | 1 | 20190715 | 0.9233716475 +(1 row) + +DROP TABLE t_clientinstrumentind2, t_clientproductind2; diff --git a/src/test/regress/expected/gporca_optimizer.out b/src/test/regress/expected/gporca_optimizer.out index eda9948ba65..c82f437e4a3 100644 --- a/src/test/regress/expected/gporca_optimizer.out +++ b/src/test/regress/expected/gporca_optimizer.out @@ -3500,15 +3500,15 @@ explain select * from orca.r, orca.s where r.a is not distinct from s.c; -- explain Hash Join with equality join condition -- force_explain explain select * from orca.r, orca.s where r.a = s.c; - QUERY PLAN --------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..491.01 rows=30 width=16) - -> Nested Loop (cost=0.00..491.00 rows=10 width=16) - Join Filter: true - -> Seq Scan on s (cost=0.00..431.00 rows=10 width=8) - -> Index Scan using r_a on r (cost=0.00..180.00 rows=1 width=8) - Index Cond: (a = s.c) - Optimizer: Pivotal Optimizer (GPORCA) + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) (cost=1.15..2.78 rows=30 width=16) + -> Hash Join (cost=1.15..2.38 rows=10 width=16) + Hash Cond: (s.c = r.a) + -> Seq Scan on s (cost=0.00..1.10 rows=10 width=8) + -> Hash (cost=1.07..1.07 rows=7 width=8) + -> Seq Scan on r (cost=0.00..1.07 rows=7 width=8) + Optimizer: Postgres query optimizer (7 rows) -- sort @@ -12923,15 +12923,15 @@ set enable_sort = off; -- 1 simple btree explain (costs off) select * from foo join tbtree on foo.a=tbtree.a; - QUERY PLAN -------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - -> Index Scan using tbtreexa on tbtree - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) + -> Hash Join + Hash Cond: (tbtree.a = foo.a) + -> Seq Scan on tbtree + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer (7 rows) select * from foo join tbtree on foo.a=tbtree.a; @@ -12953,18 +12953,16 @@ select * from foo join tbtree on foo.a=tbtree.a; -- 2 simple bitmap explain (costs off) select * from foo join tbitmap on foo.a=tbitmap.a; - QUERY PLAN --------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - -> Bitmap Heap Scan on tbitmap - Recheck Cond: (a = foo.a) - -> Bitmap Index Scan on tbitmapxa - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) + -> Seq Scan on tbitmap + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(7 rows) select * from foo join tbitmap on foo.a=tbitmap.a; a | b | c | a | b | c @@ -12985,17 +12983,20 @@ select * from foo join tbitmap on foo.a=tbitmap.a; -- 3 btree with select pred explain (costs off) select * from foo join tbtree on foo.a=tbtree.a where tbtree.a < 5000; - QUERY PLAN --------------------------------------------------------- + QUERY PLAN +------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - Filter: (a < 5000) - -> Index Scan using tbtreexa on tbtree - Index Cond: ((a = foo.a) AND (a < 5000)) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + -> Hash Join + Hash Cond: (tbtree.a = foo.a) + -> Bitmap Heap Scan on tbtree + Recheck Cond: (a < 5000) + -> Bitmap Index Scan on tbtreexa + Index Cond: (a < 5000) + -> Hash + -> Seq Scan on foo + Filter: (a < 5000) + Optimizer: Postgres query optimizer +(11 rows) select * from foo join tbtree on foo.a=tbtree.a where tbtree.a < 5000; a | b | c | a | b | c @@ -13010,19 +13011,20 @@ select * from foo join tbtree on foo.a=tbtree.a where tbtree.a < 5000; -- 4 bitmap with select pred explain (costs off) select * from foo join tbitmap on foo.a=tbitmap.a where tbitmap.a < 5000; - QUERY PLAN --------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - Filter: (a < 5000) + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) -> Bitmap Heap Scan on tbitmap - Recheck Cond: ((a = foo.a) AND (a < 5000)) + Recheck Cond: (a < 5000) -> Bitmap Index Scan on tbitmapxa - Index Cond: ((a = foo.a) AND (a < 5000)) - Optimizer: Pivotal Optimizer (GPORCA) -(10 rows) + Index Cond: (a < 5000) + -> Hash + -> Seq Scan on foo + Filter: (a < 5000) + Optimizer: Postgres query optimizer +(11 rows) select * from foo join tbitmap on foo.a=tbitmap.a where tbitmap.a < 5000; a | b | c | a | b | c @@ -13037,15 +13039,15 @@ select * from foo join tbitmap on foo.a=tbitmap.a where tbitmap.a < 5000; -- 5 btree with project explain (costs off) select * from foo join (select a, b+c as bc from tbtree) proj on foo.a=proj.a; - QUERY PLAN -------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - -> Index Scan using tbtreexa on tbtree - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) + -> Hash Join + Hash Cond: (tbtree.a = foo.a) + -> Seq Scan on tbtree + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer (7 rows) select * from foo join (select a, b+c as bc from tbtree) proj on foo.a=proj.a; @@ -13067,18 +13069,16 @@ select * from foo join (select a, b+c as bc from tbtree) proj on foo.a=proj.a; -- 6 bitmap with project explain (costs off) select * from foo join (select a, b+c as bc from tbitmap) proj on foo.a=proj.a; - QUERY PLAN --------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - -> Bitmap Heap Scan on tbitmap - Recheck Cond: (a = foo.a) - -> Bitmap Index Scan on tbitmapxa - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) + -> Seq Scan on tbitmap + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(7 rows) select * from foo join (select a, b+c as bc from tbitmap) proj on foo.a=proj.a; a | b | c | a | bc @@ -13099,17 +13099,17 @@ select * from foo join (select a, b+c as bc from tbitmap) proj on foo.a=proj.a; -- 7 btree with grby explain (costs off) select * from foo join (select a, count(*) as cnt from tbtree group by a,b) grby on foo.a=grby.a; - QUERY PLAN -------------------------------------------------------- + QUERY PLAN +--------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo + -> Hash Join + Hash Cond: (tbtree.a = foo.a) -> HashAggregate Group Key: tbtree.a, tbtree.b - -> Index Scan using tbtreexa on tbtree - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) + -> Seq Scan on tbtree + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer (9 rows) select * from foo join (select a, count(*) as cnt from tbtree group by a,b) grby on foo.a=grby.a; @@ -13131,20 +13131,18 @@ select * from foo join (select a, count(*) as cnt from tbtree group by a,b) grby -- 8 bitmap with grby explain (costs off) select * from foo join (select a, count(*) as cnt from tbitmap group by a) grby on foo.a=grby.a; - QUERY PLAN --------------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) -> HashAggregate Group Key: tbitmap.a - -> Bitmap Heap Scan on tbitmap - Recheck Cond: (a = foo.a) - -> Bitmap Index Scan on tbitmapxa - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) -(11 rows) + -> Seq Scan on tbitmap + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(9 rows) select * from foo join (select a, count(*) as cnt from tbitmap group by a) grby on foo.a=grby.a; a | b | c | a | cnt @@ -13164,21 +13162,22 @@ select * from foo join (select a, count(*) as cnt from tbitmap group by a) grby -- 9 btree with proj select grby select explain (costs off) select * from foo join (select a, count(*) + 5 as cnt from tbtree where tbtree.a < 5000 group by a having count(*) < 2) proj_sel_grby_sel on foo.a=proj_sel_grby_sel.a; - QUERY PLAN --------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - Filter: (a < 5000) - -> Result - Filter: ((count()) < 2) - -> HashAggregate - Group Key: tbtree.a - -> Index Scan using tbtreexa on tbtree - Index Cond: ((a = foo.a) AND (a < 5000)) - Optimizer: Pivotal Optimizer (GPORCA) -(12 rows) + -> Hash Join + Hash Cond: (tbtree.a = foo.a) + -> HashAggregate + Group Key: tbtree.a + Filter: (count(*) < 2) + -> Bitmap Heap Scan on tbtree + Recheck Cond: (a < 5000) + -> Bitmap Index Scan on tbtreexa + Index Cond: (a < 5000) + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(13 rows) select * from foo join (select a, count(*) + 5 as cnt from tbtree where tbtree.a < 5000 group by a having count(*) < 2) proj_sel_grby_sel on foo.a=proj_sel_grby_sel.a; a | b | c | a | cnt @@ -13191,23 +13190,22 @@ select * from foo join (select a, count(*) + 5 as cnt from tbtree where tbtree.a -- 10 bitmap with proj select grby select explain (costs off) select * from foo join (select a, count(*) + 5 as cnt from tbitmap where tbitmap.a < 5000 group by a having count(*) < 2) proj_sel_grby_sel on foo.a=proj_sel_grby_sel.a; - QUERY PLAN --------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - Filter: (a < 5000) - -> Result - Filter: ((count()) < 2) - -> HashAggregate - Group Key: tbitmap.a - -> Bitmap Heap Scan on tbitmap - Recheck Cond: ((a = foo.a) AND (a < 5000)) - -> Bitmap Index Scan on tbitmapxa - Index Cond: ((a = foo.a) AND (a < 5000)) - Optimizer: Pivotal Optimizer (GPORCA) -(14 rows) + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) + -> HashAggregate + Group Key: tbitmap.a + Filter: (count(*) < 2) + -> Bitmap Heap Scan on tbitmap + Recheck Cond: (a < 5000) + -> Bitmap Index Scan on tbitmapxa + Index Cond: (a < 5000) + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(13 rows) select * from foo join (select a, count(*) + 5 as cnt from tbitmap where tbitmap.a < 5000 group by a having count(*) < 2) proj_sel_grby_sel on foo.a=proj_sel_grby_sel.a; a | b | c | a | cnt @@ -13220,22 +13218,20 @@ select * from foo join (select a, count(*) + 5 as cnt from tbitmap where tbitmap -- 11 bitmap with two groupbys explain (costs off) select * from foo join (select a, count(*) as cnt from (select distinct a, b from tbitmap) grby1 group by a) grby2 on foo.a=grby2.a; - QUERY PLAN --------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo + -> Hash Join + Hash Cond: (tbitmap.a = foo.a) -> HashAggregate Group Key: tbitmap.a -> HashAggregate Group Key: tbitmap.a, tbitmap.b - -> Bitmap Heap Scan on tbitmap - Recheck Cond: (a = foo.a) - -> Bitmap Index Scan on tbitmapxa - Index Cond: (a = foo.a) - Optimizer: Pivotal Optimizer (GPORCA) -(13 rows) + -> Seq Scan on tbitmap + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(11 rows) select * from foo join (select a, count(*) as cnt from (select distinct a, b from tbitmap) grby1 group by a) grby2 on foo.a=grby2.a; a | b | c | a | cnt @@ -13257,23 +13253,24 @@ explain (costs off) select * from foo join (select a, count(*) + cnt1 as cnt2 from (select a, count(*) as cnt1 from tbtree group by a) grby1 where grby1.a < 5000 group by a, cnt1 having count(*) < 2) proj_sel_grby_sel on foo.a=proj_sel_grby_sel.a; - QUERY PLAN --------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on foo - Filter: (a < 5000) - -> Result - Filter: ((count()) < 2) + -> Hash Join + Hash Cond: (tbtree.a = foo.a) + -> HashAggregate + Group Key: tbtree.a, count(*) + Filter: (count(*) < 2) -> HashAggregate - Group Key: tbtree.a, count() - -> HashAggregate - Group Key: tbtree.a - -> Index Scan using tbtreexa on tbtree - Index Cond: ((a = foo.a) AND (a < 5000)) - Optimizer: Pivotal Optimizer (GPORCA) -(14 rows) + Group Key: tbtree.a + -> Bitmap Heap Scan on tbtree + Recheck Cond: (a < 5000) + -> Bitmap Index Scan on tbtreexa + Index Cond: (a < 5000) + -> Hash + -> Seq Scan on foo + Optimizer: Postgres query optimizer +(15 rows) select * from foo join (select a, count(*) + cnt1 as cnt2 from (select a, count(*) as cnt1 from tbtree group by a) grby1 where grby1.a < 5000 group by a, cnt1 having count(*) < 2) proj_sel_grby_sel @@ -13462,39 +13459,32 @@ select * from tpart_ao_btree where a = 3 and b = 3; (1 row) explain (costs off) select * from tpart_dim d join t_ao_btree f on d.a=f.a where d.b=1; - QUERY PLAN ------------------------------------------------------- + QUERY PLAN +------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on tpart_dim - Filter: (b = 1) - -> Bitmap Heap Scan on t_ao_btree - Recheck Cond: (a = tpart_dim.a) - -> Bitmap Index Scan on t_ao_btree_ix - Index Cond: (a = tpart_dim.a) - Optimizer: Pivotal Optimizer (GPORCA) -(10 rows) + -> Hash Join + Hash Cond: (f.a = d.a) + -> Seq Scan on t_ao_btree f + -> Hash + -> Seq Scan on tpart_dim d + Filter: (b = 1) + Optimizer: Postgres query optimizer +(8 rows) explain (costs off) select * from tpart_dim d join tpart_ao_btree f on d.a=f.a where d.b=1; - QUERY PLAN ------------------------------------------------------------------------------ + QUERY PLAN +---------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on tpart_dim - Filter: (b = 1) + -> Hash Join + Hash Cond: (f.a = d.a) -> Append - -> Bitmap Heap Scan on tpart_ao_btree_1_prt_1 - Recheck Cond: (a = tpart_dim.a) - -> Bitmap Index Scan on tpart_ao_btree_1_prt_1_a_b_idx - Index Cond: (a = tpart_dim.a) - -> Bitmap Heap Scan on tpart_ao_btree_1_prt_2 - Recheck Cond: (a = tpart_dim.a) - -> Bitmap Index Scan on tpart_ao_btree_1_prt_2_a_b_idx - Index Cond: (a = tpart_dim.a) - Optimizer: Pivotal Optimizer (GPORCA) -(15 rows) + -> Seq Scan on tpart_ao_btree_1_prt_1 f_1 + -> Seq Scan on tpart_ao_btree_1_prt_2 f_2 + -> Hash + -> Seq Scan on tpart_dim d + Filter: (b = 1) + Optimizer: Postgres query optimizer +(10 rows) -- negative test, make sure we don't use a btree scan on an AO table -- start_ignore @@ -13670,31 +13660,31 @@ default partition def); create INDEX y_idx on y (j); set optimizer_enable_indexjoin=on; explain (costs off) select count(*) from x, y where (x.i > y.j AND x.j <= y.i); - QUERY PLAN ---------------------------------------------------------------------------- - Aggregate + QUERY PLAN +------------------------------------------------------------------------------------- + Finalize Aggregate -> Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on x - -> Append - -> Index Scan using y_1_prt_p0_j_idx on y_1_prt_p0 - Index Cond: (j < x.i) - Filter: ((j < x.i) AND (x.j <= i)) - -> Index Scan using y_1_prt_p1_j_idx on y_1_prt_p1 - Index Cond: (j < x.i) - Filter: ((j < x.i) AND (x.j <= i)) - -> Index Scan using y_1_prt_p2_j_idx on y_1_prt_p2 - Index Cond: (j < x.i) - Filter: ((j < x.i) AND (x.j <= i)) - -> Index Scan using y_1_prt_p3_j_idx on y_1_prt_p3 - Index Cond: (j < x.i) - Filter: ((j < x.i) AND (x.j <= i)) - -> Index Scan using y_1_prt_def_j_idx on y_1_prt_def - Index Cond: (j < x.i) - Filter: ((j < x.i) AND (x.j <= i)) - Optimizer: Pivotal Optimizer (GPORCA) + -> Partial Aggregate + -> Nested Loop + -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Seq Scan on x + -> Append + -> Index Scan using y_1_prt_p0_j_idx on y_1_prt_p0 y_1 + Index Cond: (j < x.i) + Filter: (x.j <= i) + -> Index Scan using y_1_prt_p1_j_idx on y_1_prt_p1 y_2 + Index Cond: (j < x.i) + Filter: (x.j <= i) + -> Index Scan using y_1_prt_p2_j_idx on y_1_prt_p2 y_3 + Index Cond: (j < x.i) + Filter: (x.j <= i) + -> Index Scan using y_1_prt_p3_j_idx on y_1_prt_p3 y_4 + Index Cond: (j < x.i) + Filter: (x.j <= i) + -> Index Scan using y_1_prt_def_j_idx on y_1_prt_def y_5 + Index Cond: (j < x.i) + Filter: (x.j <= i) + Optimizer: Postgres query optimizer (23 rows) reset optimizer_enable_indexjoin; @@ -14581,3 +14571,105 @@ SELECT gp_segment_id, * FROM result_tab; DROP TABLE IF EXISTS dist_tab_a; DROP TABLE IF EXISTS dist_tab_b; DROP TABLE IF EXISTS result_tab; +--- Test if orca can produce correct plan for inner index nl join +CREATE TABLE t_clientinstrumentind2 ( + tradingday text, + client_id INT, + instrumentid text, + PRIMARY KEY (tradingday, client_id, instrumentid) +) +DISTRIBUTED BY (tradingday, client_id, instrumentid) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2020', appendonly=false) +); +CREATE TABLE t_clientproductind2 ( + tradingday character varying(8), + productid TEXT, + clientid INT, + exchangegroup TEXT, + customertype INT , + PRIMARY KEY (tradingday, productid, clientid, exchangegroup, customertype) +) +DISTRIBUTED BY (tradingday, productid, clientid, exchangegroup, customertype) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2020', appendonly=false) +); +INSERT INTO t_clientinstrumentind2 (tradingday, client_id, instrumentid) VALUES +('20190715', 54982370, 'al1908'), +('20190715', 54982370, 'rb2001'), +('20190715', 54982370, 'cu1909'), +('20190715', 54982370, 'cu1908'), +('20190715', 54982370, 'zn1908'), +('20190715', 54982370, 'pb1908'); +INSERT INTO t_clientproductind2 (tradingday, productid, clientid, exchangegroup, customertype) VALUES +('20190715', 'cu_f', 54982370, 'SHFE', 1), +('20190715', 'rb_f', 54982370, 'SHFE', 1), +('20190715', 'al_f', 54982370, 'SHFE', 1), +('20190715', 'zn_f', 54982370, 'SHFE', 1), +('20190715', 'pb_f', 54982370, 'SHFE', 1); +SET optimizer_enable_hashjoin = OFF; +-- FIXME: orca can't produce correct plan, we fallback this query to +-- postgres optimizer for workaround. See issue 567 +EXPLAIN (COSTS OFF) +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + -> Hash Join + Hash Cond: (t.tradingday = (t_1.tradingday)::text) + -> HashAggregate + Group Key: t.tradingday + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: t.tradingday + -> Bitmap Heap Scan on t_clientinstrumentind_2_prt_p2019 t + Recheck Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text)) + -> Bitmap Index Scan on t_clientinstrumentind_2_prt_p2019_pkey + Index Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text)) + -> Hash + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: t_1.tradingday + -> HashAggregate + Group Key: t_1.tradingday + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: t_1.tradingday + -> Bitmap Heap Scan on t_clientproductind_2_prt_p2019 t_1 + Recheck Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text)) + -> Bitmap Index Scan on t_clientproductind_2_prt_p2019_pkey + Index Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text)) + Optimizer: Postgres query optimizer +(23 rows) + +RESET optimizer_enable_hashjoin; +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; + tradingday | ins_spaninsarbitrageratio | tradingday | prod_spaninsarbitrageratio +------------+---------------------------+------------+---------------------------- + 20190715 | 1 | 20190715 | 0.9233716475 +(1 row) + +DROP TABLE t_clientinstrumentind2, t_clientproductind2; diff --git a/src/test/regress/expected/incremental_sort_optimizer.out b/src/test/regress/expected/incremental_sort_optimizer.out index 5e549c3fb31..f27f36c0296 100644 --- a/src/test/regress/expected/incremental_sort_optimizer.out +++ b/src/test/regress/expected/incremental_sort_optimizer.out @@ -1554,23 +1554,24 @@ order by count(*); QUERY PLAN ------------------------------------------------------------------------------------------------ Sort - Sort Key: (count()) + Sort Key: (count(*)) -> Finalize Aggregate -> Gather Motion 3:1 (slice1; segments: 3) -> Partial Aggregate - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) - -> Seq Scan on tenk1 - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 - Index Cond: (unique1 = tenk1.unique1) - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_2 - Index Cond: (unique1 = tenk1.unique2) - Optimizer: Pivotal Optimizer (GPORCA) -(17 rows) + -> Hash Join + Hash Cond: (t2.unique2 = t1.unique1) + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: t2.unique2 + -> Hash Join + Hash Cond: (t3.unique1 = t2.unique1) + -> Index Only Scan using tenk1_unique1 on tenk1 t3 + -> Hash + -> Bitmap Heap Scan on tenk1 t2 + -> Bitmap Index Scan on tenk1_unique2 + -> Hash + -> Index Only Scan using tenk1_unique1 on tenk1 t1 + Optimizer: Postgres query optimizer +(18 rows) -- Parallel sort but with expression (correlated subquery) that -- is prohibited in parallel plans. diff --git a/src/test/regress/expected/indexjoin_optimizer.out b/src/test/regress/expected/indexjoin_optimizer.out index 6daea4fb92f..1a944a60deb 100644 --- a/src/test/regress/expected/indexjoin_optimizer.out +++ b/src/test/regress/expected/indexjoin_optimizer.out @@ -88,27 +88,24 @@ WHERE tq.sym = tt.symbol AND tt.event_ts < tq.end_ts GROUP BY 1 ORDER BY 1 asc ; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice3; segments: 3) (cost=0.00..1359.12 rows=413 width=16) - Merge Key: ((((my_tt_agg_small.event_ts / 100000) / 5) * 5)) - -> Finalize GroupAggregate (cost=0.00..1359.09 rows=138 width=16) - Group Key: ((((my_tt_agg_small.event_ts / 100000) / 5) * 5)) - -> Sort (cost=0.00..1359.08 rows=138 width=16) - Sort Key: ((((my_tt_agg_small.event_ts / 100000) / 5) * 5)) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1358.94 rows=138 width=16) - Hash Key: ((((my_tt_agg_small.event_ts / 100000) / 5) * 5)) - -> Streaming Partial HashAggregate (cost=0.00..1358.93 rows=138 width=16) - Group Key: (((my_tt_agg_small.event_ts / 100000) / 5) * 5) - -> Nested Loop (cost=0.00..1339.87 rows=94594 width=8) - Join Filter: (((my_tq_agg_small.sym)::bpchar = my_tt_agg_small.symbol) AND (my_tt_agg_small.event_ts >= my_tq_agg_small.ets) AND (my_tt_agg_small.event_ts < my_tq_agg_small.end_ts)) - -> Seq Scan on my_tt_agg_small (cost=0.00..431.01 rows=140 width=25) - -> Materialize (cost=0.00..431.16 rows=676 width=20) - -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..431.14 rows=676 width=20) - Hash Key: my_tq_agg_small.sym - -> Seq Scan on my_tq_agg_small (cost=0.00..431.03 rows=676 width=20) - Optimizer: Pivotal Optimizer (GPORCA) version 3.83.0 -(18 rows) + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------- + Finalize GroupAggregate (cost=10000004659.04..10000004809.69 rows=413 width=16) + Group Key: ((((tt.event_ts / 100000) / 5) * 5)) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000004659.04..10000004796.27 rows=1239 width=16) + Merge Key: ((((tt.event_ts / 100000) / 5) * 5)) + -> Partial GroupAggregate (cost=10000004659.04..10000004779.75 rows=413 width=16) + Group Key: ((((tt.event_ts / 100000) / 5) * 5)) + -> Sort (cost=10000004659.04..10000004696.87 rows=15131 width=8) + Sort Key: ((((tt.event_ts / 100000) / 5) * 5)) + -> Nested Loop (cost=10000000000.15..10000003608.53 rows=15131 width=8) + -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=10000000000.00..10000000008.00 rows=420 width=25) + -> Seq Scan on my_tt_agg_small tt (cost=10000000000.00..10000000002.40 rows=140 width=25) + -> Index Scan using my_tq_agg_small_ets_end_ts_ix on my_tq_agg_small tq (cost=0.15..7.93 rows=38 width=20) + Index Cond: ((ets <= tt.event_ts) AND (end_ts > tt.event_ts)) + Filter: (tt.symbol = (sym)::bpchar) + Optimizer: Postgres query optimizer +(15 rows) reset optimizer_segments; reset optimizer_nestloop_factor; @@ -154,17 +151,16 @@ SELECT * from with_index_table td JOIN no_index_table ro ON td.y = ro.a AND td.x --------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: no_index_table.b - -> Seq Scan on no_index_table - -> Bitmap Heap Scan on with_index_table - Recheck Cond: (x = no_index_table.b) - Filter: (y = no_index_table.a) + Hash Key: ro.b + -> Seq Scan on no_index_table ro + -> Bitmap Heap Scan on with_index_table td + Recheck Cond: (x = ro.b) + Filter: (ro.a = y) -> Bitmap Index Scan on with_index_table_index - Index Cond: (x = no_index_table.b) - Optimizer: Pivotal Optimizer (GPORCA) version 3.88.1 -(12 rows) + Index Cond: (x = ro.b) + Optimizer: Postgres query optimizer +(11 rows) SELECT * from with_index_table td JOIN no_index_table ro ON td.y = ro.a AND td.x = ro.b; x | y | fake_col1 | fake_col2 | fake_col3 | a | b diff --git a/src/test/regress/expected/join_optimizer.out b/src/test/regress/expected/join_optimizer.out index 206ddcda57f..f7f7421a8a1 100644 --- a/src/test/regress/expected/join_optimizer.out +++ b/src/test/regress/expected/join_optimizer.out @@ -1914,26 +1914,26 @@ select * from int4_tbl i4, tenk1 a where exists(select * from tenk1 b where a.twothousand = b.twothousand and a.fivethous <> b.fivethous) and i4.f1 = a.tenthous; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + QUERY PLAN +--------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> HashAggregate - Group Key: int4_tbl.f1, int4_tbl.ctid, int4_tbl.gp_segment_id, tenk1_1.unique1, tenk1_1.unique2, tenk1_1.two, tenk1_1.four, tenk1_1.ten, tenk1_1.twenty, tenk1_1.hundred, tenk1_1.thousand, tenk1_1.twothousand, tenk1_1.fivethous, tenk1_1.tenthous, tenk1_1.odd, tenk1_1.even, tenk1_1.stringu1, tenk1_1.stringu2, tenk1_1.string4, tenk1_1.ctid, tenk1_1.gp_segment_id + Group Key: (RowIdExpr) -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: int4_tbl.ctid, int4_tbl.gp_segment_id, tenk1_1.ctid, tenk1_1.gp_segment_id + Hash Key: (RowIdExpr) -> Hash Join - Hash Cond: (tenk1.twothousand = tenk1_1.twothousand) - Join Filter: (tenk1_1.fivethous <> tenk1.fivethous) - -> Seq Scan on tenk1 + Hash Cond: (b.twothousand = a.twothousand) + Join Filter: (a.fivethous <> b.fivethous) + -> Seq Scan on tenk1 b -> Hash -> Broadcast Motion 3:3 (slice3; segments: 3) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice4; segments: 3) - -> Seq Scan on int4_tbl - -> Index Scan using tenk1_thous_tenthous on tenk1 tenk1_1 - Index Cond: (tenthous = int4_tbl.f1) - Optimizer: Pivotal Optimizer (GPORCA) + -> Hash Join + Hash Cond: (a.tenthous = i4.f1) + -> Seq Scan on tenk1 a + -> Hash + -> Broadcast Motion 3:3 (slice4; segments: 3) + -> Seq Scan on int4_tbl i4 + Optimizer: Postgres query optimizer (18 rows) -- @@ -2372,30 +2372,28 @@ 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 ---------------------------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Hash Join - Hash Cond: ((sum(int4_tbl.f1)) = (((sum(int4_tbl_1.f1)) + 1))) - Join Filter: ((((((sum(int4_tbl_1.f1)) + 1)) + (sum(int4_tbl.f1))) + 999) = (tenk1.tenthous)::bigint) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 1:3 (slice2) - -> Finalize Aggregate - -> Gather Motion 3:1 (slice3; segments: 3) - -> Partial Aggregate - -> Seq Scan on int4_tbl - -> Index Only Scan using tenk1_thous_tenthous on tenk1 - Index Cond: (thousand = (sum(int4_tbl.f1))) - -> Hash - -> Result - -> Broadcast Motion 1:3 (slice4) - -> Finalize Aggregate - -> Gather Motion 3:1 (slice5; segments: 3) - -> Partial Aggregate - -> Seq Scan on int4_tbl int4_tbl_1 - Optimizer: Pivotal Optimizer (GPORCA) -(21 rows) + -> Nested Loop + -> Broadcast Motion 1:3 (slice2; segments: 1) + -> Finalize Aggregate + -> Gather Motion 3:1 (slice3; segments: 3) + -> Partial Aggregate + -> Seq Scan on int4_tbl i4b + -> Materialize + -> Nested Loop + Join Filter: ((sum(i4b.f1)) = ((sum(i4a.f1) + 1))) + -> Materialize + -> Broadcast Motion 1:3 (slice4; segments: 1) + -> Finalize Aggregate + -> Gather Motion 3:1 (slice5; segments: 3) + -> Partial 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))) + Optimizer: Postgres query optimizer +(19 rows) select a.f1, b.f1, t.thousand, t.tenthous from tenk1 t, @@ -2622,19 +2620,19 @@ set enable_memoize to off; explain (costs off) select count(*) from tenk1 a, tenk1 b where a.hundred = b.thousand and (b.fivethous % 10) < 10; - QUERY PLAN ------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------- Finalize Aggregate -> Gather Motion 3:1 (slice1; segments: 3) -> Partial Aggregate - -> Nested Loop - Join Filter: true + -> Hash Join + Hash Cond: (b.thousand = a.hundred) -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on tenk1 + -> Seq Scan on tenk1 b Filter: ((fivethous % 10) < 10) - -> Index Only Scan using tenk1_hundred on tenk1 tenk1_1 - Index Cond: (hundred = tenk1.thousand) - Optimizer: Pivotal Optimizer (GPORCA) + -> Hash + -> Seq Scan on tenk1 a + Optimizer: Postgres query optimizer (11 rows) select count(*) from tenk1 a, tenk1 b @@ -2865,20 +2863,19 @@ rollback; begin; create type mycomptype as (id int, v bigint); create temp table tidv (idv mycomptype); -NOTICE: Table doesn't have 'DISTRIBUTED BY' clause, and no column type is suitable for a distribution key. Creating a NULL policy entry. create index on tidv (idv); explain (costs off) select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; - QUERY PLAN ----------------------------------------------------------- + QUERY PLAN +------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on tidv - -> Index Scan using tidv_idv_idx on tidv tidv_1 - Index Cond: (idv = tidv.idv) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + -> Hash Join + Hash Cond: (a.idv = b.idv) + -> Seq Scan on tidv a + -> Hash + -> Seq Scan on tidv b + Optimizer: Postgres query optimizer +(7 rows) set enable_mergejoin = 0; set enable_hashjoin = 0; @@ -2889,12 +2886,11 @@ select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; ---------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true - -> Seq Scan on tidv - -> Index Scan using tidv_idv_idx on tidv tidv_1 - Index Cond: (idv = tidv.idv) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + -> Seq Scan on tidv a + -> Index Only Scan using tidv_idv_idx on tidv b + Index Cond: (idv = a.idv) + Optimizer: Postgres query optimizer +(6 rows) rollback; -- @@ -3044,29 +3040,25 @@ SELECT qq, unique1 ( SELECT COALESCE(q2, -1) AS qq FROM int8_tbl b ) AS ss2 USING (qq) INNER JOIN tenk1 c ON qq = unique2; - QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Result + -> Hash Join + Hash Cond: (c.unique2 = COALESCE((COALESCE(a.q1, '0'::bigint)), (COALESCE(b.q2, '-1'::bigint)))) + -> Seq Scan on tenk1 c + -> Hash -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Merge Full Join - Merge Cond: ((COALESCE(int8_tbl.q1, '0'::bigint)) = (COALESCE(int8_tbl_1.q2, '-1'::bigint))) - -> Sort - Sort Key: (COALESCE(int8_tbl.q1, '0'::bigint)) - -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: (COALESCE(int8_tbl.q1, '0'::bigint)) - -> Seq Scan on int8_tbl - -> Sort - Sort Key: (COALESCE(int8_tbl_1.q2, '-1'::bigint)) + -> Hash Full Join + Hash Cond: ((COALESCE(a.q1, '0'::bigint)) = (COALESCE(b.q2, '-1'::bigint))) + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: (COALESCE(a.q1, '0'::bigint)) + -> Seq Scan on int8_tbl a + -> Hash -> Redistribute Motion 3:3 (slice4; segments: 3) - Hash Key: (COALESCE(int8_tbl_1.q2, '-1'::bigint)) - -> Seq Scan on int8_tbl int8_tbl_1 - -> Index Scan using tenk1_unique2 on tenk1 - Index Cond: (unique2 = (COALESCE((COALESCE(int8_tbl.q1, '0'::bigint)), (COALESCE(int8_tbl_1.q2, '-1'::bigint))))) - Optimizer: Pivotal Optimizer (GPORCA) -(20 rows) + Hash Key: (COALESCE(b.q2, '-1'::bigint)) + -> Seq Scan on int8_tbl b + Optimizer: Postgres query optimizer +(16 rows) SELECT qq, unique1 FROM @@ -3361,30 +3353,30 @@ select * from tenk1 join int4_tbl on f1 = twothousand, q1, q2 where q1 = thousand or q2 = thousand; - QUERY PLAN --------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) -> Hash Join Hash Cond: (tenk1.twothousand = int4_tbl.f1) -> Nested Loop - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Seq Scan on q2 + -> Materialize -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) - -> Seq Scan on q1 - -> Seq Scan on q2 - -> Bitmap Heap Scan on tenk1 - Recheck Cond: ((thousand = q1.q1) OR (thousand = q2.q2)) - -> BitmapOr - -> Bitmap Index Scan on tenk1_thous_tenthous - Index Cond: (thousand = q1.q1) - -> Bitmap Index Scan on tenk1_thous_tenthous - Index Cond: (thousand = q2.q2) + -> Materialize + -> Broadcast Motion 3:3 (slice3; segments: 3) + -> Seq Scan on q1 + -> Bitmap Heap Scan on tenk1 + Recheck Cond: ((q1.q1 = thousand) OR (q2.q2 = thousand)) + -> BitmapOr + -> Bitmap Index Scan on tenk1_thous_tenthous + Index Cond: (thousand = q1.q1) + -> Bitmap Index Scan on tenk1_thous_tenthous + Index Cond: (thousand = q2.q2) -> Hash -> Broadcast Motion 3:3 (slice4; segments: 3) -> Seq Scan on int4_tbl - Optimizer: Pivotal Optimizer (GPORCA) + Optimizer: Postgres query optimizer (22 rows) explain (costs off) @@ -3392,25 +3384,25 @@ select * from tenk1 join int4_tbl on f1 = twothousand, q1, q2 where thousand = (q1 + q2); - QUERY PLAN ---------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Hash Join - Hash Cond: (tenk1.twothousand = int4_tbl.f1) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice3; segments: 3) - -> Seq Scan on q1 - -> Seq Scan on q2 - -> Index Scan using tenk1_thous_tenthous on tenk1 - Index Cond: (thousand = (q1.q1 + q2.q2)) + Hash Cond: (tenk1.thousand = (q1.q1 + q2.q2)) + -> Hash Join + Hash Cond: (tenk1.twothousand = int4_tbl.f1) + -> Seq Scan on tenk1 + -> Hash + -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Seq Scan on int4_tbl -> Hash - -> Broadcast Motion 3:3 (slice4; segments: 3) - -> Seq Scan on int4_tbl - Optimizer: Pivotal Optimizer (GPORCA) + -> Broadcast Motion 3:3 (slice3; segments: 3) + -> Nested Loop + -> Seq Scan on q1 + -> Materialize + -> Broadcast Motion 3:3 (slice4; segments: 3) + -> Seq Scan on q2 + Optimizer: Postgres query optimizer (17 rows) -- @@ -3421,24 +3413,23 @@ explain (costs off) select * from tenk1, int8_tbl a, int8_tbl b where thousand = a.q1 and tenthous = b.q1 and a.q2 = 1 and b.q2 = 2; - QUERY PLAN ------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Hash Join - Hash Cond: ((tenk1.thousand)::bigint = int8_tbl_1.q1) - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on int8_tbl - Filter: (q2 = 2) - -> Index Scan using tenk1_thous_tenthous on tenk1 - Index Cond: (tenthous = int8_tbl.q1) - -> Hash - -> Broadcast Motion 3:3 (slice3; segments: 3) - -> Seq Scan on int8_tbl int8_tbl_1 - Filter: (q2 = 1) - Optimizer: Pivotal Optimizer (GPORCA) -(15 rows) + -> Nested Loop + -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Seq Scan on int8_tbl b + Filter: (q2 = 2) + -> Materialize + -> Nested Loop + -> Materialize + -> Broadcast Motion 3:3 (slice3; segments: 3) + -> Seq Scan on int8_tbl a + Filter: (q2 = 1) + -> Index Scan using tenk1_thous_tenthous on tenk1 + Index Cond: ((thousand = a.q1) AND (tenthous = b.q1)) + Optimizer: Postgres query optimizer +(14 rows) reset enable_nestloop; -- @@ -3661,58 +3652,45 @@ set enable_nestloop=on; explain (costs off) select unique1 from tenk1, (select * from f_immutable_int4(1) x) x where x = unique1; - QUERY PLAN ---------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Result - Filter: ((1) = 1) - -> Result - -> Index Only Scan using tenk1_unique1 on tenk1 - Index Cond: ((unique1 = (1)) AND (unique1 = 1)) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + QUERY PLAN +---------------------------------------------------- + Gather Motion 1:1 (slice1; segments: 1) + -> Index Only Scan using tenk1_unique1 on tenk1 + Index Cond: (unique1 = 1) + Optimizer: Postgres query optimizer +(4 rows) explain (verbose, costs off) select unique1, x.* from tenk1, (select *, random() from f_immutable_int4(1) x) x where x = unique1; - QUERY PLAN ---------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - Output: unique1, (1), (random()) + Output: tenk1.unique1, (1), (random()) -> Nested Loop - Output: unique1, (1), (random()) - Join Filter: true - -> Broadcast Motion 1:3 (slice2) + Output: tenk1.unique1, (1), (random()) + -> Redistribute Motion 1:3 (slice2; segments: 1) Output: (1), (random()) + Hash Key: (1) -> Result - Output: (1), random() - Filter: ((1) = 1) - -> Result - Output: 1 + Output: 1, random() -> Index Only Scan using tenk1_unique1 on public.tenk1 - Output: unique1 - Index Cond: ((tenk1.unique1 = (1)) AND (tenk1.unique1 = 1)) - Settings: enable_nestloop = 'on', optimizer = 'on' - Optimizer: Pivotal Optimizer (GPORCA) -(17 rows) + Output: tenk1.unique1 + Index Cond: (tenk1.unique1 = (1)) + Settings: enable_nestloop = 'on' + Optimizer: Postgres query optimizer +(14 rows) explain (costs off) select unique1 from tenk1, f_immutable_int4(1) x where x = unique1; - QUERY PLAN ---------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Result - Filter: ((1) = 1) - -> Result - -> Index Only Scan using tenk1_unique1 on tenk1 - Index Cond: ((unique1 = (1)) AND (unique1 = 1)) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + QUERY PLAN +---------------------------------------------------- + Gather Motion 1:1 (slice1; segments: 1) + -> Index Only Scan using tenk1_unique1 on tenk1 + Index Cond: (unique1 = 1) + Optimizer: Postgres query optimizer +(4 rows) explain (costs off) select unique1 from tenk1, lateral f_immutable_int4(1) x where x = unique1; @@ -3734,18 +3712,13 @@ select unique1 from tenk1, lateral f_immutable_int4(1) x where x in (select 17); explain (costs off) select unique1, x from tenk1 join f_immutable_int4(1) x on unique1 = x; - QUERY PLAN ---------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Result - Filter: ((1) = 1) - -> Result - -> Index Only Scan using tenk1_unique1 on tenk1 - Index Cond: ((unique1 = (1)) AND (unique1 = 1)) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + QUERY PLAN +---------------------------------------------------- + Gather Motion 1:1 (slice1; segments: 1) + -> Index Only Scan using tenk1_unique1 on tenk1 + Index Cond: (unique1 = 1) + Optimizer: Postgres query optimizer +(4 rows) explain (costs off) select unique1, x from tenk1 left join f_immutable_int4(1) x on unique1 = x; @@ -3891,98 +3864,81 @@ drop function mki4(int); explain (costs off) select * from tenk1 a join tenk1 b on (a.unique1 = 1 and b.unique1 = 2) or (a.unique2 = 3 and b.hundred = 4); - QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true + Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.hundred = 4))) -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Bitmap Heap Scan on tenk1 + -> Bitmap Heap Scan on tenk1 a Recheck Cond: ((unique1 = 1) OR (unique2 = 3)) -> BitmapOr -> Bitmap Index Scan on tenk1_unique1 Index Cond: (unique1 = 1) -> Bitmap Index Scan on tenk1_unique2 Index Cond: (unique2 = 3) - -> Bitmap Heap Scan on tenk1 tenk1_1 - Recheck Cond: (((unique1 = 2) OR (hundred = 4)) AND ((unique1 = 2) OR (hundred = 4))) - Filter: ((((tenk1.unique1 = 1) AND (unique1 = 2)) OR ((tenk1.unique2 = 3) AND (hundred = 4))) AND ((unique1 = 2) OR (hundred = 4))) - -> BitmapAnd - -> BitmapOr - -> Bitmap Index Scan on tenk1_unique1 - Index Cond: (unique1 = 2) - -> Bitmap Index Scan on tenk1_hundred - Index Cond: (hundred = 4) + -> Materialize + -> Bitmap Heap Scan on tenk1 b + Recheck Cond: ((unique1 = 2) OR (hundred = 4)) -> BitmapOr -> Bitmap Index Scan on tenk1_unique1 Index Cond: (unique1 = 2) -> Bitmap Index Scan on tenk1_hundred Index Cond: (hundred = 4) - Optimizer: Pivotal Optimizer (GPORCA) -(26 rows) + Optimizer: Postgres query optimizer +(20 rows) explain (costs off) select * from tenk1 a join tenk1 b on (a.unique1 = 1 and b.unique1 = 2) or (a.unique2 = 3 and b.ten = 4); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------ + QUERY PLAN +--------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true + Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR ((a.unique2 = 3) AND (b.ten = 4))) -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on tenk1 - Filter: ((unique1 = 2) OR (ten = 4)) - -> Bitmap Heap Scan on tenk1 tenk1_1 - Recheck Cond: (((unique1 = 1) OR (unique2 = 3)) AND ((unique1 = 1) OR (unique2 = 3))) - Filter: ((((unique1 = 1) AND (tenk1.unique1 = 2)) OR ((unique2 = 3) AND (tenk1.ten = 4))) AND ((unique1 = 1) OR (unique2 = 3))) - -> BitmapAnd - -> BitmapOr - -> Bitmap Index Scan on tenk1_unique1 - Index Cond: (unique1 = 1) - -> Bitmap Index Scan on tenk1_unique2 - Index Cond: (unique2 = 3) + -> Bitmap Heap Scan on tenk1 a + Recheck Cond: ((unique1 = 1) OR (unique2 = 3)) -> BitmapOr -> Bitmap Index Scan on tenk1_unique1 Index Cond: (unique1 = 1) -> Bitmap Index Scan on tenk1_unique2 Index Cond: (unique2 = 3) - Optimizer: Pivotal Optimizer (GPORCA) -(21 rows) + -> Materialize + -> Seq Scan on tenk1 b + Filter: ((unique1 = 2) OR (ten = 4)) + Optimizer: Postgres query optimizer +(15 rows) explain (costs off) select * from tenk1 a join tenk1 b on (a.unique1 = 1 and b.unique1 = 2) or ((a.unique2 = 3 or a.unique2 = 7) and b.hundred = 4); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) -> Nested Loop - Join Filter: true + Join Filter: (((a.unique1 = 1) AND (b.unique1 = 2)) OR (((a.unique2 = 3) OR (a.unique2 = 7)) AND (b.hundred = 4))) -> Broadcast Motion 3:3 (slice2; segments: 3) - -> Seq Scan on tenk1 - Filter: ((unique1 = 2) OR (hundred = 4)) - -> Bitmap Heap Scan on tenk1 tenk1_1 - Recheck Cond: (((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7))) AND ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7))) - Filter: ((((unique1 = 1) AND (tenk1.unique1 = 2)) OR (((unique2 = 3) OR (unique2 = 7)) AND (tenk1.hundred = 4))) AND ((unique1 = 1) OR ((unique2 = 3) OR (unique2 = 7)))) - -> BitmapAnd + -> Bitmap Heap Scan on tenk1 a + Recheck Cond: ((unique1 = 1) OR (unique2 = 3) OR (unique2 = 7)) -> BitmapOr -> Bitmap Index Scan on tenk1_unique1 Index Cond: (unique1 = 1) - -> BitmapOr - -> Bitmap Index Scan on tenk1_unique2 - Index Cond: (unique2 = 3) - -> Bitmap Index Scan on tenk1_unique2 - Index Cond: (unique2 = 7) - -> BitmapOr - -> BitmapOr - -> Bitmap Index Scan on tenk1_unique1 - Index Cond: (unique1 = 1) - -> Bitmap Index Scan on tenk1_unique2 - Index Cond: (unique2 = 3) + -> Bitmap Index Scan on tenk1_unique2 + Index Cond: (unique2 = 3) -> Bitmap Index Scan on tenk1_unique2 Index Cond: (unique2 = 7) - Optimizer: Pivotal Optimizer (GPORCA) -(27 rows) + -> Materialize + -> Bitmap Heap Scan on tenk1 b + Recheck Cond: ((unique1 = 2) OR (hundred = 4)) + -> BitmapOr + -> Bitmap Index Scan on tenk1_unique1 + Index Cond: (unique1 = 2) + -> Bitmap Index Scan on tenk1_hundred + Index Cond: (hundred = 4) + Optimizer: Postgres query optimizer +(22 rows) -- -- test placement of movable quals in a parameterized join tree @@ -4051,33 +4007,33 @@ select count(*) from tenk1 a join tenk1 b on a.unique1 = b.unique2 left join tenk1 c on a.unique2 = b.unique1 and c.thousand = a.thousand join int4_tbl on b.thousand = f1; - QUERY PLAN ------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- Finalize Aggregate -> Gather Motion 3:1 (slice1; segments: 3) -> Partial Aggregate - -> Hash Left Join - Hash Cond: (tenk1_1.thousand = tenk1_2.thousand) - Join Filter: (tenk1_1.unique2 = tenk1.unique1) + -> Hash Right Join + Hash Cond: (c.thousand = a.thousand) + Join Filter: (a.unique2 = b.unique1) -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: tenk1_1.thousand - -> Nested Loop - Join Filter: true - -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: tenk1.unique2 - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice4; segments: 3) - -> Seq Scan on int4_tbl - -> Index Scan using tenk1_thous_tenthous on tenk1 - Index Cond: (thousand = int4_tbl.f1) - -> Index Scan using tenk1_unique1 on tenk1 tenk1_1 - Index Cond: (unique1 = tenk1.unique2) + Hash Key: c.thousand + -> Seq Scan on tenk1 c -> Hash - -> Redistribute Motion 3:3 (slice5; segments: 3) - Hash Key: tenk1_2.thousand - -> Seq Scan on tenk1 tenk1_2 - Optimizer: Pivotal Optimizer (GPORCA) + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: a.thousand + -> Hash Join + Hash Cond: (a.unique1 = b.unique2) + -> Seq Scan on tenk1 a + -> Hash + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: b.unique2 + -> Hash Join + Hash Cond: (b.thousand = int4_tbl.f1) + -> Seq Scan on tenk1 b + -> Hash + -> Broadcast Motion 3:3 (slice5; segments: 3) + -> Seq Scan on int4_tbl + Optimizer: Postgres query optimizer (25 rows) select count(*) from @@ -4096,40 +4052,40 @@ select b.unique1 from join int4_tbl i1 on b.thousand = f1 right join int4_tbl i2 on i2.f1 = b.tenthous order by 1; - QUERY PLAN ------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - Merge Key: tenk1.unique1 + Merge Key: b.unique1 -> Sort - Sort Key: tenk1.unique1 + Sort Key: b.unique1 -> Hash Right Join - Hash Cond: (tenk1.tenthous = int4_tbl_1.f1) + Hash Cond: (b.tenthous = i2.f1) -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: tenk1.tenthous - -> Hash Left Join - Hash Cond: (tenk1_1.thousand = tenk1_2.thousand) - Join Filter: (tenk1.unique1 = 42) + Hash Key: b.tenthous + -> Hash Right Join + Hash Cond: (c.thousand = a.thousand) + Join Filter: (b.unique1 = 42) -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: tenk1_1.thousand - -> Nested Loop - Join Filter: true - -> Redistribute Motion 3:3 (slice4; segments: 3) - Hash Key: tenk1.unique2 - -> Nested Loop - Join Filter: true - -> Broadcast Motion 3:3 (slice5; segments: 3) - -> Seq Scan on int4_tbl - -> Index Scan using tenk1_thous_tenthous on tenk1 - Index Cond: (thousand = int4_tbl.f1) - -> Index Scan using tenk1_unique1 on tenk1 tenk1_1 - Index Cond: (unique1 = tenk1.unique2) + Hash Key: c.thousand + -> Seq Scan on tenk1 c -> Hash - -> Redistribute Motion 3:3 (slice6; segments: 3) - Hash Key: tenk1_2.thousand - -> Seq Scan on tenk1 tenk1_2 + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: a.thousand + -> Hash Join + Hash Cond: (a.unique1 = b.unique2) + -> Seq Scan on tenk1 a + -> Hash + -> Redistribute Motion 3:3 (slice5; segments: 3) + Hash Key: b.unique2 + -> Hash Join + Hash Cond: (b.thousand = i1.f1) + -> Seq Scan on tenk1 b + -> Hash + -> Broadcast Motion 3:3 (slice6; segments: 3) + -> Seq Scan on int4_tbl i1 -> Hash - -> Seq Scan on int4_tbl int4_tbl_1 - Optimizer: Pivotal Optimizer (GPORCA) + -> Seq Scan on int4_tbl i2 + Optimizer: Postgres query optimizer (32 rows) select b.unique1 from @@ -6776,16 +6732,15 @@ select * from j1 inner join j2 on j1.id > j2.id; Output: j1.id, j2.id -> Nested Loop Output: j1.id, j2.id - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) Output: j1.id -> Seq Scan on public.j1 Output: j1.id - -> Index Scan using j2_pkey on public.j2 + -> Index Only Scan using j2_pkey on public.j2 Output: j2.id Index Cond: (j2.id < j1.id) - Optimizer: Pivotal Optimizer (GPORCA) -(13 rows) + Optimizer: Postgres query optimizer +(12 rows) -- ensure non-unique rel is not chosen as inner explain (verbose, costs off) @@ -6909,73 +6864,49 @@ select * from j1 natural join j2; explain (verbose, costs off) select * from j1 inner join (select distinct id from j3) j3 on j1.id = j3.id; - QUERY PLAN ------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) Output: j1.id, j3.id - -> Nested Loop + -> Hash Join Output: j1.id, j3.id - Join Filter: true - -> GroupAggregate + Inner Unique: true + Hash Cond: (j1.id = j3.id) + -> Seq Scan on public.j1 + Output: j1.id + -> Hash Output: j3.id - Group Key: j3.id - -> Sort + -> HashAggregate Output: j3.id - Sort Key: j3.id - -> Redistribute Motion 3:3 (slice2; segments: 3) + Group Key: j3.id + -> Seq Scan on public.j3 Output: j3.id - Hash Key: j3.id - -> GroupAggregate - Output: j3.id - Group Key: j3.id - -> Sort - Output: j3.id - Sort Key: j3.id - -> Redistribute Motion 3:3 (slice3; segments: 3) - Output: j3.id - -> Seq Scan on public.j3 - Output: j3.id - -> Index Scan using j1_pkey on public.j1 - Output: j1.id - Index Cond: (j1.id = j3.id) - Optimizer: Pivotal Optimizer (GPORCA) -(28 rows) + Optimizer: Postgres query optimizer +(16 rows) -- ensure group by clause allows the inner to become unique explain (verbose, costs off) select * from j1 inner join (select id from j3 group by id) j3 on j1.id = j3.id; - QUERY PLAN ------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) Output: j1.id, j3.id - -> Nested Loop + -> Hash Join Output: j1.id, j3.id - Join Filter: true - -> GroupAggregate + Inner Unique: true + Hash Cond: (j1.id = j3.id) + -> Seq Scan on public.j1 + Output: j1.id + -> Hash Output: j3.id - Group Key: j3.id - -> Sort + -> HashAggregate Output: j3.id - Sort Key: j3.id - -> Redistribute Motion 3:3 (slice2; segments: 3) + Group Key: j3.id + -> Seq Scan on public.j3 Output: j3.id - Hash Key: j3.id - -> GroupAggregate - Output: j3.id - Group Key: j3.id - -> Sort - Output: j3.id - Sort Key: j3.id - -> Redistribute Motion 3:3 (slice3; segments: 3) - Output: j3.id - -> Seq Scan on public.j3 - Output: j3.id - -> Index Scan using j1_pkey on public.j1 - Output: j1.id - Index Cond: (j1.id = j3.id) - Optimizer: Pivotal Optimizer (GPORCA) -(28 rows) + Optimizer: Postgres query optimizer +(16 rows) drop table j1; drop table j2; @@ -6995,41 +6926,48 @@ analyze j3; explain (verbose, costs off) select * from j1 inner join j2 on j1.id1 = j2.id1; - QUERY PLAN ---------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) Output: j1.id1, j1.id2, j2.id1, j2.id2 - -> Nested Loop + -> Hash Join Output: j1.id1, j1.id2, j2.id1, j2.id2 - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) + Hash Cond: (j1.id1 = j2.id1) + -> Redistribute Motion 3:3 (slice2; segments: 3) + Output: j1.id1, j1.id2 + Hash Key: j1.id1 + -> Seq Scan on public.j1 + Output: j1.id1, j1.id2 + -> Hash Output: j2.id1, j2.id2 - -> Seq Scan on public.j2 + -> Redistribute Motion 3:3 (slice3; segments: 3) Output: j2.id1, j2.id2 - -> Index Scan using j1_pkey on public.j1 - Output: j1.id1, j1.id2 - Index Cond: (j1.id1 = j2.id1) - Optimizer: Pivotal Optimizer (GPORCA) -(13 rows) + Hash Key: j2.id1 + -> Seq Scan on public.j2 + Output: j2.id1, j2.id2 + Optimizer: Postgres query optimizer +(18 rows) -- ensure proper unique detection with multiple join quals explain (verbose, costs off) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2; - QUERY PLAN ---------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) Output: j1.id1, j1.id2, j2.id1, j2.id2 - -> Nested Loop + -> Hash Join Output: j1.id1, j1.id2, j2.id1, j2.id2 - Join Filter: true - -> Seq Scan on public.j2 - Output: j2.id1, j2.id2 - -> Index Scan using j1_pkey on public.j1 + Inner Unique: true + Hash Cond: ((j1.id1 = j2.id1) AND (j1.id2 = j2.id2)) + -> Seq Scan on public.j1 Output: j1.id1, j1.id2 - Index Cond: ((j1.id1 = j2.id1) AND (j1.id2 = j2.id2)) - Optimizer: Pivotal Optimizer (GPORCA) -(11 rows) + -> Hash + Output: j2.id1, j2.id2 + -> Seq Scan on public.j2 + Output: j2.id1, j2.id2 + Optimizer: Postgres query optimizer +(13 rows) -- ensure we don't detect the join to be unique when quals are not part of the -- join condition @@ -7037,24 +6975,26 @@ set enable_nestloop=on; explain (verbose, costs off) select * from j1 inner join j2 on j1.id1 = j2.id1 where j1.id2 = 1; - QUERY PLAN ---------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) Output: j1.id1, j1.id2, j2.id1, j2.id2 -> Nested Loop Output: j1.id1, j1.id2, j2.id1, j2.id2 - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) + Join Filter: (j1.id1 = j2.id1) + -> Seq Scan on public.j1 Output: j1.id1, j1.id2 - -> Index Scan using j1_pkey on public.j1 - Output: j1.id1, j1.id2 - Index Cond: (j1.id2 = 1) - -> Index Scan using j2_pkey on public.j2 + Filter: (j1.id2 = 1) + -> Materialize Output: j2.id1, j2.id2 - Index Cond: (j2.id1 = j1.id1) - Optimizer: Pivotal Optimizer (GPORCA) - Settings: enable_nestloop=on -(15 rows) + -> Redistribute Motion 3:3 (slice2; segments: 3) + Output: j2.id1, j2.id2 + Hash Key: j2.id1, 1 + -> Seq Scan on public.j2 + Output: j2.id1, j2.id2 + Settings: enable_nestloop = 'on' + Optimizer: Postgres query optimizer +(17 rows) -- as above, but for left joins. explain (verbose, costs off) @@ -7097,18 +7037,16 @@ analyze j1; -- GPDB also needs this to get the same plan as in upstream explain (costs off) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 where j1.id1 % 1000 = 1 and j2.id1 % 1000 = 1; - QUERY PLAN ---------------------------------------------------------------- + QUERY PLAN +----------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Seq Scan on j1 - Filter: ((id1 % 1000) = 1) - -> Index Scan using j2_pkey on j2 - Index Cond: ((id1 = j1.id1) AND (id2 = j1.id2)) - Filter: ((id1 % 1000) = 1) - Optimizer: Pivotal Optimizer (GPORCA) -(9 rows) + -> Merge Join + Merge Cond: (j1.id1 = j2.id1) + Join Filter: (j1.id2 = j2.id2) + -> Index Scan using j1_id1_idx on j1 + -> Index Scan using j2_id1_idx on j2 + Optimizer: Postgres query optimizer +(7 rows) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 @@ -7123,19 +7061,18 @@ where j1.id1 % 1000 = 1 and j2.id1 % 1000 = 1; explain (costs off) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 where j1.id1 % 1000 = 1 and j2.id1 % 1000 = 1 and j2.id1 = any (array[1]); - QUERY PLAN -------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Index Scan using j1_pkey on j1 - Index Cond: (id1 = 1) - Filter: ((id1 % 1000) = 1) - -> Index Scan using j2_pkey on j2 - Index Cond: ((id1 = j1.id1) AND (id1 = 1) AND (id2 = j1.id2)) - Filter: (((id1 % 1000) = 1) AND (id1 = ANY ('{1}'::integer[]))) - Optimizer: Pivotal Optimizer (GPORCA) -(10 rows) + -> Merge Join + Merge Cond: (j1.id1 = j2.id1) + Join Filter: (j1.id2 = j2.id2) + -> Index Scan using j1_id1_idx on j1 + Index Cond: (id1 = ANY ('{1}'::integer[])) + -> Index Scan using j2_id1_idx on j2 + Index Cond: (id1 = ANY ('{1}'::integer[])) + Optimizer: Postgres query optimizer +(9 rows) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 @@ -7150,21 +7087,19 @@ where j1.id1 % 1000 = 1 and j2.id1 % 1000 = 1 and j2.id1 = any (array[1]); explain (costs off) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 where j1.id1 % 1000 = 1 and j2.id1 % 1000 = 1 and j2.id1 >= any (array[1,5]); - QUERY PLAN -------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - -> Nested Loop - Join Filter: true - -> Bitmap Heap Scan on j2 - Recheck Cond: (id1 >= ANY ('{1,5}'::integer[])) + -> Merge Join + Merge Cond: ((j1.id1 = j2.id1) AND (j1.id2 = j2.id2)) + -> Index Only Scan using j1_pkey on j1 + Index Cond: (id1 >= ANY ('{1,5}'::integer[])) Filter: ((id1 % 1000) = 1) - -> Bitmap Index Scan on j2_pkey - Index Cond: (id1 >= ANY ('{1,5}'::integer[])) - -> Index Scan using j1_pkey on j1 - Index Cond: ((id1 = j2.id1) AND (id2 = j2.id2)) + -> Index Only Scan using j2_pkey on j2 + Index Cond: (id1 >= ANY ('{1,5}'::integer[])) Filter: ((id1 % 1000) = 1) - Optimizer: Pivotal Optimizer (GPORCA) -(12 rows) + Optimizer: Postgres query optimizer +(10 rows) select * from j1 inner join j2 on j1.id1 = j2.id1 and j1.id2 = j2.id2 diff --git a/src/test/regress/expected/memoize_optimizer.out b/src/test/regress/expected/memoize_optimizer.out index f34752dab7e..bffe157f538 100644 --- a/src/test/regress/expected/memoize_optimizer.out +++ b/src/test/regress/expected/memoize_optimizer.out @@ -39,21 +39,25 @@ SELECT explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty WHERE t2.unique1 < 1000;', false); - explain_memoize ------------------------------------------------------------------------------------------------------- + explain_memoize +------------------------------------------------------------------------------------------------------- Finalize Aggregate (actual rows=1 loops=N) -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=3 loops=N) -> Partial Aggregate (actual rows=1 loops=N) -> Nested Loop (actual rows=400 loops=N) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=1000 loops=N) - -> Index Scan using tenk1_unique1 on tenk1 (actual rows=340 loops=N) - Index Cond: (unique1 < 1000) - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (actual rows=0 loops=N) - Index Cond: (unique1 = tenk1.twenty) - Heap Fetches: N - Optimizer: Pivotal Optimizer (GPORCA) -(12 rows) + -> Redistribute Motion 3:3 (slice2; segments: 3) (actual rows=400 loops=N) + Hash Key: t2.twenty + -> Seq Scan on tenk1 t2 (actual rows=340 loops=N) + Filter: (unique1 < 1000) + Rows Removed by Filter: 2906 + -> Memoize (actual rows=1 loops=N) + Cache Key: t2.twenty + Cache Mode: logical + -> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=1 loops=N) + Index Cond: (unique1 = t2.twenty) + Heap Fetches: N + Optimizer: Postgres query optimizer +(16 rows) -- And check we get the expected results. SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 @@ -109,21 +113,25 @@ SELECT explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand WHERE t2.unique1 < 1200;', true); - explain_memoize ------------------------------------------------------------------------------------------------------- + explain_memoize +-------------------------------------------------------------------------------------------------------- Finalize Aggregate (actual rows=1 loops=N) -> Gather Motion 3:1 (slice1; segments: 3) (actual rows=3 loops=N) -> Partial Aggregate (actual rows=1 loops=N) - -> Nested Loop (actual rows=407 loops=N) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=1200 loops=N) - -> Index Scan using tenk1_unique1 on tenk1 (actual rows=407 loops=N) - Index Cond: (unique1 < 1200) - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (actual rows=0 loops=N) - Index Cond: (unique1 = tenk1.thousand) + -> Merge Join (actual rows=407 loops=N) + Merge Cond: (t1.unique1 = t2.thousand) + -> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=341 loops=N) Heap Fetches: N - Optimizer: Pivotal Optimizer (GPORCA) -(12 rows) + -> Sort (actual rows=407 loops=N) + Sort Key: t2.thousand + Sort Method: quicksort Memory: NkB + -> Redistribute Motion 3:3 (slice2; segments: 3) (actual rows=407 loops=N) + Hash Key: t2.thousand + -> Seq Scan on tenk1 t2 (actual rows=407 loops=N) + Filter: (unique1 < 1200) + Rows Removed by Filter: 2961 + Optimizer: Postgres query optimizer +(16 rows) CREATE TABLE flt (f float); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'f' as the Cloudberry Database data distribution key for this table. @@ -135,31 +143,33 @@ SET enable_seqscan TO off; -- Ensure memoize operates in logical mode SELECT explain_memoize(' SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f = f2.f;', false); - explain_memoize ------------------------------------------------------------------------------ + explain_memoize +------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=4 loops=N) -> Nested Loop (actual rows=4 loops=N) - Join Filter: true - -> Seq Scan on flt (actual rows=2 loops=N) - -> Index Scan using flt_f_idx on flt flt_1 (actual rows=2 loops=N) - Index Cond: (f = flt.f) - Optimizer: Pivotal Optimizer (GPORCA) -(7 rows) + -> Index Only Scan using flt_f_idx on flt f1 (actual rows=2 loops=N) + Heap Fetches: N + -> Index Only Scan using flt_f_idx on flt f2 (actual rows=2 loops=N) + Index Cond: (f = f1.f) + Heap Fetches: N + Optimizer: Postgres query optimizer +(8 rows) -- Ensure memoize operates in binary mode SELECT explain_memoize(' SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f >= f2.f;', false); - explain_memoize ---------------------------------------------------------------------------------- + explain_memoize +------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=4 loops=N) -> Nested Loop (actual rows=4 loops=N) - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=2 loops=N) - -> Seq Scan on flt (actual rows=2 loops=N) - -> Index Scan using flt_f_idx on flt flt_1 (actual rows=2 loops=N) - Index Cond: (f <= flt.f) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + -> Index Only Scan using flt_f_idx on flt f1 (actual rows=2 loops=N) + Heap Fetches: N + -> Index Only Scan using flt_f_idx on flt f2 (actual rows=2 loops=N) + Index Cond: (f <= f1.f) + Heap Fetches: N + Optimizer: Postgres query optimizer +(9 rows) DROP TABLE flt; -- Exercise Memoize in binary mode with a large fixed width type and a @@ -190,17 +200,16 @@ SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.n >= s2.n;', false); -- Ensure we get 3 hits and 3 misses SELECT explain_memoize(' SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', false); - explain_memoize ------------------------------------------------------------------------------------------ + explain_memoize +---------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=24 loops=N) -> Nested Loop (actual rows=16 loops=N) - Join Filter: true -> Broadcast Motion 3:3 (slice2; segments: 3) (actual rows=6 loops=N) - -> Seq Scan on strtest (actual rows=4 loops=N) - -> Index Scan using strtest_t_idx on strtest strtest_1 (actual rows=3 loops=N) - Index Cond: (t <= strtest.t) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + -> Seq Scan on strtest s1 (actual rows=4 loops=N) + -> Index Scan using strtest_t_idx on strtest s2 (actual rows=3 loops=N) + Index Cond: (t <= s1.t) + Optimizer: Postgres query optimizer +(7 rows) DROP TABLE strtest; -- Exercise Memoize code that flushes the cache when a parameter changes which diff --git a/src/test/regress/expected/orca_static_pruning_optimizer.out b/src/test/regress/expected/orca_static_pruning_optimizer.out index 727b2962965..b80154e425c 100644 --- a/src/test/regress/expected/orca_static_pruning_optimizer.out +++ b/src/test/regress/expected/orca_static_pruning_optimizer.out @@ -160,8 +160,6 @@ WHERE b = 42 $query$ AS qry \gset EXPLAIN (COSTS OFF, VERBOSE) :qry ; -INFO: GPORCA failed to produce a plan, falling back to planner -DETAIL: Feature not supported: hash partitioning QUERY PLAN ---------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) @@ -173,8 +171,6 @@ DETAIL: Feature not supported: hash partitioning (6 rows) :qry ; -INFO: GPORCA failed to produce a plan, falling back to planner -DETAIL: Feature not supported: hash partitioning a | b ---+---- 0 | 42 @@ -244,22 +240,22 @@ SET enable_hashjoin TO off; SET enable_mergejoin TO off; SET enable_nestloop TO on; EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM foo JOIN bar on foo.a = bar.a AND foo.b = 11; - QUERY PLAN ---------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) - Output: foo_part2.a, foo_part2.b, bar.a + Output: foo.a, foo.b, bar.a -> Nested Loop - Output: foo_part2.a, foo_part2.b, bar.a - Join Filter: true + Output: foo.a, foo.b, bar.a + Join Filter: (foo.a = bar.a) -> Seq Scan on orca_static_pruning.bar Output: bar.a - -> Append - -> Index Scan using foo_part2_a_idx on orca_static_pruning.foo_part2 - Output: foo_part2.a, foo_part2.b - Index Cond: (foo_part2.a = bar.a) - Filter: ((foo_part2.a = bar.a) AND (foo_part2.b = 11)) - Optimizer: Pivotal Optimizer (GPORCA) - Settings: enable_hashjoin=off, enable_mergejoin=off, enable_nestloop=on, optimizer=on + -> Materialize + Output: foo.a, foo.b + -> Seq Scan on orca_static_pruning.foo_part2 foo + Output: foo.a, foo.b + Filter: (foo.b = 11) + Settings: enable_hashjoin = 'off', enable_mergejoin = 'off', enable_nestloop = 'on' + Optimizer: Postgres query optimizer (14 rows) SELECT * FROM foo JOIN bar on foo.a = bar.a AND foo.b = 11; diff --git a/src/test/regress/expected/rpt_optimizer.out b/src/test/regress/expected/rpt_optimizer.out index 1783eed147b..1b8008d7a66 100644 --- a/src/test/regress/expected/rpt_optimizer.out +++ b/src/test/regress/expected/rpt_optimizer.out @@ -1008,20 +1008,19 @@ set optimizer_enable_hashjoin=off; set enable_hashjoin=off; set enable_nestloop=on; explain select b from dist_tab where b in (select distinct c from rep_tab); - QUERY PLAN ---------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..443.00 rows=4 width=4) - -> Nested Loop (cost=0.00..443.00 rows=2 width=4) - Join Filter: true - -> GroupAggregate (cost=0.00..431.00 rows=2 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.16..10000000021.44 rows=4 width=4) + -> Nested Loop (cost=10000000001.16..10000000021.39 rows=1 width=4) + -> Unique (cost=10000000001.03..10000000001.04 rows=2 width=4) Group Key: rep_tab.c - -> Sort (cost=0.00..431.00 rows=2 width=4) + -> Sort (cost=10000000001.03..10000000001.03 rows=2 width=4) Sort Key: rep_tab.c - -> Seq Scan on rep_tab (cost=0.00..431.00 rows=2 width=4) - -> Index Scan using idx on dist_tab (cost=0.00..12.00 rows=1 width=4) + -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4) + -> Index Only Scan using idx on dist_tab (cost=0.13..10.16 rows=1 width=4) Index Cond: (b = rep_tab.c) - Optimizer: Pivotal Optimizer (GPORCA) -(11 rows) + Optimizer: Postgres query optimizer +(10 rows) select b from dist_tab where b in (select distinct c from rep_tab); b @@ -1182,31 +1181,36 @@ create table t1_13532(a int, b int) distributed replicated; create table t2_13532(a int, b int) distributed replicated; create index idx_t2_13532 on t2_13532(b); explain (costs off) select * from t1_13532 x, t2_13532 y where y.a < random() and x.b = y.b; - QUERY PLAN ----------------------------------------------------------- - Gather Motion 1:1 (slice1; segments: 1) - -> Nested Loop - Join Filter: true - -> Seq Scan on t1_13532 - -> Index Scan using idx_t2_13532 on t2_13532 - Index Cond: (b = t1_13532.b) - Filter: ((a)::double precision < random()) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + QUERY PLAN +---------------------------------------------------------------------- + Hash Join + Hash Cond: (x.b = y.b) + -> Gather Motion 1:1 (slice1; segments: 1) + -> Seq Scan on t1_13532 x + -> Hash + -> Result + -> Gather Motion 1:1 (slice2; segments: 1) + -> Bitmap Heap Scan on t2_13532 y + Filter: ((a)::double precision < random()) + -> Bitmap Index Scan on idx_t2_13532 + Optimizer: Postgres query optimizer +(11 rows) set enable_bitmapscan = off; explain (costs off) select * from t1_13532 x, t2_13532 y where y.a < random() and x.b = y.b; - QUERY PLAN ----------------------------------------------------------- - Gather Motion 1:1 (slice1; segments: 1) - -> Nested Loop - Join Filter: true - -> Seq Scan on t1_13532 - -> Index Scan using idx_t2_13532 on t2_13532 - Index Cond: (b = t1_13532.b) - Filter: ((a)::double precision < random()) - Optimizer: Pivotal Optimizer (GPORCA) -(8 rows) + QUERY PLAN +---------------------------------------------------------------------- + Hash Join + Hash Cond: (x.b = y.b) + -> Gather Motion 1:1 (slice1; segments: 1) + -> Seq Scan on t1_13532 x + -> Hash + -> Result + -> Gather Motion 1:1 (slice2; segments: 1) + -> Index Scan using idx_t2_13532 on t2_13532 y + Filter: ((a)::double precision < random()) + Optimizer: Postgres query optimizer +(10 rows) -- test for optimizer_enable_replicated_table explain (costs off) select * from rep_tab; diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out index e38d83cc02d..5991016c98d 100644 --- a/src/test/regress/expected/subselect_gp_optimizer.out +++ b/src/test/regress/expected/subselect_gp_optimizer.out @@ -1658,27 +1658,22 @@ EXPLAIN SELECT '' AS five, f1 AS "Correlated Field" EXPLAIN select count(*) from (select 1 from tenk1 a where unique1 IN (select hundred from tenk1 b)) ss; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=0.00..431.98 rows=1 width=8) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.98 rows=1 width=8) - -> Partial Aggregate (cost=0.00..431.98 rows=1 width=8) - -> Nested Loop (cost=0.00..431.98 rows=34 width=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.94 rows=100 width=4) - -> GroupAggregate (cost=0.00..431.94 rows=34 width=4) - Group Key: tenk1.hundred - -> Sort (cost=0.00..431.94 rows=34 width=4) - Sort Key: tenk1.hundred - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..431.94 rows=34 width=4) - Hash Key: tenk1.hundred - -> Streaming HashAggregate (cost=0.00..431.94 rows=34 width=4) - Group Key: tenk1.hundred - -> Seq Scan on tenk1 (cost=0.00..431.51 rows=3334 width=4) - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (cost=0.00..0.04 rows=1 width=1) - Index Cond: (unique1 = tenk1.hundred) - Optimizer: Pivotal Optimizer (GPORCA) version 2.75.0 -(17 rows) + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------- + Finalize Aggregate (cost=210.51..210.52 rows=1 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=210.45..210.50 rows=3 width=8) + -> Partial Aggregate (cost=210.45..210.46 rows=1 width=8) + -> Hash Join (cost=138.92..210.37 rows=33 width=0) + Hash Cond: (a.unique1 = b.hundred) + -> Seq Scan on tenk1 a (cost=0.00..62.33 rows=3333 width=4) + -> Hash (cost=137.67..137.67 rows=100 width=4) + -> HashAggregate (cost=137.33..137.67 rows=100 width=4) + Group Key: b.hundred + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..129.00 rows=3333 width=4) + Hash Key: b.hundred + -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4) + Optimizer: Postgres query optimizer +(13 rows) EXPLAIN select count(distinct ss.ten) from (select ten from tenk1 a @@ -1709,27 +1704,24 @@ EXPLAIN select count(distinct ss.ten) from EXPLAIN select count(*) from (select 1 from tenk1 a where unique1 IN (select distinct hundred from tenk1 b)) ss; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=0.00..431.98 rows=1 width=8) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.98 rows=1 width=8) - -> Partial Aggregate (cost=0.00..431.98 rows=1 width=8) - -> Nested Loop (cost=0.00..431.98 rows=34 width=1) - Join Filter: true - -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.94 rows=100 width=4) - -> GroupAggregate (cost=0.00..431.94 rows=34 width=4) - Group Key: tenk1.hundred - -> Sort (cost=0.00..431.94 rows=34 width=4) - Sort Key: tenk1.hundred - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..431.94 rows=34 width=4) - Hash Key: tenk1.hundred - -> Streaming HashAggregate (cost=0.00..431.94 rows=34 width=4) - Group Key: tenk1.hundred - -> Seq Scan on tenk1 (cost=0.00..431.51 rows=3334 width=4) - -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (cost=0.00..0.04 rows=1 width=1) - Index Cond: (unique1 = tenk1.hundred) - Optimizer: Pivotal Optimizer (GPORCA) version 2.75.0 -(17 rows) + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------- + Finalize Aggregate (cost=146.56..146.57 rows=1 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=146.50..146.55 rows=3 width=8) + -> Partial Aggregate (cost=146.50..146.51 rows=1 width=8) + -> Hash Join (cost=75.00..146.42 rows=33 width=0) + Hash Cond: (a.unique1 = b.hundred) + -> Seq Scan on tenk1 a (cost=0.00..62.33 rows=3333 width=4) + -> Hash (cost=74.58..74.58 rows=33 width=4) + -> HashAggregate (cost=73.92..74.25 rows=33 width=4) + Group Key: b.hundred + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=70.67..73.67 rows=100 width=4) + Hash Key: b.hundred + -> HashAggregate (cost=70.67..71.67 rows=100 width=4) + Group Key: b.hundred + -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4) + Optimizer: Postgres query optimizer +(15 rows) EXPLAIN select count(distinct ss.ten) from (select ten from tenk1 a diff --git a/src/test/regress/init_file b/src/test/regress/init_file index 8c7237d1bb4..1ab637b69b9 100644 --- a/src/test/regress/init_file +++ b/src/test/regress/init_file @@ -147,6 +147,14 @@ s/.//gs m/HINT: For non-partitioned tables, run analyze .+\. For partitioned tables, run analyze rootpartition .+\. See log for columns missing statistics\./ s/.//gs +m/INFO: GPORCA failed to produce a plan, falling back to planner/ +s/.//gs +m/DETAIL: Operator Fallback: InnerIndexNestLoopJoin may have wrong plan not supported/ +s/.//gs +m/DETAIL: Feature not supported: hash partitioning/ +s/.//gs + + m/connection to server at "localhost" (.*), port .* failed: / s/.//gs diff --git a/src/test/regress/output/directory_table_optimizer.source b/src/test/regress/output/directory_table_optimizer.source index 78efd3d0022..ddc3ff805a3 100644 --- a/src/test/regress/output/directory_table_optimizer.source +++ b/src/test/regress/output/directory_table_optimizer.source @@ -1209,12 +1209,12 @@ WHERE dir_table1.relative_path = dir_table2.relative_path ORDER BY 1; Merge Key: dir_table1.relative_path -> Sort Sort Key: dir_table1.relative_path - -> Nested Loop - Join Filter: true - -> Seq Scan on dir_table2 - -> Index Scan using dir_table1_pkey on dir_table1 - Index Cond: (relative_path = dir_table2.relative_path) - Optimizer: Pivotal Optimizer (GPORCA) + -> Hash Join + Hash Cond: (dir_table1.relative_path = dir_table2.relative_path) + -> Seq Scan on dir_table1 + -> Hash + -> Seq Scan on dir_table2 + Optimizer: Postgres query optimizer (10 rows) SELECT dir_table1.relative_path FROM dir_table1, dir_table2 diff --git a/src/test/regress/sql/gporca.sql b/src/test/regress/sql/gporca.sql index b9beab300de..8c84f280192 100644 --- a/src/test/regress/sql/gporca.sql +++ b/src/test/regress/sql/gporca.sql @@ -3435,6 +3435,84 @@ DROP TABLE IF EXISTS dist_tab_a; DROP TABLE IF EXISTS dist_tab_b; DROP TABLE IF EXISTS result_tab; +--- Test if orca can produce correct plan for inner index nl join +CREATE TABLE t_clientinstrumentind2 ( + tradingday text, + client_id INT, + instrumentid text, + PRIMARY KEY (tradingday, client_id, instrumentid) +) +DISTRIBUTED BY (tradingday, client_id, instrumentid) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2020', appendonly=false) +); + +CREATE TABLE t_clientproductind2 ( + tradingday character varying(8), + productid TEXT, + clientid INT, + exchangegroup TEXT, + customertype INT , + PRIMARY KEY (tradingday, productid, clientid, exchangegroup, customertype) +) +DISTRIBUTED BY (tradingday, productid, clientid, exchangegroup, customertype) +PARTITION BY RANGE (tradingday) +( + PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2019', appendonly=false), + PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2020', appendonly=false) +); +INSERT INTO t_clientinstrumentind2 (tradingday, client_id, instrumentid) VALUES +('20190715', 54982370, 'al1908'), +('20190715', 54982370, 'rb2001'), +('20190715', 54982370, 'cu1909'), +('20190715', 54982370, 'cu1908'), +('20190715', 54982370, 'zn1908'), +('20190715', 54982370, 'pb1908'); + + +INSERT INTO t_clientproductind2 (tradingday, productid, clientid, exchangegroup, customertype) VALUES +('20190715', 'cu_f', 54982370, 'SHFE', 1), +('20190715', 'rb_f', 54982370, 'SHFE', 1), +('20190715', 'al_f', 54982370, 'SHFE', 1), +('20190715', 'zn_f', 54982370, 'SHFE', 1), +('20190715', 'pb_f', 54982370, 'SHFE', 1); + +SET optimizer_enable_hashjoin = OFF; +-- FIXME: orca can't produce correct plan, we fallback this query to +-- postgres optimizer for workaround. See issue 567 +EXPLAIN (COSTS OFF) +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; +RESET optimizer_enable_hashjoin; + +SELECT * FROM( + SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio + FROM t_clientinstrumentind2 t + WHERE t.tradingday BETWEEN '20190715'AND'20190715' + GROUP BY t.tradingday +)t1 +INNER JOIN ( + SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio + FROM t_clientproductind2 t + WHERE t.tradingday BETWEEN'20190715'AND '20190715' + GROUP BY t.tradingday)t2 +ON t1.tradingday = t2.tradingday; + +DROP TABLE t_clientinstrumentind2, t_clientproductind2; + + -- start_ignore DROP SCHEMA orca CASCADE; -- end_ignore