|
| 1 | +# Small driving table |
| 2 | +CREATE TABLE t1 (a INT, b INT); |
| 3 | +INSERT INTO t1 VALUES (1, 1), (2, 2000),(3,300); |
| 4 | +ANALYZE TABLE t1 PERSISTENT FOR ALL; |
| 5 | +Table Op Msg_type Msg_text |
| 6 | +test.t1 analyze status Engine-independent statistics collected |
| 7 | +test.t1 analyze status OK |
| 8 | +# Table that will be accessed by an index lookup (`ref` access) |
| 9 | +CREATE TABLE t2 (a INT, b INT, KEY key_b(b)); |
| 10 | +# All t11.b values are NULL |
| 11 | +INSERT INTO t2 SELECT seq/100, NULL FROM seq_1_to_1000; |
| 12 | +ANALYZE TABLE t2 PERSISTENT FOR ALL; |
| 13 | +Table Op Msg_type Msg_text |
| 14 | +test.t2 analyze status Engine-independent statistics collected |
| 15 | +test.t2 analyze status Table is already up to date |
| 16 | +# NULL-rejecting equality t1.b = t2.b will not return any matches |
| 17 | +# because all values of t2.b are NULL. So "rows" = 1 for t2 where 1 is |
| 18 | +# a special value meaning "very few" rows |
| 19 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t2 ON t1.a = t2.a AND t1.b = t2.b; |
| 20 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 21 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 22 | +1 SIMPLE t2 ref key_b key_b 5 test.t1.b 1 100.00 Using where |
| 23 | +Warnings: |
| 24 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t2`.`b` = `test`.`t1`.`b` |
| 25 | +# However, rows estimation for not NULL-rejecting conditions |
| 26 | +# must not be affected ("rows" > 1 is expected) |
| 27 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t2 ON t1.a = t2.a AND t1.b <=> t2.b; |
| 28 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 29 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 |
| 30 | +1 SIMPLE t2 ref key_b key_b 5 test.t1.b 11 100.00 Using index condition; Using where |
| 31 | +Warnings: |
| 32 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <=> `test`.`t2`.`b` |
| 33 | +ANALYZE SELECT * FROM t1 JOIN t2 ON t1.a = t2.a AND t1.b <=> t2.b; |
| 34 | +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra |
| 35 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 |
| 36 | +1 SIMPLE t2 ref key_b key_b 5 test.t1.b 11 0.00 100.00 100.00 Using index condition; Using where |
| 37 | +# Test composite index for two columns. Key prefix is used for access |
| 38 | +CREATE TABLE t3 (a INT, b INT, KEY key_ab(a,b)); |
| 39 | +# All t3.b values are NULL |
| 40 | +INSERT INTO t3 SELECT seq/100, NULL FROM seq_1_to_1000; |
| 41 | +ANALYZE TABLE t3 PERSISTENT FOR ALL; |
| 42 | +Table Op Msg_type Msg_text |
| 43 | +test.t3 analyze status Engine-independent statistics collected |
| 44 | +test.t3 analyze status Table is already up to date |
| 45 | +# NULL-rejecting equality t1.b = t3.b, same as above. |
| 46 | +# "rows" must be estimated to 1 |
| 47 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t3 ON t1.a = t3.a AND t1.b = t3.b; |
| 48 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 49 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 50 | +1 SIMPLE t3 ref key_ab key_ab 10 test.t1.a,test.t1.b 1 100.00 Using index |
| 51 | +Warnings: |
| 52 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t3`.`b` = `test`.`t1`.`b` |
| 53 | +# Rows estimation for not NULL-rejecting conditions are not affected |
| 54 | +# ("rows" > 1 is expected) |
| 55 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t3 ON t1.a = t3.a; |
| 56 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 57 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 58 | +1 SIMPLE t3 ref key_ab key_ab 5 test.t1.a 90 100.00 Using index |
| 59 | +Warnings: |
| 60 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a` |
| 61 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t3 ON t1.a = t3.a AND t1.b <=> t3.b; |
| 62 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 63 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 64 | +1 SIMPLE t3 ref key_ab key_ab 10 test.t1.a,test.t1.b 11 100.00 Using where; Using index |
| 65 | +Warnings: |
| 66 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <=> `test`.`t3`.`b` |
| 67 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t3 ON t1.a = t3.a AND t3.b is NULL; |
| 68 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 69 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 70 | +1 SIMPLE t3 ref key_ab key_ab 10 test.t1.a,const 11 100.00 Using where; Using index |
| 71 | +Warnings: |
| 72 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a` and `test`.`t3`.`b` is null |
| 73 | +OLEGS: update t2 so that there are not only NULLs, collect the stats and re-test |
| 74 | +# Test composite index for 3 columns. Key prefix is used for access |
| 75 | +CREATE TABLE t4 (a INT, b INT, c INT, KEY key_abc(a,b,c)); |
| 76 | +# All t3.b values are NULL |
| 77 | +INSERT INTO t4 SELECT seq/10, NULL, seq/10 FROM seq_1_to_1000; |
| 78 | +ANALYZE TABLE t4 PERSISTENT FOR ALL; |
| 79 | +Table Op Msg_type Msg_text |
| 80 | +test.t4 analyze status Engine-independent statistics collected |
| 81 | +test.t4 analyze status Table is already up to date |
| 82 | +# NULL-rejecting equality t1.b = t3.b, same as above. |
| 83 | +# "rows" must be estimated to 1 |
| 84 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t4 ON t1.a = t4.a AND t1.b = t4.b; |
| 85 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 86 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 87 | +1 SIMPLE t4 ref key_abc key_abc 10 test.t1.a,test.t1.b 1 100.00 Using index |
| 88 | +Warnings: |
| 89 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t1` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t1`.`a` and `test`.`t4`.`b` = `test`.`t1`.`b` |
| 90 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t4 ON t1.a = t4.a AND t1.b = t4.b and t1.b = t4.c; |
| 91 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 92 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 93 | +1 SIMPLE t4 ref key_abc key_abc 15 test.t1.a,test.t1.b,test.t1.b 1 100.00 Using index |
| 94 | +Warnings: |
| 95 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t1` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t1`.`a` and `test`.`t4`.`b` = `test`.`t1`.`b` and `test`.`t4`.`c` = `test`.`t1`.`b` |
| 96 | +# "rows" expected to be > 1 |
| 97 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t4 ON t1.a = t4.a; |
| 98 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 99 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 100 | +1 SIMPLE t4 ref key_abc key_abc 5 test.t1.a 9 100.00 Using index |
| 101 | +Warnings: |
| 102 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t1` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t1`.`a` |
| 103 | +EXPLAIN EXTENDED SELECT * FROM t1 JOIN t4 ON t1.a = t4.a AND t1.b <=> t4.c; |
| 104 | +id select_type table type possible_keys key key_len ref rows filtered Extra |
| 105 | +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where |
| 106 | +1 SIMPLE t4 ref key_abc key_abc 5 test.t1.a 9 100.00 Using where; Using index |
| 107 | +Warnings: |
| 108 | +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t1` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <=> `test`.`t4`.`c` |
| 109 | +DROP TABLE t1, t2, t3, t4; |
0 commit comments