Commit e058a251 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-17518: Range optimization doesn't use ON expressions from nested outer joins

Part#2: take into account that join nest that we are marking as constant
might already have constant tables in it. Don't count these tables twice.
parent f0cf85fd
...@@ -2564,4 +2564,19 @@ drop table t1,t2,t3; ...@@ -2564,4 +2564,19 @@ drop table t1,t2,t3;
set optimizer_use_condition_selectivity= @tmp1; set optimizer_use_condition_selectivity= @tmp1;
set use_stat_tables= @tmp2; set use_stat_tables= @tmp2;
set histogram_size= @tmp3; set histogram_size= @tmp3;
# Another test
CREATE TABLE t1 (i1 int) ;
CREATE TABLE t2 (pk int NOT NULL PRIMARY KEY) ;
CREATE TABLE t3 (pk int NOT NULL, i1 int, PRIMARY KEY (pk)) ;
INSERT INTO t3 VALUES (2, NULL);
CREATE TABLE t4 (pk int NOT NULL, i1 int, PRIMARY KEY (pk), KEY i1 (i1)) ;
CREATE VIEW v4 AS SELECT * FROM t4;
SELECT 1
FROM t3 RIGHT JOIN t1 ON t3.i1 = t1.i1
LEFT JOIN v4
RIGHT JOIN t2 ON v4.i1 = t2.pk ON t1.i1 = t2.pk
WHERE t3.pk IN (2);
1
drop view v4;
drop table t1,t2,t3,t4;
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
...@@ -2084,5 +2084,22 @@ set optimizer_use_condition_selectivity= @tmp1; ...@@ -2084,5 +2084,22 @@ set optimizer_use_condition_selectivity= @tmp1;
set use_stat_tables= @tmp2; set use_stat_tables= @tmp2;
set histogram_size= @tmp3; set histogram_size= @tmp3;
--echo # Another test
CREATE TABLE t1 (i1 int) ;
CREATE TABLE t2 (pk int NOT NULL PRIMARY KEY) ;
CREATE TABLE t3 (pk int NOT NULL, i1 int, PRIMARY KEY (pk)) ;
INSERT INTO t3 VALUES (2, NULL);
CREATE TABLE t4 (pk int NOT NULL, i1 int, PRIMARY KEY (pk), KEY i1 (i1)) ;
CREATE VIEW v4 AS SELECT * FROM t4;
SELECT 1
FROM t3 RIGHT JOIN t1 ON t3.i1 = t1.i1
LEFT JOIN v4
RIGHT JOIN t2 ON v4.i1 = t2.pk ON t1.i1 = t2.pk
WHERE t3.pk IN (2);
drop view v4;
drop table t1,t2,t3,t4;
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
...@@ -2575,6 +2575,21 @@ drop table t1,t2,t3; ...@@ -2575,6 +2575,21 @@ drop table t1,t2,t3;
set optimizer_use_condition_selectivity= @tmp1; set optimizer_use_condition_selectivity= @tmp1;
set use_stat_tables= @tmp2; set use_stat_tables= @tmp2;
set histogram_size= @tmp3; set histogram_size= @tmp3;
# Another test
CREATE TABLE t1 (i1 int) ;
CREATE TABLE t2 (pk int NOT NULL PRIMARY KEY) ;
CREATE TABLE t3 (pk int NOT NULL, i1 int, PRIMARY KEY (pk)) ;
INSERT INTO t3 VALUES (2, NULL);
CREATE TABLE t4 (pk int NOT NULL, i1 int, PRIMARY KEY (pk), KEY i1 (i1)) ;
CREATE VIEW v4 AS SELECT * FROM t4;
SELECT 1
FROM t3 RIGHT JOIN t1 ON t3.i1 = t1.i1
LEFT JOIN v4
RIGHT JOIN t2 ON v4.i1 = t2.pk ON t1.i1 = t2.pk
WHERE t3.pk IN (2);
1
drop view v4;
drop table t1,t2,t3,t4;
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
set join_cache_level=default; set join_cache_level=default;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
......
...@@ -4316,14 +4316,17 @@ void mark_join_nest_as_const(JOIN *join, ...@@ -4316,14 +4316,17 @@ void mark_join_nest_as_const(JOIN *join,
} }
JOIN_TAB *tab= tbl->table->reginfo.join_tab; JOIN_TAB *tab= tbl->table->reginfo.join_tab;
tab->type= JT_CONST; if (!(join->const_table_map & tab->table->map))
tab->info= ET_IMPOSSIBLE_ON_CONDITION; {
tab->table->const_table= 1; tab->type= JT_CONST;
tab->info= ET_IMPOSSIBLE_ON_CONDITION;
join->const_table_map|= tab->table->map; tab->table->const_table= 1;
*found_const_table_map|= tab->table->map;
set_position(join,(*const_count)++,tab,(KEYUSE*) 0); join->const_table_map|= tab->table->map;
mark_as_null_row(tab->table); // All fields are NULL *found_const_table_map|= tab->table->map;
set_position(join,(*const_count)++,tab,(KEYUSE*) 0);
mark_as_null_row(tab->table); // All fields are NULL
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment