Commit 45898445 authored by unknown's avatar unknown

merge::records_in_range and optimizer


sql/sql_select.cc:
  optimizer bug fixed. (what's the difference between s->records ans s->found_records ?)
parent 564c7b24
...@@ -35,10 +35,10 @@ insert into t1 select NULL,message from t2; ...@@ -35,10 +35,10 @@ insert into t1 select NULL,message from t2;
create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(test.t1,test.t2); create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(test.t1,test.t2);
explain select * from t3 where a < 10; explain select * from t3 where a < 10;
table type possible_keys key key_len ref rows Extra table type possible_keys key key_len ref rows Extra
t3 range a a 4 NULL 10 Using where t3 range a a 4 NULL 18 Using where
explain select * from t3 where a > 10 and a < 20; explain select * from t3 where a > 10 and a < 20;
table type possible_keys key key_len ref rows Extra table type possible_keys key key_len ref rows Extra
t3 range a a 4 NULL 10 Using where t3 range a a 4 NULL 16 Using where
select * from t3 where a = 10; select * from t3 where a = 10;
a b a b
10 Testing 10 Testing
...@@ -561,3 +561,38 @@ a ...@@ -561,3 +561,38 @@ a
1 1
2 2
drop table if exists t1, t2, t3, t4, t5, t6; drop table if exists t1, t2, t3, t4, t5, t6;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (
fileset_id tinyint(3) unsigned NOT NULL default '0',
file_code varchar(32) NOT NULL default '',
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (fileset_id,file_code),
KEY files (fileset_id,fileset_root_id)
) TYPE=MyISAM;
INSERT INTO t1 VALUES (2, '0000000111', 1), (2, '0000000112', 1), (2, '0000000113', 1),
(2, '0000000114', 1), (2, '0000000115', 1), (2, '0000000116', 1), (2, '0000000117', 1),
(2, '0000000118', 1), (2, '0000000119', 1), (2, '0000000120', 1);
CREATE TABLE t2 (
fileset_id tinyint(3) unsigned NOT NULL default '0',
file_code varchar(32) NOT NULL default '',
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (fileset_id,file_code),
KEY files (fileset_id,fileset_root_id)
) TYPE=MRG_MyISAM UNION=(t1);
EXPLAIN SELECT * FROM t2 IGNORE INDEX (files) WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
table type possible_keys key key_len ref rows Extra
t2 range PRIMARY PRIMARY 33 NULL 5 Using where
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
table type possible_keys key key_len ref rows Extra
t2 range PRIMARY,files PRIMARY 33 NULL 5 Using where
EXPLAIN SELECT * FROM t1 WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
table type possible_keys key key_len ref rows Extra
t1 range PRIMARY,files PRIMARY 33 NULL 5 Using where
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1;
table type possible_keys key key_len ref rows Extra
t2 const PRIMARY,files PRIMARY 33 const,const 1
DROP TABLE IF EXISTS t1, t2;
...@@ -204,3 +204,36 @@ create temporary table t6 (a int not null) TYPE=MERGE UNION=(t4,t5); ...@@ -204,3 +204,36 @@ create temporary table t6 (a int not null) TYPE=MERGE UNION=(t4,t5);
select * from t6; select * from t6;
drop table if exists t1, t2, t3, t4, t5, t6; drop table if exists t1, t2, t3, t4, t5, t6;
#
# testing merge::records_in_range and optimizer
#
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (
fileset_id tinyint(3) unsigned NOT NULL default '0',
file_code varchar(32) NOT NULL default '',
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (fileset_id,file_code),
KEY files (fileset_id,fileset_root_id)
) TYPE=MyISAM;
INSERT INTO t1 VALUES (2, '0000000111', 1), (2, '0000000112', 1), (2, '0000000113', 1),
(2, '0000000114', 1), (2, '0000000115', 1), (2, '0000000116', 1), (2, '0000000117', 1),
(2, '0000000118', 1), (2, '0000000119', 1), (2, '0000000120', 1);
CREATE TABLE t2 (
fileset_id tinyint(3) unsigned NOT NULL default '0',
file_code varchar(32) NOT NULL default '',
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (fileset_id,file_code),
KEY files (fileset_id,fileset_root_id)
) TYPE=MRG_MyISAM UNION=(t1);
EXPLAIN SELECT * FROM t2 IGNORE INDEX (files) WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
EXPLAIN SELECT * FROM t1 WHERE fileset_id = 2
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1;
DROP TABLE IF EXISTS t1, t2;
...@@ -1219,7 +1219,7 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds, ...@@ -1219,7 +1219,7 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
select->quick=0; select->quick=0;
if (records != HA_POS_ERROR) if (records != HA_POS_ERROR)
{ {
s->found_records=records; s->records=s->found_records=records;
s->read_time= (ha_rows) (s->quick ? s->quick->read_time : 0.0); s->read_time= (ha_rows) (s->quick ? s->quick->read_time : 0.0);
} }
} }
...@@ -1944,7 +1944,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, ...@@ -1944,7 +1944,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
records records
This gives the formula: This gives the formula:
records= (x * (b-a) + a*c-b)/(c-1) records= (x * (b-a) + a*c-b)/(c-1)
b = records matched by whole key b = records matched by whole key
a = records matched by first key part (10% of all records?) a = records matched by first key part (10% of all records?)
c = number of key parts in key c = number of key parts in key
......
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