Skip to content

Commit 05b3425

Browse files
author
Evgeny Potemkin
committed
BUG#39447: Error with NOT NULL condition and LIMIT 1
- in test_if_skip_sort_order(): if we first decided to use one index and use index condition pushdown but then re-considered and picked another index, undo the index condition pushdown properly. Original revid:sergefp@mysql.com-20081229034230-tdlibl8bgepjx7o8
1 parent 2acd12b commit 05b3425

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

mysql-test/r/innodb_mrr.result

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,32 @@ pk
351351
1
352352
5
353353
drop table t1;
354+
#
355+
# BUG#39447: Error with NOT NULL condition and LIMIT 1
356+
#
357+
CREATE TABLE t1 (
358+
id int(11) NOT NULL,
359+
parent_id int(11) DEFAULT NULL,
360+
name varchar(10) DEFAULT NULL,
361+
PRIMARY KEY (id),
362+
KEY ind_parent_id (parent_id)
363+
) ENGINE=InnoDB;
364+
insert into t1 (id, parent_id, name) values
365+
(10,NULL,'A'),
366+
(20,10,'B'),
367+
(30,10,'C'),
368+
(40,NULL,'D'),
369+
(50,40,'E'),
370+
(60,40,'F'),
371+
(70,NULL,'J');
372+
SELECT id FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
373+
id
374+
60
375+
This must show type=index, extra=Using where
376+
explain SELECT * FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
377+
id select_type table type possible_keys key key_len ref rows Extra
378+
1 SIMPLE t1 index ind_parent_id PRIMARY 4 NULL 2 Using where
379+
SELECT * FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
380+
id parent_id name
381+
60 40 F
382+
drop table t1;

mysql-test/t/innodb_mrr.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,28 @@ select pk from t1 WHERE `varchar_key` > 'kr' group by pk;
9999
select pk from t1 WHERE `int_nokey` IS NULL OR `varchar_key` > 'kr' group by pk;
100100
drop table t1;
101101

102+
--echo #
103+
--echo # BUG#39447: Error with NOT NULL condition and LIMIT 1
104+
--echo #
105+
CREATE TABLE t1 (
106+
id int(11) NOT NULL,
107+
parent_id int(11) DEFAULT NULL,
108+
name varchar(10) DEFAULT NULL,
109+
PRIMARY KEY (id),
110+
KEY ind_parent_id (parent_id)
111+
) ENGINE=InnoDB;
112+
113+
insert into t1 (id, parent_id, name) values
114+
(10,NULL,'A'),
115+
(20,10,'B'),
116+
(30,10,'C'),
117+
(40,NULL,'D'),
118+
(50,40,'E'),
119+
(60,40,'F'),
120+
(70,NULL,'J');
121+
122+
SELECT id FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
123+
--echo This must show type=index, extra=Using where
124+
explain SELECT * FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
125+
SELECT * FROM t1 WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1;
126+
drop table t1;

sql/sql_select.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18900,7 +18900,11 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
1890018900
if (table->covering_keys.is_set(best_key))
1890118901
table->set_keyread(TRUE);
1890218902
if (tab->pre_idx_push_select_cond)
18903+
{
1890318904
tab->select_cond= tab->pre_idx_push_select_cond;
18905+
if (tab->select)
18906+
tab->select->cond= tab->select_cond;
18907+
}
1890418908
table->file->ha_index_or_rnd_end();
1890518909
if (join->select_options & SELECT_DESCRIBE)
1890618910
{

0 commit comments

Comments
 (0)