Skip to content

Commit

Permalink
Bug #30810572 : FIX INNODB-MYSQL TEST
Browse files Browse the repository at this point in the history
Added ANALYZE TABLE before EXPLAIN SELECT in
innodb.innodb_mysql to stabilize the test case
RB#23871
  • Loading branch information
H N Mohan Kumar committed Feb 20, 2020
1 parent cdb7606 commit 2692669
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mysql-test/include/mix1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ CREATE TABLE t1 (
INDEX idx (a6,a7(239),a5)
) charset latin1 ENGINE=InnoDB;

ANALYZE TABLE t1;
EXPLAIN SELECT a4 FROM t1 WHERE
a6=NULL AND
a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
Expand Down Expand Up @@ -400,6 +401,7 @@ drop table t1;
create table t1 (f1 int, f2 char(1), primary key(f1,f2)) stats_persistent=0;
insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
alter table t1 drop primary key, add primary key (f2, f1);
ANALYZE TABLE t1;
explain select distinct f1 a, f1 b from t1;
explain select distinct f1, f2 from t1;
drop table t1;
Expand Down Expand Up @@ -455,9 +457,13 @@ INSERT INTO t1(id, dept, age, name) VALUES
(4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
(4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');

ANALYZE TABLE t1;
--echo # Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
--replace_column 10 #
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
DELETE FROM t1;
ANALYZE TABLE t1;
--echo # Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
--replace_column 10 #
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
Expand Down
54 changes: 53 additions & 1 deletion mysql-test/suite/innodb/r/innodb_mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ a6 timestamp NOT NULL DEFAULT '2000-01-01 01:01:01',
a7 tinyblob,
INDEX idx (a6,a7(239),a5)
) charset latin1 ENGINE=InnoDB;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT a4 FROM t1 WHERE
a6=NULL AND
a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
Expand Down Expand Up @@ -371,6 +374,9 @@ drop table t1;
create table t1 (f1 int, f2 char(1), primary key(f1,f2)) stats_persistent=0;
insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
alter table t1 drop primary key, add primary key (f2, f1);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
explain select distinct f1 a, f1 b from t1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index PRIMARY PRIMARY 8 NULL 4 100.00 Using index; Using temporary
Expand Down Expand Up @@ -425,16 +431,23 @@ INSERT INTO t1(id, dept, age, name) VALUES
(3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
(4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
(4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
# Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref name name 82 const 2 100.00 Using index
1 SIMPLE t1 NULL ref name name 82 const # 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t1`.`name` AS `name`,`test`.`t1`.`dept` AS `dept` from `test`.`t1` where (`test`.`t1`.`name` = 'rs5')
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
name dept
rs5 cs10
rs5 cs9
DELETE FROM t1;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
# Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Expand Down Expand Up @@ -2032,6 +2045,9 @@ create table t2 (a int, b int, pk int, key(a,b), primary key(pk)) engine=innodb;
insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
Warnings:
Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'.
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
# this must use key 'a', not PRIMARY:
explain select a from t2 where a=b;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Expand Down Expand Up @@ -2540,6 +2556,9 @@ c3 int NOT NULL,
KEY (c1,c2),
KEY (c3)
) ENGINE=InnoDB;
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref c1,c3 c1 4 const 1 100.00 Using where; Using filesort
Expand Down Expand Up @@ -2591,6 +2610,9 @@ c DATETIME NOT NULL,
KEY (c)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT * FROM t1 WHERE a = 'TEST' AND
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
a b c
Expand Down Expand Up @@ -2766,6 +2788,12 @@ INSERT INTO t1 VALUES (105);
INSERT INTO t1 VALUES (106);
INSERT INTO t1 VALUES (107);
INSERT INTO t2 VALUES (107),(75),(1000);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
WHERE t2.id=75 AND t1.id IS NULL;
id id
Expand Down Expand Up @@ -2869,6 +2897,9 @@ INSERT INTO t1 VALUES
(21,1,9916,1), (22,1,9917,1), (23,1,9918,1), (24,1,9919,1), (25,1,9920,1),
(26,1,9921,1), (27,1,9922,1);
FLUSH TABLES;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
ORDER BY f1 DESC LIMIT 5;
f1 f2 f3 f4
Expand Down Expand Up @@ -2898,6 +2929,9 @@ DROP TABLE t1;
CREATE TABLE t1 (a INT , b INT, c INT, d INT,
KEY (b), PRIMARY KEY (a,b)) ENGINE=INNODB STATS_PERSISTENT=0;
INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT COUNT(*) FROM t1;
id 1
select_type SIMPLE
Expand All @@ -2917,6 +2951,9 @@ Code 1003
Message /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t1`
DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT COUNT(*) FROM t1;
id 1
select_type SIMPLE
Expand All @@ -2936,6 +2973,9 @@ Code 1003
Message /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t1`
DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b,c);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT COUNT(*) FROM t1;
id 1
select_type SIMPLE
Expand All @@ -2955,6 +2995,9 @@ Code 1003
Message /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t1`
DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b,c,d);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT COUNT(*) FROM t1;
id 1
select_type SIMPLE
Expand Down Expand Up @@ -3084,6 +3127,12 @@ CREATE TABLE t1 (a tinyblob) ENGINE=InnoDB;
CREATE TABLE t2 (a int PRIMARY KEY, b tinyblob) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('1'), (NULL);
INSERT INTO t2 VALUES (1, '1');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
EXPLAIN
SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
Expand Down Expand Up @@ -3114,6 +3163,9 @@ INSERT INTO t1 VALUES (1,'f','no');
INSERT INTO t1 VALUES (2,'u','yes-u');
INSERT INTO t1 VALUES (2,'h','yes-h');
INSERT INTO t1 VALUES (3,'d','no');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK

SELECT v2
FROM t1
Expand Down
14 changes: 13 additions & 1 deletion mysql-test/suite/innodb/t/innodb_mysql.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, pk int, key(a,b), primary key(pk)) engine=innodb;
insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
ANALYZE TABLE t2;
--echo # this must use key 'a', not PRIMARY:
--replace_column 10 #
explain select a from t2 where a=b;
Expand Down Expand Up @@ -449,6 +450,7 @@ CREATE TABLE t2 (

# SHOULD use the pk.
# if we switch it from a primary key to a regular index, it works correctly as well
ANALYZE TABLE t2;
explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;

DROP TABLE t1,t2;
Expand Down Expand Up @@ -496,6 +498,7 @@ CREATE TABLE t1(
KEY (c)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
ANALYZE TABLE t1;
SELECT * FROM t1 WHERE a = 'TEST' AND
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
SELECT * FROM t1 WHERE a = 'TEST' AND
Expand Down Expand Up @@ -641,6 +644,8 @@ INSERT INTO t1 VALUES (106);
INSERT INTO t1 VALUES (107);

INSERT INTO t2 VALUES (107),(75),(1000);
ANALYZE TABLE t1;
ANALYZE TABLE t2;

SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
WHERE t2.id=75 AND t1.id IS NULL;
Expand Down Expand Up @@ -733,7 +738,7 @@ INSERT INTO t1 VALUES
(26,1,9921,1), (27,1,9922,1);

FLUSH TABLES;

ANALYZE TABLE t1;
SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
ORDER BY f1 DESC LIMIT 5;
EXPLAIN SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
Expand Down Expand Up @@ -761,18 +766,22 @@ DROP TABLE t1;
CREATE TABLE t1 (a INT , b INT, c INT, d INT,
KEY (b), PRIMARY KEY (a,b)) ENGINE=INNODB STATS_PERSISTENT=0;
INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);
ANALYZE TABLE t1;
--query_vertical EXPLAIN SELECT COUNT(*) FROM t1

DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b);
ANALYZE TABLE t1;
--query_vertical EXPLAIN SELECT COUNT(*) FROM t1

DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b,c);
ANALYZE TABLE t1;
--query_vertical EXPLAIN SELECT COUNT(*) FROM t1

DROP INDEX b ON t1;
CREATE INDEX b ON t1(a,b,c,d);
ANALYZE TABLE t1;
--query_vertical EXPLAIN SELECT COUNT(*) FROM t1

DROP TABLE t1;
Expand Down Expand Up @@ -915,6 +924,8 @@ CREATE TABLE t1 (a tinyblob) ENGINE=InnoDB;
CREATE TABLE t2 (a int PRIMARY KEY, b tinyblob) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('1'), (NULL);
INSERT INTO t2 VALUES (1, '1');
ANALYZE TABLE t1;
ANALYZE TABLE t2;

EXPLAIN
SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
Expand All @@ -940,6 +951,7 @@ INSERT INTO t1 VALUES (1,'f','no');
INSERT INTO t1 VALUES (2,'u','yes-u');
INSERT INTO t1 VALUES (2,'h','yes-h');
INSERT INTO t1 VALUES (3,'d','no');
ANALYZE TABLE t1;

--echo
SELECT v2
Expand Down

0 comments on commit 2692669

Please sign in to comment.