Skip to content

Commit 1bab110

Browse files
committed
fix
1 parent 503455f commit 1bab110

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

src/test/regress/expected/gporca.out

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14228,3 +14228,105 @@ SELECT gp_segment_id, * FROM result_tab;
1422814228
DROP TABLE IF EXISTS dist_tab_a;
1422914229
DROP TABLE IF EXISTS dist_tab_b;
1423014230
DROP TABLE IF EXISTS result_tab;
14231+
--- Test if orca can produce correct plan for inner index nl join
14232+
CREATE TABLE t_clientinstrumentind2 (
14233+
tradingday text,
14234+
client_id INT,
14235+
instrumentid text,
14236+
PRIMARY KEY (tradingday, client_id, instrumentid)
14237+
)
14238+
DISTRIBUTED BY (tradingday, client_id, instrumentid)
14239+
PARTITION BY RANGE (tradingday)
14240+
(
14241+
PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2019', appendonly=false),
14242+
PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientinstrumentind_2_prt_p2020', appendonly=false)
14243+
);
14244+
CREATE TABLE t_clientproductind2 (
14245+
tradingday character varying(8),
14246+
productid TEXT,
14247+
clientid INT,
14248+
exchangegroup TEXT,
14249+
customertype INT ,
14250+
PRIMARY KEY (tradingday, productid, clientid, exchangegroup, customertype)
14251+
)
14252+
DISTRIBUTED BY (tradingday, productid, clientid, exchangegroup, customertype)
14253+
PARTITION BY RANGE (tradingday)
14254+
(
14255+
PARTITION p2019 START ('20190101'::character varying(8)) END ('20200101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2019', appendonly=false),
14256+
PARTITION p2020 START ('20200101'::character varying(8)) END ('20210101'::character varying(8)) WITH (tablename='t_clientproductind_2_prt_p2020', appendonly=false)
14257+
);
14258+
INSERT INTO t_clientinstrumentind2 (tradingday, client_id, instrumentid) VALUES
14259+
('20190715', 54982370, 'al1908'),
14260+
('20190715', 54982370, 'rb2001'),
14261+
('20190715', 54982370, 'cu1909'),
14262+
('20190715', 54982370, 'cu1908'),
14263+
('20190715', 54982370, 'zn1908'),
14264+
('20190715', 54982370, 'pb1908');
14265+
INSERT INTO t_clientproductind2 (tradingday, productid, clientid, exchangegroup, customertype) VALUES
14266+
('20190715', 'cu_f', 54982370, 'SHFE', 1),
14267+
('20190715', 'rb_f', 54982370, 'SHFE', 1),
14268+
('20190715', 'al_f', 54982370, 'SHFE', 1),
14269+
('20190715', 'zn_f', 54982370, 'SHFE', 1),
14270+
('20190715', 'pb_f', 54982370, 'SHFE', 1);
14271+
SET optimizer_enable_hashjoin = OFF;
14272+
-- FIXME: orca can't produce correct plan, we fallback this query to
14273+
-- postgres optimizer for workaround
14274+
EXPLAIN (COSTS OFF)
14275+
SELECT * FROM(
14276+
SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio
14277+
FROM t_clientinstrumentind2 t
14278+
WHERE t.tradingday BETWEEN '20190715'AND'20190715'
14279+
GROUP BY t.tradingday
14280+
)t1
14281+
INNER JOIN (
14282+
SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio
14283+
FROM t_clientproductind2 t
14284+
WHERE t.tradingday BETWEEN'20190715'AND '20190715'
14285+
GROUP BY t.tradingday)t2
14286+
ON t1.tradingday = t2.tradingday;
14287+
QUERY PLAN
14288+
-------------------------------------------------------------------------------------------------------------------------------------------------
14289+
Gather Motion 3:1 (slice1; segments: 3)
14290+
-> Hash Join
14291+
Hash Cond: (t.tradingday = (t_1.tradingday)::text)
14292+
-> HashAggregate
14293+
Group Key: t.tradingday
14294+
-> Redistribute Motion 3:3 (slice2; segments: 3)
14295+
Hash Key: t.tradingday
14296+
-> Bitmap Heap Scan on t_clientinstrumentind_2_prt_p2019 t
14297+
Recheck Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text))
14298+
-> Bitmap Index Scan on t_clientinstrumentind_2_prt_p2019_pkey
14299+
Index Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text))
14300+
-> Hash
14301+
-> Redistribute Motion 3:3 (slice3; segments: 3)
14302+
Hash Key: t_1.tradingday
14303+
-> HashAggregate
14304+
Group Key: t_1.tradingday
14305+
-> Redistribute Motion 3:3 (slice4; segments: 3)
14306+
Hash Key: t_1.tradingday
14307+
-> Bitmap Heap Scan on t_clientproductind_2_prt_p2019 t_1
14308+
Recheck Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text))
14309+
-> Bitmap Index Scan on t_clientproductind_2_prt_p2019_pkey
14310+
Index Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text))
14311+
Optimizer: Postgres query optimizer
14312+
(23 rows)
14313+
14314+
RESET optimizer_enable_hashjoin;
14315+
SELECT * FROM(
14316+
SELECT tradingday, 1 AS ins_SpanInsArbitrageRatio
14317+
FROM t_clientinstrumentind2 t
14318+
WHERE t.tradingday BETWEEN '20190715'AND'20190715'
14319+
GROUP BY t.tradingday
14320+
)t1
14321+
INNER JOIN (
14322+
SELECT t.tradingday, 0.9233716475 AS prod_SpanInsArbitrageRatio
14323+
FROM t_clientproductind2 t
14324+
WHERE t.tradingday BETWEEN'20190715'AND '20190715'
14325+
GROUP BY t.tradingday)t2
14326+
ON t1.tradingday = t2.tradingday;
14327+
tradingday | ins_spaninsarbitrageratio | tradingday | prod_spaninsarbitrageratio
14328+
------------+---------------------------+------------+----------------------------
14329+
20190715 | 1 | 20190715 | 0.9233716475
14330+
(1 row)
14331+
14332+
DROP TABLE t_clientinstrumentind2, t_clientproductind2;

0 commit comments

Comments
 (0)