Commit d0b85a4d authored by Evgeny Potemkin's avatar Evgeny Potemkin

Merged bug#45266.

parents 55b83d71 72d020a2
......@@ -4457,4 +4457,83 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select '0' AS `a`,'0' AS `b`,'0' AS `c` from `test`.`t1` where 1
DROP TABLE t1;
#
# Bug#45266: Uninitialized variable lead to an empty result.
#
drop table if exists A,AA,B,BB;
CREATE TABLE `A` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`date_key` date NOT NULL,
`date_nokey` date NOT NULL,
`datetime_key` datetime NOT NULL,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
`time_nokey` time NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `datetime_key` (`datetime_key`)
);
CREATE TABLE `AA` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
KEY `time_key` (`time_key`),
PRIMARY KEY (`pk`)
);
CREATE TABLE `B` (
`date_nokey` date NOT NULL,
`date_key` date NOT NULL,
`time_key` time NOT NULL,
`datetime_nokey` datetime NOT NULL,
`varchar_key` varchar(1) NOT NULL,
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `varchar_key` (`varchar_key`)
);
INSERT INTO `B` VALUES ('2003-07-28','2003-07-28','15:13:38','0000-00-00 00:00:00','f'),('0000-00-00','0000-00-00','00:05:48','2004-07-02 14:34:13','x');
CREATE TABLE `BB` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`date_key` date NOT NULL,
`varchar_nokey` varchar(1) NOT NULL,
`date_nokey` date NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`)
);
INSERT INTO `BB` VALUES (10,8,'0000-00-00','i','0000-00-00'),(11,0,'2005-08-18','','2005-08-18');
SELECT table1 . `pk` AS field1
FROM
(BB AS table1 INNER JOIN
(AA AS table2 STRAIGHT_JOIN A AS table3
ON ( table3 . `date_key` = table2 . `pk` ))
ON ( table3 . `datetime_key` = table2 . `int_nokey` ))
WHERE ( table3 . `date_key` <= 4 AND table2 . `pk` = table1 . `varchar_nokey`)
GROUP BY field1 ;
field1
SELECT table3 .`date_key` field1
FROM
B table1 LEFT JOIN B table3 JOIN
(BB table6 JOIN A table7 ON table6 .`varchar_nokey`)
ON table6 .`int_nokey` ON table6 .`date_key`
WHERE NOT ( table1 .`varchar_key` AND table7 .`pk`) GROUP BY field1;
field1
NULL
SELECT table4 . `time_nokey` AS field1 FROM
(AA AS table1 CROSS JOIN
(AA AS table2 STRAIGHT_JOIN
(B AS table3 STRAIGHT_JOIN A AS table4
ON ( table4 . `date_key` = table3 . `time_key` ))
ON ( table4 . `pk` = table3 . `date_nokey` ))
ON ( table4 . `time_key` = table3 . `datetime_nokey` ))
WHERE ( table4 . `time_key` < table1 . `time_key` AND
table1 . `int_nokey` != 'f')
GROUP BY field1 ORDER BY field1 , field1;
field1
SELECT table1 .`time_key` field2 FROM B table1 LEFT JOIN BB JOIN A table5 ON table5 .`date_nokey` ON table5 .`int_nokey` GROUP BY field2;
field2
00:05:48
15:13:38
drop table A,AA,B,BB;
#end of test for bug#45266
End of 5.1 tests
......@@ -3799,4 +3799,90 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND a=a AND b=b) OR b > 20;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND b=b AND a=a) OR b > 20;
DROP TABLE t1;
--echo #
--echo # Bug#45266: Uninitialized variable lead to an empty result.
--echo #
--disable_warnings
drop table if exists A,AA,B,BB;
CREATE TABLE `A` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`date_key` date NOT NULL,
`date_nokey` date NOT NULL,
`datetime_key` datetime NOT NULL,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
`time_nokey` time NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `datetime_key` (`datetime_key`)
);
CREATE TABLE `AA` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
KEY `time_key` (`time_key`),
PRIMARY KEY (`pk`)
);
CREATE TABLE `B` (
`date_nokey` date NOT NULL,
`date_key` date NOT NULL,
`time_key` time NOT NULL,
`datetime_nokey` datetime NOT NULL,
`varchar_key` varchar(1) NOT NULL,
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `varchar_key` (`varchar_key`)
);
INSERT INTO `B` VALUES ('2003-07-28','2003-07-28','15:13:38','0000-00-00 00:00:00','f'),('0000-00-00','0000-00-00','00:05:48','2004-07-02 14:34:13','x');
CREATE TABLE `BB` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`date_key` date NOT NULL,
`varchar_nokey` varchar(1) NOT NULL,
`date_nokey` date NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`)
);
INSERT INTO `BB` VALUES (10,8,'0000-00-00','i','0000-00-00'),(11,0,'2005-08-18','','2005-08-18');
# Test #1
SELECT table1 . `pk` AS field1
FROM
(BB AS table1 INNER JOIN
(AA AS table2 STRAIGHT_JOIN A AS table3
ON ( table3 . `date_key` = table2 . `pk` ))
ON ( table3 . `datetime_key` = table2 . `int_nokey` ))
WHERE ( table3 . `date_key` <= 4 AND table2 . `pk` = table1 . `varchar_nokey`)
GROUP BY field1 ;
SELECT table3 .`date_key` field1
FROM
B table1 LEFT JOIN B table3 JOIN
(BB table6 JOIN A table7 ON table6 .`varchar_nokey`)
ON table6 .`int_nokey` ON table6 .`date_key`
WHERE NOT ( table1 .`varchar_key` AND table7 .`pk`) GROUP BY field1;
# Test #2
SELECT table4 . `time_nokey` AS field1 FROM
(AA AS table1 CROSS JOIN
(AA AS table2 STRAIGHT_JOIN
(B AS table3 STRAIGHT_JOIN A AS table4
ON ( table4 . `date_key` = table3 . `time_key` ))
ON ( table4 . `pk` = table3 . `date_nokey` ))
ON ( table4 . `time_key` = table3 . `datetime_nokey` ))
WHERE ( table4 . `time_key` < table1 . `time_key` AND
table1 . `int_nokey` != 'f')
GROUP BY field1 ORDER BY field1 , field1;
SELECT table1 .`time_key` field2 FROM B table1 LEFT JOIN BB JOIN A table5 ON table5 .`date_nokey` ON table5 .`int_nokey` GROUP BY field2;
--enable_warnings
drop table A,AA,B,BB;
--echo #end of test for bug#45266
--echo End of 5.1 tests
......@@ -2963,6 +2963,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->insert_values= 0;
table->fulltext_searched= 0;
table->file->ft_handler= 0;
table->reginfo.impossible_range= 0;
/* Catch wrong handling of the auto_increment_field_not_null. */
DBUG_ASSERT(!table->auto_increment_field_not_null);
table->auto_increment_field_not_null= FALSE;
......
......@@ -2432,7 +2432,6 @@ static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select,
if (select)
{
select->head=table;
table->reginfo.impossible_range=0;
if ((error= select->test_quick_select(thd, *(key_map *)keys,(table_map) 0,
limit, 0)) == 1)
DBUG_RETURN(select->quick->records);
......
......@@ -107,6 +107,10 @@ typedef struct st_reginfo { /* Extra info about reg */
struct st_join_table *join_tab; /* Used by SELECT() */
enum thr_lock_type lock_type; /* How database is used */
bool not_exists_optimize;
/*
TRUE <=> range optimizer found that there is no rows satisfying
table conditions.
*/
bool impossible_range;
} REGINFO;
......
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