Fix for luanchpad bug#609043
Removed indirect reference in equalities for cache index lookup. We should use a direct reference because some optimization of the query may optimize out a condition predicate and if the outer reference is the only element of the condition predicate the indirect reference becomes NULL. We can resolve correctly the indirect reference in Expression_cache_tmptable::make_equalities because it is called before optimization of the cached subquery. mysql-test/r/subquery_cache.result: The test suite for the bug added. mysql-test/t/subquery_cache.test: The test suite for the bug added. sql/sql_expression_cache.cc: Removed indirect reference in equalities for cache index lookup.
This commit is contained in:
parent
76e2be8e81
commit
02c040dd5c
@ -2881,3 +2881,107 @@ HAVING field10 = 'c'
|
||||
field1 field2 field3 field4 field5 field6 field7 field8 field9 field10
|
||||
drop table t1,t2,t3,t4,t5;
|
||||
set @@optimizer_switch= default;
|
||||
#launchpad BUG#609043
|
||||
CREATE TABLE `t1` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `t1` VALUES (19,NULL,6,'2004-08-20','2004-08-20','05:03:03','05:03:03','2007-04-19 00:19:53','2007-04-19 00:19:53','f','f');
|
||||
INSERT INTO `t1` VALUES (20,4,2,'1900-01-01','1900-01-01','18:38:59','18:38:59','1900-01-01 00:00:00','1900-01-01 00:00:00','d','d');
|
||||
CREATE TABLE `t2` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `t3` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `t4` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=101 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `t4` VALUES (100,2,5,'2001-07-26','2001-07-26','11:49:25','11:49:25','2007-04-25 05:08:49','2007-04-25 05:08:49','f','f');
|
||||
SET @@optimizer_switch = 'subquery_cache=off';
|
||||
/* cache is off */ SELECT COUNT( DISTINCT table2 .`col_int_key` ) , (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) , table2 .`col_varchar_nokey` field10
|
||||
FROM t4 table1 JOIN ( t1 table2 STRAIGHT_JOIN t1 table3 ON table2 .`pk` ) ON table3 .`col_varchar_key` = table2 .`col_varchar_key`
|
||||
GROUP BY field10 ;
|
||||
COUNT( DISTINCT table2 .`col_int_key` ) (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) field10
|
||||
1 NULL d
|
||||
1 NULL f
|
||||
SET @@optimizer_switch = 'subquery_cache=on';
|
||||
/* cache is on */ SELECT COUNT( DISTINCT table2 .`col_int_key` ) , (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) , table2 .`col_varchar_nokey` field10
|
||||
FROM t4 table1 JOIN ( t1 table2 STRAIGHT_JOIN t1 table3 ON table2 .`pk` ) ON table3 .`col_varchar_key` = table2 .`col_varchar_key`
|
||||
GROUP BY field10 ;
|
||||
COUNT( DISTINCT table2 .`col_int_key` ) (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) field10
|
||||
1 NULL d
|
||||
1 NULL f
|
||||
drop table t1,t2,t3,t4;
|
||||
set @@optimizer_switch= default;
|
||||
|
@ -1202,3 +1202,107 @@ HAVING field10 = 'c'
|
||||
|
||||
drop table t1,t2,t3,t4,t5;
|
||||
set @@optimizer_switch= default;
|
||||
|
||||
|
||||
#
|
||||
--echo #launchpad BUG#609043
|
||||
#
|
||||
CREATE TABLE `t1` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `t1` VALUES (19,NULL,6,'2004-08-20','2004-08-20','05:03:03','05:03:03','2007-04-19 00:19:53','2007-04-19 00:19:53','f','f');
|
||||
INSERT INTO `t1` VALUES (20,4,2,'1900-01-01','1900-01-01','18:38:59','18:38:59','1900-01-01 00:00:00','1900-01-01 00:00:00','d','d');
|
||||
|
||||
CREATE TABLE `t2` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE `t3` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE `t4` (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`col_int_nokey` int(11) DEFAULT NULL,
|
||||
`col_int_key` int(11) DEFAULT NULL,
|
||||
`col_date_key` date DEFAULT NULL,
|
||||
`col_date_nokey` date DEFAULT NULL,
|
||||
`col_time_key` time DEFAULT NULL,
|
||||
`col_time_nokey` time DEFAULT NULL,
|
||||
`col_datetime_key` datetime DEFAULT NULL,
|
||||
`col_datetime_nokey` datetime DEFAULT NULL,
|
||||
`col_varchar_key` varchar(1) DEFAULT NULL,
|
||||
`col_varchar_nokey` varchar(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `col_int_key` (`col_int_key`),
|
||||
KEY `col_date_key` (`col_date_key`),
|
||||
KEY `col_time_key` (`col_time_key`),
|
||||
KEY `col_datetime_key` (`col_datetime_key`),
|
||||
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=101 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `t4` VALUES (100,2,5,'2001-07-26','2001-07-26','11:49:25','11:49:25','2007-04-25 05:08:49','2007-04-25 05:08:49','f','f');
|
||||
|
||||
SET @@optimizer_switch = 'subquery_cache=off';
|
||||
|
||||
/* cache is off */ SELECT COUNT( DISTINCT table2 .`col_int_key` ) , (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) , table2 .`col_varchar_nokey` field10
|
||||
FROM t4 table1 JOIN ( t1 table2 STRAIGHT_JOIN t1 table3 ON table2 .`pk` ) ON table3 .`col_varchar_key` = table2 .`col_varchar_key`
|
||||
GROUP BY field10 ;
|
||||
|
||||
SET @@optimizer_switch = 'subquery_cache=on';
|
||||
|
||||
/* cache is on */ SELECT COUNT( DISTINCT table2 .`col_int_key` ) , (
|
||||
SELECT SUBQUERY2_t1 .`col_int_key`
|
||||
FROM t3 SUBQUERY2_t1 JOIN t2 ON SUBQUERY2_t1 .`col_int_key`
|
||||
WHERE table1 .`col_varchar_key` ) , table2 .`col_varchar_nokey` field10
|
||||
FROM t4 table1 JOIN ( t1 table2 STRAIGHT_JOIN t1 table3 ON table2 .`pk` ) ON table3 .`col_varchar_key` = table2 .`col_varchar_key`
|
||||
GROUP BY field10 ;
|
||||
|
||||
drop table t1,t2,t3,t4;
|
||||
set @@optimizer_switch= default;
|
||||
|
@ -41,7 +41,6 @@ bool Expression_cache_tmptable::make_equalities()
|
||||
List<Item> args;
|
||||
List_iterator_fast<Item*> li(*list);
|
||||
Item **ref;
|
||||
Name_resolution_context *cn= NULL;
|
||||
DBUG_ENTER("Expression_cache_tmptable::make_equalities");
|
||||
|
||||
for (uint i= 1 /* skip result filed */; (ref= li++); i++)
|
||||
@ -58,14 +57,7 @@ bool Expression_cache_tmptable::make_equalities()
|
||||
fld->type() == MYSQL_TYPE_NEWDECIMAL ||
|
||||
fld->type() == MYSQL_TYPE_DECIMAL)
|
||||
{
|
||||
if (!cn)
|
||||
{
|
||||
// dummy resolution context
|
||||
cn= new Name_resolution_context();
|
||||
cn->init();
|
||||
}
|
||||
args.push_front(new Item_func_eq(new Item_ref(cn, ref, "", "", FALSE),
|
||||
new Item_field(fld)));
|
||||
args.push_front(new Item_func_eq(*ref, new Item_field(fld)));
|
||||
}
|
||||
}
|
||||
if (args.elements == 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user