summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2017-02-06 23:52:47 +0100
committerSergei Golubchik <serg@mariadb.org>2017-02-13 18:12:14 +0100
commit8d99166c697516ad9b4084c2bc10ba4acf8b9744 (patch)
tree5deb0a17c4029027725cb86abccac7b960020085
parent0e5230e12d1d06e734141bde24e1b928986a77ed (diff)
downloadmariadb-git-8d99166c697516ad9b4084c2bc10ba4acf8b9744.tar.gz
MDEV-11640 gcol.gcol_select_myisam fails in buildbot on Power
JOIN_CACHE's were initialized in check_join_cache_usage() from make_join_readinfo(). After that make_join_readinfo() was looking whether it's possible to use keyread. Later, after make_join_readinfo(), optimizer decided whether to use filesort. And even later, at the execution time, from join_read_first(), keyread was actually enabled. The problem is, that if a query uses a vcol, base columns that it depends on are automatically added to the read_set - because they're needed to calculate the vcol. But if we're doing keyread, vcol is taken from the index, not calculated, and base columns do not need to be in the read set (even should not be - as they aren't getting values). The bug was that JOIN_CACHE used read_set with base columns, they were not read because of keyread, so it was caching garbage. So read_set is only known after the keyread was decided. And after the filesort was decided, as filesort doesn't use keyread. But check_join_cache_usage() needs to be done in make_join_readinfo(), as the code below depends on these checks, Fix: keep JOIN_CACHE checks where they were, but move initialization down to the very end of JOIN::optimize_inner. If keyread was enabled, update the read_set to include only columns that are part of the index. Copy the keyread logic from join_read_first() to happen at optimize time.
-rw-r--r--mysql-test/r/join_cache.result4
-rw-r--r--mysql-test/r/join_outer.result2
-rw-r--r--mysql-test/r/join_outer_jcl6.result2
-rw-r--r--mysql-test/r/limit_rows_examined.result12
-rw-r--r--mysql-test/r/subselect_cache.result164
-rw-r--r--mysql-test/r/subselect_sj2_jcl6.result2
-rw-r--r--mysql-test/suite/vcol/r/vcol_select_myisam.result109
-rw-r--r--mysql-test/suite/vcol/t/vcol_select_myisam.test28
-rw-r--r--sql/sql_select.cc60
-rw-r--r--sql/sql_select.h1
-rw-r--r--sql/table.cc7
11 files changed, 280 insertions, 111 deletions
diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result
index d138babc96b..5cb76a93d9a 100644
--- a/mysql-test/r/join_cache.result
+++ b/mysql-test/r/join_cache.result
@@ -4450,7 +4450,7 @@ EXPLAIN
SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 hash_index cu #hash#cu:cu 33:33 func 10 Using where; Using join buffer (flat, BNLH join)
+1 SIMPLE t1 hash_index cu #hash#cu:cu 33:33 func 10 Using where; Using index; Using join buffer (flat, BNLH join)
SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
i
6
@@ -5242,7 +5242,7 @@ EXPLAIN
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
-1 PRIMARY t2 hash_index c #hash#c:c 5:5 test.t1.b 8 Start temporary; End temporary; Using join buffer (flat, BNLH join)
+1 PRIMARY t2 hash_index c #hash#c:c 5:5 test.t1.b 8 Using index; Start temporary; End temporary; Using join buffer (flat, BNLH join)
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
a b
3914 17
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result
index 7fb3517ecb7..ffeddc989ec 100644
--- a/mysql-test/r/join_outer.result
+++ b/mysql-test/r/join_outer.result
@@ -2006,7 +2006,7 @@ SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t3 hash_ALL PRIMARY #hash#PRIMARY 4 test.t1.b 10 10.00 Using join buffer (flat, BNLH join)
-1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using join buffer (incremental, BNLH join)
+1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using index; Using join buffer (incremental, BNLH join)
Warnings:
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t2` join `test`.`t1` join `test`.`t3` where `test`.`t3`.`b` = `test`.`t1`.`b` and `test`.`t2`.`b` = `test`.`t1`.`b`
PREPARE stmt FROM
diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result
index ef749768d4c..4ffca891061 100644
--- a/mysql-test/r/join_outer_jcl6.result
+++ b/mysql-test/r/join_outer_jcl6.result
@@ -2017,7 +2017,7 @@ SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t3 hash_ALL PRIMARY #hash#PRIMARY 4 test.t1.b 10 10.00 Using join buffer (flat, BNLH join)
-1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using join buffer (incremental, BNLH join)
+1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using index; Using join buffer (incremental, BNLH join)
Warnings:
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t2` join `test`.`t1` join `test`.`t3` where `test`.`t3`.`b` = `test`.`t1`.`b` and `test`.`t2`.`b` = `test`.`t1`.`b`
PREPARE stmt FROM
diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result
index 532448a8da8..157d10ae76a 100644
--- a/mysql-test/r/limit_rows_examined.result
+++ b/mysql-test/r/limit_rows_examined.result
@@ -752,15 +752,15 @@ LIMIT ROWS EXAMINED 120;
ERROR HY000: Sort aborted:
SHOW STATUS LIKE 'Handler_read%';
Variable_name Value
-Handler_read_first 0
+Handler_read_first 1
Handler_read_key 5
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 7
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 46
+Handler_read_rnd_next 38
SHOW STATUS LIKE 'Handler_tmp%';
Variable_name Value
Handler_tmp_update 0
@@ -777,15 +777,15 @@ Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 125 rows, which exceeds LIMIT ROWS EXAMINED (124). The query result may be incomplete
SHOW STATUS LIKE 'Handler_read%';
Variable_name Value
-Handler_read_first 0
+Handler_read_first 1
Handler_read_key 5
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 7
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 2
Handler_read_rnd_deleted 1
-Handler_read_rnd_next 47
+Handler_read_rnd_next 39
SHOW STATUS LIKE 'Handler_tmp%';
Variable_name Value
Handler_tmp_update 0
diff --git a/mysql-test/r/subselect_cache.result b/mysql-test/r/subselect_cache.result
index 86bc78dc204..5c74555af00 100644
--- a/mysql-test/r/subselect_cache.result
+++ b/mysql-test/r/subselect_cache.result
@@ -2842,70 +2842,70 @@ WHERE table1 .`col_varchar_key` ) field10
1 NULL w
1 NULL y
Warnings:
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
SET @@optimizer_switch='subquery_cache=on';
/* cache is on */ SELECT COUNT( DISTINCT table2 .`col_int_key` ) , (
SELECT SUBQUERY2_t1 .`col_int_key`
@@ -2933,32 +2933,32 @@ WHERE table1 .`col_varchar_key` ) field10
1 NULL w
1 NULL y
Warnings:
-Warning 1292 Truncated incorrect DOUBLE value: 'r'
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+Warning 1292 Truncated incorrect DOUBLE value: 'b'
Warning 1292 Truncated incorrect DOUBLE value: 'c'
-Warning 1292 Truncated incorrect DOUBLE value: 'o'
Warning 1292 Truncated incorrect DOUBLE value: 'd'
-Warning 1292 Truncated incorrect DOUBLE value: 'v'
-Warning 1292 Truncated incorrect DOUBLE value: 'm'
-Warning 1292 Truncated incorrect DOUBLE value: 'j'
+Warning 1292 Truncated incorrect DOUBLE value: 'e'
Warning 1292 Truncated incorrect DOUBLE value: 'f'
-Warning 1292 Truncated incorrect DOUBLE value: 'n'
-Warning 1292 Truncated incorrect DOUBLE value: 'z'
+Warning 1292 Truncated incorrect DOUBLE value: 'g'
Warning 1292 Truncated incorrect DOUBLE value: 'h'
+Warning 1292 Truncated incorrect DOUBLE value: 'i'
+Warning 1292 Truncated incorrect DOUBLE value: 'j'
+Warning 1292 Truncated incorrect DOUBLE value: 'k'
+Warning 1292 Truncated incorrect DOUBLE value: 'l'
+Warning 1292 Truncated incorrect DOUBLE value: 'm'
+Warning 1292 Truncated incorrect DOUBLE value: 'n'
+Warning 1292 Truncated incorrect DOUBLE value: 'o'
+Warning 1292 Truncated incorrect DOUBLE value: 'p'
Warning 1292 Truncated incorrect DOUBLE value: 'q'
-Warning 1292 Truncated incorrect DOUBLE value: 'w'
-Warning 1292 Truncated incorrect DOUBLE value: 'a'
-Warning 1292 Truncated incorrect DOUBLE value: 'e'
-Warning 1292 Truncated incorrect DOUBLE value: 'u'
+Warning 1292 Truncated incorrect DOUBLE value: 'r'
Warning 1292 Truncated incorrect DOUBLE value: 's'
-Warning 1292 Truncated incorrect DOUBLE value: 'g'
-Warning 1292 Truncated incorrect DOUBLE value: 'b'
-Warning 1292 Truncated incorrect DOUBLE value: 'y'
-Warning 1292 Truncated incorrect DOUBLE value: 'p'
Warning 1292 Truncated incorrect DOUBLE value: 't'
+Warning 1292 Truncated incorrect DOUBLE value: 'u'
+Warning 1292 Truncated incorrect DOUBLE value: 'v'
+Warning 1292 Truncated incorrect DOUBLE value: 'w'
Warning 1292 Truncated incorrect DOUBLE value: 'x'
-Warning 1292 Truncated incorrect DOUBLE value: 'l'
-Warning 1292 Truncated incorrect DOUBLE value: 'k'
-Warning 1292 Truncated incorrect DOUBLE value: 'i'
+Warning 1292 Truncated incorrect DOUBLE value: 'y'
+Warning 1292 Truncated incorrect DOUBLE value: 'z'
drop table t1,t2,t3,t4;
set @@optimizer_switch= default;
#launchpad BUG#609045
diff --git a/mysql-test/r/subselect_sj2_jcl6.result b/mysql-test/r/subselect_sj2_jcl6.result
index 61519234f44..2955307eb86 100644
--- a/mysql-test/r/subselect_sj2_jcl6.result
+++ b/mysql-test/r/subselect_sj2_jcl6.result
@@ -1184,7 +1184,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Start temporary; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
-1 PRIMARY t4 hash_index NULL #hash#$hj:PRIMARY 54:59 test.t3.t3_c 2 Using where; End temporary; Using join buffer (incremental, BNLH join)
+1 PRIMARY t4 hash_index NULL #hash#$hj:PRIMARY 54:59 test.t3.t3_c 2 Using where; Using index; End temporary; Using join buffer (incremental, BNLH join)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
diff --git a/mysql-test/suite/vcol/r/vcol_select_myisam.result b/mysql-test/suite/vcol/r/vcol_select_myisam.result
index 30d21d6792a..88a9e608c9d 100644
--- a/mysql-test/suite/vcol/r/vcol_select_myisam.result
+++ b/mysql-test/suite/vcol/r/vcol_select_myisam.result
@@ -295,3 +295,112 @@ Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1`
SELECT * FROM t1 NATURAL JOIN t2;
b a
DROP TABLE t1,t2;
+create table t1 (
+pk integer auto_increment,
+bi integer not null,
+vi integer generated always as (bi) virtual,
+bc varchar(1) not null,
+vc varchar(2) generated always as (concat(bc, bc)),
+primary key (pk),
+key (vi, vc));
+insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v');
+create table t2 (
+pk integer auto_increment,
+bi integer not null,
+vi integer generated always as (bi) virtual,
+bc varchar(257) not null,
+vc varchar(2) generated always as (concat(bc, bc)),
+primary key (pk),
+key (vi, vc));
+insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y');
+explain # should be using join buffer
+select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL vi 10 NULL 19 Using index
+1 SIMPLE t1 ALL NULL NULL NULL NULL 19 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t3 index NULL PRIMARY 4 NULL 19 Using where; Using index; Using join buffer (incremental, BNL join)
+select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
+vi
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+2
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+6
+6
+6
+6
+7
+7
+8
+8
+8
+8
+9
+9
+drop table t2,t1;
diff --git a/mysql-test/suite/vcol/t/vcol_select_myisam.test b/mysql-test/suite/vcol/t/vcol_select_myisam.test
index c86ae10a4b3..5dd08894fea 100644
--- a/mysql-test/suite/vcol/t/vcol_select_myisam.test
+++ b/mysql-test/suite/vcol/t/vcol_select_myisam.test
@@ -68,3 +68,31 @@ SELECT * FROM t1 NATURAL JOIN t2;
SELECT * FROM t1 NATURAL JOIN t2;
DROP TABLE t1,t2;
+
+#
+# MDEV-11640 gcol.gcol_select_myisam fails in buildbot on Power
+#
+
+create table t1 (
+ pk integer auto_increment,
+ bi integer not null,
+ vi integer generated always as (bi) virtual,
+ bc varchar(1) not null,
+ vc varchar(2) generated always as (concat(bc, bc)),
+ primary key (pk),
+ key (vi, vc));
+insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v');
+create table t2 (
+ pk integer auto_increment,
+ bi integer not null,
+ vi integer generated always as (bi) virtual,
+ bc varchar(257) not null,
+ vc varchar(2) generated always as (concat(bc, bc)),
+ primary key (pk),
+ key (vi, vc));
+insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y');
+explain # should be using join buffer
+select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
+--sorted_result
+select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
+drop table t2,t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a981e3adc60..efdbed93802 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1111,6 +1111,34 @@ int JOIN::optimize()
}
+int JOIN::init_join_caches()
+{
+ JOIN_TAB *tab;
+
+ for (tab= first_linear_tab(this, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES);
+ tab;
+ tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS))
+ {
+ TABLE *table= tab->table;
+ if (table->file->keyread_enabled())
+ {
+ if (!(table->file->index_flags(table->file->keyread, 0, 1) & HA_CLUSTERED_INDEX))
+ table->mark_columns_used_by_index(table->file->keyread, table->read_set);
+ }
+ else if ((tab->read_first_record == join_read_first ||
+ tab->read_first_record == join_read_last) &&
+ !tab->filesort && table->covering_keys.is_set(tab->index) &&
+ !table->no_keyread)
+ {
+ table->prepare_for_keyread(tab->index, table->read_set);
+ }
+ if (tab->cache && tab->cache->init(select_options & SELECT_DESCRIBE))
+ revise_cache_usage(tab);
+ }
+ return 0;
+}
+
+
/**
global select optimisation.
@@ -2122,6 +2150,9 @@ JOIN::optimize_inner()
if (make_aggr_tables_info())
DBUG_RETURN(1);
+ if (init_join_caches())
+ DBUG_RETURN(1);
+
error= 0;
if (select_options & SELECT_DESCRIBE)
@@ -10408,11 +10439,10 @@ void set_join_cache_denial(JOIN_TAB *join_tab)
if (join_tab->cache->prev_cache)
join_tab->cache->prev_cache->next_cache= 0;
/*
- No need to do the same for next_cache since cache denial is done
- backwards starting from the latest cache in the linked list (see
- revise_cache_usage()).
+ Same for the next_cache
*/
- DBUG_ASSERT(!join_tab->cache->next_cache);
+ if (join_tab->cache->next_cache)
+ join_tab->cache->next_cache->prev_cache= 0;
join_tab->cache->free();
join_tab->cache= 0;
@@ -10872,8 +10902,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
case JT_ALL:
if (cache_level == 1)
prev_cache= 0;
- if ((tab->cache= new (root) JOIN_CACHE_BNL(join, tab, prev_cache)) &&
- !tab->cache->init(options & SELECT_DESCRIBE))
+ if ((tab->cache= new (root) JOIN_CACHE_BNL(join, tab, prev_cache)))
{
tab->icp_other_tables_ok= FALSE;
return (2 - MY_TEST(!prev_cache));
@@ -10907,8 +10936,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
goto no_join_cache;
if (cache_level == 3)
prev_cache= 0;
- if ((tab->cache= new (root) JOIN_CACHE_BNLH(join, tab, prev_cache)) &&
- !tab->cache->init(options & SELECT_DESCRIBE))
+ if ((tab->cache= new (root) JOIN_CACHE_BNLH(join, tab, prev_cache)))
{
tab->icp_other_tables_ok= FALSE;
return (4 - MY_TEST(!prev_cache));
@@ -10928,8 +10956,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
{
if (cache_level == 5)
prev_cache= 0;
- if ((tab->cache= new (root) JOIN_CACHE_BKA(join, tab, flags, prev_cache)) &&
- !tab->cache->init(options & SELECT_DESCRIBE))
+ if ((tab->cache= new (root) JOIN_CACHE_BKA(join, tab, flags, prev_cache)))
return (6 - MY_TEST(!prev_cache));
goto no_join_cache;
}
@@ -10937,8 +10964,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
{
if (cache_level == 7)
prev_cache= 0;
- if ((tab->cache= new (root) JOIN_CACHE_BKAH(join, tab, flags, prev_cache)) &&
- !tab->cache->init(options & SELECT_DESCRIBE))
+ if ((tab->cache= new (root) JOIN_CACHE_BKAH(join, tab, flags, prev_cache)))
{
tab->idx_cond_fact_out= FALSE;
return (8 - MY_TEST(!prev_cache));
@@ -19347,8 +19373,9 @@ join_read_first(JOIN_TAB *tab)
TABLE *table=tab->table;
DBUG_ENTER("join_read_first");
- if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
- table->file->ha_start_keyread(tab->index);
+ DBUG_ASSERT(table->no_keyread ||
+ !table->covering_keys.is_set(tab->index) ||
+ table->file->keyread == tab->index);
tab->table->status=0;
tab->read_record.read_record=join_read_next;
tab->read_record.table=table;
@@ -19386,8 +19413,9 @@ join_read_last(JOIN_TAB *tab)
int error= 0;
DBUG_ENTER("join_read_first");
- if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
- table->file->ha_start_keyread(tab->index);
+ DBUG_ASSERT(table->no_keyread ||
+ !table->covering_keys.is_set(tab->index) ||
+ table->file->keyread == tab->index);
tab->table->status=0;
tab->read_record.read_record=join_read_prev;
tab->read_record.table=table;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index f1d48b700d7..f5bbc6718a0 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1512,6 +1512,7 @@ public:
bool flatten_subqueries();
bool optimize_unflattened_subqueries();
bool optimize_constant_subqueries();
+ int init_join_caches();
bool make_sum_func_list(List<Item> &all_fields, List<Item> &send_fields,
bool before_group_by, bool recompute= FALSE);
diff --git a/sql/table.cc b/sql/table.cc
index 33317234c85..1c6cc4205a6 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -6076,8 +6076,11 @@ MY_BITMAP *TABLE::prepare_for_keyread(uint index, MY_BITMAP *map)
DBUG_ENTER("TABLE::prepare_for_keyread");
if (!no_keyread)
file->ha_start_keyread(index);
- mark_columns_used_by_index(index, map);
- column_bitmaps_set(map);
+ if (map != read_set || !(file->index_flags(index, 0, 1) & HA_CLUSTERED_INDEX))
+ {
+ mark_columns_used_by_index(index, map);
+ column_bitmaps_set(map);
+ }
DBUG_RETURN(backup);
}