Skip to content

Commit

Permalink
Fix: cherry-pick "Dynamic Partition Elimination, retrieving relation …
Browse files Browse the repository at this point in the history
…columns, update tests, intermedia agg"
  • Loading branch information
jiaqizho authored and my-ship-it committed Jan 24, 2025
1 parent 62b6955 commit 44a249a
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 588 deletions.
2 changes: 1 addition & 1 deletion src/backend/gporca/libgpopt/src/base/CUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3837,7 +3837,7 @@ CUtils::PexprFuncElemExpr(CMemoryPool *mp, CMDAccessor *md_accessor,
cast_func->GetResultTypeMdid()->AddRef();
CScalarFunc *popCastScalarFunc =
GPOS_NEW(mp) CScalarFunc(mp, mdid_func, cast_func->GetResultTypeMdid(),
typmod, pstrFunc, false /* funcvariadic */);
typmod, pstrFunc, 1 /* Explicit Cast */, false /* funcvariadic */);
mdid_elem_type->AddRef();
CExpression *pexprCaseTest = GPOS_NEW(mp)
CExpression(mp, GPOS_NEW(mp) CScalarCaseTest(mp, mdid_elem_type));
Expand Down
339 changes: 152 additions & 187 deletions src/test/regress/expected/gp_dqa.out

Large diffs are not rendered by default.

140 changes: 59 additions & 81 deletions src/test/regress/expected/gp_dqa_optimizer.out

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/test/regress/expected/gporca.out
Original file line number Diff line number Diff line change
Expand Up @@ -14579,17 +14579,6 @@ explain select * from ts_tbl where ts = to_timestamp('99991231'::text, 'YYYYMMDD
Optimizer: Postgres query optimizer
(4 rows)

WITH conf AS (
SELECT setting
FROM pg_catalog.pg_config
WHERE name = 'LDFLAGS_EX')
select * from conf;
setting
---------

(1 row)

reset optimizer_trace_fallback;
-- Test ORCA support for implicit array coerce cast
-- ORCA should generate a valid plan passing along the cast function as part of ArrayCoerceExpr
-- While execution thin insert query fails due to the mismatch of column length.
Expand All @@ -14610,6 +14599,17 @@ explain insert into array_coerce_foo select * from array_coerce_bar;

insert into array_coerce_foo select * from array_coerce_bar;
ERROR: value too long for type character varying(2) (seg1 127.0.0.1:7003 pid=55908)
WITH conf AS (
SELECT setting
FROM pg_catalog.pg_config
WHERE name = 'LDFLAGS_EX')
select * from conf;
setting
---------

(1 row)

reset optimizer_trace_fallback;
-- These testcases will fallback to postgres when "PexprConvert2In" is enabled if
-- underlying issues are not fixed
create table baz (a int,b int);
Expand Down
22 changes: 11 additions & 11 deletions src/test/regress/expected/gporca_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -14695,17 +14695,6 @@ explain select * from ts_tbl where ts = to_timestamp('99991231'::text, 'YYYYMMDD
Optimizer: Pivotal Optimizer (GPORCA)
(4 rows)

WITH conf AS (
SELECT setting
FROM pg_catalog.pg_config
WHERE name = 'LDFLAGS_EX')
select * from conf;
setting
---------

(1 row)

reset optimizer_trace_fallback;
-- Test ORCA support for implicit array coerce cast
-- ORCA should generate a valid plan passing along the cast function as part of ArrayCoerceExpr
-- While execution thin insert query fails due to the mismatch of column length.
Expand All @@ -14726,6 +14715,17 @@ explain insert into array_coerce_foo select * from array_coerce_bar;

insert into array_coerce_foo select * from array_coerce_bar;
ERROR: value too long for type character varying(2) (seg1 127.0.0.1:7003 pid=51460)
WITH conf AS (
SELECT setting
FROM pg_catalog.pg_config
WHERE name = 'LDFLAGS_EX')
select * from conf;
setting
---------

(1 row)

reset optimizer_trace_fallback;
-- These testcases will fallback to postgres when "PexprConvert2In" is enabled if
-- underlying issues are not fixed
create table baz (a int,b int);
Expand Down
332 changes: 166 additions & 166 deletions src/test/regress/expected/join_gp.out

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/test/regress/expected/join_gp_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -1865,18 +1865,18 @@ EXPLAIN select t1.* from t1 left join (t2 left join t3 on t3.a=t2.b) on t2.a=t1.
(3 rows)

-- inner table is a derived table
EXPLAIN
EXPLAIN (COSTS OFF)
select t1.* from t1 left join
(
select t2.b as v2b, count(*) as v2c
from t2 left join t3 on t3.a=t2.b
group by t2.b
) v2
on v2.v2b=t1.a;
QUERY PLAN
------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=1 width=4)
-> Seq Scan on t1 (cost=0.00..431.00 rows=1 width=4)
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1
Optimizer: Pivotal Optimizer (GPORCA)
(3 rows)

Expand Down
18 changes: 4 additions & 14 deletions src/test/regress/expected/join_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -5105,22 +5105,12 @@ select d.* from d left join (select id from a union select id from b) s
explain (costs off)
select i8.* from int8_tbl i8 left join (select f1 from int4_tbl group by f1) i4
on i8.q1 = i4.f1;
QUERY PLAN
------------------------------------------------------------------
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Hash Left Join
Hash Cond: (int8_tbl.q1 = (int4_tbl.f1)::bigint)
-> Seq Scan on int8_tbl
-> Hash
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: (int4_tbl.f1)::bigint
-> GroupAggregate
Group Key: int4_tbl.f1
-> Sort
Sort Key: int4_tbl.f1
-> Seq Scan on int4_tbl
-> Seq Scan on int8_tbl
Optimizer: Pivotal Optimizer (GPORCA)
(13 rows)
(3 rows)

-- check join removal with lateral references
explain (costs off)
Expand Down
52 changes: 26 additions & 26 deletions src/test/regress/expected/partition_prune_opfamily.out
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ explain select * from t1 where t1.b |=| 1;
------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..16283.50 rows=86100 width=8)
-> Append (cost=0.00..15135.50 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p2 (cost=0.00..7496.00 rows=14350 width=8)
-> Seq Scan on t1_1_prt_p2 t1_1 (cost=0.00..7496.00 rows=14350 width=8)
Filter: (b |=| 1)
-> Seq Scan on t1_1_prt_p1 (cost=0.00..7496.00 rows=14350 width=8)
-> Seq Scan on t1_1_prt_p1 t1_2 (cost=0.00..7496.00 rows=14350 width=8)
Filter: (b |=| 1)
Optimizer: Postgres query optimizer
(7 rows)
Expand All @@ -302,20 +302,20 @@ explain select * from t1, t2 where t1.b = t2.b and t2.b |=| 1;
-----------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=2794.50..426963.08 rows=13414380 width=20)
-> Hash Join (cost=2794.50..248104.68 rows=4471460 width=20)
Hash Cond: (t2_1_prt_p2.b = t1_1_prt_p2.b)
Hash Cond: (t2.b = t1.b)
-> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..14219.83 rows=25967 width=12)
Hash Key: t2_1_prt_p2.b
Hash Key: t2.b
-> Append (cost=0.00..13700.50 rows=25967 width=12)
-> Seq Scan on t2_1_prt_p2 (cost=0.00..6785.33 rows=12983 width=12)
-> Seq Scan on t2_1_prt_p2 t2_1 (cost=0.00..6785.33 rows=12983 width=12)
Filter: (b |=| 1)
-> Seq Scan on t2_1_prt_p1 (cost=0.00..6785.33 rows=12983 width=12)
-> Seq Scan on t2_1_prt_p1 t2_2 (cost=0.00..6785.33 rows=12983 width=12)
Filter: (b |=| 1)
-> Hash (cost=2077.00..2077.00 rows=57400 width=8)
-> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..2077.00 rows=57400 width=8)
Hash Key: t1_1_prt_p2.b
Hash Key: t1.b
-> Append (cost=0.00..929.00 rows=57400 width=8)
-> Seq Scan on t1_1_prt_p2 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p2 t1_1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 t1_2 (cost=0.00..321.00 rows=28700 width=8)
Optimizer: Postgres query optimizer
(17 rows)

