mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Fix for MDEV-3948, and backport of the following collection of fixes and backports
from MariaDB 10.0. The bug in mdev-3948 was an instance of the problem fixed by Sergey's patch in 10.0 - namely that the range optimizer could change table->[read | write]_set, and not restore it. revno: 3471 committer: Sergey Petrunya <psergey@askmonty.org> branch nick: 10.0-serg-fix-imerge timestamp: Sat 2012-11-03 12:24:36 +0400 message: # MDEV-3817: Wrong result with index_merge+index_merge_intersection, InnoDB table, join, AND and OR conditions Reconcile the fixes from: # # guilhem.bichot@oracle.com-20110805143029-ywrzuz15uzgontr0 # Fix for BUG#12698916 - "JOIN QUERY GIVES WRONG RESULT AT 2ND EXEC. OR # AFTER FLUSH TABLES [-INT VS NULL]" # # guilhem.bichot@oracle.com-20111209150650-tzx3ldzxe1yfwji6 # Fix for BUG#12912171 - ASSERTION FAILED: QUICK->HEAD->READ_SET == SAVE_READ_SET # and # and related fixes from: BUG#1006164, MDEV-376: Now, ROR-merged QUICK_RANGE_SELECT objects make no assumptions about the values of table->read_set and table->write_set. Each QUICK_ROR_SELECT has (and had before) its own column bitmap, but now, all QUICK_ROR_SELECT's functions that care: reset(), init_ror_merged_scan(), and get_next() will set table->read_set when invoked and restore it back to what it was before the call before they return. This allows to avoid the mess when somebody else modifies table->read_set for some reason.
This commit is contained in:
@ -149,3 +149,25 @@ set @@join_cache_level= @save_join_cache_level;
|
||||
set storage_engine=@save_storage_engine;
|
||||
set optimizer_switch=@innodb_mrr_cpk_tmp;
|
||||
drop table t0;
|
||||
#
|
||||
# MDEV-3817: Wrong result with index_merge+index_merge_intersection, InnoDB table, join, AND and OR conditions
|
||||
#
|
||||
set @tmp_mdev3817=@@optimizer_switch;
|
||||
SET optimizer_switch='index_merge=on,index_merge_intersection=on';
|
||||
CREATE TABLE t1 (
|
||||
a INT PRIMARY KEY,
|
||||
b INT,
|
||||
c VARCHAR(1024) CHARACTER SET utf8,
|
||||
d INT,
|
||||
KEY (b)
|
||||
) ENGINE=InnoDB;
|
||||
INSERT INTO t1 VALUES
|
||||
(1, 9, 'one', 11), (2, 6, 'two', 12), (3, 2, 'three', 13), (4, 5, 'four', 14);
|
||||
CREATE TABLE t2 (e INT, g INT) ENGINE=InnoDB;
|
||||
INSERT INTO t2 VALUES (1,9), (2,6) ;
|
||||
SELECT * FROM t1, t2 WHERE g = b AND ( a < 7 OR a > e );
|
||||
a b c d e g
|
||||
1 9 one 11 1 9
|
||||
2 6 two 12 2 6
|
||||
DROP TABLE t1, t2;
|
||||
set optimizer_switch=@tmp_mdev3817;
|
||||
|
@ -574,4 +574,24 @@ a b
|
||||
1 2
|
||||
0 1
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# BUG#12912171 - ASSERTION FAILED: QUICK->HEAD->READ_SET ==
|
||||
# SAVE_READ_SET
|
||||
#
|
||||
CREATE TABLE t1 (
|
||||
a INT,
|
||||
b INT,
|
||||
c INT,
|
||||
PRIMARY KEY (c,a), KEY (a),KEY (a)
|
||||
) ENGINE=INNODB PARTITION BY KEY () PARTITIONS 2;
|
||||
INSERT INTO t1 VALUES (1,5,1),(2,4,1),(3,3,1),(4,2,1),(5,1,1);
|
||||
UPDATE t1 SET b = 0, c=1 WHERE a <=>0;
|
||||
SELECT * FROM t1;
|
||||
a b c
|
||||
1 5 1
|
||||
2 4 1
|
||||
3 3 1
|
||||
4 2 1
|
||||
5 1 1
|
||||
DROP TABLE t1;
|
||||
set global default_storage_engine=default;
|
||||
|
@ -1953,3 +1953,49 @@ a b c d
|
||||
14 1 1 q
|
||||
9 7 1 s
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# BUG#13256446 - ASSERTION QUICK->HEAD->READ_SET ==
|
||||
# SAVE_READ_SET' FAILED IN OPT_RANGE.CC:1606
|
||||
#
|
||||
CREATE TABLE t1 (
|
||||
f1 INT AUTO_INCREMENT,
|
||||
f2 INT,
|
||||
f3 INT,
|
||||
f4 INT,
|
||||
PRIMARY KEY (f1),KEY(f2)
|
||||
) ENGINE=INNODB;
|
||||
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f2=103;
|
||||
INSERT INTO t1 VALUES (154,0,NULL,0),(0,NULL,9,0),
|
||||
(NULL,102,NULL,3),(0,3,NULL,0), (9,0,NULL,0),(0,9,NULL,157);
|
||||
SELECT * FROM v2;
|
||||
f1 f2 f3 f4
|
||||
UPDATE v2 SET f4=0, f2=NULL, f1=NULL WHERE f1 > 16 ORDER BY f1;
|
||||
SELECT * FROM v2;
|
||||
f1 f2 f3 f4
|
||||
DROP TABLE t1;
|
||||
DROP VIEW v2;
|
||||
CREATE TABLE t1 (
|
||||
f1 INT AUTO_INCREMENT,
|
||||
f2 INT,
|
||||
f3 INT,
|
||||
f4 INT,
|
||||
PRIMARY KEY (f1),KEY(f2)
|
||||
) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES(1,NULL,NULL,0), (2,2,0,3), (9,0,107,18),
|
||||
(10,0,0,0), (231,0,0,0), (232,0,8,0), (234,0,0,NULL), (235,8,0,3);
|
||||
CREATE ALGORITHM=MERGE VIEW v3 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f1<=85 ;
|
||||
SELECT * FROM v3;
|
||||
f1 f2 f3 f4
|
||||
1 NULL NULL 0
|
||||
2 2 0 3
|
||||
9 0 107 18
|
||||
10 0 0 0
|
||||
UPDATE v3 SET f3=0, f4=4 WHERE f2=68 ORDER BY f1;
|
||||
SELECT * FROM v3;
|
||||
f1 f2 f3 f4
|
||||
1 NULL NULL 0
|
||||
2 2 0 3
|
||||
9 0 107 18
|
||||
10 0 0 0
|
||||
DROP TABLE t1;
|
||||
DROP VIEW v3;
|
||||
|
@ -1955,4 +1955,50 @@ a b c d
|
||||
9 7 1 s
|
||||
14 1 1 q
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# BUG#13256446 - ASSERTION QUICK->HEAD->READ_SET ==
|
||||
# SAVE_READ_SET' FAILED IN OPT_RANGE.CC:1606
|
||||
#
|
||||
CREATE TABLE t1 (
|
||||
f1 INT AUTO_INCREMENT,
|
||||
f2 INT,
|
||||
f3 INT,
|
||||
f4 INT,
|
||||
PRIMARY KEY (f1),KEY(f2)
|
||||
) ENGINE=INNODB;
|
||||
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f2=103;
|
||||
INSERT INTO t1 VALUES (154,0,NULL,0),(0,NULL,9,0),
|
||||
(NULL,102,NULL,3),(0,3,NULL,0), (9,0,NULL,0),(0,9,NULL,157);
|
||||
SELECT * FROM v2;
|
||||
f1 f2 f3 f4
|
||||
UPDATE v2 SET f4=0, f2=NULL, f1=NULL WHERE f1 > 16 ORDER BY f1;
|
||||
SELECT * FROM v2;
|
||||
f1 f2 f3 f4
|
||||
DROP TABLE t1;
|
||||
DROP VIEW v2;
|
||||
CREATE TABLE t1 (
|
||||
f1 INT AUTO_INCREMENT,
|
||||
f2 INT,
|
||||
f3 INT,
|
||||
f4 INT,
|
||||
PRIMARY KEY (f1),KEY(f2)
|
||||
) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES(1,NULL,NULL,0), (2,2,0,3), (9,0,107,18),
|
||||
(10,0,0,0), (231,0,0,0), (232,0,8,0), (234,0,0,NULL), (235,8,0,3);
|
||||
CREATE ALGORITHM=MERGE VIEW v3 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f1<=85 ;
|
||||
SELECT * FROM v3;
|
||||
f1 f2 f3 f4
|
||||
1 NULL NULL 0
|
||||
2 2 0 3
|
||||
9 0 107 18
|
||||
10 0 0 0
|
||||
UPDATE v3 SET f3=0, f4=4 WHERE f2=68 ORDER BY f1;
|
||||
SELECT * FROM v3;
|
||||
f1 f2 f3 f4
|
||||
1 NULL NULL 0
|
||||
2 2 0 3
|
||||
9 0 107 18
|
||||
10 0 0 0
|
||||
DROP TABLE t1;
|
||||
DROP VIEW v3;
|
||||
set optimizer_switch=@mrr_icp_extra_tmp;
|
||||
|
@ -561,3 +561,45 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function
|
||||
DROP VIEW v1;
|
||||
DROP FUNCTION f1;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Verify that UPDATE does the same number of handler_update
|
||||
# operations, no matter if there is ORDER BY or not.
|
||||
#
|
||||
CREATE TABLE t1 (i INT) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
|
||||
(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
|
||||
(30),(31),(32),(33),(34),(35);
|
||||
CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2),
|
||||
INDEX idx (a,b(1),c)) ENGINE=INNODB;
|
||||
INSERT INTO t2 SELECT i, i, i, i FROM t1;
|
||||
FLUSH STATUS;
|
||||
START TRANSACTION;
|
||||
UPDATE t2 SET d = 10 WHERE b = 10 LIMIT 5;
|
||||
SHOW STATUS LIKE 'HANDLER_UPDATE';
|
||||
Variable_name Value
|
||||
Handler_update 1
|
||||
ROLLBACK;
|
||||
FLUSH STATUS;
|
||||
START TRANSACTION;
|
||||
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
|
||||
SHOW STATUS LIKE 'HANDLER_UPDATE';
|
||||
Variable_name Value
|
||||
Handler_update 1
|
||||
ROLLBACK;
|
||||
Same test with a different UPDATE.
|
||||
ALTER TABLE t2 DROP INDEX idx, ADD INDEX idx2 (a, b);
|
||||
FLUSH STATUS;
|
||||
START TRANSACTION;
|
||||
UPDATE t2 SET c = 10 LIMIT 5;
|
||||
SHOW STATUS LIKE 'HANDLER_UPDATE';
|
||||
Variable_name Value
|
||||
Handler_update 5
|
||||
ROLLBACK;
|
||||
FLUSH STATUS;
|
||||
START TRANSACTION;
|
||||
UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
|
||||
SHOW STATUS LIKE 'HANDLER_UPDATE';
|
||||
Variable_name Value
|
||||
Handler_update 5
|
||||
ROLLBACK;
|
||||
DROP TABLE t1, t2;
|
||||
|
Reference in New Issue
Block a user