mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Fixed wrong key usage which caused wrong result for some "WHERE primary_key=constant" queries where MySQL could use 'only index' (Bug #3666)
The bug was introduced in a patch in the 4.1.2 source tree. mysql-test/r/key.result: New result mysql-test/t/key.test: Added test case for bug in key read sql/sql_select.cc: Fixed wrong key usage which caused wrong result for some "WHERE primary_key=constant" queries where MySQL could use 'only index' (Bug #3666)
This commit is contained in:
@@ -222,3 +222,16 @@ explain select 1 from t1 where id =2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref id id 4 const 1 Using where; Using index
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (numeropost mediumint(8) unsigned NOT NULL default '0', numreponse int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse));
|
||||
INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');
|
||||
SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
numeropost
|
||||
1
|
||||
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index
|
||||
FLUSH TABLES;
|
||||
SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
numeropost
|
||||
1
|
||||
drop table t1;
|
||||
|
||||
@@ -216,3 +216,15 @@ explain select name from t1 where id =2;
|
||||
ALTER TABLE t1 DROP PRIMARY KEY, ADD INDEX (id);
|
||||
explain select 1 from t1 where id =2;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test of problem with key read (Bug #3666)
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (numeropost mediumint(8) unsigned NOT NULL default '0', numreponse int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse));
|
||||
INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');
|
||||
SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
FLUSH TABLES;
|
||||
SELECT numeropost FROM t1 WHERE numreponse='1';
|
||||
drop table t1;
|
||||
|
||||
@@ -3638,7 +3638,7 @@ make_join_readinfo(JOIN *join, uint options)
|
||||
table->status=STATUS_NO_RECORD;
|
||||
tab->read_first_record= join_read_const;
|
||||
tab->read_record.read_record= join_no_more_records;
|
||||
if (table->used_keys.is_set(tab->index) &&
|
||||
if (table->used_keys.is_set(tab->ref.key) &&
|
||||
!table->no_keyread)
|
||||
{
|
||||
table->key_read=1;
|
||||
@@ -5967,7 +5967,7 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!table->key_read && table->used_keys.is_set(tab->index) &&
|
||||
if (!table->key_read && table->used_keys.is_set(tab->ref.key) &&
|
||||
!table->no_keyread)
|
||||
{
|
||||
table->key_read=1;
|
||||
|
||||
Reference in New Issue
Block a user