From f003cc8a35a4cdd9621621f95da889777b8b31b0 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 18 Jan 2017 11:42:41 -0800 Subject: [PATCH 01/43] Fixed bug mdev-8603. When building different range and index-merge trees the range optimizer could build an index-merge tree with an index scan containing less ranges then needed. This index-merge could be chosen as the best. Following this index-merge the executioner missed some rows in the result set. The invalid index scan was built due to an inconsistency in the code back-ported from mysql into 5.3 that fixed mysql bug #11765831: the code added to key_or() could change shared keys of the second ored tree. Partially the problem was fixed in the patch for mariadb bug #823301, but it turned out that only partially. --- mysql-test/r/range_vs_index_merge.result | 46 ++++++++++++++++-- ..._vs_index_merge_innodb,innodb_plugin.rdiff | 13 ++++- .../r/range_vs_index_merge_innodb.result | 48 +++++++++++++++++-- mysql-test/t/range_vs_index_merge.test | 41 ++++++++++++++-- sql/opt_range.cc | 14 +++--- 5 files changed, 141 insertions(+), 21 deletions(-) diff --git a/mysql-test/r/range_vs_index_merge.result b/mysql-test/r/range_vs_index_merge.result index cc8a345a2ff..0acaed37d22 100644 --- a/mysql-test/r/range_vs_index_merge.result +++ b/mysql-test/r/range_vs_index_merge.result @@ -60,11 +60,11 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM City WHERE Population > 100000 AND Name LIKE 'Aba%' OR -Country IN ('CAN', 'ARG') AND ID < 3800 OR -Country < 'U' AND Name LIKE 'Zhu%' OR -ID BETWEEN 3800 AND 3810; +Country IN ('CAN', 'ARG') AND ID BETWEEN 120 AND 130 OR +Country <= 'ALB' AND Name LIKE 'L%' OR +ID BETWEEN 3807 AND 3810; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 132 Using sort_union(Name,Country,PRIMARY); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,PRIMARY,Country 35,4,3 NULL 31 Using sort_union(Name,PRIMARY,Country); Using where EXPLAIN SELECT * FROM City WHERE (Population > 101000 AND Population < 115000); @@ -1763,4 +1763,42 @@ a b 167 9999 168 10000 DROP TABLE t1; +# +# MDEV-8603: Wrong result OR/AND condition over index fields +# +CREATE TABLE t1 ( +id INT NOT NULL, +state VARCHAR(64), +capital VARCHAR(64), +UNIQUE KEY (id), +KEY state (state,id), +KEY capital (capital, id) +); +INSERT INTO t1 VALUES +(1,'Arizona','Phoenix'), +(2,'Hawaii','Honolulu'), +(3,'Georgia','Atlanta'), +(4,'Florida','Tallahassee'), +(5,'Alaska','Juneau'), +(6,'Michigan','Lansing'), +(7,'Pennsylvania','Harrisburg'), +(8,'Virginia','Richmond') +; +EXPLAIN +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 +OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range state,capital state 71 NULL 12 Using index condition; Using where +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 +OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; +id state capital +4 Florida Tallahassee +3 Georgia Atlanta +2 Hawaii Honolulu +6 Michigan Lansing +7 Pennsylvania Harrisburg +8 Virginia Richmond +DROP TABLE t1; set session optimizer_switch='index_merge_sort_intersection=default'; diff --git a/mysql-test/r/range_vs_index_merge_innodb,innodb_plugin.rdiff b/mysql-test/r/range_vs_index_merge_innodb,innodb_plugin.rdiff index ecae2c809c1..7e3c4a33ad2 100644 --- a/mysql-test/r/range_vs_index_merge_innodb,innodb_plugin.rdiff +++ b/mysql-test/r/range_vs_index_merge_innodb,innodb_plugin.rdiff @@ -1,5 +1,5 @@ ---- ./r/range_vs_index_merge_innodb.result 2012-11-21 19:35:14.000000000 +0100 -+++ ./r/range_vs_index_merge_innodb,innodb_plugin.reject 2012-11-21 20:56:00.000000000 +0100 +--- range_vs_index_merge_innodb.result 2017-01-17 15:00:18.039148421 -0800 ++++ range_vs_index_merge_innodb,innodb_plugin.result 2017-01-17 14:58:45.129148312 -0800 @@ -50,14 +50,14 @@ WHERE (Population >= 100000 OR Name LIKE 'P%') AND Country='CAN' OR (Population < 100000 OR Name Like 'T%') AND Country='ARG'; @@ -278,3 +278,12 @@ FLUSH STATUS; SELECT * FROM City WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H')) +@@ -1790,7 +1790,7 @@ + WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 + OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE t1 range state,capital state 71 NULL 10 Using index condition; Using where ++1 SIMPLE t1 range state,capital state 71 NULL 10 Using where + SELECT * FROM t1 FORCE KEY (state,capital) + WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 + OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; diff --git a/mysql-test/r/range_vs_index_merge_innodb.result b/mysql-test/r/range_vs_index_merge_innodb.result index 67e341192da..ff4940281ce 100644 --- a/mysql-test/r/range_vs_index_merge_innodb.result +++ b/mysql-test/r/range_vs_index_merge_innodb.result @@ -61,11 +61,11 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM City WHERE Population > 100000 AND Name LIKE 'Aba%' OR -Country IN ('CAN', 'ARG') AND ID < 3800 OR -Country < 'U' AND Name LIKE 'Zhu%' OR -ID BETWEEN 3800 AND 3810; +Country IN ('CAN', 'ARG') AND ID BETWEEN 120 AND 130 OR +Country <= 'ALB' AND Name LIKE 'L%' OR +ID BETWEEN 3807 AND 3810; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 125 Using sort_union(Name,Country,PRIMARY); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 33 Using sort_union(Name,Country,PRIMARY); Using where EXPLAIN SELECT * FROM City WHERE (Population > 101000 AND Population < 115000); @@ -369,7 +369,7 @@ WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 100 AND 200) AND (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 200 Using where +1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 181 Using sort_union(Name,Country,PRIMARY); Using where SELECT * FROM City USE INDEX () WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 100 AND 110) AND @@ -1764,5 +1764,43 @@ a b 167 9999 168 10000 DROP TABLE t1; +# +# MDEV-8603: Wrong result OR/AND condition over index fields +# +CREATE TABLE t1 ( +id INT NOT NULL, +state VARCHAR(64), +capital VARCHAR(64), +UNIQUE KEY (id), +KEY state (state,id), +KEY capital (capital, id) +); +INSERT INTO t1 VALUES +(1,'Arizona','Phoenix'), +(2,'Hawaii','Honolulu'), +(3,'Georgia','Atlanta'), +(4,'Florida','Tallahassee'), +(5,'Alaska','Juneau'), +(6,'Michigan','Lansing'), +(7,'Pennsylvania','Harrisburg'), +(8,'Virginia','Richmond') +; +EXPLAIN +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 +OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range state,capital state 71 NULL 10 Using index condition; Using where +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 +OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; +id state capital +4 Florida Tallahassee +3 Georgia Atlanta +2 Hawaii Honolulu +6 Michigan Lansing +7 Pennsylvania Harrisburg +8 Virginia Richmond +DROP TABLE t1; set session optimizer_switch='index_merge_sort_intersection=default'; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/range_vs_index_merge.test b/mysql-test/t/range_vs_index_merge.test index fb8fd778559..e3a699322b2 100644 --- a/mysql-test/t/range_vs_index_merge.test +++ b/mysql-test/t/range_vs_index_merge.test @@ -57,9 +57,9 @@ SELECT * FROM City EXPLAIN SELECT * FROM City WHERE Population > 100000 AND Name LIKE 'Aba%' OR - Country IN ('CAN', 'ARG') AND ID < 3800 OR - Country < 'U' AND Name LIKE 'Zhu%' OR - ID BETWEEN 3800 AND 3810; + Country IN ('CAN', 'ARG') AND ID BETWEEN 120 AND 130 OR + Country <= 'ALB' AND Name LIKE 'L%' OR + ID BETWEEN 3807 AND 3810; # The output of the next 3 commands tells us about selectivities # of the conditions utilized in 2 queries following after them @@ -1203,6 +1203,41 @@ SELECT * FROM t1 DROP TABLE t1; + +--echo # +--echo # MDEV-8603: Wrong result OR/AND condition over index fields +--echo # + +CREATE TABLE t1 ( + id INT NOT NULL, + state VARCHAR(64), + capital VARCHAR(64), + UNIQUE KEY (id), + KEY state (state,id), + KEY capital (capital, id) +); + +INSERT INTO t1 VALUES + (1,'Arizona','Phoenix'), + (2,'Hawaii','Honolulu'), + (3,'Georgia','Atlanta'), + (4,'Florida','Tallahassee'), + (5,'Alaska','Juneau'), + (6,'Michigan','Lansing'), + (7,'Pennsylvania','Harrisburg'), + (8,'Virginia','Richmond') +; + +EXPLAIN +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 + OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; +SELECT * FROM t1 FORCE KEY (state,capital) +WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9 + OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas'; + +DROP TABLE t1; + #the following command must be the last one in the file set session optimizer_switch='index_merge_sort_intersection=default'; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index a40363ff9ab..7f159016ff8 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9335,6 +9335,13 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2) if (!tmp->next_key_part) { + if (key2->use_count) + { + SEL_ARG *key2_cpy= new SEL_ARG(*key2); + if (key2_cpy) + return 0; + key2= key2_cpy; + } /* tmp->next_key_part is empty: cut the range that is covered by tmp from key2. @@ -9366,13 +9373,6 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2) key2: [---] tmp: [---------] */ - if (key2->use_count) - { - SEL_ARG *key2_cpy= new SEL_ARG(*key2); - if (key2_cpy) - return 0; - key2= key2_cpy; - } key2->copy_max_to_min(tmp); continue; } From 46eef1ede2ddfceaa056a71ea52ecacdde2bc44e Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 23 Jan 2017 19:40:22 -0800 Subject: [PATCH 02/43] Fixed bug mdev-11859. As the function Item_subselect::fix_fields does it the function Item_subselect::update_used_tables must ignore UNCACHEABLE_EXPLAIN when deciding whether the subquery item should be considered as a constant item. --- mysql-test/r/ps.result | 70 ++++++++++++++++++++++++++++++++++++++++++ mysql-test/t/ps.test | 33 ++++++++++++++++++++ sql/item_subselect.cc | 2 +- 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index bb8b76faa49..f954583a097 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -4103,4 +4103,74 @@ NULL NULL deallocate prepare stmt; drop table t1,t2,t3,t4; +# +# MDEV-11859: the plans for the first and the second executions +# of PS are not the same +# +create table t1 (id int, c varchar(3), key idx(c))engine=myisam; +insert into t1 values (3,'bar'), (1,'xxx'), (2,'foo'), (5,'yyy'); +prepare stmt1 from +"explain extended + select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'"; +execute stmt1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ref idx idx 6 const 1 100.00 Using index condition +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`c` = 'foo') +execute stmt1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ref idx idx 6 const 1 100.00 Using index condition +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`c` = 'foo') +deallocate prepare stmt1; +prepare stmt1 from +"select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'"; +flush status; +execute stmt1; +id c +2 foo +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 1 +Handler_read_last 0 +Handler_read_next 1 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 0 +flush status; +execute stmt1; +id c +2 foo +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 1 +Handler_read_last 0 +Handler_read_next 1 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 0 +deallocate prepare stmt1; +prepare stmt2 from +"explain extended + select * from t1 where (1, 2) in ( select 3, 4 )"; +execute stmt2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where 0 +execute stmt2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where 0 +deallocate prepare stmt2; +drop table t1; # End of 5.5 tests diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 1516acca01e..cfd810fd625 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3680,5 +3680,38 @@ EXECUTE stmt; deallocate prepare stmt; drop table t1,t2,t3,t4; +--echo # +--echo # MDEV-11859: the plans for the first and the second executions +--echo # of PS are not the same +--echo # + +create table t1 (id int, c varchar(3), key idx(c))engine=myisam; +insert into t1 values (3,'bar'), (1,'xxx'), (2,'foo'), (5,'yyy'); + +prepare stmt1 from +"explain extended + select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from +"select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'"; +flush status; +execute stmt1; +show status like '%Handler_read%'; +flush status; +execute stmt1; +show status like '%Handler_read%'; +deallocate prepare stmt1; + +prepare stmt2 from +"explain extended + select * from t1 where (1, 2) in ( select 3, 4 )"; +execute stmt2; +execute stmt2; +deallocate prepare stmt2; + +drop table t1; --echo # End of 5.5 tests diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 5750de713e6..5e00220db55 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -878,7 +878,7 @@ void Item_subselect::update_used_tables() if (!forced_const) { recalc_used_tables(parent_select, FALSE); - if (!engine->uncacheable()) + if (!(engine->uncacheable() & ~UNCACHEABLE_EXPLAIN)) { // did all used tables become static? if (!(used_tables_cache & ~engine->upper_select_const_tables())) From 5c9baf54e7af994391aa0510f666b364ff2e657b Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 27 Jan 2017 16:46:26 +0200 Subject: [PATCH 03/43] Fix for memory leak in applications, like QT,that calls my_thread_global_init() + my_thrad_global_end() repeatadily. This caused THR_KEY_mysys to be allocated multiple times. Deletion of THR_KEY_mysys was originally in my_thread_global_end() but was moved to my_end() as DBUG uses THR_KEY_mysys and DBUG is released after my_thread_global_end() is called. Releasing DBUG before my_thread_global_end() and move THR_KEY_mysys back into my_thread_global_end() could be a solution, but as safe_mutex and other things called by my_thread_global_end is using DBUG it may not be completely safe. To solve this, I used the simple solution to add a marker that THR_KEY_mysys is created and not re-create it in my_thread_global_init if it already exists. --- include/my_sys.h | 2 +- mysys/my_init.c | 2 +- mysys/my_thr_init.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 5392a94d27e..967228790ae 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -227,7 +227,7 @@ extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; extern ulong my_file_total_opened; extern ulong my_sync_count; extern uint mysys_usage_id; -extern my_bool my_init_done; +extern my_bool my_init_done, my_thr_key_mysys_exists; extern my_bool my_assert_on_error; extern myf my_global_flags; /* Set to MY_WME for more error messages */ /* Point to current my_message() */ diff --git a/mysys/my_init.c b/mysys/my_init.c index 99efba14a73..5f6650f0ec9 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -226,7 +226,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", /* At very last, delete mysys key, it is used everywhere including DBUG */ pthread_key_delete(THR_KEY_mysys); - my_init_done=0; + my_init_done= my_thr_key_mysys_exists= 0; } /* my_end */ #ifndef DBUG_OFF diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 3e4d091944b..aefd3564185 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -60,6 +60,8 @@ static uint get_thread_lib(void); /** True if @c my_thread_global_init() has been called. */ static my_bool my_thread_global_init_done= 0; +/* True if THR_KEY_mysys is created */ +my_bool my_thr_key_mysys_exists= 0; /* @@ -185,11 +187,20 @@ my_bool my_thread_global_init(void) return 0; my_thread_global_init_done= 1; - if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0) + /* + THR_KEY_mysys is deleted in my_end() as DBUG libraries are using it even + after my_thread_global_end() is called. + my_thr_key_mysys_exist is used to protect against application like QT + that calls my_thread_global_init() + my_thread_global_end() multiple times + without calling my_init() + my_end(). + */ + if (!my_thr_key_mysys_exists && + (pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0) { fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret); return 1; } + my_thr_key_mysys_exists= 1; /* Mutex used by my_thread_init() and after my_thread_destroy_mutex() */ my_thread_init_internal_mutex(); From 60c932a3d025d94bd319da4f34e7c498205e4206 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 27 Jan 2017 16:47:00 +0200 Subject: [PATCH 04/43] backported build-tags from 10.2 to ensure that 'make tags' works again with xemacs --- support-files/build-tags | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/support-files/build-tags b/support-files/build-tags index c37485e32f9..03b243ee8cc 100755 --- a/support-files/build-tags +++ b/support-files/build-tags @@ -1,12 +1,16 @@ #! /bin/sh rm -f TAGS -filter='\.cpp$\|\.cc$\|\.c$\|\.h$\|sql_yacc\.yy$\|\.hpp$\|\.ic$' -list="find . -type f" -git rev-parse >/dev/null 2>/dev/null && list="git ls-files" - -$list |grep $filter |while read f; -do - etags -o TAGS --append $f -done +if git rev-parse HEAD >/dev/null 2>&1 +then + cd `git rev-parse --show-toplevel` + echo client storage dbug libmysql sql-common \ + sql extra mysys mysys_ssl strings regex pcre vio include \ + tools unittest plugin libmysqld | \ + xargs -n1 git ls-files | grep -v '\.jar$' | \ + xargs etags -o TAGS --append +else + find . -type f ! -name "*.jar" | + xargs etags -o TAGS --append +fi From 2e8fa1c2b2867b99b5cc7f987ad64b666e0af2c4 Mon Sep 17 00:00:00 2001 From: Nirbhay Choubey Date: Mon, 13 Feb 2017 17:29:32 -0500 Subject: [PATCH 05/43] MDEV-12058: MariaDB Test Suite issue with test sys_vars.secure_file_priv.test Try to remove bug50373.txt before using it in SELECT .. OUTFILE (in case its a leftover from previous test runs). --- mysql-test/suite/sys_vars/t/secure_file_priv.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mysql-test/suite/sys_vars/t/secure_file_priv.test b/mysql-test/suite/sys_vars/t/secure_file_priv.test index 5c53da58275..a5a465d8c98 100644 --- a/mysql-test/suite/sys_vars/t/secure_file_priv.test +++ b/mysql-test/suite/sys_vars/t/secure_file_priv.test @@ -21,6 +21,9 @@ SHOW VARIABLES LIKE 'secure_file_priv'; --perl use File::Basename; my $protected_file= dirname($ENV{MYSQLTEST_VARDIR}).'/bug50373.txt'; +# Ensure bug50373.txt does not exist (e.g. leftover from previous +# test runs). +unlink $protected_file; open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/bug50373.inc") or die; print FILE "SELECT * FROM t1 INTO OUTFILE '".$protected_file."';\n"; print FILE "DELETE FROM t1;\n"; From 108b211ee2aa3944f060850a2522fb28c75f6158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 16 Feb 2017 12:02:31 +0200 Subject: [PATCH 06/43] Fix gcc 6.3.x compiler warnings. These are caused by fact that functions are declared with __attribute__((nonnull)) or left shit like ~0 << macro when ~0U << macro should be used. --- storage/innobase/btr/btr0btr.c | 1 - storage/innobase/btr/btr0cur.c | 8 +------- storage/innobase/buf/buf0buddy.c | 1 - storage/innobase/dict/dict0crea.c | 10 +++++----- storage/innobase/dict/dict0dict.c | 1 - storage/innobase/dict/dict0load.c | 8 ++++---- storage/innobase/dict/dict0mem.c | 2 +- storage/innobase/dyn/dyn0dyn.c | 1 - storage/innobase/fil/fil0fil.c | 2 +- storage/innobase/fsp/fsp0fsp.c | 5 ----- storage/innobase/include/dict0dict.ic | 7 ------- storage/innobase/include/dict0mem.h | 12 ++++++------ storage/innobase/include/dyn0dyn.ic | 10 ---------- storage/innobase/include/fsp0fsp.h | 2 +- storage/innobase/include/mach0data.ic | 13 ------------- storage/innobase/include/mtr0mtr.ic | 1 - storage/innobase/include/page0page.ic | 1 - storage/innobase/include/rem0rec.ic | 1 - storage/innobase/include/ut0lst.h | 3 --- storage/innobase/mtr/mtr0mtr.c | 1 - storage/innobase/page/page0page.c | 2 -- storage/innobase/page/page0zip.c | 1 - storage/innobase/rem/rem0rec.c | 3 +-- storage/innobase/row/row0merge.c | 12 ------------ storage/innobase/row/row0purge.c | 3 --- storage/innobase/row/row0upd.c | 4 ---- storage/innobase/trx/trx0trx.c | 1 - storage/xtradb/btr/btr0btr.c | 1 - storage/xtradb/btr/btr0cur.c | 10 ++-------- storage/xtradb/buf/buf0buddy.c | 1 - storage/xtradb/dict/dict0crea.c | 10 +++++----- storage/xtradb/dict/dict0dict.c | 1 - storage/xtradb/dict/dict0load.c | 10 +++++----- storage/xtradb/dict/dict0mem.c | 2 +- storage/xtradb/dyn/dyn0dyn.c | 1 - storage/xtradb/fil/fil0fil.c | 2 +- storage/xtradb/fsp/fsp0fsp.c | 5 ----- storage/xtradb/include/btr0sea.ic | 4 ---- storage/xtradb/include/dict0dict.ic | 7 ------- storage/xtradb/include/dict0mem.h | 12 ++++++------ storage/xtradb/include/dyn0dyn.ic | 10 ---------- storage/xtradb/include/fsp0fsp.h | 2 +- storage/xtradb/include/mach0data.ic | 13 ------------- storage/xtradb/include/mtr0mtr.ic | 1 - storage/xtradb/include/page0page.ic | 1 - storage/xtradb/include/rem0rec.ic | 1 - storage/xtradb/include/trx0trx.h | 1 + storage/xtradb/include/ut0lst.h | 3 --- storage/xtradb/mtr/mtr0mtr.c | 1 - storage/xtradb/page/page0page.c | 2 -- storage/xtradb/page/page0zip.c | 1 - storage/xtradb/rem/rem0rec.c | 3 +-- storage/xtradb/row/row0merge.c | 12 ------------ storage/xtradb/row/row0purge.c | 3 --- storage/xtradb/row/row0upd.c | 4 ---- storage/xtradb/trx/trx0trx.c | 1 - 56 files changed, 43 insertions(+), 198 deletions(-) diff --git a/storage/innobase/btr/btr0btr.c b/storage/innobase/btr/btr0btr.c index ede72ba57bb..58d816559d4 100644 --- a/storage/innobase/btr/btr0btr.c +++ b/storage/innobase/btr/btr0btr.c @@ -2932,7 +2932,6 @@ btr_level_list_remove_func( ulint prev_page_no; ulint next_page_no; - ut_ad(page && mtr); ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX)); ut_ad(space == page_get_space_id(page)); /* Get the previous and next page numbers of page */ diff --git a/storage/innobase/btr/btr0cur.c b/storage/innobase/btr/btr0cur.c index 3b533909e67..2c1ab4bffae 100644 --- a/storage/innobase/btr/btr0cur.c +++ b/storage/innobase/btr/btr0cur.c @@ -1877,7 +1877,6 @@ btr_cur_update_alloc_zip( mtr_t* mtr) /*!< in: mini-transaction */ { ut_a(page_zip == buf_block_get_page_zip(block)); - ut_ad(page_zip); ut_ad(!dict_index_is_ibuf(index)); if (page_zip_available(page_zip, dict_index_is_clust(index), @@ -2837,7 +2836,7 @@ btr_cur_del_mark_set_clust_rec( ut_ad(page_is_leaf(page_align(rec))); #ifdef UNIV_DEBUG - if (btr_cur_print_record_ops && thr) { + if (btr_cur_print_record_ops) { btr_cur_trx_report(thr_get_trx(thr), index, "del mark "); rec_print_new(stderr, rec, offsets); } @@ -4128,7 +4127,6 @@ btr_cur_disown_inherited_fields( ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec)); ut_ad(rec_offs_any_extern(offsets)); - ut_ad(mtr); for (i = 0; i < rec_offs_n_fields(offsets); i++) { if (rec_offs_nth_extern(offsets, i) @@ -4191,9 +4189,6 @@ btr_push_update_extern_fields( ulint n; const upd_field_t* uf; - ut_ad(tuple); - ut_ad(update); - uf = update->fields; n = upd_get_n_fields(update); @@ -4366,7 +4361,6 @@ btr_store_big_rec_extern_fields( ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(rec_offs_any_extern(offsets)); - ut_ad(btr_mtr); ut_ad(mtr_memo_contains(btr_mtr, dict_index_get_lock(index), MTR_MEMO_X_LOCK)); ut_ad(mtr_memo_contains(btr_mtr, rec_block, MTR_MEMO_PAGE_X_FIX)); diff --git a/storage/innobase/buf/buf0buddy.c b/storage/innobase/buf/buf0buddy.c index 9277a89ce66..fa2515eddc2 100644 --- a/storage/innobase/buf/buf0buddy.c +++ b/storage/innobase/buf/buf0buddy.c @@ -276,7 +276,6 @@ buf_buddy_alloc_low( { buf_block_t* block; - ut_ad(lru); ut_ad(buf_pool_mutex_own(buf_pool)); ut_ad(!mutex_own(&buf_pool->zip_mutex)); ut_ad(i >= buf_buddy_get_slot(PAGE_ZIP_MIN_SIZE)); diff --git a/storage/innobase/dict/dict0crea.c b/storage/innobase/dict/dict0crea.c index f8bcc6f2d5f..4e173fb905d 100644 --- a/storage/innobase/dict/dict0crea.c +++ b/storage/innobase/dict/dict0crea.c @@ -112,13 +112,13 @@ dict_create_sys_tables_tuple( dfield = dtuple_get_nth_field(entry, 3/*TYPE*/); ptr = mem_heap_alloc(heap, 4); - if (table->flags & (~DICT_TF_COMPACT & ~(~0 << DICT_TF_BITS))) { + if (table->flags & (~DICT_TF_COMPACT & ~(~0U << DICT_TF_BITS))) { ut_a(table->flags & DICT_TF_COMPACT); ut_a(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); ut_a((table->flags & DICT_TF_ZSSIZE_MASK) <= (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT)); - ut_a(!(table->flags & (~0 << DICT_TF2_BITS))); - mach_write_to_4(ptr, table->flags & ~(~0 << DICT_TF_BITS)); + ut_a(!(table->flags & (~0U << DICT_TF2_BITS))); + mach_write_to_4(ptr, table->flags & ~(~0U << DICT_TF_BITS)); } else { mach_write_to_4(ptr, DICT_TABLE_ORDINARY); } @@ -306,7 +306,7 @@ dict_build_table_def_step( ut_ad(!dict_table_zip_size(table) || dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); - flags = table->flags & ~(~0 << DICT_TF_BITS); + flags = table->flags & ~(~0U << DICT_TF_BITS); error = fil_create_new_single_table_tablespace( space, path_or_name, is_path, flags == DICT_TF_COMPACT ? 0 : flags, @@ -325,7 +325,7 @@ dict_build_table_def_step( mtr_commit(&mtr); } else { /* Create in the system tablespace: disallow new features */ - table->flags &= (~0 << DICT_TF_BITS) | DICT_TF_COMPACT; + table->flags &= (~0U << DICT_TF_BITS) | DICT_TF_COMPACT; } row = dict_create_sys_tables_tuple(table, node->heap); diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index 33b110ce97a..588c2968b6a 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -5848,7 +5848,6 @@ dict_set_corrupted( const char* status; btr_cur_t cursor; - ut_ad(index); ut_ad(mutex_own(&dict_sys->mutex)); ut_ad(!dict_table_is_comp(dict_sys->sys_tables)); ut_ad(!dict_table_is_comp(dict_sys->sys_indexes)); diff --git a/storage/innobase/dict/dict0load.c b/storage/innobase/dict/dict0load.c index 22de23af7ee..d7168b6e4bb 100644 --- a/storage/innobase/dict/dict0load.c +++ b/storage/innobase/dict/dict0load.c @@ -643,7 +643,7 @@ dict_sys_tables_get_flags( return(ULINT_UNDEFINED); } - if (UNIV_UNLIKELY(flags & (~0 << DICT_TF_BITS))) { + if (UNIV_UNLIKELY(flags & (~0U << DICT_TF_BITS))) { /* Some unused bits are set. */ return(ULINT_UNDEFINED); } @@ -1332,7 +1332,7 @@ err_len: goto err_len; } type = mach_read_from_4(field); - if (UNIV_UNLIKELY(type & (~0 << DICT_IT_BITS))) { + if (UNIV_UNLIKELY(type & (~0U << DICT_IT_BITS))) { return("unknown SYS_INDEXES.TYPE bits"); } @@ -1696,7 +1696,7 @@ err_len: flags2 = mach_read_from_4(field); - if (flags2 & (~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { + if (flags2 & (~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { ut_print_timestamp(stderr); fputs(" InnoDB: Warning: table ", stderr); ut_print_filename(stderr, name); @@ -1705,7 +1705,7 @@ err_len: " has unknown flags %lx.\n", (ulong) flags2); - flags2 &= ~(~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT)); + flags2 &= ~(~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT)); } flags |= flags2 << DICT_TF2_SHIFT; diff --git a/storage/innobase/dict/dict0mem.c b/storage/innobase/dict/dict0mem.c index cea7a253ba0..87d03eff3c2 100644 --- a/storage/innobase/dict/dict0mem.c +++ b/storage/innobase/dict/dict0mem.c @@ -69,7 +69,7 @@ dict_mem_table_create( DBUG_ENTER("dict_mem_table_create"); ut_ad(name); - ut_a(!(flags & (~0 << DICT_TF2_BITS))); + ut_a(!(flags & (~0U << DICT_TF2_BITS))); heap = mem_heap_create(DICT_HEAP_SIZE); diff --git a/storage/innobase/dyn/dyn0dyn.c b/storage/innobase/dyn/dyn0dyn.c index d0f50ad0c32..b723877d648 100644 --- a/storage/innobase/dyn/dyn0dyn.c +++ b/storage/innobase/dyn/dyn0dyn.c @@ -40,7 +40,6 @@ dyn_array_add_block( mem_heap_t* heap; dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); if (arr->heap == NULL) { diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index b30e8056c0a..d7ac3dd14eb 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -3308,7 +3308,7 @@ fil_open_single_table_tablespace( } if (space_id != id - || space_flags != (flags & ~(~0 << DICT_TF_BITS))) { + || space_flags != (flags & ~(~0U << DICT_TF_BITS))) { ut_print_timestamp(stderr); fputs(" InnoDB: Error: tablespace id and flags in file ", diff --git a/storage/innobase/fsp/fsp0fsp.c b/storage/innobase/fsp/fsp0fsp.c index 6d00a1f1d4a..e2e27608e5d 100644 --- a/storage/innobase/fsp/fsp0fsp.c +++ b/storage/innobase/fsp/fsp0fsp.c @@ -1285,7 +1285,6 @@ fsp_fill_free_list( ulint i; mtr_t ibuf_mtr; - ut_ad(header && mtr); ut_ad(page_offset(header) == FSP_HEADER_OFFSET); /* Check if we can fill free list from above the free list limit */ @@ -1584,9 +1583,6 @@ fsp_alloc_free_page( ulint page_no; ulint space_size; - ut_ad(mtr); - ut_ad(init_mtr); - header = fsp_get_space_header(space, zip_size, mtr); /* Get the hinted descriptor */ @@ -2602,7 +2598,6 @@ fseg_alloc_free_page_low( ibool success; ulint n; - ut_ad(mtr); ut_ad((direction >= FSP_UP) && (direction <= FSP_NO_DIR)); ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE); diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic index b65cae2a1d8..dbc3ce99ab0 100644 --- a/storage/innobase/include/dict0dict.ic +++ b/storage/innobase/include/dict0dict.ic @@ -247,7 +247,6 @@ dict_index_is_clust( /*================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED)); @@ -261,7 +260,6 @@ dict_index_is_unique( /*=================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_UNIQUE)); @@ -276,7 +274,6 @@ dict_index_is_ibuf( /*===============*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_IBUF)); @@ -293,7 +290,6 @@ dict_index_is_sec_or_ibuf( { ulint type; - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); type = index->type; @@ -311,7 +307,6 @@ dict_table_get_n_user_cols( /*=======================*/ const dict_table_t* table) /*!< in: table */ { - ut_ad(table); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); return(table->n_cols - DATA_N_SYS_COLS); @@ -343,7 +338,6 @@ dict_table_get_n_cols( /*==================*/ const dict_table_t* table) /*!< in: table */ { - ut_ad(table); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); return(table->n_cols); @@ -937,7 +931,6 @@ dict_index_is_corrupted( /*====================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY((index->type & DICT_CORRUPT) diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index a58bb914be2..1b12c8303bb 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -85,9 +85,14 @@ combination of types */ /** File format */ /* @{ */ +#define DICT_TF_BITS 6 /*!< number of flag bits */ +#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX +# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX" +#endif + #define DICT_TF_FORMAT_SHIFT 5 /* file format */ #define DICT_TF_FORMAT_MASK \ -((~(~0 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) +((~(~0U << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) #define DICT_TF_FORMAT_51 0 /*!< InnoDB/MySQL up to 5.1 */ #define DICT_TF_FORMAT_ZIP 1 /*!< InnoDB plugin for 5.1: compressed tables, @@ -98,11 +103,6 @@ combination of types */ /** Minimum supported file format */ #define DICT_TF_FORMAT_MIN DICT_TF_FORMAT_51 -/* @} */ -#define DICT_TF_BITS 6 /*!< number of flag bits */ -#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX -# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX" -#endif /* @} */ /** @brief Additional table flags. diff --git a/storage/innobase/include/dyn0dyn.ic b/storage/innobase/include/dyn0dyn.ic index 177877ed1fd..2565a249271 100644 --- a/storage/innobase/include/dyn0dyn.ic +++ b/storage/innobase/include/dyn0dyn.ic @@ -47,8 +47,6 @@ dyn_block_get_used( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ { - ut_ad(block); - return((block->used) & ~DYN_BLOCK_FULL_FLAG); } @@ -61,8 +59,6 @@ dyn_block_get_data( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ { - ut_ad(block); - return((byte*) block->data); } @@ -76,7 +72,6 @@ dyn_array_create( dyn_array_t* arr) /*!< in/out: memory buffer of size sizeof(dyn_array_t) */ { - ut_ad(arr); #if DYN_ARRAY_DATA_SIZE >= DYN_BLOCK_FULL_FLAG # error "DYN_ARRAY_DATA_SIZE >= DYN_BLOCK_FULL_FLAG" #endif @@ -119,7 +114,6 @@ dyn_array_push( dyn_block_t* block; ulint used; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); ut_ad(size <= DYN_ARRAY_DATA_SIZE); ut_ad(size); @@ -159,7 +153,6 @@ dyn_array_open( { dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); ut_ad(size <= DYN_ARRAY_DATA_SIZE); ut_ad(size); @@ -195,7 +188,6 @@ dyn_array_close( { dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); block = dyn_array_get_last_block(arr); @@ -222,7 +214,6 @@ dyn_array_get_element( { const dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); /* Get the first array block */ @@ -260,7 +251,6 @@ dyn_array_get_data_size( const dyn_block_t* block; ulint sum = 0; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); if (arr->heap == NULL) { diff --git a/storage/innobase/include/fsp0fsp.h b/storage/innobase/include/fsp0fsp.h index f07e3decc66..0b813182947 100644 --- a/storage/innobase/include/fsp0fsp.h +++ b/storage/innobase/include/fsp0fsp.h @@ -42,7 +42,7 @@ Created 12/18/1995 Heikki Tuuri #define FSP_FLAGS_POS_PAGE_SSIZE 6 /** Bit mask of the PAGE_SSIZE field */ #define FSP_FLAGS_MASK_PAGE_SSIZE \ - ((~(~0 << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ + ((~(~0U << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ << FSP_FLAGS_POS_PAGE_SSIZE) /** Return the value of the PAGE_SSIZE field */ #define FSP_FLAGS_GET_PAGE_SSIZE(flags) \ diff --git a/storage/innobase/include/mach0data.ic b/storage/innobase/include/mach0data.ic index 238a56577af..fdcb07ca29b 100644 --- a/storage/innobase/include/mach0data.ic +++ b/storage/innobase/include/mach0data.ic @@ -50,7 +50,6 @@ mach_read_from_1( /*=============*/ const byte* b) /*!< in: pointer to byte */ { - ut_ad(b); return((ulint)(b[0])); } @@ -143,7 +142,6 @@ mach_read_from_3( /*=============*/ const byte* b) /*!< in: pointer to 3 bytes */ { - ut_ad(b); return( ((ulint)(b[0]) << 16) | ((ulint)(b[1]) << 8) | (ulint)(b[2]) @@ -178,7 +176,6 @@ mach_read_from_4( /*=============*/ const byte* b) /*!< in: pointer to four bytes */ { - ut_ad(b); return( ((ulint)(b[0]) << 24) | ((ulint)(b[1]) << 16) | ((ulint)(b[2]) << 8) @@ -255,8 +252,6 @@ mach_read_compressed( { ulint flag; - ut_ad(b); - flag = mach_read_from_1(b); if (flag < 0x80UL) { @@ -333,8 +328,6 @@ mach_read_from_7( /*=============*/ const byte* b) /*!< in: pointer to 7 bytes */ { - ut_ad(b); - return(ut_ull_create(mach_read_from_3(b), mach_read_from_4(b + 3))); } @@ -364,8 +357,6 @@ mach_read_from_6( /*=============*/ const byte* b) /*!< in: pointer to 6 bytes */ { - ut_ad(b); - return(ut_ull_create(mach_read_from_2(b), mach_read_from_4(b + 2))); } @@ -413,8 +404,6 @@ mach_ull_read_compressed( ib_uint64_t n; ulint size; - ut_ad(b); - n = (ib_uint64_t) mach_read_compressed(b); size = mach_get_compressed_size((ulint) n); @@ -480,8 +469,6 @@ mach_ull_read_much_compressed( ib_uint64_t n; ulint size; - ut_ad(b); - if (*b != (byte)0xFF) { n = 0; size = 0; diff --git a/storage/innobase/include/mtr0mtr.ic b/storage/innobase/include/mtr0mtr.ic index a03a0271535..c9e2f2e39de 100644 --- a/storage/innobase/include/mtr0mtr.ic +++ b/storage/innobase/include/mtr0mtr.ic @@ -149,7 +149,6 @@ mtr_memo_contains( dyn_array_t* memo; ulint offset; - ut_ad(mtr); ut_ad(mtr->magic_n == MTR_MAGIC_N); ut_ad(mtr->state == MTR_ACTIVE || mtr->state == MTR_COMMITTING); diff --git a/storage/innobase/include/page0page.ic b/storage/innobase/include/page0page.ic index 781ad029e87..1689c0ade6b 100644 --- a/storage/innobase/include/page0page.ic +++ b/storage/innobase/include/page0page.ic @@ -154,7 +154,6 @@ page_header_get_offs( { ulint offs; - ut_ad(page); ut_ad((field == PAGE_FREE) || (field == PAGE_LAST_INSERT) || (field == PAGE_HEAP_TOP)); diff --git a/storage/innobase/include/rem0rec.ic b/storage/innobase/include/rem0rec.ic index 564d2d1b31c..c81388391d7 100644 --- a/storage/innobase/include/rem0rec.ic +++ b/storage/innobase/include/rem0rec.ic @@ -1545,7 +1545,6 @@ rec_copy( ulint extra_len; ulint data_len; - ut_ad(rec && buf); ut_ad(rec_offs_validate((rec_t*) rec, NULL, offsets)); ut_ad(rec_validate(rec, offsets)); diff --git a/storage/innobase/include/ut0lst.h b/storage/innobase/include/ut0lst.h index a010f464570..1fb43fd4805 100644 --- a/storage/innobase/include/ut0lst.h +++ b/storage/innobase/include/ut0lst.h @@ -88,7 +88,6 @@ Adds the node as the first element in a two-way linked list. */ #define UT_LIST_ADD_FIRST(NAME, BASE, N)\ {\ - ut_ad(N);\ ((BASE).count)++;\ ((N)->NAME).next = (BASE).start;\ ((N)->NAME).prev = NULL;\ @@ -134,7 +133,6 @@ Inserts a NODE2 after NODE1 in a list. #define UT_LIST_INSERT_AFTER(NAME, BASE, NODE1, NODE2)\ {\ ut_ad(NODE1);\ - ut_ad(NODE2);\ ut_ad((NODE1) != (NODE2));\ ((BASE).count)++;\ ((NODE2)->NAME).prev = (NODE1);\ @@ -169,7 +167,6 @@ Removes a node from a two-way linked list. */ #define UT_LIST_REMOVE(NAME, BASE, N) \ do { \ - ut_ad(N); \ ut_a((BASE).count > 0); \ ((BASE).count)--; \ if (((N)->NAME).next != NULL) { \ diff --git a/storage/innobase/mtr/mtr0mtr.c b/storage/innobase/mtr/mtr0mtr.c index a5c98761523..ebad6e7bfa1 100644 --- a/storage/innobase/mtr/mtr0mtr.c +++ b/storage/innobase/mtr/mtr0mtr.c @@ -257,7 +257,6 @@ mtr_commit( /*=======*/ mtr_t* mtr) /*!< in: mini-transaction */ { - ut_ad(mtr); ut_ad(mtr->magic_n == MTR_MAGIC_N); ut_ad(mtr->state == MTR_ACTIVE); ut_ad(!mtr->inside_ibuf); diff --git a/storage/innobase/page/page0page.c b/storage/innobase/page/page0page.c index 81051f8f4fe..9af4b1c8faa 100644 --- a/storage/innobase/page/page0page.c +++ b/storage/innobase/page/page0page.c @@ -1345,7 +1345,6 @@ page_dir_split_slot( ulint i; ulint n_owned; - ut_ad(page); ut_ad(!page_zip || page_is_comp(page)); ut_ad(slot_no > 0); @@ -1407,7 +1406,6 @@ page_dir_balance_slot( rec_t* old_rec; rec_t* new_rec; - ut_ad(page); ut_ad(!page_zip || page_is_comp(page)); ut_ad(slot_no > 0); diff --git a/storage/innobase/page/page0zip.c b/storage/innobase/page/page0zip.c index 7c04e0b9183..faa004be730 100644 --- a/storage/innobase/page/page0zip.c +++ b/storage/innobase/page/page0zip.c @@ -4739,7 +4739,6 @@ page_zip_parse_compress( ulint size; ulint trailer_size; - ut_ad(ptr && end_ptr); ut_ad(!page == !page_zip); if (UNIV_UNLIKELY(ptr + (2 + 2) > end_ptr)) { diff --git a/storage/innobase/rem/rem0rec.c b/storage/innobase/rem/rem0rec.c index f7252594c29..7f435a92489 100644 --- a/storage/innobase/rem/rem0rec.c +++ b/storage/innobase/rem/rem0rec.c @@ -791,8 +791,7 @@ rec_get_converted_size_comp_prefix_low( ulint extra_size; ulint data_size; ulint i; - ut_ad(index); - ut_ad(fields); + ut_ad(n_fields > 0); ut_ad(n_fields <= dict_index_get_n_fields(index)); ut_ad(!temp || extra); diff --git a/storage/innobase/row/row0merge.c b/storage/innobase/row/row0merge.c index 7d87d1f9c8f..a393254d145 100644 --- a/storage/innobase/row/row0merge.c +++ b/storage/innobase/row/row0merge.c @@ -807,14 +807,8 @@ row_merge_read_rec( ulint data_size; ulint avail_size; - ut_ad(block); - ut_ad(buf); ut_ad(b >= block[0]); ut_ad(b < block[1]); - ut_ad(index); - ut_ad(foffs); - ut_ad(mrec); - ut_ad(offsets); ut_ad(*offsets == 1 + REC_OFFS_HEADER_SIZE + dict_index_get_n_fields(index)); @@ -1175,12 +1169,6 @@ row_merge_read_clustered_index( trx->op_info = "reading clustered index"; - ut_ad(trx); - ut_ad(old_table); - ut_ad(new_table); - ut_ad(index); - ut_ad(files); - /* Create and initialize memory for record buffers */ merge_buf = mem_alloc(n_index * sizeof *merge_buf); diff --git a/storage/innobase/row/row0purge.c b/storage/innobase/row/row0purge.c index 9018582f5d6..5f3e4175544 100644 --- a/storage/innobase/row/row0purge.c +++ b/storage/innobase/row/row0purge.c @@ -751,9 +751,6 @@ row_purge( { ibool updated_extern; - ut_ad(node); - ut_ad(thr); - node->undo_rec = trx_purge_fetch_next_rec(&node->roll_ptr, &node->reservation, node->heap); diff --git a/storage/innobase/row/row0upd.c b/storage/innobase/row/row0upd.c index e7ac42a566f..4b23165cc59 100644 --- a/storage/innobase/row/row0upd.c +++ b/storage/innobase/row/row0upd.c @@ -1066,8 +1066,6 @@ row_upd_index_replace_new_col_vals_index_pos( ulint n_fields; const ulint zip_size = dict_table_zip_size(index->table); - ut_ad(index); - dtuple_set_info_bits(entry, update->info_bits); if (order_only) { @@ -1250,8 +1248,6 @@ row_upd_changes_ord_field_binary_func( ulint i; const dict_index_t* clust_index; - ut_ad(index); - ut_ad(update); ut_ad(thr); ut_ad(thr->graph); ut_ad(thr->graph->trx); diff --git a/storage/innobase/trx/trx0trx.c b/storage/innobase/trx/trx0trx.c index 2d585b7507f..151e70013f9 100644 --- a/storage/innobase/trx/trx0trx.c +++ b/storage/innobase/trx/trx0trx.c @@ -97,7 +97,6 @@ trx_create( trx_t* trx; ut_ad(mutex_own(&kernel_mutex)); - ut_ad(sess); trx = mem_alloc(sizeof(trx_t)); diff --git a/storage/xtradb/btr/btr0btr.c b/storage/xtradb/btr/btr0btr.c index 0c429363789..fb670df2329 100644 --- a/storage/xtradb/btr/btr0btr.c +++ b/storage/xtradb/btr/btr0btr.c @@ -2974,7 +2974,6 @@ btr_level_list_remove_func( ulint prev_page_no; ulint next_page_no; - ut_ad(page && mtr); ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX)); ut_ad(space == page_get_space_id(page)); /* Get the previous and next page numbers of page */ diff --git a/storage/xtradb/btr/btr0cur.c b/storage/xtradb/btr/btr0cur.c index 0ec9367b27c..d9c1a2ef7a8 100644 --- a/storage/xtradb/btr/btr0cur.c +++ b/storage/xtradb/btr/btr0cur.c @@ -2008,7 +2008,6 @@ btr_cur_update_alloc_zip( trx_t* trx) /*!< in: NULL or transaction */ { ut_a(page_zip == buf_block_get_page_zip(block)); - ut_ad(page_zip); ut_ad(!dict_index_is_ibuf(index)); if (page_zip_available(page_zip, dict_index_is_clust(index), @@ -3008,7 +3007,7 @@ btr_cur_del_mark_set_clust_rec( ut_ad(page_is_leaf(page_align(rec))); #ifdef UNIV_DEBUG - if (btr_cur_print_record_ops && thr) { + if (btr_cur_print_record_ops) { btr_cur_trx_report(thr_get_trx(thr), index, "del mark "); rec_print_new(stderr, rec, offsets); } @@ -3017,7 +3016,7 @@ btr_cur_del_mark_set_clust_rec( ut_ad(dict_index_is_clust(index)); ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets))); - if (UNIV_UNLIKELY(thr && thr_get_trx(thr)->fake_changes)) { + if (UNIV_UNLIKELY(thr_get_trx(thr)->fake_changes)) { /* skip LOCK, UNDO, CHANGE, LOG */ return(DB_SUCCESS); } @@ -4323,7 +4322,6 @@ btr_cur_disown_inherited_fields( ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec)); ut_ad(rec_offs_any_extern(offsets)); - ut_ad(mtr); for (i = 0; i < rec_offs_n_fields(offsets); i++) { if (rec_offs_nth_extern(offsets, i) @@ -4386,9 +4384,6 @@ btr_push_update_extern_fields( ulint n; const upd_field_t* uf; - ut_ad(tuple); - ut_ad(update); - uf = update->fields; n = upd_get_n_fields(update); @@ -4571,7 +4566,6 @@ btr_store_big_rec_extern_fields( ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(rec_offs_any_extern(offsets)); - ut_ad(btr_mtr); ut_ad(mtr_memo_contains(btr_mtr, dict_index_get_lock(index), MTR_MEMO_X_LOCK)); ut_ad(mtr_memo_contains(btr_mtr, rec_block, MTR_MEMO_PAGE_X_FIX)); diff --git a/storage/xtradb/buf/buf0buddy.c b/storage/xtradb/buf/buf0buddy.c index 439be08b01f..493d0d2d41c 100644 --- a/storage/xtradb/buf/buf0buddy.c +++ b/storage/xtradb/buf/buf0buddy.c @@ -288,7 +288,6 @@ buf_buddy_alloc_low( { buf_block_t* block; - ut_ad(lru); //ut_ad(buf_pool_mutex_own(buf_pool)); ut_ad(mutex_own(&buf_pool->LRU_list_mutex)); ut_ad(!mutex_own(&buf_pool->zip_mutex)); diff --git a/storage/xtradb/dict/dict0crea.c b/storage/xtradb/dict/dict0crea.c index b44fdc1d2e4..1529c22bbb9 100644 --- a/storage/xtradb/dict/dict0crea.c +++ b/storage/xtradb/dict/dict0crea.c @@ -112,13 +112,13 @@ dict_create_sys_tables_tuple( dfield = dtuple_get_nth_field(entry, 3/*TYPE*/); ptr = mem_heap_alloc(heap, 4); - if (table->flags & (~DICT_TF_COMPACT & ~(~0 << DICT_TF_BITS))) { + if (table->flags & (~DICT_TF_COMPACT & ~(~0U << DICT_TF_BITS))) { ut_a(table->flags & DICT_TF_COMPACT); ut_a(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); ut_a(((ulonglong) table->flags & DICT_TF_ZSSIZE_MASK) <= (ulonglong) (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT)); - ut_a(!(table->flags & (~0 << DICT_TF2_BITS))); - mach_write_to_4(ptr, table->flags & ~(~0 << DICT_TF_BITS)); + ut_a(!(table->flags & (~0U << DICT_TF2_BITS))); + mach_write_to_4(ptr, table->flags & ~(~0U << DICT_TF_BITS)); } else { mach_write_to_4(ptr, DICT_TABLE_ORDINARY); } @@ -306,7 +306,7 @@ dict_build_table_def_step( ut_ad(!dict_table_zip_size(table) || dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); - flags = table->flags & ~(~0 << DICT_TF_BITS); + flags = table->flags & ~(~0U << DICT_TF_BITS); error = fil_create_new_single_table_tablespace( space, path_or_name, is_path, flags == DICT_TF_COMPACT ? 0 : flags, @@ -325,7 +325,7 @@ dict_build_table_def_step( mtr_commit(&mtr); } else { /* Create in the system tablespace: disallow new features */ - table->flags &= (~0 << DICT_TF_BITS) | DICT_TF_COMPACT; + table->flags &= (~0U << DICT_TF_BITS) | DICT_TF_COMPACT; } row = dict_create_sys_tables_tuple(table, node->heap); diff --git a/storage/xtradb/dict/dict0dict.c b/storage/xtradb/dict/dict0dict.c index 87d7a3b2403..5da4509599e 100644 --- a/storage/xtradb/dict/dict0dict.c +++ b/storage/xtradb/dict/dict0dict.c @@ -6394,7 +6394,6 @@ dict_set_corrupted( const char* status; btr_cur_t cursor; - ut_ad(index); ut_ad(mutex_own(&dict_sys->mutex)); ut_ad(!dict_table_is_comp(dict_sys->sys_tables)); ut_ad(!dict_table_is_comp(dict_sys->sys_indexes)); diff --git a/storage/xtradb/dict/dict0load.c b/storage/xtradb/dict/dict0load.c index 1fdbffee3c8..5184746e48e 100644 --- a/storage/xtradb/dict/dict0load.c +++ b/storage/xtradb/dict/dict0load.c @@ -716,7 +716,7 @@ dict_sys_tables_get_flags( return(ULINT_UNDEFINED); } - if (UNIV_UNLIKELY(flags & (~0 << DICT_TF_BITS))) { + if (UNIV_UNLIKELY(flags & (~0U << DICT_TF_BITS))) { /* Some unused bits are set. */ return(ULINT_UNDEFINED); } @@ -1405,7 +1405,7 @@ err_len: goto err_len; } type = mach_read_from_4(field); - if (UNIV_UNLIKELY(type & (~0 << DICT_IT_BITS))) { + if (UNIV_UNLIKELY(type & (~0U << DICT_IT_BITS))) { return("unknown SYS_INDEXES.TYPE bits"); } @@ -1770,7 +1770,7 @@ err_len: flags2 = mach_read_from_4(field); - if (flags2 & (~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { + if (flags2 & (~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { ut_print_timestamp(stderr); fputs(" InnoDB: Warning: table ", stderr); ut_print_filename(stderr, name); @@ -1779,7 +1779,7 @@ err_len: " has unknown flags %lx.\n", (ulong) flags2); - flags2 &= ~(~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT)); + flags2 &= ~(~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT)); } flags |= flags2 << DICT_TF2_SHIFT; @@ -1912,7 +1912,7 @@ err_exit: if (!fil_open_single_table_tablespace( TRUE, table->space, table->flags == DICT_TF_COMPACT ? 0 : - table->flags & ~(~0 << DICT_TF_BITS), name, NULL)) { + table->flags & ~(~0U << DICT_TF_BITS), name, NULL)) { /* We failed to find a sensible tablespace file */ diff --git a/storage/xtradb/dict/dict0mem.c b/storage/xtradb/dict/dict0mem.c index 40099c06823..18917a30ff6 100644 --- a/storage/xtradb/dict/dict0mem.c +++ b/storage/xtradb/dict/dict0mem.c @@ -69,7 +69,7 @@ dict_mem_table_create( DBUG_ENTER("dict_mem_table_create"); ut_ad(name); - ut_a(!(flags & (~0 << DICT_TF2_BITS))); + ut_a(!(flags & (~0U << DICT_TF2_BITS))); heap = mem_heap_create(DICT_HEAP_SIZE); diff --git a/storage/xtradb/dyn/dyn0dyn.c b/storage/xtradb/dyn/dyn0dyn.c index d0f50ad0c32..b723877d648 100644 --- a/storage/xtradb/dyn/dyn0dyn.c +++ b/storage/xtradb/dyn/dyn0dyn.c @@ -40,7 +40,6 @@ dyn_array_add_block( mem_heap_t* heap; dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); if (arr->heap == NULL) { diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 7682b49e755..86e00dc22e4 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -3883,7 +3883,7 @@ skip_write: } if (space_id != id - || space_flags != (flags & ~(~0 << DICT_TF_BITS))) { + || space_flags != (flags & ~(~0U << DICT_TF_BITS))) { ut_print_timestamp(stderr); fputs(" InnoDB: Error: tablespace id and flags in file ", diff --git a/storage/xtradb/fsp/fsp0fsp.c b/storage/xtradb/fsp/fsp0fsp.c index 772e224f6f7..4477b34f7b4 100644 --- a/storage/xtradb/fsp/fsp0fsp.c +++ b/storage/xtradb/fsp/fsp0fsp.c @@ -1290,7 +1290,6 @@ fsp_fill_free_list( ulint i; mtr_t ibuf_mtr; - ut_ad(header && mtr); ut_ad(page_offset(header) == FSP_HEADER_OFFSET); /* Check if we can fill free list from above the free list limit */ @@ -1589,9 +1588,6 @@ fsp_alloc_free_page( ulint page_no; ulint space_size; - ut_ad(mtr); - ut_ad(init_mtr); - header = fsp_get_space_header(space, zip_size, mtr); /* Get the hinted descriptor */ @@ -2613,7 +2609,6 @@ fseg_alloc_free_page_low( ibool success; ulint n; - ut_ad(mtr); ut_ad((direction >= FSP_UP) && (direction <= FSP_NO_DIR)); ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE); diff --git a/storage/xtradb/include/btr0sea.ic b/storage/xtradb/include/btr0sea.ic index 3f0dfdaa511..677cb52f458 100644 --- a/storage/xtradb/include/btr0sea.ic +++ b/storage/xtradb/include/btr0sea.ic @@ -91,7 +91,6 @@ btr_search_get_hash_table( /*======================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->search_table); return(index->search_table); @@ -103,7 +102,6 @@ btr_search_get_latch( /*=================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->search_latch >= btr_search_latch_arr && index->search_latch < btr_search_latch_arr + btr_search_index_num); @@ -130,8 +128,6 @@ btr_search_index_init( /*===============*/ dict_index_t* index) /*!< in: index */ { - ut_ad(index); - index->search_latch = &btr_search_latch_arr[btr_search_get_key(index->id)]; index->search_table = diff --git a/storage/xtradb/include/dict0dict.ic b/storage/xtradb/include/dict0dict.ic index 6836928ff49..3410c945a80 100644 --- a/storage/xtradb/include/dict0dict.ic +++ b/storage/xtradb/include/dict0dict.ic @@ -247,7 +247,6 @@ dict_index_is_clust( /*================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED)); @@ -261,7 +260,6 @@ dict_index_is_unique( /*=================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_UNIQUE)); @@ -276,7 +274,6 @@ dict_index_is_ibuf( /*===============*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY(index->type & DICT_IBUF)); @@ -293,7 +290,6 @@ dict_index_is_sec_or_ibuf( { ulint type; - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); type = index->type; @@ -311,7 +307,6 @@ dict_table_get_n_user_cols( /*=======================*/ const dict_table_t* table) /*!< in: table */ { - ut_ad(table); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); return(table->n_cols - DATA_N_SYS_COLS); @@ -343,7 +338,6 @@ dict_table_get_n_cols( /*==================*/ const dict_table_t* table) /*!< in: table */ { - ut_ad(table); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); return(table->n_cols); @@ -950,7 +944,6 @@ dict_index_is_corrupted( /*====================*/ const dict_index_t* index) /*!< in: index */ { - ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); return(UNIV_UNLIKELY((index->type & DICT_CORRUPT) diff --git a/storage/xtradb/include/dict0mem.h b/storage/xtradb/include/dict0mem.h index ba98eed7701..07ecc42f045 100644 --- a/storage/xtradb/include/dict0mem.h +++ b/storage/xtradb/include/dict0mem.h @@ -85,9 +85,14 @@ combination of types */ /** File format */ /* @{ */ +#define DICT_TF_BITS 6 /*!< number of flag bits */ +#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX +# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX" +#endif + #define DICT_TF_FORMAT_SHIFT 5 /* file format */ #define DICT_TF_FORMAT_MASK \ -((~(~0 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) +((~(~0U << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) #define DICT_TF_FORMAT_51 0 /*!< InnoDB/MySQL up to 5.1 */ #define DICT_TF_FORMAT_ZIP 1 /*!< InnoDB plugin for 5.1: compressed tables, @@ -98,11 +103,6 @@ combination of types */ /** Minimum supported file format */ #define DICT_TF_FORMAT_MIN DICT_TF_FORMAT_51 -/* @} */ -#define DICT_TF_BITS 6 /*!< number of flag bits */ -#if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX -# error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX" -#endif /* @} */ /** @brief Additional table flags. diff --git a/storage/xtradb/include/dyn0dyn.ic b/storage/xtradb/include/dyn0dyn.ic index 177877ed1fd..2565a249271 100644 --- a/storage/xtradb/include/dyn0dyn.ic +++ b/storage/xtradb/include/dyn0dyn.ic @@ -47,8 +47,6 @@ dyn_block_get_used( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ { - ut_ad(block); - return((block->used) & ~DYN_BLOCK_FULL_FLAG); } @@ -61,8 +59,6 @@ dyn_block_get_data( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ { - ut_ad(block); - return((byte*) block->data); } @@ -76,7 +72,6 @@ dyn_array_create( dyn_array_t* arr) /*!< in/out: memory buffer of size sizeof(dyn_array_t) */ { - ut_ad(arr); #if DYN_ARRAY_DATA_SIZE >= DYN_BLOCK_FULL_FLAG # error "DYN_ARRAY_DATA_SIZE >= DYN_BLOCK_FULL_FLAG" #endif @@ -119,7 +114,6 @@ dyn_array_push( dyn_block_t* block; ulint used; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); ut_ad(size <= DYN_ARRAY_DATA_SIZE); ut_ad(size); @@ -159,7 +153,6 @@ dyn_array_open( { dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); ut_ad(size <= DYN_ARRAY_DATA_SIZE); ut_ad(size); @@ -195,7 +188,6 @@ dyn_array_close( { dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); block = dyn_array_get_last_block(arr); @@ -222,7 +214,6 @@ dyn_array_get_element( { const dyn_block_t* block; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); /* Get the first array block */ @@ -260,7 +251,6 @@ dyn_array_get_data_size( const dyn_block_t* block; ulint sum = 0; - ut_ad(arr); ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N); if (arr->heap == NULL) { diff --git a/storage/xtradb/include/fsp0fsp.h b/storage/xtradb/include/fsp0fsp.h index f07e3decc66..0b813182947 100644 --- a/storage/xtradb/include/fsp0fsp.h +++ b/storage/xtradb/include/fsp0fsp.h @@ -42,7 +42,7 @@ Created 12/18/1995 Heikki Tuuri #define FSP_FLAGS_POS_PAGE_SSIZE 6 /** Bit mask of the PAGE_SSIZE field */ #define FSP_FLAGS_MASK_PAGE_SSIZE \ - ((~(~0 << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ + ((~(~0U << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ << FSP_FLAGS_POS_PAGE_SSIZE) /** Return the value of the PAGE_SSIZE field */ #define FSP_FLAGS_GET_PAGE_SSIZE(flags) \ diff --git a/storage/xtradb/include/mach0data.ic b/storage/xtradb/include/mach0data.ic index 238a56577af..fdcb07ca29b 100644 --- a/storage/xtradb/include/mach0data.ic +++ b/storage/xtradb/include/mach0data.ic @@ -50,7 +50,6 @@ mach_read_from_1( /*=============*/ const byte* b) /*!< in: pointer to byte */ { - ut_ad(b); return((ulint)(b[0])); } @@ -143,7 +142,6 @@ mach_read_from_3( /*=============*/ const byte* b) /*!< in: pointer to 3 bytes */ { - ut_ad(b); return( ((ulint)(b[0]) << 16) | ((ulint)(b[1]) << 8) | (ulint)(b[2]) @@ -178,7 +176,6 @@ mach_read_from_4( /*=============*/ const byte* b) /*!< in: pointer to four bytes */ { - ut_ad(b); return( ((ulint)(b[0]) << 24) | ((ulint)(b[1]) << 16) | ((ulint)(b[2]) << 8) @@ -255,8 +252,6 @@ mach_read_compressed( { ulint flag; - ut_ad(b); - flag = mach_read_from_1(b); if (flag < 0x80UL) { @@ -333,8 +328,6 @@ mach_read_from_7( /*=============*/ const byte* b) /*!< in: pointer to 7 bytes */ { - ut_ad(b); - return(ut_ull_create(mach_read_from_3(b), mach_read_from_4(b + 3))); } @@ -364,8 +357,6 @@ mach_read_from_6( /*=============*/ const byte* b) /*!< in: pointer to 6 bytes */ { - ut_ad(b); - return(ut_ull_create(mach_read_from_2(b), mach_read_from_4(b + 2))); } @@ -413,8 +404,6 @@ mach_ull_read_compressed( ib_uint64_t n; ulint size; - ut_ad(b); - n = (ib_uint64_t) mach_read_compressed(b); size = mach_get_compressed_size((ulint) n); @@ -480,8 +469,6 @@ mach_ull_read_much_compressed( ib_uint64_t n; ulint size; - ut_ad(b); - if (*b != (byte)0xFF) { n = 0; size = 0; diff --git a/storage/xtradb/include/mtr0mtr.ic b/storage/xtradb/include/mtr0mtr.ic index 7b5d268b70f..bebe202e6ac 100644 --- a/storage/xtradb/include/mtr0mtr.ic +++ b/storage/xtradb/include/mtr0mtr.ic @@ -170,7 +170,6 @@ mtr_memo_contains( dyn_array_t* memo; ulint offset; - ut_ad(mtr); ut_ad(mtr->magic_n == MTR_MAGIC_N); ut_ad(mtr->state == MTR_ACTIVE || mtr->state == MTR_COMMITTING); diff --git a/storage/xtradb/include/page0page.ic b/storage/xtradb/include/page0page.ic index 4fe93345ce5..da9fbc5f01d 100644 --- a/storage/xtradb/include/page0page.ic +++ b/storage/xtradb/include/page0page.ic @@ -154,7 +154,6 @@ page_header_get_offs( { ulint offs; - ut_ad(page); ut_ad((field == PAGE_FREE) || (field == PAGE_LAST_INSERT) || (field == PAGE_HEAP_TOP)); diff --git a/storage/xtradb/include/rem0rec.ic b/storage/xtradb/include/rem0rec.ic index b14366312e0..b99d076b500 100644 --- a/storage/xtradb/include/rem0rec.ic +++ b/storage/xtradb/include/rem0rec.ic @@ -1545,7 +1545,6 @@ rec_copy( ulint extra_len; ulint data_len; - ut_ad(rec && buf); ut_ad(rec_offs_validate((rec_t*) rec, NULL, offsets)); ut_ad(rec_validate(rec, offsets)); diff --git a/storage/xtradb/include/trx0trx.h b/storage/xtradb/include/trx0trx.h index eac5eb87703..5da06c83a79 100644 --- a/storage/xtradb/include/trx0trx.h +++ b/storage/xtradb/include/trx0trx.h @@ -508,6 +508,7 @@ struct trx_struct{ trx_release_descriptor(). Different name ensures we notice any new code changing the state. */ + /*------------------------------*/ /* MySQL has a transaction coordinator to coordinate two phase commit between multiple storage engines and the binary log. When diff --git a/storage/xtradb/include/ut0lst.h b/storage/xtradb/include/ut0lst.h index 9bb4bc7723f..2b5f5c7a705 100644 --- a/storage/xtradb/include/ut0lst.h +++ b/storage/xtradb/include/ut0lst.h @@ -88,7 +88,6 @@ Adds the node as the first element in a two-way linked list. */ #define UT_LIST_ADD_FIRST(NAME, BASE, N)\ {\ - ut_ad(N);\ ((BASE).count)++;\ ((N)->NAME).next = (BASE).start;\ ((N)->NAME).prev = NULL;\ @@ -134,7 +133,6 @@ Inserts a NODE2 after NODE1 in a list. #define UT_LIST_INSERT_AFTER(NAME, BASE, NODE1, NODE2)\ {\ ut_ad(NODE1);\ - ut_ad(NODE2);\ ut_ad((NODE1) != (NODE2));\ ((BASE).count)++;\ ((NODE2)->NAME).prev = (NODE1);\ @@ -169,7 +167,6 @@ Removes a node from a two-way linked list. */ #define UT_LIST_REMOVE(NAME, BASE, N) \ do { \ - ut_ad(N); \ ut_a((BASE).count > 0); \ ((BASE).count)--; \ if (((N)->NAME).next != NULL) { \ diff --git a/storage/xtradb/mtr/mtr0mtr.c b/storage/xtradb/mtr/mtr0mtr.c index 083692efd77..d6aed7ee723 100644 --- a/storage/xtradb/mtr/mtr0mtr.c +++ b/storage/xtradb/mtr/mtr0mtr.c @@ -289,7 +289,6 @@ mtr_commit( /*=======*/ mtr_t* mtr) /*!< in: mini-transaction */ { - ut_ad(mtr); ut_ad(mtr->magic_n == MTR_MAGIC_N); ut_ad(mtr->state == MTR_ACTIVE); ut_ad(!mtr->inside_ibuf); diff --git a/storage/xtradb/page/page0page.c b/storage/xtradb/page/page0page.c index f2ce6c9fe16..2dd5a4ba472 100644 --- a/storage/xtradb/page/page0page.c +++ b/storage/xtradb/page/page0page.c @@ -1345,7 +1345,6 @@ page_dir_split_slot( ulint i; ulint n_owned; - ut_ad(page); ut_ad(!page_zip || page_is_comp(page)); ut_ad(slot_no > 0); @@ -1407,7 +1406,6 @@ page_dir_balance_slot( rec_t* old_rec; rec_t* new_rec; - ut_ad(page); ut_ad(!page_zip || page_is_comp(page)); ut_ad(slot_no > 0); diff --git a/storage/xtradb/page/page0zip.c b/storage/xtradb/page/page0zip.c index 3d3605d6362..7482323c9b5 100644 --- a/storage/xtradb/page/page0zip.c +++ b/storage/xtradb/page/page0zip.c @@ -4743,7 +4743,6 @@ page_zip_parse_compress( ulint size; ulint trailer_size; - ut_ad(ptr && end_ptr); ut_ad(!page == !page_zip); if (UNIV_UNLIKELY(ptr + (2 + 2) > end_ptr)) { diff --git a/storage/xtradb/rem/rem0rec.c b/storage/xtradb/rem/rem0rec.c index 69d9e49e693..ef020fe3a80 100644 --- a/storage/xtradb/rem/rem0rec.c +++ b/storage/xtradb/rem/rem0rec.c @@ -791,8 +791,7 @@ rec_get_converted_size_comp_prefix_low( ulint extra_size; ulint data_size; ulint i; - ut_ad(index); - ut_ad(fields); + ut_ad(n_fields > 0); ut_ad(n_fields <= dict_index_get_n_fields(index)); ut_ad(!temp || extra); diff --git a/storage/xtradb/row/row0merge.c b/storage/xtradb/row/row0merge.c index 3a03c7c8578..7409d5a5e1a 100644 --- a/storage/xtradb/row/row0merge.c +++ b/storage/xtradb/row/row0merge.c @@ -823,14 +823,8 @@ row_merge_read_rec( ulint data_size; ulint avail_size; - ut_ad(block); - ut_ad(buf); ut_ad(b >= block[0]); ut_ad(b < block[1]); - ut_ad(index); - ut_ad(foffs); - ut_ad(mrec); - ut_ad(offsets); ut_ad(*offsets == 1 + REC_OFFS_HEADER_SIZE + dict_index_get_n_fields(index)); @@ -1202,12 +1196,6 @@ row_merge_read_clustered_index( trx->op_info = "reading clustered index"; - ut_ad(trx); - ut_ad(old_table); - ut_ad(new_table); - ut_ad(index); - ut_ad(files); - /* Create and initialize memory for record buffers */ merge_buf = mem_alloc(n_index * sizeof *merge_buf); diff --git a/storage/xtradb/row/row0purge.c b/storage/xtradb/row/row0purge.c index 1e87016bc5e..8ada79a2bbc 100644 --- a/storage/xtradb/row/row0purge.c +++ b/storage/xtradb/row/row0purge.c @@ -751,9 +751,6 @@ row_purge( { ibool updated_extern; - ut_ad(node); - ut_ad(thr); - node->undo_rec = trx_purge_fetch_next_rec(&node->roll_ptr, &node->reservation, node->heap); diff --git a/storage/xtradb/row/row0upd.c b/storage/xtradb/row/row0upd.c index c0515c423db..64ae0e3f1d0 100644 --- a/storage/xtradb/row/row0upd.c +++ b/storage/xtradb/row/row0upd.c @@ -1084,8 +1084,6 @@ row_upd_index_replace_new_col_vals_index_pos( ulint n_fields; const ulint zip_size = dict_table_zip_size(index->table); - ut_ad(index); - dtuple_set_info_bits(entry, update->info_bits); if (order_only) { @@ -1268,8 +1266,6 @@ row_upd_changes_ord_field_binary_func( ulint i; const dict_index_t* clust_index; - ut_ad(index); - ut_ad(update); ut_ad(thr); ut_ad(thr->graph); ut_ad(thr->graph->trx); diff --git a/storage/xtradb/trx/trx0trx.c b/storage/xtradb/trx/trx0trx.c index 17cb8374d5c..dd7b8bfdd1d 100644 --- a/storage/xtradb/trx/trx0trx.c +++ b/storage/xtradb/trx/trx0trx.c @@ -218,7 +218,6 @@ trx_create( trx_t* trx; ut_ad(mutex_own(&kernel_mutex)); - ut_ad(sess); trx = mem_alloc(sizeof(trx_t)); From 29d78dbb44ee9890b6bc28873344f20fc9157928 Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Sun, 12 Feb 2017 23:19:48 +0600 Subject: [PATCH 07/43] minor typo in a description of mysql_parse() --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f000fe1a37d..3afabc079d0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5839,7 +5839,7 @@ void mysql_init_multi_delete(LEX *lex) /* - When you modify mysql_parse(), you may need to mofify + When you modify mysql_parse(), you may need to modify mysql_test_parse_for_slave() in this same file. */ From b70cd26d73d727ad871c109b47a8a2645c553fd8 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Fri, 17 Feb 2017 00:57:24 +0200 Subject: [PATCH 08/43] MDEV-11668 rpl.rpl_heartbeat_basic fails sporadically in buildbot On a slow builder, a delay between binlog events on master could occur, which would cause a heartbeat which is not expected by the test. The solution is to monitor the timing of binlog events on the master and only perform the heartbeat check if no critical delays have happened. Additionally, an unused variable was removed (this change is unrelated to the bugfix). --- .../suite/rpl/r/rpl_heartbeat_basic.result | 3 +- .../suite/rpl/t/rpl_heartbeat_basic.test | 46 ++++++++++++++++--- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result index cc9d1f99f7c..f880b33a045 100644 --- a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result +++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result @@ -7,7 +7,6 @@ RESET SLAVE; SET @restore_slave_net_timeout=@@global.slave_net_timeout; RESET MASTER; SET @restore_slave_net_timeout=@@global.slave_net_timeout; -SET @restore_event_scheduler=@@global.event_scheduler; *** Default value *** CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root'; @@ -223,7 +222,7 @@ RESET SLAVE; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_CONNECT_RETRY=20, MASTER_HEARTBEAT_PERIOD=5; include/start_slave.inc SET @@global.event_scheduler=1; -Number of received heartbeat events: 0 +Received heartbeats meet expectations: TRUE DELETE FROM t1; DROP EVENT e1; diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test index ca98690c139..960bbc3be3b 100644 --- a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test +++ b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test @@ -34,7 +34,6 @@ eval SET @restore_slave_heartbeat_timeout=$slave_heartbeat_timeout; --connection master RESET MASTER; SET @restore_slave_net_timeout=@@global.slave_net_timeout; -SET @restore_event_scheduler=@@global.event_scheduler; --echo # @@ -352,21 +351,54 @@ eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTE --connection master # Enable scheduler SET @@global.event_scheduler=1; + --sync_slave_with_master let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1); -# Wait some updates for table t1 from master -let $wait_condition= SELECT COUNT(*)=1 FROM t1 WHERE a > 5; ---source include/wait_condition.inc + +--connection master + +# Whether or not to send a heartbeat is decided on the master, based on +# whether the binlog was updated during the period or not. +# Even with the 1-second event, we cannot make the master to write binary +# logs (or execute SQL) in a timely manner. We can only check that they +# were executed in a timely manner, and if they were not, neutralize the +# heartbeat check on the slave. +# We will wait for 5 events, and keep checking 'Binlog_commits' on master. +# Time interval between consequent events will be measured. +# We can only expect that no heartbeats have been sent if the interval +# between events never exceeded MASTER_HEARTBEAT_PERIOD. +# If it has exceeded the value at least once, the slave can legitimately +# receive a heartbeat (but we cannot require it, because the delay +# could have occurred somewhere else, e.g. upon checking the status). +# So, if the delay is detected, we will signal slave to ignore possible +# heartbeats. + +let $possible_heartbeats= 0; +let $commits_to_wait= 5; +while ($commits_to_wait) +{ + let $tm= `SELECT UNIX_TIMESTAMP(NOW(3))`; + let $binlog_commits= query_get_value(SHOW STATUS LIKE 'Binlog_commits', Value, 1); + let $wait_condition= SELECT VARIABLE_VALUE > $binlog_commits FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME= 'BINLOG_COMMITS'; + --source include/wait_condition.inc + dec $commits_to_wait; + if (`SELECT UNIX_TIMESTAMP(NOW(3)) > $tm + 5`) + { + let $possible_heartbeats= 1; + let $commits_to_wait= 0; + } +} + +--connection slave let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1); -let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1); ---echo Number of received heartbeat events: $result +let $result= `SELECT CASE WHEN $possible_heartbeats THEN 'TRUE' WHEN $rcvd_heartbeats_after - $rcvd_heartbeats_before > 0 THEN 'FALSE' ELSE 'TRUE' END`; +--echo Received heartbeats meet expectations: $result --connection master DELETE FROM t1; DROP EVENT e1; --sync_slave_with_master --echo - # Check received heartbeat events while logs flushed on slave --echo *** Flush logs on slave *** STOP SLAVE; From f49375fddfd83cfc23b83b5c00d37781bf0bb070 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 16 Feb 2017 23:44:54 -0800 Subject: [PATCH 09/43] Fixed bug mdev-9028. This patch is actually a complement for the fix of bug mdev-6892. The procedure create_tmp_table() now must take into account Item_direct_refs that wrap up constant fields of derived tables/views that are used as inner tables in outer join operations. --- mysql-test/r/derived.result | 23 +++++++++++++++++++++++ mysql-test/t/derived.test | 23 +++++++++++++++++++++++ sql/sql_select.cc | 4 +++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index a4d474c9cdf..33af7c61613 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -988,4 +988,27 @@ David Yes 210 Edward Yes 150 DROP TABLE example1463; set sql_mode= @save_sql_mode; +# +# MDEV-9028: SELECT DISTINCT constant column of derived table +# used as the second operand of LEFT JOIN +# +create table t1 (id int, data varchar(255)); +insert into t1 values (1,'yes'),(2,'yes'); +select distinct t1.id, tt.id, tt.data +from t1 +left join +(select t1.id, 'yes' as data from t1) as tt +on t1.id = tt.id; +id id data +1 1 yes +2 2 yes +select distinct t1.id, tt.id, tt.data +from t1 +left join +(select t1.id, 'yes' as data from t1 where id > 1) as tt +on t1.id = tt.id; +id id data +2 2 yes +1 NULL NULL +drop table t1; # end of 5.5 diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index e8a6ac34392..f8ba87ac1f5 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -842,4 +842,27 @@ SELECT Customer, Success, SUM(OrderSize) DROP TABLE example1463; set sql_mode= @save_sql_mode; +--echo # +--echo # MDEV-9028: SELECT DISTINCT constant column of derived table +--echo # used as the second operand of LEFT JOIN +--echo # + +create table t1 (id int, data varchar(255)); +insert into t1 values (1,'yes'),(2,'yes'); + +select distinct t1.id, tt.id, tt.data + from t1 + left join + (select t1.id, 'yes' as data from t1) as tt + on t1.id = tt.id; + +select distinct t1.id, tt.id, tt.data + from t1 + left join + (select t1.id, 'yes' as data from t1 where id > 1) as tt + on t1.id = tt.id; + +drop table t1; + + --echo # end of 5.5 diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2c65c59ad7e..d9433a4167a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14627,7 +14627,9 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table, if (new_field) new_field->init(table); - if (copy_func && item->real_item()->is_result_field()) + if (copy_func && + (item->is_result_field() || + (item->real_item()->is_result_field()))) *((*copy_func)++) = item; // Save for copy_funcs if (modify_item) item->set_result_field(new_field); From 6364adb199f8adbc5adfe0c276bdf2d3dd17454c Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Sat, 18 Feb 2017 20:39:49 +0200 Subject: [PATCH 10/43] MDEV-10621 parts.partition_float_myisam failed with timeout in buildbot parts.partition_float_myisam, parts.partition_int_myisam, parts.partition_float_innodb are all known to fail with timeouts on slow builders. The tests are composed of several independent parts for corresponding subtypes (float == float + double, int == tinyint + smallint + mediumint + int + bigint). The solution is to split them into separate tests. No test logic has been changed. --- .../parts/r/partition_bigint_innodb.result | 121 +++++ .../parts/r/partition_bigint_myisam.result | 121 +++++ .../parts/r/partition_double_innodb.result | 82 ++++ .../parts/r/partition_double_myisam.result | 82 ++++ .../parts/r/partition_float_innodb.result | 82 ---- .../parts/r/partition_float_myisam.result | 82 ---- .../suite/parts/r/partition_int_innodb.result | 448 ------------------ .../suite/parts/r/partition_int_myisam.result | 448 ------------------ .../parts/r/partition_mediumint_innodb.result | 109 +++++ .../parts/r/partition_mediumint_myisam.result | 109 +++++ .../parts/r/partition_smallint_innodb.result | 109 +++++ .../parts/r/partition_smallint_myisam.result | 109 +++++ .../parts/r/partition_tinyint_innodb.result | 109 +++++ .../parts/r/partition_tinyint_myisam.result | 109 +++++ .../parts/t/partition_bigint_innodb.test | 46 ++ .../parts/t/partition_bigint_myisam.test | 46 ++ .../parts/t/partition_double_innodb.test | 46 ++ .../parts/t/partition_double_myisam.test | 46 ++ .../suite/parts/t/partition_float_innodb.test | 7 +- .../suite/parts/t/partition_float_myisam.test | 7 +- .../suite/parts/t/partition_int_innodb.test | 10 +- .../suite/parts/t/partition_int_myisam.test | 10 +- .../parts/t/partition_mediumint_innodb.test | 46 ++ .../parts/t/partition_mediumint_myisam.test | 46 ++ .../parts/t/partition_smallint_innodb.test | 46 ++ .../parts/t/partition_smallint_myisam.test | 46 ++ .../parts/t/partition_tinyint_innodb.test | 46 ++ .../parts/t/partition_tinyint_myisam.test | 46 ++ 28 files changed, 1532 insertions(+), 1082 deletions(-) create mode 100644 mysql-test/suite/parts/r/partition_bigint_innodb.result create mode 100644 mysql-test/suite/parts/r/partition_bigint_myisam.result create mode 100644 mysql-test/suite/parts/r/partition_double_innodb.result create mode 100644 mysql-test/suite/parts/r/partition_double_myisam.result create mode 100644 mysql-test/suite/parts/r/partition_mediumint_innodb.result create mode 100644 mysql-test/suite/parts/r/partition_mediumint_myisam.result create mode 100644 mysql-test/suite/parts/r/partition_smallint_innodb.result create mode 100644 mysql-test/suite/parts/r/partition_smallint_myisam.result create mode 100644 mysql-test/suite/parts/r/partition_tinyint_innodb.result create mode 100644 mysql-test/suite/parts/r/partition_tinyint_myisam.result create mode 100644 mysql-test/suite/parts/t/partition_bigint_innodb.test create mode 100644 mysql-test/suite/parts/t/partition_bigint_myisam.test create mode 100644 mysql-test/suite/parts/t/partition_double_innodb.test create mode 100644 mysql-test/suite/parts/t/partition_double_myisam.test create mode 100644 mysql-test/suite/parts/t/partition_mediumint_innodb.test create mode 100644 mysql-test/suite/parts/t/partition_mediumint_myisam.test create mode 100644 mysql-test/suite/parts/t/partition_smallint_innodb.test create mode 100644 mysql-test/suite/parts/t/partition_smallint_myisam.test create mode 100644 mysql-test/suite/parts/t/partition_tinyint_innodb.test create mode 100644 mysql-test/suite/parts/t/partition_tinyint_myisam.test diff --git a/mysql-test/suite/parts/r/partition_bigint_innodb.result b/mysql-test/suite/parts/r/partition_bigint_innodb.result new file mode 100644 index 00000000000..bb0f08d9356 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_bigint_innodb.result @@ -0,0 +1,121 @@ +create table t1 (a bigint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ +insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612), (1), (2), (65535); +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +2 +65535 +select * from t1 where a=-2; +a +delete from t1 where a=-2; +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +2 +65535 +select * from t1 where a=18446744073709551615; +a +18446744073709551615 +delete from t1 where a=18446744073709551615; +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +2 +65535 +drop table t1; +create table t2 (a bigint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612); +select * from t2; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +select * from t2 where a=18446744073709551615; +a +18446744073709551615 +delete from t2 where a=18446744073709551615; +select * from t2; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +delete from t2; +1024 inserts; +select count(*) from t2; +count(*) +1024 +drop table t2; +create table t3 (a bigint not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` bigint(20) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (9223372036854775807), (9223372036854775806), (9223372036854775805), (9223372036854775804), (-9223372036854775808), (-9223372036854775807), (1), (-1), (0); +select * from t3; +a +-1 +-9223372036854775807 +-9223372036854775808 +0 +1 +9223372036854775804 +9223372036854775805 +9223372036854775806 +9223372036854775807 +select * from t3 where a=9223372036854775806; +a +9223372036854775806 +delete from t3 where a=9223372036854775806; +select * from t3; +a +-1 +-9223372036854775807 +-9223372036854775808 +0 +1 +9223372036854775804 +9223372036854775805 +9223372036854775807 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_bigint_myisam.result b/mysql-test/suite/parts/r/partition_bigint_myisam.result new file mode 100644 index 00000000000..5938bcaf7d8 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_bigint_myisam.result @@ -0,0 +1,121 @@ +create table t1 (a bigint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ +insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612), (1), (2), (65535); +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +2 +65535 +select * from t1 where a=-2; +a +delete from t1 where a=-2; +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +2 +65535 +select * from t1 where a=18446744073709551615; +a +18446744073709551615 +delete from t1 where a=18446744073709551615; +select * from t1; +a +1 +18446744073709551612 +18446744073709551613 +18446744073709551614 +2 +65535 +drop table t1; +create table t2 (a bigint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612); +select * from t2; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +select * from t2 where a=18446744073709551615; +a +18446744073709551615 +delete from t2 where a=18446744073709551615; +select * from t2; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +delete from t2; +65535 inserts; +select count(*) from t2; +count(*) +65535 +drop table t2; +create table t3 (a bigint not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` bigint(20) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (9223372036854775807), (9223372036854775806), (9223372036854775805), (9223372036854775804), (-9223372036854775808), (-9223372036854775807), (1), (-1), (0); +select * from t3; +a +-1 +-9223372036854775807 +-9223372036854775808 +0 +1 +9223372036854775804 +9223372036854775805 +9223372036854775806 +9223372036854775807 +select * from t3 where a=9223372036854775806; +a +9223372036854775806 +delete from t3 where a=9223372036854775806; +select * from t3; +a +-1 +-9223372036854775807 +-9223372036854775808 +0 +1 +9223372036854775804 +9223372036854775805 +9223372036854775807 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_double_innodb.result b/mysql-test/suite/parts/r/partition_double_innodb.result new file mode 100644 index 00000000000..8c0daf929dd --- /dev/null +++ b/mysql-test/suite/parts/r/partition_double_innodb.result @@ -0,0 +1,82 @@ +create table t1 (a double not null, primary key(a)) engine='InnoDB' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` double NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ +insert into t1 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t1; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +1234.567 +2.2250738585072016e208 +select * from t1 where a=1.5; +a +1.5 +delete from t1 where a=1.5; +select * from t1; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1234.567 +2.2250738585072016e208 +drop table t1; +create table t2 (a double not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 10; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` double NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 10 */ +insert into t2 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t2; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +1234.567 +2.2250738585072016e208 +select * from t2 where a=1234.567; +a +1234.567 +delete from t2 where a=1234.567; +select * from t2; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +2.2250738585072016e208 +delete from t2; +1024*3 inserts; +select count(*) from t2; +count(*) +3072 +drop table t2; diff --git a/mysql-test/suite/parts/r/partition_double_myisam.result b/mysql-test/suite/parts/r/partition_double_myisam.result new file mode 100644 index 00000000000..045763e5ef9 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_double_myisam.result @@ -0,0 +1,82 @@ +create table t1 (a double not null, primary key(a)) engine='MYISAM' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` double NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ +insert into t1 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t1; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +1234.567 +2.2250738585072016e208 +select * from t1 where a=1.5; +a +1.5 +delete from t1 where a=1.5; +select * from t1; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1234.567 +2.2250738585072016e208 +drop table t1; +create table t2 (a double not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 10; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` double NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 10 */ +insert into t2 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t2; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +1234.567 +2.2250738585072016e208 +select * from t2 where a=1234.567; +a +1234.567 +delete from t2 where a=1234.567; +select * from t2; +a +-2.2250738585072016e208 +-1.5 +-1 +-2.2250738585072014e-208 +0 +1.5 +2.2250738585072016e208 +delete from t2; +16384*3 inserts; +select count(*) from t2; +count(*) +49152 +drop table t2; diff --git a/mysql-test/suite/parts/r/partition_float_innodb.result b/mysql-test/suite/parts/r/partition_float_innodb.result index d2f04a68629..b0870992c41 100644 --- a/mysql-test/suite/parts/r/partition_float_innodb.result +++ b/mysql-test/suite/parts/r/partition_float_innodb.result @@ -88,85 +88,3 @@ select count(*) from t2; count(*) 3072 drop table t2; -create table t1 (a double not null, primary key(a)) engine='InnoDB' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` double NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ -insert into t1 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); -select * from t1; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -1234.567 -2.2250738585072016e208 -select * from t1 where a=1.5; -a -1.5 -delete from t1 where a=1.5; -select * from t1; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1234.567 -2.2250738585072016e208 -drop table t1; -create table t2 (a double not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 10; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` double NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 10 */ -insert into t2 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); -select * from t2; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -1234.567 -2.2250738585072016e208 -select * from t2 where a=1234.567; -a -1234.567 -delete from t2 where a=1234.567; -select * from t2; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -2.2250738585072016e208 -delete from t2; -1024*3 inserts; -select count(*) from t2; -count(*) -3072 -drop table t2; diff --git a/mysql-test/suite/parts/r/partition_float_myisam.result b/mysql-test/suite/parts/r/partition_float_myisam.result index 2d52d095989..931c4ef0394 100644 --- a/mysql-test/suite/parts/r/partition_float_myisam.result +++ b/mysql-test/suite/parts/r/partition_float_myisam.result @@ -88,85 +88,3 @@ select count(*) from t2; count(*) 49152 drop table t2; -create table t1 (a double not null, primary key(a)) engine='MYISAM' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` double NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ -insert into t1 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); -select * from t1; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -1234.567 -2.2250738585072016e208 -select * from t1 where a=1.5; -a -1.5 -delete from t1 where a=1.5; -select * from t1; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1234.567 -2.2250738585072016e208 -drop table t1; -create table t2 (a double not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 10; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` double NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 10 */ -insert into t2 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); -select * from t2; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -1234.567 -2.2250738585072016e208 -select * from t2 where a=1234.567; -a -1234.567 -delete from t2 where a=1234.567; -select * from t2; -a --2.2250738585072016e208 --1.5 --1 --2.2250738585072014e-208 -0 -1.5 -2.2250738585072016e208 -delete from t2; -16384*3 inserts; -select count(*) from t2; -count(*) -49152 -drop table t2; diff --git a/mysql-test/suite/parts/r/partition_int_innodb.result b/mysql-test/suite/parts/r/partition_int_innodb.result index 7a51b80d5d7..c1798e5f711 100644 --- a/mysql-test/suite/parts/r/partition_int_innodb.result +++ b/mysql-test/suite/parts/r/partition_int_innodb.result @@ -1,221 +1,3 @@ -create table t1 (a tinyint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` tinyint(3) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ -insert into t1 values (255), (254), (253), (252), (1), (2), (128); -select * from t1; -a -1 -128 -2 -252 -253 -254 -255 -select * from t1 where a=253; -a -253 -delete from t1 where a=253; -select * from t1; -a -1 -128 -2 -252 -254 -255 -drop table t1; -create table t2 (a tinyint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` tinyint(3) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (255), (254), (253), (252); -select * from t2; -a -252 -253 -254 -255 -select * from t2 where a=253; -a -253 -delete from t2 where a=253; -select * from t2; -a -252 -254 -255 -delete from t2; -255 inserts; -select count(*) from t2; -count(*) -255 -drop table t2; -create table t3 (a tinyint not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` tinyint(4) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (127), (126), (125), (124), (-128), (-127), (1), (-1), (0); -select * from t3; -a --1 --127 --128 -0 -1 -124 -125 -126 -127 -select * from t3 where a=125; -a -125 -delete from t3 where a=125; -select * from t3; -a --1 --127 --128 -0 -1 -124 -126 -127 -drop table t3; -create table t1 (a smallint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` smallint(5) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ -insert into t1 values (65535), (65534), (65533), (65532), (1), (2), (256); -select * from t1; -a -1 -2 -256 -65532 -65533 -65534 -65535 -select * from t1 where a=65533; -a -65533 -delete from t1 where a=65533; -select * from t1; -a -1 -2 -256 -65532 -65534 -65535 -drop table t1; -create table t2 (a smallint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` smallint(5) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (65535), (65534), (65533), (65532); -select * from t2; -a -65532 -65533 -65534 -65535 -select * from t2 where a=65533; -a -65533 -delete from t2 where a=65533; -select * from t2; -a -65532 -65534 -65535 -delete from t2; -1024 inserts; -select count(*) from t2; -count(*) -1024 -drop table t2; -create table t3 (a smallint not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` smallint(6) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (32767), (32766), (32765), (32764), (-32768), (-32767), (1), (-1), (0); -select * from t3; -a --1 --32767 --32768 -0 -1 -32764 -32765 -32766 -32767 -select * from t3 where a=32765; -a -32765 -delete from t3 where a=32765; -select * from t3; -a --1 --32767 --32768 -0 -1 -32764 -32766 -32767 -drop table t3; create table t1 (a int unsigned not null, primary key(a)) engine='InnoDB' partition by key (a) ( partition pa1 max_rows=20 min_rows=2, @@ -325,233 +107,3 @@ a 2147483646 2147483647 drop table t3; -create table t1 (a mediumint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ -insert into t1 values (16777215), (16777214), (16777213), (16777212), (1), (2), (65535); -select * from t1; -a -1 -16777212 -16777213 -16777214 -16777215 -2 -65535 -select * from t1 where a=16777213; -a -16777213 -delete from t1 where a=16777213; -select * from t1; -a -1 -16777212 -16777214 -16777215 -2 -65535 -drop table t1; -create table t2 (a mediumint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (16777215), (16777214), (16777213), (16777212); -select * from t2; -a -16777212 -16777213 -16777214 -16777215 -select * from t2 where a=16777213; -a -16777213 -delete from t2 where a=16777213; -select * from t2; -a -16777212 -16777214 -16777215 -delete from t2; -1024 inserts; -select count(*) from t2; -count(*) -1024 -drop table t2; -create table t3 (a mediumint not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` mediumint(9) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (8388607), (8388606), (8388605), (8388604), (-8388608), (-8388607), (1), (-1), (0); -select * from t3; -a --1 --8388607 --8388608 -0 -1 -8388604 -8388605 -8388606 -8388607 -select * from t3 where a=8388605; -a -8388605 -delete from t3 where a=8388605; -select * from t3; -a --1 --8388607 --8388608 -0 -1 -8388604 -8388606 -8388607 -drop table t3; -create table t1 (a bigint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ -insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612), (1), (2), (65535); -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -2 -65535 -select * from t1 where a=-2; -a -delete from t1 where a=-2; -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -2 -65535 -select * from t1 where a=18446744073709551615; -a -18446744073709551615 -delete from t1 where a=18446744073709551615; -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -2 -65535 -drop table t1; -create table t2 (a bigint unsigned not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612); -select * from t2; -a -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -select * from t2 where a=18446744073709551615; -a -18446744073709551615 -delete from t2 where a=18446744073709551615; -select * from t2; -a -18446744073709551612 -18446744073709551613 -18446744073709551614 -delete from t2; -1024 inserts; -select count(*) from t2; -count(*) -1024 -drop table t2; -create table t3 (a bigint not null, primary key(a)) engine='InnoDB' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` bigint(20) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (9223372036854775807), (9223372036854775806), (9223372036854775805), (9223372036854775804), (-9223372036854775808), (-9223372036854775807), (1), (-1), (0); -select * from t3; -a --1 --9223372036854775807 --9223372036854775808 -0 -1 -9223372036854775804 -9223372036854775805 -9223372036854775806 -9223372036854775807 -select * from t3 where a=9223372036854775806; -a -9223372036854775806 -delete from t3 where a=9223372036854775806; -select * from t3; -a --1 --9223372036854775807 --9223372036854775808 -0 -1 -9223372036854775804 -9223372036854775805 -9223372036854775807 -drop table t3; diff --git a/mysql-test/suite/parts/r/partition_int_myisam.result b/mysql-test/suite/parts/r/partition_int_myisam.result index 4387bbfdd78..8b8352ebc38 100644 --- a/mysql-test/suite/parts/r/partition_int_myisam.result +++ b/mysql-test/suite/parts/r/partition_int_myisam.result @@ -1,221 +1,3 @@ -create table t1 (a tinyint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` tinyint(3) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ -insert into t1 values (255), (254), (253), (252), (1), (2), (128); -select * from t1; -a -1 -128 -2 -252 -253 -254 -255 -select * from t1 where a=253; -a -253 -delete from t1 where a=253; -select * from t1; -a -1 -128 -2 -252 -254 -255 -drop table t1; -create table t2 (a tinyint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` tinyint(3) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (255), (254), (253), (252); -select * from t2; -a -252 -253 -254 -255 -select * from t2 where a=253; -a -253 -delete from t2 where a=253; -select * from t2; -a -252 -254 -255 -delete from t2; -255 inserts; -select count(*) from t2; -count(*) -255 -drop table t2; -create table t3 (a tinyint not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` tinyint(4) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (127), (126), (125), (124), (-128), (-127), (1), (-1), (0); -select * from t3; -a --1 --127 --128 -0 -1 -124 -125 -126 -127 -select * from t3 where a=125; -a -125 -delete from t3 where a=125; -select * from t3; -a --1 --127 --128 -0 -1 -124 -126 -127 -drop table t3; -create table t1 (a smallint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` smallint(5) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ -insert into t1 values (65535), (65534), (65533), (65532), (1), (2), (256); -select * from t1; -a -1 -2 -256 -65532 -65533 -65534 -65535 -select * from t1 where a=65533; -a -65533 -delete from t1 where a=65533; -select * from t1; -a -1 -2 -256 -65532 -65534 -65535 -drop table t1; -create table t2 (a smallint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` smallint(5) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (65535), (65534), (65533), (65532); -select * from t2; -a -65532 -65533 -65534 -65535 -select * from t2 where a=65533; -a -65533 -delete from t2 where a=65533; -select * from t2; -a -65532 -65534 -65535 -delete from t2; -65535 inserts; -select count(*) from t2; -count(*) -65535 -drop table t2; -create table t3 (a smallint not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` smallint(6) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (32767), (32766), (32765), (32764), (-32768), (-32767), (1), (-1), (0); -select * from t3; -a --1 --32767 --32768 -0 -1 -32764 -32765 -32766 -32767 -select * from t3 where a=32765; -a -32765 -delete from t3 where a=32765; -select * from t3; -a --1 --32767 --32768 -0 -1 -32764 -32766 -32767 -drop table t3; create table t1 (a int unsigned not null, primary key(a)) engine='MYISAM' partition by key (a) ( partition pa1 max_rows=20 min_rows=2, @@ -325,233 +107,3 @@ a 2147483646 2147483647 drop table t3; -create table t1 (a mediumint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ -insert into t1 values (16777215), (16777214), (16777213), (16777212), (1), (2), (65535); -select * from t1; -a -1 -16777212 -16777213 -16777214 -16777215 -2 -65535 -select * from t1 where a=16777213; -a -16777213 -delete from t1 where a=16777213; -select * from t1; -a -1 -16777212 -16777214 -16777215 -2 -65535 -drop table t1; -create table t2 (a mediumint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (16777215), (16777214), (16777213), (16777212); -select * from t2; -a -16777212 -16777213 -16777214 -16777215 -select * from t2 where a=16777213; -a -16777213 -delete from t2 where a=16777213; -select * from t2; -a -16777212 -16777214 -16777215 -delete from t2; -65535 inserts; -select count(*) from t2; -count(*) -65535 -drop table t2; -create table t3 (a mediumint not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` mediumint(9) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (8388607), (8388606), (8388605), (8388604), (-8388608), (-8388607), (1), (-1), (0); -select * from t3; -a --1 --8388607 --8388608 -0 -1 -8388604 -8388605 -8388606 -8388607 -select * from t3 where a=8388605; -a -8388605 -delete from t3 where a=8388605; -select * from t3; -a --1 --8388607 --8388608 -0 -1 -8388604 -8388606 -8388607 -drop table t3; -create table t1 (a bigint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) ( -partition pa1 max_rows=20 min_rows=2, -partition pa2 max_rows=30 min_rows=3, -partition pa3 max_rows=30 min_rows=4, -partition pa4 max_rows=40 min_rows=2); -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, - PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, - PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, - PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ -insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612), (1), (2), (65535); -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -2 -65535 -select * from t1 where a=-2; -a -delete from t1 where a=-2; -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -2 -65535 -select * from t1 where a=18446744073709551615; -a -18446744073709551615 -delete from t1 where a=18446744073709551615; -select * from t1; -a -1 -18446744073709551612 -18446744073709551613 -18446744073709551614 -2 -65535 -drop table t1; -create table t2 (a bigint unsigned not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 8; -show create table t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 8 */ -insert into t2 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612); -select * from t2; -a -18446744073709551612 -18446744073709551613 -18446744073709551614 -18446744073709551615 -select * from t2 where a=18446744073709551615; -a -18446744073709551615 -delete from t2 where a=18446744073709551615; -select * from t2; -a -18446744073709551612 -18446744073709551613 -18446744073709551614 -delete from t2; -65535 inserts; -select count(*) from t2; -count(*) -65535 -drop table t2; -create table t3 (a bigint not null, primary key(a)) engine='MYISAM' -partition by key (a) partitions 7; -show create table t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` bigint(20) NOT NULL, - PRIMARY KEY (`a`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -/*!50100 PARTITION BY KEY (a) -PARTITIONS 7 */ -insert into t3 values (9223372036854775807), (9223372036854775806), (9223372036854775805), (9223372036854775804), (-9223372036854775808), (-9223372036854775807), (1), (-1), (0); -select * from t3; -a --1 --9223372036854775807 --9223372036854775808 -0 -1 -9223372036854775804 -9223372036854775805 -9223372036854775806 -9223372036854775807 -select * from t3 where a=9223372036854775806; -a -9223372036854775806 -delete from t3 where a=9223372036854775806; -select * from t3; -a --1 --9223372036854775807 --9223372036854775808 -0 -1 -9223372036854775804 -9223372036854775805 -9223372036854775807 -drop table t3; diff --git a/mysql-test/suite/parts/r/partition_mediumint_innodb.result b/mysql-test/suite/parts/r/partition_mediumint_innodb.result new file mode 100644 index 00000000000..8e3e5543ddc --- /dev/null +++ b/mysql-test/suite/parts/r/partition_mediumint_innodb.result @@ -0,0 +1,109 @@ +create table t1 (a mediumint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ +insert into t1 values (16777215), (16777214), (16777213), (16777212), (1), (2), (65535); +select * from t1; +a +1 +16777212 +16777213 +16777214 +16777215 +2 +65535 +select * from t1 where a=16777213; +a +16777213 +delete from t1 where a=16777213; +select * from t1; +a +1 +16777212 +16777214 +16777215 +2 +65535 +drop table t1; +create table t2 (a mediumint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (16777215), (16777214), (16777213), (16777212); +select * from t2; +a +16777212 +16777213 +16777214 +16777215 +select * from t2 where a=16777213; +a +16777213 +delete from t2 where a=16777213; +select * from t2; +a +16777212 +16777214 +16777215 +delete from t2; +1024 inserts; +select count(*) from t2; +count(*) +1024 +drop table t2; +create table t3 (a mediumint not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` mediumint(9) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (8388607), (8388606), (8388605), (8388604), (-8388608), (-8388607), (1), (-1), (0); +select * from t3; +a +-1 +-8388607 +-8388608 +0 +1 +8388604 +8388605 +8388606 +8388607 +select * from t3 where a=8388605; +a +8388605 +delete from t3 where a=8388605; +select * from t3; +a +-1 +-8388607 +-8388608 +0 +1 +8388604 +8388606 +8388607 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_mediumint_myisam.result b/mysql-test/suite/parts/r/partition_mediumint_myisam.result new file mode 100644 index 00000000000..4853680610b --- /dev/null +++ b/mysql-test/suite/parts/r/partition_mediumint_myisam.result @@ -0,0 +1,109 @@ +create table t1 (a mediumint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ +insert into t1 values (16777215), (16777214), (16777213), (16777212), (1), (2), (65535); +select * from t1; +a +1 +16777212 +16777213 +16777214 +16777215 +2 +65535 +select * from t1 where a=16777213; +a +16777213 +delete from t1 where a=16777213; +select * from t1; +a +1 +16777212 +16777214 +16777215 +2 +65535 +drop table t1; +create table t2 (a mediumint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (16777215), (16777214), (16777213), (16777212); +select * from t2; +a +16777212 +16777213 +16777214 +16777215 +select * from t2 where a=16777213; +a +16777213 +delete from t2 where a=16777213; +select * from t2; +a +16777212 +16777214 +16777215 +delete from t2; +65535 inserts; +select count(*) from t2; +count(*) +65535 +drop table t2; +create table t3 (a mediumint not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` mediumint(9) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (8388607), (8388606), (8388605), (8388604), (-8388608), (-8388607), (1), (-1), (0); +select * from t3; +a +-1 +-8388607 +-8388608 +0 +1 +8388604 +8388605 +8388606 +8388607 +select * from t3 where a=8388605; +a +8388605 +delete from t3 where a=8388605; +select * from t3; +a +-1 +-8388607 +-8388608 +0 +1 +8388604 +8388606 +8388607 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_smallint_innodb.result b/mysql-test/suite/parts/r/partition_smallint_innodb.result new file mode 100644 index 00000000000..fbf23fe582c --- /dev/null +++ b/mysql-test/suite/parts/r/partition_smallint_innodb.result @@ -0,0 +1,109 @@ +create table t1 (a smallint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ +insert into t1 values (65535), (65534), (65533), (65532), (1), (2), (256); +select * from t1; +a +1 +2 +256 +65532 +65533 +65534 +65535 +select * from t1 where a=65533; +a +65533 +delete from t1 where a=65533; +select * from t1; +a +1 +2 +256 +65532 +65534 +65535 +drop table t1; +create table t2 (a smallint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (65535), (65534), (65533), (65532); +select * from t2; +a +65532 +65533 +65534 +65535 +select * from t2 where a=65533; +a +65533 +delete from t2 where a=65533; +select * from t2; +a +65532 +65534 +65535 +delete from t2; +1024 inserts; +select count(*) from t2; +count(*) +1024 +drop table t2; +create table t3 (a smallint not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` smallint(6) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (32767), (32766), (32765), (32764), (-32768), (-32767), (1), (-1), (0); +select * from t3; +a +-1 +-32767 +-32768 +0 +1 +32764 +32765 +32766 +32767 +select * from t3 where a=32765; +a +32765 +delete from t3 where a=32765; +select * from t3; +a +-1 +-32767 +-32768 +0 +1 +32764 +32766 +32767 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_smallint_myisam.result b/mysql-test/suite/parts/r/partition_smallint_myisam.result new file mode 100644 index 00000000000..a405d025919 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_smallint_myisam.result @@ -0,0 +1,109 @@ +create table t1 (a smallint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ +insert into t1 values (65535), (65534), (65533), (65532), (1), (2), (256); +select * from t1; +a +1 +2 +256 +65532 +65533 +65534 +65535 +select * from t1 where a=65533; +a +65533 +delete from t1 where a=65533; +select * from t1; +a +1 +2 +256 +65532 +65534 +65535 +drop table t1; +create table t2 (a smallint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (65535), (65534), (65533), (65532); +select * from t2; +a +65532 +65533 +65534 +65535 +select * from t2 where a=65533; +a +65533 +delete from t2 where a=65533; +select * from t2; +a +65532 +65534 +65535 +delete from t2; +65535 inserts; +select count(*) from t2; +count(*) +65535 +drop table t2; +create table t3 (a smallint not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` smallint(6) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (32767), (32766), (32765), (32764), (-32768), (-32767), (1), (-1), (0); +select * from t3; +a +-1 +-32767 +-32768 +0 +1 +32764 +32765 +32766 +32767 +select * from t3 where a=32765; +a +32765 +delete from t3 where a=32765; +select * from t3; +a +-1 +-32767 +-32768 +0 +1 +32764 +32766 +32767 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_tinyint_innodb.result b/mysql-test/suite/parts/r/partition_tinyint_innodb.result new file mode 100644 index 00000000000..d7138539b78 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_tinyint_innodb.result @@ -0,0 +1,109 @@ +create table t1 (a tinyint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = InnoDB, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = InnoDB, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = InnoDB, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = InnoDB) */ +insert into t1 values (255), (254), (253), (252), (1), (2), (128); +select * from t1; +a +1 +128 +2 +252 +253 +254 +255 +select * from t1 where a=253; +a +253 +delete from t1 where a=253; +select * from t1; +a +1 +128 +2 +252 +254 +255 +drop table t1; +create table t2 (a tinyint unsigned not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (255), (254), (253), (252); +select * from t2; +a +252 +253 +254 +255 +select * from t2 where a=253; +a +253 +delete from t2 where a=253; +select * from t2; +a +252 +254 +255 +delete from t2; +255 inserts; +select count(*) from t2; +count(*) +255 +drop table t2; +create table t3 (a tinyint not null, primary key(a)) engine='InnoDB' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` tinyint(4) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (127), (126), (125), (124), (-128), (-127), (1), (-1), (0); +select * from t3; +a +-1 +-127 +-128 +0 +1 +124 +125 +126 +127 +select * from t3 where a=125; +a +125 +delete from t3 where a=125; +select * from t3; +a +-1 +-127 +-128 +0 +1 +124 +126 +127 +drop table t3; diff --git a/mysql-test/suite/parts/r/partition_tinyint_myisam.result b/mysql-test/suite/parts/r/partition_tinyint_myisam.result new file mode 100644 index 00000000000..08a688e8f36 --- /dev/null +++ b/mysql-test/suite/parts/r/partition_tinyint_myisam.result @@ -0,0 +1,109 @@ +create table t1 (a tinyint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +(PARTITION pa1 MAX_ROWS = 20 MIN_ROWS = 2 ENGINE = MyISAM, + PARTITION pa2 MAX_ROWS = 30 MIN_ROWS = 3 ENGINE = MyISAM, + PARTITION pa3 MAX_ROWS = 30 MIN_ROWS = 4 ENGINE = MyISAM, + PARTITION pa4 MAX_ROWS = 40 MIN_ROWS = 2 ENGINE = MyISAM) */ +insert into t1 values (255), (254), (253), (252), (1), (2), (128); +select * from t1; +a +1 +128 +2 +252 +253 +254 +255 +select * from t1 where a=253; +a +253 +delete from t1 where a=253; +select * from t1; +a +1 +128 +2 +252 +254 +255 +drop table t1; +create table t2 (a tinyint unsigned not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 8; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 8 */ +insert into t2 values (255), (254), (253), (252); +select * from t2; +a +252 +253 +254 +255 +select * from t2 where a=253; +a +253 +delete from t2 where a=253; +select * from t2; +a +252 +254 +255 +delete from t2; +255 inserts; +select count(*) from t2; +count(*) +255 +drop table t2; +create table t3 (a tinyint not null, primary key(a)) engine='MYISAM' +partition by key (a) partitions 7; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` tinyint(4) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY KEY (a) +PARTITIONS 7 */ +insert into t3 values (127), (126), (125), (124), (-128), (-127), (1), (-1), (0); +select * from t3; +a +-1 +-127 +-128 +0 +1 +124 +125 +126 +127 +select * from t3 where a=125; +a +125 +delete from t3 where a=125; +select * from t3; +a +-1 +-127 +-128 +0 +1 +124 +126 +127 +drop table t3; diff --git a/mysql-test/suite/parts/t/partition_bigint_innodb.test b/mysql-test/suite/parts/t/partition_bigint_innodb.test new file mode 100644 index 00000000000..348ee0add05 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_bigint_innodb.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_bigint_innodb.test # +# # +# Purpose: # +# Tests around integer type # +# INNODB branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_innodb # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +--source include/have_innodb.inc +let $engine= 'InnoDB'; + +##### max rows to be inserted +let $maxrows=1024; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_bigint.inc diff --git a/mysql-test/suite/parts/t/partition_bigint_myisam.test b/mysql-test/suite/parts/t/partition_bigint_myisam.test new file mode 100644 index 00000000000..f427ffce08d --- /dev/null +++ b/mysql-test/suite/parts/t/partition_bigint_myisam.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_bigint_myisam.test # +# # +# Purpose: # +# Tests around integer type # +# MyISAM branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_myisam # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +--source include/long_test.inc + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +let $engine= 'MYISAM'; +##### number of rows to be inserted +let $maxrows=65535; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_bigint.inc diff --git a/mysql-test/suite/parts/t/partition_double_innodb.test b/mysql-test/suite/parts/t/partition_double_innodb.test new file mode 100644 index 00000000000..e31f7049502 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_double_innodb.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_double_innodb.test # +# # +# Purpose: # +# Tests around float type # +# INNODB branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_float_innodb # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +--source include/have_innodb.inc +let $engine= 'InnoDB'; + +##### Number of row to be inserted. +let $maxrows=1024; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_double.inc diff --git a/mysql-test/suite/parts/t/partition_double_myisam.test b/mysql-test/suite/parts/t/partition_double_myisam.test new file mode 100644 index 00000000000..6228d657c48 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_double_myisam.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_double_myisam.test # +# # +# Purpose: # +# Tests around float type # +# MyISAM branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_float_myisam # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +--source include/long_test.inc + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +let $engine= 'MYISAM'; +##### Number of row to be inserted. +let $maxrows=16384; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_double.inc diff --git a/mysql-test/suite/parts/t/partition_float_innodb.test b/mysql-test/suite/parts/t/partition_float_innodb.test index 2f1fe723dad..8d96eafbb06 100644 --- a/mysql-test/suite/parts/t/partition_float_innodb.test +++ b/mysql-test/suite/parts/t/partition_float_innodb.test @@ -8,9 +8,9 @@ #------------------------------------------------------------------------------# # Original Author: HH # # Original Date: 2006-08-01 # -# Change Author: # -# Change Date: # -# Change: # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test for double type has been spawned into a separate test file # ################################################################################ # @@ -44,4 +44,3 @@ let $maxrows=1024; #------------------------------------------------------------------------------# # Execute the tests to be applied to all storage engines --source suite/parts/inc/partition_float.inc ---source suite/parts/inc/partition_double.inc diff --git a/mysql-test/suite/parts/t/partition_float_myisam.test b/mysql-test/suite/parts/t/partition_float_myisam.test index f15e6ad3636..bdc0edd41bb 100644 --- a/mysql-test/suite/parts/t/partition_float_myisam.test +++ b/mysql-test/suite/parts/t/partition_float_myisam.test @@ -8,9 +8,9 @@ #------------------------------------------------------------------------------# # Original Author: HH # # Original Date: 2006-08-01 # -# Change Author: # -# Change Date: # -# Change: # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test for double type has been spawned into a separate test file # ################################################################################ # @@ -44,4 +44,3 @@ let $maxrows=16384; #------------------------------------------------------------------------------# # Execute the tests to be applied to all storage engines --source suite/parts/inc/partition_float.inc ---source suite/parts/inc/partition_double.inc diff --git a/mysql-test/suite/parts/t/partition_int_innodb.test b/mysql-test/suite/parts/t/partition_int_innodb.test index 698a2c93c22..fd00e6a0d80 100644 --- a/mysql-test/suite/parts/t/partition_int_innodb.test +++ b/mysql-test/suite/parts/t/partition_int_innodb.test @@ -8,9 +8,9 @@ #------------------------------------------------------------------------------# # Original Author: HH # # Original Date: 2006-08-01 # -# Change Author: # -# Change Date: # -# Change: # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: Int subtypes (tinyint etc.) have been spawned into separate tests # ################################################################################ # @@ -43,8 +43,4 @@ let $maxrows=1024; #------------------------------------------------------------------------------# # Execute the tests to be applied to all storage engines ---source suite/parts/inc/partition_tinyint.inc ---source suite/parts/inc/partition_smallint.inc --source suite/parts/inc/partition_int.inc ---source suite/parts/inc/partition_mediumint.inc ---source suite/parts/inc/partition_bigint.inc diff --git a/mysql-test/suite/parts/t/partition_int_myisam.test b/mysql-test/suite/parts/t/partition_int_myisam.test index 5f29b575244..e8de09f1bf3 100644 --- a/mysql-test/suite/parts/t/partition_int_myisam.test +++ b/mysql-test/suite/parts/t/partition_int_myisam.test @@ -8,9 +8,9 @@ #------------------------------------------------------------------------------# # Original Author: HH # # Original Date: 2006-08-01 # -# Change Author: # -# Change Date: # -# Change: # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: Int subtypes (tinyint etc.) have been spawned into separate tests # ################################################################################ # @@ -43,8 +43,4 @@ let $maxrows=65535; #------------------------------------------------------------------------------# # Execute the tests to be applied to all storage engines ---source suite/parts/inc/partition_tinyint.inc ---source suite/parts/inc/partition_smallint.inc --source suite/parts/inc/partition_int.inc ---source suite/parts/inc/partition_mediumint.inc ---source suite/parts/inc/partition_bigint.inc diff --git a/mysql-test/suite/parts/t/partition_mediumint_innodb.test b/mysql-test/suite/parts/t/partition_mediumint_innodb.test new file mode 100644 index 00000000000..9218b55fa78 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_mediumint_innodb.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_mediumint_innodb.test # +# # +# Purpose: # +# Tests around integer type # +# INNODB branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_innodb # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +--source include/have_innodb.inc +let $engine= 'InnoDB'; + +##### max rows to be inserted +let $maxrows=1024; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_mediumint.inc diff --git a/mysql-test/suite/parts/t/partition_mediumint_myisam.test b/mysql-test/suite/parts/t/partition_mediumint_myisam.test new file mode 100644 index 00000000000..bbf1775ba97 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_mediumint_myisam.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_mediumint_myisam.test # +# # +# Purpose: # +# Tests around integer type # +# MyISAM branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_myisam # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +--source include/long_test.inc + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +let $engine= 'MYISAM'; +##### number of rows to be inserted +let $maxrows=65535; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_mediumint.inc diff --git a/mysql-test/suite/parts/t/partition_smallint_innodb.test b/mysql-test/suite/parts/t/partition_smallint_innodb.test new file mode 100644 index 00000000000..22d16cf9d55 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_smallint_innodb.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_smallint_innodb.test # +# # +# Purpose: # +# Tests around integer type # +# INNODB branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_innodb # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +--source include/have_innodb.inc +let $engine= 'InnoDB'; + +##### max rows to be inserted +let $maxrows=1024; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_smallint.inc diff --git a/mysql-test/suite/parts/t/partition_smallint_myisam.test b/mysql-test/suite/parts/t/partition_smallint_myisam.test new file mode 100644 index 00000000000..f473a6772f8 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_smallint_myisam.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_smallint_myisam.test # +# # +# Purpose: # +# Tests around integer type # +# MyISAM branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_myisam # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +--source include/long_test.inc + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +let $engine= 'MYISAM'; +##### number of rows to be inserted +let $maxrows=65535; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_smallint.inc diff --git a/mysql-test/suite/parts/t/partition_tinyint_innodb.test b/mysql-test/suite/parts/t/partition_tinyint_innodb.test new file mode 100644 index 00000000000..aec10c1aea5 --- /dev/null +++ b/mysql-test/suite/parts/t/partition_tinyint_innodb.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_tinyint_innodb.test # +# # +# Purpose: # +# Tests around integer type # +# INNODB branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_innodb # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +--source include/have_innodb.inc +let $engine= 'InnoDB'; + +##### max rows to be inserted +let $maxrows=1024; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_tinyint.inc diff --git a/mysql-test/suite/parts/t/partition_tinyint_myisam.test b/mysql-test/suite/parts/t/partition_tinyint_myisam.test new file mode 100644 index 00000000000..9807bffb1da --- /dev/null +++ b/mysql-test/suite/parts/t/partition_tinyint_myisam.test @@ -0,0 +1,46 @@ +################################################################################ +# t/partition_tinyint_myisam.test # +# # +# Purpose: # +# Tests around integer type # +# MyISAM branch # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-08-01 # +# Change Author: Elena Stepanova # +# Change Date: 2017-02-18 # +# Change: The test file is spawned from the mega-test partition_int_myisam # +################################################################################ + +# +# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE ! +# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN +# THE SOURCED FILES ONLY. +# +# Please read the README at the end of inc/partition.pre before changing +# any of the variables. +# + +--source include/long_test.inc + +#------------------------------------------------------------------------------# +# General not engine specific settings and requirements + +##### Options, for debugging support ##### +let $debug= 0; + +# The server must support partitioning. +--source include/have_partition.inc + +#------------------------------------------------------------------------------# +# Engine specific settings and requirements + +##### Storage engine to be tested +let $engine= 'MYISAM'; +##### number of rows to be inserted +let $maxrows=65535; + +#------------------------------------------------------------------------------# +# Execute the tests to be applied to all storage engines +--source suite/parts/inc/partition_tinyint.inc From 1b7aae90fbc53368f7cd41062752816460dce832 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Mon, 20 Feb 2017 18:22:01 +0400 Subject: [PATCH 11/43] MDEV-11904 Make Audit Plugin working with MySQL 8.0. MySQL 8.0 basically inherits the 5.7 model, though some modeifications required for the plugin. --- plugin/server_audit/server_audit.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 87ba00b2d35..eae7ad12f1c 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -2297,10 +2297,10 @@ typedef struct loc_system_variables } LOC_SV; +static int init_done= 0; + static int server_audit_init(void *p __attribute__((unused))) { - const void *my_hash_init_ptr; - if (!serv_ver) { #ifdef _WIN32 @@ -2309,11 +2309,16 @@ static int server_audit_init(void *p __attribute__((unused))) serv_ver= server_version; #endif /*_WIN32*/ } - my_hash_init_ptr= dlsym(RTLD_DEFAULT, "_my_hash_init"); - if (!my_hash_init_ptr) + if (!mysql_57_started) { - maria_above_5= 1; - my_hash_init_ptr= dlsym(RTLD_DEFAULT, "my_hash_init2"); + const void *my_hash_init_ptr= dlsym(RTLD_DEFAULT, "_my_hash_init"); + if (!my_hash_init_ptr) + { + maria_above_5= 1; + my_hash_init_ptr= dlsym(RTLD_DEFAULT, "my_hash_init2"); + } + if (!my_hash_init_ptr) + return 1; } if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "mysql_data_home"))) @@ -2322,7 +2327,7 @@ static int server_audit_init(void *p __attribute__((unused))) int_mysql_data_home= &default_home; } - if (!serv_ver || !my_hash_init_ptr) + if (!serv_ver) return 1; if (!started_mysql) @@ -2402,6 +2407,7 @@ static int server_audit_init(void *p __attribute__((unused))) if (logging) start_logging(); + init_done= 1; return 0; } @@ -2417,6 +2423,10 @@ static int server_audit_init_mysql(void *p) static int server_audit_deinit(void *p __attribute__((unused))) { + if (!init_done) + return 0; + + init_done= 0; coll_free(&incl_user_coll); coll_free(&excl_user_coll); @@ -2839,13 +2849,15 @@ void __attribute__ ((constructor)) audit_plugin_so_init(void) if (sc >= 24) use_event_data_for_disconnect= 1; } - else if (serv_ver[0] == '5' && serv_ver[2] == '7') + else if ((serv_ver[0] == '5' && serv_ver[2] == '7') || + (serv_ver[0] == '8' && serv_ver[2] == '0')) { mysql_57_started= 1; _mysql_plugin_declarations_[0].info= mysql_v4_descriptor; use_event_data_for_disconnect= 1; } - MYSQL_SYSVAR_NAME(loc_info).flags= PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC; + MYSQL_SYSVAR_NAME(loc_info).flags= PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | + PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC; } memset(locinfo_ini_value, 'O', sizeof(locinfo_ini_value)-1); From 5ddfcb05ca98a62b01da1c8b939e5303f900a5cc Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 17 Feb 2017 13:37:18 +0100 Subject: [PATCH 12/43] MDEV-9455: [ERROR] mysqld got signal 11 Switch MEM_ROOT to non-prune_partitions() during optimizing subselect. --- mysql-test/r/partition_innodb.result | 89 ++++++++++++++++++++++++++ mysql-test/t/partition_innodb.test | 93 ++++++++++++++++++++++++++++ sql/opt_range.cc | 11 +++- 3 files changed, 191 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/partition_innodb.result b/mysql-test/r/partition_innodb.result index 1da7dce22df..ed4aaf71a00 100644 --- a/mysql-test/r/partition_innodb.result +++ b/mysql-test/r/partition_innodb.result @@ -718,3 +718,92 @@ d 1991-01-01 DROP TABLE t1; set global default_storage_engine=default; +# +# MDEV-9455: [ERROR] mysqld got signal 11 +# +CREATE TABLE `t1` ( +`DIARY_TOTAL_DAY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT, +`IMORY_ID` bigint(20) NOT NULL, +`NAME` varchar(75) DEFAULT NULL, +`DATETIME` varchar(10) NOT NULL DEFAULT '', +`DAILY_CALL_CNT` int(11) DEFAULT NULL, +`DAILY_SMS_CNT` int(11) DEFAULT NULL, +`NUMBER` varchar(64) DEFAULT NULL, +`DURATION` varchar(16) DEFAULT NULL, +PRIMARY KEY (`DIARY_TOTAL_DAY_SEQ`,`DATETIME`), +KEY `IDX_t1_01` (`IMORY_ID`,`DATETIME`) +) AUTO_INCREMENT=328702514 DEFAULT CHARSET=utf8mb4 +PARTITION BY RANGE COLUMNS(`DATETIME`) +(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB, +PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB, +PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB, +PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB, +PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB, +PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB, +PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB, +PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB, +PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB, +PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB, +PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB) +; +CREATE TABLE `t2` ( +`DIARY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT, +`IMORY_ID` bigint(20) NOT NULL, +`CALL_TYPE` varchar(1) DEFAULT NULL, +`DATA_TYPE` varchar(1) DEFAULT NULL, +`FEATURES` varchar(1) DEFAULT NULL, +`NAME` varchar(75) DEFAULT NULL, +`NUMBER` varchar(64) DEFAULT NULL, +`DATETIME` datetime NOT NULL, +`REG_DATE` datetime NOT NULL, +`TITLE` varchar(50) DEFAULT NULL, +`BODY` varchar(4200) DEFAULT NULL, +`MIME_TYPE` varchar(32) DEFAULT NULL, +`DURATION` varchar(16) DEFAULT NULL, +`DEVICE_ID` varchar(64) DEFAULT NULL, +`DEVICE_NAME` varchar(32) DEFAULT NULL, +PRIMARY KEY (`DIARY_SEQ`,`DATETIME`,`REG_DATE`), +KEY `IDX_TB_DIARY_01` (`IMORY_ID`,`DATETIME`,`CALL_TYPE`,`NUMBER`), +KEY `IDX_TB_DIARY_02` (`REG_DATE`) +) AUTO_INCREMENT=688799006 DEFAULT CHARSET=utf8mb4 +PARTITION BY RANGE COLUMNS(REG_DATE) +(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB, +PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB, +PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB, +PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB, +PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB, +PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB, +PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB, +PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB, +PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB, +PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB, +PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB) +; +SELECT +A.IMORY_ID, +A.NUMBER, +A.NAME, +DATE_FORMAT(A.DATETIME, '%Y-%m-%d') AS TARGET_DATE, +SUM( CASE WHEN A.DATA_TYPE='1' THEN 1 ELSE 0 END) AS CALL_CNT, +SUM( CASE WHEN A.DATA_TYPE IN ('2', '3') THEN 1 ELSE 0 END) AS SMS_CNT, +SUM(CAST(A.DURATION AS INT)) AS DURATION, +( SELECT COUNT(*) +FROM t1 +WHERE IMORY_ID=A.IMORY_ID +AND NUMBER=A.NUMBER +AND NAME=A.NAME +AND DATETIME = DATE_FORMAT(A.DATETIME, '%Y-%m-%d') +) STATS_COUNT +FROM t2 A +WHERE A.IMORY_ID = 55094102 +AND A.DATETIME LIKE ( +SELECT CONCAT (DATE_FORMAT(DATETIME, '%Y-%m-%d') ,'%') +FROM t2 +WHERE IMORY_ID=55094102 +AND DIARY_SEQ IN ( 608351221, 608351225, 608351229 ) +group by DATE_FORMAT(DATETIME, '%Y-%m-%d') +) +GROUP BY A.IMORY_ID, A.NUMBER, A.NAME, DATE_FORMAT(A.DATETIME, '%Y-%m-%d') +; +IMORY_ID NUMBER NAME TARGET_DATE CALL_CNT SMS_CNT DURATION STATS_COUNT +drop table t2, t1; diff --git a/mysql-test/t/partition_innodb.test b/mysql-test/t/partition_innodb.test index 8ee15d3d723..b661e4bd3fa 100644 --- a/mysql-test/t/partition_innodb.test +++ b/mysql-test/t/partition_innodb.test @@ -808,3 +808,96 @@ SELECT * FROM t1 WHERE d = '1991-01-01'; DROP TABLE t1; set global default_storage_engine=default; + +--echo # +--echo # MDEV-9455: [ERROR] mysqld got signal 11 +--echo # + +CREATE TABLE `t1` ( + `DIARY_TOTAL_DAY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `IMORY_ID` bigint(20) NOT NULL, + `NAME` varchar(75) DEFAULT NULL, + `DATETIME` varchar(10) NOT NULL DEFAULT '', + `DAILY_CALL_CNT` int(11) DEFAULT NULL, + `DAILY_SMS_CNT` int(11) DEFAULT NULL, + `NUMBER` varchar(64) DEFAULT NULL, + `DURATION` varchar(16) DEFAULT NULL, + PRIMARY KEY (`DIARY_TOTAL_DAY_SEQ`,`DATETIME`), + KEY `IDX_t1_01` (`IMORY_ID`,`DATETIME`) +) AUTO_INCREMENT=328702514 DEFAULT CHARSET=utf8mb4 +PARTITION BY RANGE COLUMNS(`DATETIME`) +(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB, + PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB, + PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB, + PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB, + PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB, + PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB, + PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB, + PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB, + PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB, + PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB, + PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB) +; + +CREATE TABLE `t2` ( + `DIARY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `IMORY_ID` bigint(20) NOT NULL, + `CALL_TYPE` varchar(1) DEFAULT NULL, + `DATA_TYPE` varchar(1) DEFAULT NULL, + `FEATURES` varchar(1) DEFAULT NULL, + `NAME` varchar(75) DEFAULT NULL, + `NUMBER` varchar(64) DEFAULT NULL, + `DATETIME` datetime NOT NULL, + `REG_DATE` datetime NOT NULL, + `TITLE` varchar(50) DEFAULT NULL, + `BODY` varchar(4200) DEFAULT NULL, + `MIME_TYPE` varchar(32) DEFAULT NULL, + `DURATION` varchar(16) DEFAULT NULL, + `DEVICE_ID` varchar(64) DEFAULT NULL, + `DEVICE_NAME` varchar(32) DEFAULT NULL, + PRIMARY KEY (`DIARY_SEQ`,`DATETIME`,`REG_DATE`), + KEY `IDX_TB_DIARY_01` (`IMORY_ID`,`DATETIME`,`CALL_TYPE`,`NUMBER`), + KEY `IDX_TB_DIARY_02` (`REG_DATE`) +) AUTO_INCREMENT=688799006 DEFAULT CHARSET=utf8mb4 +PARTITION BY RANGE COLUMNS(REG_DATE) +(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB, + PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB, + PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB, + PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB, + PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB, + PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB, + PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB, + PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB, + PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB, + PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB, + PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB) +; + +SELECT + A.IMORY_ID, + A.NUMBER, + A.NAME, + DATE_FORMAT(A.DATETIME, '%Y-%m-%d') AS TARGET_DATE, + SUM( CASE WHEN A.DATA_TYPE='1' THEN 1 ELSE 0 END) AS CALL_CNT, + SUM( CASE WHEN A.DATA_TYPE IN ('2', '3') THEN 1 ELSE 0 END) AS SMS_CNT, + SUM(CAST(A.DURATION AS INT)) AS DURATION, + ( SELECT COUNT(*) + FROM t1 + WHERE IMORY_ID=A.IMORY_ID + AND NUMBER=A.NUMBER + AND NAME=A.NAME + AND DATETIME = DATE_FORMAT(A.DATETIME, '%Y-%m-%d') + ) STATS_COUNT +FROM t2 A +WHERE A.IMORY_ID = 55094102 + AND A.DATETIME LIKE ( + SELECT CONCAT (DATE_FORMAT(DATETIME, '%Y-%m-%d') ,'%') + FROM t2 + WHERE IMORY_ID=55094102 + AND DIARY_SEQ IN ( 608351221, 608351225, 608351229 ) + group by DATE_FORMAT(DATETIME, '%Y-%m-%d') + ) +GROUP BY A.IMORY_ID, A.NUMBER, A.NAME, DATE_FORMAT(A.DATETIME, '%Y-%m-%d') +; + +drop table t2, t1; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7f159016ff8..25a9e729a8b 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7500,8 +7500,15 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond) if (cond_func->functype() == Item_func::BETWEEN || cond_func->functype() == Item_func::IN_FUNC) inv= ((Item_func_opt_neg *) cond_func)->negated; - else if (cond_func->select_optimize() == Item_func::OPTIMIZE_NONE) - DBUG_RETURN(0); + else + { + MEM_ROOT *tmp_root= param->mem_root; + param->thd->mem_root= param->old_root; + Item_func::optimize_type opt_res= cond_func->select_optimize(); + param->thd->mem_root= tmp_root; + if (opt_res == Item_func::OPTIMIZE_NONE) + DBUG_RETURN(0); + } param->cond= cond; From 2bfe83adec576a27aed2d87ff65cebddc3430d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 20 Feb 2017 17:16:59 +0200 Subject: [PATCH 13/43] Remove a bogus Valgrind "suppression". fsp_init_file_page_low() does initialize all pages nowadays, even those in the InnoDB system tablespace. --- storage/innobase/buf/buf0buf.c | 10 +--------- storage/xtradb/buf/buf0buf.c | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c index 4963f1c30c3..a5e1c045b7b 100644 --- a/storage/innobase/buf/buf0buf.c +++ b/storage/innobase/buf/buf0buf.c @@ -2,6 +2,7 @@ Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. +Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -2997,15 +2998,6 @@ buf_page_init( /* Set the state of the block */ buf_block_set_file_page(block, space, offset); -#ifdef UNIV_DEBUG_VALGRIND - if (!space) { - /* Silence valid Valgrind warnings about uninitialized - data being written to data files. There are some unused - bytes on some pages that InnoDB does not initialize. */ - UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE); - } -#endif /* UNIV_DEBUG_VALGRIND */ - buf_block_init_low(block); block->lock_hash_val = lock_rec_hash(space, offset); diff --git a/storage/xtradb/buf/buf0buf.c b/storage/xtradb/buf/buf0buf.c index 6ef9ac0d16a..e68b0526d42 100644 --- a/storage/xtradb/buf/buf0buf.c +++ b/storage/xtradb/buf/buf0buf.c @@ -2,6 +2,7 @@ Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. +Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -3349,15 +3350,6 @@ buf_page_init( /* Set the state of the block */ buf_block_set_file_page(block, space, offset); -#ifdef UNIV_DEBUG_VALGRIND - if (!space) { - /* Silence valid Valgrind warnings about uninitialized - data being written to data files. There are some unused - bytes on some pages that InnoDB does not initialize. */ - UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE); - } -#endif /* UNIV_DEBUG_VALGRIND */ - buf_block_init_low(block); block->lock_hash_val = lock_rec_hash(space, offset); From 978179a9d4933d3d8d2ac99028798e8a07095dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 20 Feb 2017 17:58:42 +0200 Subject: [PATCH 14/43] MDEV-11520 Extending an InnoDB data file unnecessarily allocates a large memory buffer on Windows fil_extend_space_to_desired_size(), os_file_set_size(): Use calloc() for memory allocation, and handle failures. Properly check the return status of posix_fallocate(). On Windows, instead of extending the file by at most 1 megabyte at a time, write a zero-filled page at the end of the file. According to the Microsoft blog post https://blogs.msdn.microsoft.com/oldnewthing/20110922-00/?p=9573 this will physically extend the file by writing zero bytes. (InnoDB never uses DeviceIoControl() to set the file sparse.) For innodb_plugin, port the XtraDB fix for MySQL Bug#56433 (introducing fil_system->file_extend_mutex). The bug was fixed differently in MySQL 5.6 (and MariaDB Server 10.0). --- storage/innobase/fil/fil0fil.c | 87 ++++++++++++++++++---------- storage/innobase/include/sync0sync.h | 1 + storage/innobase/os/os0file.c | 82 +++++++++----------------- storage/xtradb/fil/fil0fil.c | 84 ++++++++++++++++----------- storage/xtradb/os/os0file.c | 76 +++++++++--------------- 5 files changed, 163 insertions(+), 167 deletions(-) diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index d7ac3dd14eb..195fa7adde9 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. 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 @@ -248,6 +249,7 @@ the ib_logfiles form a 'space' and it is handled here */ struct fil_system_struct { #ifndef UNIV_HOTBACKUP mutex_t mutex; /*!< The mutex protecting the cache */ + mutex_t file_extend_mutex; #endif /* !UNIV_HOTBACKUP */ hash_table_t* spaces; /*!< The hash table of spaces in the system; they are hashed on the space @@ -1658,6 +1660,8 @@ fil_init( mutex_create(fil_system_mutex_key, &fil_system->mutex, SYNC_ANY_LATCH); + mutex_create(fil_system_mutex_key, + &fil_system->file_extend_mutex, SYNC_OUTER_ANY_LATCH); fil_system->spaces = hash_create(hash_size); fil_system->name_hash = hash_create(hash_size); @@ -4096,6 +4100,10 @@ fil_extend_space_to_desired_size( ulint page_size; ibool success = TRUE; + /* fil_system->file_extend_mutex is for http://bugs.mysql.com/56433 + to prevent concurrent fil_extend_space_to_desired_size() + while fil_system->mutex is temporarily released */ + mutex_enter(&fil_system->file_extend_mutex); fil_mutex_enter_and_prepare_for_io(space_id); space = fil_space_get_by_id(space_id); @@ -4107,6 +4115,7 @@ fil_extend_space_to_desired_size( *actual_size = space->size; mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system->file_extend_mutex); return(TRUE); } @@ -4123,22 +4132,24 @@ fil_extend_space_to_desired_size( start_page_no = space->size; file_start_page_no = space->size - node->size; + mutex_exit(&fil_system->mutex); + #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { ib_int64_t start_offset = start_page_no * page_size; ib_int64_t end_offset = (size_after_extend - start_page_no) * page_size; ib_int64_t desired_size = size_after_extend*page_size; + int err = posix_fallocate( + node->handle, start_offset, end_offset); - mutex_exit(&fil_system->mutex); + success = !err; - if (posix_fallocate(node->handle, start_offset, end_offset) == -1) { - fprintf(stderr, "InnoDB: Error: preallocating file " - "space for file \'%s\' failed. Current size " - " %lld, len %lld, desired size %lld\n", - node->name, start_offset, end_offset, desired_size); - success = FALSE; - } else { - success = TRUE; + if (!success) { + fprintf(stderr, + "InnoDB: Error: extending file %s" + " from %lld to %lld bytes" + " failed with error %d\n", + node->name, start_offset, end_offset, err); } mutex_enter(&fil_system->mutex); @@ -4154,14 +4165,25 @@ fil_extend_space_to_desired_size( } #endif +#ifdef _WIN32 + /* Write 1 page of zeroes at the desired end. */ + start_page_no = size_after_extend - 1; + buf_size = page_size; +#else /* Extend at most 64 pages at a time */ buf_size = ut_min(64, size_after_extend - start_page_no) * page_size; - buf2 = mem_alloc(buf_size + page_size); +#endif + buf2 = calloc(1, buf_size + page_size); + if (!buf2) { + fprintf(stderr, "InnoDB: Cannot allocate " ULINTPF + " bytes to extend file\n", + buf_size + page_size); + mutex_exit(&fil_system->file_extend_mutex); + return(FALSE); + } buf = ut_align(buf2, page_size); - memset(buf, 0, buf_size); - - while (start_page_no < size_after_extend) { + for (;;) { ulint n_pages = ut_min(buf_size / page_size, size_after_extend - start_page_no); @@ -4170,6 +4192,7 @@ fil_extend_space_to_desired_size( offset_low = ((start_page_no - file_start_page_no) % (4096 * ((1024 * 1024) / page_size))) * page_size; + #ifdef UNIV_HOTBACKUP success = os_file_write(node->name, node->handle, buf, offset_low, offset_high, @@ -4181,34 +4204,37 @@ fil_extend_space_to_desired_size( page_size * n_pages, NULL, NULL); #endif + + /* Let us measure the size of the file to determine + how much we were able to extend it */ + + n_pages = (ulint) (os_file_get_size_as_iblonglong(node->handle) + / page_size); + + mutex_enter(&fil_system->mutex); + ut_a(n_pages >= node->size); + + start_page_no += n_pages - node->size; + space->size += n_pages - node->size; + node->size = n_pages; + if (success) { - node->size += n_pages; - space->size += n_pages; - os_has_said_disk_full = FALSE; - } else { - /* Let us measure the size of the file to determine - how much we were able to extend it */ - - n_pages = ((ulint) - (os_file_get_size_as_iblonglong( - node->handle) - / page_size)) - node->size; - - node->size += n_pages; - space->size += n_pages; + } + if (!success || start_page_no >= size_after_extend) { break; } - start_page_no += n_pages; + mutex_exit(&fil_system->mutex); } - mem_free(buf2); - + free(buf2); fil_node_complete_io(node, fil_system, OS_FILE_WRITE); +#ifdef HAVE_POSIX_FALLOCATE complete_io: +#endif /* HAVE_POSIX_FALLOCATE */ *actual_size = space->size; @@ -4228,6 +4254,7 @@ complete_io: printf("Extended %s to %lu, actual size %lu pages\n", space->name, size_after_extend, *actual_size); */ mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system->file_extend_mutex); fil_flush(space_id); diff --git a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h index bc8d0d27be3..f074ca2f189 100644 --- a/storage/innobase/include/sync0sync.h +++ b/storage/innobase/include/sync0sync.h @@ -675,6 +675,7 @@ or row lock! */ #define SYNC_BUF_BLOCK 146 /* Block mutex */ #define SYNC_BUF_FLUSH_LIST 145 /* Buffer flush list mutex */ #define SYNC_DOUBLEWRITE 140 +#define SYNC_OUTER_ANY_LATCH 136 #define SYNC_ANY_LATCH 135 #define SYNC_MEM_HASH 131 #define SYNC_MEM_POOL 130 diff --git a/storage/innobase/os/os0file.c b/storage/innobase/os/os0file.c index d792e7a61d8..72b9651f596 100644 --- a/storage/innobase/os/os0file.c +++ b/storage/innobase/os/os0file.c @@ -2,6 +2,7 @@ Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Percona Inc. +Copyright (c) 2012, 2017, MariaDB Corporation. All Rights Reserved. Portions of this file contain modifications contributed and copyrighted by Percona Inc.. Those modifications are @@ -2027,48 +2028,44 @@ os_file_set_size( ut_a(size == (size & 0xFFFFFFFF)); - current_size = 0; desired_size = (ib_int64_t)size + (((ib_int64_t)size_high) << 32); #ifdef HAVE_POSIX_FALLOCATE - if (srv_use_posix_fallocate) { - if (posix_fallocate(file, current_size, desired_size) == -1) { + if (srv_use_posix_fallocate) { + int err = posix_fallocate(file, 0, desired_size); + if (err) { fprintf(stderr, - "InnoDB: Error: preallocating data for" - " file %s failed at\n" - "InnoDB: offset 0 size %lld %lld. Operating system" - " error number %d.\n" - "InnoDB: Check that the disk is not full" - " or a disk quota exceeded.\n" - "InnoDB: Some operating system error numbers" - " are described at\n" - "InnoDB: " - REFMAN "operating-system-error-codes.html\n", - name, (long long)size_high, (long long)size, errno); - - return (FALSE); + "InnoDB: Error: preallocating %lld bytes for" + " file %s failed with error %d.\n", + desired_size, name, err); } - return (TRUE); + return(!err); } #endif +#ifdef _WIN32 + /* Write 1 page of zeroes at the desired end. */ + buf_size = UNIV_PAGE_SIZE; + current_size = desired_size - buf_size; +#else /* Write up to 1 megabyte at a time. */ buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE)) * UNIV_PAGE_SIZE; - buf2 = ut_malloc(buf_size + UNIV_PAGE_SIZE); + current_size = 0; +#endif + buf2 = calloc(1, buf_size + UNIV_PAGE_SIZE); + + if (!buf2) { + fprintf(stderr, "InnoDB: Cannot allocate " ULINTPF + " bytes to extend file\n", + buf_size + UNIV_PAGE_SIZE); + return(FALSE); + } /* Align the buffer for possible raw i/o */ buf = ut_align(buf2, UNIV_PAGE_SIZE); - /* Write buffer full of zeros */ - memset(buf, 0, buf_size); - - if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, "InnoDB: Progress in MB:"); - } - - while (current_size < desired_size) { + do { ulint n_bytes; if (desired_size - current_size < (ib_int64_t) buf_size) { @@ -2082,37 +2079,14 @@ os_file_set_size( (ulint)(current_size >> 32), n_bytes); if (!ret) { - ut_free(buf2); - goto error_handling; - } - - /* Print about progress for each 100 MB written */ - if ((ib_int64_t) (current_size + n_bytes) / (ib_int64_t)(100 * 1024 * 1024) - != current_size / (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, " %lu00", - (ulong) ((current_size + n_bytes) - / (ib_int64_t)(100 * 1024 * 1024))); + break; } current_size += n_bytes; - } + } while (current_size < desired_size); - if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, "\n"); - } - - ut_free(buf2); - - ret = os_file_flush(file); - - if (ret) { - return(TRUE); - } - -error_handling: - return(FALSE); + free(buf2); + return(ret && os_file_flush(file)); } /***********************************************************************//** diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 86e00dc22e4..3f9103c521f 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved. 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 @@ -4934,9 +4935,9 @@ fil_extend_space_to_desired_size( ulint page_size; ibool success = TRUE; - /* file_extend_mutex is for http://bugs.mysql.com/56433 */ - /* to protect from the other fil_extend_space_to_desired_size() */ - /* during temprary releasing &fil_system->mutex */ + /* fil_system->file_extend_mutex is for http://bugs.mysql.com/56433 + to prevent concurrent fil_extend_space_to_desired_size() + while fil_system->mutex is temporarily released */ mutex_enter(&fil_system->file_extend_mutex); fil_mutex_enter_and_prepare_for_io(space_id); @@ -4966,6 +4967,8 @@ fil_extend_space_to_desired_size( start_page_no = space->size; file_start_page_no = space->size - node->size; + mutex_exit(&fil_system->mutex); + #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { @@ -4973,19 +4976,19 @@ fil_extend_space_to_desired_size( = file_start_page_no * page_size; ib_int64_t end_offset = (size_after_extend - file_start_page_no) * page_size; + int err = posix_fallocate( + node->handle, start_offset, end_offset); - mutex_exit(&fil_system->mutex); - success = (posix_fallocate(node->handle, start_offset, - end_offset) == 0); - if (!success) - { + success = !err; + + if (!success) { fprintf(stderr, - "InnoDB: Error: preallocating file space for " - "file \'%s\' failed. Current size %lld, " - "len %lld, desired size %lld\n", node->name, - start_offset, end_offset, - start_offset + end_offset); + "InnoDB: Error: extending file %s" + " from %lld to %lld bytes" + " failed with error %d\n", + node->name, start_offset, end_offset, err); } + mutex_enter(&fil_system->mutex); if (success) { @@ -4999,14 +5002,25 @@ fil_extend_space_to_desired_size( } #endif +#ifdef _WIN32 + /* Write 1 page of zeroes at the desired end. */ + start_page_no = size_after_extend - 1; + buf_size = page_size; +#else /* Extend at most 64 pages at a time */ buf_size = ut_min(64, size_after_extend - start_page_no) * page_size; - buf2 = mem_alloc(buf_size + page_size); +#endif + buf2 = calloc(1, buf_size + page_size); + if (!buf2) { + fprintf(stderr, "InnoDB: Cannot allocate " ULINTPF + " bytes to extend file\n", + buf_size + page_size); + mutex_exit(&fil_system->file_extend_mutex); + return(FALSE); + } buf = ut_align(buf2, page_size); - memset(buf, 0, buf_size); - - while (start_page_no < size_after_extend) { + for (;;) { ulint n_pages = ut_min(buf_size / page_size, size_after_extend - start_page_no); @@ -5016,7 +5030,6 @@ fil_extend_space_to_desired_size( % (4096 * ((1024 * 1024) / page_size))) * page_size; - mutex_exit(&fil_system->mutex); #ifdef UNIV_HOTBACKUP success = os_file_write(node->name, node->handle, buf, offset_low, offset_high, @@ -5028,36 +5041,37 @@ fil_extend_space_to_desired_size( page_size * n_pages, NULL, NULL, space_id, NULL); #endif + + /* Let us measure the size of the file to determine + how much we were able to extend it */ + + n_pages = (ulint) (os_file_get_size_as_iblonglong(node->handle) + / page_size); + mutex_enter(&fil_system->mutex); + ut_a(n_pages >= node->size); + + start_page_no += n_pages - node->size; + space->size += n_pages - node->size; + node->size = n_pages; if (success) { - node->size += n_pages; - space->size += n_pages; - os_has_said_disk_full = FALSE; - } else { - /* Let us measure the size of the file to determine - how much we were able to extend it */ - - n_pages = ((ulint) - (os_file_get_size_as_iblonglong( - node->handle) - / page_size)) - node->size; - - node->size += n_pages; - space->size += n_pages; + } + if (!success || start_page_no >= size_after_extend) { break; } - start_page_no += n_pages; + mutex_exit(&fil_system->mutex); } - mem_free(buf2); - + free(buf2); fil_node_complete_io(node, fil_system, OS_FILE_WRITE); +#ifdef HAVE_POSIX_FALLOCATE complete_io: +#endif /* HAVE_POSIX_FALLOCATE */ *actual_size = space->size; diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index cca5ffa4772..201e4487ada 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -2,6 +2,7 @@ Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Percona Inc. +Copyright (c) 2011, 2017, MariaDB Corporation. All Rights Reserved. Portions of this file contain modifications contributed and copyrighted by Percona Inc.. Those modifications are @@ -2184,42 +2185,44 @@ os_file_set_size( ut_a(size == (size & 0xFFFFFFFF)); - current_size = 0; desired_size = (ib_int64_t)size + (((ib_int64_t)size_high) << 32); #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { - - if (posix_fallocate(file, current_size, desired_size) == -1) { - - fprintf(stderr, "InnoDB: Error: preallocating file " - "space for file \'%s\' failed. Current size " - "%lld, desired size %lld\n", - name, current_size, desired_size); - os_file_handle_error_no_exit(name, "posix_fallocate"); - return(FALSE); + int err = posix_fallocate(file, 0, desired_size); + if (err) { + fprintf(stderr, + "InnoDB: Error: preallocating %lld bytes for" + " file %s failed with error %d.\n", + desired_size, name, err); } - return(TRUE); + return(!err); } #endif +#ifdef _WIN32 + /* Write 1 page of zeroes at the desired end. */ + buf_size = UNIV_PAGE_SIZE; + current_size = desired_size - buf_size; +#else /* Write up to 1 megabyte at a time. */ buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE)) * UNIV_PAGE_SIZE; - buf2 = ut_malloc(buf_size + UNIV_PAGE_SIZE); + current_size = 0; +#endif + buf2 = calloc(1, buf_size + UNIV_PAGE_SIZE); + + if (!buf2) { + fprintf(stderr, "InnoDB: Cannot allocate " ULINTPF + " bytes to extend file\n", + buf_size + UNIV_PAGE_SIZE); + return(FALSE); + } /* Align the buffer for possible raw i/o */ buf = ut_align(buf2, UNIV_PAGE_SIZE); - /* Write buffer full of zeros */ - memset(buf, 0, buf_size); - - if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, "InnoDB: Progress in MB:"); - } - - while (current_size < desired_size) { + do { ulint n_bytes; if (desired_size - current_size < (ib_int64_t) buf_size) { @@ -2233,37 +2236,14 @@ os_file_set_size( (ulint)(current_size >> 32), n_bytes); if (!ret) { - ut_free(buf2); - goto error_handling; - } - - /* Print about progress for each 100 MB written */ - if ((ib_int64_t) (current_size + n_bytes) / (ib_int64_t)(100 * 1024 * 1024) - != current_size / (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, " %lu00", - (ulong) ((current_size + n_bytes) - / (ib_int64_t)(100 * 1024 * 1024))); + break; } current_size += n_bytes; - } + } while (current_size < desired_size); - if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) { - - fprintf(stderr, "\n"); - } - - ut_free(buf2); - - ret = os_file_flush(file, TRUE); - - if (ret) { - return(TRUE); - } - -error_handling: - return(FALSE); + free(buf2); + return(ret && os_file_flush(file, TRUE)); } /***********************************************************************//** From cf673adee2d1e43d5cdeab91c7f1fc3e73fa3b37 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 22 Feb 2017 01:36:16 +0400 Subject: [PATCH 15/43] MDEV-10418 Assertion `m_extra_cache' failed in ha_partition::late_extra_cache(uint). m_extra_prepare_for_update should be cleaned in ha_partition::reset() --- mysql-test/r/partition_myisam.result | 16 ++++++++++++++++ mysql-test/t/partition_myisam.test | 21 +++++++++++++++++++++ sql/ha_partition.cc | 1 + 3 files changed, 38 insertions(+) diff --git a/mysql-test/r/partition_myisam.result b/mysql-test/r/partition_myisam.result index f9bf3a9fb07..d54e2a2856a 100644 --- a/mysql-test/r/partition_myisam.result +++ b/mysql-test/r/partition_myisam.result @@ -248,3 +248,19 @@ PARTITION p1 VALUES LESS THAN (100) MAX_ROWS=100, PARTITION pMax VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (1, "Partition p1, first row"); DROP TABLE t1; +# +# MDEV-10418 Assertion `m_extra_cache' failed +# in ha_partition::late_extra_cache(uint) +# +CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 INT) ENGINE=MyISAM PARTITION BY RANGE(f2) (PARTITION pmax VALUES LESS THAN MAXVALUE); +INSERT INTO t2 VALUES (8); +CREATE ALGORITHM = MERGE VIEW v AS SELECT f2 FROM t2, t1; +UPDATE v SET f2 = 1; +SELECT * FROM t2; +f2 +1 +DROP VIEW v; +DROP TABLE t2; +DROP TABLE t1; diff --git a/mysql-test/t/partition_myisam.test b/mysql-test/t/partition_myisam.test index 0fdd351c714..d6b1af1379e 100644 --- a/mysql-test/t/partition_myisam.test +++ b/mysql-test/t/partition_myisam.test @@ -180,3 +180,24 @@ PARTITION BY RANGE (a) PARTITION pMax VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (1, "Partition p1, first row"); DROP TABLE t1; + +--echo # +--echo # MDEV-10418 Assertion `m_extra_cache' failed +--echo # in ha_partition::late_extra_cache(uint) +--echo # + +CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (f2 INT) ENGINE=MyISAM PARTITION BY RANGE(f2) (PARTITION pmax VALUES LESS THAN MAXVALUE); +INSERT INTO t2 VALUES (8); + +CREATE ALGORITHM = MERGE VIEW v AS SELECT f2 FROM t2, t1; + +UPDATE v SET f2 = 1; + +SELECT * FROM t2; + +DROP VIEW v; +DROP TABLE t2; +DROP TABLE t1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 15fa7d12b16..43743544c25 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -6667,6 +6667,7 @@ int ha_partition::reset(void) DBUG_ENTER("ha_partition::reset"); if (m_part_info) bitmap_set_all(&m_part_info->used_partitions); + m_extra_prepare_for_update= FALSE; file= m_file; do { From 32591b750fa52047d0b359c3fc02e9cf41631331 Mon Sep 17 00:00:00 2001 From: Sachin Setiya Date: Wed, 22 Feb 2017 11:40:01 +0530 Subject: [PATCH 16/43] MDEV-11718 5.5 rpl and federated tests massively fail in buildbot with valgrind Problem:- When MariaDB is compiled with jemalloc support, And we run mtr valgrind test, valgrind interferes with libjemalloc and returns false errors. Solution:- Run valgrind with --soname-synonyms=somalloc=libjemalloc* or --soname-synonyms=somalloc=NONE depending on whether we are dynamically linking or statically linking. Signed-off-by: Sachin Setiya --- mysql-test/mysql-test-run.pl | 9 +++++++++ mysql-test/valgrind.supp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 7bbbcead665..4229ceedb4d 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -6193,6 +6193,15 @@ sub valgrind_arguments { mtr_add_arg($args, "--num-callers=16"); mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir) if -f "$glob_mysql_test_dir/valgrind.supp"; + my $temp= `ldd $ENV{MTR_BINDIR}/sql/mysqld | grep 'libjemalloc'`; + if ($temp) + { + mtr_add_arg($args, "--soname-synonyms=somalloc=libjemalloc*"); + } + else + { + mtr_add_arg($args, "--soname-synonyms=somalloc=NONE"); + } } # Add valgrind options, can be overriden by user diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index 154031feb0d..4448f2a069a 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -1074,3 +1074,13 @@ ... fun:pthread_create* } + +{ + Memory Leak in loader and valgrind malloc + Memcheck:Leak + match-leak-kinds:reachable + obj:*/vgpreload_memcheck*.so + ... + obj:*/ld-*.so + ... +} From 6de50b2c7fd3a956ef8e32f5a76a65fd7a10969a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Feb 2017 09:17:30 +0200 Subject: [PATCH 17/43] MDEV-11520 post-fixes Remove the unused variable desired_size. Also, correct the expression for the posix_fallocate() start_offset, and actually test that it works with a multi-file system tablespace. Before MDEV-11520, the expression was wrong in both innodb_plugin and xtradb, in different ways. The start_offset formula was tested with the following: ./mtr --big-test --mysqld=--innodb-use-fallocate \ --mysqld=--innodb-data-file-path='ibdata1:5M;ibdata2:5M:autoextend' \ --parallel=auto --force --retry=0 --suite=innodb & ls -lsh mysql-test/var/*/mysqld.1/data/ibdata2 --- storage/innobase/fil/fil0fil.c | 8 +++++--- storage/xtradb/fil/fil0fil.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index 195fa7adde9..d3b1d2bc1d9 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -4136,9 +4136,11 @@ fil_extend_space_to_desired_size( #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { - ib_int64_t start_offset = start_page_no * page_size; - ib_int64_t end_offset = (size_after_extend - start_page_no) * page_size; - ib_int64_t desired_size = size_after_extend*page_size; + + ib_int64_t start_offset + = (start_page_no - file_start_page_no) * page_size; + ib_int64_t end_offset + = (size_after_extend - file_start_page_no) * page_size; int err = posix_fallocate( node->handle, start_offset, end_offset); diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 3f9103c521f..51491275ef6 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -4973,7 +4973,7 @@ fil_extend_space_to_desired_size( if (srv_use_posix_fallocate) { ib_int64_t start_offset - = file_start_page_no * page_size; + = (start_page_no - file_start_page_no) * page_size; ib_int64_t end_offset = (size_after_extend - file_start_page_no) * page_size; int err = posix_fallocate( From 365c4e971a684151762058befb27b54832dc8779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Feb 2017 10:03:33 +0200 Subject: [PATCH 18/43] MDEV-11520/MDEV-5746 post-fix: Do not posix_fallocate() too much. Before the MDEV-11520 fixes, fil_extend_space_to_desired_size() in MariaDB Server 5.5 incorrectly passed the desired file size as the third argument to posix_fallocate(), even though the length of the extension should have been passed. This looks like a regression that was introduced in the 5.5 version of MDEV-5746. --- storage/innobase/fil/fil0fil.c | 11 +++++------ storage/xtradb/fil/fil0fil.c | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index d3b1d2bc1d9..46338b079da 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -4136,13 +4136,11 @@ fil_extend_space_to_desired_size( #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { - ib_int64_t start_offset = (start_page_no - file_start_page_no) * page_size; - ib_int64_t end_offset - = (size_after_extend - file_start_page_no) * page_size; - int err = posix_fallocate( - node->handle, start_offset, end_offset); + ib_int64_t len + = (size_after_extend - start_page_no) * page_size; + int err = posix_fallocate(node->handle, start_offset, len); success = !err; @@ -4151,7 +4149,8 @@ fil_extend_space_to_desired_size( "InnoDB: Error: extending file %s" " from %lld to %lld bytes" " failed with error %d\n", - node->name, start_offset, end_offset, err); + node->name, + start_offset, len + start_offset, err); } mutex_enter(&fil_system->mutex); diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 51491275ef6..3a45cc6c098 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -4971,13 +4971,11 @@ fil_extend_space_to_desired_size( #ifdef HAVE_POSIX_FALLOCATE if (srv_use_posix_fallocate) { - ib_int64_t start_offset = (start_page_no - file_start_page_no) * page_size; - ib_int64_t end_offset - = (size_after_extend - file_start_page_no) * page_size; - int err = posix_fallocate( - node->handle, start_offset, end_offset); + ib_int64_t len + = (size_after_extend - start_page_no) * page_size; + int err = posix_fallocate(node->handle, start_offset, len); success = !err; @@ -4986,7 +4984,8 @@ fil_extend_space_to_desired_size( "InnoDB: Error: extending file %s" " from %lld to %lld bytes" " failed with error %d\n", - node->name, start_offset, end_offset, err); + node->name, + start_offset, len + start_offset, err); } mutex_enter(&fil_system->mutex); From bdb672fe96cfb75baab0ea1f1db8870d6cb8911b Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Thu, 23 Feb 2017 19:46:10 +0200 Subject: [PATCH 19/43] MDEV-12120 tokudb_bugs.xa-N tests fail with timeout on valgrind The tests are disabled for valgrind in 5.6/10.x (LP:1549196), so they should be disabled in 5.5 as well --- storage/tokudb/mysql-test/tokudb_bugs/t/xa-3.test | 1 + storage/tokudb/mysql-test/tokudb_bugs/t/xa-4.test | 1 + storage/tokudb/mysql-test/tokudb_bugs/t/xa-6.test | 1 + 3 files changed, 3 insertions(+) diff --git a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-3.test b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-3.test index 116d5b5d99b..5e3db1b11b6 100644 --- a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-3.test +++ b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-3.test @@ -2,6 +2,7 @@ -- source include/have_tokudb.inc -- source include/have_debug.inc -- source include/not_embedded.inc +-- source include/not_valgrind.inc --disable_warnings drop table if exists t1, t2; diff --git a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-4.test b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-4.test index 014b371630f..4992eae3f5f 100644 --- a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-4.test +++ b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-4.test @@ -2,6 +2,7 @@ -- source include/have_tokudb.inc -- source include/have_debug.inc -- source include/not_embedded.inc +-- source include/not_valgrind.inc --disable_warnings drop table if exists t1, t2; diff --git a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-6.test b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-6.test index 3d9e1be711b..495849e862c 100644 --- a/storage/tokudb/mysql-test/tokudb_bugs/t/xa-6.test +++ b/storage/tokudb/mysql-test/tokudb_bugs/t/xa-6.test @@ -1,5 +1,6 @@ --source include/have_tokudb.inc --source include/have_debug.inc +-- source include/not_valgrind.inc --disable_warnings drop table if exists t1; From ac78927aefa2bd0d869d999839480d69086a9882 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 24 Feb 2017 00:10:08 -0800 Subject: [PATCH 20/43] Fixed bug mdev-7992. 'Not exists' optimization can be used for nested outer joins only if IS NULL predicate from the WHERE condition is activated. So we have to check that all guards that wrap this predicate are in the 'open' state. This patch supports usage of 'Not exists' optimization for any outer join, no matter how it's nested in other outer joins. This patch is also considered as a proper fix for bugs #49322/#58490 and LP #817360. --- mysql-test/r/join_nested.result | 95 ++++++++++++++++++++++++++++ mysql-test/r/join_nested_jcl6.result | 95 ++++++++++++++++++++++++++++ mysql-test/t/join_nested.test | 71 ++++++++++++++++++++- sql/sql_select.cc | 73 ++++++++++----------- 4 files changed, 294 insertions(+), 40 deletions(-) diff --git a/mysql-test/r/join_nested.result b/mysql-test/r/join_nested.result index 84b6ff640e9..6ddd39cbfec 100644 --- a/mysql-test/r/join_nested.result +++ b/mysql-test/r/join_nested.result @@ -1870,4 +1870,99 @@ f4 NULL NULL DROP TABLE t1,t2,t3,t4,t5; +# +# MDEV-7992: Nested left joins + 'not exists' optimization +# +CREATE TABLE t1( +K1 INT PRIMARY KEY, +Name VARCHAR(15) +); +INSERT INTO t1 VALUES +(1,'T1Row1'), (2,'T1Row2'); +CREATE TABLE t2( +K2 INT PRIMARY KEY, +K1r INT, +rowTimestamp DATETIME, +Event VARCHAR(15) +); +INSERT INTO t2 VALUES +(1, 1, '2015-04-13 10:42:11' ,'T1Row1Event1'), +(2, 1, '2015-04-13 10:42:12' ,'T1Row1Event2'), +(3, 1, '2015-04-13 10:42:12' ,'T1Row1Event3'); +SELECT t1a.*, t2a.*, +t2i.K2 AS K2B, t2i.K1r AS K1rB, +t2i.rowTimestamp AS rowTimestampB, t2i.Event AS EventB +FROM +t1 t1a JOIN t2 t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +( t1 t1i LEFT JOIN t2 t2i ON t2i.K1r = t1i.K1) +ON (t1i.K1 = 1) AND +(((t2i.K1r = t1a.K1 AND t2i.rowTimestamp > t2a.rowTimestamp ) OR +(t2i.rowTimestamp = t2a.rowTimestamp AND t2i.K2 > t2a.K2)) +OR (t2i.K2 IS NULL)) +WHERE +t2a.K1r = 1 AND t2i.K2 IS NULL; +K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB +1 T1Row1 3 1 2015-04-13 10:42:12 T1Row1Event3 NULL NULL NULL NULL +EXPLAIN EXTENDED SELECT t1a.*, t2a.*, +t2i.K2 AS K2B, t2i.K1r AS K1rB, +t2i.rowTimestamp AS rowTimestampB, t2i.Event AS EventB +FROM +t1 t1a JOIN t2 t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +( t1 t1i LEFT JOIN t2 t2i ON t2i.K1r = t1i.K1) +ON (t1i.K1 = 1) AND +(((t2i.K1r = t1a.K1 AND t2i.rowTimestamp > t2a.rowTimestamp ) OR +(t2i.rowTimestamp = t2a.rowTimestamp AND t2i.K2 > t2a.K2)) +OR (t2i.K2 IS NULL)) +WHERE +t2a.K1r = 1 AND t2i.K2 IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1a const PRIMARY PRIMARY 4 const 1 100.00 +1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index +1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists +Warnings: +Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`test`.`t2a`.`K2` AS `K2`,`test`.`t2a`.`K1r` AS `K1r`,`test`.`t2a`.`rowTimestamp` AS `rowTimestamp`,`test`.`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `test`.`t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `test`.`t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `test`.`t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`test`.`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`)) +CREATE VIEW v1 AS +SELECT t2i.* +FROM t1 as t1i LEFT JOIN t2 as t2i ON t2i.K1r = t1i.K1 +WHERE t1i.K1 = 1 ; +SELECT +t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB, +t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB +FROM +t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +v1 as t2b +ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR +(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2)) +OR (t2b.K2 IS NULL) +WHERE +t1a.K1 = 1 AND +t2b.K2 IS NULL; +K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB +1 T1Row1 3 1 2015-04-13 10:42:12 T1Row1Event3 NULL NULL NULL NULL +EXPLAIN EXTENDED SELECT +t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB, +t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB +FROM +t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +v1 as t2b +ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR +(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2)) +OR (t2b.K2 IS NULL) +WHERE +t1a.K1 = 1 AND +t2b.K2 IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1a const PRIMARY PRIMARY 4 const 1 100.00 +1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index +1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists +Warnings: +Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`t2a`.`K2` AS `K2`,`t2a`.`K1r` AS `K1r`,`t2a`.`rowTimestamp` AS `rowTimestamp`,`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`)) +DROP VIEW v1; +DROP TABLE t1,t2; set optimizer_search_depth= @tmp_mdev621; diff --git a/mysql-test/r/join_nested_jcl6.result b/mysql-test/r/join_nested_jcl6.result index 3b47645ca79..bac8e1cb7db 100644 --- a/mysql-test/r/join_nested_jcl6.result +++ b/mysql-test/r/join_nested_jcl6.result @@ -1881,6 +1881,101 @@ f4 NULL NULL DROP TABLE t1,t2,t3,t4,t5; +# +# MDEV-7992: Nested left joins + 'not exists' optimization +# +CREATE TABLE t1( +K1 INT PRIMARY KEY, +Name VARCHAR(15) +); +INSERT INTO t1 VALUES +(1,'T1Row1'), (2,'T1Row2'); +CREATE TABLE t2( +K2 INT PRIMARY KEY, +K1r INT, +rowTimestamp DATETIME, +Event VARCHAR(15) +); +INSERT INTO t2 VALUES +(1, 1, '2015-04-13 10:42:11' ,'T1Row1Event1'), +(2, 1, '2015-04-13 10:42:12' ,'T1Row1Event2'), +(3, 1, '2015-04-13 10:42:12' ,'T1Row1Event3'); +SELECT t1a.*, t2a.*, +t2i.K2 AS K2B, t2i.K1r AS K1rB, +t2i.rowTimestamp AS rowTimestampB, t2i.Event AS EventB +FROM +t1 t1a JOIN t2 t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +( t1 t1i LEFT JOIN t2 t2i ON t2i.K1r = t1i.K1) +ON (t1i.K1 = 1) AND +(((t2i.K1r = t1a.K1 AND t2i.rowTimestamp > t2a.rowTimestamp ) OR +(t2i.rowTimestamp = t2a.rowTimestamp AND t2i.K2 > t2a.K2)) +OR (t2i.K2 IS NULL)) +WHERE +t2a.K1r = 1 AND t2i.K2 IS NULL; +K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB +1 T1Row1 3 1 2015-04-13 10:42:12 T1Row1Event3 NULL NULL NULL NULL +EXPLAIN EXTENDED SELECT t1a.*, t2a.*, +t2i.K2 AS K2B, t2i.K1r AS K1rB, +t2i.rowTimestamp AS rowTimestampB, t2i.Event AS EventB +FROM +t1 t1a JOIN t2 t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +( t1 t1i LEFT JOIN t2 t2i ON t2i.K1r = t1i.K1) +ON (t1i.K1 = 1) AND +(((t2i.K1r = t1a.K1 AND t2i.rowTimestamp > t2a.rowTimestamp ) OR +(t2i.rowTimestamp = t2a.rowTimestamp AND t2i.K2 > t2a.K2)) +OR (t2i.K2 IS NULL)) +WHERE +t2a.K1r = 1 AND t2i.K2 IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1a const PRIMARY PRIMARY 4 const 1 100.00 +1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index +1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists +Warnings: +Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`test`.`t2a`.`K2` AS `K2`,`test`.`t2a`.`K1r` AS `K1r`,`test`.`t2a`.`rowTimestamp` AS `rowTimestamp`,`test`.`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `test`.`t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `test`.`t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `test`.`t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`test`.`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`)) +CREATE VIEW v1 AS +SELECT t2i.* +FROM t1 as t1i LEFT JOIN t2 as t2i ON t2i.K1r = t1i.K1 +WHERE t1i.K1 = 1 ; +SELECT +t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB, +t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB +FROM +t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +v1 as t2b +ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR +(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2)) +OR (t2b.K2 IS NULL) +WHERE +t1a.K1 = 1 AND +t2b.K2 IS NULL; +K1 Name K2 K1r rowTimestamp Event K2B K1rB rowTimestampB EventB +1 T1Row1 3 1 2015-04-13 10:42:12 T1Row1Event3 NULL NULL NULL NULL +EXPLAIN EXTENDED SELECT +t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB, +t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB +FROM +t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1 +LEFT JOIN +v1 as t2b +ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR +(t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2)) +OR (t2b.K2 IS NULL) +WHERE +t1a.K1 = 1 AND +t2b.K2 IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1a const PRIMARY PRIMARY 4 const 1 100.00 +1 SIMPLE t2a ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t1i const PRIMARY PRIMARY 4 const 1 100.00 Using index +1 SIMPLE t2i ALL NULL NULL NULL NULL 3 100.00 Using where; Not exists +Warnings: +Note 1003 select 1 AS `K1`,'T1Row1' AS `Name`,`t2a`.`K2` AS `K2`,`t2a`.`K1r` AS `K1r`,`t2a`.`rowTimestamp` AS `rowTimestamp`,`t2a`.`Event` AS `Event`,`test`.`t2i`.`K2` AS `K2B`,`test`.`t2i`.`K1r` AS `K1rB`,`test`.`t2i`.`rowTimestamp` AS `rowTimestampB`,`test`.`t2i`.`Event` AS `EventB` from `test`.`t1` `t1a` join `test`.`t2` `t2a` left join (`test`.`t1` `t1i` left join `test`.`t2` `t2i` on((`test`.`t2i`.`K1r` = 1))) on(((`test`.`t1i`.`K1` = 1) and (((`test`.`t2i`.`K1r` = 1) and (`test`.`t2i`.`rowTimestamp` > `t2a`.`rowTimestamp`)) or ((`test`.`t2i`.`rowTimestamp` = `t2a`.`rowTimestamp`) and (`test`.`t2i`.`K2` > `t2a`.`K2`)) or isnull(`test`.`t2i`.`K2`)))) where ((`t2a`.`K1r` = 1) and isnull(`test`.`t2i`.`K2`)) +DROP VIEW v1; +DROP TABLE t1,t2; set optimizer_search_depth= @tmp_mdev621; CREATE TABLE t5 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); CREATE TABLE t6 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test index 7b7d9236835..e60b7827f75 100644 --- a/mysql-test/t/join_nested.test +++ b/mysql-test/t/join_nested.test @@ -1309,5 +1309,74 @@ LEFT JOIN t4 AS alias5 JOIN t5 ON alias5.f5 ON alias2.f3 ON alias1.f2; DROP TABLE t1,t2,t3,t4,t5; -set optimizer_search_depth= @tmp_mdev621; +--echo # +--echo # MDEV-7992: Nested left joins + 'not exists' optimization +--echo # + +CREATE TABLE t1( + K1 INT PRIMARY KEY, + Name VARCHAR(15) +); + +INSERT INTO t1 VALUES + (1,'T1Row1'), (2,'T1Row2'); + + +CREATE TABLE t2( + K2 INT PRIMARY KEY, + K1r INT, + rowTimestamp DATETIME, + Event VARCHAR(15) +); + +INSERT INTO t2 VALUES + (1, 1, '2015-04-13 10:42:11' ,'T1Row1Event1'), + (2, 1, '2015-04-13 10:42:12' ,'T1Row1Event2'), + (3, 1, '2015-04-13 10:42:12' ,'T1Row1Event3'); + +let $q1= +SELECT t1a.*, t2a.*, + t2i.K2 AS K2B, t2i.K1r AS K1rB, + t2i.rowTimestamp AS rowTimestampB, t2i.Event AS EventB +FROM + t1 t1a JOIN t2 t2a ON t2a.K1r = t1a.K1 + LEFT JOIN + ( t1 t1i LEFT JOIN t2 t2i ON t2i.K1r = t1i.K1) + ON (t1i.K1 = 1) AND + (((t2i.K1r = t1a.K1 AND t2i.rowTimestamp > t2a.rowTimestamp ) OR + (t2i.rowTimestamp = t2a.rowTimestamp AND t2i.K2 > t2a.K2)) + OR (t2i.K2 IS NULL)) +WHERE +t2a.K1r = 1 AND t2i.K2 IS NULL; + +eval $q1; +eval EXPLAIN EXTENDED $q1; + +CREATE VIEW v1 AS + SELECT t2i.* + FROM t1 as t1i LEFT JOIN t2 as t2i ON t2i.K1r = t1i.K1 + WHERE t1i.K1 = 1 ; + +let $q2= +SELECT + t1a.*, t2a.*, t2b.K2 as K2B, t2b.K1r as K1rB, + t2b.rowTimestamp as rowTimestampB, t2b.Event as EventB +FROM + t1 as t1a JOIN t2 as t2a ON t2a.K1r = t1a.K1 + LEFT JOIN + v1 as t2b + ON ((t2b.K1r = t1a.K1 AND t2b.rowTimestamp > t2a.rowTimestamp) OR + (t2b.rowTimestamp = t2a.rowTimestamp AND t2b.K2 > t2a.K2)) + OR (t2b.K2 IS NULL) +WHERE + t1a.K1 = 1 AND + t2b.K2 IS NULL; + +eval $q2; +eval EXPLAIN EXTENDED $q2; + +DROP VIEW v1; +DROP TABLE t1,t2; + +set optimizer_search_depth= @tmp_mdev621; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d9433a4167a..4133c8258a2 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7793,8 +7793,6 @@ get_best_combination(JOIN *join) form=join->table[tablenr]=j->table; used_tables|= form->map; form->reginfo.join_tab=j; - if (!*j->on_expr_ref) - form->reginfo.not_exists_optimize=0; // Only with LEFT JOIN DBUG_PRINT("info",("type: %d", j->type)); if (j->type == JT_CONST) goto loop_end; // Handled in make_join_stat.. @@ -8625,7 +8623,10 @@ make_outerjoin_info(JOIN *join) tab->cond_equal= tbl->cond_equal; if (embedding && !embedding->is_active_sjm()) tab->first_upper= embedding->nested_join->first_nested; - } + } + else if (!embedding) + tab->table->reginfo.not_exists_optimize= 0; + for ( ; embedding ; embedding= embedding->embedding) { if (embedding->is_active_sjm()) @@ -8635,7 +8636,10 @@ make_outerjoin_info(JOIN *join) } /* Ignore sj-nests: */ if (!(embedding->on_expr && embedding->outer_join)) + { + tab->table->reginfo.not_exists_optimize= 0; continue; + } NESTED_JOIN *nested_join= embedding->nested_join; if (!nested_join->counter) { @@ -8651,17 +8655,10 @@ make_outerjoin_info(JOIN *join) } if (!tab->first_inner) tab->first_inner= nested_join->first_nested; - if (tab->table->reginfo.not_exists_optimize) - tab->first_inner->table->reginfo.not_exists_optimize= 1; if (++nested_join->counter < nested_join->n_tables) break; /* Table tab is the last inner table for nested join. */ nested_join->first_nested->last_inner= tab; - if (tab->first_inner->table->reginfo.not_exists_optimize) - { - for (JOIN_TAB *join_tab= tab->first_inner; join_tab <= tab; join_tab++) - join_tab->table->reginfo.not_exists_optimize= 1; - } } } DBUG_RETURN(FALSE); @@ -17099,32 +17096,41 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, first_unmatched->found= 1; for (JOIN_TAB *tab= first_unmatched; tab <= join_tab; tab++) { + /* + Check whether 'not exists' optimization can be used here. + If tab->table->reginfo.not_exists_optimize is set to true + then WHERE contains a conjunctive predicate IS NULL over + a non-nullable field of tab. When activated this predicate + will filter out all records with matches for the left part + of the outer join whose inner tables start from the + first_unmatched table and include table tab. To safely use + 'not exists' optimization we have to check that the + IS NULL predicate is really activated, i.e. all guards + that wrap it are in the 'open' state. + */ + bool not_exists_opt_is_applicable= + tab->table->reginfo.not_exists_optimize; + for (JOIN_TAB *first_upper= first_unmatched->first_upper; + not_exists_opt_is_applicable && first_upper; + first_upper= first_upper->first_upper) + { + if (!first_upper->found) + not_exists_opt_is_applicable= false; + } /* Check all predicates that has just been activated. */ /* Actually all predicates non-guarded by first_unmatched->found will be re-evaluated again. It could be fixed, but, probably, it's not worth doing now. */ - /* - not_exists_optimize has been created from a - select_cond containing 'is_null'. This 'is_null' - predicate is still present on any 'tab' with - 'not_exists_optimize'. Furthermore, the usual rules - for condition guards also applies for - 'not_exists_optimize' -> When 'is_null==false' we - know all cond. guards are open and we can apply - the 'not_exists_optimize'. - */ - DBUG_ASSERT(!(tab->table->reginfo.not_exists_optimize && - !tab->select_cond)); - if (tab->select_cond && !tab->select_cond->val_int()) { /* The condition attached to table tab is false */ - if (tab == join_tab) { found= 0; + if (not_exists_opt_is_applicable) + DBUG_RETURN(NESTED_LOOP_NO_MORE_ROWS); } else { @@ -17133,21 +17139,10 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, not to the last table of the current nest level. */ join->return_tab= tab; - } - - if (tab->table->reginfo.not_exists_optimize) - { - /* - When not_exists_optimize is set: No need to further - explore more rows of 'tab' for this partial result. - Any found 'tab' matches are known to evaluate to 'false'. - Returning .._NO_MORE_ROWS will skip rem. 'tab' rows. - */ - DBUG_RETURN(NESTED_LOOP_NO_MORE_ROWS); - } - else if (tab != join_tab) - { - DBUG_RETURN(NESTED_LOOP_OK); + if (not_exists_opt_is_applicable) + DBUG_RETURN(NESTED_LOOP_NO_MORE_ROWS); + else + DBUG_RETURN(NESTED_LOOP_OK); } } } From eef21014898d61e77890359d6546d4985d829ef6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 16 Feb 2017 11:32:47 +0100 Subject: [PATCH 21/43] MDEV-11933 Wrong usage of linked list in mysql_prune_stmt_list mysql_prune_stmt_list() was walking the list following element->next pointers, but inside the loop it was invoking list_add(element) that modified element->next. So, mysql_prune_stmt_list() failed to visit and reset all elements, and some of them were left with pointers to invalid MYSQL. --- sql-common/client.c | 11 ++------- tests/mysql_client_test.c | 50 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index c2e0cc3161a..b348afcff2d 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1,5 +1,5 @@ /* Copyright (c) 2003, 2016, Oracle and/or its affiliates. - Copyright (c) 2009, 2016, MariaDB + Copyright (c) 2009, 2017, 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 @@ -3819,8 +3819,6 @@ static void mysql_close_free(MYSQL *mysql) static void mysql_prune_stmt_list(MYSQL *mysql) { LIST *element= mysql->stmts; - LIST *pruned_list= 0; - for (; element; element= element->next) { MYSQL_STMT *stmt= (MYSQL_STMT *) element->data; @@ -3830,14 +3828,9 @@ static void mysql_prune_stmt_list(MYSQL *mysql) stmt->last_errno= CR_SERVER_LOST; strmov(stmt->last_error, ER(CR_SERVER_LOST)); strmov(stmt->sqlstate, unknown_sqlstate); - } - else - { - pruned_list= list_add(pruned_list, element); + mysql->stmts= list_delete(mysql->stmts, element); } } - - mysql->stmts= pruned_list; } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 446018e6906..f62545daa21 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -1,5 +1,5 @@ -/* Copyright (c) 2002, 2012, Oracle and/or its affiliates. - Copyright (c) 2008, 2012, Monty Program Ab +/* Copyright (c) 2002, 2014, Oracle and/or its affiliates. + Copyright (c) 2008, 2017, 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 @@ -19031,6 +19031,49 @@ static void test_mdev4326() myquery(rc); } + +/** + BUG#17512527: LIST HANDLING INCORRECT IN MYSQL_PRUNE_STMT_LIST() +*/ +static void test_bug17512527() +{ + MYSQL *conn; + MYSQL_STMT *stmt1, *stmt2; + unsigned long thread_id; + char query[MAX_TEST_QUERY_LENGTH]; + int rc; + + conn= client_connect(0, MYSQL_PROTOCOL_SOCKET, 1); + + stmt1 = mysql_stmt_init(conn); + check_stmt(stmt1); + rc= mysql_stmt_prepare(stmt1, STRING_WITH_LEN("SELECT 1")); + check_execute(stmt1, rc); + + stmt2 = mysql_stmt_init(conn); + check_stmt(stmt2); + + thread_id= mysql_thread_id(conn); + sprintf(query, "KILL %lu", thread_id); + if (thread_query(query)) + exit(1); + + rc= mysql_stmt_prepare(stmt2, STRING_WITH_LEN("SELECT 2")); + check_execute(stmt2, rc); + + rc= mysql_stmt_execute(stmt1); + check_execute_r(stmt1, rc); + + rc= mysql_stmt_execute(stmt2); + check_execute(stmt2, rc); + + mysql_close(conn); + + mysql_stmt_close(stmt2); + mysql_stmt_close(stmt1); +} + + static struct my_tests_st my_tests[]= { { "disable_query_logs", disable_query_logs }, { "test_view_sp_list_fields", test_view_sp_list_fields }, @@ -19297,6 +19340,9 @@ static struct my_tests_st my_tests[]= { { "test_bug13001491", test_bug13001491 }, { "test_mdev4326", test_mdev4326 }, { "test_ps_sp_out_params", test_ps_sp_out_params }, +#ifndef _WIN32 + { "test_bug17512527", test_bug17512527}, +#endif { 0, 0 } }; From 8897b50dca49df288595a9146631c4b789de7685 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 16 Feb 2017 13:24:00 +0100 Subject: [PATCH 22/43] MDEV-11525 Assertion `cp + len <= buff + buff_size' failed in JOIN_CACHE::write_record_data Workaround for join_cache + index on vcols + keyread bug. Initialize the record to avoid caching garbage in non-read fields. A proper fix (do not cache non-read fields at all) is done in 10.2 in commits 5d7607f340f..8d99166c697 --- .../suite/vcol/r/vcol_select_myisam.result | 109 ++++++++++++++++++ .../suite/vcol/t/vcol_select_myisam.test | 32 +++++ sql/sql_join_cache.cc | 5 + 3 files changed, 146 insertions(+) diff --git a/mysql-test/suite/vcol/r/vcol_select_myisam.result b/mysql-test/suite/vcol/r/vcol_select_myisam.result index 934d047f6bf..6dee132b3e5 100644 --- a/mysql-test/suite/vcol/r/vcol_select_myisam.result +++ b/mysql-test/suite/vcol/r/vcol_select_myisam.result @@ -295,3 +295,112 @@ Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` SELECT * FROM t1 NATURAL JOIN t2; b a DROP TABLE t1,t2; +create table t1 ( +pk integer auto_increment, +bi integer not null, +vi integer generated always as (bi) persistent, +bc varchar(1) not null, +vc varchar(2) generated always as (concat(bc, bc)) persistent, +primary key (pk), +key (vi, vc)); +insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v'); +create table t2 ( +pk integer auto_increment, +bi integer not null, +vi integer generated always as (bi) persistent, +bc varchar(257) not null, +vc varchar(2) generated always as (concat(bc, bc)) persistent, +primary key (pk), +key (vi, vc)); +insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y'); +explain # should be using join buffer +select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL vi 10 NULL 19 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 19 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 index NULL PRIMARY 4 NULL 19 Using where; Using index; Using join buffer (incremental, BNL join) +select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc)); +vi +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +2 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +4 +6 +6 +6 +6 +7 +7 +8 +8 +8 +8 +9 +9 +drop table t2,t1; diff --git a/mysql-test/suite/vcol/t/vcol_select_myisam.test b/mysql-test/suite/vcol/t/vcol_select_myisam.test index c14faba576d..b392b74c2d9 100644 --- a/mysql-test/suite/vcol/t/vcol_select_myisam.test +++ b/mysql-test/suite/vcol/t/vcol_select_myisam.test @@ -68,3 +68,35 @@ SELECT * FROM t1 NATURAL JOIN t2; SELECT * FROM t1 NATURAL JOIN t2; DROP TABLE t1,t2; + +# +# MDEV-11525 Assertion `cp + len <= buff + buff_size' failed in JOIN_CACHE::write_record_data +# + +create table t1 ( + pk integer auto_increment, + bi integer not null, + vi integer generated always as (bi) persistent, + bc varchar(1) not null, + vc varchar(2) generated always as (concat(bc, bc)) persistent, + primary key (pk), + key (vi, vc)); +insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v'); +create table t2 ( + pk integer auto_increment, + bi integer not null, + vi integer generated always as (bi) persistent, + bc varchar(257) not null, + vc varchar(2) generated always as (concat(bc, bc)) persistent, + primary key (pk), + key (vi, vc)); +insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y'); +explain # should be using join buffer +select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc)); +--sorted_result +select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc)); +drop table t2,t1; + +# +# End of 5.5 tests +# diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 9411b3a92c8..820ac75c885 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -589,6 +589,11 @@ void JOIN_CACHE::create_remaining_fields() { MY_BITMAP *rem_field_set; TABLE *table= tab->table; +#if MYSQL_VERSION_ID < 100204 + empty_record(table); +#else +#error remove +#endif if (all_read_fields) rem_field_set= table->read_set; From 924a81a548994bd61e9b8ea662bdb64ef1c12ea0 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 15:06:25 +0100 Subject: [PATCH 23/43] bugfix: DEBUG_SYNC() invoked with no THD While DEBUG_SYNC doesn't make sense without a valid THD, it might be put in the code that's invoked both within and outside of a THD context (e.g. in maria_open(), there is no THD during recovery). --- sql/debug_sync.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 4cff1c09ba7..82203505f50 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -1520,6 +1520,8 @@ static void debug_sync(THD *thd, const char *sync_point_name, size_t name_len) { if (!thd) thd= current_thd; + if (!thd) + return; st_debug_sync_control *ds_control= thd->debug_sync_control; st_debug_sync_action *action; From 3cba74e032050b126eaf1fd27072b1afaeef79b3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 10:01:31 +0100 Subject: [PATCH 24/43] cleanup: fn_format, remove dead code my_realpath() ignores MY_xxx flags anyway --- mysys/mf_format.c | 7 +------ sql/sql_parse.cc | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/mysys/mf_format.c b/mysys/mf_format.c index d20ce882459..996fee68bd1 100644 --- a/mysys/mf_format.c +++ b/mysys/mf_format.c @@ -97,13 +97,8 @@ char * fn_format(char * to, const char *name, const char *dir, pos=strmake(strmov(to,dev),name,length); (void) strmov(pos,ext); /* Don't convert extension */ } - /* - If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do - realpath if the file is a symbolic link - */ if (flag & MY_RETURN_REAL_PATH) - (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ? - MY_RESOLVE_LINK: 0)); + (void) my_realpath(to, to, MYF(0)); else if (flag & MY_RESOLVE_SYMLINKS) { strmov(buff,to); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3afabc079d0..a12a2c4193c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7715,8 +7715,7 @@ int test_if_data_home_dir(const char *dir) if (!dir) DBUG_RETURN(0); - (void) fn_format(path, dir, "", "", - (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS)); + (void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH); dir_len= strlen(path); if (mysql_unpacked_real_data_home_len<= dir_len) { From 24d8bc707a3d3161229b1cfc94b34dc50473bc59 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 10:08:49 +0100 Subject: [PATCH 25/43] cleanup: my_register_filename() Don't let my_register_filename() fail because strdup() failed. Better to have NULL for a filename, then to fail the already successful open(). Filenames are only used for error reporting and there was already code to ignore OOMs (my_fdopen()) and to cope with missing filenames (my_filename()). --- mysys/my_create.c | 20 +++----------------- mysys/my_div.c | 2 +- mysys/my_fopen.c | 18 ++++++------------ mysys/my_open.c | 27 +++++++++------------------ 4 files changed, 19 insertions(+), 48 deletions(-) diff --git a/mysys/my_create.c b/mysys/my_create.c index 2e4e8eb1af2..e9a1365ca19 100644 --- a/mysys/my_create.c +++ b/mysys/my_create.c @@ -36,7 +36,7 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, myf MyFlags) { - int fd, rc; + int fd; DBUG_ENTER("my_create"); DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %d", FileName, CreateFlags, access_flags, MyFlags)); @@ -54,21 +54,7 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, fd= -1; } - rc= my_register_filename(fd, FileName, FILE_BY_CREATE, + fd= my_register_filename(fd, FileName, FILE_BY_CREATE, EE_CANTCREATEFILE, MyFlags); - /* - my_register_filename() may fail on some platforms even if the call to - *open() above succeeds. In this case, don't leave the stale file because - callers assume the file to not exist if my_create() fails, so they don't - do any cleanups. - */ - if (unlikely(fd >= 0 && rc < 0)) - { - int tmp= my_errno; - my_close(fd, MyFlags); - my_delete(FileName, MyFlags); - my_errno= tmp; - } - - DBUG_RETURN(rc); + DBUG_RETURN(fd); } /* my_create */ diff --git a/mysys/my_div.c b/mysys/my_div.c index 660b87e5ab4..44eb5392421 100644 --- a/mysys/my_div.c +++ b/mysys/my_div.c @@ -27,7 +27,7 @@ char * my_filename(File fd) { DBUG_ENTER("my_filename"); - if ((uint) fd >= (uint) my_file_limit) + if ((uint) fd >= (uint) my_file_limit || !my_file_info[fd].name) DBUG_RETURN((char*) "UNKNOWN"); if (fd >= 0 && my_file_info[fd].type != UNOPEN) { diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c index cc1019365ac..99a9035c0c2 100644 --- a/mysys/my_fopen.c +++ b/mysys/my_fopen.c @@ -69,19 +69,13 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags) DBUG_RETURN(fd); /* safeguard */ } mysql_mutex_lock(&THR_LOCK_open); - if ((my_file_info[filedesc].name= (char*) - my_strdup(filename,MyFlags))) - { - my_stream_opened++; - my_file_total_opened++; - my_file_info[filedesc].type= STREAM_BY_FOPEN; - mysql_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); - DBUG_RETURN(fd); - } + my_file_info[filedesc].name= (char*) my_strdup(filename,MyFlags); + my_stream_opened++; + my_file_total_opened++; + my_file_info[filedesc].type= STREAM_BY_FOPEN; mysql_mutex_unlock(&THR_LOCK_open); - (void) my_fclose(fd,MyFlags); - my_errno=ENOMEM; + DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); + DBUG_RETURN(fd); } else my_errno=errno; diff --git a/mysys/my_open.c b/mysys/my_open.c index 645d6709358..d19db0aaf0c 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -131,25 +131,16 @@ File my_register_filename(File fd, const char *FileName, enum file_type thread_safe_increment(my_file_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } - else - { - mysql_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags))) - { - my_file_opened++; - my_file_total_opened++; - my_file_info[fd].type = type_of_file; - mysql_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("fd: %d",fd)); - DBUG_RETURN(fd); - } - mysql_mutex_unlock(&THR_LOCK_open); - my_errno= ENOMEM; - } - (void) my_close(fd, MyFlags); + mysql_mutex_lock(&THR_LOCK_open); + my_file_info[fd].name = (char*) my_strdup(FileName, MyFlags); + my_file_opened++; + my_file_total_opened++; + my_file_info[fd].type = type_of_file; + mysql_mutex_unlock(&THR_LOCK_open); + DBUG_PRINT("exit",("fd: %d",fd)); + DBUG_RETURN(fd); } - else - my_errno= errno; + my_errno= errno; DBUG_PRINT("error",("Got error %d on open", my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) From c826ac9d539fa66d45afd0ca0d54b2579fcbb797 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 10:10:34 +0100 Subject: [PATCH 26/43] cleanup: mysys_test_invalid_symlink Remove maria_test_invalid_symlink() and myisam_test_invalid_symlink(), introduce mysys_test_invalid_symlink(). Other engines might need it too --- include/my_sys.h | 2 ++ mysys/my_symlink.c | 9 +++++++++ sql/mysqld.cc | 2 +- storage/maria/ha_maria.cc | 4 ---- storage/maria/ma_open.c | 4 ++-- storage/maria/ma_static.c | 6 ------ storage/myisam/mi_delete_table.c | 4 ++-- storage/myisam/mi_open.c | 4 ++-- storage/myisam/mi_static.c | 8 -------- 9 files changed, 18 insertions(+), 25 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 967228790ae..82ab830e9c7 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -548,6 +548,8 @@ extern ulong my_crc_dbug_check; typedef int (*Process_option_func)(void *ctx, const char *group_name, const char *option); +extern int (*mysys_test_invalid_symlink)(const char *filename); + #include diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c index b0e910f7ba0..bc01a68263d 100644 --- a/mysys/my_symlink.c +++ b/mysys/my_symlink.c @@ -1,5 +1,6 @@ /* Copyright (c) 2001, 2011, Oracle and/or its affiliates + Copyright (c) 2010, 2017, 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 @@ -23,6 +24,14 @@ #include #endif +static int always_valid(const char *filename __attribute__((unused))) +{ + return 0; +} + +int (*mysys_test_invalid_symlink)(const char *filename)= always_valid; + + /* Reads the content of a symbolic link If the file is not a symbolic link, return the original file name in to. diff --git a/sql/mysqld.cc b/sql/mysqld.cc index eb19e09d74e..2e8a62ecb12 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7267,7 +7267,7 @@ static int mysql_init_variables(void) mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0; #if defined(HAVE_REALPATH) && !defined(HAVE_valgrind) && !defined(HAVE_BROKEN_REALPATH) /* We can only test for sub paths if my_symlink.c is using realpath */ - myisam_test_invalid_symlink= test_if_data_home_dir; + mysys_test_invalid_symlink= test_if_data_home_dir; #endif opt_log= opt_slow_log= 0; opt_bin_log= opt_bin_log_used= 0; diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 38ee0758611..60e3f62096d 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -3572,10 +3572,6 @@ static int ha_maria_init(void *p) maria_pagecache->extra_debug= 1; maria_assert_if_crashed_table= debug_assert_if_crashed_table; -#if defined(HAVE_REALPATH) && !defined(HAVE_valgrind) && !defined(HAVE_BROKEN_REALPATH) - /* We can only test for sub paths if my_symlink.c is using realpath */ - maria_test_invalid_symlink= test_if_data_home_dir; -#endif if (res) maria_hton= 0; diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index f8f90812e51..83d37a17483 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -288,7 +288,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) MARIA_NAME_IEXT, MY_UNPACK_FILENAME),MYF(0)); if (my_is_symlink(org_name) && - (realpath_err || (*maria_test_invalid_symlink)(name_buff))) + (realpath_err || mysys_test_invalid_symlink(name_buff))) { my_errno= HA_WRONG_CREATE_OPTION; DBUG_RETURN(0); @@ -1880,7 +1880,7 @@ int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name, if (my_is_symlink(real_data_name)) { if (my_realpath(real_data_name, real_data_name, MYF(0)) || - (*maria_test_invalid_symlink)(real_data_name)) + mysys_test_invalid_symlink(real_data_name)) { my_errno= HA_WRONG_CREATE_OPTION; return 1; diff --git a/storage/maria/ma_static.c b/storage/maria/ma_static.c index a075459d389..3b6115e8a37 100644 --- a/storage/maria/ma_static.c +++ b/storage/maria/ma_static.c @@ -106,12 +106,6 @@ uint32 maria_readnext_vec[]= SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER }; -static int always_valid(const char *filename __attribute__((unused))) -{ - return 0; -} - -int (*maria_test_invalid_symlink)(const char *filename)= always_valid; my_bool (*ma_killed)(MARIA_HA *)= ma_killed_standalone; #ifdef HAVE_PSI_INTERFACE diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index 885990ee1be..7643c093e86 100644 --- a/storage/myisam/mi_delete_table.c +++ b/storage/myisam/mi_delete_table.c @@ -30,7 +30,7 @@ int mi_delete_table(const char *name) #endif fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) + if (my_is_symlink(from) && mysys_test_invalid_symlink(from)) { /* Symlink is pointing to file in data directory. @@ -45,7 +45,7 @@ int mi_delete_table(const char *name) DBUG_RETURN(my_errno); } fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) + if (my_is_symlink(from) && mysys_test_invalid_symlink(from)) { /* Symlink is pointing to file in data directory. diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index 94bc92088ad..7efed26a52b 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -93,7 +93,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) realpath_err= my_realpath(name_buff, fn_format(org_name,name,"",MI_NAME_IEXT,4),MYF(0)); if (my_is_symlink(org_name) && - (realpath_err || (*myisam_test_invalid_symlink)(name_buff))) + (realpath_err || mysys_test_invalid_symlink(name_buff))) { my_errno= HA_WRONG_CREATE_OPTION; DBUG_RETURN (NULL); @@ -1246,7 +1246,7 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, if (my_is_symlink(real_data_name)) { if (my_realpath(real_data_name, real_data_name, MYF(0)) || - (*myisam_test_invalid_symlink)(real_data_name)) + mysys_test_invalid_symlink(real_data_name)) { my_errno= HA_WRONG_CREATE_OPTION; return 1; diff --git a/storage/myisam/mi_static.c b/storage/myisam/mi_static.c index 30e463746d5..a8bff936ad1 100644 --- a/storage/myisam/mi_static.c +++ b/storage/myisam/mi_static.c @@ -42,14 +42,6 @@ ulong myisam_data_pointer_size=4; ulonglong myisam_mmap_size= SIZE_T_MAX, myisam_mmap_used= 0; my_bool (*mi_killed)(MI_INFO *)= mi_killed_standalone; -static int always_valid(const char *filename __attribute__((unused))) -{ - return 0; -} - -int (*myisam_test_invalid_symlink)(const char *filename)= always_valid; - - /* read_vec[] is used for converting between P_READ_KEY.. and SEARCH_ Position is , == , >= , <= , > , < From 8722d4b8d219f687509b95d952fb46dff684ba00 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 10:20:15 +0100 Subject: [PATCH 27/43] cleanup: remove 16-year-old "TODO" --- storage/maria/ma_check.c | 6 +++--- storage/maria/ma_open.c | 10 +++------- storage/maria/maria_chk.c | 2 +- storage/maria/maria_def.h | 3 +-- storage/myisam/mi_check.c | 6 +++--- storage/myisam/mi_open.c | 10 +++------- storage/myisam/myisamchk.c | 2 +- storage/myisam/myisamdef.h | 3 +-- 8 files changed, 16 insertions(+), 26 deletions(-) diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index ecdc512ef69..571cb532a1c 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -2839,7 +2839,7 @@ int maria_repair(HA_CHECK *param, register MARIA_HA *info, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) | sync_dir) || - _ma_open_datafile(info, share, NullS, -1)) + _ma_open_datafile(info, share, NullS)) { goto err; } @@ -3990,7 +3990,7 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) | sync_dir) || - _ma_open_datafile(info, share, NullS, -1)) + _ma_open_datafile(info, share, NullS)) { _ma_check_print_error(param, "Couldn't change to new data file"); goto err; @@ -4622,7 +4622,7 @@ err: MYF((param->testflag & T_BACKUP_DATA ? MY_REDEL_MAKE_BACKUP : 0) | sync_dir)) || - _ma_open_datafile(info,share, NullS, -1)) + _ma_open_datafile(info,share, NullS)) got_error=1; } } diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 83d37a17483..bc1e5ac9a8b 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -104,7 +104,7 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, const char *name, } if (data_file >= 0) info.dfile.file= data_file; - else if (_ma_open_datafile(&info, share, name, -1)) + else if (_ma_open_datafile(&info, share, name)) goto err; errpos= 5; @@ -820,7 +820,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) if ((share->data_file_type == BLOCK_RECORD || share->data_file_type == COMPRESSED_RECORD)) { - if (_ma_open_datafile(&info, share, name, -1)) + if (_ma_open_datafile(&info, share, name)) goto err; data_file= info.dfile.file; } @@ -1863,13 +1863,9 @@ void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file, Open data file We can't use dup() here as the data file descriptors need to have different active seek-positions. - - The argument file_to_dup is here for the future if there would on some OS - exist a dup()-like call that would give us two different file descriptors. *************************************************************************/ -int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name, - File file_to_dup __attribute__((unused))) +int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name) { char *data_name= share->data_file_name.str; char real_data_name[FN_REFLEN]; diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index cfc8a604118..61d0b1f66c0 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -1242,7 +1242,7 @@ static int maria_chk(HA_CHECK *param, char *filename) mysql_file_close(info->dfile.file, MYF(MY_WME)); /* Close new file */ error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT, 0, MYF(0)); - if (_ma_open_datafile(info,info->s, NullS, -1)) + if (_ma_open_datafile(info,info->s, NullS)) error=1; param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ param->read_cache.file= info->dfile.file; diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 473cddee190..11cf8c8612e 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -1302,8 +1302,7 @@ int _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos); extern MARIA_HA *_ma_test_if_reopen(const char *filename); my_bool _ma_check_table_is_closed(const char *name, const char *where); -int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name, - File file_to_dup); +int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name); int _ma_open_keyfile(MARIA_SHARE *share); void _ma_setup_functions(register MARIA_SHARE *share); my_bool _ma_dynmap_file(MARIA_HA *info, my_off_t size); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index ff9ea4b82cb..42e67147db2 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -2538,7 +2538,7 @@ err: (void) mysql_file_delete(mi_key_file_datatmp, param->temp_filename, MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ - if (unlikely(mi_open_datafile(info, share, name, -1))) + if (unlikely(mi_open_datafile(info, share, name))) param->retry_repair= 0; /* Safety */ } mi_mark_crashed_on_repair(info); @@ -3072,7 +3072,7 @@ err: (void) mysql_file_delete(mi_key_file_datatmp, param->temp_filename, MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ - if (unlikely(mi_open_datafile(info, share, name, -1))) + if (unlikely(mi_open_datafile(info, share, name))) param->retry_repair= 0; /* Safety */ } mi_mark_crashed_on_repair(info); @@ -4785,7 +4785,7 @@ static int replace_data_file(HA_CHECK *param, MI_INFO *info, DATA_TMP_EXT, param->backup_time, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) || - mi_open_datafile(info, share, name, -1)) + mi_open_datafile(info, share, name)) return 1; return 0; } diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index 7efed26a52b..eaee7b8f200 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -480,7 +480,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) lock_error=1; /* Database unlocked */ } - if (mi_open_datafile(&info, share, name, -1)) + if (mi_open_datafile(&info, share, name)) goto err; errpos=5; @@ -561,7 +561,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno=EACCES; /* Can't open in write mode */ goto err; } - if (mi_open_datafile(&info, share, name, old_info->dfile)) + if (mi_open_datafile(&info, share, name)) goto err; errpos=5; have_rtree= old_info->rtree_recursion_state != NULL; @@ -1229,13 +1229,9 @@ uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo) Open data file. We can't use dup() here as the data file descriptors need to have different active seek-positions. - -The argument file_to_dup is here for the future if there would on some OS -exist a dup()-like call that would give us two different file descriptors. *************************************************************************/ -int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, - File file_to_dup __attribute__((unused))) +int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name) { char *data_name= share->data_file_name; char real_data_name[FN_REFLEN]; diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index 917893f58a9..cfd58418c87 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -1012,7 +1012,7 @@ static int myisamchk(HA_CHECK *param, char * filename) MYF(MY_WME)); /* Close new file */ error|=change_to_newfile(filename, MI_NAME_DEXT, DATA_TMP_EXT, 0, MYF(0)); - if (mi_open_datafile(info,info->s, NULL, -1)) + if (mi_open_datafile(info,info->s, NULL)) error=1; param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ param->read_cache.file=info->dfile; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index 221d6e36aea..751aa9b6235 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -708,8 +708,7 @@ void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows); extern MI_INFO *test_if_reopen(char *filename); my_bool check_table_is_closed(const char *name, const char *where); -int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *orn_name, - File file_to_dup); +int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *orn_name); int mi_open_keyfile(MYISAM_SHARE *share); void mi_setup_functions(register MYISAM_SHARE *share); From d78d0d459d10dd12069de82d6735f1acf183c631 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 10:38:14 +0100 Subject: [PATCH 28/43] cleanup: NO_OPEN_3 was never defined --- mysys/my_open.c | 4 +--- plugin/server_audit/server_audit.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/mysys/my_open.c b/mysys/my_open.c index d19db0aaf0c..24d5c881372 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -45,10 +45,8 @@ File my_open(const char *FileName, int Flags, myf MyFlags) MyFlags|= my_global_flags; #if defined(_WIN32) fd= my_win_open(FileName, Flags); -#elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, my_umask); /* Normal unix */ #else - fd = open((char *) FileName, Flags); + fd = open(FileName, Flags, my_umask); #endif fd= my_register_filename(fd, FileName, FILE_BY_OPEN, diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index eae7ad12f1c..10dcb1852e8 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -158,10 +158,8 @@ static File loc_open(const char *FileName, int Flags) File fd; #if defined(_WIN32) fd= my_win_open(FileName, Flags); -#elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, my_umask); /* Normal unix */ #else - fd = open((char *) FileName, Flags); + fd = open(FileName, Flags, my_umask); #endif my_errno= errno; return fd; From b27fd90ad36f4194665744cc1dcdd05f2d0b47ef Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 15 Feb 2017 18:45:19 +0100 Subject: [PATCH 29/43] MDEV-11902 mi_open race condition TOCTOU bug. The path is checked to be valid, symlinks are resolved. Then the resolved path is opened. Between the check and the open, there's a window when one can replace some path component with a symlink, bypassing validity checks. Fix: after we resolved all symlinks in the path, don't allow open() to resolve symlinks, there should be none. Compared to the old MyISAM/Aria code: * fastpath. Opening of not-symlinked files is just one open(), no fn_format() and lstat() anymore. * opening of symlinked tables doesn't do fn_format() and lstat() either. it also doesn't to realpath() (which was lstat-ing every path component), instead if opens every path component with O_PATH. * share->data_file_name stores realpath(path) not readlink(path). So, SHOW CREATE TABLE needs to do lstat/readlink() now (see ::info()), and certain error messages (cannot open file "XXX") show the real file path with all symlinks resolved. --- include/my_sys.h | 6 +- mysql-test/r/symlink-aria-11902.result | 39 ++++++++ mysql-test/r/symlink-myisam-11902.result | 38 ++++++++ .../federated/federated_bug_35333.result | 3 - .../suite/federated/federated_bug_35333.test | 2 +- mysql-test/t/repair_symlink-5543.test | 4 +- mysql-test/t/symlink-aria-11902.test | 6 ++ mysql-test/t/symlink-myisam-11902.test | 60 +++++++++++++ mysys/my_open.c | 90 ++++++++++++++++++- sql/handler.cc | 1 + storage/maria/ma_open.c | 48 +++++----- storage/myisam/ha_myisam.cc | 15 +++- storage/myisam/mi_open.c | 54 ++++++----- 13 files changed, 298 insertions(+), 68 deletions(-) create mode 100644 mysql-test/r/symlink-aria-11902.result create mode 100644 mysql-test/r/symlink-myisam-11902.result create mode 100644 mysql-test/t/symlink-aria-11902.test create mode 100644 mysql-test/t/symlink-myisam-11902.test diff --git a/include/my_sys.h b/include/my_sys.h index 82ab830e9c7..bb19a30497a 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -63,9 +63,9 @@ typedef struct my_aio_result { #define MY_FAE 8 /* Fatal if any error */ #define MY_WME 16 /* Write message on error */ #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */ -#define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */ -#define MY_UNUSED 64 /* Unused (was support for RAID) */ -#define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */ +#define MY_IGNORE_BADFD 32 /* my_sync(): ignore 'bad descriptor' errors */ +#define MY_NOSYMLINKS 512 /* my_open(): don't follow symlinks */ +#define MY_FULL_IO 512 /* my_read(): loop intil I/O is complete */ #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */ #define MY_COPYTIME 64 /* my_redel() copys time */ diff --git a/mysql-test/r/symlink-aria-11902.result b/mysql-test/r/symlink-aria-11902.result new file mode 100644 index 00000000000..f704bb86ea7 --- /dev/null +++ b/mysql-test/r/symlink-aria-11902.result @@ -0,0 +1,39 @@ +set default_storage_engine=Aria; +call mtr.add_suppression("File.*t1.* not found"); +create table mysql.t1 (a int, b char(16), index(a)); +insert mysql.t1 values (100, 'test'),(101,'test'); +create table t1 (a int, b char(16), index(a)) +data directory="MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +select * from t1; +a b +200 some +201 some +flush tables; +set debug_sync='mi_open_datafile SIGNAL ok WAIT_FOR go'; +select * from t1; +set debug_sync='now WAIT_FOR ok'; +set debug_sync='now SIGNAL go'; +ERROR HY000: File 'MYSQLTEST_VARDIR/tmp/foo/t1.MAD' not found (Errcode: 20) +flush tables; +drop table if exists t1; +create table t1 (a int, b char(16), index (a)) +index directory="MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +explain select a from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL a 5 NULL 2 Using index +select a from t1; +a +200 +201 +flush tables; +set debug_sync='mi_open_kfile SIGNAL waiting WAIT_FOR run'; +select a from t1; +set debug_sync='now WAIT_FOR waiting'; +set debug_sync='now SIGNAL run'; +ERROR HY000: Can't find file: 't1' (errno: 20) +flush tables; +drop table if exists t1; +drop table mysql.t1; +set debug_sync='RESET'; diff --git a/mysql-test/r/symlink-myisam-11902.result b/mysql-test/r/symlink-myisam-11902.result new file mode 100644 index 00000000000..74785bbcdd1 --- /dev/null +++ b/mysql-test/r/symlink-myisam-11902.result @@ -0,0 +1,38 @@ +call mtr.add_suppression("File.*t1.* not found"); +create table mysql.t1 (a int, b char(16), index(a)); +insert mysql.t1 values (100, 'test'),(101,'test'); +create table t1 (a int, b char(16), index(a)) +data directory="MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +select * from t1; +a b +200 some +201 some +flush tables; +set debug_sync='mi_open_datafile SIGNAL ok WAIT_FOR go'; +select * from t1; +set debug_sync='now WAIT_FOR ok'; +set debug_sync='now SIGNAL go'; +ERROR HY000: File 'MYSQLTEST_VARDIR/tmp/foo/t1.MYD' not found (Errcode: 20) +flush tables; +drop table if exists t1; +create table t1 (a int, b char(16), index (a)) +index directory="MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +explain select a from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL a 5 NULL 2 Using index +select a from t1; +a +200 +201 +flush tables; +set debug_sync='mi_open_kfile SIGNAL waiting WAIT_FOR run'; +select a from t1; +set debug_sync='now WAIT_FOR waiting'; +set debug_sync='now SIGNAL run'; +ERROR HY000: Can't find file: 't1' (errno: 20) +flush tables; +drop table if exists t1; +drop table mysql.t1; +set debug_sync='RESET'; diff --git a/mysql-test/suite/federated/federated_bug_35333.result b/mysql-test/suite/federated/federated_bug_35333.result index e1319cfeeae..c19fb78b7ae 100644 --- a/mysql-test/suite/federated/federated_bug_35333.result +++ b/mysql-test/suite/federated/federated_bug_35333.result @@ -27,9 +27,6 @@ TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE ROW_FORMAT TABLE_ROWS DATA_LENGTH TABL test t1 BASE TABLE NULL NULL NULL NULL Can't find file: 't1' (errno: 2) Warnings: Warning 1017 Can't find file: 't1' (errno: 2) -SHOW WARNINGS; -Level Code Message -Warning 1017 Can't find file: 't1' (errno: 2) DROP TABLE t1; ERROR 42S02: Unknown table 't1' # diff --git a/mysql-test/suite/federated/federated_bug_35333.test b/mysql-test/suite/federated/federated_bug_35333.test index 6487e10e018..5134dbc6252 100644 --- a/mysql-test/suite/federated/federated_bug_35333.test +++ b/mysql-test/suite/federated/federated_bug_35333.test @@ -61,10 +61,10 @@ let $MYSQLD_DATADIR= `SELECT @@datadir`; --echo # --echo # Trigger a MyISAM system error during an INFORMATION_SCHEMA.TABLES query --echo # +--replace_result 20 2 SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; -SHOW WARNINGS; --disable_warnings --error 1051 DROP TABLE t1; diff --git a/mysql-test/t/repair_symlink-5543.test b/mysql-test/t/repair_symlink-5543.test index bad65a4175a..6bdf72b4d40 100644 --- a/mysql-test/t/repair_symlink-5543.test +++ b/mysql-test/t/repair_symlink-5543.test @@ -9,7 +9,7 @@ eval create table t1 (a int) engine=myisam data directory='$MYSQL_TMP_DIR'; insert t1 values (1); --system ln -s $MYSQL_TMP_DIR/foobar5543 $MYSQL_TMP_DIR/t1.TMD ---replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +--replace_regex / '.*\/t1/ 'MYSQL_TMP_DIR\/t1/ repair table t1; drop table t1; @@ -17,7 +17,7 @@ drop table t1; eval create table t2 (a int) engine=aria data directory='$MYSQL_TMP_DIR'; insert t2 values (1); --system ln -s $MYSQL_TMP_DIR/foobar5543 $MYSQL_TMP_DIR/t2.TMD ---replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +--replace_regex / '.*\/t2/ 'MYSQL_TMP_DIR\/t2/ repair table t2; drop table t2; diff --git a/mysql-test/t/symlink-aria-11902.test b/mysql-test/t/symlink-aria-11902.test new file mode 100644 index 00000000000..a2a266cbb25 --- /dev/null +++ b/mysql-test/t/symlink-aria-11902.test @@ -0,0 +1,6 @@ +# +# MDEV-11902 mi_open race condition +# +source include/have_maria.inc; +set default_storage_engine=Aria; +source symlink-myisam-11902.test; diff --git a/mysql-test/t/symlink-myisam-11902.test b/mysql-test/t/symlink-myisam-11902.test new file mode 100644 index 00000000000..7e35ad117d0 --- /dev/null +++ b/mysql-test/t/symlink-myisam-11902.test @@ -0,0 +1,60 @@ +# +# MDEV-11902 mi_open race condition +# +source include/have_debug_sync.inc; +source include/have_symlink.inc; +source include/not_windows.inc; +call mtr.add_suppression("File.*t1.* not found"); + +create table mysql.t1 (a int, b char(16), index(a)); +insert mysql.t1 values (100, 'test'),(101,'test'); +let $datadir=`select @@datadir`; + +exec mkdir $MYSQLTEST_VARDIR/tmp/foo; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval create table t1 (a int, b char(16), index(a)) + data directory="$MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +select * from t1; +flush tables; +set debug_sync='mi_open_datafile SIGNAL ok WAIT_FOR go'; +send select * from t1; +connect con1, localhost, root; +set debug_sync='now WAIT_FOR ok'; +exec rm -r $MYSQLTEST_VARDIR/tmp/foo; +exec ln -s $datadir/mysql $MYSQLTEST_VARDIR/tmp/foo; +set debug_sync='now SIGNAL go'; +connection default; +replace_regex / '.*\/tmp\// 'MYSQLTEST_VARDIR\/tmp\// /31/20/; +error 29; +reap; +flush tables; +drop table if exists t1; +exec rm -r $MYSQLTEST_VARDIR/tmp/foo; + +# same with INDEX DIRECTORY +exec mkdir $MYSQLTEST_VARDIR/tmp/foo; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval create table t1 (a int, b char(16), index (a)) + index directory="$MYSQLTEST_VARDIR/tmp/foo"; +insert t1 values (200, 'some'),(201,'some'); +explain select a from t1; +select a from t1; +flush tables; +set debug_sync='mi_open_kfile SIGNAL waiting WAIT_FOR run'; +send select a from t1; +connection con1; +set debug_sync='now WAIT_FOR waiting'; +exec rm -r $MYSQLTEST_VARDIR/tmp/foo; +exec ln -s $datadir/mysql $MYSQLTEST_VARDIR/tmp/foo; +set debug_sync='now SIGNAL run'; +connection default; +replace_regex / '.*\/tmp\// 'MYSQLTEST_VARDIR\/tmp\// /31/20/; +error ER_FILE_NOT_FOUND; +reap; +flush tables; +drop table if exists t1; +exec rm -r $MYSQLTEST_VARDIR/tmp/foo; + +drop table mysql.t1; +set debug_sync='RESET'; diff --git a/mysys/my_open.c b/mysys/my_open.c index 24d5c881372..0effc4bedda 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -15,9 +15,14 @@ #include "mysys_priv.h" #include "mysys_err.h" -#include +#include #include +#if !defined(O_PATH) && defined(O_EXEC) /* FreeBSD */ +#define O_PATH O_EXEC +#endif + +static int open_nosymlinks(const char *pathname, int flags, int mode); /* Open a file @@ -46,7 +51,10 @@ File my_open(const char *FileName, int Flags, myf MyFlags) #if defined(_WIN32) fd= my_win_open(FileName, Flags); #else - fd = open(FileName, Flags, my_umask); + if (MyFlags & MY_NOSYMLINKS) + fd = open_nosymlinks(FileName, Flags, my_umask); + else + fd = open(FileName, Flags, my_umask); #endif fd= my_register_filename(fd, FileName, FILE_BY_OPEN, @@ -174,3 +182,81 @@ void my_print_open_files(void) } #endif + +/** + like open(), but with symlinks are not accepted anywhere in the path + + This is used for opening symlinked tables for DATA/INDEX DIRECTORY. + The paths there have been realpath()-ed. So, we can assume here that + + * `pathname` is an absolute path + * no '.', '..', and '//' in the path + * file exists +*/ +static int open_nosymlinks(const char *pathname, int flags, int mode) +{ +#ifndef O_PATH +#ifdef HAVE_REALPATH + char buf[PATH_MAX+1]; + if (realpath(pathname, buf) == NULL) + return -1; + if (strcmp(pathname, buf)) + { + errno= ENOTDIR; + return -1; + } +#endif + return open(pathname, flags, mode | O_NOFOLLOW); +#else + + char buf[PATH_MAX+1]; + char *s= buf, *e= buf+1, *end= strnmov(buf, pathname, sizeof(buf)); + int fd, dfd= -1; + + if (*end) + { + errno= ENAMETOOLONG; + return -1; + } + + if (*s != '/') /* not an absolute path */ + { + errno= ENOENT; + return -1; + } + + for (;;) + { + if (*e == '/') /* '//' in the path */ + { + errno= ENOENT; + goto err; + } + while (*e && *e != '/') + e++; + *e= 0; + if (!memcmp(s, ".", 2) || !memcmp(s, "..", 3)) + { + errno= ENOENT; + goto err; + } + + fd = openat(dfd, s, O_NOFOLLOW | (e < end ? O_PATH : flags), mode); + if (fd < 0) + goto err; + + if (dfd >= 0) + close(dfd); + + dfd= fd; + s= ++e; + + if (e >= end) + return fd; + } +err: + if (dfd >= 0) + close(dfd); + return -1; +#endif +} diff --git a/sql/handler.cc b/sql/handler.cc index bc71aa57fb7..cef3f098161 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2908,6 +2908,7 @@ void handler::print_error(int error, myf errflag) textno=ER_FILE_USED; break; case ENOENT: + case ENOTDIR: textno=ER_FILE_NOT_FOUND; break; case ENOSPC: diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index bc1e5ac9a8b..f1dd1abc195 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -312,13 +312,16 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) my_errno= HA_ERR_CRASHED; goto err; }); + DEBUG_SYNC_C("mi_open_kfile"); if ((kfile=mysql_file_open(key_file_kfile, name_buff, - (open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0) + (open_mode=O_RDWR) | O_SHARE | O_NOFOLLOW, + MYF(MY_NOSYMLINKS))) < 0) { if ((errno != EROFS && errno != EACCES) || mode != O_RDONLY || (kfile=mysql_file_open(key_file_kfile, name_buff, - (open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0) + (open_mode=O_RDONLY) | O_SHARE | O_NOFOLLOW, + MYF(MY_NOSYMLINKS))) < 0) goto err; } share->mode=open_mode; @@ -363,7 +366,18 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) (void) strmov(index_name, org_name); *strrchr(org_name, FN_EXTCHAR)= '\0'; (void) fn_format(data_name,org_name,"",MARIA_NAME_DEXT, - MY_APPEND_EXT|MY_UNPACK_FILENAME|MY_RESOLVE_SYMLINKS); + MY_APPEND_EXT|MY_UNPACK_FILENAME); + if (my_is_symlink(data_name)) + { + if (my_realpath(data_name, data_name, MYF(0))) + goto err; + if (mysys_test_invalid_symlink(data_name)) + { + my_errno= HA_WRONG_CREATE_OPTION; + goto err; + } + share->mode|= O_NOFOLLOW; /* all symlinks are resolved by realpath() */ + } info_length=mi_uint2korr(share->state.header.header_length); base_pos= mi_uint2korr(share->state.header.base_pos); @@ -1867,27 +1881,11 @@ void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file, int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name) { - char *data_name= share->data_file_name.str; - char real_data_name[FN_REFLEN]; - - if (org_name) - { - fn_format(real_data_name, org_name, "", MARIA_NAME_DEXT, 4); - if (my_is_symlink(real_data_name)) - { - if (my_realpath(real_data_name, real_data_name, MYF(0)) || - mysys_test_invalid_symlink(real_data_name)) - { - my_errno= HA_WRONG_CREATE_OPTION; - return 1; - } - data_name= real_data_name; - } - } - + myf flags= MY_WME | (share->mode & O_NOFOLLOW ? MY_NOSYMLINKS : 0); + DEBUG_SYNC_C("mi_open_datafile"); info->dfile.file= share->bitmap.file.file= - mysql_file_open(key_file_dfile, data_name, - share->mode | O_SHARE, MYF(MY_WME)); + mysql_file_open(key_file_dfile, share->data_file_name.str, + share->mode | O_SHARE, MYF(flags)); return info->dfile.file >= 0 ? 0 : 1; } @@ -1901,8 +1899,8 @@ int _ma_open_keyfile(MARIA_SHARE *share) mysql_mutex_lock(&share->intern_lock); share->kfile.file= mysql_file_open(key_file_kfile, share->unique_file_name.str, - share->mode | O_SHARE, - MYF(MY_WME)); + share->mode | O_SHARE | O_NOFOLLOW, + MYF(MY_WME | MY_NOSYMLINKS)); mysql_mutex_unlock(&share->intern_lock); return (share->kfile.file < 0); } diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 784da17d790..ddbd14010b9 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1874,15 +1874,22 @@ int ha_myisam::info(uint flag) Set data_file_name and index_file_name to point at the symlink value if table is symlinked (Ie; Real name is not same as generated name) */ + char buf[FN_REFLEN]; data_file_name= index_file_name= 0; fn_format(name_buff, file->filename, "", MI_NAME_DEXT, MY_APPEND_EXT | MY_UNPACK_FILENAME); - if (strcmp(name_buff, misam_info.data_file_name)) - data_file_name=misam_info.data_file_name; + if (my_is_symlink(name_buff)) + { + my_readlink(buf, name_buff, MYF(0)); + data_file_name= ha_thd()->strdup(buf); + } fn_format(name_buff, file->filename, "", MI_NAME_IEXT, MY_APPEND_EXT | MY_UNPACK_FILENAME); - if (strcmp(name_buff, misam_info.index_file_name)) - index_file_name=misam_info.index_file_name; + if (my_is_symlink(name_buff)) + { + my_readlink(buf, name_buff, MYF(0)); + index_file_name= ha_thd()->strdup(buf); + } } if (flag & HA_STATUS_ERRKEY) { diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index eaee7b8f200..af769afb81a 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -114,15 +114,17 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno= HA_ERR_CRASHED; goto err; }); - if ((kfile= mysql_file_open(mi_key_file_kfile, - name_buff, - (open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0) + + DEBUG_SYNC_C("mi_open_kfile"); + if ((kfile= mysql_file_open(mi_key_file_kfile, name_buff, + (open_mode= O_RDWR) | O_SHARE | O_NOFOLLOW, + MYF(MY_NOSYMLINKS))) < 0) { if ((errno != EROFS && errno != EACCES) || mode != O_RDONLY || - (kfile= mysql_file_open(mi_key_file_kfile, - name_buff, - (open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0) + (kfile= mysql_file_open(mi_key_file_kfile, name_buff, + (open_mode= O_RDONLY) | O_SHARE| O_NOFOLLOW, + MYF(MY_NOSYMLINKS))) < 0) goto err; } share->mode=open_mode; @@ -166,7 +168,18 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) (void) strmov(index_name, org_name); *strrchr(org_name, '.')= '\0'; (void) fn_format(data_name,org_name,"",MI_NAME_DEXT, - MY_APPEND_EXT|MY_UNPACK_FILENAME|MY_RESOLVE_SYMLINKS); + MY_APPEND_EXT|MY_UNPACK_FILENAME); + if (my_is_symlink(data_name)) + { + if (my_realpath(data_name, data_name, MYF(0))) + goto err; + if (mysys_test_invalid_symlink(data_name)) + { + my_errno= HA_WRONG_CREATE_OPTION; + goto err; + } + share->mode|= O_NOFOLLOW; /* all symlinks are resolved by realpath() */ + } info_length=mi_uint2korr(share->state.header.header_length); base_pos=mi_uint2korr(share->state.header.base_pos); @@ -1233,25 +1246,10 @@ active seek-positions. int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name) { - char *data_name= share->data_file_name; - char real_data_name[FN_REFLEN]; - - if (org_name) - { - fn_format(real_data_name,org_name,"",MI_NAME_DEXT,4); - if (my_is_symlink(real_data_name)) - { - if (my_realpath(real_data_name, real_data_name, MYF(0)) || - mysys_test_invalid_symlink(real_data_name)) - { - my_errno= HA_WRONG_CREATE_OPTION; - return 1; - } - data_name= real_data_name; - } - } - info->dfile= mysql_file_open(mi_key_file_dfile, - data_name, share->mode | O_SHARE, MYF(MY_WME)); + myf flags= MY_WME | (share->mode & O_NOFOLLOW ? MY_NOSYMLINKS: 0); + DEBUG_SYNC_C("mi_open_datafile"); + info->dfile= mysql_file_open(mi_key_file_dfile, share->data_file_name, + share->mode | O_SHARE, MYF(flags)); return info->dfile >= 0 ? 0 : 1; } @@ -1260,8 +1258,8 @@ int mi_open_keyfile(MYISAM_SHARE *share) { if ((share->kfile= mysql_file_open(mi_key_file_kfile, share->unique_file_name, - share->mode | O_SHARE, - MYF(MY_WME))) < 0) + share->mode | O_SHARE | O_NOFOLLOW, + MYF(MY_NOSYMLINKS | MY_WME))) < 0) return 1; return 0; } From b6862c914f8b18bce41deea606770e9864aa0de5 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 18 Feb 2017 15:18:35 +0100 Subject: [PATCH 30/43] cleanup: remove now-unused argument --- storage/maria/ma_check.c | 6 +++--- storage/maria/ma_open.c | 12 ++++++------ storage/maria/maria_chk.c | 2 +- storage/maria/maria_def.h | 2 +- storage/myisam/mi_check.c | 18 ++++++++---------- storage/myisam/mi_open.c | 6 +++--- storage/myisam/myisamchk.c | 2 +- storage/myisam/myisamdef.h | 2 +- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 571cb532a1c..fb35edc3be3 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -2839,7 +2839,7 @@ int maria_repair(HA_CHECK *param, register MARIA_HA *info, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) | sync_dir) || - _ma_open_datafile(info, share, NullS)) + _ma_open_datafile(info, share)) { goto err; } @@ -3990,7 +3990,7 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) | sync_dir) || - _ma_open_datafile(info, share, NullS)) + _ma_open_datafile(info, share)) { _ma_check_print_error(param, "Couldn't change to new data file"); goto err; @@ -4622,7 +4622,7 @@ err: MYF((param->testflag & T_BACKUP_DATA ? MY_REDEL_MAKE_BACKUP : 0) | sync_dir)) || - _ma_open_datafile(info,share, NullS)) + _ma_open_datafile(info,share)) got_error=1; } } diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index f1dd1abc195..a382c30e025 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -85,7 +85,7 @@ MARIA_HA *_ma_test_if_reopen(const char *filename) */ -static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, const char *name, +static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, int mode, File data_file) { int save_errno; @@ -104,7 +104,7 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, const char *name, } if (data_file >= 0) info.dfile.file= data_file; - else if (_ma_open_datafile(&info, share, name)) + else if (_ma_open_datafile(&info, share)) goto err; errpos= 5; @@ -242,7 +242,7 @@ MARIA_HA *maria_clone(MARIA_SHARE *share, int mode) { MARIA_HA *new_info; mysql_mutex_lock(&THR_LOCK_maria); - new_info= maria_clone_internal(share, NullS, mode, + new_info= maria_clone_internal(share, mode, share->data_file_type == BLOCK_RECORD ? share->bitmap.file.file : -1); mysql_mutex_unlock(&THR_LOCK_maria); @@ -834,7 +834,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) if ((share->data_file_type == BLOCK_RECORD || share->data_file_type == COMPRESSED_RECORD)) { - if (_ma_open_datafile(&info, share, name)) + if (_ma_open_datafile(&info, share)) goto err; data_file= info.dfile.file; } @@ -1006,7 +1006,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) data_file= share->bitmap.file.file; /* Only opened once */ } - if (!(m_info= maria_clone_internal(share, name, mode, data_file))) + if (!(m_info= maria_clone_internal(share, mode, data_file))) goto err; if (maria_is_crashed(m_info)) @@ -1879,7 +1879,7 @@ void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file, active seek-positions. *************************************************************************/ -int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name) +int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share) { myf flags= MY_WME | (share->mode & O_NOFOLLOW ? MY_NOSYMLINKS : 0); DEBUG_SYNC_C("mi_open_datafile"); diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index 61d0b1f66c0..df3077c81c7 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -1242,7 +1242,7 @@ static int maria_chk(HA_CHECK *param, char *filename) mysql_file_close(info->dfile.file, MYF(MY_WME)); /* Close new file */ error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT, 0, MYF(0)); - if (_ma_open_datafile(info,info->s, NullS)) + if (_ma_open_datafile(info, info->s)) error=1; param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ param->read_cache.file= info->dfile.file; diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 11cf8c8612e..fa168305cae 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -1302,7 +1302,7 @@ int _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos); extern MARIA_HA *_ma_test_if_reopen(const char *filename); my_bool _ma_check_table_is_closed(const char *name, const char *where); -int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name); +int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share); int _ma_open_keyfile(MARIA_SHARE *share); void _ma_setup_functions(register MARIA_SHARE *share); my_bool _ma_dynmap_file(MARIA_HA *info, my_off_t size); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 42e67147db2..df97d6035d8 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -80,8 +80,7 @@ static SORT_KEY_BLOCKS *alloc_key_blocks(HA_CHECK *param, uint blocks, uint buffer_length); static ha_checksum mi_byte_checksum(const uchar *buf, uint length); static void set_data_file_type(MI_SORT_INFO *sort_info, MYISAM_SHARE *share); -static int replace_data_file(HA_CHECK *param, MI_INFO *info, - const char *name, File new_file); +static int replace_data_file(HA_CHECK *param, MI_INFO *info, File new_file); void myisamchk_init(HA_CHECK *param) { @@ -1715,7 +1714,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - got_error= replace_data_file(param, info, name, new_file); + got_error= replace_data_file(param, info, new_file); new_file= -1; param->retry_repair= 0; } @@ -2524,7 +2523,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - got_error= replace_data_file(param, info, name, new_file); + got_error= replace_data_file(param, info, new_file); new_file= -1; } } @@ -2538,7 +2537,7 @@ err: (void) mysql_file_delete(mi_key_file_datatmp, param->temp_filename, MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ - if (unlikely(mi_open_datafile(info, share, name))) + if (unlikely(mi_open_datafile(info, share))) param->retry_repair= 0; /* Safety */ } mi_mark_crashed_on_repair(info); @@ -3058,7 +3057,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - got_error= replace_data_file(param, info, name, new_file); + got_error= replace_data_file(param, info, new_file); new_file= -1; } } @@ -3072,7 +3071,7 @@ err: (void) mysql_file_delete(mi_key_file_datatmp, param->temp_filename, MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ - if (unlikely(mi_open_datafile(info, share, name))) + if (unlikely(mi_open_datafile(info, share))) param->retry_repair= 0; /* Safety */ } mi_mark_crashed_on_repair(info); @@ -4749,8 +4748,7 @@ int mi_make_backup_of_index(MI_INFO *info, time_t backup_time, myf flags) } -static int replace_data_file(HA_CHECK *param, MI_INFO *info, - const char *name, File new_file) +static int replace_data_file(HA_CHECK *param, MI_INFO *info, File new_file) { MYISAM_SHARE *share=info->s; @@ -4785,7 +4783,7 @@ static int replace_data_file(HA_CHECK *param, MI_INFO *info, DATA_TMP_EXT, param->backup_time, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) || - mi_open_datafile(info, share, name)) + mi_open_datafile(info, share)) return 1; return 0; } diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index af769afb81a..86b70129203 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -493,7 +493,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) lock_error=1; /* Database unlocked */ } - if (mi_open_datafile(&info, share, name)) + if (mi_open_datafile(&info, share)) goto err; errpos=5; @@ -574,7 +574,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno=EACCES; /* Can't open in write mode */ goto err; } - if (mi_open_datafile(&info, share, name)) + if (mi_open_datafile(&info, share)) goto err; errpos=5; have_rtree= old_info->rtree_recursion_state != NULL; @@ -1244,7 +1244,7 @@ We can't use dup() here as the data file descriptors need to have different active seek-positions. *************************************************************************/ -int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name) +int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share) { myf flags= MY_WME | (share->mode & O_NOFOLLOW ? MY_NOSYMLINKS: 0); DEBUG_SYNC_C("mi_open_datafile"); diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index cfd58418c87..c905ad4048d 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -1012,7 +1012,7 @@ static int myisamchk(HA_CHECK *param, char * filename) MYF(MY_WME)); /* Close new file */ error|=change_to_newfile(filename, MI_NAME_DEXT, DATA_TMP_EXT, 0, MYF(0)); - if (mi_open_datafile(info,info->s, NULL)) + if (mi_open_datafile(info, info->s)) error=1; param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ param->read_cache.file=info->dfile; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index 751aa9b6235..50439c0859d 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -708,7 +708,7 @@ void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows); extern MI_INFO *test_if_reopen(char *filename); my_bool check_table_is_closed(const char *name, const char *where); -int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *orn_name); +int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share); int mi_open_keyfile(MYISAM_SHARE *share); void mi_setup_functions(register MYISAM_SHARE *share); From f2d24ea68b9fde45d9a221f2c2a5d75fd10ef650 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2017 13:39:54 +0100 Subject: [PATCH 31/43] compilation failure At least it would be a compilation failure with -DDONT_ALLOW_SHOW_COMMANDS. Otherwise it only confuses ctags to ignore ~75% of sql_parse.cc --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a12a2c4193c..32784f6432a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1631,12 +1631,12 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, #endif case SCH_COLUMNS: case SCH_STATISTICS: - { #ifdef DONT_ALLOW_SHOW_COMMANDS my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); #else + { DBUG_ASSERT(table_ident); TABLE_LIST **query_tables_last= lex->query_tables_last; schema_select_lex= new SELECT_LEX(); From 6d50324558e79d6e90848059bf7cd918685b02ba Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2017 22:41:17 +0100 Subject: [PATCH 32/43] support MY_NOSYMLINKS in my_delete() --- mysys/my_delete.c | 11 +++++- mysys/my_open.c | 88 +++------------------------------------------- mysys/my_symlink.c | 75 +++++++++++++++++++++++++++++++++++++++ mysys/mysys_priv.h | 28 +++++++++++++++ 4 files changed, 118 insertions(+), 84 deletions(-) diff --git a/mysys/my_delete.c b/mysys/my_delete.c index 155e925e9ba..8487f1d2e5a 100644 --- a/mysys/my_delete.c +++ b/mysys/my_delete.c @@ -21,6 +21,12 @@ static int my_win_unlink(const char *name); #endif +CREATE_NOSYMLINK_FUNCTION( + unlink_nosymlinks(const char *pathname), + unlinkat(dfd, filename, 0), + unlink(pathname) +); + int my_delete(const char *name, myf MyFlags) { int err; @@ -30,7 +36,10 @@ int my_delete(const char *name, myf MyFlags) #ifdef _WIN32 err = my_win_unlink(name); #else - err = unlink(name); + if (MyFlags & MY_NOSYMLINKS) + err= unlink_nosymlinks(name); + else + err= unlink(name); #endif if(err) diff --git a/mysys/my_open.c b/mysys/my_open.c index 0effc4bedda..cafb94ef558 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -18,11 +18,11 @@ #include #include -#if !defined(O_PATH) && defined(O_EXEC) /* FreeBSD */ -#define O_PATH O_EXEC -#endif - -static int open_nosymlinks(const char *pathname, int flags, int mode); +CREATE_NOSYMLINK_FUNCTION( + open_nosymlinks(const char *pathname, int flags, int mode), + openat(dfd, filename, O_NOFOLLOW | flags, mode), + open(pathname, O_NOFOLLOW | flags, mode) +); /* Open a file @@ -182,81 +182,3 @@ void my_print_open_files(void) } #endif - -/** - like open(), but with symlinks are not accepted anywhere in the path - - This is used for opening symlinked tables for DATA/INDEX DIRECTORY. - The paths there have been realpath()-ed. So, we can assume here that - - * `pathname` is an absolute path - * no '.', '..', and '//' in the path - * file exists -*/ -static int open_nosymlinks(const char *pathname, int flags, int mode) -{ -#ifndef O_PATH -#ifdef HAVE_REALPATH - char buf[PATH_MAX+1]; - if (realpath(pathname, buf) == NULL) - return -1; - if (strcmp(pathname, buf)) - { - errno= ENOTDIR; - return -1; - } -#endif - return open(pathname, flags, mode | O_NOFOLLOW); -#else - - char buf[PATH_MAX+1]; - char *s= buf, *e= buf+1, *end= strnmov(buf, pathname, sizeof(buf)); - int fd, dfd= -1; - - if (*end) - { - errno= ENAMETOOLONG; - return -1; - } - - if (*s != '/') /* not an absolute path */ - { - errno= ENOENT; - return -1; - } - - for (;;) - { - if (*e == '/') /* '//' in the path */ - { - errno= ENOENT; - goto err; - } - while (*e && *e != '/') - e++; - *e= 0; - if (!memcmp(s, ".", 2) || !memcmp(s, "..", 3)) - { - errno= ENOENT; - goto err; - } - - fd = openat(dfd, s, O_NOFOLLOW | (e < end ? O_PATH : flags), mode); - if (fd < 0) - goto err; - - if (dfd >= 0) - close(dfd); - - dfd= fd; - s= ++e; - - if (e >= end) - return fd; - } -err: - if (dfd >= 0) - close(dfd); - return -1; -#endif -} diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c index bc01a68263d..ed35fff41e9 100644 --- a/mysys/my_symlink.c +++ b/mysys/my_symlink.c @@ -177,3 +177,78 @@ int my_realpath(char *to, const char *filename, myf MyFlags) #endif return 0; } + +#ifdef HAVE_OPEN_PARENT_DIR_NOSYMLINKS +/** opens the parent dir. walks the path, and does not resolve symlinks + + returns the pointer to the file name (basename) within the pathname + or NULL in case of an error + + stores the parent dir (dirname) file descriptor in pdfd. + It can be -1 even if there was no error! + + This is used for symlinked tables for DATA/INDEX DIRECTORY. + The paths there have been realpath()-ed. So, we can assume here that + + * `pathname` is an absolute path + * no '.', '..', and '//' in the path + * file exists +*/ + +const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd) +{ + char buf[PATH_MAX+1]; + char *s= buf, *e= buf+1, *end= strnmov(buf, pathname, sizeof(buf)); + int fd, dfd= -1; + + if (*end) + { + errno= ENAMETOOLONG; + return NULL; + } + + if (*s != '/') /* not an absolute path */ + { + errno= ENOENT; + return NULL; + } + + for (;;) + { + if (*e == '/') /* '//' in the path */ + { + errno= ENOENT; + goto err; + } + while (*e && *e != '/') + e++; + *e= 0; + + if (!memcmp(s, ".", 2) || !memcmp(s, "..", 3)) + { + errno= ENOENT; + goto err; + } + + if (++e >= end) + { + *pdfd= dfd; + return pathname + (s - buf); + } + + fd = openat(dfd, s, O_NOFOLLOW | O_PATH); + if (fd < 0) + goto err; + + if (dfd >= 0) + close(dfd); + + dfd= fd; + s= e; + } +err: + if (dfd >= 0) + close(dfd); + return NULL; +} +#endif diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index f5d2f301837..4b489504c26 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -89,6 +89,34 @@ void sf_free(void *ptr); void my_error_unregister_all(void); +#if !defined(O_PATH) && defined(O_EXEC) /* FreeBSD */ +#define O_PATH O_EXEC +#endif + +#ifdef O_PATH +#define HAVE_OPEN_PARENT_DIR_NOSYMLINKS +const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd); +#define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ + int dfd, res; \ + const char *filename= my_open_parent_dir_nosymlinks(pathname, &dfd); \ + if (filename == NULL) return -1; \ + res= AT; \ + if (dfd >= 0) close(dfd); \ + return res; +#elif defined(HAVE_REALPATH) +#define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ + char buf[PATH_MAX+1]; \ + if (realpath(pathname, buf) == NULL) return -1; \ + if (strcmp(pathname, buf)) { errno= ENOTDIR; return -1; } \ + return NOAT; +#else +#define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ + return NOAT; +#endif + +#define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) \ +static int PROTO { NOSYMLINK_FUNCTION_BODY(AT,NOAT) } + #ifdef _WIN32 #include /* my_winfile.c exports, should not be used outside mysys */ From 93cb0246b8c883c4f5010468892986fa1d5ba379 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2017 11:07:38 +0100 Subject: [PATCH 33/43] race-condition safe implementation of mi_delete_table/maria_delete_table --- include/my_sys.h | 3 +++ mysys/my_symlink2.c | 28 ++++++++++++++++++++++++++ mysys/my_sync.c | 2 +- storage/maria/ma_delete_table.c | 11 +++-------- storage/myisam/mi_delete_table.c | 34 +++----------------------------- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index bb19a30497a..261d68deaab 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -581,6 +581,9 @@ extern File my_create_with_symlink(const char *linkname, const char *filename, extern int my_delete_with_symlink(const char *name, myf MyFlags); extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); extern int my_symlink(const char *content, const char *linkname, myf MyFlags); +extern int my_handler_delete_with_symlink(PSI_file_key key, const char *name, + const char *ext, myf sync_dir); + extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags); extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset, myf MyFlags); diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index fcaf78ccff6..66b823aeafe 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -182,3 +182,31 @@ int my_rename_with_symlink(const char *from, const char *to, myf MyFlags) DBUG_RETURN(result); #endif /* HAVE_READLINK */ } + +/** delete a - possibly symlinked - table file + + This is used to delete a file that is part of a table (e.g. MYI or MYD + file of MyISAM) when dropping a table. A file might be a symlink - + if the table was created with DATA DIRECTORY or INDEX DIRECTORY - + in this case both the symlink and the symlinked file are deleted, + but only if the symlinked file is not in the datadir. +*/ +int my_handler_delete_with_symlink(PSI_file_key key, const char *name, + const char *ext, myf sync_dir) +{ + char orig[FN_REFLEN], real[FN_REFLEN]; + int res= 0; + DBUG_ENTER("my_handler_delete_with_symlink"); + + fn_format(orig, name, "", ext, MY_UNPACK_FILENAME | MY_APPEND_EXT); + if (my_is_symlink(orig)) + { + /* + Delete the symlinked file only if the symlink is not + pointing into datadir. + */ + if (!(my_realpath(real, orig, MYF(0)) || mysys_test_invalid_symlink(real))) + res= mysql_file_delete(key, real, MYF(MY_NOSYMLINKS | MY_WME | sync_dir)); + } + DBUG_RETURN(mysql_file_delete(key, orig, MYF(MY_WME | sync_dir)) || res); +} diff --git a/mysys/my_sync.c b/mysys/my_sync.c index 88bcb685271..77e7befebed 100644 --- a/mysys/my_sync.c +++ b/mysys/my_sync.c @@ -199,7 +199,7 @@ int my_sync_dir_by_file(const char *file_name __attribute__((unused)), char dir_name[FN_REFLEN]; size_t dir_name_length; dirname_part(dir_name, file_name, &dir_name_length); - return my_sync_dir(dir_name, my_flags); + return my_sync_dir(dir_name, my_flags & ~MY_NOSYMLINKS); #else return 0; #endif diff --git a/storage/maria/ma_delete_table.c b/storage/maria/ma_delete_table.c index 09d5cde5ad0..c4bcd5ba060 100644 --- a/storage/maria/ma_delete_table.c +++ b/storage/maria/ma_delete_table.c @@ -84,15 +84,10 @@ int maria_delete_table(const char *name) int maria_delete_table_files(const char *name, myf sync_dir) { - char from[FN_REFLEN]; DBUG_ENTER("maria_delete_table_files"); - fn_format(from,name,"",MARIA_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (mysql_file_delete_with_symlink(key_file_kfile, from, - MYF(MY_WME | sync_dir))) + if (my_handler_delete_with_symlink(key_file_kfile, name, MARIA_NAME_IEXT, sync_dir) || + my_handler_delete_with_symlink(key_file_dfile, name, MARIA_NAME_DEXT, sync_dir)) DBUG_RETURN(my_errno); - fn_format(from,name,"",MARIA_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - DBUG_RETURN(mysql_file_delete_with_symlink(key_file_dfile, - from, MYF(MY_WME | sync_dir)) ? - my_errno : 0); + DBUG_RETURN(0); } diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index 7643c093e86..ebedfbda343 100644 --- a/storage/myisam/mi_delete_table.c +++ b/storage/myisam/mi_delete_table.c @@ -22,42 +22,14 @@ int mi_delete_table(const char *name) { - char from[FN_REFLEN]; DBUG_ENTER("mi_delete_table"); #ifdef EXTRA_DEBUG check_table_is_closed(name,"delete"); #endif - fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && mysys_test_invalid_symlink(from)) - { - /* - Symlink is pointing to file in data directory. - Remove symlink, keep file. - */ - if (mysql_file_delete(mi_key_file_kfile, from, MYF(MY_WME))) - DBUG_RETURN(my_errno); - } - else - { - if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME))) - DBUG_RETURN(my_errno); - } - fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && mysys_test_invalid_symlink(from)) - { - /* - Symlink is pointing to file in data directory. - Remove symlink, keep file. - */ - if (mysql_file_delete(mi_key_file_dfile, from, MYF(MY_WME))) - DBUG_RETURN(my_errno); - } - else - { - if (mysql_file_delete_with_symlink(mi_key_file_dfile, from, MYF(MY_WME))) - DBUG_RETURN(my_errno); - } + if (my_handler_delete_with_symlink(mi_key_file_kfile, name, MI_NAME_IEXT, 0) || + my_handler_delete_with_symlink(mi_key_file_dfile, name, MI_NAME_DEXT, 0)) + DBUG_RETURN(my_errno); DBUG_RETURN(0); } From 955f2f036d6252b90e2bffcec521dd4a7db0a30a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2017 19:53:12 +0100 Subject: [PATCH 34/43] race-condition safe implementation of test_if_data_home_dir() don't realpath() twice --- sql/mysqld.cc | 2 +- sql/sql_parse.cc | 44 +++++++++++++++++++++++++++++++------------- sql/sql_parse.h | 3 ++- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2e8a62ecb12..3d2de3126ff 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7267,7 +7267,7 @@ static int mysql_init_variables(void) mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0; #if defined(HAVE_REALPATH) && !defined(HAVE_valgrind) && !defined(HAVE_BROKEN_REALPATH) /* We can only test for sub paths if my_symlink.c is using realpath */ - mysys_test_invalid_symlink= test_if_data_home_dir; + mysys_test_invalid_symlink= path_starts_from_data_home_dir; #endif opt_log= opt_slow_log= 0; opt_bin_log= opt_bin_log_used= 0; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 32784f6432a..c3170d04304 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7697,26 +7697,20 @@ bool check_ident_length(LEX_STRING *ident) Check if path does not contain mysql data home directory SYNOPSIS - test_if_data_home_dir() - dir directory + path_starts_from_data_home_dir() + dir directory, with all symlinks resolved RETURN VALUES 0 ok 1 error ; Given path contains data directory */ -C_MODE_START +extern "C" { -int test_if_data_home_dir(const char *dir) +int path_starts_from_data_home_dir(const char *path) { - char path[FN_REFLEN]; - int dir_len; - DBUG_ENTER("test_if_data_home_dir"); + int dir_len= strlen(path); + DBUG_ENTER("path_starts_from_data_home_dir"); - if (!dir) - DBUG_RETURN(0); - - (void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH); - dir_len= strlen(path); if (mysql_unpacked_real_data_home_len<= dir_len) { if (dir_len > mysql_unpacked_real_data_home_len && @@ -7744,7 +7738,31 @@ int test_if_data_home_dir(const char *dir) DBUG_RETURN(0); } -C_MODE_END +} + +/* + Check if path does not contain mysql data home directory + + SYNOPSIS + test_if_data_home_dir() + dir directory + + RETURN VALUES + 0 ok + 1 error ; Given path contains data directory +*/ + +int test_if_data_home_dir(const char *dir) +{ + char path[FN_REFLEN]; + DBUG_ENTER("test_if_data_home_dir"); + + if (!dir) + DBUG_RETURN(0); + + (void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH); + DBUG_RETURN(path_starts_from_data_home_dir(path)); +} /** diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 66a8f6efc7d..c5ea38706c4 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -33,7 +33,8 @@ enum enum_mysql_completiontype { COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 }; -extern "C" int test_if_data_home_dir(const char *dir); +extern "C" int path_starts_from_data_home_dir(const char *dir); +int test_if_data_home_dir(const char *dir); bool multi_update_precheck(THD *thd, TABLE_LIST *tables); bool multi_delete_precheck(THD *thd, TABLE_LIST *tables); From d72dbb41229ceb6434ecd3e23d559bb7b39dd15f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2017 22:40:47 +0100 Subject: [PATCH 35/43] bugfix: remove my_delete_with_symlink() it was race condition prone. instead use either a pair of my_delete() calls with already resolved paths, or a safe high-level function my_handler_delete_with_symlink(), like MyISAM and Aria already do. --- include/my_sys.h | 1 - include/mysql/psi/mysql_file.h | 41 ------------------------ mysys/my_symlink2.c | 21 ------------- sql/handler.cc | 4 +-- sql/sql_db.cc | 6 ++-- storage/maria/ma_create.c | 57 ++++++++++++++++++---------------- storage/myisam/mi_create.c | 53 ++++++++++++++++--------------- 7 files changed, 62 insertions(+), 121 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 261d68deaab..10551e119ac 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -578,7 +578,6 @@ extern int my_realpath(char *to, const char *filename, myf MyFlags); extern File my_create_with_symlink(const char *linkname, const char *filename, int createflags, int access_flags, myf MyFlags); -extern int my_delete_with_symlink(const char *name, myf MyFlags); extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); extern int my_symlink(const char *content, const char *linkname, myf MyFlags); extern int my_handler_delete_with_symlink(PSI_file_key key, const char *name, diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h index 6fc6689c47d..4a0f3fdd68b 100644 --- a/include/mysql/psi/mysql_file.h +++ b/include/mysql/psi/mysql_file.h @@ -434,20 +434,6 @@ inline_mysql_file_create_with_symlink(P1, P2, P3, P4, P5) #endif -/** - @def mysql_file_delete_with_symlink(K, P1, P2) - Instrumented delete with symbolic link. - @c mysql_file_delete_with_symlink is a replacement - for @c my_delete_with_symlink. -*/ -#ifdef HAVE_PSI_INTERFACE - #define mysql_file_delete_with_symlink(K, P1, P2) \ - inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2) -#else - #define mysql_file_delete_with_symlink(K, P1, P2) \ - inline_mysql_file_delete_with_symlink(P1, P2) -#endif - /** @def mysql_file_rename_with_symlink(K, P1, P2, P3) Instrumented rename with symbolic link. @@ -1348,33 +1334,6 @@ inline_mysql_file_create_with_symlink( return file; } -static inline int -inline_mysql_file_delete_with_symlink( -#ifdef HAVE_PSI_INTERFACE - PSI_file_key key, const char *src_file, uint src_line, -#endif - const char *name, myf flags) -{ - int result; -#ifdef HAVE_PSI_INTERFACE - struct PSI_file_locker *locker= NULL; - PSI_file_locker_state state; - if (likely(PSI_server != NULL)) - { - locker= PSI_server->get_thread_file_name_locker(&state, key, PSI_FILE_DELETE, - name, &locker); - if (likely(locker != NULL)) - PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); - } -#endif - result= my_delete_with_symlink(name, flags); -#ifdef HAVE_PSI_INTERFACE - if (likely(locker != NULL)) - PSI_server->end_file_wait(locker, (size_t) 0); -#endif - return result; -} - static inline int inline_mysql_file_rename_with_symlink( #ifdef HAVE_PSI_INTERFACE diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index 66b823aeafe..5fe7b8fcae9 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -91,27 +91,6 @@ File my_create_with_symlink(const char *linkname, const char *filename, DBUG_RETURN(file); } -/* - If the file was a symlink, delete both symlink and the file which the - symlink pointed to. -*/ - -int my_delete_with_symlink(const char *name, myf MyFlags) -{ - char link_name[FN_REFLEN]; - int was_symlink= (!my_disable_symlinks && - !my_readlink(link_name, name, MYF(0))); - int result; - DBUG_ENTER("my_delete_with_symlink"); - - if (!(result=my_delete(name, MyFlags))) - { - if (was_symlink) - result=my_delete(link_name, MyFlags); - } - DBUG_RETURN(result); -} - /* If the file is a normal file, just rename it. If the file is a symlink: diff --git a/sql/handler.cc b/sql/handler.cc index cef3f098161..2ae144a86cc 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3378,12 +3378,10 @@ int handler::delete_table(const char *name) int saved_error= 0; int error= 0; int enoent_or_zero= ENOENT; // Error if no file was deleted - char buff[FN_REFLEN]; for (const char **ext=bas_ext(); *ext ; ext++) { - fn_format(buff, name, "", *ext, MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (mysql_file_delete_with_symlink(key_file_misc, buff, MYF(0))) + if (my_handler_delete_with_symlink(key_file_misc, name, *ext, 0)) { if (my_errno != ENOENT) { diff --git a/sql/sql_db.cc b/sql/sql_db.cc index f72a8918f61..7bb4f0fa60e 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1083,9 +1083,9 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp, strxmov(filePath, path, "/", file->name, NullS); /* We ignore ENOENT error in order to skip files that was deleted - by concurrently running statement like REAPIR TABLE ... + by concurrently running statement like REPAIR TABLE ... */ - if (my_delete_with_symlink(filePath, MYF(0)) && + if (my_handler_delete_with_symlink(key_file_misc, filePath, "", MYF(0)) && my_errno != ENOENT) { my_error(EE_DELETE, MYF(0), filePath, my_errno); @@ -1206,7 +1206,7 @@ long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path) continue; } strxmov(filePath, org_path, "/", file->name, NullS); - if (mysql_file_delete_with_symlink(key_file_misc, filePath, MYF(MY_WME))) + if (my_handler_delete_with_symlink(key_file_misc, filePath, "", MYF(MY_WME))) { goto err; } diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index 28c3491730f..3e96ffea335 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -52,7 +52,8 @@ int maria_create(const char *name, enum data_file_type datafile_type, unique_key_parts,fulltext_keys,offset, not_block_record_extra_length; uint max_field_lengths, extra_header_size, column_nr; ulong reclength, real_reclength,min_pack_length; - char filename[FN_REFLEN], linkname[FN_REFLEN], *linkname_ptr; + char kfilename[FN_REFLEN], klinkname[FN_REFLEN], *klinkname_ptr; + char dfilename[FN_REFLEN], dlinkname[FN_REFLEN], *dlinkname_ptr; ulong pack_reclength; ulonglong tot_length,max_rows, tmp; enum en_fieldtype type; @@ -805,19 +806,19 @@ int maria_create(const char *name, enum data_file_type datafile_type, /* chop off the table name, tempory tables use generated name */ if ((path= strrchr(ci->index_file_name, FN_LIBCHAR))) *path= '\0'; - fn_format(filename, name, ci->index_file_name, MARIA_NAME_IEXT, + fn_format(kfilename, name, ci->index_file_name, MARIA_NAME_IEXT, MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | MY_APPEND_EXT); } else { - fn_format(filename, ci->index_file_name, "", MARIA_NAME_IEXT, + fn_format(kfilename, ci->index_file_name, "", MARIA_NAME_IEXT, MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); } - fn_format(linkname, name, "", MARIA_NAME_IEXT, + fn_format(klinkname, name, "", MARIA_NAME_IEXT, MY_UNPACK_FILENAME|MY_APPEND_EXT); - linkname_ptr= linkname; + klinkname_ptr= klinkname; /* Don't create the table if the link or file exists to ensure that one doesn't accidently destroy another table. @@ -831,10 +832,10 @@ int maria_create(const char *name, enum data_file_type datafile_type, { char *iext= strrchr(name, '.'); int have_iext= iext && !strcmp(iext, MARIA_NAME_IEXT); - fn_format(filename, name, "", MARIA_NAME_IEXT, + fn_format(kfilename, name, "", MARIA_NAME_IEXT, MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); - linkname_ptr= NullS; + klinkname_ptr= NullS; /* Replace the current file. Don't sync dir now if the data file has the same path. @@ -854,7 +855,7 @@ int maria_create(const char *name, enum data_file_type datafile_type, NOTE: The filename is compared against unique_file_name of every open table. Hence we need a real path here. */ - if (_ma_test_if_reopen(filename)) + if (_ma_test_if_reopen(kfilename)) { my_printf_error(HA_ERR_TABLE_EXIST, "Aria table '%s' is in use " "(most likely by a MERGE table). Try FLUSH TABLES.", @@ -863,8 +864,8 @@ int maria_create(const char *name, enum data_file_type datafile_type, goto err; } - if ((file= mysql_file_create_with_symlink(key_file_kfile, linkname_ptr, - filename, 0, create_mode, + if ((file= mysql_file_create_with_symlink(key_file_kfile, klinkname_ptr, + kfilename, 0, create_mode, MYF(MY_WME|create_flag))) < 0) goto err; errpos=1; @@ -1118,30 +1119,30 @@ int maria_create(const char *name, enum data_file_type datafile_type, /* chop off the table name, tempory tables use generated name */ if ((path= strrchr(ci->data_file_name, FN_LIBCHAR))) *path= '\0'; - fn_format(filename, name, ci->data_file_name, MARIA_NAME_DEXT, + fn_format(dfilename, name, ci->data_file_name, MARIA_NAME_DEXT, MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_APPEND_EXT); } else { - fn_format(filename, ci->data_file_name, "", MARIA_NAME_DEXT, + fn_format(dfilename, ci->data_file_name, "", MARIA_NAME_DEXT, MY_UNPACK_FILENAME | (have_dext ? MY_REPLACE_EXT : MY_APPEND_EXT)); } - fn_format(linkname, name, "",MARIA_NAME_DEXT, + fn_format(dlinkname, name, "",MARIA_NAME_DEXT, MY_UNPACK_FILENAME | MY_APPEND_EXT); - linkname_ptr= linkname; + dlinkname_ptr= dlinkname; create_flag=0; } else { - fn_format(filename,name,"", MARIA_NAME_DEXT, + fn_format(dfilename,name,"", MARIA_NAME_DEXT, MY_UNPACK_FILENAME | MY_APPEND_EXT); - linkname_ptr= NullS; + dlinkname_ptr= NullS; create_flag= (flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } if ((dfile= - mysql_file_create_with_symlink(key_file_dfile, linkname_ptr, - filename, 0, create_mode, + mysql_file_create_with_symlink(key_file_dfile, dlinkname_ptr, + dfilename, 0, create_mode, MYF(MY_WME | create_flag | sync_dir))) < 0) goto err; errpos=3; @@ -1189,19 +1190,21 @@ err_no_lock: mysql_file_close(dfile, MYF(0)); /* fall through */ case 2: - if (! (flags & HA_DONT_TOUCH_DATA)) - mysql_file_delete_with_symlink(key_file_dfile, - fn_format(filename,name,"",MARIA_NAME_DEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - sync_dir); + if (! (flags & HA_DONT_TOUCH_DATA)) + { + mysql_file_delete(key_file_dfile, dfilename, MYF(sync_dir)); + if (dlinkname_ptr) + mysql_file_delete(key_file_dfile, dlinkname_ptr, MYF(sync_dir)); + } /* fall through */ case 1: mysql_file_close(file, MYF(0)); if (! (flags & HA_DONT_TOUCH_DATA)) - mysql_file_delete_with_symlink(key_file_kfile, - fn_format(filename,name,"",MARIA_NAME_IEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - sync_dir); + { + mysql_file_delete(key_file_kfile, kfilename, MYF(sync_dir)); + if (klinkname_ptr) + mysql_file_delete(key_file_kfile, klinkname_ptr, MYF(sync_dir)); + } } my_free(log_data); my_free(rec_per_key_part); diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index bdd932b86fe..fdc9eeef147 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -45,7 +45,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, max_key_block_length,unique_key_parts,fulltext_keys,offset; uint aligned_key_start, block_length, res; ulong reclength, real_reclength,min_pack_length; - char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr; + char kfilename[FN_REFLEN],klinkname[FN_REFLEN], *klinkname_ptr; + char dfilename[FN_REFLEN],dlinkname[FN_REFLEN], *dlinkname_ptr; ulong pack_reclength; ulonglong tot_length,max_rows, tmp; enum en_fieldtype type; @@ -591,19 +592,19 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, /* chop off the table name, tempory tables use generated name */ if ((path= strrchr(ci->index_file_name, FN_LIBCHAR))) *path= '\0'; - fn_format(filename, name, ci->index_file_name, MI_NAME_IEXT, + fn_format(kfilename, name, ci->index_file_name, MI_NAME_IEXT, MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | MY_APPEND_EXT); } else { - fn_format(filename, ci->index_file_name, "", MI_NAME_IEXT, + fn_format(kfilename, ci->index_file_name, "", MI_NAME_IEXT, MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); } - fn_format(linkname, name, "", MI_NAME_IEXT, + fn_format(klinkname, name, "", MI_NAME_IEXT, MY_UNPACK_FILENAME|MY_APPEND_EXT); - linkname_ptr=linkname; + klinkname_ptr= klinkname; /* Don't create the table if the link or file exists to ensure that one doesn't accidently destroy another table. @@ -614,10 +615,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { char *iext= strrchr(name, '.'); int have_iext= iext && !strcmp(iext, MI_NAME_IEXT); - fn_format(filename, name, "", MI_NAME_IEXT, + fn_format(kfilename, name, "", MI_NAME_IEXT, MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); - linkname_ptr=0; + klinkname_ptr= 0; /* Replace the current file */ create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } @@ -632,7 +633,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, NOTE: The filename is compared against unique_file_name of every open table. Hence we need a real path here. */ - if (test_if_reopen(filename)) + if (test_if_reopen(kfilename)) { my_printf_error(HA_ERR_TABLE_EXIST, "MyISAM table '%s' is in use " "(most likely by a MERGE table). Try FLUSH TABLES.", @@ -642,7 +643,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, } if ((file= mysql_file_create_with_symlink(mi_key_file_kfile, - linkname_ptr, filename, 0, + klinkname_ptr, kfilename, 0, create_mode, MYF(MY_WME | create_flag))) < 0) goto err; @@ -662,31 +663,31 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, /* chop off the table name, tempory tables use generated name */ if ((path= strrchr(ci->data_file_name, FN_LIBCHAR))) *path= '\0'; - fn_format(filename, name, ci->data_file_name, MI_NAME_DEXT, + fn_format(dfilename, name, ci->data_file_name, MI_NAME_DEXT, MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_APPEND_EXT); } else { - fn_format(filename, ci->data_file_name, "", MI_NAME_DEXT, + fn_format(dfilename, ci->data_file_name, "", MI_NAME_DEXT, MY_UNPACK_FILENAME | (have_dext ? MY_REPLACE_EXT : MY_APPEND_EXT)); } - fn_format(linkname, name, "",MI_NAME_DEXT, + fn_format(dlinkname, name, "",MI_NAME_DEXT, MY_UNPACK_FILENAME | MY_APPEND_EXT); - linkname_ptr=linkname; + dlinkname_ptr= dlinkname; create_flag=0; } else { - fn_format(filename,name,"", MI_NAME_DEXT, + fn_format(dfilename,name,"", MI_NAME_DEXT, MY_UNPACK_FILENAME | MY_APPEND_EXT); - linkname_ptr=0; + dlinkname_ptr= 0; create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } if ((dfile= mysql_file_create_with_symlink(mi_key_file_dfile, - linkname_ptr, filename, 0, + dlinkname_ptr, dfilename, 0, create_mode, MYF(MY_WME | create_flag))) < 0) goto err; @@ -838,19 +839,21 @@ err_no_lock: (void) mysql_file_close(dfile, MYF(0)); /* fall through */ case 2: - if (! (flags & HA_DONT_TOUCH_DATA)) - mysql_file_delete_with_symlink(mi_key_file_dfile, - fn_format(filename, name, "", MI_NAME_DEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + if (! (flags & HA_DONT_TOUCH_DATA)) + { + mysql_file_delete(mi_key_file_dfile, dfilename, MYF(0)); + if (dlinkname_ptr) + mysql_file_delete(mi_key_file_dfile, dlinkname_ptr, MYF(0)); + } /* fall through */ case 1: (void) mysql_file_close(file, MYF(0)); if (! (flags & HA_DONT_TOUCH_DATA)) - mysql_file_delete_with_symlink(mi_key_file_kfile, - fn_format(filename, name, "", MI_NAME_IEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + { + mysql_file_delete(mi_key_file_kfile, kfilename, MYF(0)); + if (klinkname_ptr) + mysql_file_delete(mi_key_file_kfile, klinkname_ptr, MYF(0)); + } } my_free(rec_per_key_part); DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */ From 44534487d4b1364e34a072a67130fe1848636c99 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 21 Feb 2017 11:07:42 +0100 Subject: [PATCH 36/43] MDEV-11505 wrong databasename in mysqldump comment fix_for_comment() uses a static buffer. cannot have two fix_for_comment() calls as arguments to one printf(). --- client/mysqldump.c | 5 +++-- mysql-test/t/mysqldump.test | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 32c350d3078..6e9d8946a0f 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -670,8 +670,9 @@ static void write_header(FILE *sql_file, char *db_name) "-- MySQL dump %s Distrib %s, for %s (%s)\n--\n", DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); - print_comment(sql_file, 0, "-- Host: %s Database: %s\n", - fix_for_comment(current_host ? current_host : "localhost"), + print_comment(sql_file, 0, "-- Host: %s ", + fix_for_comment(current_host ? current_host : "localhost")); + print_comment(sql_file, 0, "Database: %s\n", fix_for_comment(db_name ? db_name : "")); print_comment(sql_file, 0, "-- ------------------------------------------------------\n" diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index f0ada44fafd..7b517a7ce59 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2509,3 +2509,11 @@ if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Wind } --exec $MYSQL_DUMP --routines --compact $shell_ready_db_name DROP DATABASE `a\"'``b`; + +#" +# MDEV-11505 wrong databasename in mysqldump comment +# +let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/bug11505.sql; +let SEARCH_PATTERN=Database: mysql; +exec $MYSQL_DUMP mysql func > $SEARCH_FILE; +source include/search_pattern_in_file.inc; From 831b531895d9a4c0735eaff727acbc28f4e4b412 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 22 Feb 2017 15:22:22 +0100 Subject: [PATCH 37/43] MDEV-10788 Not able to compile source with -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=Debug It's too plainful to require to be included first for third-party storage engines. And anyway, some source files might not include at all, so there is no guarantee that all parts of the binary will see identical definitions of system structures (e.g. struct stat). Define _FILE_OFFSET_BITS on the compiler's command line instead. --- CMakeLists.txt | 3 +++ config.h.cmake | 18 ------------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ab8870ffb8..6cf2ccb175f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -341,6 +341,9 @@ INCLUDE(configure.cmake) # Common defines and includes ADD_DEFINITIONS(-DHAVE_CONFIG_H) +IF(_FILE_OFFSET_BITS) + ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}) +ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include) # Add bundled or system zlib. diff --git a/config.h.cmake b/config.h.cmake index 225d4891bf8..dfdd4215e4a 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -484,7 +484,6 @@ #cmakedefine _LARGE_FILES 1 #cmakedefine _LARGEFILE_SOURCE 1 #cmakedefine _LARGEFILE64_SOURCE 1 -#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ #cmakedefine TIME_WITH_SYS_TIME 1 @@ -647,21 +646,4 @@ #cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@ #cmakedefine TIME_T_UNSIGNED @TIME_T_UNSIGNED@ -/* - stat structure (from ) is conditionally defined - to have different layout and size depending on the defined macros. - The correct macro is defined in my_config.h, which means it MUST be - included first (or at least before - so, practically, - before including any system headers). - - Check the include order by looking at __GLIBC__ (defined in ) - - But we cannot force all third-party clients/connectors to include - my_config.h first. So, their crashes are their responsibility, - we enable this check only for MariaDB sources (SAFE_MUTEX check). -*/ -#if defined(__GLIBC__) && defined(SAFE_MUTEX) -#error MUST be included first! -#endif - #endif From 713d513624a05c8ba4e5c87d90300cc9bce4e015 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Feb 2017 10:32:34 +0100 Subject: [PATCH 38/43] MDEV-12074 selinux build failure on Fedora 24 --- .gitignore | 2 +- support-files/SELinux/CMakeLists.txt | 4 ++-- support-files/SELinux/{centos6-mariadb.te => mariadb.te} | 0 support-files/rpm/server-postin.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename support-files/SELinux/{centos6-mariadb.te => mariadb.te} (100%) diff --git a/.gitignore b/.gitignore index 4d96bfe65a3..4e3d2a1e66e 100644 --- a/.gitignore +++ b/.gitignore @@ -221,7 +221,7 @@ support-files/mysql.spec support-files/mysqld_multi.server support-files/wsrep.cnf support-files/wsrep_notify -support-files/SELinux/centos6-mariadb.pp +support-files/SELinux/mariadb.pp tags tests/async_queries tests/bug25714 diff --git a/support-files/SELinux/CMakeLists.txt b/support-files/SELinux/CMakeLists.txt index e3cdb26ca8f..996d56d6c05 100644 --- a/support-files/SELinux/CMakeLists.txt +++ b/support-files/SELinux/CMakeLists.txt @@ -20,7 +20,7 @@ MARK_AS_ADVANCED(CHECKMODULE SEMODULE_PACKAGE) SET(params DESTINATION ${INSTALL_SUPPORTFILESDIR}/SELinux COMPONENT SupportFiles) IF(CHECKMODULE AND SEMODULE_PACKAGE) - FOREACH(pol centos6-mariadb) + FOREACH(pol mariadb) SET(src ${CMAKE_CURRENT_SOURCE_DIR}/${pol}.te) SET(mod ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${pol}-pp.dir/${pol}.mod) SET(out ${CMAKE_CURRENT_BINARY_DIR}/${pol}.pp) @@ -32,4 +32,4 @@ IF(CHECKMODULE AND SEMODULE_PACKAGE) INSTALL(FILES ${out} ${params}) ENDFOREACH() ENDIF() -INSTALL(FILES centos6-mariadb.te rhel4-mysql.fc rhel4-mysql.te ${params}) +INSTALL(FILES mariadb.te rhel4-mysql.fc rhel4-mysql.te ${params}) diff --git a/support-files/SELinux/centos6-mariadb.te b/support-files/SELinux/mariadb.te similarity index 100% rename from support-files/SELinux/centos6-mariadb.te rename to support-files/SELinux/mariadb.te diff --git a/support-files/rpm/server-postin.sh b/support-files/rpm/server-postin.sh index 377a752824d..d9f06fa43b8 100644 --- a/support-files/rpm/server-postin.sh +++ b/support-files/rpm/server-postin.sh @@ -82,7 +82,7 @@ if [ -f /etc/redhat-release ] ; then fi if grep 'CentOS release 6' /etc/redhat-release >/dev/null 2>&1; then if [ -x /usr/sbin/semodule ] ; then - /usr/sbin/semodule -i /usr/share/mysql/SELinux/centos6-mariadb.pp + /usr/sbin/semodule -i /usr/share/mysql/SELinux/mariadb.pp fi fi fi From 2c354e7468395f87a68833e4c048fdfa2be344d1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Feb 2017 10:34:51 +0100 Subject: [PATCH 39/43] MDEV-11789 MariaDB fails to restart after 10.0.29-1.el7 update --- support-files/rpm/server-postin.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/support-files/rpm/server-postin.sh b/support-files/rpm/server-postin.sh index d9f06fa43b8..2275d4acc7b 100644 --- a/support-files/rpm/server-postin.sh +++ b/support-files/rpm/server-postin.sh @@ -80,11 +80,10 @@ if [ -f /etc/redhat-release ] ; then echo echo fi - if grep 'CentOS release 6' /etc/redhat-release >/dev/null 2>&1; then - if [ -x /usr/sbin/semodule ] ; then - /usr/sbin/semodule -i /usr/share/mysql/SELinux/mariadb.pp - fi - fi +fi + +if [ -x /usr/sbin/semodule ] ; then + /usr/sbin/semodule -i /usr/share/mysql/SELinux/mariadb.pp fi if [ -x sbin/restorecon ] ; then From 0a480f03c64c7f8ffaef40b49a62d194d4aa6a04 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Feb 2017 10:37:02 +0100 Subject: [PATCH 40/43] delete the installation warning for CentOS4/RHEL4 it went out of support five years ago --- support-files/rpm/server-postin.sh | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/support-files/rpm/server-postin.sh b/support-files/rpm/server-postin.sh index 2275d4acc7b..139d9e3f700 100644 --- a/support-files/rpm/server-postin.sh +++ b/support-files/rpm/server-postin.sh @@ -55,32 +55,6 @@ fi SETARGETDIR=/etc/selinux/targeted/src/policy SEDOMPROG=$SETARGETDIR/domains/program SECONPROG=$SETARGETDIR/file_contexts/program -if [ -f /etc/redhat-release ] ; then - if grep '\(Red Hat Enterprise Linux ..\|CentOS\) release 4' \ - /etc/redhat-release >/dev/null 2>&1; then - echo - echo - echo 'Notes regarding SELinux on this platform:' - echo '=========================================' - echo - echo 'The default policy might cause server startup to fail because it is ' - echo 'not allowed to access critical files. In this case, please update ' - echo 'your installation. ' - echo - echo 'The default policy might also cause inavailability of SSL related ' - echo 'features because the server is not allowed to access /dev/random ' - echo 'and /dev/urandom. If this is a problem, please do the following: ' - echo - echo ' 1) install selinux-policy-targeted-sources from your OS vendor' - echo ' 2) add the following two lines to '$SEDOMPROG/mysqld.te':' - echo ' allow mysqld_t random_device_t:chr_file read;' - echo ' allow mysqld_t urandom_device_t:chr_file read;' - echo ' 3) cd to '$SETARGETDIR' and issue the following command:' - echo ' make load' - echo - echo - fi -fi if [ -x /usr/sbin/semodule ] ; then /usr/sbin/semodule -i /usr/share/mysql/SELinux/mariadb.pp From 494a94158a6f509afad1078615679c51b723b7a6 Mon Sep 17 00:00:00 2001 From: Dmitry Lenev Date: Thu, 23 Feb 2017 12:41:13 +0100 Subject: [PATCH 41/43] Fix for bug#11759114 - '51401: GRANT TREATS NONEXISTENT FUNCTIONS/PRIVILEGES DIFFERENTLY'. The problem was that attempt to grant EXECUTE or ALTER ROUTINE privilege on stored procedure which didn't exist succeed instead of returning an appropriate error like it happens in similar situation for stored functions or tables. The code which handles granting of privileges on individual routine calls sp_exist_routines() function to check if routine exists and assumes that the 3rd parameter of the latter specifies whether it should check for existence of stored procedure or function. In practice, this parameter had completely different meaning and, as result, this check was not done properly for stored procedures. This fix addresses this problem by bringing sp_exist_routines() signature and code in line with expectation of its caller. --- mysql-test/r/grant.result | 23 +++++++++++++++++++++++ mysql-test/t/grant.test | 25 +++++++++++++++++++++++++ sql/sp.cc | 22 ++++++++++------------ sql/sp.h | 2 +- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index f3910b67dd3..399f8964c2f 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -1701,6 +1701,7 @@ Assigning privileges without procs_priv table. CREATE DATABASE mysqltest1; CREATE PROCEDURE mysqltest1.test() SQL SECURITY DEFINER SELECT 1; +CREATE FUNCTION mysqltest1.test() RETURNS INT RETURN 1; GRANT EXECUTE ON FUNCTION mysqltest1.test TO mysqltest_1@localhost; ERROR 42S02: Table 'mysql.procs_priv' doesn't exist GRANT ALL PRIVILEGES ON test.* TO mysqltest_1@localhost; @@ -2537,3 +2538,25 @@ DROP USER mysqltest_u1@localhost; # End of Bug#38347. +# +# BUG#11759114 - '51401: GRANT TREATS NONEXISTENT FUNCTIONS/PRIVILEGES +# DIFFERENTLY'. +# +drop database if exists mysqltest_db1; +create database mysqltest_db1; +create user mysqltest_u1; +# Both GRANT statements below should fail with the same error. +grant execute on function mysqltest_db1.f1 to mysqltest_u1; +ERROR 42000: FUNCTION or PROCEDURE f1 does not exist +grant execute on procedure mysqltest_db1.p1 to mysqltest_u1; +ERROR 42000: FUNCTION or PROCEDURE p1 does not exist +# Let us show that GRANT behaviour for routines is consistent +# with GRANT behaviour for tables. Attempt to grant privilege +# on non-existent table also results in an error. +grant select on mysqltest_db1.t1 to mysqltest_u1; +ERROR 42S02: Table 'mysqltest_db1.t1' doesn't exist +show grants for mysqltest_u1; +Grants for mysqltest_u1@% +GRANT USAGE ON *.* TO 'mysqltest_u1'@'%' +drop database mysqltest_db1; +drop user mysqltest_u1; diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 20284ec9ae9..7a8fb0598d1 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -1675,6 +1675,7 @@ FLUSH PRIVILEGES; CREATE DATABASE mysqltest1; CREATE PROCEDURE mysqltest1.test() SQL SECURITY DEFINER SELECT 1; +CREATE FUNCTION mysqltest1.test() RETURNS INT RETURN 1; --error ER_NO_SUCH_TABLE GRANT EXECUTE ON FUNCTION mysqltest1.test TO mysqltest_1@localhost; GRANT ALL PRIVILEGES ON test.* TO mysqltest_1@localhost; @@ -2186,3 +2187,27 @@ DROP USER mysqltest_u1@localhost; --echo --echo # End of Bug#38347. --echo + + +--echo # +--echo # BUG#11759114 - '51401: GRANT TREATS NONEXISTENT FUNCTIONS/PRIVILEGES +--echo # DIFFERENTLY'. +--echo # +--disable_warnings +drop database if exists mysqltest_db1; +--enable_warnings +create database mysqltest_db1; +create user mysqltest_u1; +--echo # Both GRANT statements below should fail with the same error. +--error ER_SP_DOES_NOT_EXIST +grant execute on function mysqltest_db1.f1 to mysqltest_u1; +--error ER_SP_DOES_NOT_EXIST +grant execute on procedure mysqltest_db1.p1 to mysqltest_u1; +--echo # Let us show that GRANT behaviour for routines is consistent +--echo # with GRANT behaviour for tables. Attempt to grant privilege +--echo # on non-existent table also results in an error. +--error ER_NO_SUCH_TABLE +grant select on mysqltest_db1.t1 to mysqltest_u1; +show grants for mysqltest_u1; +drop database mysqltest_db1; +drop user mysqltest_u1; diff --git a/sql/sp.cc b/sql/sp.cc index 254c9c5a101..e9340608646 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1767,7 +1767,8 @@ sp_find_routine(THD *thd, stored_procedure_type type, sp_name *name, @param thd Thread handler @param routines List of needles in the hay stack - @param any Any of the needles are good enough + @param is_proc Indicates whether routines in the list are procedures + or functions. @return @retval FALSE Found. @@ -1775,7 +1776,7 @@ sp_find_routine(THD *thd, stored_procedure_type type, sp_name *name, */ bool -sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any) +sp_exist_routines(THD *thd, TABLE_LIST *routines, bool is_proc) { TABLE_LIST *routine; bool sp_object_found; @@ -1791,17 +1792,14 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any) lex_name.str= thd->strmake(routine->table_name, lex_name.length); name= new sp_name(lex_db, lex_name, true); name->init_qname(thd); - sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, - &thd->sp_proc_cache, FALSE) != NULL || - sp_find_routine(thd, TYPE_ENUM_FUNCTION, name, - &thd->sp_func_cache, FALSE) != NULL; + sp_object_found= is_proc ? sp_find_routine(thd, TYPE_ENUM_PROCEDURE, + name, &thd->sp_proc_cache, + FALSE) != NULL : + sp_find_routine(thd, TYPE_ENUM_FUNCTION, + name, &thd->sp_func_cache, + FALSE) != NULL; thd->warning_info->clear_warning_info(thd->query_id); - if (sp_object_found) - { - if (any) - break; - } - else if (!any) + if (! sp_object_found) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", routine->table_name); diff --git a/sql/sp.h b/sql/sp.h index 3353132346b..82d4704cf2c 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -121,7 +121,7 @@ sp_cache_routine(THD *thd, stored_procedure_type type, sp_name *name, bool lookup_only, sp_head **sp); bool -sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any); +sp_exist_routines(THD *thd, TABLE_LIST *procs, bool is_proc); bool sp_show_create_routine(THD *thd, stored_procedure_type type, sp_name *name); From 199f88cb9cfb08cefced1b51a7d98fe4c91b7a2e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Feb 2017 12:48:15 +0100 Subject: [PATCH 42/43] MDEV-5999 MySQL Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY - REQUIRES FLUSH PRIVILEGES use update_hostname() to update the hostname. test case comes from commit 0abdeed1d6d Author: gopal.shankar@oracle.com <> Date: Thu Mar 29 00:20:54 2012 +0530 Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY - REQUIRES FLUSH PRIVILEGES --- mysql-test/r/grant.result | 26 +++++++++++++++++++++++++ mysql-test/t/grant.test | 40 +++++++++++++++++++++++++++++++++++++++ sql/sql_acl.cc | 4 ++-- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 399f8964c2f..94087393489 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -2560,3 +2560,29 @@ Grants for mysqltest_u1@% GRANT USAGE ON *.* TO 'mysqltest_u1'@'%' drop database mysqltest_db1; drop user mysqltest_u1; +# +# Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY - +# REQUIRES FLUSH PRIVILEGES +# +CREATE USER foo@'127.0.0.1'; +GRANT ALL ON *.* TO foo@'127.0.0.1'; +# First attempt, should connect successfully +SELECT user(), current_user(); +user() current_user() +foo@localhost foo@127.0.0.1 +# Rename the user +RENAME USER foo@'127.0.0.1' to foo@'127.0.0.0/255.0.0.0'; +# Second attempt, should connect successfully as its valid mask +# This was failing without fix +SELECT user(), current_user(); +user() current_user() +foo@localhost foo@127.0.0.0/255.0.0.0 +# Rename the user back to original +RENAME USER foo@'127.0.0.0/255.0.0.0' to foo@'127.0.0.1'; +# Third attempt, should connect successfully +SELECT user(), current_user(); +user() current_user() +foo@localhost foo@127.0.0.1 +# Clean-up +DROP USER foo@'127.0.0.1'; +# End of Bug#12766319 diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 7a8fb0598d1..efa79c5b768 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -2211,3 +2211,43 @@ grant select on mysqltest_db1.t1 to mysqltest_u1; show grants for mysqltest_u1; drop database mysqltest_db1; drop user mysqltest_u1; + + +--echo # +--echo # Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY - +--echo # REQUIRES FLUSH PRIVILEGES +--echo # + +CREATE USER foo@'127.0.0.1'; +GRANT ALL ON *.* TO foo@'127.0.0.1'; + +--echo # First attempt, should connect successfully +connect (conn1, '127.0.0.1', foo,,test); +SELECT user(), current_user(); + +--echo # Rename the user +RENAME USER foo@'127.0.0.1' to foo@'127.0.0.0/255.0.0.0'; + +--echo # Second attempt, should connect successfully as its valid mask +--echo # This was failing without fix +connect (conn2, '127.0.0.1', foo,,test); +SELECT user(), current_user(); + +--echo # Rename the user back to original +RENAME USER foo@'127.0.0.0/255.0.0.0' to foo@'127.0.0.1'; + +--echo # Third attempt, should connect successfully +connect (conn3, '127.0.0.1', foo,,test); +SELECT user(), current_user(); + +--echo # Clean-up +connection default; +disconnect conn1; +disconnect conn2; +disconnect conn3; +DROP USER foo@'127.0.0.1'; + +--echo # End of Bug#12766319 + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 0a1c11ef97a..03f0e878db6 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -6285,12 +6285,12 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop, switch ( struct_no ) { case USER_ACL: acl_user->user= strdup_root(&mem, user_to->user.str); - acl_user->host.hostname= strdup_root(&mem, user_to->host.str); + update_hostname(&acl_user->host, strdup_root(&mem, user_to->host.str)); break; case DB_ACL: acl_db->user= strdup_root(&mem, user_to->user.str); - acl_db->host.hostname= strdup_root(&mem, user_to->host.str); + update_hostname(&acl_db->host, strdup_root(&mem, user_to->host.str)); break; case COLUMN_PRIVILEGES_HASH: From 5a0fff50f87e20c4e95a84143a0a3bb67e03e29e Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sun, 26 Feb 2017 15:40:18 -0800 Subject: [PATCH 43/43] Fixed bug mdev-12099. The function mysql_derived_merge() erroneously did not mark newly formed AND formulas in ON conditions with the flag abort_on_null. As a result not_null_tables() calculated incorrectly for these conditions. This could prevent conversion of embedded outer joins into inner joins. Changed a test case from table_elim.test to preserve the former execution plan. --- mysql-test/r/table_elim.result | 5 +- mysql-test/r/view.result | 83 ++++++++++++++++++++++++++++++++++ mysql-test/t/table_elim.test | 4 +- mysql-test/t/view.test | 60 ++++++++++++++++++++++++ sql/sql_derived.cc | 3 ++ 5 files changed, 151 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/table_elim.result b/mysql-test/r/table_elim.result index f475198ac02..4505adab443 100644 --- a/mysql-test/r/table_elim.result +++ b/mysql-test/r/table_elim.result @@ -597,7 +597,8 @@ CREATE TABLE t1 (a int(11), b varchar(1)) ; INSERT IGNORE INTO t1 VALUES (0,'g'); CREATE TABLE t3 ( a varchar(1)) ; INSERT IGNORE INTO t3 VALUES ('g'); -CREATE TABLE t2 ( a int(11) NOT NULL, PRIMARY KEY (a)) ; +CREATE TABLE t2 ( a int(11) NOT NULL, PRIMARY KEY (a)); +INSERT INTO t2 VALUES (9), (10); create view v1 as SELECT t1.* FROM t1 LEFT JOIN t2 ON ( t1.a = t2.a ) WHERE t2.a <> 0; SELECT alias1.* FROM t3 LEFT JOIN v1 as alias1 ON ( t3.a = alias1.b ); a b @@ -606,7 +607,7 @@ EXPLAIN SELECT alias1.* FROM t3 LEFT JOIN v1 as alias1 ON ( t3.a = alias1.b ); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t3 system NULL NULL NULL NULL 1 1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where -1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where; Using index +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index drop view v1; DROP TABLE t1,t2,t3; # diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 6848ba30245..414de5662f3 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5535,6 +5535,89 @@ Warnings: Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them drop view v1; drop table t1,t2; +# +# MDEV-12099: usage of mergeable view with LEFT JOIN +# that can be converted to INNER JOIN +# +create table t1 (a int, b int, key(a)) engine=myisam; +insert into t1 values +(3,20), (7,10), (2,10), (4,30), (8,70), +(7,70), (9,100), (9,60), (8,80), (7,60); +create table t2 (c int, d int, key (c)) engine=myisam; +insert into t2 values +(50,100), (20, 200), (10,300), +(150,100), (120, 200), (110,300), +(250,100), (220, 200), (210,300); +create table t3(e int, f int not null, key(e), unique (f)) engine=myisam; +insert into t3 values +(100, 3), (300, 5), (400, 4), (300,7), +(300,2), (600, 13), (800, 15), (700, 14), +(600, 23), (800, 25), (700, 24); +create view v1 as +select * from t2 left join t3 on t3.e=t2.d where t3.f is not null; +select * +from t1 left join v1 on v1.c=t1.b +where t1.a < 5; +a b c d e f +2 10 10 300 300 5 +2 10 10 300 300 7 +2 10 10 300 300 2 +3 20 NULL NULL NULL NULL +4 30 NULL NULL NULL NULL +select * +from t1 left join ( t2 left join t3 on t3.e=t2.d ) +on t2.c=t1.b and t3.f is not null +where t1.a < 5; +a b c d e f +2 10 10 300 300 5 +2 10 10 300 300 7 +2 10 10 300 300 2 +3 20 NULL NULL NULL NULL +4 30 NULL NULL NULL NULL +explain extended +select * +from t1 left join v1 on v1.c=t1.b +where t1.a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition +1 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where +1 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`c` = `test`.`t1`.`b`) and (`test`.`t3`.`e` = `test`.`t2`.`d`) and (`test`.`t3`.`f` is not null) and (`test`.`t1`.`b` is not null) and (`test`.`t2`.`d` is not null))) where (`test`.`t1`.`a` < 5) +explain extended +select * +from t1 left join ( t2 left join t3 on t3.e=t2.d ) +on t2.c=t1.b and t3.f is not null +where t1.a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition +1 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where +1 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`c` = `test`.`t1`.`b`) and (`test`.`t3`.`e` = `test`.`t2`.`d`) and (`test`.`t3`.`f` is not null) and (`test`.`t1`.`b` is not null) and (`test`.`t2`.`d` is not null))) where (`test`.`t1`.`a` < 5) +explain extended +select * +from t1 left join v1 on v1.c=t1.b and v1.f=t1.a +where t1.a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition +1 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where +1 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`c` = `test`.`t1`.`b`) and (`test`.`t3`.`f` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t3`.`e`) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`b` is not null))) where (`test`.`t1`.`a` < 5) +explain extended +select * +from t1 left join ( t2 left join t3 on t3.e=t2.d ) +on t2.c=t1.b and t3.f=t1.a and t3.f is not null +where t1.a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition +1 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where +1 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`c` = `test`.`t1`.`b`) and (`test`.`t3`.`f` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t3`.`e`) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`b` is not null))) where (`test`.`t1`.`a` < 5) +drop view v1; +drop table t1,t2,t3; # ----------------------------------------------------------------- # -- End of 5.5 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/table_elim.test b/mysql-test/t/table_elim.test index 24f48206013..717aecb42e2 100644 --- a/mysql-test/t/table_elim.test +++ b/mysql-test/t/table_elim.test @@ -534,12 +534,12 @@ INSERT IGNORE INTO t1 VALUES (0,'g'); CREATE TABLE t3 ( a varchar(1)) ; INSERT IGNORE INTO t3 VALUES ('g'); -CREATE TABLE t2 ( a int(11) NOT NULL, PRIMARY KEY (a)) ; +CREATE TABLE t2 ( a int(11) NOT NULL, PRIMARY KEY (a)); +INSERT INTO t2 VALUES (9), (10); create view v1 as SELECT t1.* FROM t1 LEFT JOIN t2 ON ( t1.a = t2.a ) WHERE t2.a <> 0; SELECT alias1.* FROM t3 LEFT JOIN v1 as alias1 ON ( t3.a = alias1.b ); EXPLAIN SELECT alias1.* FROM t3 LEFT JOIN v1 as alias1 ON ( t3.a = alias1.b ); - drop view v1; DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index ebd68587a47..aece2000cd4 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5505,6 +5505,66 @@ SHOW CREATE VIEW v1; drop view v1; drop table t1,t2; + +--echo # +--echo # MDEV-12099: usage of mergeable view with LEFT JOIN +--echo # that can be converted to INNER JOIN +--echo # + +create table t1 (a int, b int, key(a)) engine=myisam; +insert into t1 values + (3,20), (7,10), (2,10), (4,30), (8,70), + (7,70), (9,100), (9,60), (8,80), (7,60); + +create table t2 (c int, d int, key (c)) engine=myisam; +insert into t2 values + (50,100), (20, 200), (10,300), + (150,100), (120, 200), (110,300), + (250,100), (220, 200), (210,300); + +create table t3(e int, f int not null, key(e), unique (f)) engine=myisam; +insert into t3 values + (100, 3), (300, 5), (400, 4), (300,7), + (300,2), (600, 13), (800, 15), (700, 14), + (600, 23), (800, 25), (700, 24); + +create view v1 as + select * from t2 left join t3 on t3.e=t2.d where t3.f is not null; + +select * + from t1 left join v1 on v1.c=t1.b + where t1.a < 5; + +select * + from t1 left join ( t2 left join t3 on t3.e=t2.d ) + on t2.c=t1.b and t3.f is not null + where t1.a < 5; + +explain extended +select * + from t1 left join v1 on v1.c=t1.b + where t1.a < 5; + +explain extended +select * + from t1 left join ( t2 left join t3 on t3.e=t2.d ) + on t2.c=t1.b and t3.f is not null + where t1.a < 5; + +explain extended +select * + from t1 left join v1 on v1.c=t1.b and v1.f=t1.a + where t1.a < 5; + +explain extended +select * + from t1 left join ( t2 left join t3 on t3.e=t2.d ) + on t2.c=t1.b and t3.f=t1.a and t3.f is not null + where t1.a < 5; + +drop view v1; +drop table t1,t2,t3; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.5 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 44395599961..20fca2de8cf 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -446,6 +446,9 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) { Item *expr= derived->on_expr; expr= and_conds(expr, dt_select->join ? dt_select->join->conds : 0); + if (expr) + expr->top_level_item(); + if (expr && (derived->prep_on_expr || expr != derived->on_expr)) { derived->on_expr= expr;