Merge 10.1 into 10.2

For MDEV-15955, the fix in create_tmp_field_from_item() would cause a
compilation error. After a discussion with Alexander Barkov, the fix
was omitted and only the test case was kept.

In 10.3 and later, MDEV-15955 is fixed properly by overriding
create_tmp_field() in Item_func_user_var.
This commit is contained in:
Marko Mäkelä 2019-08-20 09:15:28 +03:00
commit 48c67038b9
19 changed files with 962 additions and 87 deletions

View File

@ -2928,6 +2928,332 @@ NULL NULL NULL 9
NULL NULL NULL 5
drop table t1,t2,t3,t4,s1,s2;
#
# MDEV-20265: Mix of comma joins with JOIN expressions
# (correction of the fix for MDEV-19421)
# MDEV-20330: duplicate
#
create table t1 (a int);
insert into t1 values (7), (5), (3);
create table t2 (a int);
insert into t2 values (5), (1), (7);
create table t3 (a int);
insert into t3 values (2), (7), (3);
create table t4 (a int);
insert into t4 values (4), (7), (9), (5);
create table t5 (a int);
insert into t5 values (3), (7), (9), (2);
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 5 2 NULL
5 5 2 NULL
3 5 2 NULL
7 1 2 NULL
5 1 2 NULL
3 1 2 NULL
7 7 2 NULL
5 7 2 NULL
3 7 2 NULL
7 5 3 NULL
5 5 3 NULL
3 5 3 NULL
7 1 3 NULL
5 1 3 NULL
3 1 3 NULL
7 7 3 NULL
5 7 3 NULL
3 7 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t4` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 NULL NULL 4
5 NULL NULL 4
3 NULL NULL 4
7 NULL NULL 9
5 NULL NULL 9
3 NULL NULL 9
7 NULL NULL 5
5 NULL NULL 5
3 NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` left join `test`.`t5` on(`test`.`t5`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
7 5 2 7 7
5 5 2 7 7
3 5 2 7 7
7 1 2 7 7
5 1 2 7 7
3 1 2 7 7
7 7 2 7 7
5 7 2 7 7
3 7 2 7 7
7 5 7 7 7
5 5 7 7 7
3 5 7 7 7
7 1 7 7 7
5 1 7 7 7
3 1 7 7 7
7 7 7 7 7
5 7 7 7 7
3 7 7 7 7
7 5 3 7 7
5 5 3 7 7
3 5 3 7 7
7 1 3 7 7
5 1 3 7 7
3 1 3 7 7
7 7 3 7 7
5 7 3 7 7
3 7 3 7 7
7 5 2 9 9
5 5 2 9 9
3 5 2 9 9
7 1 2 9 9
5 1 2 9 9
3 1 2 9 9
7 7 2 9 9
5 7 2 9 9
3 7 2 9 9
7 5 7 9 9
5 5 7 9 9
3 5 7 9 9
7 1 7 9 9
5 1 7 9 9
3 1 7 9 9
7 7 7 9 9
5 7 7 9 9
3 7 7 9 9
7 5 3 9 9
5 5 3 9 9
3 5 3 9 9
7 1 3 9 9
5 1 3 9 9
3 1 3 9 9
7 7 3 9 9
5 7 3 9 9
3 7 3 9 9
7 5 2 4 NULL
5 5 2 4 NULL
3 5 2 4 NULL
7 1 2 4 NULL
5 1 2 4 NULL
3 1 2 4 NULL
7 7 2 4 NULL
5 7 2 4 NULL
3 7 2 4 NULL
7 5 7 4 NULL
5 5 7 4 NULL
3 5 7 4 NULL
7 1 7 4 NULL
5 1 7 4 NULL
3 1 7 4 NULL
7 7 7 4 NULL
5 7 7 4 NULL
3 7 7 4 NULL
7 5 3 4 NULL
5 5 3 4 NULL
3 5 3 4 NULL
7 1 3 4 NULL
5 1 3 4 NULL
3 1 3 4 NULL
7 7 3 4 NULL
5 7 3 4 NULL
3 7 3 4 NULL
7 5 2 5 NULL
5 5 2 5 NULL
3 5 2 5 NULL
7 1 2 5 NULL
5 1 2 5 NULL
3 1 2 5 NULL
7 7 2 5 NULL
5 7 2 5 NULL
3 7 2 5 NULL
7 5 7 5 NULL
5 5 7 5 NULL
3 5 7 5 NULL
7 1 7 5 NULL
5 1 7 5 NULL
3 1 7 5 NULL
7 7 7 5 NULL
5 7 7 5 NULL
3 7 7 5 NULL
7 5 3 5 NULL
5 5 3 5 NULL
3 5 3 5 NULL
7 1 3 5 NULL
5 1 3 5 NULL
3 1 3 5 NULL
7 7 3 5 NULL
5 7 3 5 NULL
3 7 3 5 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t5` left join (`test`.`t2` join `test`.`t3` join `test`.`t4`) on(`test`.`t4`.`a` = `test`.`t5`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
7 5 2 7 7
5 5 2 7 7
3 5 2 7 7
7 1 2 7 7
5 1 2 7 7
3 1 2 7 7
7 7 2 7 7
5 7 2 7 7
3 7 2 7 7
7 5 7 7 7
5 5 7 7 7
3 5 7 7 7
7 1 7 7 7
5 1 7 7 7
3 1 7 7 7
7 7 7 7 7
5 7 7 7 7
3 7 7 7 7
7 5 3 7 7
5 5 3 7 7
3 5 3 7 7
7 1 3 7 7
5 1 3 7 7
3 1 3 7 7
7 7 3 7 7
5 7 3 7 7
3 7 3 7 7
7 5 2 9 9
5 5 2 9 9
3 5 2 9 9
7 1 2 9 9
5 1 2 9 9
3 1 2 9 9
7 7 2 9 9
5 7 2 9 9
3 7 2 9 9
7 5 7 9 9
5 5 7 9 9
3 5 7 9 9
7 1 7 9 9
5 1 7 9 9
3 1 7 9 9
7 7 7 9 9
5 7 7 9 9
3 7 7 9 9
7 5 3 9 9
5 5 3 9 9
3 5 3 9 9
7 1 3 9 9
5 1 3 9 9
3 1 3 9 9
7 7 3 9 9
5 7 3 9 9
3 7 3 9 9
7 NULL NULL NULL 3
5 NULL NULL NULL 3
3 NULL NULL NULL 3
7 NULL NULL NULL 2
5 NULL NULL NULL 2
3 NULL NULL NULL 2
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) join `test`.`t5` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t4`.`a` = `test`.`t5`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
5 5 2 7 7
7 7 2 7 7
3 NULL 2 7 7
5 5 7 7 7
7 7 7 7 7
3 NULL 7 7 7
5 5 3 7 7
7 7 3 7 7
3 NULL 3 7 7
5 5 2 9 9
7 7 2 9 9
3 NULL 2 9 9
5 5 7 9 9
7 7 7 9 9
3 NULL 7 9 9
5 5 3 9 9
7 7 3 9 9
3 NULL 3 9 9
5 5 NULL NULL 3
7 7 NULL NULL 3
3 NULL NULL NULL 3
5 5 NULL NULL 2
7 7 NULL NULL 2
3 NULL NULL NULL 2
drop table t1,t2,t3,t4,t5;
select a.a
from (select 1 as a) a,
(select 2 as b) b
cross join
(select 3 as c) c
left join
(select 4 as d) d
on 1;
a
1
#
# End of MariaDB 5.5 tests
#
#

View File

@ -2,9 +2,15 @@
# MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above
#
# Verbose run
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
@ -28,11 +34,25 @@ Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zo
Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
# Silent run
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
@ -53,39 +73,83 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset,
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
#
# Testing with explicit timezonefile
#
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
#
# Testing --leap
#
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone_leap_second ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone_leap_second;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone_leap_second ENGINE=MyISAM;
END IF|
\d ;
ALTER TABLE time_zone_leap_second ORDER BY Transition_time;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
#
# MDEV-6236 - [PATCH] mysql_tzinfo_to_sql may produce invalid SQL
#
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
TRUNCATE TABLE time_zone_transition_type;
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;

View File

@ -1635,3 +1635,37 @@ set @@use_stat_tables= @save_use_stat_tables;
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
drop function f1;
#
# MDEV-19834 Selectivity of an equality condition discounted twice
#
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables='preferably';
create table t1 (a int, b int, key (b), key (a));
insert into t1
select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
analyze table t1 ;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
# Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.97 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`a` in (17,51,5)
explain extended select * from t1 use index () where b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 4.76 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`b` = 2
# Now, the equality is used for ref access, while the range condition
# gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ref b,a b 5 const 58 2.90 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
drop table t1;
set use_stat_tables= @save_use_stat_tables;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
# End of 10.1 tests

View File

@ -1645,6 +1645,40 @@ set @@use_stat_tables= @save_use_stat_tables;
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
drop function f1;
#
# MDEV-19834 Selectivity of an equality condition discounted twice
#
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables='preferably';
create table t1 (a int, b int, key (b), key (a));
insert into t1
select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
analyze table t1 ;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
# Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.97 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where (`test`.`t1`.`a` in (17,51,5))
explain extended select * from t1 use index () where b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 4.76 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where (`test`.`t1`.`b` = 2)
# Now, the equality is used for ref access, while the range condition
# gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ref b,a b 5 const 59 2.80 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 2) and (`test`.`t1`.`a` in (17,51,5)))
drop table t1;
set use_stat_tables= @save_use_stat_tables;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
# End of 10.1 tests
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
set @tmp_ust= @@use_stat_tables;
set @tmp_oucs= @@optimizer_use_condition_selectivity;

View File

@ -1156,6 +1156,17 @@ ExtractValue('foo','bar') i MIN(d)
3 1976-12-14 13:21:07
DROP TABLE t1;
#
# MDEV-19034 ASAN unknown-crash in get_date_time_separator with PAD_CHAR_TO_FULL_LENGTH
#
SET SQL_MODE=DEFAULT;
CREATE OR REPLACE TABLE t1 (a CHAR(11));
CREATE OR REPLACE TABLE t2 (b DATETIME);
INSERT INTO t1 VALUES ('2010-02-19') ;
SET SQL_MODE= 'PAD_CHAR_TO_FULL_LENGTH';
INSERT INTO t2 SELECT * FROM t1;
DROP TABLE t1, t2;
SET SQL_MODE=DEFAULT;
#
# End of 10.1 tests
#
#

View File

@ -1,4 +1,28 @@
#
# Start of 5.5 tests
#
#
# MDEV-15955 Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_LONGLONG' failed in Protocol_text::store_longlong
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
SELECT @a := 1 FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
@a := 1
1
SELECT COALESCE(1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
COALESCE(1)
1
SELECT COALESCE(@a:=1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
COALESCE(@a:=1)
1
SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
COALESCE(@a)
1
DROP TABLE t1;
#
# End of 5.5 tests
#
#
# Start of 10.1 tests
#
#

View File

@ -2,9 +2,15 @@
# MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above
#
# Verbose run
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
@ -28,11 +34,25 @@ Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zo
Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
# Silent run
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
@ -53,26 +73,56 @@ INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset,
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
#
# Testing with explicit timezonefile
#
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
#
# Testing --leap
#
set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');
prepare set_wsrep_myisam from @prep;
set @toggle=1; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone_leap_second ENGINE=InnoDB;
END IF|
\d ;
TRUNCATE TABLE time_zone_leap_second;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone_leap_second ENGINE=MyISAM;
END IF|
\d ;
ALTER TABLE time_zone_leap_second ORDER BY Transition_time;
set @toggle=0; execute set_wsrep_myisam using @toggle;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;

View File

@ -0,0 +1,74 @@
#
# MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above
#
# Verbose run
set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');
prepare set_wsrep_write_binlog from @prep1;
set @toggle=0; execute set_wsrep_write_binlog using @toggle;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
TRUNCATE TABLE time_zone_transition_type;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('GMT', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/garbage' as time zone. Skipping it.
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/ignored.tab' as time zone. Skipping it.
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('posix/GMT', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it.
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/ignored.tab' as time zone. Skipping it.
Warning: Skipping directory 'MYSQLTEST_VARDIR/zoneinfo/posix/posix': to avoid infinite symlink recursion.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
# Silent run
set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');
prepare set_wsrep_write_binlog from @prep1;
set @toggle=0; execute set_wsrep_write_binlog using @toggle;
TRUNCATE TABLE time_zone;
TRUNCATE TABLE time_zone_name;
TRUNCATE TABLE time_zone_transition;
TRUNCATE TABLE time_zone_transition_type;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('GMT', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/garbage' as time zone. Skipping it.
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('posix/GMT', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
Warning: Unable to load 'MYSQLTEST_VARDIR/zoneinfo/posix/garbage' as time zone. Skipping it.
ALTER TABLE time_zone_transition ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ORDER BY Time_zone_id, Transition_type_id;
#
# Testing with explicit timezonefile
#
set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');
prepare set_wsrep_write_binlog from @prep1;
set @toggle=0; execute set_wsrep_write_binlog using @toggle;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT')
;
#
# Testing --leap
#
set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');
prepare set_wsrep_write_binlog from @prep1;
set @toggle=0; execute set_wsrep_write_binlog using @toggle;
TRUNCATE TABLE time_zone_leap_second;
ALTER TABLE time_zone_leap_second ORDER BY Transition_time;

View File

@ -0,0 +1,40 @@
--source include/have_wsrep.inc
--source include/have_symlink.inc
--source include/not_windows.inc
--echo #
--echo # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above
--echo #
--exec mkdir $MYSQLTEST_VARDIR/zoneinfo
--exec ln -s $MYSQLTEST_VARDIR/zoneinfo $MYSQLTEST_VARDIR/zoneinfo/posix
--copy_file std_data/zoneinfo/GMT $MYSQLTEST_VARDIR/zoneinfo/GMT
--copy_file std_data/words.dat $MYSQLTEST_VARDIR/zoneinfo/garbage
--copy_file std_data/words.dat $MYSQLTEST_VARDIR/zoneinfo/ignored.tab
--echo # Verbose run
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --verbose --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo # Silent run
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo #
--echo # Testing with explicit timezonefile
--echo #
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1
--echo #
--echo # Testing --leap
--echo #
--exec $MYSQL_TZINFO_TO_SQL --leap --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1
#
# Cleanup
#
--exec rm -rf $MYSQLTEST_VARDIR/zoneinfo

View File

@ -1613,6 +1613,65 @@ eval $q;
drop table t1,t2,t3,t4,s1,s2;
--echo #
--echo # MDEV-20265: Mix of comma joins with JOIN expressions
--echo # (correction of the fix for MDEV-19421)
--echo # MDEV-20330: duplicate
--echo #
create table t1 (a int);
insert into t1 values (7), (5), (3);
create table t2 (a int);
insert into t2 values (5), (1), (7);
create table t3 (a int);
insert into t3 values (2), (7), (3);
create table t4 (a int);
insert into t4 values (4), (7), (9), (5);
create table t5 (a int);
insert into t5 values (3), (7), (9), (2);
let $q=
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 left join t4 on t3.a=t4.a;
eval explain extended $q;
eval $q;
let $q=
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 right join t4 on t3.a=t4.a;
eval explain extended $q;
eval $q;
let $q=
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
eval explain extended $q;
eval $q;
let $q=
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
eval explain extended $q;
eval $q;
let $q=
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
eval explain extended $q;
eval $q;
drop table t1,t2,t3,t4,t5;
select a.a
from (select 1 as a) a,
(select 2 as b) b
cross join
(select 3 as c) c
left join
(select 4 as d) d
on 1;
--echo #
--echo # End of MariaDB 5.5 tests
--echo #

View File

@ -1,4 +1,5 @@
--source include/have_stat_tables.inc
--source include/have_sequence.inc
--disable_warnings
drop table if exists t0,t1,t2,t3;
@ -1102,3 +1103,26 @@ set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectiv
drop table t1;
drop function f1;
--echo #
--echo # MDEV-19834 Selectivity of an equality condition discounted twice
--echo #
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables='preferably';
create table t1 (a int, b int, key (b), key (a));
insert into t1
select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
analyze table t1 ;
--echo # Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
explain extended select * from t1 use index () where b=2;
--echo # Now, the equality is used for ref access, while the range condition
--echo # gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
drop table t1;
set use_stat_tables= @save_use_stat_tables;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
--echo # End of 10.1 tests

View File

@ -710,6 +710,20 @@ INSERT INTO t1 VALUES (3,NULL),(3,'1976-12-14 13:21:07'),(NULL,'1981-09-24 01:04
SELECT ExtractValue('foo','bar'), i, MIN(d) FROM t1 GROUP BY i;
DROP TABLE t1;
--echo #
--echo # MDEV-19034 ASAN unknown-crash in get_date_time_separator with PAD_CHAR_TO_FULL_LENGTH
--echo #
SET SQL_MODE=DEFAULT;
CREATE OR REPLACE TABLE t1 (a CHAR(11));
CREATE OR REPLACE TABLE t2 (b DATETIME);
INSERT INTO t1 VALUES ('2010-02-19') ;
SET SQL_MODE= 'PAD_CHAR_TO_FULL_LENGTH';
INSERT INTO t2 SELECT * FROM t1;
DROP TABLE t1, t2;
SET SQL_MODE=DEFAULT;
--echo #
--echo # End of 10.1 tests
--echo #

View File

@ -1,3 +1,24 @@
--echo #
--echo # Start of 5.5 tests
--echo #
--echo #
--echo # MDEV-15955 Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_LONGLONG' failed in Protocol_text::store_longlong
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
SELECT @a := 1 FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
SELECT COALESCE(1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
SELECT COALESCE(@a:=1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
--echo #
--echo # Start of 10.1 tests
--echo #

View File

@ -184,7 +184,7 @@ static int get_date_time_separator(uint *number_of_fields, ulonglong flags,
do
{
s++;
} while (my_isspace(&my_charset_latin1, *s));
} while (s < end && my_isspace(&my_charset_latin1, *s));
*str= s;
return 0;
}

View File

@ -8168,10 +8168,6 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
TABLE_LIST *head= join_list->head();
if (head->nested_join && head->nested_join->nest_type & REBALANCED_NEST)
{
List_iterator<TABLE_LIST> li(*join_list);
li++;
while (li++)
li.remove();
DBUG_RETURN(head);
}
@ -8307,9 +8303,9 @@ void st_select_lex::add_joined_table(TABLE_LIST *table)
J LJ - ON
/ \ / \
t1 LJ - ON (TQ3*) => J t2
t1 LJ - ON (TQ3*) => t3 J
/ \ / \
t3 t2 t1 t3
t3 t2 t1 t2
With several left associative JOINs
SELECT * FROM t1 JOIN t2 JOIN t3 LEFT JOIN t4 ON t3.a=t4.a (Q4)
@ -8317,11 +8313,11 @@ void st_select_lex::add_joined_table(TABLE_LIST *table)
J1 LJ - ON
/ \ / \
t1 LJ - ON J2 t4
t1 J2 J2 t4
/ \ => / \
J2 t4 J1 t3
t2 LJ - ON J1 t3
/ \ / \
t2 t3 t1 t2
t3 t4 t1 t2
Here's another example:
SELECT *
@ -8341,9 +8337,52 @@ void st_select_lex::add_joined_table(TABLE_LIST *table)
the transformation additionally has to take care about setting proper
references in the field natural_join for both operands of the natural
join operation.
The queries that combine comma syntax for join operation with
JOIN expression require a special care. Consider the query
SELECT * FROM t1, t2 JOIN t3 LEFT JOIN t4 ON t3.a=t4.a (Q7)
This query is equivalent to the query
SELECT * FROM (t1, t2) JOIN t3 LEFT JOIN t4 ON t3.a=t4.a
The latter is transformed in the same way as query Q1
J LJ - ON
/ \ / \
(t1,t2) LJ - ON => J t4
/ \ / \
t3 t4 (t1,t2) t3
A transformation similar to the transformation for Q3 is done for
the following query with RIGHT JOIN
SELECT * FROM t1, t2 JOIN t3 RIGHT JOIN t4 ON t3.a=t4.a (Q8)
J LJ - ON
/ \ / \
t3 LJ - ON => t4 J
/ \ / \
t4 (t1,t2) (t1,t2) t3
The function also has to change the name resolution context for ON
expressions used in the transformed join expression to take into
account the tables of the left_op node.
TODO:
A more elegant solution would be to implement the transformation that
eliminates nests for cross join operations. For Q7 it would work like this:
J LJ - ON
/ \ / \
(t1,t2) LJ - ON => (t1,t2,t3) t4
/ \
t3 t4
For Q8 with RIGHT JOIN the transformation would work similarly:
J LJ - ON
/ \ / \
t3 LJ - ON => t4 (t1,t2,t3)
/ \
t4 (t1,t2)
*/
bool st_select_lex::add_cross_joined_table(TABLE_LIST *left_op,
@ -8366,7 +8405,11 @@ bool st_select_lex::add_cross_joined_table(TABLE_LIST *left_op,
}
TABLE_LIST *tbl;
List<TABLE_LIST> *jl= &right_op->nested_join->join_list;
List<TABLE_LIST> *right_op_jl= right_op->join_list;
TABLE_LIST *r_tbl= right_op_jl->pop();
DBUG_ASSERT(right_op == r_tbl);
TABLE_LIST *l_tbl= right_op_jl->pop();
DBUG_ASSERT(left_op == l_tbl);
TABLE_LIST *cj_nest;
/*
@ -8383,6 +8426,8 @@ bool st_select_lex::add_cross_joined_table(TABLE_LIST *left_op,
List<TABLE_LIST> *cjl= &cj_nest->nested_join->join_list;
cjl->empty();
List<TABLE_LIST> *jl= &right_op->nested_join->join_list;
DBUG_ASSERT(jl->elements == 2);
/* Look for the left most node tbl of the right_op tree */
for ( ; ; )
{
@ -8454,6 +8499,8 @@ bool st_select_lex::add_cross_joined_table(TABLE_LIST *left_op,
create a new top level nested join node.
*/
right_op->nested_join->nest_type|= REBALANCED_NEST;
if (unlikely(right_op_jl->push_front(right_op)))
DBUG_RETURN(true);
DBUG_RETURN(false);
}

View File

@ -7961,6 +7961,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
KEYUSE *keyuse= pos->key;
KEYUSE *prev_ref_keyuse= keyuse;
uint key= keyuse->key;
bool used_range_selectivity= false;
/*
Check if we have a prefix of key=const that matches a quick select.
@ -7986,6 +7987,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
keyparts++;
}
sel /= (double)table->quick_rows[key] / (double) table->stat_records();
used_range_selectivity= true;
}
}
@ -8021,13 +8023,14 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
if (keyparts > keyuse->keypart)
{
/* Ok this is the keyuse that will be used for ref access */
if (!used_range_selectivity && keyuse->val->const_item())
{
uint fldno;
if (is_hash_join_key_no(key))
fldno= keyuse->keypart;
else
fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1;
if (keyuse->val->const_item())
{
if (table->field[fldno]->cond_selectivity > 0)
{
sel /= table->field[fldno]->cond_selectivity;
@ -16344,9 +16347,8 @@ Field *Item::create_tmp_field(bool group, TABLE *table, uint convert_int_length)
static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
Item ***copy_func, bool modify_item)
{
Field *UNINIT_VAR(new_field);
DBUG_ASSERT(thd == table->in_use);
new_field= item->Item::create_tmp_field(false, table);
Field *new_field= item->Item::create_tmp_field(false, table);
if (copy_func &&
(item->is_result_field() ||

View File

@ -2119,7 +2119,12 @@ int alloc_statistics_for_table(THD* thd, TABLE *table)
Histogram_type hist_type= (Histogram_type) (thd->variables.histogram_type);
uchar *histogram= NULL;
if (hist_size > 0)
histogram= (uchar *) alloc_root(&table->mem_root, hist_size * columns);
{
if ((histogram= (uchar *) alloc_root(&table->mem_root,
hist_size * columns)))
bzero(histogram, hist_size * columns);
}
if (!table_stats || !column_stats || !index_stats || !idx_avg_frequency ||
(hist_size && !histogram))

View File

@ -148,6 +148,7 @@ typedef struct st_time_zone_info
static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage);
my_bool opt_leap, opt_verbose, opt_skip_write_binlog;
#if defined(TZINFO2SQL) || defined(TESTTIME)
@ -2437,6 +2438,14 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp)
We are assuming that there are only one list of leap seconds
For all timezones.
*/
if (!opt_skip_write_binlog)
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on') = 1 THEN\n"
"ALTER TABLE time_zone_leap_second ENGINE=InnoDB;\n"
"END IF|\n"
"\\d ;\n");
printf("TRUNCATE TABLE time_zone_leap_second;\n");
if (sp->leapcnt)
@ -2449,6 +2458,14 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp)
printf(";\n");
}
if (!opt_skip_write_binlog)
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on') = 1 THEN\n"
"ALTER TABLE time_zone_leap_second ENGINE=MyISAM;\n"
"END IF|\n"
"\\d ;\n");
printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n");
}
@ -2605,8 +2622,6 @@ scan_tz_dir(char * name_end, uint symlink_recursion_level, uint verbose)
}
my_bool opt_leap, opt_verbose;
static const char *load_default_groups[]=
{ "mysql_tzinfo_to_sql", 0};
@ -2627,6 +2642,8 @@ static struct my_option my_long_options[] =
&opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-write-binlog", 'S', "Do not replicate changes to time zone tables to other nodes in a Galera cluster",
&opt_skip_write_binlog,&opt_skip_write_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@ -2695,11 +2712,14 @@ main(int argc, char **argv)
return 1;
}
// Replicate MyISAM DDL for this session, cf. lp:1161432
// timezone info unfixable in XtraDB Cluster
printf("set @prep=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET GLOBAL wsrep_replicate_myisam=?', 'do ?');\n"
"prepare set_wsrep_myisam from @prep;\n"
"set @toggle=1; execute set_wsrep_myisam using @toggle;\n");
if (opt_skip_write_binlog)
/* If skip_write_binlog is set and wsrep is compiled in we disable
sql_log_bin and wsrep_on to avoid Galera replicating below
truncate table clauses. This will allow user to set different
time zones to nodes in Galera cluster. */
printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n"
"prepare set_wsrep_write_binlog from @prep1;\n"
"set @toggle=0; execute set_wsrep_write_binlog using @toggle;\n");
if (argc == 1 && !opt_leap)
{
@ -2707,6 +2727,21 @@ main(int argc, char **argv)
root_name_end= strmake_buf(fullname, argv[0]);
if(!opt_skip_write_binlog)
{
// Alter time zone tables to InnoDB if wsrep_on is enabled
// to allow changes to them to replicate with Galera
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on') = 1 THEN\n"
"ALTER TABLE time_zone ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_name ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition_type ENGINE=InnoDB;\n"
"END IF|\n"
"\\d ;\n");
}
printf("TRUNCATE TABLE time_zone;\n");
printf("TRUNCATE TABLE time_zone_name;\n");
printf("TRUNCATE TABLE time_zone_transition;\n");
@ -2748,8 +2783,19 @@ main(int argc, char **argv)
free_root(&tz_storage, MYF(0));
}
// Reset wsrep_replicate_myisam. lp:1161432
printf("set @toggle=0; execute set_wsrep_myisam using @toggle;\n");
if(!opt_skip_write_binlog)
{
// Fall back to MyISAM
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on') = 1 THEN\n"
"ALTER TABLE time_zone ENGINE=MyISAM;\n"
"ALTER TABLE time_zone_name ENGINE=MyISAM;\n"
"ALTER TABLE time_zone_transition ENGINE=MyISAM;\n"
"ALTER TABLE time_zone_transition_type ENGINE=MyISAM;\n"
"END IF|\n"
"\\d ;\n");
}
free_defaults(default_argv);
my_end(0);

View File

@ -762,7 +762,7 @@ static ssize_t sst_prepare_other (const char* method,
my_free(binlog_opt_val);
my_free(binlog_index_opt_val);
if (ret < 0 || ret >= cmd_len)
if (ret < 0 || size_t(ret) >= cmd_len)
{
WSREP_ERROR("sst_prepare_other(): snprintf() failed: %d", ret);
return (ret < 0 ? ret : -EMSGSIZE);
@ -1064,7 +1064,7 @@ static int sst_donate_mysqldump (const char* addr,
(long long)seqno, wsrep_gtid_domain_id,
bypass ? " " WSREP_SST_OPT_BYPASS : "");
if (ret < 0 || ret >= cmd_len)
if (ret < 0 || size_t(ret) >= cmd_len)
{
WSREP_ERROR("sst_donate_mysqldump(): snprintf() failed: %d", ret);
return (ret < 0 ? ret : -EMSGSIZE);
@ -1434,7 +1434,7 @@ static int sst_donate_other (const char* method,
bypass ? " " WSREP_SST_OPT_BYPASS : "");
my_free(binlog_opt_val);
if (ret < 0 || ret >= cmd_len)
if (ret < 0 || size_t(ret) >= cmd_len)
{
WSREP_ERROR("sst_donate_other(): snprintf() failed: %d", ret);
return (ret < 0 ? ret : -EMSGSIZE);