From 2c9844a438c5f0bddcb037a1e05978118f48abb6 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sun, 19 May 2019 11:44:34 -0700 Subject: [PATCH 01/14] MDEV-18896 Crash in convert_join_subqueries_to_semijoins : Correction This patch complements the original patch for MDEV-18896 that prevents conversions to semi-joins in tableless selects used in INSERT statements in post-5.5 versions of the server. The test case was corrected as well to ensure that potential conversion to jtbm semi-joins is also checked (the problem was that one of the preceeding testcases in subselect_sj.test did not restore the state of the optimizer switch leaving the 'materialization' in the state 'off' and so blocking this check). Noticed an inconsistency in the state of select_lex::table_list used in INSERT statements and left a comment about this. --- mysql-test/r/subselect_sj.result | 1 + mysql-test/r/subselect_sj_jcl6.result | 1 + mysql-test/t/subselect_sj.test | 2 ++ sql/opt_subselect.cc | 2 +- sql/sql_parse.cc | 7 +++++++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index 73c620b2973..d0b8b626ba2 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -3181,6 +3181,7 @@ drop table t1,t2,t3; # # MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT # +set @@optimizer_switch= @subselect_sj_tmp; create table t1 (a1 varchar(25)); create table t2 (a2 varchar(25)) ; insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2); diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index 03cf368f32c..e9a8b7301f7 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -3195,6 +3195,7 @@ drop table t1,t2,t3; # # MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT # +set @@optimizer_switch= @subselect_sj_tmp; create table t1 (a1 varchar(25)); create table t2 (a2 varchar(25)) ; insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2); diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index aabb21b4245..6b59049bc4f 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2873,6 +2873,8 @@ drop table t1,t2,t3; --echo # MDEV-18896: IN subquery in WHERE of a table-less query used for INSERT --echo # +set @@optimizer_switch= @subselect_sj_tmp; + create table t1 (a1 varchar(25)); create table t2 (a2 varchar(25)) ; insert into t1 select 'xxx' from dual where 'xxx' in (select a2 from t2); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index fee68d33c33..a0e19af3d4e 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -525,7 +525,7 @@ bool is_materialization_applicable(THD *thd, Item_in_subselect *in_subs, parent_unit->first_select()->leaf_tables.elements && // 2 (thd->lex->sql_command == SQLCOM_SELECT || // * thd->lex->sql_command == SQLCOM_CREATE_TABLE) && // * - child_select->outer_select()->leaf_tables.elements && // 2A + child_select->outer_select()->table_list.first && // 2A subquery_types_allow_materialization(in_subs) && (in_subs->is_top_level_item() || //3 optimizer_flag(thd, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4ed2bcaed38..1d5733a646b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3034,6 +3034,13 @@ end_with_restore_list: */ /* Skip first table, which is the table we are inserting in */ TABLE_LIST *second_table= first_table->next_local; + /* + This is a hack: this leaves select_lex->table_list in an inconsistent + state as 'elements' does not contain number of elements in the list. + Moreover, if second_table == NULL then 'next' becomes invalid. + TODO: fix it by removing the front element (restoring of it should + be done properly as well) + */ select_lex->table_list.first= second_table; select_lex->context.table_list= select_lex->context.first_name_resolution_table= second_table; From 7b59ec6f345986db0cbc6f8b1d504a6e7e21cb5f Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 28 Nov 2018 13:25:43 +0300 Subject: [PATCH 02/14] MDEV-17799 Add ASAN-poisoned redzones for MEM_ROOT and mem_heap_t This patch is for MEM_ROOT only. In debug mode add 8 byte of poisoned memory before every allocated chunk. On the right of every chunk there will be either 1-7 trailing poisoned bytes, or next chunk's redzone, or poisoned non allocated memory or redzone of a malloc()ed buffer. --- include/my_valgrind.h | 7 +++++++ mysys/my_alloc.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/my_valgrind.h b/include/my_valgrind.h index 6df8f5a772e..14db2af2cb3 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -13,6 +13,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ +#ifndef _my_valgrind_h +#define _my_valgrind_h + /* clang -> gcc */ #ifndef __has_feature # define __has_feature(x) 0 @@ -49,9 +52,13 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ #endif /* HAVE_VALGRIND */ #ifndef DBUG_OFF +static const size_t REDZONE_SIZE= 8; #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #else +static const size_t REDZONE_SIZE= 0; #define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #endif #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) #define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0) + +#endif /* _my_valgrind_h */ diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 15b96e8a20a..9e5b6809dea 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -197,7 +197,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_SET("-d,simulate_out_of_memory"); DBUG_RETURN((void*) 0); /* purecov: inspected */ }); - length= ALIGN_SIZE(length); + length= ALIGN_SIZE(length) + REDZONE_SIZE; if ((*(prev= &mem_root->free)) != NULL) { if ((*prev)->left < length && @@ -242,6 +242,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) mem_root->used= next; mem_root->first_block_usage= 0; } + point+= REDZONE_SIZE; TRASH_ALLOC(point, original_length); DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point)); DBUG_RETURN((void*) point); From 5034b31b01b790ce1c28159402d754f7f951edc5 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 May 2019 18:23:10 +0200 Subject: [PATCH 03/14] MDEV-17799 Add ASAN-poisoned redzones for MEM_ROOT post-merge changes Closes #954 --- include/my_valgrind.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/my_valgrind.h b/include/my_valgrind.h index 14db2af2cb3..ad22f0cad40 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -13,8 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ -#ifndef _my_valgrind_h -#define _my_valgrind_h +#ifndef MY_VALGRIND_INCLUDED +#define MY_VALGRIND_INCLUDED /* clang -> gcc */ #ifndef __has_feature @@ -36,6 +36,7 @@ # define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len) # define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len) # define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len) +# define REDZONE_SIZE 8 #elif defined(__SANITIZE_ADDRESS__) # include /* How to do manual poisoning: @@ -44,21 +45,21 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ # define MEM_NOACCESS(a,len) ASAN_POISON_MEMORY_REGION(a,len) # define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) # define MEM_CHECK_DEFINED(a,len) ((void) 0) +# define REDZONE_SIZE 8 #else # define MEM_UNDEFINED(a,len) ((void) (a), (void) (len)) # define MEM_NOACCESS(a,len) ((void) 0) # define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) # define MEM_CHECK_DEFINED(a,len) ((void) 0) +# define REDZONE_SIZE 0 #endif /* HAVE_VALGRIND */ #ifndef DBUG_OFF -static const size_t REDZONE_SIZE= 8; #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #else -static const size_t REDZONE_SIZE= 0; #define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #endif #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) #define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0) -#endif /* _my_valgrind_h */ +#endif /* MY_VALGRIND_INCLUDED */ From aaa920dad359abd4b1b94330a0a942387a8814ad Mon Sep 17 00:00:00 2001 From: Ian Gilfillan Date: Tue, 21 May 2019 14:54:03 +0200 Subject: [PATCH 04/14] MDEV-19537: Document mysqlimport option ignore-foreign-keys --- man/mysqlimport.1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/man/mysqlimport.1 b/man/mysqlimport.1 index 0032edf8a8f..61d270d7057 100644 --- a/man/mysqlimport.1 +++ b/man/mysqlimport.1 @@ -1,6 +1,6 @@ '\" t .\" -.TH "\FBMYSQLIMPORT\FR" "1" "14/12/2015" "MariaDB 10\&.1" "MariaDB Database System" +.TH "\FBMYSQLIMPORT\FR" "1" "21 May 2019" "MariaDB 10\&.1" "MariaDB Database System" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -346,6 +346,22 @@ option\&. .sp -1 .IP \(bu 2.3 .\} +.\" mysqlimport: ignore-foreign-keys option +.\" ignore-foreign-keys option: mysqlimport +\fB\-\-ignore\-foreign\-keys\fR, +\fB\-k\fR +.sp +Disable foreign key checks while importing the data\&. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} .\" mysqlimport: ignore-lines option .\" ignore-lines option: mysqlimport \fB\-\-ignore\-lines=\fR\fB\fIN\fR\fR From 6dbc2ab8b36ca9b9255a9a4e3bae28e76522e5c8 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 20 May 2019 17:44:55 +0530 Subject: [PATCH 05/14] MDEV-17752: Plan changes from hash_index_merge to index_merge with new optimizer defaults The code in best_access_path function, when it does not find a key suitable for ref access and join_cache_level is set to a value so that hash_join is possible we build a hash key. Later in the function we compare the cost of ref access with table scan (or index scan or quick selects). No need to do this when we have got the hash key. --- mysql-test/r/join_cache.result | 31 +++++++++++++++++++++++++ mysql-test/r/join_nested_jcl6.result | 2 +- mysql-test/t/join_cache.test | 34 ++++++++++++++++++++++++++++ sql/sql_select.cc | 4 +++- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index 01339f7c191..cf23979b49a 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -2885,6 +2885,37 @@ Klaipeda Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Panevezys Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx set join_cache_level=default; set join_buffer_size=default; +# +# MDEV-17752: Plan changes from hash_index_merge to index_merge with new optimizer defaults +# +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_use_stat_tables=@@use_stat_tables; +set optimizer_use_condition_selectivity=4; +set use_stat_tables='preferably'; +use world; +set join_cache_level=4; +CREATE INDEX City_Name ON City(Name); +ANALYZE TABLE City, Country; +EXPLAIN +SELECT Country.Name, Country.Population, City.Name, City.Population +FROM Country LEFT JOIN City +ON City.Country=Country.Code AND City.Population > 5000000 +WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE Country range Name Name 302 NULL 15 Using index condition; Using where; Rowid-ordered scan +1 SIMPLE City hash_range Population,Country #hash#Country:Population 3:4 world.Country.Code 25 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +EXPLAIN +SELECT Country.Name, Country.Population, City.Name, City.Population +FROM Country LEFT JOIN City +ON City.Country=Country.Code AND +(City.Population > 5000000 OR City.Name LIKE 'Za%') +WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE Country range Name Name 302 NULL 15 Using index condition; Using where; Rowid-ordered scan +1 SIMPLE City hash_index_merge Population,Country,City_Name #hash#Country:Population,City_Name 3:4,35 world.Country.Code 96 Using sort_union(Population,City_Name); Using where; Using join buffer (flat, BNLH join) +set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set @@use_stat_tables=@save_use_stat_tables; +set join_cache_level=default; DROP DATABASE world; use test; CREATE TABLE t1( diff --git a/mysql-test/r/join_nested_jcl6.result b/mysql-test/r/join_nested_jcl6.result index bac8e1cb7db..51073bf0f1d 100644 --- a/mysql-test/r/join_nested_jcl6.result +++ b/mysql-test/r/join_nested_jcl6.result @@ -1342,7 +1342,7 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON c21=c31) ON c11=c21; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 1 SIMPLE t2 hash_ALL NULL #hash#$hj 5 test.t1.c11 0 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE t3 ALL NULL NULL NULL NULL 0 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t3 hash_ALL NULL #hash#$hj 5 test.t1.c11 0 Using where; Using join buffer (incremental, BNLH join) DROP TABLE t1,t2,t3; CREATE TABLE t1 (goods int(12) NOT NULL, price varchar(128) NOT NULL); INSERT INTO t1 VALUES (23, 2340), (26, 9900); diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 24dd637052c..48f129c676d 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -967,6 +967,40 @@ SELECT City.Name, Country.Name, Country.PopulationBar FROM City,Country set join_cache_level=default; set join_buffer_size=default; + +--echo # +--echo # MDEV-17752: Plan changes from hash_index_merge to index_merge with new optimizer defaults +--echo # + +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_use_stat_tables=@@use_stat_tables; +set optimizer_use_condition_selectivity=4; +set use_stat_tables='preferably'; + +use world; +set join_cache_level=4; +CREATE INDEX City_Name ON City(Name); + +--disable_result_log +ANALYZE TABLE City, Country; +--enable_result_log + +EXPLAIN +SELECT Country.Name, Country.Population, City.Name, City.Population + FROM Country LEFT JOIN City + ON City.Country=Country.Code AND City.Population > 5000000 + WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; + +EXPLAIN +SELECT Country.Name, Country.Population, City.Name, City.Population + FROM Country LEFT JOIN City + ON City.Country=Country.Code AND + (City.Population > 5000000 OR City.Name LIKE 'Za%') + WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set @@use_stat_tables=@save_use_stat_tables; +set join_cache_level=default; + DROP DATABASE world; use test; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c1bec0f1c20..7426540c8d7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6396,7 +6396,8 @@ best_access_path(JOIN *join, 'range' access using index IDX, and the best way to perform 'ref' access is to use the same index IDX, with the same or more key parts. (note: it is not clear how this rule is/should be extended to - index_merge quick selects) + index_merge quick selects). Also if we have a hash join we prefer that + over a table scan (3) See above note about InnoDB. (4) NOT ("FORCE INDEX(...)" is used for table and there is 'ref' access path, but there is no quick select) @@ -6412,6 +6413,7 @@ best_access_path(JOIN *join, be used for cases with small datasets, which is annoying. */ if ((records >= s->found_records || best > s->read_time) && // (1) + !(best_key && best_key->key == MAX_KEY) && // (2) !(s->quick && best_key && s->quick->index == best_key->key && // (2) best_max_key_part >= s->table->quick_key_parts[best_key->key]) &&// (2) !((s->table->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) && // (3) From 4584c186312a6e9b16271c5d863c76f939d4df53 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 22 May 2019 00:52:15 +0200 Subject: [PATCH 06/14] make CPACK_RPM_DEBUGINFO_PACKAGE configurable from the command-line --- cmake/cpack_rpm.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cpack_rpm.cmake b/cmake/cpack_rpm.cmake index 4e9410306a8..10afa56aec1 100644 --- a/cmake/cpack_rpm.cmake +++ b/cmake/cpack_rpm.cmake @@ -32,7 +32,7 @@ IF(CMAKE_VERSION VERSION_LESS "3.6.0") SET(CPACK_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${VERSION}-${RPM}-${CMAKE_SYSTEM_PROCESSOR}") ELSE() SET(CPACK_RPM_FILE_NAME "RPM-DEFAULT") - SET(CPACK_RPM_DEBUGINFO_PACKAGE ON) + SET(CPACK_RPM_DEBUGINFO_PACKAGE ON CACHE INTERNAL "") ENDIF() SET(CPACK_RPM_PACKAGE_RELEASE "1%{?dist}") From aad4e5637daf52c2b27a355e0c2f9038d940209d Mon Sep 17 00:00:00 2001 From: Robert Bindar Date: Wed, 22 May 2019 12:20:02 +0300 Subject: [PATCH 07/14] Stale files cause intermittent failure when ordering is unfortunate Running trigger_null-8605 drop_bad_db_type tests in this order was failing due to unremoved temporary files created in trigger_null-8605 --- mysql-test/t/trigger_null-8605.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mysql-test/t/trigger_null-8605.test b/mysql-test/t/trigger_null-8605.test index 34a57654b48..7645b61f5ad 100644 --- a/mysql-test/t/trigger_null-8605.test +++ b/mysql-test/t/trigger_null-8605.test @@ -149,6 +149,7 @@ EOF load data infile 'mdev8605.txt' into table t1 fields terminated by ','; select * from t1; drop table t1; +--remove_file $datadir/test/mdev8605.txt # timestamps (on NULL = NOW()) create table t1 (a timestamp, b int auto_increment primary key); @@ -218,6 +219,7 @@ load data infile 'sep8605.txt' into table t1 fields terminated by ',' (@a,a2,a3,b,c) set a1=100-@a; select 100-a1,a2,a3,b,c from t1; delete from t1; +--remove_file $datadir/test/sep8605.txt --write_file $datadir/test/fix8605.txt 00012010-11-12 01:02:030010000000000000000 @@ -231,6 +233,7 @@ set statement timestamp=777777777 for load data infile 'fix8605.txt' into table t1 fields terminated by ''; select * from t1; delete from t1; +--remove_file $datadir/test/fix8605.txt --write_file $datadir/test/xml8605.txt @@ -300,6 +303,7 @@ set statement timestamp=777777777 for load xml infile 'xml8605.txt' into table t1 rows identified by ''; select * from t1; drop table t1; +--remove_file $datadir/test/xml8605.txt # explicit DEFAULT create table t1 (a int not null default 5, b int, c int); From e57bb1f76cd0f8eac587a5fede01ba19bd54677a Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 14 May 2019 23:58:56 -0700 Subject: [PATCH 08/14] MDEV-19258 RIGHT JOIN hangs in MariaDB This patch corrects the patch for the bug 10006. The latter incorrectly calculates the attribute TABLE_LIST::dep_tables for inner tables of outer joins that are to be converted into inner joins. As a result after the patch some valid join orders were not evaluated and the optimizer could choose an execution plan that was far from being optimal. --- mysql-test/r/join_outer.result | 139 +++++++++++++++++++++++++++- mysql-test/r/join_outer_jcl6.result | 139 +++++++++++++++++++++++++++- mysql-test/t/join_outer.test | 127 ++++++++++++++++++++++++- sql/sql_select.cc | 16 +++- 4 files changed, 416 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 6bd12dbe1a6..3120a6df81e 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -2447,7 +2447,7 @@ t1.b1+'0' t2.b2 + '0' 0 0 1 1 DROP TABLE t1, t2; -set @join_cache_level= @save_join_cache_level; +set @@join_cache_level= @save_join_cache_level; # # MDEV-14779: using left join causes incorrect results with materialization and derived tables # @@ -2513,4 +2513,141 @@ ORDER BY tb1.i1; v2 DROP TABLE t1,t2; # end of 5.5 tests +# +# MDEV-19258: chained right joins all converted to inner joins +# +CREATE TABLE t1 ( +id int NOT NULL AUTO_INCREMENT, +timestamp bigint NOT NULL, +modifiedBy varchar(255) DEFAULT NULL, +PRIMARY KEY (id) +); +CREATE TABLE t2 ( +id int NOT NULL, +REV int NOT NULL, +REVTYPE tinyint DEFAULT NULL, +profile_id int DEFAULT NULL, +PRIMARY KEY (id,REV) +); +CREATE TABLE t3 ( +id int NOT NULL, +REV int NOT NULL, +person_id int DEFAULT NULL, +PRIMARY KEY (id,REV) +); +CREATE TABLE t4 ( +id int NOT NULL, +REV int NOT NULL, +PRIMARY KEY (id,REV) +); +INSERT INTO t1 VALUES +(1,1294391193890,'Cxqy$*9.kKeE'),(2,1294643906883,'rE4wqGV0gif@'), +(3,1294643927456,'L?3yt(%dY$Br'),(4,1294644343525,'WH&ObiZ$#2S4'), +(5,1294644616416,'YXnCbt?olUZ0'),(6,1294644954537,'8Npe4!(#lU@k'), +(7,1294645046659,'knc0GhXB1#ib'),(8,1294645183829,'w*oPpVfuS8^m'), +(9,1294645386701,'hwXR@3qVzrbU'),(10,1294645525982,'BeLW*Y9ndP0l'), +(11,1294645627723,'nTegib^)qZ$I'),(12,1294650860266,'u62C^Kzx3wH8'), +(13,1294657613745,'4&BkFjGa!qLg'),(14,1294660627161,')anpt312SCoh'), +(15,1294661023336,'LtJ2PX?*kTmx'),(16,1294662838066,'POGRr@?#ofpl'), +(17,1294663020989,'o.)1EOT2jnF7'),(18,1294663308065,'&TZ0F0LHE6.h'), +(19,1294664900039,'j)kSC%^In$9d'),(20,1294668904556,'97glN50)cAo.'), +(21,1294728056853,'lrKZxmw?I.Ek'),(22,1294728157174,'@P*SRg!pT.q?'), +(23,1294728327099,'W9gPrptF.)8n'),(24,1294728418481,'$q*c^sM&URd#'), +(25,1294728729620,'9*f4&bTPRtHo'),(26,1294728906014,')4VtTEnS7$oI'), +(27,1294732190003,'8dkNSPq2u3AQ'),(28,1294733205065,'SV2N6IoEf438'), +(29,1294741984927,'rBKj.0S^Ey%*'),(30,1294751748352,'j$2DvlBqk)Fw'), +(31,1294753902212,'C$N6OrEw8elz'),(32,1294758120598,'DCSVZw!rnxXq'), +(33,1294761769556,'OTS@QU8a6s5c'),(34,1294816845305,'IUE2stG0D3L5'), +(35,1294816966909,'Xd16yka.9nHe'),(36,1294817116302,'lOQHZpm%!8qb'), +(37,1294817374775,'^&pE3IhNf7ey'),(38,1294817538907,'oEn4#7C0Vhfp'), +(39,1294818482950,'bx54J*O0Va&?'),(40,1294819047024,'J%@a&1.qgdb?'), +(41,1294821826077,'C9kojr$L3Phz'),(42,1294825454458,'gG#BOnM80ZPi'), +(43,1294904129918,'F^!TrjM#zdvc'),(44,1294904254166,'Va&Tb)k0RvlM'), +(45,1294904414964,'dJjq0M6HvhR#'),(46,1294904505784,'nJmxg)ELqY(b'), +(47,1294904602835,'dhF#or$Vge!7'),(48,1294904684728,'?bIh5E3l!0em'), +(49,1294904877898,'Y*WflOdcxnk.'),(50,1294905002390,'*?H!lUgez5A.'), +(51,1294905096043,'wlEIY3n9uz!p'),(52,1294905404621,'T?qv3H6&hlQD'), +(53,1294905603922,'S@Bhys^Ti7bt'),(54,1294905788416,'KR?a5NVukz#l'), +(55,1294905993190,'A*&q4kWhED!o'),(56,1294906205254,'fT0%7z0DF6h*'), +(57,1294906319680,'LhzdW4?ivjR0'),(58,1294906424296,'h0KDlns%U*6T'), +(59,1294906623844,'b$CfB1noI6Ax'),(60,1294911258896,'#T1*LP!3$Oys'); +INSERT INTO t2 VALUES +(1,1,0,10209),(1,42480,1,10209),(1,61612,1,10209),(1,257545,1,10209), +(1,385332,1,10209),(1,1687999,1,10209),(3,1,0,10210),(3,617411,2,10210), +(4,11,0,14),(4,95149,1,10211),(4,607890,2,10211),(5,1,0,10212), +(6,1,0,10213),(6,93344,1,10213),(6,295578,1,10213),(6,295579,1,10213), +(6,295644,1,10213),(7,1,0,10214),(7,12,1,7),(7,688796,1,10214), +(7,1140433,1,10214),(7,1715227,1,10214),(8,1,0,10215),(8,74253,1,10215), +(8,93345,1,10215),(8,12,2,2),(9,1,0,10216),(9,93342,1,10216), +(9,122354,1,10216),(9,301499,2,10216),(10,11,0,5),(10,93343,1,10217), +(10,122355,1,10217),(10,123050,1,10217),(10,301500,2,10217),(11,1,0,10218), +(11,87852,1,10218),(11,605499,2,10218),(12,1,0,10219),(12,88024,1,10219), +(12,605892,2,10219),(13,1,0,10220); +INSERT INTO t3 VALUES +(1,1,300003),(1,117548,NULL),(2,1,300003),(2,117548,300006), +(3,1,300153),(3,117548,NULL),(4,1,300153),(4,117548,NULL), +(5,1,300153),(5,117548,NULL),(6,1,300182),(6,117548,NULL), +(7,1,300205),(7,117548,NULL),(8,1,300217),(8,117548,NULL), +(9,1,300290),(9,117548,NULL),(10,1,300290),(10,117548,NULL), +(11,1,300405),(11,117548,NULL),(12,1,300670),(12,117548,NULL), +(13,1,300670),(13,117548,NULL),(14,1,300006),(14,117548,NULL), +(15,1,300671),(15,117548,NULL),(16,1,300732),(16,117548,NULL); +INSERT INTO t4 VALUES +(300000,1),(300001,1),(300003,1),(300004,1), +(300005,1),(300005,688796),(300006,1),(300006,97697), +(300009,1),(300010,1),(300011,1),(300012,1),(300013,1), +(300014,1),(300015,1),(300016,1),(300017,1),(300018,1), +(300019,1),(300020,1),(300021,1),(300022,1),(300023,1), +(300024,1),(300025,1),(300026,1),(300027,1),(300028,1); +# This should have join order of t2,t3,t4,t1 +EXPLAIN EXTENDED SELECT * +FROM t1 INNER JOIN t2 ON t2.REV=t1.id +INNER JOIN t3 ON t3.id=t2.profile_id +INNER JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND +t2.REVTYPE=2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where +1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where +1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416)) +SELECT * +FROM t1 INNER JOIN t2 ON t2.REV=t1.id +INNER JOIN t3 ON t3.id=t2.profile_id +INNER JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND +t2.REVTYPE=2; +id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 +# This should have join order of t2,t3,t4,t1 with the same plan as above +# because all RIGHT JOIN operations are converted into INNER JOIN +EXPLAIN EXTENDED SELECT * +FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id +RIGHT JOIN t3 ON t3.id=t2.profile_id +RIGHT JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 +AND t2.REVTYPE=2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where +1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where +1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t4` join `test`.`t3` join `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416)) +SELECT * +FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id +RIGHT JOIN t3 ON t3.id=t2.profile_id +RIGHT JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 +AND t2.REVTYPE=2; +id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 +DROP TABLE t1,t2,t3,t4; +# end of 10.1 tests SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index faad87468c5..44250a96c05 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -2458,7 +2458,7 @@ t1.b1+'0' t2.b2 + '0' 0 0 1 1 DROP TABLE t1, t2; -set @join_cache_level= @save_join_cache_level; +set @@join_cache_level= @save_join_cache_level; # # MDEV-14779: using left join causes incorrect results with materialization and derived tables # @@ -2524,6 +2524,143 @@ ORDER BY tb1.i1; v2 DROP TABLE t1,t2; # end of 5.5 tests +# +# MDEV-19258: chained right joins all converted to inner joins +# +CREATE TABLE t1 ( +id int NOT NULL AUTO_INCREMENT, +timestamp bigint NOT NULL, +modifiedBy varchar(255) DEFAULT NULL, +PRIMARY KEY (id) +); +CREATE TABLE t2 ( +id int NOT NULL, +REV int NOT NULL, +REVTYPE tinyint DEFAULT NULL, +profile_id int DEFAULT NULL, +PRIMARY KEY (id,REV) +); +CREATE TABLE t3 ( +id int NOT NULL, +REV int NOT NULL, +person_id int DEFAULT NULL, +PRIMARY KEY (id,REV) +); +CREATE TABLE t4 ( +id int NOT NULL, +REV int NOT NULL, +PRIMARY KEY (id,REV) +); +INSERT INTO t1 VALUES +(1,1294391193890,'Cxqy$*9.kKeE'),(2,1294643906883,'rE4wqGV0gif@'), +(3,1294643927456,'L?3yt(%dY$Br'),(4,1294644343525,'WH&ObiZ$#2S4'), +(5,1294644616416,'YXnCbt?olUZ0'),(6,1294644954537,'8Npe4!(#lU@k'), +(7,1294645046659,'knc0GhXB1#ib'),(8,1294645183829,'w*oPpVfuS8^m'), +(9,1294645386701,'hwXR@3qVzrbU'),(10,1294645525982,'BeLW*Y9ndP0l'), +(11,1294645627723,'nTegib^)qZ$I'),(12,1294650860266,'u62C^Kzx3wH8'), +(13,1294657613745,'4&BkFjGa!qLg'),(14,1294660627161,')anpt312SCoh'), +(15,1294661023336,'LtJ2PX?*kTmx'),(16,1294662838066,'POGRr@?#ofpl'), +(17,1294663020989,'o.)1EOT2jnF7'),(18,1294663308065,'&TZ0F0LHE6.h'), +(19,1294664900039,'j)kSC%^In$9d'),(20,1294668904556,'97glN50)cAo.'), +(21,1294728056853,'lrKZxmw?I.Ek'),(22,1294728157174,'@P*SRg!pT.q?'), +(23,1294728327099,'W9gPrptF.)8n'),(24,1294728418481,'$q*c^sM&URd#'), +(25,1294728729620,'9*f4&bTPRtHo'),(26,1294728906014,')4VtTEnS7$oI'), +(27,1294732190003,'8dkNSPq2u3AQ'),(28,1294733205065,'SV2N6IoEf438'), +(29,1294741984927,'rBKj.0S^Ey%*'),(30,1294751748352,'j$2DvlBqk)Fw'), +(31,1294753902212,'C$N6OrEw8elz'),(32,1294758120598,'DCSVZw!rnxXq'), +(33,1294761769556,'OTS@QU8a6s5c'),(34,1294816845305,'IUE2stG0D3L5'), +(35,1294816966909,'Xd16yka.9nHe'),(36,1294817116302,'lOQHZpm%!8qb'), +(37,1294817374775,'^&pE3IhNf7ey'),(38,1294817538907,'oEn4#7C0Vhfp'), +(39,1294818482950,'bx54J*O0Va&?'),(40,1294819047024,'J%@a&1.qgdb?'), +(41,1294821826077,'C9kojr$L3Phz'),(42,1294825454458,'gG#BOnM80ZPi'), +(43,1294904129918,'F^!TrjM#zdvc'),(44,1294904254166,'Va&Tb)k0RvlM'), +(45,1294904414964,'dJjq0M6HvhR#'),(46,1294904505784,'nJmxg)ELqY(b'), +(47,1294904602835,'dhF#or$Vge!7'),(48,1294904684728,'?bIh5E3l!0em'), +(49,1294904877898,'Y*WflOdcxnk.'),(50,1294905002390,'*?H!lUgez5A.'), +(51,1294905096043,'wlEIY3n9uz!p'),(52,1294905404621,'T?qv3H6&hlQD'), +(53,1294905603922,'S@Bhys^Ti7bt'),(54,1294905788416,'KR?a5NVukz#l'), +(55,1294905993190,'A*&q4kWhED!o'),(56,1294906205254,'fT0%7z0DF6h*'), +(57,1294906319680,'LhzdW4?ivjR0'),(58,1294906424296,'h0KDlns%U*6T'), +(59,1294906623844,'b$CfB1noI6Ax'),(60,1294911258896,'#T1*LP!3$Oys'); +INSERT INTO t2 VALUES +(1,1,0,10209),(1,42480,1,10209),(1,61612,1,10209),(1,257545,1,10209), +(1,385332,1,10209),(1,1687999,1,10209),(3,1,0,10210),(3,617411,2,10210), +(4,11,0,14),(4,95149,1,10211),(4,607890,2,10211),(5,1,0,10212), +(6,1,0,10213),(6,93344,1,10213),(6,295578,1,10213),(6,295579,1,10213), +(6,295644,1,10213),(7,1,0,10214),(7,12,1,7),(7,688796,1,10214), +(7,1140433,1,10214),(7,1715227,1,10214),(8,1,0,10215),(8,74253,1,10215), +(8,93345,1,10215),(8,12,2,2),(9,1,0,10216),(9,93342,1,10216), +(9,122354,1,10216),(9,301499,2,10216),(10,11,0,5),(10,93343,1,10217), +(10,122355,1,10217),(10,123050,1,10217),(10,301500,2,10217),(11,1,0,10218), +(11,87852,1,10218),(11,605499,2,10218),(12,1,0,10219),(12,88024,1,10219), +(12,605892,2,10219),(13,1,0,10220); +INSERT INTO t3 VALUES +(1,1,300003),(1,117548,NULL),(2,1,300003),(2,117548,300006), +(3,1,300153),(3,117548,NULL),(4,1,300153),(4,117548,NULL), +(5,1,300153),(5,117548,NULL),(6,1,300182),(6,117548,NULL), +(7,1,300205),(7,117548,NULL),(8,1,300217),(8,117548,NULL), +(9,1,300290),(9,117548,NULL),(10,1,300290),(10,117548,NULL), +(11,1,300405),(11,117548,NULL),(12,1,300670),(12,117548,NULL), +(13,1,300670),(13,117548,NULL),(14,1,300006),(14,117548,NULL), +(15,1,300671),(15,117548,NULL),(16,1,300732),(16,117548,NULL); +INSERT INTO t4 VALUES +(300000,1),(300001,1),(300003,1),(300004,1), +(300005,1),(300005,688796),(300006,1),(300006,97697), +(300009,1),(300010,1),(300011,1),(300012,1),(300013,1), +(300014,1),(300015,1),(300016,1),(300017,1),(300018,1), +(300019,1),(300020,1),(300021,1),(300022,1),(300023,1), +(300024,1),(300025,1),(300026,1),(300027,1),(300028,1); +# This should have join order of t2,t3,t4,t1 +EXPLAIN EXTENDED SELECT * +FROM t1 INNER JOIN t2 ON t2.REV=t1.id +INNER JOIN t3 ON t3.id=t2.profile_id +INNER JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND +t2.REVTYPE=2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where +1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where +1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416)) +SELECT * +FROM t1 INNER JOIN t2 ON t2.REV=t1.id +INNER JOIN t3 ON t3.id=t2.profile_id +INNER JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND +t2.REVTYPE=2; +id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 +# This should have join order of t2,t3,t4,t1 with the same plan as above +# because all RIGHT JOIN operations are converted into INNER JOIN +EXPLAIN EXTENDED SELECT * +FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id +RIGHT JOIN t3 ON t3.id=t2.profile_id +RIGHT JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 +AND t2.REVTYPE=2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where +1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where +1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t4` join `test`.`t3` join `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416)) +SELECT * +FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id +RIGHT JOIN t3 ON t3.id=t2.profile_id +RIGHT JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 +AND t2.REVTYPE=2; +id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1 +12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 +DROP TABLE t1,t2,t3,t4; +# end of 10.1 tests SET optimizer_switch=@save_optimizer_switch; set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 6d20c089bd9..19cc5b8049a 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -1976,7 +1976,7 @@ set @save_join_cache_level= @@join_cache_level; SET @@join_cache_level = 3; SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2; DROP TABLE t1, t2; -set @join_cache_level= @save_join_cache_level; +set @@join_cache_level= @save_join_cache_level; --echo # --echo # MDEV-14779: using left join causes incorrect results with materialization and derived tables @@ -2042,4 +2042,129 @@ DROP TABLE t1,t2; --echo # end of 5.5 tests +--echo # +--echo # MDEV-19258: chained right joins all converted to inner joins +--echo # + + CREATE TABLE t1 ( + id int NOT NULL AUTO_INCREMENT, + timestamp bigint NOT NULL, + modifiedBy varchar(255) DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE t2 ( + id int NOT NULL, + REV int NOT NULL, + REVTYPE tinyint DEFAULT NULL, + profile_id int DEFAULT NULL, + PRIMARY KEY (id,REV) +); + +CREATE TABLE t3 ( + id int NOT NULL, + REV int NOT NULL, + person_id int DEFAULT NULL, + PRIMARY KEY (id,REV) +); + +CREATE TABLE t4 ( + id int NOT NULL, + REV int NOT NULL, + PRIMARY KEY (id,REV) +); + +INSERT INTO t1 VALUES +(1,1294391193890,'Cxqy$*9.kKeE'),(2,1294643906883,'rE4wqGV0gif@'), +(3,1294643927456,'L?3yt(%dY$Br'),(4,1294644343525,'WH&ObiZ$#2S4'), +(5,1294644616416,'YXnCbt?olUZ0'),(6,1294644954537,'8Npe4!(#lU@k'), +(7,1294645046659,'knc0GhXB1#ib'),(8,1294645183829,'w*oPpVfuS8^m'), +(9,1294645386701,'hwXR@3qVzrbU'),(10,1294645525982,'BeLW*Y9ndP0l'), +(11,1294645627723,'nTegib^)qZ$I'),(12,1294650860266,'u62C^Kzx3wH8'), +(13,1294657613745,'4&BkFjGa!qLg'),(14,1294660627161,')anpt312SCoh'), +(15,1294661023336,'LtJ2PX?*kTmx'),(16,1294662838066,'POGRr@?#ofpl'), +(17,1294663020989,'o.)1EOT2jnF7'),(18,1294663308065,'&TZ0F0LHE6.h'), +(19,1294664900039,'j)kSC%^In$9d'),(20,1294668904556,'97glN50)cAo.'), +(21,1294728056853,'lrKZxmw?I.Ek'),(22,1294728157174,'@P*SRg!pT.q?'), +(23,1294728327099,'W9gPrptF.)8n'),(24,1294728418481,'$q*c^sM&URd#'), +(25,1294728729620,'9*f4&bTPRtHo'),(26,1294728906014,')4VtTEnS7$oI'), +(27,1294732190003,'8dkNSPq2u3AQ'),(28,1294733205065,'SV2N6IoEf438'), +(29,1294741984927,'rBKj.0S^Ey%*'),(30,1294751748352,'j$2DvlBqk)Fw'), +(31,1294753902212,'C$N6OrEw8elz'),(32,1294758120598,'DCSVZw!rnxXq'), +(33,1294761769556,'OTS@QU8a6s5c'),(34,1294816845305,'IUE2stG0D3L5'), +(35,1294816966909,'Xd16yka.9nHe'),(36,1294817116302,'lOQHZpm%!8qb'), +(37,1294817374775,'^&pE3IhNf7ey'),(38,1294817538907,'oEn4#7C0Vhfp'), +(39,1294818482950,'bx54J*O0Va&?'),(40,1294819047024,'J%@a&1.qgdb?'), +(41,1294821826077,'C9kojr$L3Phz'),(42,1294825454458,'gG#BOnM80ZPi'), +(43,1294904129918,'F^!TrjM#zdvc'),(44,1294904254166,'Va&Tb)k0RvlM'), +(45,1294904414964,'dJjq0M6HvhR#'),(46,1294904505784,'nJmxg)ELqY(b'), +(47,1294904602835,'dhF#or$Vge!7'),(48,1294904684728,'?bIh5E3l!0em'), +(49,1294904877898,'Y*WflOdcxnk.'),(50,1294905002390,'*?H!lUgez5A.'), +(51,1294905096043,'wlEIY3n9uz!p'),(52,1294905404621,'T?qv3H6&hlQD'), +(53,1294905603922,'S@Bhys^Ti7bt'),(54,1294905788416,'KR?a5NVukz#l'), +(55,1294905993190,'A*&q4kWhED!o'),(56,1294906205254,'fT0%7z0DF6h*'), +(57,1294906319680,'LhzdW4?ivjR0'),(58,1294906424296,'h0KDlns%U*6T'), +(59,1294906623844,'b$CfB1noI6Ax'),(60,1294911258896,'#T1*LP!3$Oys'); + + +INSERT INTO t2 VALUES +(1,1,0,10209),(1,42480,1,10209),(1,61612,1,10209),(1,257545,1,10209), +(1,385332,1,10209),(1,1687999,1,10209),(3,1,0,10210),(3,617411,2,10210), +(4,11,0,14),(4,95149,1,10211),(4,607890,2,10211),(5,1,0,10212), +(6,1,0,10213),(6,93344,1,10213),(6,295578,1,10213),(6,295579,1,10213), +(6,295644,1,10213),(7,1,0,10214),(7,12,1,7),(7,688796,1,10214), +(7,1140433,1,10214),(7,1715227,1,10214),(8,1,0,10215),(8,74253,1,10215), +(8,93345,1,10215),(8,12,2,2),(9,1,0,10216),(9,93342,1,10216), +(9,122354,1,10216),(9,301499,2,10216),(10,11,0,5),(10,93343,1,10217), +(10,122355,1,10217),(10,123050,1,10217),(10,301500,2,10217),(11,1,0,10218), +(11,87852,1,10218),(11,605499,2,10218),(12,1,0,10219),(12,88024,1,10219), +(12,605892,2,10219),(13,1,0,10220); + +INSERT INTO t3 VALUES +(1,1,300003),(1,117548,NULL),(2,1,300003),(2,117548,300006), +(3,1,300153),(3,117548,NULL),(4,1,300153),(4,117548,NULL), +(5,1,300153),(5,117548,NULL),(6,1,300182),(6,117548,NULL), +(7,1,300205),(7,117548,NULL),(8,1,300217),(8,117548,NULL), +(9,1,300290),(9,117548,NULL),(10,1,300290),(10,117548,NULL), +(11,1,300405),(11,117548,NULL),(12,1,300670),(12,117548,NULL), +(13,1,300670),(13,117548,NULL),(14,1,300006),(14,117548,NULL), +(15,1,300671),(15,117548,NULL),(16,1,300732),(16,117548,NULL); + +INSERT INTO t4 VALUES +(300000,1),(300001,1),(300003,1),(300004,1), +(300005,1),(300005,688796),(300006,1),(300006,97697), +(300009,1),(300010,1),(300011,1),(300012,1),(300013,1), +(300014,1),(300015,1),(300016,1),(300017,1),(300018,1), +(300019,1),(300020,1),(300021,1),(300022,1),(300023,1), +(300024,1),(300025,1),(300026,1),(300027,1),(300028,1); + +let $q1= +SELECT * +FROM t1 INNER JOIN t2 ON t2.REV=t1.id + INNER JOIN t3 ON t3.id=t2.profile_id + INNER JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND + t2.REVTYPE=2; + +--echo # This should have join order of t2,t3,t4,t1 +eval EXPLAIN EXTENDED $q1; +eval $q1; + +let $q2= +SELECT * +FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id + RIGHT JOIN t3 ON t3.id=t2.profile_id + RIGHT JOIN t4 ON t4.id=t3.person_id +WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 + AND t2.REVTYPE=2; + +--echo # This should have join order of t2,t3,t4,t1 with the same plan as above +--echo # because all RIGHT JOIN operations are converted into INNER JOIN +eval EXPLAIN EXTENDED $q2; +eval $q2; + +DROP TABLE t1,t2,t3,t4; + +--echo # end of 10.1 tests + SET optimizer_switch=@save_optimizer_switch; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7426540c8d7..02f1623a878 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14635,8 +14635,20 @@ simplify_joins(JOIN *join, List *join_list, COND *conds, bool top, table->table->maybe_null= FALSE; table->outer_join= 0; if (!(straight_join || table->straight)) - table->dep_tables= table->embedding && !table->embedding->sj_subq_pred ? - table->embedding->dep_tables : 0; + { + table->dep_tables= 0; + TABLE_LIST *embedding= table->embedding; + while (embedding) + { + if (embedding->nested_join->join_list.head()->outer_join) + { + if (!embedding->sj_subq_pred) + table->dep_tables= embedding->dep_tables; + break; + } + embedding= embedding->embedding; + } + } if (table->on_expr) { /* Add ON expression to the WHERE or upper-level ON condition. */ From aaf53ea0b68efde4a90cabbbcaf9ca41c1fbf62f Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 23 May 2019 21:12:14 +0300 Subject: [PATCH 09/14] MDEV-17948 Assertion `thd_killed(thd) || !m_active_tranxs .. Simulation of a big-sized event in rpl.rpl_semi_sync_skip_repl did not clean up after itself so screw the last binlog event offset which could jump backwards. The test is refined to rotate a binlog file with simulation and use the next one for logics of the test incl master-slave synchonization. --- .../rpl/r/rpl_semi_sync_skip_repl.result | 13 +++++---- .../suite/rpl/t/rpl_semi_sync_skip_repl.test | 29 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_skip_repl.result b/mysql-test/suite/rpl/r/rpl_semi_sync_skip_repl.result index 4762ac8dd07..272263bc288 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_skip_repl.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_skip_repl.result @@ -5,19 +5,22 @@ SET @@GLOBAL.rpl_semi_sync_master_enabled = 1; SET @@GLOBAL.rpl_semi_sync_master_timeout=100; include/stop_slave.inc SET @@GLOBAL.replicate_events_marked_for_skip=FILTER_ON_MASTER; -SET @@GLOBAL. rpl_semi_sync_slave_enabled = 1; +SET @@GLOBAL.rpl_semi_sync_slave_enabled = 1; include/start_slave.inc CREATE TABLE t1 (a INT) ENGINE=innodb; -SET @@GLOBAL.debug_dbug= "d,dbug_master_binlog_over_2GB"; +SET @@GLOBAL.debug_dbug="d,dbug_master_binlog_over_2GB"; SET @@SESSION.skip_replication=1; INSERT INTO t1 SET a=1; SET @@SESSION.skip_replication=0; INSERT INTO t1 SET a=0; SET @@GLOBAL.debug_dbug=""; -SET @@GLOBAL. rpl_semi_sync_master_timeout = 10000; -SET @@GLOBAL. rpl_semi_sync_master_enabled = 0; +FLUSH LOGS; +SET @@GLOBAL.debug_dbug=@@GLOBAL.debug_dbug; +SET @@GLOBAL.rpl_semi_sync_master_timeout = 10000; +SET @@GLOBAL.rpl_semi_sync_master_enabled = 0; DROP TABLE t1; include/stop_slave.inc -SET @@GLOBAL. rpl_semi_sync_slave_enabled = 0; +SET @@GLOBAL.rpl_semi_sync_slave_enabled = 0; SET @@GLOBAL.replicate_events_marked_for_skip = REPLICATE; +include/start_slave.inc include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_skip_repl.test b/mysql-test/suite/rpl/t/rpl_semi_sync_skip_repl.test index 2f6da18067c..8c00bae06cd 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_skip_repl.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_skip_repl.test @@ -16,29 +16,34 @@ source include/master-slave.inc; # Suppress warnings that might be generated during the test call mtr.add_suppression("Timeout waiting for reply of binlog"); ---let $sav_enabled_master=`SELECT @@GLOBAL.rpl_semi_sync_master_enabled ` ---let $sav_timeout_master=`SELECT @@GLOBAL.rpl_semi_sync_master_timeout ` +--let $sav_enabled_master=`SELECT @@GLOBAL.rpl_semi_sync_master_enabled` +--let $sav_timeout_master=`SELECT @@GLOBAL.rpl_semi_sync_master_timeout` SET @@GLOBAL.rpl_semi_sync_master_enabled = 1; SET @@GLOBAL.rpl_semi_sync_master_timeout=100; --connection slave +--let $sav_skip_marked_slave=`SELECT @@GLOBAL.replicate_events_marked_for_skip` +--let $sav_enabled_slave=`SELECT @@GLOBAL.rpl_semi_sync_slave_enabled` source include/stop_slave.inc; ---let $sav_skip_marked_slave=`SELECT @@GLOBAL.replicate_events_marked_for_skip ` SET @@GLOBAL.replicate_events_marked_for_skip=FILTER_ON_MASTER; ---let $sav_enabled_slave=`SELECT @@GLOBAL.rpl_semi_sync_slave_enabled ` -SET @@GLOBAL. rpl_semi_sync_slave_enabled = 1; - +SET @@GLOBAL.rpl_semi_sync_slave_enabled = 1; source include/start_slave.inc; --connection master CREATE TABLE t1 (a INT) ENGINE=innodb; # Make the following events as if they offset over 2GB from the beginning of binlog -SET @@GLOBAL.debug_dbug= "d,dbug_master_binlog_over_2GB"; +--let $sav_debug_dbug=@@GLOBAL.debug_dbug +SET @@GLOBAL.debug_dbug="d,dbug_master_binlog_over_2GB"; SET @@SESSION.skip_replication=1; INSERT INTO t1 SET a=1; SET @@SESSION.skip_replication=0; INSERT INTO t1 SET a=0; +SET @@GLOBAL.debug_dbug=""; + +# The current binlog is inconsistent so let's rotate it away +# to clean up simulation results. +FLUSH LOGS; --sync_slave_with_master @@ -46,17 +51,17 @@ INSERT INTO t1 SET a=0; # Clean up # --connection master -SET @@GLOBAL.debug_dbug=""; ---eval SET @@GLOBAL. rpl_semi_sync_master_timeout = $sav_timeout_master ---eval SET @@GLOBAL. rpl_semi_sync_master_enabled = $sav_enabled_master +--eval SET @@GLOBAL.debug_dbug=$sav_debug_dbug +--eval SET @@GLOBAL.rpl_semi_sync_master_timeout = $sav_timeout_master +--eval SET @@GLOBAL.rpl_semi_sync_master_enabled = $sav_enabled_master --connection master DROP TABLE t1; --sync_slave_with_master source include/stop_slave.inc; ---eval SET @@GLOBAL. rpl_semi_sync_slave_enabled = $sav_enabled_slave +--eval SET @@GLOBAL.rpl_semi_sync_slave_enabled = $sav_enabled_slave --eval SET @@GLOBAL.replicate_events_marked_for_skip = $sav_skip_marked_slave ---let $rpl_only_running_threads= 1 +source include/start_slave.inc; --source include/rpl_end.inc From 0955462d0aafab01def9c1a5ec131eb641cb9e68 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 27 May 2019 19:08:00 -0700 Subject: [PATCH 10/14] MDEV-18479 Assertion `join->best_read < double(1.79769313486231570815e+308L)' or server crashes in JOIN::fix_all_splittings_in_plan after EXPLAIN This patch resolves the problem of overflowing when performing calculations to estimate the cost of an evaluated query execution plan. The overflowing in a non-debug build could cause different kind of problems uncluding crashes of the server. --- mysql-test/r/derived_view.result | 401 +++++++++++++++++++++++++++++++ mysql-test/t/derived_view.test | 260 ++++++++++++++++++++ sql/opt_subselect.cc | 69 +++--- sql/sql_const.h | 8 + sql/sql_select.cc | 113 +++++---- 5 files changed, 772 insertions(+), 79 deletions(-) diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 12811ebc6b3..ab363934e8f 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -2640,3 +2640,404 @@ Note 1003 select straight_join `test`.`t1`.`c1` AS `c1` from `test`.`t1` where < DROP TABLE t1, t2; set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; +# +# Bug mdev-12812: EXPLAIN for query with many expensive derived +# +CREATE TABLE t1 +(id int auto_increment primary key, +uid int NOT NULL, +gp_id int NOT NULL, +r int NOT NULL +); +INSERT INTO t1(uid,gp_id,r) VALUES +(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),(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),(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),(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),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1); +CREATE TABLE t2 (id int) ; +INSERT INTO t2 VALUES (1); +explain SELECT 1 FROM t2 JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_1 ON gp_1.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_2 ON gp_2.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id +JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_3 ON gp_3.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id +JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_4 ON gp_4.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id +JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_5 ON gp_5.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id +JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_6 ON gp_6.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id +JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +WHERE p1.gp_id=7) gp_7 ON gp_7.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_8 ON gp_8.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_9 ON gp_9.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_14 ON gp_14.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_15 ON gp_15.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +) gp_16 ON gp_16.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +)gp_17 ON gp_17.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +)gp_18 ON gp_18.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id +JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id +)gp_19 ON gp_19.id=t2.id +JOIN +(SELECT t2.id +FROM t2 +JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id +JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id +JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id +JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id +JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id +) gp_20 ON gp_20.id=t2.id ; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE p4 ALL NULL NULL NULL NULL 550 Using where +1 SIMPLE p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +1 SIMPLE p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p1 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p3 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p1 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p3 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p1 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p3 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL 50328437500000 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL 27680640625000000 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL 7798774269472204288 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL 7798774269472204288 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE ALL NULL NULL NULL NULL -3222391729959551616 Using where; Using join buffer (incremental, BNL join) +17 DERIVED t2 system NULL NULL NULL NULL 1 +17 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +17 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +17 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +17 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +17 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +16 DERIVED t2 system NULL NULL NULL NULL 1 +16 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +16 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +16 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +16 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +16 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +16 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +16 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +15 DERIVED t2 system NULL NULL NULL NULL 1 +15 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +15 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +15 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +15 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +15 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +15 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +15 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +14 DERIVED t2 system NULL NULL NULL NULL 1 +14 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +14 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +14 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +14 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +14 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +14 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +13 DERIVED t2 system NULL NULL NULL NULL 1 +13 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +13 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +13 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +13 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +13 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +13 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +13 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +12 DERIVED t2 system NULL NULL NULL NULL 1 +12 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +12 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +12 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +12 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +12 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +12 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +12 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +11 DERIVED t2 system NULL NULL NULL NULL 1 +11 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +11 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +11 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +11 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +11 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +11 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +11 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +10 DERIVED t2 system NULL NULL NULL NULL 1 +10 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +10 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +10 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +10 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +10 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +10 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +10 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +9 DERIVED t2 system NULL NULL NULL NULL 1 +9 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where +9 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +9 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +9 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +9 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +9 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +9 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED t2 system NULL NULL NULL NULL 1 +8 DERIVED p1 ALL NULL NULL NULL NULL 550 Using where +8 DERIVED p3 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +8 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +8 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED t2 system NULL NULL NULL NULL 1 +7 DERIVED p1 ALL NULL NULL NULL NULL 550 Using where +7 DERIVED p3 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (flat, BNL join) +7 DERIVED p4 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p5 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p6 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p7 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p8 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p9 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +7 DERIVED p10 ALL NULL NULL NULL NULL 550 Using where; Using join buffer (incremental, BNL join) +DROP TABLE t1, t2; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index 07fbe4980a5..f6613e2593a 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1934,3 +1934,263 @@ DROP TABLE t1, t2; # The following command must be the last one the file set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; + +--echo # +--echo # Bug mdev-12812: EXPLAIN for query with many expensive derived +--echo # + +CREATE TABLE t1 +(id int auto_increment primary key, + uid int NOT NULL, + gp_id int NOT NULL, + r int NOT NULL +); + +INSERT INTO t1(uid,gp_id,r) VALUES +(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),(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),(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),(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),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1),(1,2,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1),(1,3,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1),(1,4,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1),(1,5,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1),(1,6,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1),(1,7,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1),(1,8,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1),(1,9,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1), +(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,10,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1),(1,11,1), +(1,11,1); + +CREATE TABLE t2 (id int) ; +INSERT INTO t2 VALUES (1); + +explain SELECT 1 FROM t2 JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_1 ON gp_1.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_2 ON gp_2.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id + JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_3 ON gp_3.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id + JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_4 ON gp_4.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id + JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_5 ON gp_5.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id + JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_6 ON gp_6.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p1 ON p1.r=1 AND p1.uid=t2.id + JOIN t1 p3 ON p3.r=3 AND p3.uid=t2.id + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + WHERE p1.gp_id=7) gp_7 ON gp_7.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_8 ON gp_8.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_9 ON gp_9.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_14 ON gp_14.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_15 ON gp_15.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + ) gp_16 ON gp_16.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + )gp_17 ON gp_17.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + )gp_18 ON gp_18.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + JOIN t1 p9 ON p9.r=9 AND p9.uid=t2.id + JOIN t1 p10 ON p10.r=10 AND p10.uid=t2.id + )gp_19 ON gp_19.id=t2.id +JOIN +(SELECT t2.id + FROM t2 + JOIN t1 p4 ON p4.r=4 AND p4.uid=t2.id + JOIN t1 p5 ON p5.r=5 AND p5.uid=t2.id + JOIN t1 p6 ON p6.r=6 AND p6.uid=t2.id + JOIN t1 p7 ON p7.r=7 AND p7.uid=t2.id + JOIN t1 p8 ON p8.r=8 AND p8.uid=t2.id + ) gp_20 ON gp_20.id=t2.id ; + +DROP TABLE t1, t2; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index a0e19af3d4e..cb821325e57 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -27,6 +27,7 @@ #endif #include "sql_base.h" +#include "sql_const.h" #include "sql_select.h" #include "filesort.h" #include "opt_subselect.h" @@ -1380,8 +1381,8 @@ void get_delayed_table_estimates(TABLE *table, *startup_cost= item->jtbm_read_time; /* Calculate cost of scanning the temptable */ - double data_size= item->jtbm_record_count * - hash_sj_engine->tmp_table->s->reclength; + double data_size= COST_MULT(item->jtbm_record_count, + hash_sj_engine->tmp_table->s->reclength); /* Do like in handler::read_time */ *scan_time= data_size/IO_SIZE + 2; } @@ -2451,7 +2452,8 @@ bool optimize_semijoin_nests(JOIN *join, table_map all_table_map) int tableno; double rows= 1.0; while ((tableno = tm_it.next_bit()) != Table_map_iterator::BITMAP_END) - rows *= join->map2table[tableno]->table->quick_condition_rows; + rows= COST_MULT(rows, + join->map2table[tableno]->table->quick_condition_rows); sjm->rows= min(sjm->rows, rows); } memcpy(sjm->positions, join->best_positions + join->const_tables, @@ -2564,7 +2566,7 @@ static uint get_tmp_table_rec_length(Item **p_items, uint elements) static double get_tmp_table_lookup_cost(THD *thd, double row_count, uint row_size) { - if (row_count * row_size > thd->variables.max_heap_table_size) + if (row_count > thd->variables.max_heap_table_size / (double) row_size) return (double) DISK_TEMPTABLE_LOOKUP_COST; else return (double) HEAP_TEMPTABLE_LOOKUP_COST; @@ -2970,8 +2972,11 @@ bool Sj_materialization_picker::check_qep(JOIN *join, } double mat_read_time= prefix_cost.total_cost(); - mat_read_time += mat_info->materialization_cost.total_cost() + - prefix_rec_count * mat_info->lookup_cost.total_cost(); + mat_read_time= + COST_ADD(mat_read_time, + COST_ADD(mat_info->materialization_cost.total_cost(), + COST_MULT(prefix_rec_count, + mat_info->lookup_cost.total_cost()))); /* NOTE: When we pick to use SJM[-Scan] we don't memcpy its POSITION @@ -3011,9 +3016,12 @@ bool Sj_materialization_picker::check_qep(JOIN *join, } /* Add materialization cost */ - prefix_cost += mat_info->materialization_cost.total_cost() + - prefix_rec_count * mat_info->scan_cost.total_cost(); - prefix_rec_count *= mat_info->rows; + prefix_cost= + COST_ADD(prefix_cost, + COST_ADD(mat_info->materialization_cost.total_cost(), + COST_MULT(prefix_rec_count, + mat_info->scan_cost.total_cost()))); + prefix_rec_count= COST_MULT(prefix_rec_count, mat_info->rows); uint i; table_map rem_tables= remaining_tables; @@ -3027,8 +3035,8 @@ bool Sj_materialization_picker::check_qep(JOIN *join, { best_access_path(join, join->positions[i].table, rem_tables, i, disable_jbuf, prefix_rec_count, &curpos, &dummy); - prefix_rec_count *= curpos.records_read; - prefix_cost += curpos.read_time; + prefix_rec_count= COST_MULT(prefix_rec_count, curpos.records_read); + prefix_cost= COST_ADD(prefix_cost, curpos.read_time); } *strategy= SJ_OPT_MATERIALIZE_SCAN; @@ -3335,16 +3343,18 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, for (uint j= first_dupsweedout_table; j <= idx; j++) { POSITION *p= join->positions + j; - current_fanout *= p->records_read; - dups_cost += p->read_time + current_fanout / TIME_FOR_COMPARE; + current_fanout= COST_MULT(current_fanout, p->records_read); + dups_cost= COST_ADD(dups_cost, + COST_ADD(p->read_time, + current_fanout / TIME_FOR_COMPARE)); if (p->table->emb_sj_nest) { - sj_inner_fanout *= p->records_read; + sj_inner_fanout= COST_MULT(sj_inner_fanout, p->records_read); dups_removed_fanout |= p->table->table->map; } else { - sj_outer_fanout *= p->records_read; + sj_outer_fanout= COST_MULT(sj_outer_fanout, p->records_read); temptable_rec_size += p->table->table->file->ref_length; } } @@ -3363,12 +3373,13 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, sj_outer_fanout, temptable_rec_size); - double write_cost= join->positions[first_tab].prefix_record_count* - sj_outer_fanout * one_write_cost; - double full_lookup_cost= join->positions[first_tab].prefix_record_count* - sj_outer_fanout* sj_inner_fanout * - one_lookup_cost; - dups_cost += write_cost + full_lookup_cost; + double write_cost= COST_MULT(join->positions[first_tab].prefix_record_count, + sj_outer_fanout * one_write_cost); + double full_lookup_cost= + COST_MULT(join->positions[first_tab].prefix_record_count, + COST_MULT(sj_outer_fanout, + sj_inner_fanout * one_lookup_cost)); + dups_cost= COST_ADD(dups_cost, COST_ADD(write_cost, full_lookup_cost)); *read_time= dups_cost; *record_count= prefix_rec_count * sj_outer_fanout; @@ -3515,8 +3526,8 @@ static void recalculate_prefix_record_count(JOIN *join, uint start, uint end) if (j == join->const_tables) prefix_count= 1.0; else - prefix_count= join->best_positions[j-1].prefix_record_count * - join->best_positions[j-1].records_read; + prefix_count= COST_MULT(join->best_positions[j-1].prefix_record_count, + join->best_positions[j-1].records_read); join->best_positions[j].prefix_record_count= prefix_count; } @@ -5807,14 +5818,16 @@ bool JOIN::choose_subquery_plan(table_map join_tables) The cost of executing the subquery and storing its result in an indexed temporary table. */ - double materialization_cost= inner_read_time_1 + - write_cost * inner_record_count_1; + double materialization_cost= COST_ADD(inner_read_time_1, + COST_MULT(write_cost, + inner_record_count_1)); - materialize_strategy_cost= materialization_cost + - outer_lookup_keys * lookup_cost; + materialize_strategy_cost= COST_ADD(materialization_cost, + COST_MULT(outer_lookup_keys, + lookup_cost)); /* C.2 Compute the cost of the IN=>EXISTS strategy. */ - in_exists_strategy_cost= outer_lookup_keys * inner_read_time_2; + in_exists_strategy_cost= COST_MULT(outer_lookup_keys, inner_read_time_2); /* C.3 Compare the costs and choose the cheaper strategy. */ if (materialize_strategy_cost >= in_exists_strategy_cost) diff --git a/sql/sql_const.h b/sql/sql_const.h index 96b64481936..c3b03dd7848 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -214,6 +214,14 @@ #define HEAP_TEMPTABLE_LOOKUP_COST 0.05 #define DISK_TEMPTABLE_LOOKUP_COST 1.0 + +#define COST_MAX (DBL_MAX * (1.0 - DBL_EPSILON)) + +#define COST_ADD(c,d) (COST_MAX - (d) > (c) ? (c) + (d) : COST_MAX) + +#define COST_MULT(c,f) (COST_MAX / (f) > (c) ? (c) * (f) : COST_MAX) + + #define MY_CHARSET_BIN_MB_MAXLEN 1 /** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4886e35c82e..961a7dac265 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5676,7 +5676,7 @@ best_access_path(JOIN *join, else tmp= table->file->read_time(key, 1, (ha_rows) min(tmp,s->worst_seeks)); - tmp*= record_count; + tmp= COST_MULT(tmp, record_count); } } else @@ -5841,18 +5841,18 @@ best_access_path(JOIN *join, else tmp= table->file->read_time(key, 1, (ha_rows) min(tmp,s->worst_seeks)); - tmp*= record_count; + tmp= COST_MULT(tmp, record_count); } else - tmp= best_time; // Do nothing + tmp= best_time; // Do nothing } - tmp += s->startup_cost; + tmp= COST_ADD(tmp, s->startup_cost); loose_scan_opt.check_ref_access_part2(key, start_key, records, tmp); } /* not ft_key */ if (tmp + 0.0001 < best_time - records/(double) TIME_FOR_COMPARE) { - best_time= tmp + records/(double) TIME_FOR_COMPARE; + best_time= COST_ADD(tmp, records/(double) TIME_FOR_COMPARE); best= tmp; best_records= records; best_key= start_key; @@ -5885,14 +5885,18 @@ best_access_path(JOIN *join, ha_rows rnd_records= matching_candidates_in_table(s, found_constraint); tmp= s->quick ? s->quick->read_time : s->scan_time(); - tmp+= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; + double cmp_time= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; + tmp= COST_ADD(tmp, cmp_time); /* We read the table as many times as join buffer becomes full. */ - tmp*= (1.0 + floor((double) cache_record_length(join,idx) * - record_count / - (double) thd->variables.join_buff_size)); - best_time= tmp + - (record_count*join_sel) / TIME_FOR_COMPARE * rnd_records; + + double refills= (1.0 + floor((double) cache_record_length(join,idx) * + record_count / + (double) thd->variables.join_buff_size)); + tmp= COST_MULT(tmp, refills); + best_time= COST_ADD(tmp, + COST_MULT((record_count*join_sel) / TIME_FOR_COMPARE, + rnd_records)); best= tmp; records= rows2double(rnd_records); best_key= hj_start_key; @@ -5960,9 +5964,9 @@ best_access_path(JOIN *join, access (see first else-branch below), but we don't take it into account here for range/index_merge access. Find out why this is so. */ - tmp= record_count * - (s->quick->read_time + - (s->found_records - rnd_records)/(double) TIME_FOR_COMPARE); + double cmp_time= (s->found_records - rnd_records)/(double) TIME_FOR_COMPARE; + tmp= COST_MULT(record_count, + COST_ADD(s->quick->read_time, cmp_time)); loose_scan_opt.check_range_access(join, idx, s->quick); } @@ -5977,16 +5981,15 @@ best_access_path(JOIN *join, - read the whole table record - skip rows which does not satisfy join condition */ - tmp= record_count * - (tmp + - (s->records - rnd_records)/(double) TIME_FOR_COMPARE); + double cmp_time= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; + tmp= COST_MULT(record_count, COST_ADD(tmp,cmp_time)); } else { - /* We read the table as many times as join buffer becomes full. */ - tmp*= (1.0 + floor((double) cache_record_length(join,idx) * - record_count / - (double) thd->variables.join_buff_size)); + double refills= (1.0 + floor((double) cache_record_length(join,idx) * + (record_count / + (double) thd->variables.join_buff_size))); + tmp= COST_MULT(tmp, refills); /* We don't make full cartesian product between rows in the scanned table and existing records because we skip all rows from the @@ -5994,7 +5997,8 @@ best_access_path(JOIN *join, we read the table (see flush_cached_records for details). Here we take into account cost to read and skip these records. */ - tmp+= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; + double cmp_time= (s->records - rnd_records)/(double) TIME_FOR_COMPARE; + tmp= COST_ADD(tmp, cmp_time); } } @@ -6005,9 +6009,9 @@ best_access_path(JOIN *join, tmp give us total cost of using TABLE SCAN */ if (best == DBL_MAX || - (tmp + record_count/(double) TIME_FOR_COMPARE*rnd_records < + COST_ADD(tmp, record_count/(double) TIME_FOR_COMPARE*rnd_records) < (best_key->is_for_hash_join() ? best_time : - best + record_count/(double) TIME_FOR_COMPARE*records))) + COST_ADD(best, record_count/(double) TIME_FOR_COMPARE*records))) { /* If the table has a range (s->quick is set) make_join_select() @@ -6526,9 +6530,10 @@ optimize_straight_join(JOIN *join, table_map join_tables) join->positions + idx, &loose_scan_pos); /* compute the cost of the new plan extended with 's' */ - record_count*= join->positions[idx].records_read; - read_time+= join->positions[idx].read_time + - record_count / (double) TIME_FOR_COMPARE; + record_count= COST_MULT(record_count, join->positions[idx].records_read); + read_time= COST_ADD(read_time, + COST_ADD(join->positions[idx].read_time, + record_count / (double) TIME_FOR_COMPARE)); advance_sj_state(join, join_tables, idx, &record_count, &read_time, &loose_scan_pos); @@ -6710,9 +6715,10 @@ greedy_search(JOIN *join, swap_variables(JOIN_TAB*, join->best_ref[idx], join->best_ref[best_idx]); /* compute the cost of the new plan extended with 'best_table' */ - record_count*= join->positions[idx].records_read; - read_time+= join->positions[idx].read_time + - record_count / (double) TIME_FOR_COMPARE; + record_count= COST_MULT(record_count, join->positions[idx].records_read); + read_time= COST_ADD(read_time, + COST_ADD(join->positions[idx].read_time, + record_count / (double) TIME_FOR_COMPARE)); remaining_tables&= ~(best_table->table->map); --size_remain; @@ -6819,11 +6825,13 @@ void JOIN::get_partial_cost_and_fanout(int end_tab_idx, } if (tab->records_read && (cur_table_map & filter_map)) { - record_count *= tab->records_read; - read_time += tab->read_time + record_count / (double) TIME_FOR_COMPARE; + record_count= COST_MULT(record_count, tab->records_read); + read_time= COST_ADD(read_time, + COST_ADD(tab->read_time, + record_count / (double) TIME_FOR_COMPARE)); if (tab->emb_sj_nest) - sj_inner_fanout *= tab->records_read; - } + sj_inner_fanout= COST_MULT(sj_inner_fanout, tab->records_read); + } if (i == last_sj_table) { @@ -6861,8 +6869,8 @@ void JOIN::get_prefix_cost_and_fanout(uint n_tables, { if (best_positions[i].records_read) { - record_count *= best_positions[i].records_read; - read_time += best_positions[i].read_time; + record_count= COST_MULT(record_count, best_positions[i].records_read); + read_time= COST_ADD(read_time, best_positions[i].read_time); } } *read_time_arg= read_time;// + record_count / TIME_FOR_COMPARE; @@ -7068,10 +7076,11 @@ best_extension_by_limited_search(JOIN *join, record_count, join->positions + idx, &loose_scan_pos); /* Compute the cost of extending the plan with 's' */ - - current_record_count= record_count * position->records_read; - current_read_time=read_time + position->read_time + - current_record_count / (double) TIME_FOR_COMPARE; + current_record_count= COST_MULT(record_count, position->records_read); + current_read_time=COST_ADD(read_time, + COST_ADD(position->read_time, + current_record_count / + (double) TIME_FOR_COMPARE)); advance_sj_state(join, remaining_tables, idx, ¤t_record_count, ¤t_read_time, &loose_scan_pos); @@ -7145,7 +7154,7 @@ best_extension_by_limited_search(JOIN *join, join->sort_by_table != join->positions[join->const_tables].table->table) /* We have to make a temp table */ - current_read_time+= current_record_count; + current_read_time= COST_ADD(current_read_time, current_record_count); if (current_read_time < join->best_read) { memcpy((uchar*) join->best_positions, (uchar*) join->positions, @@ -7189,11 +7198,11 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, DBUG_PRINT("best",("read_time: %g record_count: %g",read_time, record_count)); - read_time+=record_count/(double) TIME_FOR_COMPARE; + read_time= COST_ADD(read_time, record_count/(double) TIME_FOR_COMPARE); if (join->sort_by_table && join->sort_by_table != join->positions[join->const_tables].table->table) - read_time+=record_count; // We have to make a temp table + read_time= COST_ADD(read_time, record_count); // We have to make a temp table if (read_time < join->best_read) { memcpy((uchar*) join->best_positions,(uchar*) join->positions, @@ -7202,7 +7211,8 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, } DBUG_RETURN(FALSE); } - if (read_time+record_count/(double) TIME_FOR_COMPARE >= join->best_read) + if (COST_ADD(read_time, record_count/(double) TIME_FOR_COMPARE) + >= join->best_read) DBUG_RETURN(FALSE); /* Found better before */ JOIN_TAB *s; @@ -7224,8 +7234,8 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, Go to the next level only if there hasn't been a better key on this level! This will cut down the search for a lot simple cases! */ - double current_record_count=record_count*records; - double current_read_time=read_time+best; + double current_record_count= COST_MULT(record_count, records); + double current_read_time= COST_ADD(read_time, best); advance_sj_state(join, rest_tables, idx, ¤t_record_count, ¤t_read_time, &loose_scan_pos); @@ -7552,8 +7562,8 @@ prev_record_reads(POSITION *positions, uint idx, table_map found_ref) #max_nested_outer_joins=64-1) will not make it any more precise. */ if (pos->records_read) - found*= pos->records_read; - } + found= COST_MULT(found, pos->records_read); + } } return found; } @@ -13835,11 +13845,12 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, pos= loose_scan_pos; reopt_remaining_tables &= ~rs->table->map; - rec_count *= pos.records_read; - cost += pos.read_time; + rec_count= COST_MULT(rec_count, pos.records_read); + cost= COST_ADD(cost, pos.read_time); + if (!rs->emb_sj_nest) - *outer_rec_count *= pos.records_read; + *outer_rec_count= COST_MULT(*outer_rec_count, pos.records_read); } join->cur_sj_inner_tables= save_cur_sj_inner_tables; From 661289f4627b81b85d362cf62587dcfd4fb381c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 21 May 2019 09:20:49 +0300 Subject: [PATCH 11/14] Mention the sample IPv4 address 10.0.0.1 --- debian/po/ca.po | 4 ++-- debian/po/cs.po | 4 ++-- debian/po/da.po | 4 ++-- debian/po/es.po | 4 ++-- debian/po/pt_BR.po | 4 ++-- debian/po/tr.po | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/debian/po/ca.po b/debian/po/ca.po index 7c7d2210834..f2a6a3dc0bf 100644 --- a/debian/po/ca.po +++ b/debian/po/ca.po @@ -207,13 +207,13 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "El MySQL noms s'installa en cas de tenir un nom d'ordinador central que " #~ "no sigui numric i que es pugui resoldre a travs del fitxer /etc/hosts. " #~ "Ex. si l'ordre \"hostname\" retorna \"myhostname\", llavors hi ha d'haver " -#~ "una lnia com la segent \"10.1.0.1 myhostname\"." +#~ "una lnia com la segent \"10.0.0.1 myhostname\"." #, fuzzy #~ msgid "" diff --git a/debian/po/cs.po b/debian/po/cs.po index f3ae24b1e8c..259bc9a96f8 100644 --- a/debian/po/cs.po +++ b/debian/po/cs.po @@ -298,13 +298,13 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "MySQL se nainstaluje pouze v případě, že používáte nenumerické jméno " #~ "počítače, které se dá přeložit přes soubor /etc/hosts. Např. když příkaz " #~ "\"hostname\" vrátí \"diamond\", tak v /etc/hosts musí existovat obdobný " -#~ "řádek jako \"10.1.0.1 diamond\"." +#~ "řádek jako \"10.0.0.1 diamond\"." #~ msgid "" #~ "A new mysql user \"debian-sys-maint\" will be created. This mysql account " diff --git a/debian/po/da.po b/debian/po/da.po index d68b8575d72..8abb89ebbd4 100644 --- a/debian/po/da.po +++ b/debian/po/da.po @@ -324,12 +324,12 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "MySQL vil kun blive installeret, hvis du har et ikke-numerisk vrtsnavn, " #~ "som kan sls op i filen /ets/hosts. Hvis f.eks. kommandoen \"hostname\" " -#~ "svarer med \"mitvaertsnavn\", skal du have en linje a'la \"10.1.0.1 " +#~ "svarer med \"mitvaertsnavn\", skal du have en linje a'la \"10.0.0.1 " #~ "mitvaertsnavn\" i /etc/hosts." #~ msgid "" diff --git a/debian/po/es.po b/debian/po/es.po index e76c173a9f5..e0b72b87737 100644 --- a/debian/po/es.po +++ b/debian/po/es.po @@ -341,13 +341,13 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "Sólo se instalará MySQL si tiene un nombre de equipo que no sea una " #~ "dirección IP y pueda resolverse a través del archivo /etc/hosts. Por " #~ "ejemplo, si la orden «hostname» devuelve «MiNombreEquipo» entonces deberá " -#~ "existir una línea «10.1.0.1 MiNombreEquipo» en dicho archivo." +#~ "existir una línea «10.0.0.1 MiNombreEquipo» en dicho archivo." #~ msgid "" #~ "A new mysql user \"debian-sys-maint\" will be created. This mysql account " diff --git a/debian/po/pt_BR.po b/debian/po/pt_BR.po index a0b4cdbfbfb..35f1b4fcea4 100644 --- a/debian/po/pt_BR.po +++ b/debian/po/pt_BR.po @@ -308,13 +308,13 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "O MySQL será instalado somente caso você possua um nome de host NÃO " #~ "NUMÉRICO que possa ser resolvido através do arquivo /etc/hosts, ou seja, " #~ "caso o comando \"hostname\" retorne \"myhostname\", uma linha como " -#~ "\"10.1.0.1 myhostname\" deverá existir no arquivo /etc/hosts." +#~ "\"10.0.0.1 myhostname\" deverá existir no arquivo /etc/hosts." #~ msgid "" #~ "A new mysql user \"debian-sys-maint\" will be created. This mysql account " diff --git a/debian/po/tr.po b/debian/po/tr.po index 814341a6bc2..dafbd6121d8 100644 --- a/debian/po/tr.po +++ b/debian/po/tr.po @@ -206,12 +206,12 @@ msgstr "" #~ msgid "" #~ "MySQL will only install if you have a non-numeric hostname that is " #~ "resolvable via the /etc/hosts file. E.g. if the \"hostname\" command " -#~ "returns \"myhostname\" then there must be a line like \"10.1.0.1 " +#~ "returns \"myhostname\" then there must be a line like \"10.0.0.1 " #~ "myhostname\"." #~ msgstr "" #~ "MySQL sadece /etc/hosts dosyası yoluyla çözülebilir NUMERİK OLMAYAN bir " #~ "makine adına sahipseniz kurulacaktır. Örneğin, eğer \"hostname\" komutu " -#~ "\"makinem\" ismini döndürüyorsa, bu dosya içinde \"10.1.0.1 makinem\" " +#~ "\"makinem\" ismini döndürüyorsa, bu dosya içinde \"10.0.0.1 makinem\" " #~ "gibi bir satır olmalıdır." #, fuzzy From 242a28c320ae8b16144c5e91cbcf8806ce1e5d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 28 May 2019 08:07:45 +0300 Subject: [PATCH 12/14] MDEV-6812: Remove the wrapper my_log2f() --- storage/innobase/row/row0merge.cc | 17 +++-------------- storage/xtradb/row/row0merge.cc | 17 +++-------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 5042a9ed170..463be8d229d 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -27,6 +27,7 @@ Completed by Sunny Bains and Marko Makela #include #include #include +#include #include "row0merge.h" #include "row0ext.h" @@ -42,15 +43,8 @@ Completed by Sunny Bains and Marko Makela #include "row0import.h" #include "handler0alter.h" #include "ha_prototypes.h" -#include "math.h" /* log() */ #include "fil0crypt.h" -float my_log2f(float n) -{ - /* log(n) / log(2) is log2. */ - return (float)(log((double)n) / log((double)2)); -} - /* Ignore posix_fadvise() on those platforms where it does not exist */ #if defined __WIN__ # define posix_fadvise(fd, offset, len, advice) /* nothing */ @@ -2503,18 +2497,13 @@ row_merge_sort( /* Record the number of merge runs we need to perform */ num_runs = file->offset; - /* Find the number N which 2^N is greater or equal than num_runs */ - /* N is merge sort running count */ - total_merge_sort_count = ceil(my_log2f(num_runs)); - if(total_merge_sort_count <= 0) { - total_merge_sort_count=1; - } - /* If num_runs are less than 1, nothing to merge */ if (num_runs <= 1) { DBUG_RETURN(error); } + total_merge_sort_count = ceil(log2f(num_runs)); + /* "run_offset" records each run's first offset number */ run_offset = (ulint*) mem_alloc(file->offset * sizeof(ulint)); diff --git a/storage/xtradb/row/row0merge.cc b/storage/xtradb/row/row0merge.cc index cc7c648fe4c..f71a623da20 100644 --- a/storage/xtradb/row/row0merge.cc +++ b/storage/xtradb/row/row0merge.cc @@ -27,6 +27,7 @@ Completed by Sunny Bains and Marko Makela #include #include #include +#include #include "row0merge.h" #include "row0ext.h" @@ -42,15 +43,8 @@ Completed by Sunny Bains and Marko Makela #include "row0import.h" #include "handler0alter.h" #include "ha_prototypes.h" -#include "math.h" /* log2() */ #include "fil0crypt.h" -float my_log2f(float n) -{ - /* log(n) / log(2) is log2. */ - return (float)(log((double)n) / log((double)2)); -} - /* Ignore posix_fadvise() on those platforms where it does not exist */ #if defined __WIN__ # define posix_fadvise(fd, offset, len, advice) /* nothing */ @@ -2516,18 +2510,13 @@ row_merge_sort( /* Record the number of merge runs we need to perform */ num_runs = file->offset; - /* Find the number N which 2^N is greater or equal than num_runs */ - /* N is merge sort running count */ - total_merge_sort_count = ceil(my_log2f(num_runs)); - if(total_merge_sort_count <= 0) { - total_merge_sort_count=1; - } - /* If num_runs are less than 1, nothing to merge */ if (num_runs <= 1) { DBUG_RETURN(error); } + total_merge_sort_count = ceil(log2f(num_runs)); + /* "run_offset" records each run's first offset number */ run_offset = (ulint*) mem_alloc(file->offset * sizeof(ulint)); From 626f2a1c170e615c7866c1041746159dc3f709af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 28 May 2019 10:50:17 +0300 Subject: [PATCH 13/14] MDEV-19614 SET GLOBAL innodb_ deadlock due to LOCK_global_system_variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The update callback functions for several settable global InnoDB variables are acquiring InnoDB latches while holding LOCK_global_system_variables. On the other hand, some InnoDB code is invoking THDVAR() while holding InnoDB latches. An example of this is thd_lock_wait_timeout() that is called by lock_rec_enqueue_waiting(). In some cases, the intern_sys_var_ptr() that is invoked by THDVAR() may acquire LOCK_global_system_variables, via sync_dynamic_session_variables(). In lock_rec_enqueue_waiting(), we really must be holding some InnoDB latch while invoking THDVAR(). This implies that LOCK_global_system_variables must conceptually reside below any InnoDB latch in the latching order. That in turns implies that the various update callback functions must release LOCK_global_system_variables before acquiring any InnoDB mutexes or rw-locks, and reacquire LOCK_global_system_variables later. The validate functions are being invoked while not holding LOCK_global_system_variables and thus they do not need any changes. The following statements are affected by this: SET GLOBAL innodb_adaptive_hash_index = …; SET GLOBAL innodb_cmp_per_index_enabled = 1; SET GLOBAL innodb_old_blocks_pct = …; SET GLOBAL innodb_fil_make_page_dirty_debug = …; -- debug builds only SET GLOBAL innodb_buffer_pool_evict = uncompressed; -- debug builds only SET GLOBAL innodb_purge_run_now = 1; -- debug builds only SET GLOBAL innodb_purge_stop_now = 1; -- debug builds only SET GLOBAL innodb_log_checkpoint_now = 1; -- debug builds only SET GLOBAL innodb_buf_flush_list_now = 1; -- debug builds only SET GLOBAL innodb_buffer_pool_dump_now = 1; SET GLOBAL innodb_buffer_pool_load_now = 1; SET GLOBAL innodb_buffer_pool_load_abort = 1; SET GLOBAL innodb_status_output = …; SET GLOBAL innodb_status_output_locks = …; SET GLOBAL innodb_encryption_threads = …; SET GLOBAL innodb_encryption_rotate_key_age = …; SET GLOBAL innodb_encryption_rotation_iops = …; SET GLOBAL innodb_encrypt_tables = …; SET GLOBAL innodb_disallow_writes = …; buf_LRU_old_ratio_update(): Correct the return type. --- storage/innobase/buf/buf0lru.cc | 14 +-- storage/innobase/handler/ha_innodb.cc | 126 +++++++++++++------------- storage/innobase/include/buf0lru.h | 8 +- storage/xtradb/buf/buf0lru.cc | 14 +-- storage/xtradb/handler/ha_innodb.cc | 126 +++++++++++++------------- storage/xtradb/include/buf0lru.h | 8 +- 6 files changed, 152 insertions(+), 144 deletions(-) diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index 7edc9520e02..29fe81dc920 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -2243,8 +2243,8 @@ buf_LRU_old_ratio_update_instance( buf_pool_t* buf_pool,/*!< in: buffer pool instance */ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust) /*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust) /*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ { uint ratio; @@ -2282,17 +2282,17 @@ buf_LRU_old_ratio_update_instance( Updates buf_pool->LRU_old_ratio. @return updated old_pct */ UNIV_INTERN -ulint +uint buf_LRU_old_ratio_update( /*=====================*/ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust) /*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust) /*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ { ulint i; - ulint new_ratio = 0; + uint new_ratio = 0; for (i = 0; i < srv_buf_pool_instances; i++) { buf_pool_t* buf_pool; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index cb6ec20e0d6..e04d431174a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -17166,11 +17166,13 @@ innodb_adaptive_hash_index_update( const void* save) /*!< in: immediate result from check function */ { + mysql_mutex_unlock(&LOCK_global_system_variables); if (*(my_bool*) save) { btr_search_enable(); } else { btr_search_disable(); } + mysql_mutex_lock(&LOCK_global_system_variables); } /****************************************************************//** @@ -17191,7 +17193,9 @@ innodb_cmp_per_index_update( /* Reset the stats whenever we enable the table INFORMATION_SCHEMA.innodb_cmp_per_index. */ if (!srv_cmp_per_index_enabled && *(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); page_zip_reset_stat_per_index(); + mysql_mutex_lock(&LOCK_global_system_variables); } srv_cmp_per_index_enabled = !!(*(my_bool*) save); @@ -17212,9 +17216,11 @@ innodb_old_blocks_pct_update( const void* save) /*!< in: immediate result from check function */ { - innobase_old_blocks_pct = static_cast( - buf_LRU_old_ratio_update( - *static_cast(save), TRUE)); + mysql_mutex_unlock(&LOCK_global_system_variables); + uint ratio = buf_LRU_old_ratio_update(*static_cast(save), + true); + mysql_mutex_lock(&LOCK_global_system_variables); + innobase_old_blocks_pct = ratio; } /****************************************************************//** @@ -17232,9 +17238,10 @@ innodb_change_buffer_max_size_update( const void* save) /*!< in: immediate result from check function */ { - innobase_change_buffer_max_size = - (*static_cast(save)); + innobase_change_buffer_max_size = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); ibuf_max_size_update(innobase_change_buffer_max_size); + mysql_mutex_lock(&LOCK_global_system_variables); } #ifdef UNIV_DEBUG @@ -17278,6 +17285,7 @@ innodb_make_page_dirty( { mtr_t mtr; ulong space_id = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); mtr_start(&mtr); @@ -17295,6 +17303,7 @@ innodb_make_page_dirty( MLOG_2BYTES, &mtr); } mtr_commit(&mtr); + mysql_mutex_lock(&LOCK_global_system_variables); } #endif // UNIV_DEBUG @@ -17933,8 +17942,11 @@ innodb_buffer_pool_evict_update( { if (const char* op = *static_cast(save)) { if (!strcmp(op, "uncompressed")) { + mysql_mutex_unlock(&LOCK_global_system_variables); for (uint tries = 0; tries < 10000; tries++) { if (innodb_buffer_pool_evict_uncompressed()) { + mysql_mutex_lock( + &LOCK_global_system_variables); return; } @@ -18237,7 +18249,9 @@ purge_run_now_set( check function */ { if (*(my_bool*) save && trx_purge_state() != PURGE_STATE_DISABLED) { + mysql_mutex_unlock(&LOCK_global_system_variables); trx_purge_run(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -18260,7 +18274,9 @@ purge_stop_now_set( check function */ { if (*(my_bool*) save && trx_purge_state() != PURGE_STATE_DISABLED) { + mysql_mutex_unlock(&LOCK_global_system_variables); trx_purge_stop(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -18282,6 +18298,8 @@ checkpoint_now_set( check function */ { if (*(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); + while (log_sys->last_checkpoint_lsn < log_sys->lsn) { log_make_checkpoint_at(LSN_MAX, TRUE); fil_flush_file_spaces(FIL_LOG); @@ -18295,6 +18313,8 @@ checkpoint_now_set( "system tablespace at checkpoint err=%s", ut_strerr(err)); } + + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -18316,8 +18336,10 @@ buf_flush_list_now_set( check function */ { if (*(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_flush_list(ULINT_MAX, LSN_MAX, NULL); buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST); + mysql_mutex_lock(&LOCK_global_system_variables); } } #endif /* UNIV_DEBUG */ @@ -18419,7 +18441,9 @@ buffer_pool_dump_now( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_dump_start(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -18442,7 +18466,9 @@ buffer_pool_load_now( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_load_start(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -18465,96 +18491,71 @@ buffer_pool_load_abort( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_load_abort(); + mysql_mutex_lock(&LOCK_global_system_variables); } } /** Update innodb_status_output or innodb_status_output_locks, which control InnoDB "status monitor" output to the error log. -@param[in] thd thread handle -@param[in] var system variable -@param[out] var_ptr current value +@param[out] var current value @param[in] save to-be-assigned value */ static void -innodb_status_output_update( -/*========================*/ - THD* thd __attribute__((unused)), - struct st_mysql_sys_var* var __attribute__((unused)), - void* var_ptr __attribute__((unused)), - const void* save __attribute__((unused))) +innodb_status_output_update(THD*,st_mysql_sys_var*,void*var,const void*save) { - *static_cast(var_ptr) = *static_cast(save); + *static_cast(var) = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); /* Wakeup server monitor thread. */ os_event_set(srv_monitor_event); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_threads */ +/** Update the system variable innodb_encryption_threads. +@param[in] save to-be-assigned value */ static void -innodb_encryption_threads_update( -/*=============================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_threads_update(THD*,st_mysql_sys_var*,void*,const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_thread_cnt(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_rotate_key_age */ +/** Update the system variable innodb_encryption_rotate_key_age. +@param[in] save to-be-assigned value */ static void -innodb_encryption_rotate_key_age_update( -/*====================================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_rotate_key_age_update(THD*,st_mysql_sys_var*,void*, + const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_rotate_key_age(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_rotation_iops */ +/** Update the system variable innodb_encryption_rotation_iops. +@param[in] save to-be-assigned value */ static void -innodb_encryption_rotation_iops_update( -/*===================================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_rotation_iops_update(THD*,st_mysql_sys_var*,void*, + const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_rotation_iops(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encrypt_tables*/ +/** Update the system variable innodb_encrypt_tables. +@param[in] save to-be-assigned value */ static void -innodb_encrypt_tables_update( -/*=========================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encrypt_tables_update(THD*,st_mysql_sys_var*,void*,const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_encrypt_tables(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } static SHOW_VAR innodb_status_variables_export[]= { @@ -19736,12 +19737,15 @@ innobase_disallow_writes_update( variable */ const void* save) /* in: temporary storage */ { - *(my_bool*)var_ptr = *(my_bool*)save; + const my_bool val = *static_cast(save); + *static_cast(var_ptr) = val; ut_a(srv_allow_writes_event); - if (*(my_bool*)var_ptr) + mysql_mutex_unlock(&LOCK_global_system_variables); + if (val) os_event_reset(srv_allow_writes_event); else os_event_set(srv_allow_writes_event); + mysql_mutex_lock(&LOCK_global_system_variables); } static MYSQL_SYSVAR_BOOL(disallow_writes, innobase_disallow_writes, diff --git a/storage/innobase/include/buf0lru.h b/storage/innobase/include/buf0lru.h index 948c6f25503..09100b35e68 100644 --- a/storage/innobase/include/buf0lru.h +++ b/storage/innobase/include/buf0lru.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -202,13 +202,13 @@ buf_LRU_make_block_old( Updates buf_pool->LRU_old_ratio. @return updated old_pct */ UNIV_INTERN -ulint +uint buf_LRU_old_ratio_update( /*=====================*/ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust);/*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust);/*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ /********************************************************************//** Update the historical stats that we are collecting for LRU eviction diff --git a/storage/xtradb/buf/buf0lru.cc b/storage/xtradb/buf/buf0lru.cc index 5f3a8627055..13bf5e79f2d 100644 --- a/storage/xtradb/buf/buf0lru.cc +++ b/storage/xtradb/buf/buf0lru.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -2408,8 +2408,8 @@ buf_LRU_old_ratio_update_instance( buf_pool_t* buf_pool,/*!< in: buffer pool instance */ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust) /*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust) /*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ { uint ratio; @@ -2447,17 +2447,17 @@ buf_LRU_old_ratio_update_instance( Updates buf_pool->LRU_old_ratio. @return updated old_pct */ UNIV_INTERN -ulint +uint buf_LRU_old_ratio_update( /*=====================*/ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust) /*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust) /*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ { ulint i; - ulint new_ratio = 0; + uint new_ratio = 0; for (i = 0; i < srv_buf_pool_instances; i++) { buf_pool_t* buf_pool; diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index aa17eb6a5ea..0cdd5ac2452 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -17887,11 +17887,13 @@ innodb_adaptive_hash_index_update( const void* save) /*!< in: immediate result from check function */ { + mysql_mutex_unlock(&LOCK_global_system_variables); if (*(my_bool*) save) { btr_search_enable(); } else { btr_search_disable(); } + mysql_mutex_lock(&LOCK_global_system_variables); } /****************************************************************//** @@ -17912,7 +17914,9 @@ innodb_cmp_per_index_update( /* Reset the stats whenever we enable the table INFORMATION_SCHEMA.innodb_cmp_per_index. */ if (!srv_cmp_per_index_enabled && *(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); page_zip_reset_stat_per_index(); + mysql_mutex_lock(&LOCK_global_system_variables); } srv_cmp_per_index_enabled = !!(*(my_bool*) save); @@ -17933,9 +17937,11 @@ innodb_old_blocks_pct_update( const void* save) /*!< in: immediate result from check function */ { - innobase_old_blocks_pct = static_cast( - buf_LRU_old_ratio_update( - *static_cast(save), TRUE)); + mysql_mutex_unlock(&LOCK_global_system_variables); + uint ratio = buf_LRU_old_ratio_update(*static_cast(save), + true); + mysql_mutex_lock(&LOCK_global_system_variables); + innobase_old_blocks_pct = ratio; } /****************************************************************//** @@ -17953,9 +17959,10 @@ innodb_change_buffer_max_size_update( const void* save) /*!< in: immediate result from check function */ { - innobase_change_buffer_max_size = - (*static_cast(save)); + innobase_change_buffer_max_size = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); ibuf_max_size_update(innobase_change_buffer_max_size); + mysql_mutex_lock(&LOCK_global_system_variables); } #ifdef UNIV_DEBUG @@ -17999,6 +18006,7 @@ innodb_make_page_dirty( { mtr_t mtr; ulong space_id = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); mtr_start(&mtr); @@ -18016,6 +18024,7 @@ innodb_make_page_dirty( MLOG_2BYTES, &mtr); } mtr_commit(&mtr); + mysql_mutex_lock(&LOCK_global_system_variables); } #endif // UNIV_DEBUG @@ -18661,8 +18670,11 @@ innodb_buffer_pool_evict_update( { if (const char* op = *static_cast(save)) { if (!strcmp(op, "uncompressed")) { + mysql_mutex_unlock(&LOCK_global_system_variables); for (uint tries = 0; tries < 10000; tries++) { if (innodb_buffer_pool_evict_uncompressed()) { + mysql_mutex_lock( + &LOCK_global_system_variables); return; } @@ -19199,7 +19211,9 @@ purge_run_now_set( check function */ { if (*(my_bool*) save && trx_purge_state() != PURGE_STATE_DISABLED) { + mysql_mutex_unlock(&LOCK_global_system_variables); trx_purge_run(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19222,7 +19236,9 @@ purge_stop_now_set( check function */ { if (*(my_bool*) save && trx_purge_state() != PURGE_STATE_DISABLED) { + mysql_mutex_unlock(&LOCK_global_system_variables); trx_purge_stop(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19244,6 +19260,8 @@ checkpoint_now_set( check function */ { if (*(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); + while (log_sys->last_checkpoint_lsn < log_sys->lsn) { log_make_checkpoint_at(LSN_MAX, TRUE); fil_flush_file_spaces(FIL_LOG); @@ -19257,6 +19275,8 @@ checkpoint_now_set( "system tablespace at checkpoint err=%s", ut_strerr(err)); } + + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19278,8 +19298,10 @@ buf_flush_list_now_set( check function */ { if (*(my_bool*) save) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_flush_list(ULINT_MAX, LSN_MAX, NULL); buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19406,7 +19428,9 @@ buffer_pool_dump_now( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_dump_start(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19429,7 +19453,9 @@ buffer_pool_load_now( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_load_start(); + mysql_mutex_lock(&LOCK_global_system_variables); } } @@ -19452,96 +19478,71 @@ buffer_pool_load_abort( check function */ { if (*(my_bool*) save && !srv_read_only_mode) { + mysql_mutex_unlock(&LOCK_global_system_variables); buf_load_abort(); + mysql_mutex_lock(&LOCK_global_system_variables); } } /** Update innodb_status_output or innodb_status_output_locks, which control InnoDB "status monitor" output to the error log. -@param[in] thd thread handle -@param[in] var system variable -@param[out] var_ptr current value +@param[out] var current value @param[in] save to-be-assigned value */ static void -innodb_status_output_update( -/*========================*/ - THD* thd __attribute__((unused)), - struct st_mysql_sys_var* var __attribute__((unused)), - void* var_ptr __attribute__((unused)), - const void* save __attribute__((unused))) +innodb_status_output_update(THD*,st_mysql_sys_var*,void*var,const void*save) { - *static_cast(var_ptr) = *static_cast(save); + *static_cast(var) = *static_cast(save); + mysql_mutex_unlock(&LOCK_global_system_variables); /* Wakeup server monitor thread. */ os_event_set(srv_monitor_event); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_threads */ +/** Update the system variable innodb_encryption_threads. +@param[in] save to-be-assigned value */ static void -innodb_encryption_threads_update( -/*=============================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_threads_update(THD*,st_mysql_sys_var*,void*,const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_thread_cnt(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_rotate_key_age */ +/** Update the system variable innodb_encryption_rotate_key_age. +@param[in] save to-be-assigned value */ static void -innodb_encryption_rotate_key_age_update( -/*====================================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_rotate_key_age_update(THD*,st_mysql_sys_var*,void*, + const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_rotate_key_age(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encryption_rotation_iops */ +/** Update the system variable innodb_encryption_rotation_iops. +@param[in] save to-be-assigned value */ static void -innodb_encryption_rotation_iops_update( -/*===================================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encryption_rotation_iops_update(THD*,st_mysql_sys_var*,void*, + const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_rotation_iops(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } -/****************************************************************** -Update the system variable innodb_encrypt_tables*/ +/** Update the system variable innodb_encrypt_tables. +@param[in] save to-be-assigned value */ static void -innodb_encrypt_tables_update( -/*=========================*/ - THD* thd, /*!< in: thread handle */ - struct st_mysql_sys_var* var, /*!< in: pointer to - system variable */ - void* var_ptr,/*!< out: where the - formal string goes */ - const void* save) /*!< in: immediate result - from check function */ +innodb_encrypt_tables_update(THD*,st_mysql_sys_var*,void*,const void*save) { + mysql_mutex_unlock(&LOCK_global_system_variables); fil_crypt_set_encrypt_tables(*static_cast(save)); + mysql_mutex_lock(&LOCK_global_system_variables); } static SHOW_VAR innodb_status_variables_export[]= { @@ -20979,12 +20980,15 @@ innobase_disallow_writes_update( variable */ const void* save) /* in: temporary storage */ { - *(my_bool*)var_ptr = *(my_bool*)save; + const my_bool val = *static_cast(save); + *static_cast(var_ptr) = val; ut_a(srv_allow_writes_event); - if (*(my_bool*)var_ptr) + mysql_mutex_unlock(&LOCK_global_system_variables); + if (val) os_event_reset(srv_allow_writes_event); else os_event_set(srv_allow_writes_event); + mysql_mutex_lock(&LOCK_global_system_variables); } static MYSQL_SYSVAR_BOOL(disallow_writes, innobase_disallow_writes, diff --git a/storage/xtradb/include/buf0lru.h b/storage/xtradb/include/buf0lru.h index e0f2277b6a2..69ada4abb70 100644 --- a/storage/xtradb/include/buf0lru.h +++ b/storage/xtradb/include/buf0lru.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -208,13 +208,13 @@ buf_LRU_make_block_old( Updates buf_pool->LRU_old_ratio. @return updated old_pct */ UNIV_INTERN -ulint +uint buf_LRU_old_ratio_update( /*=====================*/ uint old_pct,/*!< in: Reserve this percentage of the buffer pool for "old" blocks. */ - ibool adjust);/*!< in: TRUE=adjust the LRU list; - FALSE=just assign buf_pool->LRU_old_ratio + bool adjust);/*!< in: true=adjust the LRU list; + false=just assign buf_pool->LRU_old_ratio during the initialization of InnoDB */ /********************************************************************//** Update the historical stats that we are collecting for LRU eviction From 8358c6f03edb941be488f009c2bd0eb9df47e8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 28 May 2019 15:24:32 +0300 Subject: [PATCH 14/14] MDEV-19614: Fix innodb_plugin on Windows LOCK_global_system_variables: Declare with MYSQL_PLUGIN_IMPORT --- sql/mysqld.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/mysqld.h b/sql/mysqld.h index 1f34856c6c8..e939524dbff 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -1,5 +1,5 @@ /* Copyright (c) 2006, 2016, Oracle and/or its affiliates. - Copyright (c) 2010, 2016, MariaDB + Copyright (c) 2010, 2019, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -560,11 +560,11 @@ extern mysql_mutex_t LOCK_item_func_sleep, LOCK_status, LOCK_show_status, LOCK_error_log, LOCK_delayed_insert, LOCK_short_uuid_generator, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, - LOCK_slave_list, LOCK_active_mi, LOCK_manager, - LOCK_global_system_variables, LOCK_user_conn, + LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_user_conn, LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count, LOCK_slave_background; -extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count; +extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count, + LOCK_global_system_variables; #ifdef HAVE_OPENSSL extern char* des_key_file; extern mysql_mutex_t LOCK_des_key_file;