1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#
# MDEV-6065 MySQL Bug#13623473 "MISSING ROWS ON SELECT AND JOIN WITH TIME/DATETIME COMPARE"
#
# Systematic testing of ref access and range scan
SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key));
INSERT INTO t1 VALUES ('00:00:00'),('-24:00:00'),('-48:00:00'),('24:00:00'),('48:00:00');
CREATE TABLE t2 (col_datetime_key DATETIME, KEY(col_datetime_key));
INSERT INTO t2 SELECT * FROM t1;
let $cnt_0=5;
let $operator= =;
# For operator in =, >=, >, <=, <
while ($cnt_0)
{
let $cnt_1=2;
let $first_table=t1;
# for table in t1,t2
while ($cnt_1)
{
if ($first_table==t1)
{
let $first_index=col_time_key;
let $second_table=t2;
let $second_index=col_datetime_key;
}
if ($first_table==t2)
{
let $first_index=col_datetime_key;
let $second_table=t1;
let $second_index=col_time_key;
}
let $cnt_2=2;
let $first_index_hint=ignore;
# for first_index_hint in ignore,force
while ($cnt_2)
{
let $cnt_3=2;
let $second_index_hint=ignore;
# for second_index_hint in ignore, force
while ($cnt_3)
{
let $cnt_4=2;
let $first_operand=col_time_key;
# for first_operand in col_time_key, col_datetime_key
while ($cnt_4)
{
if ($first_operand==col_time_key)
{
let $second_operand=col_datetime_key;
}
if ($first_operand==col_datetime_key)
{
let $second_operand=col_time_key;
}
eval EXPLAIN EXTENDED SELECT * FROM
$first_table $first_index_hint INDEX ($first_index)
STRAIGHT_JOIN
$second_table $second_index_hint INDEX ($second_index)
WHERE $first_operand $operator $second_operand;
--sorted_result
eval SELECT * FROM
$first_table $first_index_hint INDEX ($first_index)
STRAIGHT_JOIN
$second_table $second_index_hint INDEX ($second_index)
WHERE $first_operand $operator $second_operand;
let $first_operand=col_datetime_key;
dec $cnt_4;
}
let $second_index_hint=force;
dec $cnt_3;
}
let $first_index_hint=force;
dec $cnt_2;
}
let $first_table=t2;
dec $cnt_1;
}
if ($cnt_0==5)
{
let $operator= >=;
}
if ($cnt_0==4)
{
let $operator= >;
}
if ($cnt_0==3)
{
let $operator= <=;
}
if ($cnt_0==2)
{
let $operator= <;
}
dec $cnt_0;
}
DROP TABLE t1,t2;
#
# Original test of the bug report
#
CREATE TABLE t1 (
pk INT NOT NULL AUTO_INCREMENT,
col_int_nokey INT,
col_int_key INT NOT NULL,
PRIMARY KEY (pk),
KEY col_int_key (col_int_key)
);
INSERT INTO t1 VALUES (10,1,7), (11,7,0), (12,4,9), (13,7,3),
(14,0,4), (15,2,2), (16,9,5), (17,4,3), (18,0,1), (19,9,3), (20,1,6),
(21,3,7), (22,8,5), (23,8,1), (24,18,204), (25,84,224), (26,6,9),
(27,3,5), (28,6,0), (29,6,3);
CREATE TABLE t2 (
col_int_nokey INT NOT NULL,
col_datetime_key DATETIME NOT NULL,
col_varchar_key VARCHAR(1) NOT NULL,
KEY col_datetime_key (col_datetime_key),
KEY col_varchar_key (col_varchar_key)
);
INSERT INTO t2 VALUES (1,'2001-11-04 19:07:55','k');
CREATE TABLE t3 (
col_time_key TIME,
KEY col_time_key (col_time_key)
);
INSERT INTO t3 VALUES ('21:22:34'), ('10:50:38'), ('00:21:38'),
('04:08:02'), ('16:25:11'), ('10:14:58'), ('19:47:59'), ('11:14:24'),
('00:00:00'), ('00:00:00'), ('15:57:25'), ('07:05:51'), ('19:22:21'),
('03:53:16'), ('09:16:38'), ('15:37:26'), ('00:00:00'), ('05:03:03'),
('02:59:24'), ('00:01:58');
let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 FORCE INDEX (col_time_key)
ON t3.col_time_key > t2.col_datetime_key;
eval EXPLAIN EXTENDED $query;
--sorted_result
eval $query;
let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 IGNORE INDEX (col_time_key)
ON t3.col_time_key > t2.col_datetime_key;
eval EXPLAIN EXTENDED $query;
--sorted_result
eval $query;
let $query=SELECT outr.col_int_nokey
FROM t2 as outr
STRAIGHT_JOIN t3 AS outr2
ON outr2.col_time_key > outr.col_datetime_key
WHERE outr.col_int_nokey IN (
SELECT col_int_key
FROM t1 AS innr
WHERE innr.pk >= innr.col_int_nokey
) AND (
outr.col_int_nokey <= 6
OR
outr.col_varchar_key IS NULL
);
eval EXPLAIN EXTENDED $query;
--sorted_result
eval $query;
DROP TABLE t1,t2,t3;
SET TIMESTAMP=0; # back to current time
#
# End of 10.0 tests
#
|