Commit 1cbf8f74 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed cached constsnt determination (bug #142 related)

parent fd88f185
...@@ -1049,3 +1049,26 @@ select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1 ...@@ -1049,3 +1049,26 @@ select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1
Continent Name Population Continent Name Population
Oceania Sydney 3276207 Oceania Sydney 3276207
drop table t1, t2; drop table t1, t2;
CREATE TABLE `t1` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) character set latin1 NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `pseudo` (`pseudo`),
) TYPE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
INSERT INTO t1 (pseudo) VALUES ('test');
SELECT 0 IN (SELECT 1 FROM t1 a);
0 IN (SELECT 1 FROM t1 a)
0
EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2 DEPENDENT SUBSELECT NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
INSERT INTO t1 (pseudo) VALUES ('test1');
SELECT 0 IN (SELECT 1 FROM t1 a);
0 IN (SELECT 1 FROM t1 a)
0
EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2 DEPENDENT SUBSELECT NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
drop table t1;
...@@ -644,3 +644,20 @@ INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,773 ...@@ -644,3 +644,20 @@ INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,773
select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent);
drop table t1, t2; drop table t1, t2;
#
# constants in IN
#
CREATE TABLE `t1` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) character set latin1 NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `pseudo` (`pseudo`),
) TYPE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
INSERT INTO t1 (pseudo) VALUES ('test');
SELECT 0 IN (SELECT 1 FROM t1 a);
EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a);
INSERT INTO t1 (pseudo) VALUES ('test1');
SELECT 0 IN (SELECT 1 FROM t1 a);
EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a);
drop table t1;
...@@ -298,12 +298,22 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, ...@@ -298,12 +298,22 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
return 1; return 1;
cache->setup(args[0]); cache->setup(args[0]);
if (cache->cols() == 1) if (cache->cols() == 1)
{
if (args[0]->used_tables())
cache->set_used_tables(RAND_TABLE_BIT); cache->set_used_tables(RAND_TABLE_BIT);
else
cache->set_used_tables(0);
}
else else
{ {
uint n= cache->cols(); uint n= cache->cols();
for (uint i= 0; i < n; i++) for (uint i= 0; i < n; i++)
{
if (args[0]->el(i)->used_tables())
((Item_cache *)cache->el(i))->set_used_tables(RAND_TABLE_BIT); ((Item_cache *)cache->el(i))->set_used_tables(RAND_TABLE_BIT);
else
((Item_cache *)cache->el(i))->set_used_tables(0);
}
} }
if (args[1]->fix_fields(thd, tables, args)) if (args[1]->fix_fields(thd, tables, args))
return 1; return 1;
......
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