Commit f4830634 authored by Sergey Glukhov's avatar Sergey Glukhov

Bug#50389 Using intersect does not return all rows

In process of record search it is not taken into account
that inital quick->file->ref value could be inapplicable
to range interval. After proper row is found this value is
stored into the record buffer and later the record is
filtered out at condition evaluation stage.
The fix is store a refernce of found row to the handler ref field.
parent 936a2b11
...@@ -2417,4 +2417,42 @@ ENGINE=InnoDB; ...@@ -2417,4 +2417,42 @@ ENGINE=InnoDB;
INSERT INTO t1 VALUES (0, 77, 1, 3); INSERT INTO t1 VALUES (0, 77, 1, 3);
UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25; UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25;
DROP TABLE t1; DROP TABLE t1;
#
# Bug#50389 Using intersect does not return all rows
#
CREATE TABLE t1 (
f1 INT(10) NOT NULL,
f2 INT(10),
f3 INT(10),
f4 TINYINT(4),
f5 VARCHAR(50),
PRIMARY KEY (f1),
KEY idx1 (f2,f5,f4),
KEY idx2 (f2,f4)
) ENGINE=InnoDB;
LOAD DATA INFILE '../../std_data/intersect-bug50389.tsv' INTO TABLE t1;
SELECT * FROM t1 WHERE f1 IN
(3305028,3353871,3772880,3346860,4228206,3336022,
3470988,3305175,3329875,3817277,3856380,3796193,
3784744,4180925,4559596,3963734,3856391,4494153)
AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
f1 f2 f3 f4 f5
3305175 1221457 0 0 abcdefghijklmnopwrst
3329875 1221457 1382427 0 abcdefghijklmnopwrst
3336022 1221457 0 0 abcdefghijklmnopwrst
3346860 1221457 0 0 abcdefghijklmnopwrst
3772880 1221457 0 0 abcdefghijklmnopwrst
3784744 1221457 1382427 0 abcdefghijklmnopwrst
3796193 1221457 0 0 abcdefghijklmnopwrst
4228206 1221457 0 0 abcdefghijklmnopwrst
4494153 1221457 0 0 abcdefghijklmnopwrst
4559596 1221457 0 0 abcdefghijklmnopwrst
EXPLAIN SELECT * FROM t1 WHERE f1 IN
(3305028,3353871,3772880,3346860,4228206,3336022,
3470988,3305175,3329875,3817277,3856380,3796193,
3784744,4180925,4559596,3963734,3856391,4494153)
AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge PRIMARY,idx1,idx2 idx2,idx1,PRIMARY 7,60,4 NULL 1 Using intersect(idx2,idx1,PRIMARY); Using where
DROP TABLE t1;
End of 5.1 tests End of 5.1 tests
This diff is collapsed.
...@@ -663,4 +663,35 @@ UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25; ...@@ -663,4 +663,35 @@ UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Bug#50389 Using intersect does not return all rows
--echo #
CREATE TABLE t1 (
f1 INT(10) NOT NULL,
f2 INT(10),
f3 INT(10),
f4 TINYINT(4),
f5 VARCHAR(50),
PRIMARY KEY (f1),
KEY idx1 (f2,f5,f4),
KEY idx2 (f2,f4)
) ENGINE=InnoDB;
LOAD DATA INFILE '../../std_data/intersect-bug50389.tsv' INTO TABLE t1;
SELECT * FROM t1 WHERE f1 IN
(3305028,3353871,3772880,3346860,4228206,3336022,
3470988,3305175,3329875,3817277,3856380,3796193,
3784744,4180925,4559596,3963734,3856391,4494153)
AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
EXPLAIN SELECT * FROM t1 WHERE f1 IN
(3305028,3353871,3772880,3346860,4228206,3336022,
3470988,3305175,3329875,3817277,3856380,3796193,
3784744,4180925,4559596,3963734,3856391,4494153)
AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
DROP TABLE t1;
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -8349,6 +8349,7 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() ...@@ -8349,6 +8349,7 @@ int QUICK_ROR_INTERSECT_SELECT::get_next()
if ((error= quick->get_next())) if ((error= quick->get_next()))
DBUG_RETURN(error); DBUG_RETURN(error);
} }
quick->file->position(quick->record);
} }
memcpy(last_rowid, quick->file->ref, head->file->ref_length); memcpy(last_rowid, quick->file->ref, head->file->ref_length);
last_rowid_count= 1; last_rowid_count= 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