Expand All @@ -333,19 +333,19 @@ select * from t1, t2 where t1.b = t2.b and t2.b |=| 1;
(8 rows)

explain select * from t1, t2 where t1.a = t2.a and t1.b |=| t2.b;
QUERY PLAN
---------------------------------------------------------------------------------------------
QUERY PLAN
-----------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=1496.17..1344006.67 rows=13414380 width=20)
-> Hash Join (cost=1496.17..1165148.27 rows=4471460 width=20)
Hash Cond: (t1_1_prt_p2.a = t2_1_prt_p2.a)
Join Filter: (t1_1_prt_p2.b |=| t2_1_prt_p2.b)
Hash Cond: (t1.a = t2.a)
Join Filter: (t1.b |=| t2.b)
-> Append (cost=0.00..929.00 rows=57400 width=8)
-> Seq Scan on t1_1_prt_p2 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p2 t1_1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 t1_2 (cost=0.00..321.00 rows=28700 width=8)
-> Hash (cost=847.00..847.00 rows=51933 width=12)
-> Append (cost=0.00..847.00 rows=51933 width=12)
-> Seq Scan on t2_1_prt_p2 (cost=0.00..293.67 rows=25967 width=12)
-> Seq Scan on t2_1_prt_p1 (cost=0.00..293.67 rows=25967 width=12)
-> Seq Scan on t2_1_prt_p2 t2_1 (cost=0.00..293.67 rows=25967 width=12)
-> Seq Scan on t2_1_prt_p1 t2_2 (cost=0.00..293.67 rows=25967 width=12)
Optimizer: Postgres query optimizer
(12 rows)

Expand All @@ -363,17 +363,17 @@ select * from t1, t2 where t1.a = t2.a and t1.b |=| t2.b;
(8 rows)

explain select * from t1, t2 where t1.a = t2.a and t1.b |=| t2.b and t2.b = 1;
QUERY PLAN
-------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=358.91..1921.43 rows=6707 width=20)
-> Hash Join (cost=358.91..1832.00 rows=2236 width=20)
Hash Cond: (t1_1_prt_p2.a = t2_1_prt_p1.a)
Join Filter: (t1_1_prt_p2.b |=| t2_1_prt_p1.b)
QUERY PLAN
----------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=358.91..1921.44 rows=6707 width=20)
-> Hash Join (cost=358.91..1832.02 rows=2236 width=20)
Hash Cond: (t1.a = t2.a)
Join Filter: (t1.b |=| t2.b)
-> Append (cost=0.00..929.00 rows=57400 width=8)
-> Seq Scan on t1_1_prt_p2 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p2 t1_1 (cost=0.00..321.00 rows=28700 width=8)
-> Seq Scan on t1_1_prt_p1 t1_2 (cost=0.00..321.00 rows=28700 width=8)
-> Hash (cost=358.58..358.58 rows=26 width=12)
-> Seq Scan on t2_1_prt_p1 (cost=0.00..358.58 rows=26 width=12)
-> Seq Scan on t2_1_prt_p1 t2 (cost=0.00..358.58 rows=26 width=12)
Filter: (b = 1)
Optimizer: Postgres query optimizer
(11 rows)
Expand Down
Loading

0 comments on commit 44a249a

Please sign in to comment.