Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-36106 New-style hints: [NO_]DERIVED_CONDITION_PUSHDOWN, [NO_]MERGE #3870

Open
wants to merge 1 commit into
base: bb-11.8-MDEV-35504-opt-hints-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,276 changes: 1,276 additions & 0 deletions mysql-test/main/mdev-36106-derived-condition-pushdown-hint.result

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions mysql-test/main/mdev-36106-derived-condition-pushdown-hint.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
--source include/have_sequence.inc
--disable_ps_protocol
--disable_view_protocol
create table t1 (a int, b int, c int);
create table t2 (a int, b int, c int, d decimal);
insert into t1 values
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
(7,11,708), (6,20,214);
create index t1_a on t1 (a);
insert into t2 values
(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707;
create table t3 select 2*seq as a, 2*seq+1 as b from seq_0_to_1000;
CREATE TABLE t4 (a INT, b INT);
INSERT INTO t4 VALUES (1,2),(2,3),(3,4);
create table t5 select seq as i, 10*seq as j from seq_1_to_10;
create view v2 as select * from t5;

set @save_optimizer_switch=@@optimizer_switch;

set session optimizer_switch='condition_pushdown_for_derived=on';

--source include/explain-no-costs.inc
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));

--source include/explain-no-costs.inc
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);

--source include/explain-no-costs.inc
explain format=json select * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(du)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(du)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt,du)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt,du)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT t4.b AS a
FROM t4
GROUP BY t4.a
) dt WHERE (dt.a=2);
SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT t4.b AS a
FROM t4
GROUP BY t4.a
) dt WHERE (dt.a=2);

--source include/explain-no-costs.inc
explain format=json SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT qb.b AS a
FROM (
select 1*t4.b as b, 1*t4.a as a from t4
) qb
GROUP BY qb.a
) dt WHERE (dt.a=2);
SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT qb.b AS a
FROM (
select 1*t4.b as b, 1*t4.a as a from t4
) qb
GROUP BY qb.a
) dt WHERE (dt.a=2);

set session optimizer_switch='condition_pushdown_for_derived=off';

--source include/explain-no-costs.inc
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
select /*+ DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));

--source include/explain-no-costs.inc
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);

--source include/explain-no-costs.inc
explain format=json SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT t4.b AS a
FROM t4
GROUP BY t4.a
) dt WHERE (dt.a=2);
SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT t4.b AS a
FROM t4
GROUP BY t4.a
) dt WHERE (dt.a=2);

--source include/explain-no-costs.inc
explain format=json SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT qb.b AS a
FROM (
select 1*t4.b as b, 1*t4.a as a from t4
) qb
GROUP BY qb.a
) dt WHERE (dt.a=2);
SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
SELECT qb.b AS a
FROM (
select 1*t4.b as b, 1*t4.a as a from t4
) qb
GROUP BY qb.a
) dt WHERE (dt.a=2);

--source include/explain-no-costs.inc
explain format=json select * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(du)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ DERIVED_CONDITION_PUSHDOWN(du)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

--source include/explain-no-costs.inc
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt,du)*/ * from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
select /*+ DERIVED_CONDITION_PUSHDOWN(dt,du)*/ count(*) from (
select t3.b as a from t3 group by t3.a
) dt join (
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);

set optimizer_switch=@save_optimizer_switch;
drop view v1, v2;
drop table t1, t2, t3, t4, t5;
--enable_view_protocol
--enable_ps_protocol
Loading