Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
58b4f52a
Commit
58b4f52a
authored
Oct 29, 2014
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
1e1a8a7f
a8341dfd
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
347 additions
and
12 deletions
+347
-12
mysql-test/r/derived_opt.result
mysql-test/r/derived_opt.result
+153
-1
mysql-test/r/innodb_mrr_cpk.result
mysql-test/r/innodb_mrr_cpk.result
+38
-0
mysql-test/r/join_cache.result
mysql-test/r/join_cache.result
+6
-6
mysql-test/t/derived_opt.test
mysql-test/t/derived_opt.test
+92
-1
mysql-test/t/innodb_mrr_cpk.test
mysql-test/t/innodb_mrr_cpk.test
+29
-0
sql/multi_range_read.cc
sql/multi_range_read.cc
+8
-2
sql/multi_range_read.h
sql/multi_range_read.h
+6
-0
sql/sql_select.cc
sql/sql_select.cc
+14
-1
sql/table.cc
sql/table.cc
+1
-1
No files found.
mysql-test/r/derived_opt.result
View file @
58b4f52a
drop table if exists t1,t2,t3;
drop table if exists t0,t1,t2,t3;
drop database if exists test1;
set @exit_optimizer_switch=@@optimizer_switch;
set optimizer_switch='derived_merge=on,derived_with_keys=on';
set @save_optimizer_switch=@@optimizer_switch;
...
...
@@ -352,4 +353,155 @@ pk pk
72 72
80 80
drop table t1, t2, t3, t4;
#
# MDEV-6888: Query spends a long time in best_extension_by_limited_search with mrr enabled
#
create database test1;
use test1;
set @tmp_jcl= @@join_cache_level;
set @tmp_os= @@optimizer_switch;
set join_cache_level=8;
set optimizer_switch='mrr=on,mrr_sort_keys=on';
CREATE TABLE t0 (
f1 bigint(20) DEFAULT NULL,
f2 char(50) DEFAULT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1;
INSERT INTO t0 VALUES (NULL,'numeric column is NULL'),(0,NULL),(5,'five'),(1,'one'),(2,'two');
CREATE TABLE t1 (
f1 decimal(64,30) DEFAULT NULL,
f2 varchar(50) DEFAULT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES
(NULL,'numeric column is NULL'),
(0.000000000000000000000000000000,NULL),
(5.000000000000000000000000000000,'five'),
(1.000000000000000000000000000000,'one'),
(3.000000000000000000000000000000,'three');
CREATE TABLE t2 (
f1 double DEFAULT NULL,
f2 varbinary(50) DEFAULT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1;
INSERT INTO t2 VALUES (NULL,'numeric column is NULL'),(0,NULL),(5,'five'),(2,'two'),(3,'three');
create VIEW v0 AS select f1,f2 from t1 ;
create VIEW v1 AS select tab1_v1.f1,tab1_v1.f2 from t1 tab1_v1 join v0 tab2 on tab1_v1.f1 = tab2.f1 and tab1_v1.f2 = tab2.f2;
create VIEW v2 AS select tab1_v2.f1,tab1_v2.f2 from t2 tab1_v2 join v1 tab2 on tab1_v2.f1 = tab2.f1 and tab1_v2.f2 = tab2.f2;
create VIEW v3 AS select tab1_v3.f1,tab1_v3.f2 from t0 tab1_v3 join v2 tab2 on tab1_v3.f1 = tab2.f1 and tab1_v3.f2 = tab2.f2;
create VIEW v4 AS select tab1_v4.f1,tab1_v4.f2 from t1 tab1_v4 join v3 tab2 on tab1_v4.f1 = tab2.f1 and tab1_v4.f2 = tab2.f2;
create VIEW v5 AS select tab1_v5.f1,tab1_v5.f2 from t2 tab1_v5 join v4 tab2 on tab1_v5.f1 = tab2.f1 and tab1_v5.f2 = tab2.f2;
create VIEW v6 AS select tab1_v6.f1,tab1_v6.f2 from t0 tab1_v6 join v5 tab2 on tab1_v6.f1 = tab2.f1 and tab1_v6.f2 = tab2.f2;
create VIEW v7 AS select tab1_v7.f1,tab1_v7.f2 from t1 tab1_v7 join v6 tab2 on tab1_v7.f1 = tab2.f1 and tab1_v7.f2 = tab2.f2;
create VIEW v8 AS select tab1_v8.f1,tab1_v8.f2 from t2 tab1_v8 join v7 tab2 on tab1_v8.f1 = tab2.f1 and tab1_v8.f2 = tab2.f2;
create VIEW v9 AS select tab1_v9.f1,tab1_v9.f2 from t0 tab1_v9 join v8 tab2 on tab1_v9.f1 = tab2.f1 and tab1_v9.f2 = tab2.f2;
create VIEW v10 AS select tab1_v10.f1,tab1_v10.f2 from t1 tab1_v10 join v9 tab2 on tab1_v10.f1 = tab2.f1 and tab1_v10.f2 = tab2.f2;
create VIEW v11 AS select tab1_v11.f1,tab1_v11.f2 from t2 tab1_v11 join v10 tab2 on tab1_v11.f1 = tab2.f1 and tab1_v11.f2 = tab2.f2;
create VIEW v12 AS select tab1_v12.f1,tab1_v12.f2 from t0 tab1_v12 join v11 tab2 on tab1_v12.f1 = tab2.f1 and tab1_v12.f2 = tab2.f2;
create VIEW v13 AS select tab1_v13.f1,tab1_v13.f2 from t1 tab1_v13 join v12 tab2 on tab1_v13.f1 = tab2.f1 and tab1_v13.f2 = tab2.f2;
create VIEW v14 AS select tab1_v14.f1,tab1_v14.f2 from t2 tab1_v14 join v13 tab2 on tab1_v14.f1 = tab2.f1 and tab1_v14.f2 = tab2.f2;
create VIEW v15 AS select tab1_v15.f1,tab1_v15.f2 from t0 tab1_v15 join v14 tab2 on tab1_v15.f1 = tab2.f1 and tab1_v15.f2 = tab2.f2;
create VIEW v16 AS select tab1_v16.f1,tab1_v16.f2 from t1 tab1_v16 join v15 tab2 on tab1_v16.f1 = tab2.f1 and tab1_v16.f2 = tab2.f2;
create VIEW v17 AS select tab1_v17.f1,tab1_v17.f2 from t2 tab1_v17 join v16 tab2 on tab1_v17.f1 = tab2.f1 and tab1_v17.f2 = tab2.f2;
create VIEW v18 AS select tab1_v18.f1,tab1_v18.f2 from t0 tab1_v18 join v17 tab2 on tab1_v18.f1 = tab2.f1 and tab1_v18.f2 = tab2.f2;
create VIEW v19 AS select tab1_v19.f1,tab1_v19.f2 from t1 tab1_v19 join v18 tab2 on tab1_v19.f1 = tab2.f1 and tab1_v19.f2 = tab2.f2;
create VIEW v20 AS select tab1_v20.f1,tab1_v20.f2 from t2 tab1_v20 join v19 tab2 on tab1_v20.f1 = tab2.f1 and tab1_v20.f2 = tab2.f2;
create VIEW v21 AS select tab1_v21.f1,tab1_v21.f2 from t0 tab1_v21 join v20 tab2 on tab1_v21.f1 = tab2.f1 and tab1_v21.f2 = tab2.f2;
create VIEW v22 AS select tab1_v22.f1,tab1_v22.f2 from t1 tab1_v22 join v21 tab2 on tab1_v22.f1 = tab2.f1 and tab1_v22.f2 = tab2.f2;
create VIEW v23 AS select tab1_v23.f1,tab1_v23.f2 from t2 tab1_v23 join v22 tab2 on tab1_v23.f1 = tab2.f1 and tab1_v23.f2 = tab2.f2;
create VIEW v24 AS select tab1_v24.f1,tab1_v24.f2 from t0 tab1_v24 join v23 tab2 on tab1_v24.f1 = tab2.f1 and tab1_v24.f2 = tab2.f2;
create VIEW v25 AS select tab1_v25.f1,tab1_v25.f2 from t1 tab1_v25 join v24 tab2 on tab1_v25.f1 = tab2.f1 and tab1_v25.f2 = tab2.f2;
create VIEW v26 AS select tab1_v26.f1,tab1_v26.f2 from t2 tab1_v26 join v25 tab2 on tab1_v26.f1 = tab2.f1 and tab1_v26.f2 = tab2.f2;
create VIEW v27 AS select tab1_v27.f1,tab1_v27.f2 from t0 tab1_v27 join v26 tab2 on tab1_v27.f1 = tab2.f1 and tab1_v27.f2 = tab2.f2;
EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1, CAST(f2 AS CHAR) AS f2 FROM v27;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tab1_v27 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE tab1_v26 hash_ALL NULL #hash#$hj 63 test1.tab1_v27.f1,test1.tab1_v27.f2 5 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE tab1_v25 hash_ALL NULL #hash#$hj 31 test1.tab1_v26.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v24 hash_ALL NULL #hash#$hj 60 test1.tab1_v25.f1,test1.tab1_v25.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v23 hash_ALL NULL #hash#$hj 63 test1.tab1_v24.f1,test1.tab1_v24.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v22 hash_ALL NULL #hash#$hj 31 test1.tab1_v23.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v21 hash_ALL NULL #hash#$hj 60 test1.tab1_v22.f1,test1.tab1_v22.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v20 hash_ALL NULL #hash#$hj 63 test1.tab1_v21.f1,test1.tab1_v21.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v19 hash_ALL NULL #hash#$hj 31 test1.tab1_v20.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v18 hash_ALL NULL #hash#$hj 60 test1.tab1_v19.f1,test1.tab1_v19.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v17 hash_ALL NULL #hash#$hj 63 test1.tab1_v18.f1,test1.tab1_v18.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v16 hash_ALL NULL #hash#$hj 31 test1.tab1_v17.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v15 hash_ALL NULL #hash#$hj 60 test1.tab1_v16.f1,test1.tab1_v16.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v14 hash_ALL NULL #hash#$hj 63 test1.tab1_v15.f1,test1.tab1_v15.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v13 hash_ALL NULL #hash#$hj 31 test1.tab1_v14.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v12 hash_ALL NULL #hash#$hj 60 test1.tab1_v13.f1,test1.tab1_v13.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v11 hash_ALL NULL #hash#$hj 63 test1.tab1_v12.f1,test1.tab1_v12.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v10 hash_ALL NULL #hash#$hj 31 test1.tab1_v11.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v9 hash_ALL NULL #hash#$hj 60 test1.tab1_v10.f1,test1.tab1_v10.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v8 hash_ALL NULL #hash#$hj 63 test1.tab1_v9.f1,test1.tab1_v9.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v7 hash_ALL NULL #hash#$hj 31 test1.tab1_v8.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v6 hash_ALL NULL #hash#$hj 60 test1.tab1_v7.f1,test1.tab1_v7.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v5 hash_ALL NULL #hash#$hj 63 test1.tab1_v6.f1,test1.tab1_v6.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v4 hash_ALL NULL #hash#$hj 31 test1.tab1_v5.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v3 hash_ALL NULL #hash#$hj 60 test1.tab1_v4.f1,test1.tab1_v4.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v2 hash_ALL NULL #hash#$hj 63 test1.tab1_v3.f1,test1.tab1_v3.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v1 hash_ALL NULL #hash#$hj 31 test1.tab1_v2.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t1 hash_ALL NULL #hash#$hj 85 test1.tab1_v1.f1,test1.tab1_v1.f2 5 Using where; Using join buffer (incremental, BNLH join)
# This used to hang forever:
EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1, CAST(f2 AS CHAR) AS f2 FROM v27;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tab1_v27 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE tab1_v26 hash_ALL NULL #hash#$hj 63 test1.tab1_v27.f1,test1.tab1_v27.f2 5 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE tab1_v25 hash_ALL NULL #hash#$hj 31 test1.tab1_v26.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v24 hash_ALL NULL #hash#$hj 60 test1.tab1_v25.f1,test1.tab1_v25.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v23 hash_ALL NULL #hash#$hj 63 test1.tab1_v24.f1,test1.tab1_v24.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v22 hash_ALL NULL #hash#$hj 31 test1.tab1_v23.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v21 hash_ALL NULL #hash#$hj 60 test1.tab1_v22.f1,test1.tab1_v22.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v20 hash_ALL NULL #hash#$hj 63 test1.tab1_v21.f1,test1.tab1_v21.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v19 hash_ALL NULL #hash#$hj 31 test1.tab1_v20.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v18 hash_ALL NULL #hash#$hj 60 test1.tab1_v19.f1,test1.tab1_v19.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v17 hash_ALL NULL #hash#$hj 63 test1.tab1_v18.f1,test1.tab1_v18.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v16 hash_ALL NULL #hash#$hj 31 test1.tab1_v17.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v15 hash_ALL NULL #hash#$hj 60 test1.tab1_v16.f1,test1.tab1_v16.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v14 hash_ALL NULL #hash#$hj 63 test1.tab1_v15.f1,test1.tab1_v15.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v13 hash_ALL NULL #hash#$hj 31 test1.tab1_v14.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v12 hash_ALL NULL #hash#$hj 60 test1.tab1_v13.f1,test1.tab1_v13.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v11 hash_ALL NULL #hash#$hj 63 test1.tab1_v12.f1,test1.tab1_v12.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v10 hash_ALL NULL #hash#$hj 31 test1.tab1_v11.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v9 hash_ALL NULL #hash#$hj 60 test1.tab1_v10.f1,test1.tab1_v10.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v8 hash_ALL NULL #hash#$hj 63 test1.tab1_v9.f1,test1.tab1_v9.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v7 hash_ALL NULL #hash#$hj 31 test1.tab1_v8.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v6 hash_ALL NULL #hash#$hj 60 test1.tab1_v7.f1,test1.tab1_v7.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v5 hash_ALL NULL #hash#$hj 63 test1.tab1_v6.f1,test1.tab1_v6.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v4 hash_ALL NULL #hash#$hj 31 test1.tab1_v5.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v3 hash_ALL NULL #hash#$hj 60 test1.tab1_v4.f1,test1.tab1_v4.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v2 hash_ALL NULL #hash#$hj 63 test1.tab1_v3.f1,test1.tab1_v3.f2 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE tab1_v1 hash_ALL NULL #hash#$hj 31 test1.tab1_v2.f1 5 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t1 hash_ALL NULL #hash#$hj 85 test1.tab1_v1.f1,test1.tab1_v1.f2 5 Using where; Using join buffer (incremental, BNLH join)
use test;
drop database test1;
set join_cache_level=@tmp_jcl;
set optimizer_switch=@tmp_os;
#
# MDEV-6879: Dereference of NULL primary_file->table in DsMrr_impl::get_disk_sweep_mrr_cost()
#
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, c text);
insert into t2
select
A.a + B.a* 10,
A.a + B.a* 10,
'blob-data'
from t1 A, t1 B;
set @tmp_jcl= @@join_cache_level;
set @tmp_os= @@optimizer_switch;
set join_cache_level=6;
set @@optimizer_switch='derived_merge=on,derived_with_keys=on,mrr=on';
explain
select * from
t1 join
(select * from t2 order by a limit 1000) as D1
where
D1.a= t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 10 Using where
1 PRIMARY <derived2> hash_ALL key0 #hash#key0 5 test.t1.a 100 Using join buffer (flat, BNLH join)
2 DERIVED t2 ALL NULL NULL NULL NULL 100 Using filesort
set join_cache_level=@tmp_jcl;
set optimizer_switch=@tmp_os;
drop table t1, t2;
set optimizer_switch=@exit_optimizer_switch;
mysql-test/r/innodb_mrr_cpk.result
View file @
58b4f52a
...
...
@@ -149,3 +149,41 @@ 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-6878: Use of uninitialized saved_primary_key in Mrr_ordered_index_reader::resume_read()
#
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
pk varchar(32) character set utf8 primary key,
kp1 char(32) not null,
col1 varchar(32),
key (kp1)
) engine=innodb;
insert into t1
select
concat('pk-', 1000 +A.a),
concat('kp1-', 1000 +A.a),
concat('val-', 1000 +A.a)
from test.t0 A ;
create table t2 as select kp1 as a from t1;
set join_cache_level=8;
set optimizer_switch='mrr=on,mrr_sort_keys=on';
explain
select * from t2 straight_join t1 force index(kp1) where t1.kp1=t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 10
1 SIMPLE t1 ref kp1 kp1 32 test.t2.a 1 Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
select * from t2 straight_join t1 force index(kp1) where t1.kp1=t2.a;
a pk kp1 col1
kp1-1000 pk-1000 kp1-1000 val-1000
kp1-1001 pk-1001 kp1-1001 val-1001
kp1-1002 pk-1002 kp1-1002 val-1002
kp1-1003 pk-1003 kp1-1003 val-1003
kp1-1004 pk-1004 kp1-1004 val-1004
kp1-1005 pk-1005 kp1-1005 val-1005
kp1-1006 pk-1006 kp1-1006 val-1006
kp1-1007 pk-1007 kp1-1007 val-1007
kp1-1008 pk-1008 kp1-1008 val-1008
kp1-1009 pk-1009 kp1-1009 val-1009
drop table t0,t1,t2;
mysql-test/r/join_cache.result
View file @
58b4f52a
...
...
@@ -498,8 +498,8 @@ CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join)
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
...
...
@@ -576,8 +576,8 @@ CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE C
ity ALL NULL NULL NULL NULL 4079
Using where; Using join buffer (flat, BNL join)
1 SIMPLE C
ountryLanguage ALL NULL NULL NULL NULL 984
Using where; Using join buffer (incremental, BNL join)
1 SIMPLE C
ountryLanguage ALL NULL NULL NULL NULL 984
Using where; Using join buffer (flat, BNL join)
1 SIMPLE C
ity ALL NULL NULL NULL NULL 4079
Using where; Using join buffer (incremental, BNL join)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
...
...
@@ -654,8 +654,8 @@ CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
...
...
@@ -732,8 +732,8 @@ CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE C
ity hash_ALL NULL #hash#$hj 3 world.Country.Code 4079
Using where; Using join buffer (flat, BNLH join)
1 SIMPLE C
ountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984
Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE C
ountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984
Using where; Using join buffer (flat, BNLH join)
1 SIMPLE C
ity hash_ALL NULL #hash#$hj 3 world.Country.Code 4079
Using where; Using join buffer (incremental, BNLH join)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
...
...
mysql-test/t/derived_opt.test
View file @
58b4f52a
# Initialize
--
disable_warnings
drop
table
if
exists
t1
,
t2
,
t3
;
drop
table
if
exists
t0
,
t1
,
t2
,
t3
;
drop
database
if
exists
test1
;
--
enable_warnings
set
@
exit_optimizer_switch
=@@
optimizer_switch
;
...
...
@@ -272,5 +273,95 @@ limit 10;
drop
table
t1
,
t2
,
t3
,
t4
;
--
echo
#
--
echo
# MDEV-6888: Query spends a long time in best_extension_by_limited_search with mrr enabled
--
echo
#
create
database
test1
;
use
test1
;
set
@
tmp_jcl
=
@@
join_cache_level
;
set
@
tmp_os
=
@@
optimizer_switch
;
set
join_cache_level
=
8
;
set
optimizer_switch
=
'mrr=on,mrr_sort_keys=on'
;
CREATE
TABLE
t0
(
f1
bigint
(
20
)
DEFAULT
NULL
,
f2
char
(
50
)
DEFAULT
NULL
)
ENGINE
=
MEMORY
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t0
VALUES
(
NULL
,
'numeric column is NULL'
),(
0
,
NULL
),(
5
,
'five'
),(
1
,
'one'
),(
2
,
'two'
);
CREATE
TABLE
t1
(
f1
decimal
(
64
,
30
)
DEFAULT
NULL
,
f2
varchar
(
50
)
DEFAULT
NULL
)
ENGINE
=
MEMORY
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
NULL
,
'numeric column is NULL'
),
(
0.000000000000000000000000000000
,
NULL
),
(
5.000000000000000000000000000000
,
'five'
),
(
1.000000000000000000000000000000
,
'one'
),
(
3.000000000000000000000000000000
,
'three'
);
CREATE
TABLE
t2
(
f1
double
DEFAULT
NULL
,
f2
varbinary
(
50
)
DEFAULT
NULL
)
ENGINE
=
MEMORY
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t2
VALUES
(
NULL
,
'numeric column is NULL'
),(
0
,
NULL
),(
5
,
'five'
),(
2
,
'two'
),(
3
,
'three'
);
create
VIEW
v0
AS
select
f1
,
f2
from
t1
;
let
$cnt
=
27
;
while
(
$cnt
)
{
# i runs from 1 to 27
let
$i
=
`select 28 - $cnt`
;
let
$prev
=
`select $i - 1`
;
# rem = i mod 3
let
$rem
=
`select MOD($i, 3)`
;
# view uses $i, $prev and $rem:
eval
create
VIEW
v
$i
AS
select
tab1_v
$i
.
f1
,
tab1_v
$i
.
f2
from
t
$rem
tab1_v
$i
join
v
$prev
tab2
on
tab1_v
$i
.
f1
=
tab2
.
f1
and
tab1_v
$i
.
f2
=
tab2
.
f2
;
dec
$cnt
;
}
EXPLAIN
SELECT
CAST
(
f1
AS
SIGNED
INTEGER
)
AS
f1
,
CAST
(
f2
AS
CHAR
)
AS
f2
FROM
v27
;
--
echo
# This used to hang forever:
EXPLAIN
SELECT
CAST
(
f1
AS
SIGNED
INTEGER
)
AS
f1
,
CAST
(
f2
AS
CHAR
)
AS
f2
FROM
v27
;
use
test
;
drop
database
test1
;
set
join_cache_level
=@
tmp_jcl
;
set
optimizer_switch
=@
tmp_os
;
--
echo
#
--
echo
# MDEV-6879: Dereference of NULL primary_file->table in DsMrr_impl::get_disk_sweep_mrr_cost()
--
echo
#
create
table
t1
(
a
int
);
insert
into
t1
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
create
table
t2
(
a
int
,
b
int
,
c
text
);
insert
into
t2
select
A
.
a
+
B
.
a
*
10
,
A
.
a
+
B
.
a
*
10
,
'blob-data'
from
t1
A
,
t1
B
;
set
@
tmp_jcl
=
@@
join_cache_level
;
set
@
tmp_os
=
@@
optimizer_switch
;
set
join_cache_level
=
6
;
set
@@
optimizer_switch
=
'derived_merge=on,derived_with_keys=on,mrr=on'
;
explain
select
*
from
t1
join
(
select
*
from
t2
order
by
a
limit
1000
)
as
D1
where
D1
.
a
=
t1
.
a
;
set
join_cache_level
=@
tmp_jcl
;
set
optimizer_switch
=@
tmp_os
;
drop
table
t1
,
t2
;
# The following command must be the last one the file
set
optimizer_switch
=@
exit_optimizer_switch
;
mysql-test/t/innodb_mrr_cpk.test
View file @
58b4f52a
...
...
@@ -139,3 +139,32 @@ set storage_engine=@save_storage_engine;
set
optimizer_switch
=@
innodb_mrr_cpk_tmp
;
drop
table
t0
;
--
echo
#
--
echo
# MDEV-6878: Use of uninitialized saved_primary_key in Mrr_ordered_index_reader::resume_read()
--
echo
#
create
table
t0
(
a
int
);
insert
into
t0
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
create
table
t1
(
pk
varchar
(
32
)
character
set
utf8
primary
key
,
kp1
char
(
32
)
not
null
,
col1
varchar
(
32
),
key
(
kp1
)
)
engine
=
innodb
;
insert
into
t1
select
concat
(
'pk-'
,
1000
+
A
.
a
),
concat
(
'kp1-'
,
1000
+
A
.
a
),
concat
(
'val-'
,
1000
+
A
.
a
)
from
test
.
t0
A
;
create
table
t2
as
select
kp1
as
a
from
t1
;
set
join_cache_level
=
8
;
set
optimizer_switch
=
'mrr=on,mrr_sort_keys=on'
;
explain
select
*
from
t2
straight_join
t1
force
index
(
kp1
)
where
t1
.
kp1
=
t2
.
a
;
select
*
from
t2
straight_join
t1
force
index
(
kp1
)
where
t1
.
kp1
=
t2
.
a
;
drop
table
t0
,
t1
,
t2
;
sql/multi_range_read.cc
View file @
58b4f52a
...
...
@@ -410,6 +410,7 @@ bool Mrr_ordered_index_reader::set_interruption_temp_buffer(uint rowid_length,
*
space_start
+=
key_len
;
have_saved_rowid
=
FALSE
;
read_was_interrupted
=
FALSE
;
return
FALSE
;
}
...
...
@@ -418,6 +419,7 @@ void Mrr_ordered_index_reader::set_no_interruption_temp_buffer()
support_scan_interruptions
=
FALSE
;
saved_key_tuple
=
saved_rowid
=
saved_primary_key
=
NULL
;
/* safety */
have_saved_rowid
=
FALSE
;
read_was_interrupted
=
FALSE
;
}
void
Mrr_ordered_index_reader
::
interrupt_read
()
...
...
@@ -435,6 +437,7 @@ void Mrr_ordered_index_reader::interrupt_read()
&
table
->
key_info
[
table
->
s
->
primary_key
],
table
->
key_info
[
table
->
s
->
primary_key
].
key_length
);
}
read_was_interrupted
=
TRUE
;
/* Save the last rowid */
memcpy
(
saved_rowid
,
file
->
ref
,
file
->
ref_length
);
...
...
@@ -452,6 +455,10 @@ void Mrr_ordered_index_reader::position()
void
Mrr_ordered_index_reader
::
resume_read
()
{
TABLE
*
table
=
file
->
get_table
();
if
(
!
read_was_interrupted
)
return
;
KEY
*
used_index
=
&
table
->
key_info
[
file
->
active_index
];
key_restore
(
table
->
record
[
0
],
saved_key_tuple
,
used_index
,
used_index
->
key_length
);
...
...
@@ -541,8 +548,7 @@ int Mrr_ordered_index_reader::init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
is_mrr_assoc
=
!
test
(
mode
&
HA_MRR_NO_ASSOCIATION
);
mrr_funcs
=
*
seq_funcs
;
source_exhausted
=
FALSE
;
if
(
support_scan_interruptions
)
bzero
(
saved_key_tuple
,
key_info
->
key_length
);
read_was_interrupted
=
false
;
have_saved_rowid
=
FALSE
;
return
0
;
}
...
...
sql/multi_range_read.h
View file @
58b4f52a
...
...
@@ -324,6 +324,12 @@ class Mrr_ordered_index_reader : public Mrr_index_reader
uchar
*
saved_key_tuple
;
/* Saved current key tuple */
uchar
*
saved_primary_key
;
/* Saved current primary key tuple */
/*
TRUE<=> saved_key_tuple (and saved_primary_key when applicable) have
valid values.
*/
bool
read_was_interrupted
;
static
int
compare_keys
(
void
*
arg
,
uchar
*
key1
,
uchar
*
key2
);
static
int
compare_keys_reverse
(
void
*
arg
,
uchar
*
key1
,
uchar
*
key2
);
...
...
sql/sql_select.cc
View file @
58b4f52a
...
...
@@ -9663,6 +9663,19 @@ uint check_join_cache_usage(JOIN_TAB *tab,
cache_level
--
;
}
/*
Don't use BKA for materialized tables. We could actually have a
meaningful use of BKA when linked join buffers are used.
The problem is, the temp.table is not filled (actually not even opened
properly) yet, and this doesn't let us call
handler->multi_range_read_info(). It is possible to come up with
estimates, etc. without acessing the table, but it seems not to worth the
effort now.
*/
if
(
tab
->
table
->
pos_in_table_list
->
is_materialized_derived
())
no_bka_cache
=
true
;
/*
Don't use join buffering if we're dictated not to by no_jbuf_after
(This is not meaningfully used currently)
...
...
@@ -9729,7 +9742,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
if
(
tab
->
ref
.
is_access_triggered
())
goto
no_join_cache
;
if
(
!
tab
->
is_ref_for_hash_join
())
if
(
!
tab
->
is_ref_for_hash_join
()
&&
!
no_bka_cache
)
{
flags
=
HA_MRR_NO_NULL_ENDPOINTS
|
HA_MRR_SINGLE_POINT
;
if
(
tab
->
table
->
covering_keys
.
is_set
(
tab
->
ref
.
key
))
...
...
sql/table.cc
View file @
58b4f52a
...
...
@@ -5401,7 +5401,6 @@ void TABLE::create_key_part_by_field(KEY *keyinfo,
KEY_PART_INFO
*
key_part_info
,
Field
*
field
,
uint
fieldnr
)
{
field
->
flags
|=
PART_KEY_FLAG
;
key_part_info
->
null_bit
=
field
->
null_bit
;
key_part_info
->
null_offset
=
(
uint
)
(
field
->
null_ptr
-
(
uchar
*
)
record
[
0
]);
...
...
@@ -5552,6 +5551,7 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
(
*
reg_field
)
->
key_start
.
set_bit
(
key
);
(
*
reg_field
)
->
part_of_key
.
set_bit
(
key
);
create_key_part_by_field
(
keyinfo
,
key_part_info
,
*
reg_field
,
fld_idx
+
1
);
(
*
reg_field
)
->
flags
|=
PART_KEY_FLAG
;
key_start
=
FALSE
;
key_part_info
++
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment