mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-536: LP:1050806 - different result for a query using subquery, and
MDEV-567: Wrong result from a query with correlated subquery if ICP is allowed: backport the fix developed for SHOW EXPLAIN: revision-id: psergey@askmonty.org-20120719115219-212cxmm6qvf0wlrb branch nick: 5.5-show-explain-r21 timestamp: Thu 2012-07-19 15:52:19 +0400 BUG#992942 & MDEV-325: Pre-liminary commit for testing and adjust it so that it handles DS-MRR scans correctly.
This commit is contained in:
@@ -180,6 +180,32 @@ SET optimizer_switch=@tmp_optimizer_switch;
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1,t2,t3;
|
||||
#
|
||||
# MDEV-536: LP:1050806 - different result for a query using subquery
|
||||
#
|
||||
DROP TABLE IF EXISTS `t1`;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 't1'
|
||||
CREATE TABLE `t1` (
|
||||
`node_uid` bigint(20) unsigned DEFAULT NULL,
|
||||
`date` datetime DEFAULT NULL,
|
||||
`mirror_date` datetime DEFAULT NULL,
|
||||
KEY `date` (`date`)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
node_uid date mirror_date result
|
||||
2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0
|
||||
2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-567: Wrong result from a query with correlated subquery if ICP is allowed
|
||||
#
|
||||
CREATE TABLE t1 (a int, b int, INDEX idx(a));
|
||||
@@ -197,5 +223,76 @@ a b
|
||||
1 0
|
||||
1 1
|
||||
1 3
|
||||
DROP TABLE t1, t2, t3;
|
||||
set @tmp_mdev567=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=off';
|
||||
SELECT * FROM t3
|
||||
WHERE a = (SELECT COUNT(DISTINCT t2.b) FROM t1, t2
|
||||
WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9
|
||||
AND t3.b = t1.b
|
||||
GROUP BY t1.b);
|
||||
a b
|
||||
1 0
|
||||
1 1
|
||||
1 3
|
||||
DROP TABLE t1,t2,t3;
|
||||
set optimizer_switch=@tmp_mdev567;
|
||||
#
|
||||
# MDEV-614, also MDEV-536, also LP:1050806:
|
||||
# different result for a query using subquery between 5.5.25 and 5.5.27
|
||||
#
|
||||
CREATE TABLE `t1` (
|
||||
`node_uid` bigint(20) unsigned DEFAULT NULL,
|
||||
`date` datetime DEFAULT NULL,
|
||||
`mirror_date` datetime DEFAULT NULL,
|
||||
KEY `date` (`date`)
|
||||
) ENGINE=MyISAM;
|
||||
INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
|
||||
explain
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2
|
||||
2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
node_uid date mirror_date result
|
||||
2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0
|
||||
2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0
|
||||
set @tmp_mdev614=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=off';
|
||||
explain
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2
|
||||
2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Using filesort
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
node_uid date mirror_date result
|
||||
2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0
|
||||
2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0
|
||||
set optimizer_switch=@tmp_mdev614;
|
||||
DROP TABLE t1;
|
||||
set optimizer_switch=@subselect2_test_tmp;
|
||||
|
@@ -203,6 +203,32 @@ SET optimizer_switch=@tmp_optimizer_switch;
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1,t2,t3;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-536: LP:1050806 - different result for a query using subquery
|
||||
--echo #
|
||||
DROP TABLE IF EXISTS `t1`;
|
||||
|
||||
CREATE TABLE `t1` (
|
||||
`node_uid` bigint(20) unsigned DEFAULT NULL,
|
||||
`date` datetime DEFAULT NULL,
|
||||
`mirror_date` datetime DEFAULT NULL,
|
||||
KEY `date` (`date`)
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
|
||||
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-567: Wrong result from a query with correlated subquery if ICP is allowed
|
||||
--echo #
|
||||
@@ -220,7 +246,75 @@ SELECT * FROM t3
|
||||
WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9
|
||||
AND t3.b = t1.b
|
||||
GROUP BY t1.b);
|
||||
DROP TABLE t1, t2, t3;
|
||||
|
||||
|
||||
set @tmp_mdev567=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=off';
|
||||
SELECT * FROM t3
|
||||
WHERE a = (SELECT COUNT(DISTINCT t2.b) FROM t1, t2
|
||||
WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9
|
||||
AND t3.b = t1.b
|
||||
GROUP BY t1.b);
|
||||
|
||||
DROP TABLE t1,t2,t3;
|
||||
set optimizer_switch=@tmp_mdev567;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-614, also MDEV-536, also LP:1050806:
|
||||
--echo # different result for a query using subquery between 5.5.25 and 5.5.27
|
||||
--echo #
|
||||
|
||||
CREATE TABLE `t1` (
|
||||
`node_uid` bigint(20) unsigned DEFAULT NULL,
|
||||
`date` datetime DEFAULT NULL,
|
||||
`mirror_date` datetime DEFAULT NULL,
|
||||
KEY `date` (`date`)
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
|
||||
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
|
||||
|
||||
explain
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
|
||||
set @tmp_mdev614=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=off';
|
||||
explain
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
|
||||
SELECT * FROM (
|
||||
SELECT node_uid, date, mirror_date, @result := 0 AS result
|
||||
FROM t1
|
||||
WHERE date < '2012-12-12 12:12:12'
|
||||
AND node_uid in (2085, 2084)
|
||||
ORDER BY mirror_date ASC
|
||||
) AS calculated_result;
|
||||
|
||||
set optimizer_switch=@tmp_mdev614;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
|
||||
set optimizer_switch=@subselect2_test_tmp;
|
||||
|
||||
|
Reference in New Issue
Block a user