summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2004-09-02 22:06:30 -0700
committerunknown <igor@rurik.mysql.com>2004-09-02 22:06:30 -0700
commitafac3c31278d491e8e1329129b38df4ab2e9371e (patch)
tree0a2fb6ed09ccf0be9c7f6da755d585bdd8c916eb
parentc1fd20bb5ed75b4d6df24703e0b26a488eac4a3b (diff)
downloadmariadb-git-afac3c31278d491e8e1329129b38df4ab2e9371e.tar.gz
select.result, select.test:
Added a test case for bug #5333. null_key.result, key_primary.result: Made covering index usable for const tables. sql_select.cc: Made covering index usable for const tables: downported the corresponding code from 4.1. Simultaneously fixed bug #5333 reported for 4.1. The bug was due to the fact that field index in join structures was always set to 0 for const tables. sql/sql_select.cc: Made covering index usable for const tables: downported the corresponding code from 4.1. Simultaneously fixed bug #5333 reported for 4.1. The bug was due to the fact that field index in join structures was always set to 0 for const tables. mysql-test/t/select.test: Added a test case for bug #5333. mysql-test/r/key_primary.result: Made covering index usable for const tables. mysql-test/r/null_key.result: Made covering index usable for const tables. mysql-test/r/select.result: Added a test case for bug #5333.
-rw-r--r--mysql-test/r/key_primary.result2
-rw-r--r--mysql-test/r/null_key.result2
-rw-r--r--mysql-test/r/select.result16
-rw-r--r--mysql-test/t/select.test21
-rw-r--r--sql/sql_select.cc11
5 files changed, 49 insertions, 3 deletions
diff --git a/mysql-test/r/key_primary.result b/mysql-test/r/key_primary.result
index 87289f1cf54..3216ead667b 100644
--- a/mysql-test/r/key_primary.result
+++ b/mysql-test/r/key_primary.result
@@ -13,7 +13,7 @@ t1
AB%
describe select * from t1 where t1="ABC";
table type possible_keys key key_len ref rows Extra
-t1 const PRIMARY PRIMARY 3 const 1
+t1 const PRIMARY PRIMARY 3 const 1 Using index
describe select * from t1 where t1="ABCD";
Comment
Impossible WHERE noticed after reading const tables
diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result
index 009a3e06eb2..41b0ae26617 100644
--- a/mysql-test/r/null_key.result
+++ b/mysql-test/r/null_key.result
@@ -12,7 +12,7 @@ table type possible_keys key key_len ref rows Extra
t1 ref a,b a 9 const,const 1 Using where; Using index
explain select * from t1 where a=2 and b = 2;
table type possible_keys key key_len ref rows Extra
-t1 const a,b a 9 const,const 1
+t1 const a,b a 9 const,const 1 Using index
explain select * from t1 where a<=>b limit 2;
table type possible_keys key key_len ref rows Extra
t1 index NULL a 9 NULL 12 Using where; Using index
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 206fa507615..ce5ea94a08e 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2327,3 +2327,19 @@ select * from t2,t3 where t2.s = t3.s;
s s
two two
drop table t1, t2, t3;
+CREATE TABLE t1 (
+i int(11) NOT NULL default '0',
+c char(10) NOT NULL default '',
+PRIMARY KEY (i),
+UNIQUE KEY c (c)
+) TYPE=MyISAM;
+INSERT INTO t1 VALUES (1,'a');
+INSERT INTO t1 VALUES (2,'b');
+INSERT INTO t1 VALUES (3,'c');
+EXPLAIN SELECT i FROM t1 WHERE i=1;
+table type possible_keys key key_len ref rows Extra
+t1 const PRIMARY PRIMARY 4 const 1 Using index
+EXPLAIN SELECT i FROM t1 WHERE i=1;
+table type possible_keys key key_len ref rows Extra
+t1 const PRIMARY PRIMARY 4 const 1 Using index
+DROP TABLE t1;
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 7cb157f194e..dae44159683 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -1874,3 +1874,24 @@ select * from t3 where s = 'one';
select * from t1,t2 where t1.s = t2.s;
select * from t2,t3 where t2.s = t3.s;
drop table t1, t2, t3;
+
+#
+# Covering index is mentioned in EXPLAIN output for const tables (bug #5333)
+#
+
+CREATE TABLE t1 (
+ i int(11) NOT NULL default '0',
+ c char(10) NOT NULL default '',
+ PRIMARY KEY (i),
+ UNIQUE KEY c (c)
+) TYPE=MyISAM;
+
+INSERT INTO t1 VALUES (1,'a');
+INSERT INTO t1 VALUES (2,'b');
+INSERT INTO t1 VALUES (3,'c');
+
+EXPLAIN SELECT i FROM t1 WHERE i=1;
+
+EXPLAIN SELECT i FROM t1 WHERE i=1;
+
+DROP TABLE t1; \ No newline at end of file
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 882f345a1ca..d2b9f9d4588 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4901,6 +4901,15 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos)
}
else
{
+ if (!table->key_read &&
+ (table->used_keys & ((key_map) 1 << tab->ref.key)) &&
+ !table->no_keyread &&
+ (int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY)
+ {
+ table->key_read=1;
+ table->file->extra(HA_EXTRA_KEYREAD);
+ tab->index= tab->ref.key;
+ }
if ((error=join_read_const(tab)))
{
tab->info="unique row not found";
@@ -7617,7 +7626,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
sprintf(buff3,"%.0f",join->best_positions[i].records_read);
item_list.push_back(new Item_string(buff3,strlen(buff3)));
my_bool key_read=table->key_read;
- if (tab->type == JT_NEXT &&
+ if ((tab->type == JT_NEXT || tab->type == JT_CONST) &&
((table->used_keys & ((key_map) 1 << tab->index))))
key_read=1;