From 0af84363b1ab5ca6fced83c8dc24de6251cced3e Mon Sep 17 00:00:00 2001 From: Joerg Bruehe Date: Mon, 16 Apr 2012 12:36:21 +0200 Subject: Raise version number after cloning for the 5.5.24 build. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0f96ceb238d..6111f6d453f 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=24 +MYSQL_VERSION_PATCH=25 MYSQL_VERSION_EXTRA= -- cgit v1.2.1 From b61d6be9fdfa61b7ae8e8436cf1748fc126ec15f Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Tue, 17 Apr 2012 13:25:41 +0300 Subject: Raise version number after cloning 5.1.63 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index ccc2ac26570..84295a15f4a 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ dnl dnl When changing the major version number please also check the switch dnl statement in mysqlbinlog::check_master_version(). You may also need dnl to update version.c in ndb. -AC_INIT([MySQL Server], [5.1.63], [], [mysql]) +AC_INIT([MySQL Server], [5.1.64], [], [mysql]) AC_CONFIG_SRCDIR([sql/mysqld.cc]) AC_CANONICAL_SYSTEM -- cgit v1.2.1 From fe0400694171f0def529e35a77db128b835f5626 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Tue, 17 Apr 2012 16:54:02 +0530 Subject: Bug #12902967 CREATING SELF REFERENCING FK ON SAME INDEX UNHANDLED, CONFUSING ERROR The main confusion with the error message is that "it implies that your data dictionary may now be out of sync". This patch will remove the unwanted and the misleading error message by not doing an unnecessary operation in the error handling code. rb://980 approved by: Dmitry Lenev --- .../suite/innodb/r/innodb_bug12902967.result | 6 +++ mysql-test/suite/innodb/t/innodb_bug12902967.test | 42 +++++++++++++++++ sql/sql_table.cc | 53 ++++++++++++++++++---- 3 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 mysql-test/suite/innodb/r/innodb_bug12902967.result create mode 100644 mysql-test/suite/innodb/t/innodb_bug12902967.test diff --git a/mysql-test/suite/innodb/r/innodb_bug12902967.result b/mysql-test/suite/innodb/r/innodb_bug12902967.result new file mode 100644 index 00000000000..b20710f08fb --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb_bug12902967.result @@ -0,0 +1,6 @@ +create table t1 (f1 integer primary key) engine innodb; +alter table t1 add constraint c1 foreign key (f1) references t1(f1); +ERROR HY000: Error on rename of '#sql-temporary' to './test/t1' (errno: 150) +InnoDB: which are not compatible with the new table definition. +InnoDB: has or is referenced in foreign key constraints +drop table t1; diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test new file mode 100644 index 00000000000..87e648c2726 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test @@ -0,0 +1,42 @@ +# Bug 12902967: Creating self referencing fk on same index unhandled, +# confusing error +# +# Creating a self referencing foreign key on the same +# column/index is an unhandled exception, it should throw a sensible +# error but instead implies that your data dictionary may now be out +# of sync: + +--source include/have_innodb.inc + +let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err; +--remove_file $error_log +--source include/restart_mysqld.inc + +create table t1 (f1 integer primary key) engine innodb; + +# The below statement should produce error message in error log. +# This error message should mention problem with foreign keys +# rather than with data dictionary. +--replace_regex /'\.\/test\/#sql-[0-9a-f_]*'/'#sql-temporary'/ +--error ER_ERROR_ON_RENAME +alter table t1 add constraint c1 foreign key (f1) references t1(f1); + +perl; + +$file = "$ENV{'error_log'}"; +open ( FILE, $file) || die "can't open file! ($file)\n"; +@lines = ; +close (FILE); +$count = 0; +foreach $line (reverse @lines) { + if ($line =~ "^InnoDB:") { + ++$count; + print "$line"; + if ($count == 2) { + break; + } + } +} +EOF + +drop table t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0f4bac47cab..c146079fdb3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -246,10 +246,17 @@ uint explain_filename(THD* thd, { part_name_len= tmp_p - part_name - 1; subpart_name= tmp_p + 3; + tmp_p+= 3; + } + else if ((tmp_p[1] == 'Q' || tmp_p[1] == 'q') && + (tmp_p[2] == 'L' || tmp_p[2] == 'l') && + tmp_p[3] == '-') + { + name_type= TEMP; + tmp_p+= 4; /* sql- prefix found */ } else res= 2; - tmp_p+= 3; break; case 'T': case 't': @@ -6718,21 +6725,47 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP); } else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db, - new_alias, FN_FROM_IS_TMP) || - ((new_name != table_name || new_db != db) && // we also do rename - (need_copy_table != ALTER_TABLE_METADATA_ONLY || - mysql_rename_table(save_old_db_type, db, table_name, new_db, - new_alias, NO_FRM_RENAME)) && - Table_triggers_list::change_table_name(thd, db, alias, table_name, - new_db, new_alias))) + new_alias, FN_FROM_IS_TMP)) { /* Try to get everything back. */ - error=1; - (void) quick_rm_table(new_db_type,new_db,new_alias, 0); + error= 1; (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP); (void) mysql_rename_table(old_db_type, db, old_name, db, alias, FN_FROM_IS_TMP); } + else if (new_name != table_name || new_db != db) + { + if (need_copy_table == ALTER_TABLE_METADATA_ONLY && + mysql_rename_table(save_old_db_type, db, table_name, new_db, + new_alias, NO_FRM_RENAME)) + { + /* Try to get everything back. */ + error= 1; + (void) quick_rm_table(new_db_type, new_db, new_alias, 0); + (void) mysql_rename_table(old_db_type, db, old_name, db, alias, + FN_FROM_IS_TMP); + } + else if (Table_triggers_list::change_table_name(thd, db, alias, + table_name, new_db, + new_alias)) + { + /* Try to get everything back. */ + error= 1; + (void) quick_rm_table(new_db_type, new_db, new_alias, 0); + (void) mysql_rename_table(old_db_type, db, old_name, db, + alias, FN_FROM_IS_TMP); + /* + If we were performing "fast"/in-place ALTER TABLE we also need + to restore old name of table in storage engine as a separate + step, as the above rename affects .FRM only. + */ + if (need_copy_table == ALTER_TABLE_METADATA_ONLY) + { + (void) mysql_rename_table(save_old_db_type, new_db, new_alias, + db, table_name, NO_FRM_RENAME); + } + } + } if (! error) (void) quick_rm_table(old_db_type, db, old_name, FN_IS_TMP); -- cgit v1.2.1 From 75ff20a2b4311e9235fba71544c256481fe7f24b Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 18 Apr 2012 09:21:23 +0530 Subject: Bug #12902967 Creating self referencing fk on same index unhandled, confusing error. I have added the not_embedded.inc in the test file. --- mysql-test/suite/innodb/t/innodb_bug12902967.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test index 87e648c2726..9101c8c705b 100644 --- a/mysql-test/suite/innodb/t/innodb_bug12902967.test +++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test @@ -7,6 +7,7 @@ # of sync: --source include/have_innodb.inc +--source include/not_embedded.inc let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err; --remove_file $error_log -- cgit v1.2.1 From 25f82f8a261963f633ccfdabce27dfc1e0309286 Mon Sep 17 00:00:00 2001 From: Chaithra Gopalareddy Date: Wed, 18 Apr 2012 11:25:01 +0530 Subject: Bug#12713907:STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY COUNT(*) LIMIT. PROBLEM: With respect to problem in the bug description, we exhibit different behaviors for the two tables presented, because innodb statistics (rec_per_key in this case) are updated for the first table and not so for the second one. As a result the query plan gets changed in test_if_skip_sort_order to use 'index' scan. Hence the difference in the explain output. (NOTE: We can reproduce the problem with first table by reducing the number of tuples and changing the table structure) The varied output w.r.t the query on the second table is because of the result in the query plan change. When a query plan is changed to use 'index' scan, after the call to test_if_skip_sort_order, we set keyread to TRUE immedietly. If for some reason we drop this index scan for a filesort later on, we fetch only the keys not the entire tuple. As a result we would see junk values in the result set. Following is the code flow: Call test_if_skip_sort_order -Choose an index to give sorted output -If this is a covering index, set_keyread to TRUE -Set the scan to INDEX scan Call test_if_skip_sort_order second time -Index is not chosen (note that we do not pass the actual limit value second time. Hence we do not choose index scan second time which in itself is a bug fixed in 5.6 with WL#5558) -goto filesort Call filesort -Create quick range on a different index -Since keyread is set to TRUE, we fetch only the columns of the index -results in the required columns are not fetched FIX: Remove the call to set_keyread(TRUE) from test_if_skip_sort_order. The access function which is 'join_read_first' or 'join_read_last' calls set_keyread anyways. mysql-test/r/func_group_innodb.result: Added test result for Bug#12713907 mysql-test/t/func_group_innodb.test: Added test case for Bug#12713907 sql/sql_select.cc: Remove the call to set_keyread as we do it from access functions 'join_read_first' and 'join_read_last' --- mysql-test/r/func_group_innodb.result | 40 +++++++++++++++++++++++++++++++ mysql-test/t/func_group_innodb.test | 44 +++++++++++++++++++++++++++++++++++ sql/sql_select.cc | 2 -- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_group_innodb.result b/mysql-test/r/func_group_innodb.result index 908e85c1652..e68242a8191 100644 --- a/mysql-test/r/func_group_innodb.result +++ b/mysql-test/r/func_group_innodb.result @@ -145,3 +145,43 @@ select count(*), min(7), max(7) from t2m, t1i; count(*) min(7) max(7) 0 NULL NULL drop table t1m, t1i, t2m, t2i; +# +# Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY +# COUNT(*) LIMIT. +# +CREATE TABLE t1 ( +id BIGINT(20) , +member_id_to INT(11) , +r_date DATE , +PRIMARY KEY (id,r_date), +KEY r_date_idx (r_date), +KEY t1_idx01 (member_id_to) +) ENGINE=InnoDB; +INSERT INTO t1 VALUES +(107924526,518491,'2011-05-01'), +(107924527,518491,'2011-05-01'), +(107924528,518491,'2011-05-01'), +(107924529,518491,'2011-05-01'), +(107924530,518491,'2011-05-01'), +(107924531,518491,'2011-05-01'), +(107924532,518491,'2011-05-01'), +(107924534,518491,'2011-06-21'), +(107924535,518491,'2011-06-21'), +(107924536,518491,'2011-06-21'), +(107924537,518491,'2011-06-21'), +(107924538,518491,'2011-06-21'), +(107924542,1601319,'2011-06-21'), +(107924543,1601319,'2011-06-21'), +(107924544,1601319,'2011-06-21'), +(107924545,1601319,'2011-06-21'), +(107924546,1601319,'2011-06-21'), +(107924547,1601319,'2011-06-21'), +(107924548,1601319,'2011-06-21'), +(107924549,1601319,'2011-06-21'), +(107924550,1601319,'2011-06-21'); +SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date = +'2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1; +member_id_to COUNT(*) +518491 5 +DROP TABLE t1; +# End of test BUG#12713907 diff --git a/mysql-test/t/func_group_innodb.test b/mysql-test/t/func_group_innodb.test index 1bdfd8f54bb..58f365bb244 100644 --- a/mysql-test/t/func_group_innodb.test +++ b/mysql-test/t/func_group_innodb.test @@ -83,3 +83,47 @@ explain select count(*), min(7), max(7) from t2m, t1i; select count(*), min(7), max(7) from t2m, t1i; drop table t1m, t1i, t2m, t2i; + +--echo # +--echo # Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY +--echo # COUNT(*) LIMIT. +--echo # + +CREATE TABLE t1 ( +id BIGINT(20) , +member_id_to INT(11) , +r_date DATE , +PRIMARY KEY (id,r_date), +KEY r_date_idx (r_date), +KEY t1_idx01 (member_id_to) +) ENGINE=InnoDB; + +INSERT INTO t1 VALUES +(107924526,518491,'2011-05-01'), +(107924527,518491,'2011-05-01'), +(107924528,518491,'2011-05-01'), +(107924529,518491,'2011-05-01'), +(107924530,518491,'2011-05-01'), +(107924531,518491,'2011-05-01'), +(107924532,518491,'2011-05-01'), +(107924534,518491,'2011-06-21'), +(107924535,518491,'2011-06-21'), +(107924536,518491,'2011-06-21'), +(107924537,518491,'2011-06-21'), +(107924538,518491,'2011-06-21'), +(107924542,1601319,'2011-06-21'), +(107924543,1601319,'2011-06-21'), +(107924544,1601319,'2011-06-21'), +(107924545,1601319,'2011-06-21'), +(107924546,1601319,'2011-06-21'), +(107924547,1601319,'2011-06-21'), +(107924548,1601319,'2011-06-21'), +(107924549,1601319,'2011-06-21'), +(107924550,1601319,'2011-06-21'); + +SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date = + '2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1; + +DROP TABLE t1; + +--echo # End of test BUG#12713907 diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5f1efabfc97..1c5f4f5a648 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13820,8 +13820,6 @@ check_reverse_order: join_read_first:join_read_last; tab->type=JT_NEXT; // Read with index_first(), index_next() - if (table->covering_keys.is_set(best_key)) - table->set_keyread(TRUE); table->file->ha_index_or_rnd_end(); if (tab->join->select_options & SELECT_DESCRIBE) { -- cgit v1.2.1 From 448c3d627542c835ac7ea1851e8e019596e377fd Mon Sep 17 00:00:00 2001 From: Nuno Carvalho Date: Wed, 18 Apr 2012 10:08:01 +0100 Subject: WL#6236: Allow SHOW MASTER LOGS and SHOW BINARY LOGS with REPLICATION CLIENT Currently SHOW MASTER LOGS and SHOW BINARY LOGS require the SUPER privilege. Monitoring tools (such as MEM) often want to check this output - for instance MEM generates the SUM of the sizes of the logs reported here, and puts that in the Replication overview within the MEM Dashboard. However, because of the SUPER requirement, these tools often have an account that holds open the connection whilst monitoring, and can lock out administrators when the server gets overloaded and reaches max_connections - there is already another SUPER privileged account connected, the "monitor". As SHOW MASTER STATUS, and all other replication related statements, return with either REPLICATION CLIENT or SUPER privileges, this worklog is to make SHOW MASTER LOGS and SHOW BINARY LOGS be consistent with this as well, and allow both of these commands with either SUPER or REPLICATION CLIENT. This allows monitoring tools to not require a SUPER privilege any more, so is safer in overloaded situations, as well as being more secure, as lighter privileges can be given to users of such tools or scripts. --- mysql-test/suite/binlog/r/binlog_grant.result | 4 ++++ mysql-test/suite/binlog/t/binlog_grant.test | 19 +++++++++++++++++++ sql/sql_parse.cc | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/binlog/r/binlog_grant.result b/mysql-test/suite/binlog/r/binlog_grant.result index 21ebb891103..38442349d3b 100644 --- a/mysql-test/suite/binlog/r/binlog_grant.result +++ b/mysql-test/suite/binlog/r/binlog_grant.result @@ -26,3 +26,7 @@ ERROR 42000: Access denied; you need the SUPER privilege for this operation **** Clean up **** set global binlog_format = @saved_binlog_format; drop user mysqltest_1@localhost; +GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost'; +SHOW MASTER LOGS; +SHOW BINARY LOGS; +DROP USER 'mysqltest_1'@'localhost'; diff --git a/mysql-test/suite/binlog/t/binlog_grant.test b/mysql-test/suite/binlog/t/binlog_grant.test index d36dcce4cc3..bbf57b075af 100644 --- a/mysql-test/suite/binlog/t/binlog_grant.test +++ b/mysql-test/suite/binlog/t/binlog_grant.test @@ -58,3 +58,22 @@ disconnect root; connection default; set global binlog_format = @saved_binlog_format; drop user mysqltest_1@localhost; + + +# Testing if REPLICATION CLIENT privilege is enough to execute +# SHOW MASTER LOGS and SHOW BINARY. +GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost'; +--connect(rpl,localhost,mysqltest_1,,) + +--connection rpl +# We are only interested if the following commands succeed and not on +# their output. +--disable_result_log +SHOW MASTER LOGS; +SHOW BINARY LOGS; +--enable_result_log + +# clean up +--disconnect rpl +connection default; +DROP USER 'mysqltest_1'@'localhost'; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 0f190809ab9..14b778328d2 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3057,7 +3057,7 @@ end_with_restore_list: goto error; #else { - if (check_global_access(thd, SUPER_ACL)) + if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL)) goto error; res = show_binlogs(thd); break; -- cgit v1.2.1 From b73da023bfc173b404f5298d6b8b36cc8cfc493d Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 18 Apr 2012 15:16:11 +0530 Subject: Bug #12902967 Creating self referencing fk on same index unhandled, confusing error. Updated the test script to work properly on windows platform. --- mysql-test/suite/innodb/t/innodb_bug12902967.test | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test index 9101c8c705b..7bc5727a7a6 100644 --- a/mysql-test/suite/innodb/t/innodb_bug12902967.test +++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test @@ -10,7 +10,6 @@ --source include/not_embedded.inc let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err; ---remove_file $error_log --source include/restart_mysqld.inc create table t1 (f1 integer primary key) engine innodb; @@ -21,7 +20,7 @@ create table t1 (f1 integer primary key) engine innodb; --replace_regex /'\.\/test\/#sql-[0-9a-f_]*'/'#sql-temporary'/ --error ER_ERROR_ON_RENAME alter table t1 add constraint c1 foreign key (f1) references t1(f1); - +--source include/restart_mysqld.inc perl; $file = "$ENV{'error_log'}"; -- cgit v1.2.1 From 11b2cf4f03b7c4b84c26d3c95cdf6f8fa6322349 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 18 Apr 2012 13:14:05 +0200 Subject: Backport 5.5=>5.1 Patch for Bug#13805127: Stored program cache produces wrong result in same THD. --- mysql-test/r/ps.result | 103 +++++++++++++++++++++++++++++ mysql-test/r/sp.result | 38 +++++++++++ mysql-test/t/ps.test | 90 +++++++++++++++++++++++++ mysql-test/t/sp.test | 37 +++++++++++ sql/mem_root_array.h | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ sql/sql_lex.cc | 22 +++++++ sql/sql_lex.h | 16 ++++- sql/sql_prepare.cc | 8 +++ 8 files changed, 487 insertions(+), 2 deletions(-) create mode 100644 sql/mem_root_array.h diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 84c64a3905a..60370e4b708 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -3040,3 +3040,106 @@ id select_type table type possible_keys key key_len ref rows Extra DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. + +# Bug#13805127: Stored program cache produces wrong result in same THD + +PREPARE s1 FROM +" +SELECT c1, t2.c2, count(c3) +FROM + ( + SELECT 3 as c2 FROM dual WHERE @x = 1 + UNION + SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2 +"; + +SET @x = 1; +SELECT c1, t2.c2, count(c3) +FROM +( +SELECT 3 as c2 FROM dual WHERE @x = 1 +UNION +SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 +) AS t1, +( +SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual +UNION +SELECT '2012-03-01 02:00:00', 3, 2 FROM dual +UNION +SELECT '2012-03-01 01:00:00', 2, 1 FROM dual +) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 + +EXECUTE s1; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 + +SET @x = 2; +SELECT c1, t2.c2, count(c3) +FROM +( +SELECT 3 as c2 FROM dual WHERE @x = 1 +UNION +SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 +) AS t1, +( +SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual +UNION +SELECT '2012-03-01 02:00:00', 3, 2 FROM dual +UNION +SELECT '2012-03-01 01:00:00', 2, 1 FROM dual +) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 + +EXECUTE s1; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 + +SET @x = 1; +SELECT c1, t2.c2, count(c3) +FROM +( +SELECT 3 as c2 FROM dual WHERE @x = 1 +UNION +SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 +) AS t1, +( +SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual +UNION +SELECT '2012-03-01 02:00:00', 3, 2 FROM dual +UNION +SELECT '2012-03-01 01:00:00', 2, 1 FROM dual +) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 + +EXECUTE s1; +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 +DEALLOCATE PREPARE s1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 11d6ff02756..0d0d76e609b 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -7110,3 +7110,41 @@ DROP FUNCTION f1; # ------------------------------------------------------------------ # -- End of 5.1 tests # ------------------------------------------------------------------ + +# Bug#13805127: Stored program cache produces wrong result in same THD + +CREATE PROCEDURE p1(x INT UNSIGNED) +BEGIN +SELECT c1, t2.c2, count(c3) +FROM +( +SELECT 3 as c2 FROM dual WHERE x = 1 +UNION +SELECT 2 FROM dual WHERE x = 1 OR x = 2 +) AS t1, +( +SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual +UNION +SELECT '2012-03-01 02:00:00', 3, 2 FROM dual +UNION +SELECT '2012-03-01 01:00:00', 2, 1 FROM dual +) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2 +; +END| + +CALL p1(1); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 +CALL p1(2); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +CALL p1(1); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 +DROP PROCEDURE p1; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 9b3f3e750e1..88bfe1dd2be 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3102,3 +3102,93 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1; --echo End of 5.1 tests. + +--echo +--echo # Bug#13805127: Stored program cache produces wrong result in same THD +--echo + +PREPARE s1 FROM +" +SELECT c1, t2.c2, count(c3) +FROM + ( + SELECT 3 as c2 FROM dual WHERE @x = 1 + UNION + SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2 +"; + +--echo +SET @x = 1; +SELECT c1, t2.c2, count(c3) +FROM + ( + SELECT 3 as c2 FROM dual WHERE @x = 1 + UNION + SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +--echo +EXECUTE s1; + +--echo +SET @x = 2; +SELECT c1, t2.c2, count(c3) +FROM + ( + SELECT 3 as c2 FROM dual WHERE @x = 1 + UNION + SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +--echo +EXECUTE s1; + +--echo +SET @x = 1; +SELECT c1, t2.c2, count(c3) +FROM + ( + SELECT 3 as c2 FROM dual WHERE @x = 1 + UNION + SELECT 2 FROM dual WHERE @x = 1 OR @x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, c2; +--echo +EXECUTE s1; + +DEALLOCATE PREPARE s1; + diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index ae4e1dd588e..75d290f7c8b 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -8429,3 +8429,40 @@ DROP FUNCTION f1; --echo # ------------------------------------------------------------------ --echo # -- End of 5.1 tests --echo # ------------------------------------------------------------------ + +--echo +--echo # Bug#13805127: Stored program cache produces wrong result in same THD +--echo + +delimiter |; + +CREATE PROCEDURE p1(x INT UNSIGNED) +BEGIN + SELECT c1, t2.c2, count(c3) + FROM + ( + SELECT 3 as c2 FROM dual WHERE x = 1 + UNION + SELECT 2 FROM dual WHERE x = 1 OR x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 + WHERE t2.c2 = t1.c2 + GROUP BY c1, c2 + ; +END| + +delimiter ;| + +--echo +CALL p1(1); +CALL p1(2); +CALL p1(1); + +DROP PROCEDURE p1; + diff --git a/sql/mem_root_array.h b/sql/mem_root_array.h new file mode 100644 index 00000000000..5ce4dcb584d --- /dev/null +++ b/sql/mem_root_array.h @@ -0,0 +1,175 @@ +/* Copyright (c) 2011, Oracle and/or its affiliates. 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 Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#ifndef MEM_ROOT_ARRAY_INCLUDED +#define MEM_ROOT_ARRAY_INCLUDED + +#include + +/** + A typesafe replacement for DYNAMIC_ARRAY. + We use MEM_ROOT for allocating storage, rather than the C++ heap. + The interface is chosen to be similar to std::vector. + + @remark + Unlike DYNAMIC_ARRAY, elements are properly copied + (rather than memcpy()d) if the underlying array needs to be expanded. + + @remark + Depending on has_trivial_destructor, we destroy objects which are + removed from the array (including when the array object itself is destroyed). + + @remark + Note that MEM_ROOT has no facility for reusing free space, + so don't use this if multiple re-expansions are likely to happen. + + @param Element_type The type of the elements of the container. + Elements must be copyable. + @param has_trivial_destructor If true, we don't destroy elements. + We could have used type traits to determine this. + __has_trivial_destructor is supported by some (but not all) + compilers we use. +*/ +template +class Mem_root_array +{ +public: + Mem_root_array(MEM_ROOT *root) + : m_root(root), m_array(NULL), m_size(0), m_capacity(0) + { + DBUG_ASSERT(m_root != NULL); + } + + ~Mem_root_array() + { + clear(); + } + + Element_type &at(size_t n) + { + DBUG_ASSERT(n < size()); + return m_array[n]; + } + + const Element_type &at(size_t n) const + { + DBUG_ASSERT(n < size()); + return m_array[n]; + } + + // Returns a pointer to the first element in the array. + Element_type *begin() { return &m_array[0]; } + + // Returns a pointer to the past-the-end element in the array. + Element_type *end() { return &m_array[size()]; } + + // Erases all of the elements. + void clear() + { + if (!empty()) + chop(0); + } + + /* + Chops the tail off the array, erasing all tail elements. + @param pos Index of first element to erase. + */ + void chop(const size_t pos) + { + DBUG_ASSERT(pos < m_size); + if (!has_trivial_destructor) + { + for (size_t ix= pos; ix < m_size; ++ix) + { + Element_type *p= &m_array[ix]; + p->~Element_type(); // Destroy discarded element. + } + } + m_size= pos; + } + + /* + Reserves space for array elements. + Copies over existing elements, in case we are re-expanding the array. + + @param n number of elements. + @retval true if out-of-memory, false otherwise. + */ + bool reserve(size_t n) + { + if (n <= m_capacity) + return false; + + void *mem= alloc_root(m_root, n * element_size()); + if (!mem) + return true; + Element_type *array= static_cast(mem); + + // Copy all the existing elements into the new array. + for (size_t ix= 0; ix < m_size; ++ix) + { + Element_type *new_p= &array[ix]; + Element_type *old_p= &m_array[ix]; + new (new_p) Element_type(*old_p); // Copy into new location. + if (!has_trivial_destructor) + old_p->~Element_type(); // Destroy the old element. + } + + // Forget the old array. + m_array= array; + m_capacity= n; + return false; + } + + /* + Adds a new element at the end of the array, after its current last + element. The content of this new element is initialized to a copy of + the input argument. + + @param element Object to copy. + @retval true if out-of-memory, false otherwise. + */ + bool push_back(const Element_type &element) + { + const size_t min_capacity= 20; + const size_t expansion_factor= 2; + if (0 == m_capacity && reserve(min_capacity)) + return true; + if (m_size == m_capacity && reserve(m_capacity * expansion_factor)) + return true; + Element_type *p= &m_array[m_size++]; + new (p) Element_type(element); + return false; + } + + size_t capacity() const { return m_capacity; } + size_t element_size() const { return sizeof(Element_type); } + bool empty() const { return size() == 0; } + size_t size() const { return m_size; } + +private: + MEM_ROOT *const m_root; + Element_type *m_array; + size_t m_size; + size_t m_capacity; + + // Not (yet) implemented. + Mem_root_array(const Mem_root_array&); + Mem_root_array &operator=(const Mem_root_array&); +}; + + +#endif // MEM_ROOT_ARRAY_INCLUDED diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 4a0553ad59b..fd9367b99f2 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -305,6 +305,8 @@ void lex_start(THD *thd) lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED; lex->select_lex.init_order(); lex->select_lex.group_list.empty(); + if (lex->select_lex.group_list_ptrs) + lex->select_lex.group_list_ptrs->clear(); lex->describe= 0; lex->subqueries= FALSE; lex->context_analysis_only= 0; @@ -1632,6 +1634,8 @@ void st_select_lex::init_select() { st_select_lex_node::init_select(); group_list.empty(); + if (group_list_ptrs) + group_list_ptrs->clear(); type= db= 0; having= 0; table_join_options= 0; @@ -2901,6 +2905,8 @@ static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl) The passed WHERE and HAVING are to be saved for the future executions. This function saves it, and returns a copy which can be thrashed during this execution of the statement. By saving/thrashing here we mean only + We also save the chain of ORDER::next in group_list, in case + the list is modified by remove_const(). AND/OR trees. The function also calls fix_prepare_info_in_table_list that saves all ON expressions. @@ -2912,6 +2918,19 @@ void st_select_lex::fix_prepare_information(THD *thd, Item **conds, if (!thd->stmt_arena->is_conventional() && first_execution) { first_execution= 0; + if (group_list.first) + { + if (!group_list_ptrs) + { + void *mem= thd->stmt_arena->alloc(sizeof(Group_list_ptrs)); + group_list_ptrs= new (mem) Group_list_ptrs(thd->stmt_arena->mem_root); + } + group_list_ptrs->reserve(group_list.elements); + for (ORDER *order= group_list.first; order; order= order->next) + { + group_list_ptrs->push_back(order); + } + } if (*conds) { prep_where= *conds; @@ -3016,3 +3035,6 @@ bool st_lex::is_partition_management() const alter_info.flags == ALTER_REORGANIZE_PARTITION)); } +#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION +template class Mem_root_array; +#endif diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 035fa1fde91..d512190eecc 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -40,6 +40,7 @@ class Event_parse_data; */ #include "set_var.h" +#include "mem_root_array.h" #ifdef MYSQL_YACC #define LEX_YYSTYPE void * @@ -183,6 +184,7 @@ enum enum_drop_mode }; typedef List List_item; +typedef Mem_root_array Group_list_ptrs; /* SERVERS CACHE CHANGES */ typedef struct st_lex_server_options @@ -590,7 +592,16 @@ public: enum olap_type olap; /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */ SQL_I_List table_list; - SQL_I_List group_list; /* GROUP BY clause. */ + + /* + GROUP BY clause. + This list may be mutated during optimization (by remove_const()), + so for prepared statements, we keep a copy of the ORDER.next pointers in + group_list_ptrs, and re-establish the original list before each execution. + */ + SQL_I_List group_list; + Group_list_ptrs *group_list_ptrs; + List item_list; /* list of fields & expressions */ List interval_list; bool is_item_list_lookup; @@ -779,7 +790,8 @@ public: bool test_limit(); friend void lex_start(THD *thd); - st_select_lex() : n_sum_items(0), n_child_sum_items(0) {} + st_select_lex() : group_list_ptrs(NULL), n_sum_items(0), n_child_sum_items(0) + {} void make_empty_select() { init_query(); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 98379dba9ba..27e70aaf843 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2361,6 +2361,14 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) DBUG_ASSERT(sl->join == 0); ORDER *order; /* Fix GROUP list */ + if (sl->group_list_ptrs && sl->group_list_ptrs->size() > 0) + { + for (uint ix= 0; ix < sl->group_list_ptrs->size() - 1; ++ix) + { + order= sl->group_list_ptrs->at(ix); + order->next= sl->group_list_ptrs->at(ix+1); + } + } for (order= sl->group_list.first; order; order= order->next) order->item= &order->item_ptr; /* Fix ORDER list */ -- cgit v1.2.1 From 892106db9219f2714a65bd0d07da262c5aaa8fca Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 18 Apr 2012 14:13:13 +0200 Subject: new header file must be listed in Makefile.am --- sql/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/Makefile.am b/sql/Makefile.am index f8ba25377cd..2336faf4e31 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -71,6 +71,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ tztime.h my_decimal.h\ sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \ parse_file.h sql_view.h sql_trigger.h \ + mem_root_array.h \ sql_array.h sql_cursor.h events.h scheduler.h \ event_db_repository.h event_queue.h \ sql_plugin.h authors.h event_parse_data.h \ -- cgit v1.2.1 From bf4161adae1a0b103d5424f2fe3ec8c167311997 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Thu, 19 Apr 2012 14:57:34 +0530 Subject: BUG#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE Reason: This is a regression happened because of changes done in code refactoring in 5.1 from 5.0. Issue: While doing "Show tables" lex->verbose was being checked to avoid opening FRM files to get table type. In case of "Show full table", lex->verbose is true to indicate table type is required. In 5.0, this check was present which got missing in >=5.5. Fix: Added the required check to avoid opening FRM files unnecessarily in case of "Show tables". --- sql/sql_show.cc | 64 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index ab3217dbe48..1b0f94ce18e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3198,39 +3198,44 @@ end: static int fill_schema_table_names(THD *thd, TABLE *table, LEX_STRING *db_name, LEX_STRING *table_name, - bool with_i_schema) + bool with_i_schema, + bool need_table_type) { - if (with_i_schema) + /* Avoid opening FRM files if table type is not needed. */ + if (need_table_type) { - table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), - system_charset_info); - } - else - { - enum legacy_db_type not_used; - char path[FN_REFLEN + 1]; - (void) build_table_filename(path, sizeof(path) - 1, db_name->str, - table_name->str, reg_ext, 0); - switch (mysql_frm_type(thd, path, ¬_used)) { - case FRMTYPE_ERROR: - table->field[3]->store(STRING_WITH_LEN("ERROR"), - system_charset_info); - break; - case FRMTYPE_TABLE: - table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), - system_charset_info); - break; - case FRMTYPE_VIEW: - table->field[3]->store(STRING_WITH_LEN("VIEW"), + if (with_i_schema) + { + table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), system_charset_info); - break; - default: - DBUG_ASSERT(0); } - if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE) + else { - thd->clear_error(); - return 0; + enum legacy_db_type not_used; + char path[FN_REFLEN + 1]; + (void) build_table_filename(path, sizeof(path) - 1, db_name->str, + table_name->str, reg_ext, 0); + switch (mysql_frm_type(thd, path, ¬_used)) { + case FRMTYPE_ERROR: + table->field[3]->store(STRING_WITH_LEN("ERROR"), + system_charset_info); + break; + case FRMTYPE_TABLE: + table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), + system_charset_info); + break; + case FRMTYPE_VIEW: + table->field[3]->store(STRING_WITH_LEN("VIEW"), + system_charset_info); + break; + default: + DBUG_ASSERT(0); + } + if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE) + { + thd->clear_error(); + return 0; + } } } if (schema_table_store_record(thd, table)) @@ -3551,7 +3556,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) if (schema_table_idx == SCH_TABLE_NAMES) { if (fill_schema_table_names(thd, tables->table, db_name, - table_name, with_i_schema)) + table_name, with_i_schema, + lex->verbose)) continue; } else -- cgit v1.2.1 From 49e484c8cd2e362e843bbd5d756422cc7e2686d3 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Fri, 20 Apr 2012 19:41:20 +0300 Subject: BUG#11754117 incorrect logging of INSERT into auto-increment BUG#11761686 insert_id event is not filtered. Two issues are covered. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe by autoincrement logging design. The case is specific to MyISAM engine because Innodb does not allow such table definition. However no warnings and row-format logging in the MIXED mode was done, and that is fixed. Int-, Rand-, User-var log-events were not filtered along with their parent query that made possible them to screw up execution context of the following query. Fixed with deferring their execution until the parent query. ****** Bug#11754117 Post review fixes. mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result: a new result file is added. mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result: results updated. mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test: regression test for BUG#11754117-45670 is added. mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test: regression test for filtering issue of BUG#11754117 - 45670 is added. sql/log_event.cc: Logics are added for deferring and executing events associated with the Query event. sql/log_event.h: Interface to deferred events batch execution is added. sql/rpl_rli.cc: initialization for new RLI members is added. sql/rpl_rli.h: New members to RLI are added to facilitate deferred events gathering and execution control; two general character RLI cleanup methods are constructed. sql/rpl_utility.cc: Deferred_log_events methods are difined. sql/rpl_utility.h: A new class Deferred_log_events is defined to implement IRU events gathering, execution and cleanup. sql/slave.cc: Necessary changes to initialize `rli->deferred_events' and prevent deferred event deletion in the main read-exec branch. sql/sql_base.cc: A new safe-check function for multi-part pk with auto-increment is defined and deployed in lock_tables(). sql/sql_class.cc: Initialization for a new member and replication cleanups are added to THD class. sql/sql_class.h: THD class receives a new member to hold a specific execution context for slave applier. sql/sql_parse.cc: Execution of the deferred event in started prior to its parent query. --- .../suite/rpl/r/rpl_auto_increment_bug45679.result | 36 +++++++++++++ .../suite/rpl/r/rpl_filter_tables_not_exist.result | 21 ++++++++ .../suite/rpl/t/rpl_auto_increment_bug45679.test | 62 ++++++++++++++++++++++ .../suite/rpl/t/rpl_filter_tables_not_exist.test | 60 +++++++++++++++++++++ sql/log_event.cc | 36 ++++++++++++- sql/log_event.h | 10 ++++ sql/rpl_rli.cc | 4 +- sql/rpl_rli.h | 35 ++++++++++++ sql/rpl_utility.cc | 61 +++++++++++++++++++++ sql/rpl_utility.h | 18 +++++++ sql/slave.cc | 9 +++- sql/sql_base.cc | 34 ++++++++++++ sql/sql_class.cc | 8 ++- sql/sql_class.h | 2 + sql/sql_parse.cc | 5 ++ 15 files changed, 397 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result create mode 100644 mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test diff --git a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result new file mode 100644 index 00000000000..75f4e661dc1 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result @@ -0,0 +1,36 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.'); +create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam; +create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb; +ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key +create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb; +set @@binlog_format=statement; +*** autoincrement field is not the first in PK warning must be there: *** +insert into tm set b=null, a=1; +Warnings: +Note 1592 Statement may not be safe to log in statement format. +show warnings; +Level Code Message +Note 1592 Statement may not be safe to log in statement format. +*** no warning when autoincrement is the first in PK +insert into ti set b=null, a=1; +show warnings; +Level Code Message +create function multi_part_pk_with_autoinc (arg int) +returns int +begin +insert into tm set b=null, a=arg; +return arg; +end// +select multi_part_pk_with_autoinc (3); +multi_part_pk_with_autoinc (3) +3 +*** autoincrement field is not the first in PK warning must be there: *** +show warnings; +Level Code Message +set @@binlog_format=mixed; +insert into tm set b=null, a=2; +drop table tm, ti; +drop function multi_part_pk_with_autoinc; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result index c88dcee9dbc..f0dc97b71f2 100644 --- a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result +++ b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result @@ -114,4 +114,25 @@ id c 3 3 [on master] drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +CREATE TABLE test.t1 (a INT); +INSERT INTO test.t1 VALUES(1); +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW +INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c); +SET INSERT_ID=2; +SET @c=2; +SET @@rand_seed1=10000000, @@rand_seed2=1000000; +INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); +Warnings: +Note 1592 Statement may not be safe to log in statement format. +SELECT b into @b FROM test.t5; +UPDATE test.t1 SET a=2; +SELECT a AS 'ONE' into @a FROM test.t_slave; +SELECT c AS 'NULL' into @c FROM test.t_slave; +SELECT b into @b FROM test.t_slave; +drop table test.t5; +drop table test.t1; +drop table test.t_slave; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test b/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test new file mode 100644 index 00000000000..6996e1c73c7 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test @@ -0,0 +1,62 @@ +# Test of auto-increment. +# +# BUG#11754117-45670 +# Multipart primary key with the autoincrement part not first in it +# is replication unsafe. +# + +source include/master-slave.inc; +source include/have_binlog_format_mixed.inc; +source include/have_innodb.inc; + +call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.'); + +--connection master +create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam; +--error ER_WRONG_AUTO_KEY +create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb; +create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb; + +set @@binlog_format=statement; +--echo *** autoincrement field is not the first in PK warning must be there: *** +insert into tm set b=null, a=1; +show warnings; +--echo *** no warning when autoincrement is the first in PK +insert into ti set b=null, a=1; +show warnings; + +delimiter //; +create function multi_part_pk_with_autoinc (arg int) +returns int +begin + insert into tm set b=null, a=arg; + return arg; +end// +delimiter ;// + +select multi_part_pk_with_autoinc (3); +--echo *** autoincrement field is not the first in PK warning must be there: *** +show warnings; + +set @@binlog_format=mixed; +insert into tm set b=null, a=2; + +sync_slave_with_master; + +if (`select count(*) <> 3 from tm`) +{ + --echo Wrong result from SELECT on the slave side. + select * from tm; + --die +} + +# cleanup + +--connection master + +drop table tm, ti; +drop function multi_part_pk_with_autoinc; + +sync_slave_with_master; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test b/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test index 13c66f9f64b..b62a6e96437 100644 --- a/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test +++ b/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test @@ -206,4 +206,64 @@ SELECT * FROM t3; connection master; echo [on master]; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; + +--sync_slave_with_master + +# +# BUG#11754117 - 45670: INTVAR_EVENTS FOR FILTERED-OUT QUERY_LOG_EVENTS ARE EXECUTED +# Int-, Rand- and User- var events accompaning a filtered out Query-log-event should +# be filtered as well. +# +connection master; +CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); # ignored on slave +CREATE TABLE test.t1 (a INT); # accepted on slave +INSERT INTO test.t1 VALUES(1); + +--sync_slave_with_master +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW + INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c); + +connection master; +SET INSERT_ID=2; +SET @c=2; +SET @@rand_seed1=10000000, @@rand_seed2=1000000; +INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); # to be ignored +SELECT b into @b FROM test.t5; +--let $b_master=`select @b` +UPDATE test.t1 SET a=2; # to run trigger on slave + +--sync_slave_with_master + +# The proof: +SELECT a AS 'ONE' into @a FROM test.t_slave; +SELECT c AS 'NULL' into @c FROM test.t_slave; + +let $count= 1; +let $table= test.t_slave; +source include/wait_until_rows_count.inc; + +if (`SELECT @a != 2 and @c != NULL`) +{ + SELECT * FROM test.t_slave; + --die Intvar or user var from replication events unexpetedly escaped out to screw a following query applying context. +} + +SELECT b into @b FROM test.t_slave; +--let $b_slave=`select @b` + +if (`SELECT $b_slave = $b_master`) +{ + --echo Might be pure coincidence of two randoms from master and slave table. Don not panic yet. +} + +# cleanup BUG#11754117 +connection master; +drop table test.t5; +drop table test.t1; + +--sync_slave_with_master +drop table test.t_slave; + --source include/rpl_end.inc diff --git a/sql/log_event.cc b/sql/log_event.cc index 427f27650dd..8606964113c 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -5257,11 +5257,12 @@ void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) #endif +#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT) + /* Intvar_log_event::do_apply_event() */ -#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT) int Intvar_log_event::do_apply_event(Relay_log_info const *rli) { /* @@ -5270,6 +5271,9 @@ int Intvar_log_event::do_apply_event(Relay_log_info const *rli) */ const_cast(rli)->set_flag(Relay_log_info::IN_STMT); + if (rli->deferred_events_collecting) + return rli->deferred_events->add(this); + switch (type) { case LAST_INSERT_ID_EVENT: thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1; @@ -5375,6 +5379,9 @@ int Rand_log_event::do_apply_event(Relay_log_info const *rli) */ const_cast(rli)->set_flag(Relay_log_info::IN_STMT); + if (rli->deferred_events_collecting) + return rli->deferred_events->add(this); + thd->rand.seed1= (ulong) seed1; thd->rand.seed2= (ulong) seed2; return 0; @@ -5401,6 +5408,29 @@ Rand_log_event::do_shall_skip(Relay_log_info *rli) return continue_group(rli); } +/** + Exec deferred Int-, Rand- and User- var events prefixing + a Query-log-event event. + + @param thd THD handle + + @return false on success, true if a failure in an event applying occurred. +*/ +bool slave_execute_deferred_events(THD *thd) +{ + bool res= false; + Relay_log_info *rli= thd->rli_slave; + + DBUG_ASSERT(rli && (!rli->deferred_events_collecting || rli->deferred_events)); + + if (!rli->deferred_events_collecting || rli->deferred_events->is_empty()) + return res; + + res= rli->deferred_events->execute(rli); + + return res; +} + #endif /* !MYSQL_CLIENT */ @@ -5785,6 +5815,10 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli) { Item *it= 0; CHARSET_INFO *charset; + + if (rli->deferred_events_collecting) + return rli->deferred_events->add(this); + if (!(charset= get_charset(charset_number, MYF(MY_WME)))) return 1; LEX_STRING user_var_name; diff --git a/sql/log_event.h b/sql/log_event.h index 7c707c29278..4c80148458c 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -3961,6 +3961,16 @@ static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); } +#ifndef MYSQL_CLIENT +/** + The function is called by slave applier in case there are + active table filtering rules to force gathering events associated + with Query-log-event into an array to execute + them once the fate of the Query is determined for execution. +*/ +bool slave_execute_deferred_events(THD *thd); +#endif + /** @} (end of group Replication) */ diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 6fe4cbd4ea6..904b5533f3b 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -45,7 +45,9 @@ Relay_log_info::Relay_log_info() inited(0), abort_slave(0), slave_running(0), until_condition(UNTIL_NONE), until_log_pos(0), retried_trans(0), tables_to_lock(0), tables_to_lock_count(0), - last_event_start_time(0), m_flags(0) + last_event_start_time(0), + deferred_events(NULL), + m_flags(0) { DBUG_ENTER("Relay_log_info::Relay_log_info"); diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index f49be72db46..959105b16e0 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -369,6 +369,41 @@ public: */ time_t last_event_start_time; + /* + A container to hold on Intvar-, Rand-, Uservar- log-events in case + the slave is configured with table filtering rules. + The withhold events are executed when their parent Query destiny is + determined for execution as well. + */ + Deferred_log_events *deferred_events; + + /* + State of the container: true stands for IRU events gathering, + false does for execution, either deferred or direct. + */ + bool deferred_events_collecting; + + /* + Returns true if the argument event resides in the containter; + more specifically, the checking is done against the last added event. + */ + bool is_deferred_event(Log_event * ev) + { + return deferred_events_collecting ? deferred_events->is_last(ev) : false; + }; + /* The general cleanup that slave applier may need at the end of query. */ + inline void cleanup_after_query() + { + if (deferred_events) + deferred_events->rewind(); + }; + /* The general cleanup that slave applier may need at the end of session. */ + void cleanup_after_session() + { + if (deferred_events) + delete deferred_events; + }; + /** Helper function to do after statement completion. diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index 46c93f7cd20..5f2b5cbf86b 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -226,3 +226,64 @@ table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table) return error; } + +#ifndef MYSQL_CLIENT +Deferred_log_events::Deferred_log_events(Relay_log_info *rli) : last_added(NULL) +{ + my_init_dynamic_array(&array, sizeof(Log_event *), 32, 16); +} + +Deferred_log_events::~Deferred_log_events() +{ + delete_dynamic(&array); +} + +int Deferred_log_events::add(Log_event *ev) +{ + last_added= ev; + insert_dynamic(&array, (uchar*) &ev); + return 0; +} + +bool Deferred_log_events::is_empty() +{ + return array.elements == 0; +} + +bool Deferred_log_events::execute(Relay_log_info *rli) +{ + bool res= false; + + DBUG_ASSERT(rli->deferred_events_collecting); + + rli->deferred_events_collecting= false; + for (uint i= 0; !res && i < array.elements; i++) + { + Log_event *ev= (* (Log_event **) + dynamic_array_ptr(&array, i)); + res= ev->apply_event(rli); + } + rli->deferred_events_collecting= true; + return res; +} + +void Deferred_log_events::rewind() +{ + /* + Reset preceeding Query log event events which execution was + deferred because of slave side filtering. + */ + if (!is_empty()) + { + for (uint i= 0; i < array.elements; i++) + { + Log_event *ev= *(Log_event **) dynamic_array_ptr(&array, i); + delete ev; + } + if (array.elements > array.max_element) + freeze_size(&array); + reset_dynamic(&array); + } +} + +#endif diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h index 4036a41bc60..81a10cca814 100644 --- a/sql/rpl_utility.h +++ b/sql/rpl_utility.h @@ -290,6 +290,24 @@ namespace { }; } + +class Deferred_log_events +{ +private: + DYNAMIC_ARRAY array; + Log_event *last_added; + +public: + Deferred_log_events(Relay_log_info *rli); + ~Deferred_log_events(); + /* queue for exection at Query-log-event time prior the Query */; + int add(Log_event *ev); + bool is_empty(); + bool execute(Relay_log_info *rli); + void rewind(); + bool is_last(Log_event *ev) { return ev == last_added; }; +}; + #endif // NB. number of printed bit values is limited to sizeof(buf) - 1 diff --git a/sql/slave.cc b/sql/slave.cc index be109a385da..0910d196583 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2360,7 +2360,8 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) used to read info about the relay log's format; it will be deleted when the SQL thread does not need it, i.e. when this thread terminates. */ - if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT) + if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT && + !rli->is_deferred_event(ev)) { DBUG_PRINT("info", ("Deleting the event after it has been executed")); delete ev; @@ -2990,6 +2991,12 @@ pthread_handler_t handle_slave_sql(void *arg) goto err; } thd->init_for_queries(); + thd->rli_slave= rli; + if ((rli->deferred_events_collecting= rpl_filter->is_on())) + { + rli->deferred_events= new Deferred_log_events(rli); + } + thd->temporary_tables = rli->save_temporary_tables; // restore temp tables set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp tables pthread_mutex_lock(&LOCK_thread_count); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index ace78947054..ca24830db63 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -116,6 +116,8 @@ static void close_old_data_files(THD *thd, TABLE *table, bool morph_locks, bool send_refresh); static bool has_write_table_with_auto_increment(TABLE_LIST *tables); +static bool +has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables); extern "C" uchar *table_cache_key(const uchar *record, size_t *length, @@ -5471,6 +5473,12 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen) *(ptr++)= table->table; } + if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables) + { + if (has_write_table_auto_increment_not_first_in_pk(tables)) + thd->lex->set_stmt_unsafe(); + } + /* We have to emulate LOCK TABLES if we are statement needs prelocking. */ if (thd->lex->requires_prelocking()) { @@ -9065,6 +9073,32 @@ has_write_table_with_auto_increment(TABLE_LIST *tables) return 0; } +/* + Tells if there is a table whose auto_increment column is a part + of a compound primary key while is not the first column in + the table definition. + + @param tables Table list + + @return true if the table exists, fais if does not. +*/ + +static bool +has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables) +{ + for (TABLE_LIST *table= tables; table; table= table->next_global) + { + /* we must do preliminary checks as table->table may be NULL */ + if (!table->placeholder() && + table->table->found_next_number_field && + (table->lock_type >= TL_WRITE_ALLOW_WRITE) + && table->table->s->next_number_keypart != 0) + return 1; + } + + return 0; +} + /* Open and lock system tables for read. diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 32e2e90acd7..2f3e8153cbd 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -601,7 +601,7 @@ Diagnostics_area::disable_status() THD::THD() :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION, /* statement id */ 0), - Open_tables_state(refresh_version), rli_fake(0), + Open_tables_state(refresh_version), rli_fake(NULL), rli_slave(NULL), lock_id(&main_lock_id), user_time(0), in_sub_stmt(0), sql_log_bin_toplevel(false), @@ -1035,6 +1035,8 @@ THD::~THD() delete rli_fake; rli_fake= NULL; } + if (rli_slave) + rli_slave->cleanup_after_session(); #endif free_root(&main_mem_root, MYF(0)); @@ -1267,6 +1269,10 @@ void THD::cleanup_after_query() /* reset table map for multi-table update */ table_map_for_update= 0; m_binlog_invoker= FALSE; +#ifndef EMBEDDED_LIBRARY + if (rli_slave) + rli_slave->cleanup_after_query(); +#endif } diff --git a/sql/sql_class.h b/sql/sql_class.h index 3c1b2c1330f..31d2c664aae 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1291,6 +1291,8 @@ class THD :public Statement, public: /* Used to execute base64 coded binlog events in MySQL server */ Relay_log_info* rli_fake; + /* Slave applier execution context */ + Relay_log_info* rli_slave; /* Constant for THD::where initialization in the beginning of every query. diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 14b778328d2..729a963eef1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2248,6 +2248,11 @@ mysql_execute_command(THD *thd) } DBUG_RETURN(0); } + /* + Execute deferred events first + */ + if (slave_execute_deferred_events(thd)) + DBUG_RETURN(-1); } else { -- cgit v1.2.1 From cdaae1692b1e74c0fdeaaece82e3350a30e3bbd2 Mon Sep 17 00:00:00 2001 From: Nuno Carvalho Date: Fri, 20 Apr 2012 22:25:59 +0100 Subject: BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER The function mysql_show_binlog_events has a local stack variable 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however this variable goes out of scope and is destroyed before clean thd->current_linfo. The problem is solved by moving 'LOG_INFO linfo;' to function scope. --- ...l_parallel_show_binlog_events_purge_logs.result | 13 ++++++++ ...rpl_parallel_show_binlog_events_purge_logs.test | 35 ++++++++++++++++++++++ sql/log.h | 5 ++++ sql/sql_repl.cc | 5 +++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result create mode 100644 mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test diff --git a/mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result b/mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result new file mode 100644 index 00000000000..b69deb17c4c --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result @@ -0,0 +1,13 @@ +include/master-slave.inc +[connection master] +[connection slave] +SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end'; +SHOW BINLOG EVENTS; +[connection slave1] +SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events'; +FLUSH LOGS; +SET DEBUG_SYNC= 'now SIGNAL end'; +SET DEBUG_SYNC= 'RESET'; +[connection slave] +SET DEBUG_SYNC= 'RESET'; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test b/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test new file mode 100644 index 00000000000..16d986268c9 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test @@ -0,0 +1,35 @@ +# BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER +# +# The function mysql_show_binlog_events has a local stack variable +# 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however +# this variable goes out of scope and is destroyed before clean +# thd->current_linfo. +# +# This test case runs SHOW BINLOG EVENTS and FLUSH LOGS to make sure +# that with the fix local variable linfo is valid along all +# mysql_show_binlog_events function scope. +# +--source include/have_debug_sync.inc +--source include/master-slave.inc + +--echo [connection slave] +--connection slave +SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end'; +--send SHOW BINLOG EVENTS + +--connection slave1 +--echo [connection slave1] +SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events'; +FLUSH LOGS; +SET DEBUG_SYNC= 'now SIGNAL end'; +SET DEBUG_SYNC= 'RESET'; + +--echo [connection slave] +--connection slave +--disable_result_log +--reap +--enable_result_log +SET DEBUG_SYNC= 'RESET'; + +--connection master +--source include/rpl_end.inc diff --git a/sql/log.h b/sql/log.h index 81342f6e696..9ed5db04e87 100644 --- a/sql/log.h +++ b/sql/log.h @@ -130,6 +130,11 @@ extern TC_LOG_DUMMY tc_log_dummy; class Relay_log_info; +/* + Note that we destroy the lock mutex in the desctructor here. + This means that object instances cannot be destroyed/go out of scope, + until we have reset thd->current_linfo to NULL; + */ typedef struct st_log_info { char log_file_name[FN_REFLEN]; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index a2c388ba388..b985805a827 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1454,6 +1454,8 @@ bool mysql_show_binlog_events(THD* thd) IO_CACHE log; File file = -1; int old_max_allowed_packet= thd->variables.max_allowed_packet; + LOG_INFO linfo; + DBUG_ENTER("mysql_show_binlog_events"); Log_event::init_show_field_list(&field_list); @@ -1480,7 +1482,6 @@ bool mysql_show_binlog_events(THD* thd) char search_file_name[FN_REFLEN], *name; const char *log_file_name = lex_mi->log_file_name; pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock(); - LOG_INFO linfo; Log_event* ev; unit->set_limit(thd->lex->current_select); @@ -1572,6 +1573,8 @@ bool mysql_show_binlog_events(THD* thd) pthread_mutex_unlock(log_lock); } + // Check that linfo is still on the function scope. + DEBUG_SYNC(thd, "after_show_binlog_events"); ret= FALSE; -- cgit v1.2.1 From dcb5071b1906d76b4c61d3125ddc7368f3ee8c4f Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Sat, 21 Apr 2012 05:23:09 +0530 Subject: BUG#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE Details: - test case bug12427262.test was failing on windows because on windows '/' was not recognized. And this was used in LIKE clause of the query being run in this test case. Fix: - Windows needs '\\\\' for path seperater in mysql. I was not sure how to keep a single query with two different syntax based on platform. So modifying query to make sure it runs correctly on both platform. --- mysql-test/r/bug12427262.result | 19 +++++++++++-------- mysql-test/t/bug12427262.test | 15 +++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/bug12427262.result b/mysql-test/r/bug12427262.result index f0f7ae46ba2..c541ba0f664 100644 --- a/mysql-test/r/bug12427262.result +++ b/mysql-test/r/bug12427262.result @@ -1,8 +1,8 @@ # # Bug#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE. # -create database show_table_db; -use show_table_db; +create database show_table_lw_db; +use show_table_lw_db; create table t1 (c1 int); create table t2 (c1 int); create table t3 (c1 int); @@ -14,9 +14,10 @@ create table t8 (c1 int); create table t9 (c1 int); create table t10 (c1 int); select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_before; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_before; show tables; -Tables_in_show_table_db +Tables_in_show_table_lw_db t1 t10 t2 @@ -28,12 +29,13 @@ t7 t8 t9 select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_after; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_after; select @count_read_after-@count_read_before; @count_read_after-@count_read_before 0.000000000000000000000000000000 show full tables; -Tables_in_show_table_db Table_type +Tables_in_show_table_lw_db Table_type t1 BASE TABLE t10 BASE TABLE t2 BASE TABLE @@ -45,9 +47,10 @@ t7 BASE TABLE t8 BASE TABLE t9 BASE TABLE select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_after; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_after; select @count_read_after-@count_read_before; @count_read_after-@count_read_before 10.000000000000000000000000000000 drop table t1; -drop database show_table_db; +drop database show_table_lw_db; diff --git a/mysql-test/t/bug12427262.test b/mysql-test/t/bug12427262.test index b7193dd1125..aca37a651c4 100644 --- a/mysql-test/t/bug12427262.test +++ b/mysql-test/t/bug12427262.test @@ -6,8 +6,8 @@ --source include/have_perfschema.inc --disable_warnings -create database show_table_db; -use show_table_db; +create database show_table_lw_db; +use show_table_lw_db; create table t1 (c1 int); create table t2 (c1 int); create table t3 (c1 int); @@ -22,14 +22,16 @@ create table t10 (c1 int); # Query PS to know initial read count for frm file. select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_before; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_before; show tables; # Query PS to know read count for frm file after above query. It should # not be changed as FRM file will not be opened for above query. select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_after; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_after; select @count_read_after-@count_read_before; @@ -38,11 +40,12 @@ show full tables; # Query PS to know read count for frm file after above query. COUNT_READ # will be incremented by 1 as FRM file will be opened for above query. select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME -like "%show_table_db/%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' into @count_read_after; +like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM' +into @count_read_after; select @count_read_after-@count_read_before; --disable_warnings drop table t1; -drop database show_table_db; +drop database show_table_lw_db; --enable_warnings -- cgit v1.2.1 From 6d74c922af3d37debfe3a42803d5c86b56dd936e Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Sat, 21 Apr 2012 14:19:06 +0300 Subject: merge bug11754117-45670 fixes from 5.1: fixing result files. --- mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result | 9 +++++++-- mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result index 75f4e661dc1..198ecfb6724 100644 --- a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result +++ b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result @@ -9,10 +9,10 @@ set @@binlog_format=statement; *** autoincrement field is not the first in PK warning must be there: *** insert into tm set b=null, a=1; Warnings: -Note 1592 Statement may not be safe to log in statement format. +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe. show warnings; Level Code Message -Note 1592 Statement may not be safe to log in statement format. +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe. *** no warning when autoincrement is the first in PK insert into ti set b=null, a=1; show warnings; @@ -26,9 +26,14 @@ end// select multi_part_pk_with_autoinc (3); multi_part_pk_with_autoinc (3) 3 +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly. +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe. *** autoincrement field is not the first in PK warning must be there: *** show warnings; Level Code Message +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly. +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe. set @@binlog_format=mixed; insert into tm set b=null, a=2; drop table tm, ti; diff --git a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result index f0dc97b71f2..025ef690ed7 100644 --- a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result +++ b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result @@ -126,7 +126,7 @@ SET @c=2; SET @@rand_seed1=10000000, @@rand_seed2=1000000; INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); Warnings: -Note 1592 Statement may not be safe to log in statement format. +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. SELECT b into @b FROM test.t5; UPDATE test.t1 SET a=2; SELECT a AS 'ONE' into @a FROM test.t_slave; -- cgit v1.2.1 From da7436a2a88a94440b746ad6600450569a50923b Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Sat, 21 Apr 2012 15:06:06 +0300 Subject: merge bug11754117-45670 fixes from 5.1: fixing comments in sql_lex.h. --- sql/sql_lex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 992ed551564..111a22c7ff9 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1330,7 +1330,8 @@ public: BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS, /** - INSERT into auto-inc field which is not the first field in the table. + INSERT into auto-inc field which is not the first part of composed + primary key. */ BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST, -- cgit v1.2.1 From bd0c38064faf52e65ee8d2044f15b6393b44522d Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Mon, 23 Apr 2012 11:51:19 +0300 Subject: BUG#11754117 rpl_auto_increment_bug45679.test is refined due to not fixed in 5.1 Bug11749859-39934. --- mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result | 2 +- mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result index 75f4e661dc1..e2b3206eb02 100644 --- a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result +++ b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result @@ -26,7 +26,7 @@ end// select multi_part_pk_with_autoinc (3); multi_part_pk_with_autoinc (3) 3 -*** autoincrement field is not the first in PK warning must be there: *** +*** No warnings in 5.1 because of Bug11749859-39934 *** show warnings; Level Code Message set @@binlog_format=mixed; diff --git a/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test b/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test index 6996e1c73c7..0df086ddbfa 100644 --- a/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test +++ b/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test @@ -35,7 +35,7 @@ end// delimiter ;// select multi_part_pk_with_autoinc (3); ---echo *** autoincrement field is not the first in PK warning must be there: *** +--echo *** No warnings in 5.1 because of Bug11749859-39934 *** show warnings; set @@binlog_format=mixed; -- cgit v1.2.1 From 2415d955c8fff4a2001f4d1774a75f156b787e7c Mon Sep 17 00:00:00 2001 From: Inaam Rana Date: Mon, 23 Apr 2012 06:39:16 -0400 Subject: Bug#12677594 - 61575: INNODB: WARNING: IO_SETUP() FAILED WITH EAGAIN. rb://1033 approved by: Marko Makela Check return value from os_aio_init() and refuse to start if it fails. --- storage/innobase/srv/srv0start.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/storage/innobase/srv/srv0start.c b/storage/innobase/srv/srv0start.c index 343e41fe376..86669a50895 100644 --- a/storage/innobase/srv/srv0start.c +++ b/storage/innobase/srv/srv0start.c @@ -1364,10 +1364,18 @@ innobase_start_or_create_for_mysql(void) } # endif /* __WIN__ */ - os_aio_init(io_limit, - srv_n_read_io_threads, - srv_n_write_io_threads, - SRV_MAX_N_PENDING_SYNC_IOS); + if (!os_aio_init(io_limit, + srv_n_read_io_threads, + srv_n_write_io_threads, + SRV_MAX_N_PENDING_SYNC_IOS)) { + + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Fatal error: cannot initialize AIO" + " sub-system\n"); + + return(DB_ERROR); + } fil_init(srv_file_per_table ? 50000 : 5000, srv_max_n_open_files); -- cgit v1.2.1 From 678f221cb9ac3ba18b70568077d8979adb1ac44c Mon Sep 17 00:00:00 2001 From: Kent Boortz Date: Mon, 23 Apr 2012 12:52:14 +0200 Subject: Allow Windows absolute paths in N:\ formatfor the --vardir option --- mysql-test/mysql-test-run.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 43734d04286..927a2ebfa91 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1442,7 +1442,7 @@ sub command_line_setup { # We make the path absolute, as the server will do a chdir() before usage unless ( $opt_vardir =~ m,^/, or - (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) ) + (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:[/\\],i) ) { # Make absolute path, relative test dir $opt_vardir= "$glob_mysql_test_dir/$opt_vardir"; -- cgit v1.2.1 From e881e03e01e1c27fa4d7715aec750d34af56aadd Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Mon, 23 Apr 2012 16:26:22 +0300 Subject: Bug #59148 - made tests experimental Fixed a cmake 2.8.8 compilation problem. --- configure.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.cmake b/configure.cmake index c3cc787ebc8..b8fa70db203 100644 --- a/configure.cmake +++ b/configure.cmake @@ -149,7 +149,9 @@ IF(UNIX) SET(CMAKE_REQUIRED_LIBRARIES ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT}) - LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES) + IF(NOT ${CMAKE_REQUIRED_LIBRARIES} MATCHES '') + LIST(REMOVE_DUPLICATES ${CMAKE_REQUIRED_LIBRARIES}) + ENDIF() LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT}) OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF) -- cgit v1.2.1 From b872ce0312022b5ac86a368305c34ce9fda7d720 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Mon, 23 Apr 2012 17:18:55 +0300 Subject: Fixed a cmake compile problem because of the 2.8.8 fix. --- configure.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure.cmake b/configure.cmake index b8fa70db203..5b1afd66439 100644 --- a/configure.cmake +++ b/configure.cmake @@ -149,8 +149,9 @@ IF(UNIX) SET(CMAKE_REQUIRED_LIBRARIES ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT}) - IF(NOT ${CMAKE_REQUIRED_LIBRARIES} MATCHES '') - LIST(REMOVE_DUPLICATES ${CMAKE_REQUIRED_LIBRARIES}) + LIST(LENGTH CMAKE_REQUIRED_LIBRARIES required_libs_length) + IF(${required_libs_length} GREATER 0) + LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES) ENDIF() LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT}) -- cgit v1.2.1 From 08ead005b11a2806e45f395dd4b36ecd0f471b7c Mon Sep 17 00:00:00 2001 From: Inaam Rana Date: Mon, 23 Apr 2012 22:15:29 -0400 Subject: Bug#13990648: 65061: LRU FLUSH RATE CALCULATION IS BASED ON INVALID VALUES rb://1043 approved by: Sunny Bains Two internal counters were incremented twice for a single operations. The counters are: srv_buf_pool_flushed buf_lru_flush_page_count --- storage/innobase/buf/buf0flu.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/storage/innobase/buf/buf0flu.c b/storage/innobase/buf/buf0flu.c index 6e8e8fdda5a..7cd09d6675e 100644 --- a/storage/innobase/buf/buf0flu.c +++ b/storage/innobase/buf/buf0flu.c @@ -1750,8 +1750,6 @@ buf_flush_batch( } #endif /* UNIV_DEBUG */ - srv_buf_pool_flushed += count; - return(count); } @@ -1778,13 +1776,6 @@ buf_flush_common( #endif /* UNIV_DEBUG */ srv_buf_pool_flushed += page_count; - - if (flush_type == BUF_FLUSH_LRU) { - /* We keep track of all flushes happening as part of LRU - flush. When estimating the desired rate at which flush_list - should be flushed we factor in this value. */ - buf_lru_flush_page_count += page_count; - } } /******************************************************************//** -- cgit v1.2.1 From 3f98e95354b6d1c55a824bb1b314e3bb8c465ef0 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Thu, 26 Apr 2012 19:34:03 +0530 Subject: BUG#13812374 - RPL.RPL_REPORT_PORT FAILS OCCASIONALLY ON PB2 Problem - The failure on PB2 is possbily due to the port number being still in use even after the server restarts which is not reflected in the server restart. Fix - The problem is fixed by starting the servers forcefully using the option file and also the parameters for the server restart is passed correctly. mysql-test/suite/rpl/t/rpl_report_port-master.opt: Option file for the master. --- mysql-test/suite/rpl/r/rpl_report_port.result | 4 ++-- mysql-test/suite/rpl/t/rpl_report_port-master.opt | 1 + mysql-test/suite/rpl/t/rpl_report_port.test | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 mysql-test/suite/rpl/t/rpl_report_port-master.opt diff --git a/mysql-test/suite/rpl/r/rpl_report_port.result b/mysql-test/suite/rpl/r/rpl_report_port.result index d9887f41ff9..6a9ac341780 100644 --- a/mysql-test/suite/rpl/r/rpl_report_port.result +++ b/mysql-test/suite/rpl/r/rpl_report_port.result @@ -3,8 +3,8 @@ include/master-slave.inc include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000] include/start_slave.inc [Slave restarted with the report-port set to some value] -include/assert.inc [The value shown for the slave's port number is 9000 which is the value set for report-port.] -include/rpl_restart_server.inc [server_number=2 parameters: --report-port=] +include/assert.inc [The value shown for the slave's port number is user specified port number which is the value set for report-port.] +include/rpl_restart_server.inc [server_number=2] include/start_slave.inc [Slave restarted with the report-port set to the value of slave's port number] include/assert.inc [The default value shown for the slave's port number is the actual port number of the slave.] diff --git a/mysql-test/suite/rpl/t/rpl_report_port-master.opt b/mysql-test/suite/rpl/t/rpl_report_port-master.opt new file mode 100644 index 00000000000..cef79bc8585 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_report_port-master.opt @@ -0,0 +1 @@ +--force-restart diff --git a/mysql-test/suite/rpl/t/rpl_report_port.test b/mysql-test/suite/rpl/t/rpl_report_port.test index 379f9aed946..12c34ce01b1 100644 --- a/mysql-test/suite/rpl/t/rpl_report_port.test +++ b/mysql-test/suite/rpl/t/rpl_report_port.test @@ -38,21 +38,23 @@ connection master; # 9000 is the value of the port we should get. --let $report_port= query_get_value(SHOW SLAVE HOSTS, Port, 1) ---let assert_text= The value shown for the slave's port number is 9000 which is the value set for report-port. +--let assert_text= The value shown for the slave's port number is user specified port number which is the value set for report-port. --let assert_cond= $report_port = "9000" --source include/assert.inc - # Start the server with the report-port being passed with no value. So on SHOW SLAVE HOSTS # on the master the value of slave's port should be the actual value of the slave port. +connection master; --let $rpl_server_number= 2 ---let $rpl_server_parameters= --report-port= +--let $rpl_server_parameters= --source include/rpl_restart_server.inc connection slave; --source include/start_slave.inc +connection master; +sync_slave_with_master; --echo [Slave restarted with the report-port set to the value of slave's port number] connection master; -- cgit v1.2.1 From 1a2cf649dc411b47122419cb9e8c8ef1a26ae91a Mon Sep 17 00:00:00 2001 From: irana Date: Thu, 26 Apr 2012 08:17:14 -0700 Subject: InnoDB: Adjust error message when a dropped tablespace is accessed. --- storage/innodb_plugin/fil/fil0fil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innodb_plugin/fil/fil0fil.c b/storage/innodb_plugin/fil/fil0fil.c index eebfbd9ccad..6f2ab938042 100644 --- a/storage/innodb_plugin/fil/fil0fil.c +++ b/storage/innodb_plugin/fil/fil0fil.c @@ -1853,7 +1853,7 @@ fil_inc_pending_ops( if (space == NULL) { fprintf(stderr, - "InnoDB: Error: trying to do ibuf merge to a" + "InnoDB: Error: trying to do an operation on a" " dropped tablespace %lu\n", (ulong) id); } -- cgit v1.2.1 From 08e7444e549722f61dd90fdf23ce05632c72044e Mon Sep 17 00:00:00 2001 From: Yasufumi Kinoshita Date: Fri, 27 Apr 2012 19:38:13 +0900 Subject: Bug#11758510 (#50723): INNODB CHECK TABLE FATAL SEMAPHORE WAIT TIMEOUT POSSIBLY TOO SHORT FOR BI Fixed not to check timeout during the check table. --- storage/innobase/dict/dict0load.c | 4 ++-- storage/innobase/include/srv0srv.h | 1 + storage/innobase/row/row0mysql.c | 4 ++-- storage/innobase/sync/sync0arr.c | 5 +++++ storage/innodb_plugin/dict/dict0load.c | 4 ++-- storage/innodb_plugin/handler/ha_innodb.cc | 4 ++-- storage/innodb_plugin/include/srv0srv.h | 1 + storage/innodb_plugin/sync/sync0arr.c | 5 +++++ 8 files changed, 20 insertions(+), 8 deletions(-) diff --git a/storage/innobase/dict/dict0load.c b/storage/innobase/dict/dict0load.c index 7e820cfb08d..3c3c0d10c7c 100644 --- a/storage/innobase/dict/dict0load.c +++ b/storage/innobase/dict/dict0load.c @@ -150,7 +150,7 @@ dict_print(void) monitor printout */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); mutex_enter(&(dict_sys->mutex)); @@ -178,7 +178,7 @@ loop: /* Restore the fatal semaphore wait timeout */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); return; diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index 811074b2be8..aa6c88e0538 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -173,6 +173,7 @@ extern ibool srv_print_latch_waits; extern ulint srv_activity_count; extern ulint srv_fatal_semaphore_wait_threshold; +#define SRV_SEMAPHORE_WAIT_EXTENSION 7200 extern ulint srv_dml_needed_delay; extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs, diff --git a/storage/innobase/row/row0mysql.c b/storage/innobase/row/row0mysql.c index 6148b01af9d..16fd2b3b482 100644 --- a/storage/innobase/row/row0mysql.c +++ b/storage/innobase/row/row0mysql.c @@ -4165,7 +4165,7 @@ row_check_table_for_mysql( /* Enlarge the fatal lock wait timeout during CHECK TABLE. */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); index = dict_table_get_first_index(table); @@ -4223,7 +4223,7 @@ row_check_table_for_mysql( /* Restore the fatal lock wait timeout after CHECK TABLE. */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); prebuilt->trx->op_info = ""; diff --git a/storage/innobase/sync/sync0arr.c b/storage/innobase/sync/sync0arr.c index 93a7398f252..60a96fe4388 100644 --- a/storage/innobase/sync/sync0arr.c +++ b/storage/innobase/sync/sync0arr.c @@ -931,6 +931,11 @@ sync_array_print_long_waits( ibool fatal = FALSE; double longest_diff = 0; + /* For huge tables, skip the check during CHECK TABLE etc... */ + if (fatal_timeout > SRV_SEMAPHORE_WAIT_EXTENSION) { + return(FALSE); + } + for (i = 0; i < sync_primary_wait_array->n_cells; i++) { double diff; diff --git a/storage/innodb_plugin/dict/dict0load.c b/storage/innodb_plugin/dict/dict0load.c index 7a0b6edcb08..7231fadabe1 100644 --- a/storage/innodb_plugin/dict/dict0load.c +++ b/storage/innodb_plugin/dict/dict0load.c @@ -164,7 +164,7 @@ dict_print(void) monitor printout */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); mutex_enter(&(dict_sys->mutex)); @@ -192,7 +192,7 @@ loop: /* Restore the fatal semaphore wait timeout */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); return; diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index f16b9fabd20..30448bccf7b 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -8148,7 +8148,7 @@ ha_innobase::check( /* Enlarge the fatal lock wait timeout during CHECK TABLE. */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); for (index = dict_table_get_first_index(prebuilt->table); @@ -8244,7 +8244,7 @@ ha_innobase::check( /* Restore the fatal lock wait timeout after CHECK TABLE. */ mutex_enter(&kernel_mutex); - srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */ + srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION; mutex_exit(&kernel_mutex); prebuilt->trx->op_info = ""; diff --git a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h index 7c63a5f0d45..1a9f54882c5 100644 --- a/storage/innodb_plugin/include/srv0srv.h +++ b/storage/innodb_plugin/include/srv0srv.h @@ -244,6 +244,7 @@ extern ibool srv_print_latch_waits; extern ulint srv_activity_count; extern ulint srv_fatal_semaphore_wait_threshold; +#define SRV_SEMAPHORE_WAIT_EXTENSION 7200 extern ulint srv_dml_needed_delay; extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs, diff --git a/storage/innodb_plugin/sync/sync0arr.c b/storage/innodb_plugin/sync/sync0arr.c index 13970023573..90ea50b641b 100644 --- a/storage/innodb_plugin/sync/sync0arr.c +++ b/storage/innodb_plugin/sync/sync0arr.c @@ -927,6 +927,11 @@ sync_array_print_long_waits( ibool fatal = FALSE; double longest_diff = 0; + /* For huge tables, skip the check during CHECK TABLE etc... */ + if (fatal_timeout > SRV_SEMAPHORE_WAIT_EXTENSION) { + return(FALSE); + } + for (i = 0; i < sync_primary_wait_array->n_cells; i++) { double diff; -- cgit v1.2.1 From 6fa011056abf534bf3d544cdef14f3a539777b6d Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Fri, 27 Apr 2012 18:42:27 +0400 Subject: Follow-up for Bug#12762885 - 61713: MYSQL WILL NOT BIND TO "LOCALHOST" IF LOCALHOST IS BOTH IPV4/IPV6 ENABLED. The original patch removed default value of the bind-address option. So, the default value became NULL. By coincedence NULL resolves to 0.0.0.0 and ::, and since the server chooses first IPv4-address, 0.0.0.0 is choosen. So, there was no change in the behaviour. This patch restores default value of the bind-address option to "0.0.0.0". --- sql/mysqld.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 547378d4661..e90bd8dad33 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1841,6 +1841,9 @@ static void network_init(void) struct addrinfo *ai, *a; struct addrinfo hints; + if (!my_bind_addr_str) + my_bind_addr_str= (char *) "0.0.0.0"; + sql_print_information("Server hostname (bind-address): '%s'; port: %d", my_bind_addr_str, mysqld_port); -- cgit v1.2.1 From 25cdec81e082049a668552f631fa32a838d915e3 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Fri, 27 Apr 2012 19:14:28 +0400 Subject: Proper follow-up for Bug#12762885 - 61713: MYSQL WILL NOT BIND TO "LOCALHOST" IF LOCALHOST IS BOTH IPV4/IPV6 ENABLED. The original patch removed default value of the bind-address option. So, the default value became NULL. By coincedence NULL resolves to 0.0.0.0 and ::, and since the server chooses first IPv4-address, 0.0.0.0 is choosen. So, there was no change in the behaviour. This patch restores default value of the bind-address option to "0.0.0.0". --- mysql-test/r/mysqld--help-notwin.result | 2 +- mysql-test/r/mysqld--help-win.result | 2 +- sql/mysqld.cc | 8 +------- sql/mysqld.h | 1 + sql/sys_vars.cc | 5 +++++ 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index 36649cf761d..ac8edfc5083 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -747,7 +747,7 @@ autocommit TRUE automatic-sp-privileges TRUE back-log 50 big-tables FALSE -bind-address (No default value) +bind-address 0.0.0.0 binlog-cache-size 32768 binlog-direct-non-transactional-updates FALSE binlog-format STATEMENT diff --git a/mysql-test/r/mysqld--help-win.result b/mysql-test/r/mysqld--help-win.result index db7dd264b76..d47b6f0c1a5 100644 --- a/mysql-test/r/mysqld--help-win.result +++ b/mysql-test/r/mysqld--help-win.result @@ -755,7 +755,7 @@ autocommit TRUE automatic-sp-privileges TRUE back-log 50 big-tables FALSE -bind-address (No default value) +bind-address 0.0.0.0 binlog-cache-size 32768 binlog-direct-non-transactional-updates FALSE binlog-format STATEMENT diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e90bd8dad33..936167280e0 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -341,7 +341,7 @@ static char *default_character_set_name; static char *character_set_filesystem_name; static char *lc_messages; static char *lc_time_names_name; -static char *my_bind_addr_str; +char *my_bind_addr_str; static char *default_collation_name; char *default_storage_engine; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; @@ -1841,9 +1841,6 @@ static void network_init(void) struct addrinfo *ai, *a; struct addrinfo hints; - if (!my_bind_addr_str) - my_bind_addr_str= (char *) "0.0.0.0"; - sql_print_information("Server hostname (bind-address): '%s'; port: %d", my_bind_addr_str, mysqld_port); @@ -5713,9 +5710,6 @@ struct my_option my_long_options[]= {"autocommit", 0, "Set default value for autocommit (0 or 1)", &opt_autocommit, &opt_autocommit, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, NULL}, - {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", - &my_bind_addr_str, &my_bind_addr_str, 0, GET_STR, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"binlog-do-db", OPT_BINLOG_DO_DB, "Tells the master it should log updates for the specified database, " "and exclude all others not explicitly mentioned.", diff --git a/sql/mysqld.h b/sql/mysqld.h index 2604e889ebd..7fef4c6af82 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -146,6 +146,7 @@ extern char *opt_backup_history_logname, *opt_backup_progress_logname, extern const char *log_output_str; extern const char *log_backup_output_str; extern char *mysql_home_ptr, *pidfile_name_ptr; +extern char *my_bind_addr_str; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char default_logfile_name[FN_REFLEN]; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index f15664bca10..9c7421c46f2 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -308,6 +308,11 @@ static Sys_var_charptr Sys_basedir( READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'), IN_FS_CHARSET, DEFAULT(0)); +static Sys_var_charptr Sys_my_bind_addr( + "bind_address", "IP address to bind to.", + READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG), + IN_FS_CHARSET, DEFAULT("0.0.0.0")); + static Sys_var_ulong Sys_binlog_cache_size( "binlog_cache_size", "The size of the transactional cache for " "updates to transactional engines for the binary log. " -- cgit v1.2.1 From 476762bd7b3bbe6c1f89858174c0dde5e44b361b Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Fri, 27 Apr 2012 21:07:53 +0400 Subject: Revert two follow-ups for Bug#12762885: - alexander.nozdrin@oracle.com-20120427151428-7llk1mlwx8xmbx0t - alexander.nozdrin@oracle.com-20120427144227-kltwiuu8snds4j3l. --- mysql-test/r/mysqld--help-notwin.result | 2 +- mysql-test/r/mysqld--help-win.result | 2 +- sql/mysqld.cc | 5 ++++- sql/mysqld.h | 1 - sql/sys_vars.cc | 5 ----- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index ac8edfc5083..36649cf761d 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -747,7 +747,7 @@ autocommit TRUE automatic-sp-privileges TRUE back-log 50 big-tables FALSE -bind-address 0.0.0.0 +bind-address (No default value) binlog-cache-size 32768 binlog-direct-non-transactional-updates FALSE binlog-format STATEMENT diff --git a/mysql-test/r/mysqld--help-win.result b/mysql-test/r/mysqld--help-win.result index d47b6f0c1a5..db7dd264b76 100644 --- a/mysql-test/r/mysqld--help-win.result +++ b/mysql-test/r/mysqld--help-win.result @@ -755,7 +755,7 @@ autocommit TRUE automatic-sp-privileges TRUE back-log 50 big-tables FALSE -bind-address 0.0.0.0 +bind-address (No default value) binlog-cache-size 32768 binlog-direct-non-transactional-updates FALSE binlog-format STATEMENT diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 936167280e0..547378d4661 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -341,7 +341,7 @@ static char *default_character_set_name; static char *character_set_filesystem_name; static char *lc_messages; static char *lc_time_names_name; -char *my_bind_addr_str; +static char *my_bind_addr_str; static char *default_collation_name; char *default_storage_engine; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; @@ -5710,6 +5710,9 @@ struct my_option my_long_options[]= {"autocommit", 0, "Set default value for autocommit (0 or 1)", &opt_autocommit, &opt_autocommit, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, NULL}, + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", + &my_bind_addr_str, &my_bind_addr_str, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"binlog-do-db", OPT_BINLOG_DO_DB, "Tells the master it should log updates for the specified database, " "and exclude all others not explicitly mentioned.", diff --git a/sql/mysqld.h b/sql/mysqld.h index 7fef4c6af82..2604e889ebd 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -146,7 +146,6 @@ extern char *opt_backup_history_logname, *opt_backup_progress_logname, extern const char *log_output_str; extern const char *log_backup_output_str; extern char *mysql_home_ptr, *pidfile_name_ptr; -extern char *my_bind_addr_str; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char default_logfile_name[FN_REFLEN]; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 9c7421c46f2..f15664bca10 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -308,11 +308,6 @@ static Sys_var_charptr Sys_basedir( READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'), IN_FS_CHARSET, DEFAULT(0)); -static Sys_var_charptr Sys_my_bind_addr( - "bind_address", "IP address to bind to.", - READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG), - IN_FS_CHARSET, DEFAULT("0.0.0.0")); - static Sys_var_ulong Sys_binlog_cache_size( "binlog_cache_size", "The size of the transactional cache for " "updates to transactional engines for the binary log. " -- cgit v1.2.1 From 95205bbaffed8adb80185af5fa24aef697b6c9d4 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Fri, 27 Apr 2012 21:14:35 +0400 Subject: Third attempt to do a follow-up for Bug#12762885 - 61713: MYSQL WILL NOT BIND TO "LOCALHOST" IF LOCALHOST IS BOTH IPV4/IPV6 ENABLED. Previous commit comments were wrong. The default value has always been NULL. The original patch for Bug#12762885 just makes it visible in the logs. This patch uses "0.0.0.0" string if bind-address is not set. --- sql/mysqld.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 547378d4661..63656460f42 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1840,9 +1840,13 @@ static void network_init(void) { struct addrinfo *ai, *a; struct addrinfo hints; + const char *bind_address= my_bind_addr_str; + + if (!bind_address) + bind_address= "0.0.0.0"; sql_print_information("Server hostname (bind-address): '%s'; port: %d", - my_bind_addr_str, mysqld_port); + bind_address, mysqld_port); // Get list of IP-addresses associated with the server hostname. bzero(&hints, sizeof (hints)); @@ -1851,7 +1855,7 @@ static void network_init(void) hints.ai_family= AF_UNSPEC; my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port); - if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai)) + if (getaddrinfo(bind_address, port_buf, &hints, &ai)) { sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */ sql_print_error("Can't start server: cannot resolve hostname!"); @@ -1871,7 +1875,7 @@ static void network_init(void) } sql_print_information(" - '%s' resolves to '%s';", - my_bind_addr_str, ip_addr); + bind_address, ip_addr); } /* -- cgit v1.2.1 From b757c13078ec88bb734c8697a9e3ecd870934f8a Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Fri, 4 May 2012 12:29:49 +0530 Subject: In perl, to break out of a foreach loop we need to use the keyword "last" and not "break". Fixing the failing test case. --- mysql-test/suite/innodb/t/innodb_bug12902967.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test index 7bc5727a7a6..e9d832f3c19 100644 --- a/mysql-test/suite/innodb/t/innodb_bug12902967.test +++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test @@ -33,7 +33,7 @@ foreach $line (reverse @lines) { ++$count; print "$line"; if ($count == 2) { - break; + last; } } } -- cgit v1.2.1 From daafaa0f86208fb5ddb13468e79772abef46cbd1 Mon Sep 17 00:00:00 2001 From: Venkata Sidagam Date: Fri, 4 May 2012 18:33:34 +0530 Subject: Bug #11754178 45740: MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM Problem Statement: ------------------ mysqldump is not having the dump stmts for general_log and slow_log tables. That is because of the fix for Bug#26121. Hence, after dropping the mysql database, and applying the dump by enabling the logging, "'general_log' table not found" errors are logged into the server log file. Analysis: --------- As part of the fix for Bug#26121, we skipped the dumping of tables for general_log and slow_log, because the data dump of those tables are taking LOCKS, which is not allowed for log tables. Fix: ---- We came up with an approach that instead of taking both meta data and data dump information for those tables, take only the meta data dump which doesn't need LOCKS. As part of fixing the issue we came up with below algorithm. Design before fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. Design with the fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Explicitly call the 'show create table' for general_log and slow_log 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. While taking the meta data dump for general_log and slow_log the "CREATE TABLE" is replaced with "CREATE TABLE IF NOT EXISTS". This is because we skipped "DROP TABLE" for those tables, "DROP TABLE" fails for these tables if logging is enabled. Customer is applying the dump by enabling logging so, if the dump has "DROP TABLE" it will fail. Hence, removed the "DROP TABLE" stmts for those tables. After the fix we could observe "Table 'mysql.general_log' doesn't exist" errors initially that is because in the customer scenario they are dropping the mysql database by enabling the logging, Hence, those errors are expected. Once we apply the dump which is taken before the "drop database mysql", the errors will not be there. client/mysqldump.c: In get_table_structure() added code to skip the DROP TABLE stmts for general_log and slow_log tables, because when logging is enabled those stmts will fail. And replaced CREATE TABLE with CREATE IF NOT EXISTS for those tables, just to make sure CREATE stmt for those tables doesn't fail since we removed DROP stmts for those tables. In dump_all_tables_in_db() added code to call get_table_structure() for general_log and slow_log tables. mysql-test/r/mysqldump.result: Added a test as part of fix for Bug #11754178 mysql-test/t/mysqldump.test: Added a test as part of fix for Bug #11754178 --- client/mysqldump.c | 58 +++++++++++++++++++++++++++++++++++++------ mysql-test/r/mysqldump.result | 42 +++++++++++++++++++++++++++++++ mysql-test/t/mysqldump.test | 29 +++++++++++++++++++--- 3 files changed, 118 insertions(+), 11 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 8601b533849..dc124f1b335 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -84,6 +84,15 @@ #define IGNORE_DATA 0x01 /* don't dump data for this table */ #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */ +/* general_log or slow_log tables under mysql database */ +static inline my_bool general_log_or_slow_log_tables(const char *db, + const char *table) +{ + return (strcmp(db, "mysql") == 0) && + ((strcmp(table, "general_log") == 0) || + (strcmp(table, "slow_log") == 0)); +} + static void add_load_option(DYNAMIC_STRING *str, const char *option, const char *option_value); static ulong find_set(TYPELIB *lib, const char *x, uint length, @@ -2458,6 +2467,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, "TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'"; FILE *sql_file= md_result_file; int len; + my_bool is_log_table; MYSQL_RES *result; MYSQL_ROW row; DBUG_ENTER("get_table_structure"); @@ -2542,9 +2552,12 @@ static uint get_table_structure(char *table, char *db, char *table_type, /* Even if the "table" is a view, we do a DROP TABLE here. The view-specific code below fills in the DROP VIEW. + We will skip the DROP TABLE for general_log and slow_log, since + those stmts will fail, in case we apply dump by enabling logging. */ - fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", - opt_quoted_table); + if (!general_log_or_slow_log_tables(db, table)) + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", + opt_quoted_table); check_io(sql_file); } @@ -2656,12 +2669,25 @@ static uint get_table_structure(char *table, char *db, char *table_type, row= mysql_fetch_row(result); - fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" : - "/*!40101 SET @saved_cs_client = @@character_set_client */;\n" - "/*!40101 SET character_set_client = utf8 */;\n" - "%s;\n" - "/*!40101 SET character_set_client = @saved_cs_client */;\n", - row[1]); + is_log_table= general_log_or_slow_log_tables(db, table); + if (is_log_table) + row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */ + if (opt_compatible_mode & 3) + { + fprintf(sql_file, + is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n", + row[1]); + } + else + { + fprintf(sql_file, + "/*!40101 SET @saved_cs_client = @@character_set_client */;\n" + "/*!40101 SET character_set_client = utf8 */;\n" + "%s%s;\n" + "/*!40101 SET character_set_client = @saved_cs_client */;\n", + is_log_table ? "CREATE TABLE IF NOT EXISTS " : "", + row[1]); + } check_io(sql_file); mysql_free_result(result); @@ -4261,6 +4287,22 @@ static int dump_all_tables_in_db(char *database) if (opt_xml) print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); + if (strcmp(database, "mysql") == 0) + { + char table_type[NAME_LEN]; + char ignore_flag; + uint num_fields; + num_fields= get_table_structure((char *) "general_log", + database, table_type, &ignore_flag); + if (num_fields == 0) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'general_log' table\n"); + num_fields= get_table_structure((char *) "slow_log", + database, table_type, &ignore_flag); + if (num_fields == 0) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'slow_log' table\n"); + } if (lock_tables) { DYNAMIC_STRING query; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 1d4a5783c3f..fac94e855a4 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5067,5 +5067,47 @@ RETURN CONCAT(']]]]>, ', s, '!') DROP DATABASE BUG52792; USE test; # +# Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM +# +SET @old_log_output_state= @@global.log_output; +SET @old_general_log_state= @@global.general_log; +SET @old_slow_query_log_state= @@global.slow_query_log; +call mtr.add_suppression("Failed to write to mysql.general_log"); +SET @@global.log_output="TABLE"; +SET @@global.general_log='ON'; +SET @@global.slow_query_log='ON'; +DROP DATABASE mysql; +Warnings: +Error 1146 Table 'mysql.proc' doesn't exist +Error 1146 Table 'mysql.event' doesn't exist +SHOW CREATE TABLE mysql.general_log; +Table Create Table +general_log CREATE TABLE `general_log` ( + `event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `user_host` mediumtext NOT NULL, + `thread_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `command_type` varchar(64) NOT NULL, + `argument` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log' +SHOW CREATE TABLE mysql.slow_log; +Table Create Table +slow_log CREATE TABLE `slow_log` ( + `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `user_host` mediumtext NOT NULL, + `query_time` time NOT NULL, + `lock_time` time NOT NULL, + `rows_sent` int(11) NOT NULL, + `rows_examined` int(11) NOT NULL, + `db` varchar(512) NOT NULL, + `last_insert_id` int(11) NOT NULL, + `insert_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `sql_text` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +SET @@global.log_output= @old_log_output_state; +SET @@global.slow_query_log= @old_slow_query_log_state; +SET @@global.general_log= @old_general_log_state; +# # End of 5.1 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 20c788e3b9a..7393ca88f0a 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2308,9 +2308,32 @@ DROP DATABASE BUG52792; USE test; +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc + --echo # ---echo # End of 5.1 tests +--echo # Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM --echo # +SET @old_log_output_state= @@global.log_output; +SET @old_general_log_state= @@global.general_log; +SET @old_slow_query_log_state= @@global.slow_query_log; -# Wait till we reached the initial number of concurrent sessions ---source include/wait_until_count_sessions.inc +call mtr.add_suppression("Failed to write to mysql.general_log"); +--exec $MYSQL_DUMP -uroot --all-databases > $MYSQLTEST_VARDIR/tmp/bug45740.sql +# Make log_output as table and enable general_log and slow_log +SET @@global.log_output="TABLE"; +SET @@global.general_log='ON'; +SET @@global.slow_query_log='ON'; +DROP DATABASE mysql; +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug45740.sql +SHOW CREATE TABLE mysql.general_log; +SHOW CREATE TABLE mysql.slow_log; +--remove_file $MYSQLTEST_VARDIR/tmp/bug45740.sql + +SET @@global.log_output= @old_log_output_state; +SET @@global.slow_query_log= @old_slow_query_log_state; +SET @@global.general_log= @old_general_log_state; + +--echo # +--echo # End of 5.1 tests +--echo # -- cgit v1.2.1 From e7364ec29c522b5d98951b851ca3cc62a9f46d59 Mon Sep 17 00:00:00 2001 From: Venkata Sidagam Date: Mon, 7 May 2012 16:46:44 +0530 Subject: Bug #11754178 45740: MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM Problem Statement: ------------------ mysqldump is not having the dump stmts for general_log and slow_log tables. That is because of the fix for Bug#26121. Hence, after dropping the mysql database, and applying the dump by enabling the logging, "'general_log' table not found" errors are logged into the server log file. Analysis: --------- As part of the fix for Bug#26121, we skipped the dumping of tables for general_log and slow_log, because the data dump of those tables are taking LOCKS, which is not allowed for log tables. Fix: ---- We came up with an approach that instead of taking both meta data and data dump information for those tables, take only the meta data dump which doesn't need LOCKS. As part of fixing the issue we came up with below algorithm. Design before fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. Design with the fix: 1) mysql database is having tables like db, event,... general_log, ... slow_log... 2) Skip general_log and slow_log while preparing the tables list 3) Explicitly call the 'show create table' for general_log and slow_log 3) Take the TL_READ lock on tables which are present in the table list and do 'show create table'. 4) Release the lock. While taking the meta data dump for general_log and slow_log the "CREATE TABLE" is replaced with "CREATE TABLE IF NOT EXISTS". This is because we skipped "DROP TABLE" for those tables, "DROP TABLE" fails for these tables if logging is enabled. Customer is applying the dump by enabling logging so, if the dump has "DROP TABLE" it will fail. Hence, removed the "DROP TABLE" stmts for those tables. After the fix we could observe "Table 'mysql.general_log' doesn't exist" errors initially that is because in the customer scenario they are dropping the mysql database by enabling the logging, Hence, those errors are expected. Once we apply the dump which is taken before the "drop database mysql", the errors will not be there. client/mysqldump.c: In get_table_structure() added code to skip the DROP TABLE stmts for general_log and slow_log tables, because when logging is enabled those stmts will fail. And replaced CREATE TABLE with CREATE IF NOT EXISTS for those tables, just to make sure CREATE stmt for those tables doesn't fail since we removed DROP stmts for those tables. In dump_all_tables_in_db() added code to call get_table_structure() for general_log and slow_log tables. mysql-test/r/mysqldump.result: Added a test as part of fix for Bug #11754178 mysql-test/t/mysqldump.test: Added a test as part of fix for Bug #11754178 --- client/mysqldump.c | 58 +++++++++++++++++++++++++++++++++++++------ mysql-test/r/mysqldump.result | 42 +++++++++++++++++++++++++++++++ mysql-test/t/mysqldump.test | 29 +++++++++++++++++++--- 3 files changed, 118 insertions(+), 11 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 8601b533849..dc124f1b335 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -84,6 +84,15 @@ #define IGNORE_DATA 0x01 /* don't dump data for this table */ #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */ +/* general_log or slow_log tables under mysql database */ +static inline my_bool general_log_or_slow_log_tables(const char *db, + const char *table) +{ + return (strcmp(db, "mysql") == 0) && + ((strcmp(table, "general_log") == 0) || + (strcmp(table, "slow_log") == 0)); +} + static void add_load_option(DYNAMIC_STRING *str, const char *option, const char *option_value); static ulong find_set(TYPELIB *lib, const char *x, uint length, @@ -2458,6 +2467,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, "TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'"; FILE *sql_file= md_result_file; int len; + my_bool is_log_table; MYSQL_RES *result; MYSQL_ROW row; DBUG_ENTER("get_table_structure"); @@ -2542,9 +2552,12 @@ static uint get_table_structure(char *table, char *db, char *table_type, /* Even if the "table" is a view, we do a DROP TABLE here. The view-specific code below fills in the DROP VIEW. + We will skip the DROP TABLE for general_log and slow_log, since + those stmts will fail, in case we apply dump by enabling logging. */ - fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", - opt_quoted_table); + if (!general_log_or_slow_log_tables(db, table)) + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", + opt_quoted_table); check_io(sql_file); } @@ -2656,12 +2669,25 @@ static uint get_table_structure(char *table, char *db, char *table_type, row= mysql_fetch_row(result); - fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" : - "/*!40101 SET @saved_cs_client = @@character_set_client */;\n" - "/*!40101 SET character_set_client = utf8 */;\n" - "%s;\n" - "/*!40101 SET character_set_client = @saved_cs_client */;\n", - row[1]); + is_log_table= general_log_or_slow_log_tables(db, table); + if (is_log_table) + row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */ + if (opt_compatible_mode & 3) + { + fprintf(sql_file, + is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n", + row[1]); + } + else + { + fprintf(sql_file, + "/*!40101 SET @saved_cs_client = @@character_set_client */;\n" + "/*!40101 SET character_set_client = utf8 */;\n" + "%s%s;\n" + "/*!40101 SET character_set_client = @saved_cs_client */;\n", + is_log_table ? "CREATE TABLE IF NOT EXISTS " : "", + row[1]); + } check_io(sql_file); mysql_free_result(result); @@ -4261,6 +4287,22 @@ static int dump_all_tables_in_db(char *database) if (opt_xml) print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); + if (strcmp(database, "mysql") == 0) + { + char table_type[NAME_LEN]; + char ignore_flag; + uint num_fields; + num_fields= get_table_structure((char *) "general_log", + database, table_type, &ignore_flag); + if (num_fields == 0) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'general_log' table\n"); + num_fields= get_table_structure((char *) "slow_log", + database, table_type, &ignore_flag); + if (num_fields == 0) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'slow_log' table\n"); + } if (lock_tables) { DYNAMIC_STRING query; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 1d4a5783c3f..fac94e855a4 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5067,5 +5067,47 @@ RETURN CONCAT(']]]]>, ', s, '!') DROP DATABASE BUG52792; USE test; # +# Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM +# +SET @old_log_output_state= @@global.log_output; +SET @old_general_log_state= @@global.general_log; +SET @old_slow_query_log_state= @@global.slow_query_log; +call mtr.add_suppression("Failed to write to mysql.general_log"); +SET @@global.log_output="TABLE"; +SET @@global.general_log='ON'; +SET @@global.slow_query_log='ON'; +DROP DATABASE mysql; +Warnings: +Error 1146 Table 'mysql.proc' doesn't exist +Error 1146 Table 'mysql.event' doesn't exist +SHOW CREATE TABLE mysql.general_log; +Table Create Table +general_log CREATE TABLE `general_log` ( + `event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `user_host` mediumtext NOT NULL, + `thread_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `command_type` varchar(64) NOT NULL, + `argument` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log' +SHOW CREATE TABLE mysql.slow_log; +Table Create Table +slow_log CREATE TABLE `slow_log` ( + `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `user_host` mediumtext NOT NULL, + `query_time` time NOT NULL, + `lock_time` time NOT NULL, + `rows_sent` int(11) NOT NULL, + `rows_examined` int(11) NOT NULL, + `db` varchar(512) NOT NULL, + `last_insert_id` int(11) NOT NULL, + `insert_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `sql_text` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +SET @@global.log_output= @old_log_output_state; +SET @@global.slow_query_log= @old_slow_query_log_state; +SET @@global.general_log= @old_general_log_state; +# # End of 5.1 tests # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 20c788e3b9a..7393ca88f0a 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2308,9 +2308,32 @@ DROP DATABASE BUG52792; USE test; +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc + --echo # ---echo # End of 5.1 tests +--echo # Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM --echo # +SET @old_log_output_state= @@global.log_output; +SET @old_general_log_state= @@global.general_log; +SET @old_slow_query_log_state= @@global.slow_query_log; -# Wait till we reached the initial number of concurrent sessions ---source include/wait_until_count_sessions.inc +call mtr.add_suppression("Failed to write to mysql.general_log"); +--exec $MYSQL_DUMP -uroot --all-databases > $MYSQLTEST_VARDIR/tmp/bug45740.sql +# Make log_output as table and enable general_log and slow_log +SET @@global.log_output="TABLE"; +SET @@global.general_log='ON'; +SET @@global.slow_query_log='ON'; +DROP DATABASE mysql; +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug45740.sql +SHOW CREATE TABLE mysql.general_log; +SHOW CREATE TABLE mysql.slow_log; +--remove_file $MYSQLTEST_VARDIR/tmp/bug45740.sql + +SET @@global.log_output= @old_log_output_state; +SET @@global.slow_query_log= @old_slow_query_log_state; +SET @@global.general_log= @old_general_log_state; + +--echo # +--echo # End of 5.1 tests +--echo # -- cgit v1.2.1 From 391ea219c21a66e24ea9985ca2581f75bbd7c8f5 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Thu, 10 May 2012 10:18:31 +0530 Subject: Bug #14007649 65111: INNODB SOMETIMES FAILS TO UPDATE ROWS INSERTED BY A CONCURRENT TRANSACTIO The member function QUICK_RANGE_SELECT::init_ror_merged_scan() performs a table handler clone. Innodb does not provide a clone operation. The ha_innobase::clone() is not there. The handler::clone() does not take care of the ha_innobase->prebuilt->select_lock_type. Because of this what happens is that for one index we do a locking read, and for the other index we were doing a non-locking (consistent) read. The patch introduces ha_innobase::clone() member function. It is implemented similar to ha_myisam::clone(). It calls the base class handler::clone() and then does any additional operation required. I am setting the ha_innobase->prebuilt->select_lock_type correctly. rb://1060 approved by Marko --- .../suite/innodb/r/innodb_bug14007649.result | 56 +++++++++++++++++++++ mysql-test/suite/innodb/t/innodb_bug14007649.test | 58 ++++++++++++++++++++++ .../innodb_plugin/r/innodb_bug14007649.result | 56 +++++++++++++++++++++ .../suite/innodb_plugin/t/innodb_bug14007649.test | 58 ++++++++++++++++++++++ storage/innobase/btr/btr0cur.c | 2 + storage/innobase/handler/ha_innodb.cc | 24 +++++++++ storage/innobase/handler/ha_innodb.h | 1 + storage/innodb_plugin/btr/btr0cur.c | 2 + storage/innodb_plugin/handler/ha_innodb.cc | 25 ++++++++++ storage/innodb_plugin/handler/ha_innodb.h | 1 + 10 files changed, 283 insertions(+) create mode 100644 mysql-test/suite/innodb/r/innodb_bug14007649.result create mode 100644 mysql-test/suite/innodb/t/innodb_bug14007649.test create mode 100644 mysql-test/suite/innodb_plugin/r/innodb_bug14007649.result create mode 100644 mysql-test/suite/innodb_plugin/t/innodb_bug14007649.test diff --git a/mysql-test/suite/innodb/r/innodb_bug14007649.result b/mysql-test/suite/innodb/r/innodb_bug14007649.result new file mode 100644 index 00000000000..1f802dcd146 --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb_bug14007649.result @@ -0,0 +1,56 @@ +create table t1 ( +rowid int, +f1 int, +f2 int, +key i1 (f1, f2), +key i2 (f2)) engine=innodb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `rowid` int(11) DEFAULT NULL, + `f1` int(11) DEFAULT NULL, + `f2` int(11) DEFAULT NULL, + KEY `i1` (`f1`,`f2`), + KEY `i2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL); +start transaction with consistent snapshot; +start transaction; +update t1 set f2 = 4 where f1 = 1 and f2 is null; +(b) Number of rows updated: +select row_count(); +row_count() +1 +insert into t1 values (3, 1, null); +(b) After update and insert query. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 4 +3 1 NULL +commit; +(a) Before the update statement is executed. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 NULL +SET SESSION debug="+d,bug14007649"; +update t1 set f2 = 6 where f1 = 1 and f2 is null; +(a) Number of rows updated: +select row_count(); +row_count() +1 +(a) After the update statement is executed. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 NULL +3 1 6 +commit; +"The trx with consistent snapshot ended." +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 4 +3 1 6 +drop table t1; diff --git a/mysql-test/suite/innodb/t/innodb_bug14007649.test b/mysql-test/suite/innodb/t/innodb_bug14007649.test new file mode 100644 index 00000000000..2832bd41f3c --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb_bug14007649.test @@ -0,0 +1,58 @@ +--source include/have_innodb.inc +--source include/have_debug.inc + +create table t1 ( + rowid int, + f1 int, + f2 int, + key i1 (f1, f2), + key i2 (f2)) engine=innodb; + +show create table t1; +insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL); + +connect (a,localhost,root,,); +connect (b,localhost,root,,); + +connection a; +start transaction with consistent snapshot; + +connection b; +start transaction; +update t1 set f2 = 4 where f1 = 1 and f2 is null; + +-- echo (b) Number of rows updated: +select row_count(); + +insert into t1 values (3, 1, null); + +-- echo (b) After update and insert query. +select rowid, f1, f2 from t1; + +commit; + +connection a; + +-- echo (a) Before the update statement is executed. +select rowid, f1, f2 from t1; + +SET SESSION debug="+d,bug14007649"; +update t1 set f2 = 6 where f1 = 1 and f2 is null; + +-- echo (a) Number of rows updated: +select row_count(); + +-- echo (a) After the update statement is executed. +select rowid, f1, f2 from t1; + +commit; + +--echo "The trx with consistent snapshot ended." + +select rowid, f1, f2 from t1; + +connection default; +disconnect a; +disconnect b; + +drop table t1; diff --git a/mysql-test/suite/innodb_plugin/r/innodb_bug14007649.result b/mysql-test/suite/innodb_plugin/r/innodb_bug14007649.result new file mode 100644 index 00000000000..1f802dcd146 --- /dev/null +++ b/mysql-test/suite/innodb_plugin/r/innodb_bug14007649.result @@ -0,0 +1,56 @@ +create table t1 ( +rowid int, +f1 int, +f2 int, +key i1 (f1, f2), +key i2 (f2)) engine=innodb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `rowid` int(11) DEFAULT NULL, + `f1` int(11) DEFAULT NULL, + `f2` int(11) DEFAULT NULL, + KEY `i1` (`f1`,`f2`), + KEY `i2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL); +start transaction with consistent snapshot; +start transaction; +update t1 set f2 = 4 where f1 = 1 and f2 is null; +(b) Number of rows updated: +select row_count(); +row_count() +1 +insert into t1 values (3, 1, null); +(b) After update and insert query. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 4 +3 1 NULL +commit; +(a) Before the update statement is executed. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 NULL +SET SESSION debug="+d,bug14007649"; +update t1 set f2 = 6 where f1 = 1 and f2 is null; +(a) Number of rows updated: +select row_count(); +row_count() +1 +(a) After the update statement is executed. +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 NULL +3 1 6 +commit; +"The trx with consistent snapshot ended." +select rowid, f1, f2 from t1; +rowid f1 f2 +1 1 10 +2 1 4 +3 1 6 +drop table t1; diff --git a/mysql-test/suite/innodb_plugin/t/innodb_bug14007649.test b/mysql-test/suite/innodb_plugin/t/innodb_bug14007649.test new file mode 100644 index 00000000000..e1d27ecd742 --- /dev/null +++ b/mysql-test/suite/innodb_plugin/t/innodb_bug14007649.test @@ -0,0 +1,58 @@ +--source include/have_innodb_plugin.inc +--source include/have_debug.inc + +create table t1 ( + rowid int, + f1 int, + f2 int, + key i1 (f1, f2), + key i2 (f2)) engine=innodb; + +show create table t1; +insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL); + +connect (a,localhost,root,,); +connect (b,localhost,root,,); + +connection a; +start transaction with consistent snapshot; + +connection b; +start transaction; +update t1 set f2 = 4 where f1 = 1 and f2 is null; + +-- echo (b) Number of rows updated: +select row_count(); + +insert into t1 values (3, 1, null); + +-- echo (b) After update and insert query. +select rowid, f1, f2 from t1; + +commit; + +connection a; + +-- echo (a) Before the update statement is executed. +select rowid, f1, f2 from t1; + +SET SESSION debug="+d,bug14007649"; +update t1 set f2 = 6 where f1 = 1 and f2 is null; + +-- echo (a) Number of rows updated: +select row_count(); + +-- echo (a) After the update statement is executed. +select rowid, f1, f2 from t1; + +commit; + +--echo "The trx with consistent snapshot ended." + +select rowid, f1, f2 from t1; + +connection default; +disconnect a; +disconnect b; + +drop table t1; diff --git a/storage/innobase/btr/btr0cur.c b/storage/innobase/btr/btr0cur.c index c09d6408fa0..4678ea8cd22 100644 --- a/storage/innobase/btr/btr0cur.c +++ b/storage/innobase/btr/btr0cur.c @@ -2792,6 +2792,8 @@ btr_estimate_n_rows_in_range( n_rows = n_rows * 2; } + DBUG_EXECUTE_IF("bug14007649", return(n_rows);); + /* Do not estimate the number of rows in the range to over 1 / 2 of the estimated rows in the whole table */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 6576016501f..8ed082037f0 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -3180,6 +3180,30 @@ table_opened: DBUG_RETURN(0); } +handler* +ha_innobase::clone( +/*===============*/ + const char* name, /*!< in: table name */ + MEM_ROOT* mem_root) /*!< in: memory context */ +{ + ha_innobase* new_handler; + + DBUG_ENTER("ha_innobase::clone"); + + new_handler = static_cast(handler::clone(name, + mem_root)); + if (new_handler) { + DBUG_ASSERT(new_handler->prebuilt != NULL); + DBUG_ASSERT(new_handler->user_thd == user_thd); + DBUG_ASSERT(new_handler->prebuilt->trx == prebuilt->trx); + + new_handler->prebuilt->select_lock_type + = prebuilt->select_lock_type; + } + + DBUG_RETURN(new_handler); +} + uint ha_innobase::max_supported_key_part_length() const { diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 8b91f7d4c51..93229ad9185 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -117,6 +117,7 @@ class ha_innobase: public handler const key_map *keys_to_use_for_scanning() { return &key_map_full; } int open(const char *name, int mode, uint test_if_locked); + handler* clone(const char *name, MEM_ROOT *mem_root); int close(void); double scan_time(); double read_time(uint index, uint ranges, ha_rows rows); diff --git a/storage/innodb_plugin/btr/btr0cur.c b/storage/innodb_plugin/btr/btr0cur.c index b67da53ec8a..223b976dea7 100644 --- a/storage/innodb_plugin/btr/btr0cur.c +++ b/storage/innodb_plugin/btr/btr0cur.c @@ -3194,6 +3194,8 @@ btr_estimate_n_rows_in_range( n_rows = n_rows * 2; } + DBUG_EXECUTE_IF("bug14007649", return(n_rows);); + /* Do not estimate the number of rows in the range to over 1 / 2 of the estimated rows in the whole table */ diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index ca6788999ae..2207f9d009d 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -3889,6 +3889,31 @@ table_opened: DBUG_RETURN(0); } +UNIV_INTERN +handler* +ha_innobase::clone( +/*===============*/ + const char* name, /*!< in: table name */ + MEM_ROOT* mem_root) /*!< in: memory context */ +{ + ha_innobase* new_handler; + + DBUG_ENTER("ha_innobase::clone"); + + new_handler = static_cast(handler::clone(name, + mem_root)); + if (new_handler) { + DBUG_ASSERT(new_handler->prebuilt != NULL); + DBUG_ASSERT(new_handler->user_thd == user_thd); + DBUG_ASSERT(new_handler->prebuilt->trx == prebuilt->trx); + + new_handler->prebuilt->select_lock_type + = prebuilt->select_lock_type; + } + + DBUG_RETURN(new_handler); +} + UNIV_INTERN uint ha_innobase::max_supported_key_part_length() const diff --git a/storage/innodb_plugin/handler/ha_innodb.h b/storage/innodb_plugin/handler/ha_innodb.h index f7a5456b1a7..15cc4a77b6f 100644 --- a/storage/innodb_plugin/handler/ha_innodb.h +++ b/storage/innodb_plugin/handler/ha_innodb.h @@ -132,6 +132,7 @@ class ha_innobase: public handler const key_map* keys_to_use_for_scanning(); int open(const char *name, int mode, uint test_if_locked); + handler* clone(const char *name, MEM_ROOT *mem_root); int close(void); double scan_time(); double read_time(uint index, uint ranges, ha_rows rows); -- cgit v1.2.1 From da5214831d3d0f0880b4068a06ce062ca703293f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 May 2012 13:46:05 +0300 Subject: Fix for bug lp:944706, task MDEV-193 The patch enables back constant subquery execution during query optimization after it was disabled during the development of MWL#89 (cost-based choice of IN-TO-EXISTS vs MATERIALIZATION). The main idea is that constant subqueries are allowed to be executed during optimization if their execution is not expensive. The approach is as follows: - Constant subqueries are recursively optimized in the beginning of JOIN::optimize of the outer query. This is done by the new method JOIN::optimize_constant_subqueries(). This is done so that the cost of executing these queries can be estimated. - Optimization of the outer query proceeds normally. During this phase the optimizer may request execution of non-expensive constant subqueries. Each place where the optimizer may potentially execute an expensive expression is guarded with the predicate Item::is_expensive(). - The implementation of Item_subselect::is_expensive has been extended to use the number of examined rows (estimated by the optimizer) as a way to determine whether the subquery is expensive or not. - The new system variable "expensive_subquery_limit" controls how many examined rows are considered to be not expensive. The default is 100. In addition, multiple changes were needed to make this solution work in the light of the changes made by MWL#89. These changes were needed to fix various crashes and wrong results, and legacy bugs discovered during development. --- mysql-test/r/explain.result | 12 +- mysql-test/r/group_min_max.result | 22 ++-- mysql-test/r/join_outer.result | 4 +- mysql-test/r/join_outer_jcl6.result | 4 +- mysql-test/r/key.result | 4 +- mysql-test/r/limit_rows_examined.result | 2 +- mysql-test/r/myisam_mrr.result | 4 +- mysql-test/r/mysqld--help.result | 5 + mysql-test/r/subselect.result | 92 ++++++++++----- mysql-test/r/subselect3.result | 2 +- mysql-test/r/subselect3_jcl6.result | 2 +- mysql-test/r/subselect4.result | 35 +++--- mysql-test/r/subselect_cache.result | 8 +- mysql-test/r/subselect_innodb.result | 6 +- mysql-test/r/subselect_mat.result | 36 +++--- mysql-test/r/subselect_mat_cost_bugs.result | 4 +- mysql-test/r/subselect_no_mat.result | 98 ++++++++++------ mysql-test/r/subselect_no_opts.result | 98 ++++++++++------ mysql-test/r/subselect_no_scache.result | 92 ++++++++++----- mysql-test/r/subselect_no_semijoin.result | 102 +++++++++++------ mysql-test/r/subselect_sj_mat.result | 18 +-- mysql-test/suite/sys_vars/r/all_vars.result | 1 + mysql-test/t/subselect.test | 32 ++++++ mysql-test/t/subselect4.test | 8 ++ sql/item.h | 12 +- sql/item_cmpfunc.cc | 10 +- sql/item_cmpfunc.h | 4 +- sql/item_strfunc.h | 2 +- sql/item_subselect.cc | 42 +++++++ sql/item_subselect.h | 8 +- sql/opt_subselect.cc | 47 +++++++- sql/sql_class.h | 1 + sql/sql_delete.cc | 2 +- sql/sql_lex.cc | 26 ++++- sql/sql_lex.h | 7 +- sql/sql_select.cc | 169 ++++++++++++++++++---------- sql/sql_select.h | 3 + sql/sql_update.cc | 2 +- sql/sys_vars.cc | 7 +- sql/table.cc | 8 +- 40 files changed, 714 insertions(+), 327 deletions(-) diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index a6fa21ad800..863526c637e 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -260,7 +260,7 @@ FLUSH TABLES; EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT 1 FROM t1 t JOIN t2 WHERE b <= 1 AND t.a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table DROP TABLE t1, t2; # # Bug #48573: difference of index selection between rpm binary and @@ -287,7 +287,7 @@ WHERE t1.f1 GROUP BY t1.f1)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a @@ -297,12 +297,12 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 DEALLOCATE PREPARE stmt; PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 @@ -313,12 +313,12 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index c5c5f65df29..95caa6853b8 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -2398,12 +2398,12 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index -2 SUBQUERY t1 index NULL a 10 NULL 1 Using index +2 SUBQUERY t1 index NULL a 10 NULL 15 Using index EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index -2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY t1 index NULL a 10 NULL 15 Using index EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra @@ -2419,9 +2419,9 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2 ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) AND t1_outer1.b = t1_outer2.b; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer1 ref a a 5 const 2 Using where; Using index +1 PRIMARY t1_outer1 ref a a 5 const 1 Using where; Using index 1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join) -2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by +2 SUBQUERY t1 index NULL a 10 NULL 15 Using index EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2; id select_type table type possible_keys key key_len ref rows Extra @@ -2756,8 +2756,8 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) NULL @@ -2828,8 +2828,8 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) NULL @@ -2907,8 +2907,8 @@ NULL EXPLAIN SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); id select_type table type possible_keys key key_len ref rows Extra -x x x x x x x x x Using where; Using index -x x x x x x x x x Using where; Using index +x x x x x x x x x Impossible WHERE noticed after reading const tables +x x x x x x x x x Using index SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); MIN( a ) NULL diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index ebe8255fd8b..49a6a0d76d3 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1871,10 +1871,10 @@ EXPLAIN EXTENDED SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where +1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where 1 +Note 1003 select NULL AS `a` from `test`.`t2` where 1 DROP TABLE t1,t2,t3; # # LP bug #817384 Wrong result with outer join + subquery in ON diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 3d0e4cbfc79..d1333136f1c 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1882,10 +1882,10 @@ EXPLAIN EXTENDED SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where +1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where 1 +Note 1003 select NULL AS `a` from `test`.`t2` where 1 DROP TABLE t1,t2,t3; # # LP bug #817384 Wrong result with outer join + subquery in ON diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index 4035f61e36b..e215caadb1c 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -598,8 +598,8 @@ VALUES EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index -2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY t1 index NULL a 10 NULL 15 Using index SELECT 1 as RES FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; RES diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result index f4242f17a14..3a5212818ef 100644 --- a/mysql-test/r/limit_rows_examined.result +++ b/mysql-test/r/limit_rows_examined.result @@ -679,7 +679,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 Using temporary 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Distinct 2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 -2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 SELECT DISTINCT a AS field1 FROM t1, t2 WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; diff --git a/mysql-test/r/myisam_mrr.result b/mysql-test/r/myisam_mrr.result index d4b25f25d40..03d212dbc04 100644 --- a/mysql-test/r/myisam_mrr.result +++ b/mysql-test/r/myisam_mrr.result @@ -349,10 +349,10 @@ WHERE t2.int_key IS NULL GROUP BY t2.pk ); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 SUBQUERY t2 ref int_key int_key 5 const 1 100.00 Using index condition Warnings: -Note 1003 select min(1) AS `MIN(t1.pk)` from dual where exists(select `test`.`t2`.`pk` from `test`.`t2` where isnull(`test`.`t2`.`int_key`)) +Note 1003 select min(`test`.`t1`.`pk`) AS `MIN(t1.pk)` from `test`.`t1` where 0 DROP TABLE t1, t2; # # BUG#42048 Discrepancy between MyISAM and Maria's ICP implementation diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index fcadee7aced..ad55bfa3003 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -159,6 +159,10 @@ The following options may be given as the first argument: Enable the event scheduler. Possible values are ON, OFF, and DISABLED (keep the event scheduler completely deactivated, it cannot be activated run-time) + --expensive-subquery-limit=# + The maximum number of rows a subquery may examine in + order to be executed during optimization and used for + constant optimization --expire-logs-days=# If non-zero, binary logs will be purged after expire_logs_days days; possible purges happen at startup @@ -885,6 +889,7 @@ delayed-queue-size 1000 div-precision-increment 4 engine-condition-pushdown FALSE event-scheduler OFF +expensive-subquery-limit 100 expire-logs-days 0 external-locking FALSE extra-max-connections 1 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index dca872f0bbd..a75d0f960af 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -371,12 +371,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index -2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index Warnings: -Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -517,6 +517,7 @@ ERROR 21000: Subquery returns more than 1 row show warnings; Level Code Message Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row drop table t1; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -547,11 +548,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index -2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index -Warnings: -Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1')))) +ERROR 21000: Subquery returns more than 1 row SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); ERROR 21000: Subquery returns more than 1 row EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; @@ -1675,34 +1672,34 @@ select * from t3 where NULL >= any (select b from t2); a explain extended select * from t3 where NULL >= any (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= any (select b from t2 group by 1); a explain extended select * from t3 where NULL >= any (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2); a explain extended select * from t3 where NULL >= some (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2 group by 1); a explain extended select * from t3 where NULL >= some (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 insert into t2 values (2,2), (2,1), (3,3), (3,1); select * from t3 where a > all (select max(b) from t2 group by a); a @@ -1764,7 +1761,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION t1 system NULL NULL NULL NULL 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 select 'e' AS `s1` from dual where (('f',((select 'e' from dual union select 'e' from dual) < 'f'))) +Note 1003 select 'e' AS `s1` from dual where 1 drop table t1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); @@ -3099,7 +3096,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3111,7 +3108,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3727,8 +3724,8 @@ explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found -3 UNION t12 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table NULL UNION RESULT ALL NULL NULL NULL NULL NULL DROP TABLE t1; CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); @@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref a a 5 const 0 Using where; Using index -2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort DROP TABLE t1; CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -4626,7 +4623,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where ((1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); 1 1 @@ -5960,7 +5957,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) @@ -6121,7 +6118,7 @@ set optimizer_switch=@tmp_optimizer_switch; EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # @@ -6562,5 +6559,40 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE COUNT(f1) f4 0 0 drop table t1,t2; +# +# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result index 014ff5b5810..b33e7e113f2 100644 --- a/mysql-test/r/subselect3.result +++ b/mysql-test/r/subselect3.result @@ -1479,7 +1479,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(<(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9))>(((select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)),(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)) in ( (select `test`.`t3`.`b` from `test`.`t3` ), (9 in on distinct_key where ((9 = ``.`b`)))))))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1 SELECT * FROM t1 WHERE ( ( SELECT a FROM t2 WHERE a = 9 ), diff --git a/mysql-test/r/subselect3_jcl6.result b/mysql-test/r/subselect3_jcl6.result index a62048db506..4660cd60603 100644 --- a/mysql-test/r/subselect3_jcl6.result +++ b/mysql-test/r/subselect3_jcl6.result @@ -1489,7 +1489,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(<(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9))>(((select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)),(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)) in ( (select `test`.`t3`.`b` from `test`.`t3` ), (9 in on distinct_key where ((9 = ``.`b`)))))))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1 SELECT * FROM t1 WHERE ( ( SELECT a FROM t2 WHERE a = 9 ), diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index 82360f9fe9f..c17ffe75282 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -562,7 +562,7 @@ WHERE f3 = ( SELECT t1.f3 FROM t1 WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 )); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref f3 f3 5 const 0 Using where +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY eq_ref distinct_key distinct_key 4 func 1 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 @@ -577,7 +577,7 @@ WHERE f3 = ( SELECT f3 FROM t1 WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 )); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref f3 f3 5 const 0 Using where +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY eq_ref distinct_key distinct_key 8 func,func 1 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 @@ -1220,6 +1220,13 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where 3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary 3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +SELECT * FROM t1 WHERE +(SELECT f2 FROM t2 +WHERE f4 <= ALL +(SELECT max(SQ1_t1.f4) +FROM t3 AS SQ1_t1 JOIN t3 AS SQ1_t3 ON SQ1_t3.f4 +GROUP BY SQ1_t1.f4)); +ERROR 21000: Subquery returns more than 1 row drop table t1, t2, t3; # # BUG#52317: Assertion failing in Field_varstring::store() @@ -1250,8 +1257,7 @@ FROM t2 JOIN t1 ON t1.f3 WHERE ('v') IN (SELECT f4 FROM t2) GROUP BY f9; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), @@ -1267,8 +1273,7 @@ FROM t2 JOIN t1 ON t1.f3 WHERE ('v') IN (SELECT f4 FROM t2) ORDER BY f9; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), @@ -1277,7 +1282,7 @@ FROM t2 JOIN t1 ON t1.f3 WHERE ('v') IN (SELECT f4 FROM t2) ORDER BY f9; COUNT(t2.f3) f9 -0 2 +0 NULL EXPLAIN SELECT COUNT(t2.f3), (SELECT t2.f1 FROM t1 limit 1) AS f9 @@ -1285,8 +1290,7 @@ FROM t2 JOIN t1 WHERE ('v') IN (SELECT f4 FROM t2) GROUP BY f9; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), @@ -1302,8 +1306,7 @@ FROM t2 JOIN t1 WHERE ('v') IN (SELECT f4 FROM t2) ORDER BY f9; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), @@ -1325,7 +1328,7 @@ EXPLAIN SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 -2 SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1; field1 NULL @@ -1333,7 +1336,7 @@ EXPLAIN SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 -2 SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1; field1 NULL @@ -1631,7 +1634,7 @@ SET SESSION optimizer_switch='in_to_exists=on,materialization=off'; EXPLAIN SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1 2 DEPENDENT SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); @@ -1852,8 +1855,8 @@ GROUP BY 1, 2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 system NULL NULL NULL NULL 1 Using temporary; Using filesort 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where -2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 MATERIALIZED t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table PREPARE st1 FROM " SELECT t2.f1, (SELECT f2 FROM t1 WHERE (7) IN (SELECT f1 FROM t1)) FROM t2 JOIN t3 ON t3.f4 = t2.f4 diff --git a/mysql-test/r/subselect_cache.result b/mysql-test/r/subselect_cache.result index e38e8b42e9a..7bd10dc11a6 100644 --- a/mysql-test/r/subselect_cache.result +++ b/mysql-test/r/subselect_cache.result @@ -486,9 +486,9 @@ Handler_read_key 7 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 -Handler_read_rnd 10 +Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 42 +Handler_read_rnd_next 31 set optimizer_switch='subquery_cache=off'; flush status; select a from t1 ORDER BY (select d from t2 where b=c); @@ -514,9 +514,9 @@ Handler_read_key 0 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 -Handler_read_rnd 10 +Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 72 +Handler_read_rnd_next 61 set optimizer_switch='subquery_cache=on'; #single value subquery test (distinct ORDER BY) flush status; diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result index 60faea8853f..bbaf26e6249 100644 --- a/mysql-test/r/subselect_innodb.result +++ b/mysql-test/r/subselect_innodb.result @@ -272,8 +272,8 @@ FROM t2 WHERE (SELECT DISTINCT b FROM t3) > 0); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using where; Using index -2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 -3 SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using temporary +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +3 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 0 Using temporary SELECT * FROM t1 WHERE t1.a = ( @@ -301,7 +301,7 @@ GROUP BY 1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t1 ALL NULL NULL NULL NULL 1 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 3 SUBQUERY t3 ALL NULL NULL NULL NULL 1 SELECT MAX( f1 ) FROM t2 WHERE f2 >= ( diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 86442df1e8b..323da97cc89 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -1152,8 +1152,8 @@ create table t2 (b1 int); insert into t1 values (5); explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 MATERIALIZED t2 system NULL NULL NULL NULL 0 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); min(a1) NULL @@ -1162,8 +1162,8 @@ set @@optimizer_switch=@optimizer_switch_local_default; set @@optimizer_switch='materialization=off,in_to_exists=on'; explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); min(a1) NULL @@ -1171,8 +1171,8 @@ set @@optimizer_switch=@optimizer_switch_local_default; set @@optimizer_switch='semijoin=off'; explain select min(a1) from t1 where 7 in (select b1 from t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 MATERIALIZED t2 system NULL NULL NULL NULL 0 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2); min(a1) NULL @@ -1181,16 +1181,16 @@ set @@optimizer_switch='materialization=off,in_to_exists=on'; # with MariaDB and MWL#90, this particular case is solved: explain select min(a1) from t1 where 7 in (select b1 from t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2); min(a1) NULL # but when we go around MWL#90 code, the problem still shows up: explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; min(a1) NULL @@ -1932,7 +1932,7 @@ WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index -2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index 2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 SELECT a, c FROM t1, t2 @@ -1951,8 +1951,8 @@ WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index -2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index -2 MATERIALIZED s1 hash_ALL NULL #hash#$hj 5 test.s2.d 8 Using where; Using join buffer (flat, BNLH join) +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 SELECT a, c FROM t1, t2 WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 @@ -2153,7 +2153,7 @@ set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_ EXPLAIN SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); @@ -2222,10 +2222,10 @@ NULL EXPLAIN EXTENDED SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 index NULL b 5 NULL 2 100.00 Using index +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where <9>((9,9 in ( (select `test`.`t2`.`a` from `test`.`t2` ), (9 in on distinct_key where ((9 = ``.`a`)))))) +Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off'; SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); max_res @@ -2233,10 +2233,10 @@ NULL EXPLAIN EXTENDED SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 index NULL b 5 NULL 2 100.00 Using index +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where <9>((9,(select `test`.`t2`.`a` from `test`.`t2` where (9 = `test`.`t2`.`a`)))) +Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 DROP TABLE t1,t2; # # LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index 96f904c722c..e656bf8e22f 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -124,7 +124,7 @@ FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT t1.* FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); @@ -148,7 +148,7 @@ FROM t2 GROUP BY f1 id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t1 system NULL NULL NULL NULL 1 -3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +3 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort drop table t1, t2, t3; # # LP BUG#715034 Item_sum_distinct::clear(): Assertion `tree != 0' failed diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index d5c7084c48d..507c8741d25 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -378,12 +378,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index -2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index Warnings: -Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -524,6 +524,7 @@ ERROR 21000: Subquery returns more than 1 row show warnings; Level Code Message Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row drop table t1; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -554,11 +555,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index -2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index -Warnings: -Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1')))) +ERROR 21000: Subquery returns more than 1 row SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); ERROR 21000: Subquery returns more than 1 row EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; @@ -1682,34 +1679,34 @@ select * from t3 where NULL >= any (select b from t2); a explain extended select * from t3 where NULL >= any (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= any (select b from t2 group by 1); a explain extended select * from t3 where NULL >= any (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2); a explain extended select * from t3 where NULL >= some (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2 group by 1); a explain extended select * from t3 where NULL >= some (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 insert into t2 values (2,2), (2,1), (3,3), (3,1); select * from t3 where a > all (select max(b) from t2 group by a); a @@ -1771,7 +1768,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION t1 system NULL NULL NULL NULL 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 select 'e' AS `s1` from dual where (('f',((select 'e' from dual union select 'e' from dual) < 'f'))) +Note 1003 select 'e' AS `s1` from dual where 1 drop table t1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); @@ -3105,7 +3102,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3117,7 +3114,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3731,8 +3728,8 @@ explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found -3 UNION t12 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table NULL UNION RESULT ALL NULL NULL NULL NULL NULL DROP TABLE t1; CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); @@ -4202,8 +4199,8 @@ CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref a a 5 const 0 Using where; Using index -2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort DROP TABLE t1; CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -4531,13 +4528,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where <1>((1,(select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` having (1 = (min(`test`.`t1`.`a`)))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where <1>((1,(select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = (min(`test`.`t1`.`a`)))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; DROP TABLE t1; # @@ -4628,7 +4625,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where ((1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); 1 1 @@ -5961,7 +5958,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) @@ -6120,7 +6117,7 @@ set optimizer_switch=@tmp_optimizer_switch; EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # @@ -6561,6 +6558,41 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE COUNT(f1) f4 0 0 drop table t1,t2; +# +# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 7b44b1a1f5d..9ca09ac061c 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -374,12 +374,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index -2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index Warnings: -Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -520,6 +520,7 @@ ERROR 21000: Subquery returns more than 1 row show warnings; Level Code Message Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row drop table t1; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -550,11 +551,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index -2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index -Warnings: -Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1')))) +ERROR 21000: Subquery returns more than 1 row SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); ERROR 21000: Subquery returns more than 1 row EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; @@ -1678,34 +1675,34 @@ select * from t3 where NULL >= any (select b from t2); a explain extended select * from t3 where NULL >= any (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= any (select b from t2 group by 1); a explain extended select * from t3 where NULL >= any (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2); a explain extended select * from t3 where NULL >= some (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2 group by 1); a explain extended select * from t3 where NULL >= some (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 insert into t2 values (2,2), (2,1), (3,3), (3,1); select * from t3 where a > all (select max(b) from t2 group by a); a @@ -1767,7 +1764,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION t1 system NULL NULL NULL NULL 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 select 'e' AS `s1` from dual where (('f',((select 'e' from dual union select 'e' from dual) < 'f'))) +Note 1003 select 'e' AS `s1` from dual where 1 drop table t1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); @@ -3101,7 +3098,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3113,7 +3110,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3727,8 +3724,8 @@ explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found -3 UNION t12 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table NULL UNION RESULT ALL NULL NULL NULL NULL NULL DROP TABLE t1; CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); @@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref a a 5 const 0 Using where; Using index -2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort DROP TABLE t1; CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -4527,13 +4524,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where (1,(select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` having (1 = (min(`test`.`t1`.`a`))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where (1,(select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = (min(`test`.`t1`.`a`))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; DROP TABLE t1; # @@ -4624,7 +4621,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where ((1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); 1 1 @@ -5957,7 +5954,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) @@ -6116,7 +6113,7 @@ set optimizer_switch=@tmp_optimizer_switch; EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # @@ -6557,6 +6554,41 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE COUNT(f1) f4 0 0 drop table t1,t2; +# +# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 9b24af0dc3a..f7a8e8efd01 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -377,12 +377,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index -2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index Warnings: -Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -523,6 +523,7 @@ ERROR 21000: Subquery returns more than 1 row show warnings; Level Code Message Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row drop table t1; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -553,11 +554,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index -2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index -Warnings: -Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1')))) +ERROR 21000: Subquery returns more than 1 row SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); ERROR 21000: Subquery returns more than 1 row EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; @@ -1681,34 +1678,34 @@ select * from t3 where NULL >= any (select b from t2); a explain extended select * from t3 where NULL >= any (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= any (select b from t2 group by 1); a explain extended select * from t3 where NULL >= any (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2); a explain extended select * from t3 where NULL >= some (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2 group by 1); a explain extended select * from t3 where NULL >= some (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 insert into t2 values (2,2), (2,1), (3,3), (3,1); select * from t3 where a > all (select max(b) from t2 group by a); a @@ -1770,7 +1767,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION t1 system NULL NULL NULL NULL 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 select 'e' AS `s1` from dual where (('f',((select 'e' from dual union select 'e' from dual) < 'f'))) +Note 1003 select 'e' AS `s1` from dual where 1 drop table t1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); @@ -3105,7 +3102,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3117,7 +3114,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3733,8 +3730,8 @@ explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found -3 UNION t12 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table NULL UNION RESULT ALL NULL NULL NULL NULL NULL DROP TABLE t1; CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); @@ -4204,8 +4201,8 @@ CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref a a 5 const 0 Using where; Using index -2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort DROP TABLE t1; CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -4632,7 +4629,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where ((1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); 1 1 @@ -5966,7 +5963,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) @@ -6127,7 +6124,7 @@ set optimizer_switch=@tmp_optimizer_switch; EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # @@ -6568,6 +6565,41 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE COUNT(f1) f4 0 0 drop table t1,t2; +# +# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index ba42ff881fc..f0186c682a4 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -374,12 +374,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index -2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index Warnings: -Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -520,6 +520,7 @@ ERROR 21000: Subquery returns more than 1 row show warnings; Level Code Message Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row drop table t1; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -550,11 +551,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index -2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index -Warnings: -Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1')))) +ERROR 21000: Subquery returns more than 1 row SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); ERROR 21000: Subquery returns more than 1 row EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; @@ -1678,34 +1675,34 @@ select * from t3 where NULL >= any (select b from t2); a explain extended select * from t3 where NULL >= any (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= any (select b from t2 group by 1); a explain extended select * from t3 where NULL >= any (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2); a explain extended select * from t3 where NULL >= some (select b from t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 select * from t3 where NULL >= some (select b from t2 group by 1); a explain extended select * from t3 where NULL >= some (select b from t2 group by 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 -2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table Warnings: -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where ((NULL,((select min(NULL) from `test`.`t2`) <= NULL))) +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 insert into t2 values (2,2), (2,1), (3,3), (3,1); select * from t3 where a > all (select max(b) from t2 group by a); a @@ -1767,7 +1764,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION t1 system NULL NULL NULL NULL 1 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 select 'e' AS `s1` from dual where (('f',((select 'e' from dual union select 'e' from dual) < 'f'))) +Note 1003 select 'e' AS `s1` from dual where 1 drop table t1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); @@ -3101,7 +3098,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3113,7 +3110,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' @@ -3727,8 +3724,8 @@ explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found -3 UNION t12 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table NULL UNION RESULT ALL NULL NULL NULL NULL NULL DROP TABLE t1; CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); @@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref a a 5 const 0 Using where; Using index -2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort DROP TABLE t1; CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -4525,15 +4522,15 @@ SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where <1>((1,1 in ( (select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` ), (1 in on distinct_key where ((1 = ``.`min(a)`)))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where <1>((1,1 in ( (select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` ), (1 in on distinct_key where ((1 = ``.`min(a)`)))))) +Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; DROP TABLE t1; # @@ -4624,7 +4621,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: -Note 1003 select 1 AS `1` from `test`.`t1` where ((1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) +Note 1003 select 1 AS `1` from `test`.`t1` where 1 SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); 1 1 @@ -5957,7 +5954,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) @@ -6116,7 +6113,7 @@ set optimizer_switch=@tmp_optimizer_switch; EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -2 SUBQUERY t1 ref a a 5 const 1 Using index +2 SUBQUERY t1 ref a a 5 const 1 DROP TABLE t1; # @@ -6557,6 +6554,41 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE COUNT(f1) f4 0 0 drop table t1,t2; +# +# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index dc1d9b407fd..d329c31fd16 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -1197,8 +1197,8 @@ set @@optimizer_switch=@optimizer_switch_local_default; set @@optimizer_switch='materialization=off,in_to_exists=on'; explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); min(a1) NULL @@ -1206,8 +1206,8 @@ set @@optimizer_switch=@optimizer_switch_local_default; set @@optimizer_switch='semijoin=off'; explain select min(a1) from t1 where 7 in (select b1 from t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2); min(a1) NULL @@ -1223,8 +1223,8 @@ NULL # but when we go around MWL#90 code, the problem still shows up: explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; min(a1) NULL @@ -1971,7 +1971,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t2 index c c 5 NULL 8 Using index 1 PRIMARY eq_ref distinct_key distinct_key 8 func,func 1 -2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index 2 MATERIALIZED s1 ALL c NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 SELECT a, c FROM t1, t2 @@ -1991,8 +1991,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t2 index c c 5 NULL 8 Using index 1 PRIMARY eq_ref distinct_key distinct_key 8 func,func 1 -2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index -2 MATERIALIZED s1 hash_ALL c #hash#$hj 10 const,test.s2.d 8 Using where; Using join buffer (flat, BNLH join) +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 hash_ALL c #hash#$hj 5 const 8 Using where; Using join buffer (flat, BNLH join) 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 SELECT a, c FROM t1, t2 WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 diff --git a/mysql-test/suite/sys_vars/r/all_vars.result b/mysql-test/suite/sys_vars/r/all_vars.result index 1bd4e394f6a..692545ae0fb 100644 --- a/mysql-test/suite/sys_vars/r/all_vars.result +++ b/mysql-test/suite/sys_vars/r/all_vars.result @@ -10,5 +10,6 @@ there should be *no* long test name listed below: select distinct variable_name as `there should be *no* variables listed below:` from t2 left join t1 on variable_name=test_name where test_name is null; there should be *no* variables listed below: +expensive_subquery_limit drop table t1; drop table t2; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 6e98c064d94..d649c300ab5 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -304,6 +304,7 @@ SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a; SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a; INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); +-- error ER_SUBQUERY_NO_1_ROW EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -- error ER_SUBQUERY_NO_1_ROW SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); @@ -5529,5 +5530,36 @@ SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE drop table t1,t2; +--echo # +--echo # LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not +--echo # precomputed and thus not part of optimization +--echo # + +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); + +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); + +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); + +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); + +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); + +drop table t1; + --echo # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test index 8915cdd6500..9ec282ba3db 100644 --- a/mysql-test/t/subselect4.test +++ b/mysql-test/t/subselect4.test @@ -977,6 +977,14 @@ SELECT * FROM t1 WHERE FROM t3 AS SQ1_t1 JOIN t3 AS SQ1_t3 ON SQ1_t3.f4 GROUP BY SQ1_t1.f4)); +--error ER_SUBQUERY_NO_1_ROW +SELECT * FROM t1 WHERE +(SELECT f2 FROM t2 + WHERE f4 <= ALL + (SELECT max(SQ1_t1.f4) + FROM t3 AS SQ1_t1 JOIN t3 AS SQ1_t3 ON SQ1_t3.f4 + GROUP BY SQ1_t1.f4)); + drop table t1, t2, t3; --echo # diff --git a/sql/item.h b/sql/item.h index b3801e6c488..df220118745 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1395,21 +1395,21 @@ public: { return cmp_context == IMPOSSIBLE_RESULT || item->cmp_context == cmp_context; } - /* + /** Test whether an expression is expensive to compute. Used during optimization to avoid computing expensive expressions during this phase. Also used to force temp tables when sorting on expensive functions. - TODO: + @todo Normally we should have a method: cost Item::execution_cost(), where 'cost' is either 'double' or some structure of various cost parameters. - NOTE - This function is now used to prevent evaluation of materialized IN - subquery predicates before it is allowed. grep for - DontEvaluateMaterializedSubqueryTooEarly to see the uses. + @note + This function is now used to prevent evaluation of expensive subquery + predicates during the optimization phase. It also prevents evaluation + of predicates that are not computable at this moment. */ virtual bool is_expensive() { diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d3251bc1fb3..b45b138ced2 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5539,7 +5539,15 @@ void Item_equal::add_const(Item *c, Item *f) else { Item_func_eq *func= new Item_func_eq(c, const_item); - func->set_cmp_func(); + if (func->set_cmp_func()) + { + /* + Setting a comparison function fails when trying to compare + incompatible charsets. Charset compatibility is checked earlier, + except for constant subqueries where we may do it here. + */ + return; + } func->quick_fix_field(); cond_false= !func->val_int(); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index b9740c7af03..875fdc3b34f 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -370,9 +370,9 @@ public: Item_bool_func2(Item *a,Item *b) :Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), abort_on_null(FALSE) {} void fix_length_and_dec(); - void set_cmp_func() + int set_cmp_func() { - cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, TRUE); + return cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, TRUE); } optimize_type select_optimize() const { return OPTIMIZE_OP; } virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index ad854b02765..b71408bd5f5 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -829,7 +829,7 @@ public: { DBUG_ASSERT(args[0]->fixed); conv_charset= cs; - if (cache_if_const && args[0]->const_item() && !args[0]->with_subselect) + if (cache_if_const && args[0]->const_item() && !args[0]->is_expensive()) { uint errors= 0; String tmp, *str= args[0]->val_str(&tmp); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 276f35fe301..1367037d17e 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -522,6 +522,48 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent, */ } + +/** + Determine if a subquery is expensive to execute during query optimization. + + @details The cost of execution of a subquery is estimated based on an + estimate of the number of rows the subquery will access during execution. + This measure is used instead of JOIN::read_time, because it is considered + to be much more reliable than the cost estimate. + + @return true if the subquery is expensive + @return false otherwise +*/ +bool Item_subselect::is_expensive() +{ + double examined_rows= 0; + + for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) + { + JOIN *cur_join= sl->join; + if (!cur_join) + continue; + + /* If a subquery is not optimized we cannot estimate its cost. */ + if (!cur_join->join_tab) + return true; + + if (sl->first_inner_unit()) + { + /* + Subqueries that contain subqueries are considered expensive. + @todo: accumulate the cost of subqueries. + */ + return true; + } + + examined_rows+= cur_join->get_examined_rows(); + } + + return (examined_rows > thd->variables.expensive_subquery_limit); +} + + bool Item_subselect::walk(Item_processor processor, bool walk_subquery, uchar *argument) { diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 1a4c8a25a01..746813407c2 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -209,7 +209,7 @@ public: */ bool is_evaluated() const; bool is_uncacheable() const; - bool is_expensive() { return TRUE; } + bool is_expensive(); /* Used by max/min subquery to initialize value presence registration @@ -235,7 +235,7 @@ public: @retval TRUE if the predicate is expensive @retval FALSE otherwise */ - bool is_expensive_processor(uchar *arg) { return TRUE; } + bool is_expensive_processor(uchar *arg) { return is_expensive(); } /** Get the SELECT_LEX structure associated with this Item. @@ -581,6 +581,10 @@ public: bool fix_fields(THD *thd, Item **ref); void fix_length_and_dec(); void fix_after_pullout(st_select_lex *new_parent, Item **ref); + bool const_item() const + { + return Item_subselect::const_item() && left_expr->const_item(); + } void update_used_tables(); bool setup_mat_engine(); bool init_left_expr_cache(); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 9bf1aaf4039..3e21187e6fa 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -4872,7 +4872,43 @@ static void remove_subq_pushed_predicates(JOIN *join, Item **where) bool JOIN::optimize_unflattened_subqueries() { - return select_lex->optimize_unflattened_subqueries(); + return select_lex->optimize_unflattened_subqueries(false); +} + +/** + Optimize all constant subqueries of a query that were not flattened into + a semijoin. + + @details + Similar to other constant conditions, constant subqueries can be used in + various constant optimizations. Having optimized constant subqueries before + these constant optimizations, makes it possible to estimate if a subquery + is "cheap" enough to be executed during the optimization phase. + + Constant subqueries can be optimized and evaluated independent of the outer + query, therefore if const_only = true, this method can be called early in + the optimization phase of the outer query. + + @return Operation status + @retval FALSE success. + @retval TRUE error occurred. +*/ + +bool JOIN::optimize_constant_subqueries() +{ + ulonglong save_options= select_lex->options; + bool res; + /* + Constant subqueries may be executed during the optimization phase. + In EXPLAIN mode the optimizer doesn't initialize many of the data structures + needed for execution. In order to make it possible to execute subqueries + during optimization, constant subqueries must be optimized for execution, + not for EXPLAIN. + */ + select_lex->options&= ~SELECT_DESCRIBE; + res= select_lex->optimize_unflattened_subqueries(true); + select_lex->options= save_options; + return res; } @@ -5273,7 +5309,14 @@ bool JOIN::choose_subquery_plan(table_map join_tables) by the IN predicate. */ outer_join= unit->outer_select() ? unit->outer_select()->join : NULL; - if (outer_join && outer_join->table_count > 0) + /* + Get the cost of the outer join if: + (1) It has at least one table, and + (2) It has been already optimized (if there is no join_tab, then the + outer join has not been optimized yet). + */ + if (outer_join && outer_join->table_count > 0 && // (1) + outer_join->join_tab) // (2) { /* TODO: diff --git a/sql/sql_class.h b/sql/sql_class.h index c6c46975076..ee472e2e7e6 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -482,6 +482,7 @@ typedef struct system_variables ulonglong group_concat_max_len; ha_rows select_limit; ha_rows max_join_size; + ha_rows expensive_subquery_limit; ulong auto_increment_increment, auto_increment_offset; ulong lock_wait_timeout; ulong join_cache_level; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index cc358eca440..5128b1284dd 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -120,7 +120,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } /* Apply the IN=>EXISTS transformation to all subqueries and optimize them. */ - if (select_lex->optimize_unflattened_subqueries()) + if (select_lex->optimize_unflattened_subqueries(false)) DBUG_RETURN(TRUE); const_cond= (!conds || conds->const_item()); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 6fd6e53424f..fb5307f9e3a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3405,7 +3405,23 @@ bool st_select_lex::add_index_hint (THD *thd, char *str, uint length) } -bool st_select_lex::optimize_unflattened_subqueries() +/** + Optimize all subqueries that have not been flattened into semi-joins. + + @details + This functionality is a method of SELECT_LEX instead of JOIN because + SQL statements as DELETE/UPDATE do not have a corresponding JOIN object. + + @see JOIN::optimize_unflattened_subqueries + + @param const_only Restrict subquery optimization to constant subqueries + + @return Operation status + @retval FALSE success. + @retval TRUE error occurred. +*/ + +bool st_select_lex::optimize_unflattened_subqueries(bool const_only) { for (SELECT_LEX_UNIT *un= first_inner_unit(); un; un= un->next_unit()) { @@ -3415,11 +3431,17 @@ bool st_select_lex::optimize_unflattened_subqueries() { if (subquery_predicate->substype() == Item_subselect::IN_SUBS) { - Item_in_subselect *in_subs=(Item_in_subselect*)subquery_predicate; + Item_in_subselect *in_subs= (Item_in_subselect*) subquery_predicate; if (in_subs->is_jtbm_merged) continue; } + if (const_only && !subquery_predicate->const_item()) + { + /* Skip non-constant subqueries if the caller asked so. */ + continue; + } + bool empty_union_result= true; /* If the subquery is a UNION, optimize all the subqueries in the UNION. If diff --git a/sql/sql_lex.h b/sql/sql_lex.h index f1ee6cf22ec..922386151f8 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -997,12 +997,7 @@ public: void clear_index_hints(void) { index_hints= NULL; } bool is_part_of_union() { return master_unit()->is_union(); } - /* - Optimize all subqueries that have not been flattened into semi-joins. - This functionality is a method of SELECT_LEX instead of JOIN because - some SQL statements as DELETE do not have a corresponding JOIN object. - */ - bool optimize_unflattened_subqueries(); + bool optimize_unflattened_subqueries(bool const_only); /* Set the EXPLAIN type for this subquery. */ void set_explain_type(); bool handle_derived(LEX *lex, uint phases); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 916e521d3b9..933679a0d9c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -986,7 +986,10 @@ JOIN::optimize() } eval_select_list_used_tables(); - + + if (optimize_constant_subqueries()) + DBUG_RETURN(1); + table_count= select_lex->leaf_tables.elements; if (setup_ftfuncs(select_lex)) /* should be after having->fix_fields */ @@ -1273,6 +1276,12 @@ JOIN::optimize() { conds= substitute_for_best_equal_field(NO_PARTICULAR_TAB, conds, cond_equal, map2table); + if (thd->is_error()) + { + error= 1; + DBUG_PRINT("error",("Error from substitute_for_best_equal")); + DBUG_RETURN(1); + } conds->update_used_tables(); DBUG_EXECUTE("where", print_where(conds, @@ -1293,6 +1302,12 @@ JOIN::optimize() *tab->on_expr_ref, tab->cond_equal, map2table); + if (thd->is_error()) + { + error= 1; + DBUG_PRINT("error",("Error from substitute_for_best_equal")); + DBUG_RETURN(1); + } (*tab->on_expr_ref)->update_used_tables(); } } @@ -6591,6 +6606,33 @@ void JOIN::get_prefix_cost_and_fanout(uint n_tables, } +/** + Estimate the number of rows that query execution will read. + + @todo This is a very pessimistic upper bound. Use join selectivity + when available to produce a more realistic number. +*/ + +double JOIN::get_examined_rows() +{ + /* Each constant table examines one row, and the result is at most one row. */ + ha_rows examined_rows= const_tables; + uint i= const_tables; + double prev_fanout= 1; + + if (table_count == const_tables) + return examined_rows; + + examined_rows+= join_tab[i++].get_examined_rows(); + for (; i < table_count ; i++) + { + prev_fanout *= best_positions[i-1].records_read; + examined_rows+= join_tab[i].get_examined_rows() * prev_fanout; + } + return examined_rows; +} + + /** Find a good, possibly optimal, query execution plan (QEP) by a possibly exhaustive search. @@ -8011,36 +8053,15 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table) row_limit= unit->select_limit_cnt; do_send_rows= row_limit ? 1 : 0; - join_tab->use_join_cache= FALSE; - join_tab->cache=0; /* No caching */ + bzero(join_tab, sizeof(JOIN_TAB)); join_tab->table=temp_table; - join_tab->cache_select= 0; - join_tab->select=0; - join_tab->select_cond= 0; // Avoid valgrind warning join_tab->set_select_cond(NULL, __LINE__); - join_tab->quick=0; join_tab->type= JT_ALL; /* Map through all records */ join_tab->keys.init(); join_tab->keys.set_all(); /* test everything in quick */ - join_tab->info=0; - join_tab->on_expr_ref=0; - join_tab->last_inner= 0; - join_tab->first_unmatched= 0; join_tab->ref.key = -1; - join_tab->not_used_in_distinct=0; join_tab->read_first_record= join_init_read_record; - join_tab->preread_init_done= FALSE; join_tab->join= this; - join_tab->ref.key_parts= 0; - join_tab->keep_current_rowid= FALSE; - join_tab->flush_weedout_table= join_tab->check_weed_out_table= NULL; - join_tab->do_firstmatch= NULL; - join_tab->loosescan_match_tab= NULL; - join_tab->emb_sj_nest= NULL; - join_tab->pre_idx_push_select_cond= NULL; - join_tab->bush_root_tab= NULL; - join_tab->bush_children= NULL; - join_tab->last_leaf_in_bush= FALSE; bzero((char*) &join_tab->read_record,sizeof(join_tab->read_record)); temp_table->status=0; temp_table->null_row=0; @@ -10225,6 +10246,51 @@ double JOIN_TAB::scan_time() return res; } + +/** + Estimate the number of rows that a an access method will read from a table. + + @todo: why not use JOIN_TAB::found_records +*/ + +ha_rows JOIN_TAB::get_examined_rows() +{ + ha_rows examined_rows; + + if (select && select->quick) + examined_rows= select->quick->records; + else if (type == JT_NEXT || type == JT_ALL || + type == JT_HASH || type ==JT_HASH_NEXT) + { + if (limit) + { + /* + @todo This estimate is wrong, a LIMIT query may examine much more rows + than the LIMIT itself. + */ + examined_rows= limit; + } + else + { + if (table->is_filled_at_execution()) + examined_rows= records; + else + { + /* + handler->info(HA_STATUS_VARIABLE) has been called in + make_join_statistics() + */ + examined_rows= table->file->stats.records; + } + } + } + else + examined_rows= (ha_rows) records_read; + + return examined_rows; +} + + /** Initialize the join_tab before reading. Currently only derived table/view materialization is done here. @@ -11204,9 +11270,9 @@ static bool check_simple_equality(Item *left_item, Item *right_item, if (!item) { Item_func_eq *eq_item; - if ((eq_item= new Item_func_eq(orig_left_item, orig_right_item))) + if (!(eq_item= new Item_func_eq(orig_left_item, orig_right_item)) || + eq_item->set_cmp_func()) return FALSE; - eq_item->set_cmp_func(); eq_item->quick_fix_field(); item= eq_item; } @@ -11299,9 +11365,9 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row, if (!is_converted) { Item_func_eq *eq_item; - if (!(eq_item= new Item_func_eq(left_item, right_item))) + if (!(eq_item= new Item_func_eq(left_item, right_item)) || + eq_item->set_cmp_func()) return FALSE; - eq_item->set_cmp_func(); eq_item->quick_fix_field(); eq_list->push_back(eq_item); } @@ -11987,9 +12053,8 @@ Item *eliminate_item_equal(COND *cond, COND_EQUAL *upper_levels, eq_item= new Item_func_eq(field_item->real_item(), head_item); - if (!eq_item) + if (!eq_item || eq_item->set_cmp_func()) return 0; - eq_item->set_cmp_func(); eq_item->quick_fix_field(); } current_sjm= field_sjm; @@ -12076,7 +12141,7 @@ Item *eliminate_item_equal(COND *cond, COND_EQUAL *upper_levels, Item_equal::get_first() for details. @return - The transformed condition + The transformed condition, or NULL in case of error */ static COND* substitute_for_best_equal_field(JOIN_TAB *context_tab, @@ -18544,6 +18609,7 @@ check_reverse_order: tab->ref.key_parts= 0; if (select_limit < table->file->stats.records) tab->limit= select_limit; + table->disable_keyread(); } } else if (tab->type != JT_ALL) @@ -21269,10 +21335,17 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, } else { - TABLE_LIST *real_table= table->pos_in_table_list; - item_list.push_back(new Item_string(real_table->alias, - strlen(real_table->alias), - cs)); + TABLE_LIST *real_table= table->pos_in_table_list; + /* + Internal temporary tables have no corresponding table reference + object. Such a table may appear in EXPLAIN when a subquery that needs + a temporary table has been executed, and JOIN::exec replaced the + original JOIN with a plan to access the data in the temp table + (made by JOIN::make_simple_join). + */ + const char *tab_name= real_table ? real_table->alias : + "internal_tmp_table"; + item_list.push_back(new Item_string(tab_name, strlen(tab_name), cs)); } /* "partitions" column */ if (join->thd->lex->describe & DESCRIBE_PARTITIONS) @@ -21430,32 +21503,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, } else { - ha_rows examined_rows; - if (tab->select && tab->select->quick) - examined_rows= tab->select->quick->records; - else if (tab->type == JT_NEXT || tab->type == JT_ALL || is_hj) - { - if (tab->limit) - examined_rows= tab->limit; - else - { - if (tab->table->is_filled_at_execution()) - { - examined_rows= tab->records; - } - else - { - /* - handler->info(HA_STATUS_VARIABLE) has been called in - make_join_statistics() - */ - examined_rows= tab->table->file->stats.records; - } - } - } - else - examined_rows=(ha_rows)tab->records_read; - + ha_rows examined_rows= tab->get_examined_rows(); + item_list.push_back(new Item_int((longlong) (ulonglong) examined_rows, MY_INT64_NUM_DECIMAL_DIGITS)); diff --git a/sql/sql_select.h b/sql/sql_select.h index 08ddc27e204..ee91928fa15 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -512,6 +512,7 @@ typedef struct st_join_table { return (is_hash_join_key_no(key) ? hj_key : table->key_info+key); } double scan_time(); + ha_rows get_examined_rows(); bool preread_init(); bool is_sjm_nest() { return test(bush_children); } @@ -1281,6 +1282,7 @@ public: bool alloc_func_list(); bool flatten_subqueries(); bool optimize_unflattened_subqueries(); + bool optimize_constant_subqueries(); bool make_sum_func_list(List &all_fields, List &send_fields, bool before_group_by, bool recompute= FALSE); @@ -1380,6 +1382,7 @@ public: void get_prefix_cost_and_fanout(uint n_tables, double *read_time_arg, double *record_count_arg); + double get_examined_rows(); /* defined in opt_subselect.cc */ bool transform_max_min_subquery(); /* True if this JOIN is a subquery under an IN predicate. */ diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7d5fe875d64..f2b6c5c9f92 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -368,7 +368,7 @@ int mysql_update(THD *thd, } /* Apply the IN=>EXISTS transformation to all subqueries and optimize them. */ - if (select_lex->optimize_unflattened_subqueries()) + if (select_lex->optimize_unflattened_subqueries(false)) DBUG_RETURN(TRUE); if (select_lex->inner_refs_list.elements && diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index ca434821800..65b21273348 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3780,4 +3780,9 @@ static Sys_var_ulong Sys_debug_binlog_fsync_sleep( CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1)); #endif - +static Sys_var_harows Sys_expensive_subquery_limit( + "expensive_subquery_limit", + "The maximum number of rows a subquery may examine in order to be " + "executed during optimization and used for constant optimization", + SESSION_VAR(expensive_subquery_limit), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(0, HA_POS_ERROR), DEFAULT(100), BLOCK_SIZE(1)); diff --git a/sql/table.cc b/sql/table.cc index 40304dc6fdc..bc7ad0e5831 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -5985,7 +5985,13 @@ void TABLE::use_index(int key_to_save) bool TABLE::is_filled_at_execution() { - return test(pos_in_table_list->jtbm_subselect || + /* + pos_in_table_list == NULL for internal temporary tables because they + do not have a corresponding table reference. Such tables are filled + during execution. + */ + return test(!pos_in_table_list || + pos_in_table_list->jtbm_subselect || pos_in_table_list->is_active_sjm()); } -- cgit v1.2.1 From e5bca74bfb47a1c45c995573fd58b1a751ccd884 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 May 2012 14:52:01 +0300 Subject: Fixed bug mdev-277 as part of the fix for lp:944706 The cause for this bug is that the method JOIN::get_examined_rows iterates over all JOIN_TABs of the join assuming they are just a sequence. In the query above, the innermost subquery is merged into its parent query. When we call JOIN::get_examined_rows for the second-level subquery, the iteration that assumes sequential order of join tabs goes outside the join_tab array and calls the method JOIN_TAB::get_examined_rows on uninitialized memory. The fix is to iterate over JOIN_TABs in a way that takes into account the nested semi-join structure of JOIN_TABs. In particular iterate as select_describe. --- mysql-test/r/subselect.result | 21 +++++++++++++++++++++ mysql-test/r/subselect_no_mat.result | 20 ++++++++++++++++++++ mysql-test/r/subselect_no_opts.result | 21 +++++++++++++++++++++ mysql-test/r/subselect_no_scache.result | 21 +++++++++++++++++++++ mysql-test/r/subselect_no_semijoin.result | 21 +++++++++++++++++++++ mysql-test/t/subselect.test | 19 +++++++++++++++++++ sql/sql_select.cc | 19 ++++++++++--------- 7 files changed, 133 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index a75d0f960af..05773560ba8 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -6594,5 +6594,26 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); MAX( alias2.a ) Arden-Arcade drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY eq_ref distinct_key distinct_key 4 func 1 +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 507c8741d25..2465c1af367 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -6593,6 +6593,26 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); MAX( alias2.a ) Arden-Arcade drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; Start temporary; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 End temporary; Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 9ca09ac061c..7dacffe0b74 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -6589,6 +6589,27 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); MAX( alias2.a ) Arden-Arcade drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY eq_ref distinct_key distinct_key 4 func 1 +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index f7a8e8efd01..e3a938cdece 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -6600,6 +6600,27 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); MAX( alias2.a ) Arden-Arcade drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY eq_ref distinct_key distinct_key 4 func 1 +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index f0186c682a4..6bb6b2861f9 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -6589,6 +6589,27 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); MAX( alias2.a ) Arden-Arcade drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY eq_ref distinct_key distinct_key 4 func 1 +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index d649c300ab5..f63ac838d2c 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -5561,5 +5561,24 @@ WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); drop table t1; +--echo # +--echo # MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +--echo # with semijoin+materialization, IN and = subqueries +--echo # + +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); + +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); + +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); + +drop table t1, t2; + --echo # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 933679a0d9c..10c841639a9 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -270,6 +270,8 @@ Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field, bool *inherited_fl); JOIN_TAB *first_depth_first_tab(JOIN* join); JOIN_TAB *next_depth_first_tab(JOIN* join, JOIN_TAB* tab); +JOIN_TAB *first_breadth_first_tab(JOIN *join); +JOIN_TAB *next_breadth_first_tab(JOIN *join, JOIN_TAB *tab); /** This handles SELECT with and without UNION. @@ -6615,19 +6617,18 @@ void JOIN::get_prefix_cost_and_fanout(uint n_tables, double JOIN::get_examined_rows() { - /* Each constant table examines one row, and the result is at most one row. */ - ha_rows examined_rows= const_tables; - uint i= const_tables; + ha_rows examined_rows; double prev_fanout= 1; + JOIN_TAB *tab= first_breadth_first_tab(this); + JOIN_TAB *prev_tab= tab; - if (table_count == const_tables) - return examined_rows; + examined_rows= tab->get_examined_rows(); - examined_rows+= join_tab[i++].get_examined_rows(); - for (; i < table_count ; i++) + while ((tab= next_breadth_first_tab(this, tab))) { - prev_fanout *= best_positions[i-1].records_read; - examined_rows+= join_tab[i].get_examined_rows() * prev_fanout; + prev_fanout *= prev_tab->records_read; + examined_rows+= tab->get_examined_rows() * prev_fanout; + prev_tab= tab; } return examined_rows; } -- cgit v1.2.1 From 950abd526837b8772044d521387fa6d410de5706 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 May 2012 08:48:10 +0300 Subject: Fix of LP bug#992380 + revise fix_fields about missing with_subselect collection The problem is that some fix_fields do not call Item_func::fix_fields and do not collect with subselect_information. --- mysql-test/r/func_in.result | 9 +++++++++ mysql-test/t/func_in.test | 11 +++++++++++ sql/item_cmpfunc.cc | 3 +++ sql/item_func.cc | 1 + sql/item_row.cc | 1 + sql/item_sum.cc | 3 +++ 6 files changed, 28 insertions(+) diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index 7f0e607e789..e45c775b377 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -787,3 +787,12 @@ DROP TABLE t1; # End of test BUG#13012483 # End of 5.1 tests +# +# LP bug#992380 Crash when creating PS for a query with +# subquery in WHERE (see also mysql bug#13012483) +# +CREATE TABLE t1 (a INT); +PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)"; +EXECUTE s; +1 +DROP TABLE t1; diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index dd4194e2a4e..9e054da3fe2 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -576,3 +576,14 @@ DROP TABLE t1; --echo # --echo End of 5.1 tests + +--echo # +--echo # LP bug#992380 Crash when creating PS for a query with +--echo # subquery in WHERE (see also mysql bug#13012483) +--echo # +CREATE TABLE t1 (a INT); +PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)"; +EXECUTE s; + +DROP TABLE t1; + diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ea216944dbb..dda9ab418a4 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1791,6 +1791,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) } if (args[1]->maybe_null) maybe_null=1; + with_subselect= 1; with_sum_func= with_sum_func || args[1]->with_sum_func; used_tables_cache|= args[1]->used_tables(); not_null_tables_cache|= args[1]->not_null_tables(); @@ -4907,6 +4908,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref) args[1]->fix_fields(thd, args + 1)) || args[1]->check_cols(1)) return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; + with_subselect|= args[0]->with_subselect | args[1]->with_subselect; max_length= 1; decimals= 0; @@ -5597,6 +5599,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref) used_tables_cache|= item->used_tables(); tmp_table_map= item->not_null_tables(); not_null_tables_cache|= tmp_table_map; + DBUG_ASSERT(!item->with_sum_func && !item->with_subselect); if (item->maybe_null) maybe_null=1; } diff --git a/sql/item_func.cc b/sql/item_func.cc index ed771b60769..8028ae53eaf 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2918,6 +2918,7 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func, if (item->maybe_null) func->maybe_null=1; func->with_sum_func= func->with_sum_func || item->with_sum_func; + func->with_subselect|= item->with_subselect; used_tables_cache|=item->used_tables(); const_item_cache&=item->const_item(); f_args.arg_type[i]=item->result_type(); diff --git a/sql/item_row.cc b/sql/item_row.cc index 4040dbff7c6..5296f866248 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -88,6 +88,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) } maybe_null|= item->maybe_null; with_sum_func= with_sum_func || item->with_sum_func; + with_subselect|= item->with_subselect; } fixed= 1; return FALSE; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index ac6ddc0fd54..61a780b6222 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -574,6 +574,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields(thd, args + i) || args[i]->check_cols(1)) return TRUE; set_if_bigger(decimals, args[i]->decimals); + with_subselect|= args[i]->with_subselect; } result_field=0; max_length=float_length(decimals); @@ -604,6 +605,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) (item= args[0])->check_cols(1)) return TRUE; decimals=item->decimals; + with_subselect= args[0]->with_subselect; switch (hybrid_type= item->result_type()) { case INT_RESULT: @@ -3216,6 +3218,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) args[i]->fix_fields(thd, args + i)) || args[i]->check_cols(1)) return TRUE; + with_subselect|= args[i]->with_subselect; } if (agg_item_charsets(collation, func_name(), -- cgit v1.2.1 From d56f5dae1ef60468dd7497453bcdca9b653922ca Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 23 May 2012 18:18:08 +0300 Subject: Fix bug lp:1001506 This is a backport of the (unchaged) fix for MySQL bug #11764372, 57197. Analysis: When the outer query finishes its main execution and computes GROUP BY, it needs to construct a new temporary table (and a corresponding JOIN) to execute the last DISTINCT operation. At this point JOIN::exec calls JOIN::join_free, which calls JOIN::cleanup -> TMP_TABLE_PARAM::cleanup for both the outer and the inner JOINs. The call to the inner TMP_TABLE_PARAM::cleanup sets copy_field = NULL, but not copy_field_end. The final execution phase that computes the DISTINCT invokes: evaluate_join_record -> end_write -> copy_funcs The last function copies the results of all functions into the temp table. copy_funcs walks over all functions in join->tmp_table_param.items_to_copy. In this case items_to_copy contains both assignments to user variables. The process of copying user variables invokes Item_func_set_user_var::check which in turn re-evaluates the arguments of the user variable assignment. This in turn triggers re-evaluation of the subquery, and ultimately copy_field. However, the previous call to TMP_TABLE_PARAM::cleanup for the subquery already set copy_field to NULL but not its copy_field_end. This results in a null pointer access, and a crash. Fix: Set copy_field_end and save_copy_field_end to null when deleting copy fields in TMP_TABLE_PARAM::cleanup(). --- mysql-test/r/user_var.result | 7 +++++++ mysql-test/t/user_var.test | 11 +++++++++++ sql/sql_class.h | 3 ++- sql/sql_select.cc | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 374520ff610..19cb54ad2bc 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -456,4 +456,11 @@ SELECT (@v:=a) <> (@v:=1) FROM t1; (@v:=a) <> (@v:=1) 1 DROP TABLE t1; +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); +SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2 +GROUP BY @b:=(SELECT COUNT(*) > t2.a); +@a:=MIN(t1.a) +1 +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index efaf8afd91e..2782f61994d 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -365,4 +365,15 @@ SELECT (@v:=a) <> (@v:=1) FROM t1; DROP TABLE t1; +# +# LP BUG#1001506 Crash on a query with GROUP BY and user variables +# MySQL Bug #11764372 57197: EVEN MORE USER VARIABLE CRASHING FUN +# + +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); +SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2 +GROUP BY @b:=(SELECT COUNT(*) > t2.a); +DROP TABLE t1; + --echo End of 5.1 tests diff --git a/sql/sql_class.h b/sql/sql_class.h index 4bf1bc3964c..14f4f022de3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2880,7 +2880,8 @@ public: if (copy_field) /* Fix for Intel compiler */ { delete [] copy_field; - save_copy_field= copy_field= 0; + save_copy_field= copy_field= NULL; + save_copy_field_end= copy_field_end= NULL; } } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 150f19f96a6..46b4511e24f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16072,6 +16072,8 @@ copy_fields(TMP_TABLE_PARAM *param) Copy_field *ptr=param->copy_field; Copy_field *end=param->copy_field_end; + DBUG_ASSERT((ptr != NULL && end >= ptr) || (ptr == NULL && end == NULL)); + for (; ptr != end; ptr++) (*ptr->do_copy)(ptr); -- cgit v1.2.1 From 4fa89b5fe05280fefa2b30df927d0db6c6888f98 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 May 2012 14:08:28 +0300 Subject: Test case for bug lp:1001117, MySQL BUG#12330344 Analysis: The problem in the original MySQL bug is that the range optimizer performs its analysis in a separate MEM_ROOT object that is freed after the range optimzier is done. During range analysis get_mm_tree calls Item_func_like::select_optimize, which in turn evaluates its right argument. In the test case the right argument is a subquery. In MySQL, subqueries are optimized lazyly, thus the call to val_str triggers optimization for the subquery. All objects needed by the subquery plan end up in the temporary MEM_ROOT used by the range optimizer. When execution ends, the JOIN::cleanup process tries to cleanup objects of the subquery plan, but all these objects are gone with the temporary MEM_ROOT. The solution for MySQL is to switch the mem_root. In MariaDB with the patch for bug lp:944706, all constant subqueries that may be used by the optimization process are preoptimized. Therefore Item_func_like::select_optimize only triggers subquery execution, and the above problem is not present. The patch however adds a test whether the evaluated right argument of the LIKE predicate is expensive. This is consistent with our approach not to evaluate expensive expressions during optimization. --- mysql-test/r/partition.result | 12 ++++++++++++ mysql-test/t/partition.test | 13 +++++++++++++ sql/item_cmpfunc.cc | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 1bc1ea31671..431c5dda116 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -2461,3 +2461,15 @@ SELECT 1 FROM t1 JOIN t1 AS t2 USING (a); 1 1 drop table t1; +# +# LP BUG#1001117 Crash on a simple select that uses a temptable view +# MySQL Bug #12330344 Crash and/or valgrind errors in free_io_cache with join, view, +# partitioned table +# +CREATE TABLE t1(a INT PRIMARY KEY) PARTITION BY LINEAR KEY (a); +CREATE ALGORITHM=TEMPTABLE VIEW vtmp AS +SELECT 1 FROM t1 AS t1_0 JOIN t1 ON t1_0.a LIKE (SELECT 1 FROM t1); +SELECT * FROM vtmp; +1 +DROP VIEW vtmp; +DROP TABLE t1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index d6d49c59255..08c028c8224 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -2463,3 +2463,16 @@ INSERT INTO t1 VALUES (6,8,10); SELECT 1 FROM t1 JOIN t1 AS t2 USING (a); drop table t1; + +--echo # +--echo # LP BUG#1001117 Crash on a simple select that uses a temptable view +--echo # MySQL Bug #12330344 Crash and/or valgrind errors in free_io_cache with join, view, +--echo # partitioned table +--echo # + +CREATE TABLE t1(a INT PRIMARY KEY) PARTITION BY LINEAR KEY (a); +CREATE ALGORITHM=TEMPTABLE VIEW vtmp AS +SELECT 1 FROM t1 AS t1_0 JOIN t1 ON t1_0.a LIKE (SELECT 1 FROM t1); +SELECT * FROM vtmp; +DROP VIEW vtmp; +DROP TABLE t1; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index b45b138ced2..560373b69e6 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -4736,7 +4736,7 @@ longlong Item_func_like::val_int() Item_func::optimize_type Item_func_like::select_optimize() const { - if (args[1]->const_item()) + if (args[1]->const_item() && !args[1]->is_expensive()) { String* res2= args[1]->val_str((String *)&cmp.value2); const char *ptr2; -- cgit v1.2.1 From f45784c8503d0bbe77f3aec351fc87ff536b19be Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 May 2012 10:29:53 +0300 Subject: Fix of LP bug#992380 + revise fix_fields about missing with_subselect collection The problem is that some fix_fields do not call Item_func::fix_fields and do not collect with subselect_information. --- mysql-test/r/func_test.result | 41 ++++++++++++++++++++ mysql-test/r/negation_elimination.result | 4 +- mysql-test/r/ps.result | 56 +++++++++++++++++++++++++++ mysql-test/t/func_test.test | 20 ++++++++++ mysql-test/t/ps.test | 65 ++++++++++++++++++++++++++++++++ sql/item_cmpfunc.cc | 38 +++++++++++++++++++ sql/item_cmpfunc.h | 3 ++ 7 files changed, 225 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result index a97e6869d09..e3c77a40a77 100644 --- a/mysql-test/r/func_test.result +++ b/mysql-test/r/func_test.result @@ -279,3 +279,44 @@ NULL SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; GREATEST(1.5E+2,1.3E+2,NULL) NULL +create table t1 (a int); +insert into t1 values (1), (100), (0), (NULL); +select not a from t1; +not a +0 +0 +1 +NULL +explain extended select not a from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 select (`test`.`t1`.`a` = 0) AS `not a` from `test`.`t1` +select * from t1 where not a; +a +0 +explain extended select * from t1 where not a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +select not (a+0) from t1; +not (a+0) +0 +0 +1 +NULL +explain extended select not (a+0) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 select (not((`test`.`t1`.`a` + 0))) AS `not (a+0)` from `test`.`t1` +select * from t1 where not (a+0); +a +0 +explain extended select * from t1 where not (a+0); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not((`test`.`t1`.`a` + 0))) +drop table t1; diff --git a/mysql-test/r/negation_elimination.result b/mysql-test/r/negation_elimination.result index af48002ed0f..35510242bcb 100644 --- a/mysql-test/r/negation_elimination.result +++ b/mysql-test/r/negation_elimination.result @@ -321,7 +321,7 @@ select * from t1 where not(NULL or a); a explain select * from t1 where not(NULL and a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 5 NULL 21 Using where; Using index +1 SIMPLE t1 ref a a 5 const 1 Using where; Using index select * from t1 where not(NULL and a); a 0 @@ -387,5 +387,5 @@ explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like " id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or `test`.`t1`.`a`) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) +Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or (`test`.`t1`.`a` <> 0)) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) drop table t1; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index b3f4ad017d3..72558324b50 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -3040,3 +3040,59 @@ id select_type table type possible_keys key key_len ref rows Extra DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. +# +# LP bug#1001500 Crash on the second execution of the PS for +# a query with degenerated conjunctive condition +# (see also mysql bug#12582849) +# +CREATE TABLE t1 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +col_varchar_nokey VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +); +INSERT INTO t1 ( +col_int_key, col_int_nokey, +col_varchar_key, col_varchar_nokey +) VALUES +(4, 2, 'v', 'v'), +(62, 150, 'v', 'v'); +CREATE TABLE t2 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +col_varchar_nokey VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +); +INSERT INTO t2 ( +col_int_key, col_int_nokey, +col_varchar_key, col_varchar_nokey +) VALUES +(8, NULL, 'x', 'x'), +(7, 8, 'd', 'd'); +PREPARE stmt FROM ' +SELECT + ( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1 + FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2 + ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ) + ) + WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk + ) AS field1 +FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk ) +GROUP BY field1 +'; +EXECUTE stmt; +field1 +150 +EXECUTE stmt; +field1 +150 +DEALLOCATE PREPARE stmt; +DROP TABLE t1, t2; diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test index 77bf3be5e72..4cba29986a1 100644 --- a/mysql-test/t/func_test.test +++ b/mysql-test/t/func_test.test @@ -160,3 +160,23 @@ SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; # End of 4.1 tests + +# +# test of replacing NOT +# +create table t1 (a int); +insert into t1 values (1), (100), (0), (NULL); + +select not a from t1; +explain extended select not a from t1; + +select * from t1 where not a; +explain extended select * from t1 where not a; + +select not (a+0) from t1; +explain extended select not (a+0) from t1; + +select * from t1 where not (a+0); +explain extended select * from t1 where not (a+0); + +drop table t1; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 9b3f3e750e1..e3f2a5c87d1 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3102,3 +3102,68 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1; --echo End of 5.1 tests. + +--echo # +--echo # LP bug#1001500 Crash on the second execution of the PS for +--echo # a query with degenerated conjunctive condition +--echo # (see also mysql bug#12582849) +--echo # + +CREATE TABLE t1 ( + pk INTEGER AUTO_INCREMENT, + col_int_nokey INTEGER, + col_int_key INTEGER, + + col_varchar_key VARCHAR(1), + col_varchar_nokey VARCHAR(1), + + PRIMARY KEY (pk), + KEY (col_int_key), + KEY (col_varchar_key, col_int_key) +); + +INSERT INTO t1 ( + col_int_key, col_int_nokey, + col_varchar_key, col_varchar_nokey +) VALUES +(4, 2, 'v', 'v'), +(62, 150, 'v', 'v'); + +CREATE TABLE t2 ( + pk INTEGER AUTO_INCREMENT, + col_int_nokey INTEGER, + col_int_key INTEGER, + + col_varchar_key VARCHAR(1), + col_varchar_nokey VARCHAR(1), + + PRIMARY KEY (pk), + KEY (col_int_key), + KEY (col_varchar_key, col_int_key) +); + +INSERT INTO t2 ( + col_int_key, col_int_nokey, + col_varchar_key, col_varchar_nokey +) VALUES +(8, NULL, 'x', 'x'), +(7, 8, 'd', 'd'); + +PREPARE stmt FROM ' +SELECT + ( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1 + FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2 + ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ) + ) + WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk + ) AS field1 +FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk ) +GROUP BY field1 +'; + +EXECUTE stmt; +EXECUTE stmt; + +DEALLOCATE PREPARE stmt; + +DROP TABLE t1, t2; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index dda9ab418a4..61554bdf420 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -4271,6 +4271,22 @@ Item_cond::fix_fields(THD *thd, Item **ref) if (abort_on_null) item->top_level_item(); + /* + replace degraded condition: + was: + become: = 1 + */ + if (item->type() == FIELD_ITEM) + { + Query_arena backup, *arena; + Item *new_item; + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((new_item= new Item_func_ne(item, new Item_int(0, 1)))) + li.replace(item= new_item); + if (arena) + thd->restore_active_arena(arena, &backup); + } + // item can be substituted in fix_fields if ((!item->fixed && item->fix_fields(thd, li.ref())) || @@ -5283,6 +5299,28 @@ Item *Item_func_not::neg_transformer(THD *thd) /* NOT(x) -> x */ } +bool Item_func_not::fix_fields(THD *thd, Item **ref) +{ + if (args[0]->type() == FIELD_ITEM) + { + /* replace "NOT " with " == 0" */ + Query_arena backup, *arena; + Item *new_item; + bool rc= TRUE; + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((new_item= new Item_func_eq(args[0], new Item_int(0, 1)))) + { + new_item->name= name; + rc= (*ref= new_item)->fix_fields(thd, ref); + } + if (arena) + thd->restore_active_arena(arena, &backup); + return rc; + } + return Item_func::fix_fields(thd, ref); +} + + Item *Item_bool_rowready_func2::neg_transformer(THD *thd) { Item *item= negated_item(); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 25b636397a8..7239079c56f 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -413,6 +413,7 @@ public: enum Functype functype() const { return NOT_FUNC; } const char *func_name() const { return "not"; } Item *neg_transformer(THD *thd); + bool fix_fields(THD *, Item **); virtual void print(String *str, enum_query_type query_type); }; @@ -479,6 +480,8 @@ public: longlong val_int(); enum Functype functype() const { return NOT_ALL_FUNC; } const char *func_name() const { return ""; } + bool fix_fields(THD *thd, Item **ref) + {return Item_func::fix_fields(thd, ref);} virtual void print(String *str, enum_query_type query_type); void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; }; void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; }; -- cgit v1.2.1 From 941018f8d10240e9ec457ea6ab984844c343f6b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 May 2012 00:18:53 +0300 Subject: Patch for mdev-287: CHEAP SQ: A query with subquery in SELECT list, EXISTS, inner joins takes hundreds times longer Analysis: The fix for lp:944706 introduces early subquery optimization. While a subquery is being optimized some of its predicates may be removed. In the test case, the EXISTS subquery is constant, and is evaluated to TRUE. As a result the whole OR is TRUE, and thus the correlated condition "b = alias1.b" is optimized away. The subquery becomes non-correlated. The subquery cache is designed to work only for correlated subqueries. If constant subquery optimization is disallowed, then the constant subquery is not evaluated, the subquery remains correlated, and its execution is cached. As a result execution is fast. However, when the constant subquery was optimized away, it was neither cached by the subquery cache, nor it was cached by the internal subquery caching. The latter was due to the fact that the subquery still appeared as correlated to the subselect_XYZ_engine::exec methods, and they re-executed the subquery on each call to Item_subselect::exec. Solution: The solution is to update the correlated status of the subquery after it has been optimized. This status consists of: - st_select_lex::is_correlated - Item_subselect::is_correlated - SELECT_LEX::uncacheable - SELECT_LEX_UNIT::uncacheable The status is updated by st_select_lex::update_correlated_cache(), and its caller st_select_lex::optimize_unflattened_subqueries. The solution relies on the fact that the optimizer already called st_select_lex::update_used_tables() for each subquery. This allows to efficiently update the correlated status of each subquery without walking the whole subquery tree. Notice that his patch is an improvement over MySQL 5.6 and older, where subqueries are not pre-optimized, and the above analysis is not possible. --- mysql-test/r/derived_opt.result | 24 ++--- mysql-test/r/explain.result | 4 +- mysql-test/r/index_merge_innodb.result | 2 +- mysql-test/r/index_merge_myisam.result | 2 +- mysql-test/r/join_outer.result | 2 +- mysql-test/r/join_outer_jcl6.result | 2 +- mysql-test/r/ps.result | 24 ++--- mysql-test/r/subselect.result | 123 +++++++++++++++++++---- mysql-test/r/subselect4.result | 120 +++++++++++----------- mysql-test/r/subselect_extra_no_semijoin.result | 4 +- mysql-test/r/subselect_mat.result | 12 +-- mysql-test/r/subselect_mat_cost.result | 2 +- mysql-test/r/subselect_mat_cost_bugs.result | 2 +- mysql-test/r/subselect_no_mat.result | 127 ++++++++++++++++++++---- mysql-test/r/subselect_no_opts.result | 125 +++++++++++++++++++---- mysql-test/r/subselect_no_scache.result | 121 ++++++++++++++++++---- mysql-test/r/subselect_no_semijoin.result | 115 ++++++++++++++++++--- mysql-test/r/subselect_partial_match.result | 6 +- mysql-test/r/subselect_sj_mat.result | 6 +- mysql-test/t/subselect.test | 44 ++++++++ sql/sql_lex.cc | 61 ++++++++++++ sql/sql_lex.h | 1 + 22 files changed, 730 insertions(+), 199 deletions(-) diff --git a/mysql-test/r/derived_opt.result b/mysql-test/r/derived_opt.result index c5376bee756..11216a32e61 100644 --- a/mysql-test/r/derived_opt.result +++ b/mysql-test/r/derived_opt.result @@ -161,24 +161,24 @@ prepare stmt1 from @stmt ; execute stmt1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables execute stmt1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables deallocate prepare stmt1; drop tables t1,t2; set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index 863526c637e..e081b56e6ce 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -225,10 +225,10 @@ INSERT INTO t2 VALUES (NULL), (0); EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 -Note 1003 select ((select 1 from `test`.`t2` where (`test`.`t2`.`d` = NULL))) AS `(SELECT 1 FROM t2 WHERE d = c)` from dual +Note 1003 select (select 1 from `test`.`t2` where (`test`.`t2`.`d` = NULL)) AS `(SELECT 1 FROM t2 WHERE d = c)` from dual DROP TABLE t1, t2; # # Bug#30302: Tables that were optimized away are printed in the diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result index 50b0147b6ad..ce65836d8bc 100644 --- a/mysql-test/r/index_merge_innodb.result +++ b/mysql-test/r/index_merge_innodb.result @@ -654,7 +654,7 @@ EXPLAIN SELECT t1.f1 FROM t1 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index -2 DEPENDENT SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index +2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index DROP TABLE t1,t2; # # BUG#56862/640419: Wrong result with sort_union index merge when one diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index b560c1e5176..bf151a872cf 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -1487,7 +1487,7 @@ EXPLAIN SELECT t1.f1 FROM t1 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t2 ref f2,f3 f2 5 const 1 Using where +2 SUBQUERY t2 ref f2,f3 f2 5 const 1 Using where DROP TABLE t1,t2; create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 49a6a0d76d3..074b8bcadaa 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1872,7 +1872,7 @@ SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 select NULL AS `a` from `test`.`t2` where 1 DROP TABLE t1,t2,t3; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index d1333136f1c..f40515bc9a0 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1883,7 +1883,7 @@ SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 select NULL AS `a` from `test`.`t2` where 1 DROP TABLE t1,t2,t3; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index ce0926c6bc1..06443dc55ae 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -160,26 +160,26 @@ execute stmt1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables execute stmt1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table -5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables deallocate prepare stmt1; set optimizer_switch=@tmp_optimizer_switch; drop tables t1,t2; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 05773560ba8..c90596315e1 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -51,12 +51,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list) EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 select 1 AS `1` from dual having (<1>((select 1)) = 1) +Note 1003 select 1 AS `1` from dual having ((select 1) = 1) SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; 1 1 @@ -904,7 +904,7 @@ a t1.a in (select t2.a from t2) explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index +2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in t2 on a checking NULL having (`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` CREATE TABLE t3 (a int(11) default '0'); @@ -1317,7 +1317,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1327,7 +1327,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; @@ -1605,25 +1605,25 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` drop table t1,t2; @@ -3097,7 +3097,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3109,7 +3109,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -3160,7 +3160,7 @@ INSERT INTO t2 VALUES (1),(2),(3); EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key +2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key SELECT a, a IN (SELECT a FROM t1) FROM t2; a a IN (SELECT a FROM t1) 1 1 @@ -3696,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index -2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 @@ -4577,7 +4577,7 @@ FROM t1 WHERE a = 230; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) FROM t1 WHERE a = 230; @@ -5713,7 +5713,7 @@ WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT b FROM t1 WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; @@ -6530,7 +6530,7 @@ EXPLAIN SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 NULL @@ -6538,7 +6538,7 @@ EXPLAIN SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 0 @@ -6573,7 +6573,7 @@ WHERE alias1.a = alias2.a OR alias1.a = 'y' HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) AS field FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR alias1.a = 'y' @@ -6587,7 +6587,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index 1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index 1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); @@ -6615,5 +6615,90 @@ SELECT * FROM t1 WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); a1 drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 6 +Subquery_cache_miss 2 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 8 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 22 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index c17ffe75282..e9284e427ef 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -226,10 +226,10 @@ NULL EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 ; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 -Note 1003 select <>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual first equivalent variant SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c ; RESULT @@ -237,10 +237,10 @@ NULL EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 -Note 1003 select <>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual group by NULL +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual group by NULL second equivalent variant SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ; RESULT @@ -248,10 +248,10 @@ NULL EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 -Note 1003 select <>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual group by NULL +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual group by NULL DROP TABLE t1,t2; # # BUG#45928 "Differing query results depending on MRR and @@ -649,7 +649,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2) as not_in; not_in NULL @@ -671,7 +671,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2) as not_in; not_in NULL @@ -679,7 +679,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) > 7) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) > 7) as not_in; not_in 1 @@ -687,7 +687,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) is null) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) is null) as not_in; not_in NULL @@ -695,7 +695,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2) as not_in; not_in NULL @@ -703,7 +703,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2) as not_in; not_in NULL @@ -719,28 +719,28 @@ EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4) FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4) FROM t2); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3+f4, min(f4) FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3+f4, min(f4) FROM t2); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4)+max(f4) FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4)+max(f4) FROM t2); f1 f2 EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2) as not_in; not_in NULL @@ -748,21 +748,21 @@ EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, count(f4) FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, count(f4) FROM t2); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, f3 + count(f4) FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, f3 + count(f4) FROM t2); f1 f2 EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2) as not_in; not_in NULL @@ -770,7 +770,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) > 7) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) > 7) as not_in; not_in 1 @@ -778,7 +778,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) is null) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 HAVING max(f4) is null) as not_in; not_in NULL @@ -786,7 +786,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2) as not_in; not_in NULL @@ -794,7 +794,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2) as not_in; not_in NULL @@ -835,7 +835,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -857,7 +857,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -865,7 +865,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) > 7) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) > 7) as not_in; not_in 1 @@ -873,7 +873,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) is null) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) is null) as not_in; not_in NULL @@ -881,7 +881,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -889,7 +889,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -905,28 +905,28 @@ EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3+f4, min(f4) FROM t2 WHERE f3 > 10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3+f4, min(f4) FROM t2 WHERE f3 > 10); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4)+max(f4) FROM t2 WHERE f3 > 10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, min(f4)+max(f4) FROM t2 WHERE f3 > 10); f1 f2 EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, min(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -934,21 +934,21 @@ EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10); f1 f2 EXPLAIN SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, f3 + count(f4) FROM t2 WHERE f3 > 10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT f3, f3 + count(f4) FROM t2 WHERE f3 > 10); f1 f2 EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -956,7 +956,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) > 7) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) > 7) as not_in; not_in 1 @@ -964,7 +964,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) is null) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT f3, count(f4) FROM t2 WHERE f3 > 10 HAVING max(f4) is null) as not_in; not_in NULL @@ -972,7 +972,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4) FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -980,7 +980,7 @@ EXPLAIN SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2 WHERE f3 > 10) as not_in; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan +2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan SELECT (2, 0) NOT IN (SELECT max(f3+f3), count(f4)+f3 FROM t2 WHERE f3 > 10) as not_in; not_in NULL @@ -1240,7 +1240,7 @@ EXPLAIN SELECT i FROM t1 WHERE (1) NOT IN (SELECT i FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t2 index_subquery k k 5 const 2 Using index +2 SUBQUERY t2 index_subquery k k 5 const 2 Using index DROP TABLE t2; DROP TABLE t1; # @@ -1258,8 +1258,8 @@ WHERE ('v') IN (SELECT f4 FROM t2) GROUP BY f9; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 FROM t2 JOIN t1 ON t1.f3 @@ -1274,8 +1274,8 @@ WHERE ('v') IN (SELECT f4 FROM t2) ORDER BY f9; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 FROM t2 JOIN t1 ON t1.f3 @@ -1291,8 +1291,8 @@ WHERE ('v') IN (SELECT f4 FROM t2) GROUP BY f9; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), (SELECT t2.f1 FROM t1 limit 1) AS f9 FROM t2 JOIN t1 @@ -1307,8 +1307,8 @@ WHERE ('v') IN (SELECT f4 FROM t2) ORDER BY f9; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(t2.f3), (SELECT t2.f1 FROM t1 limit 1) AS f9 FROM t2 JOIN t1 @@ -1390,7 +1390,7 @@ EXPLAIN SELECT 'bug' FROM DUAL WHERE ( 5 ) IN ( SELECT * FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1400,7 +1400,7 @@ EXPLAIN SELECT ( 5 ) IN ( SELECT * FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1411,7 +1411,7 @@ EXPLAIN SELECT 'bug' FROM DUAL WHERE ( 5 ) IN (SELECT * FROM v2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t1 system NULL NULL NULL NULL 1 4 UNION t2 system NULL NULL NULL NULL 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1431,7 +1431,7 @@ EXPLAIN SELECT ( 5 ) IN ( SELECT * FROM v2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t1 system NULL NULL NULL NULL 1 4 UNION t2 system NULL NULL NULL NULL 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1443,7 +1443,7 @@ EXPLAIN SELECT 'bug' FROM DUAL WHERE ( 5 ) IN ( SELECT * FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1453,7 +1453,7 @@ EXPLAIN SELECT ( 5 ) IN ( SELECT * FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1464,7 +1464,7 @@ EXPLAIN SELECT 'bug' FROM DUAL WHERE ( 5 ) IN (SELECT * FROM v2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t1 system NULL NULL NULL NULL 1 4 UNION t2 system NULL NULL NULL NULL 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1474,7 +1474,7 @@ EXPLAIN SELECT 'bug' FROM t3 WHERE ( 5 ) IN (SELECT * FROM v2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t1 system NULL NULL NULL NULL 1 4 UNION t2 system NULL NULL NULL NULL 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1484,7 +1484,7 @@ EXPLAIN SELECT ( 5 ) IN ( SELECT * FROM v2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t1 system NULL NULL NULL NULL 1 4 UNION t2 system NULL NULL NULL NULL 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL @@ -1635,8 +1635,8 @@ EXPLAIN SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE -2 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index +2 SUBQUERY t3 system NULL NULL NULL NULL 1 +2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); f4 drop table t1,t2,t3; diff --git a/mysql-test/r/subselect_extra_no_semijoin.result b/mysql-test/r/subselect_extra_no_semijoin.result index 773ee9898a4..ba001c71e3f 100644 --- a/mysql-test/r/subselect_extra_no_semijoin.result +++ b/mysql-test/r/subselect_extra_no_semijoin.result @@ -46,7 +46,7 @@ select * from t1 where id in (select id from t1 as x1 where (t1.cur_date is null)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE Warnings: Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1003 select 1 AS `id`,'2007-04-25 18:30:22' AS `cur_date` from dual where <1>((1,(select `test`.`x1`.`id` from `test`.`t1` `x1` where 0))) @@ -58,7 +58,7 @@ select * from t2 where id in (select id from t2 as x1 where (t2.cur_date is null)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE Warnings: Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1003 select 1 AS `id`,'2007-04-25' AS `cur_date` from dual where <1>((1,(select `test`.`x1`.`id` from `test`.`t2` `x1` where 0))) diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 323da97cc89..7485a9fa436 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -1163,7 +1163,7 @@ set @@optimizer_switch='materialization=off,in_to_exists=on'; explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); min(a1) NULL @@ -1182,7 +1182,7 @@ set @@optimizer_switch='materialization=off,in_to_exists=on'; explain select min(a1) from t1 where 7 in (select b1 from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2); min(a1) NULL @@ -1190,7 +1190,7 @@ NULL explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; min(a1) NULL @@ -2162,7 +2162,7 @@ EXPLAIN SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1) @@ -2179,7 +2179,7 @@ EXPLAIN SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1) @@ -2234,7 +2234,7 @@ EXPLAIN EXTENDED SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); 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 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 DROP TABLE t1,t2; diff --git a/mysql-test/r/subselect_mat_cost.result b/mysql-test/r/subselect_mat_cost.result index 893209a07fc..081196a227b 100644 --- a/mysql-test/r/subselect_mat_cost.result +++ b/mysql-test/r/subselect_mat_cost.result @@ -496,7 +496,7 @@ from City where City.population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY City range Population Population 5 NULL 4 Using index condition; Rowid-ordered scan -2 DEPENDENT SUBQUERY Country index_subquery CountryCapital CountryCapital 5 func 2 Using index; Using where +2 SUBQUERY Country index_subquery CountryCapital CountryCapital 5 func 2 Using index; Using where select Name, City.id in (select capital from Country where capital is not null) as is_capital from City where City.population > 10000000; diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index e656bf8e22f..635e868dd31 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -124,7 +124,7 @@ FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT t1.* FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 2465c1af367..0722ca7ba88 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -58,12 +58,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list) EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 select 1 AS `1` from dual having (<1>((select 1)) = 1) +Note 1003 select 1 AS `1` from dual having ((select 1) = 1) SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; 1 1 @@ -911,7 +911,7 @@ a t1.a in (select t2.a from t2) explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index +2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in t2 on a checking NULL having (`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` CREATE TABLE t3 (a int(11) default '0'); @@ -1324,7 +1324,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1334,7 +1334,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; @@ -1612,25 +1612,25 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<`test`.`t1`.`s1`>((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond((`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` drop table t1,t2; @@ -3103,7 +3103,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3115,7 +3115,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -3166,7 +3166,7 @@ INSERT INTO t2 VALUES (1),(2),(3); EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key +2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key SELECT a, a IN (SELECT a FROM t1) FROM t2; a a IN (SELECT a FROM t1) 1 1 @@ -3700,7 +3700,7 @@ ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index -2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 @@ -4526,13 +4526,13 @@ SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); 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 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; @@ -4579,7 +4579,7 @@ FROM t1 WHERE a = 230; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) FROM t1 WHERE a = 230; @@ -5714,7 +5714,7 @@ WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT b FROM t1 WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; @@ -6529,7 +6529,7 @@ EXPLAIN SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 NULL @@ -6537,7 +6537,7 @@ EXPLAIN SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 0 @@ -6572,7 +6572,7 @@ WHERE alias1.a = alias2.a OR alias1.a = 'y' HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) AS field FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR alias1.a = 'y' @@ -6586,7 +6586,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index 1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index 1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); @@ -6613,6 +6613,91 @@ SELECT * FROM t1 WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); a1 drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 6 +Subquery_cache_miss 2 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 8 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 22 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 7dacffe0b74..27cf1f70864 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -54,7 +54,7 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list) EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 @@ -907,7 +907,7 @@ a t1.a in (select t2.a from t2) explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index +2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a`,(((`test`.`t1`.`a`) in t2 on a checking NULL having (`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` CREATE TABLE t3 (a int(11) default '0'); @@ -1320,7 +1320,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1330,7 +1330,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; @@ -1608,25 +1608,25 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond((`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` drop table t1,t2; @@ -3099,7 +3099,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3111,7 +3111,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -3162,7 +3162,7 @@ INSERT INTO t2 VALUES (1),(2),(3); EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key +2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key SELECT a, a IN (SELECT a FROM t1) FROM t2; a a IN (SELECT a FROM t1) 1 1 @@ -3696,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index -2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 @@ -4522,13 +4522,13 @@ SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); 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 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; @@ -4575,7 +4575,7 @@ FROM t1 WHERE a = 230; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) FROM t1 WHERE a = 230; @@ -5710,7 +5710,7 @@ WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT b FROM t1 WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; @@ -6525,7 +6525,7 @@ EXPLAIN SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 NULL @@ -6533,7 +6533,7 @@ EXPLAIN SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 0 @@ -6568,7 +6568,7 @@ WHERE alias1.a = alias2.a OR alias1.a = 'y' HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) AS field FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR alias1.a = 'y' @@ -6582,7 +6582,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index 1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index 1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); @@ -6610,6 +6610,91 @@ SELECT * FROM t1 WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); a1 drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 6 +Subquery_cache_miss 2 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 8 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 22 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index e3a938cdece..9994ede79de 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -57,7 +57,7 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list) EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 @@ -910,7 +910,7 @@ a t1.a in (select t2.a from t2) explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index +2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a`,(((`test`.`t1`.`a`) in t2 on a checking NULL having (`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` CREATE TABLE t3 (a int(11) default '0'); @@ -1323,7 +1323,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1333,7 +1333,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; @@ -1611,25 +1611,25 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond((`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key Warnings: Note 1003 select `test`.`t1`.`s1` AS `s1`,(not((`test`.`t1`.`s1`,(((`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond((`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` drop table t1,t2; @@ -3103,7 +3103,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3115,7 +3115,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -3166,7 +3166,7 @@ INSERT INTO t2 VALUES (1),(2),(3); EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key +2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key SELECT a, a IN (SELECT a FROM t1) FROM t2; a a IN (SELECT a FROM t1) 1 1 @@ -3702,7 +3702,7 @@ ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index -2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 @@ -4583,7 +4583,7 @@ FROM t1 WHERE a = 230; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) FROM t1 WHERE a = 230; @@ -5719,7 +5719,7 @@ WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT b FROM t1 WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; @@ -6536,7 +6536,7 @@ EXPLAIN SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 NULL @@ -6544,7 +6544,7 @@ EXPLAIN SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 0 @@ -6579,7 +6579,7 @@ WHERE alias1.a = alias2.a OR alias1.a = 'y' HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) AS field FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR alias1.a = 'y' @@ -6593,7 +6593,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index 1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index 1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); @@ -6621,6 +6621,91 @@ SELECT * FROM t1 WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); a1 drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 58 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 6bb6b2861f9..1973262cdaf 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -54,12 +54,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list) EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 -3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 select 1 AS `1` from dual having (<1>((select 1)) = 1) +Note 1003 select 1 AS `1` from dual having ((select 1) = 1) SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; 1 1 @@ -1320,7 +1320,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1330,7 +1330,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; @@ -3099,7 +3099,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3111,7 +3111,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -3696,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index -2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 @@ -4522,13 +4522,13 @@ SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); 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 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where 0 SET join_cache_level=@save_join_cache_level; @@ -4575,7 +4575,7 @@ FROM t1 WHERE a = 230; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) FROM t1 WHERE a = 230; @@ -5710,7 +5710,7 @@ WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT b FROM t1 WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) GROUP BY b; @@ -6525,7 +6525,7 @@ EXPLAIN SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 NULL @@ -6533,7 +6533,7 @@ EXPLAIN SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; COUNT(f1) f4 0 0 @@ -6568,7 +6568,7 @@ WHERE alias1.a = alias2.a OR alias1.a = 'y' HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) AS field FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR alias1.a = 'y' @@ -6582,7 +6582,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index 1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index 1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where SELECT MAX( alias2.a ) FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); @@ -6610,6 +6610,91 @@ SELECT * FROM t1 WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); a1 drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 6 +Subquery_cache_miss 2 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 8 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 22 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_partial_match.result b/mysql-test/r/subselect_partial_match.result index 4e37b831326..9dc2b44fd30 100644 --- a/mysql-test/r/subselect_partial_match.result +++ b/mysql-test/r/subselect_partial_match.result @@ -879,7 +879,7 @@ EXPLAIN SELECT * FROM t1 WHERE (6, 4 ) NOT IN (SELECT b, a FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where SELECT * FROM t1 WHERE (6, 4 ) NOT IN (SELECT b, a FROM t2); c 0 @@ -888,7 +888,7 @@ EXPLAIN SELECT * FROM t1 WHERE (6, 4 ) NOT IN (SELECT a, b FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where SELECT * FROM t1 WHERE (6, 4 ) NOT IN (SELECT a, b FROM t2); c 0 @@ -913,7 +913,7 @@ set @@optimizer_switch='in_to_exists=on,materialization=off'; EXPLAIN SELECT * FROM t2 WHERE ( 3 , 1 ) NOT IN ( SELECT f1 , f2 FROM t1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t2 WHERE ( 3 , 1 ) NOT IN ( SELECT f1 , f2 FROM t1 ); f3 5 diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index d329c31fd16..01a4c7d67c9 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -1198,7 +1198,7 @@ set @@optimizer_switch='materialization=off,in_to_exists=on'; explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); min(a1) NULL @@ -1207,7 +1207,7 @@ set @@optimizer_switch='semijoin=off'; explain select min(a1) from t1 where 7 in (select b1 from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2); min(a1) NULL @@ -1224,7 +1224,7 @@ NULL explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; min(a1) NULL diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index f63ac838d2c..1cbb15b0b95 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -5580,5 +5580,49 @@ WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); drop table t1, t2; +--echo # +--echo # MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +--echo # inner joins takes hundreds times longer +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); + +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); + +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); + +set @@expensive_subquery_limit= 0; + +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; + +flush status; + +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; + +show status like "subquery_cache%"; +show status like '%Handler_read%'; + +set @@expensive_subquery_limit= default; + +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; + +flush status; + +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; + +show status like "subquery_cache%"; +show status like '%Handler_read%'; + +drop table t1, t2, t3; + --echo # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index fb5307f9e3a..0392e807519 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3443,6 +3443,7 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only) } bool empty_union_result= true; + bool is_correlated_unit= false; /* If the subquery is a UNION, optimize all the subqueries in the UNION. If there is no UNION, then the loop will execute once for the subquery. @@ -3467,6 +3468,8 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only) inner_join->select_options|= SELECT_DESCRIBE; } res= inner_join->optimize(); + sl->update_correlated_cache(); + is_correlated_unit|= sl->is_correlated; inner_join->select_options= save_options; un->thd->lex->current_select= save_select; if (empty_union_result) @@ -3482,6 +3485,9 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only) } if (empty_union_result) subquery_predicate->no_rows_in_result(); + if (!is_correlated_unit) + un->uncacheable&= ~UNCACHEABLE_DEPENDENT; + subquery_predicate->is_correlated= is_correlated_unit; } } return FALSE; @@ -3850,6 +3856,61 @@ void SELECT_LEX::update_used_tables() } +/** + @brief + Update is_correlated cache for this select + + @details +*/ + +void st_select_lex::update_correlated_cache() +{ + TABLE_LIST *tl; + List_iterator ti(leaf_tables); + + is_correlated= false; + + while ((tl= ti++)) + { + if (tl->on_expr) + is_correlated|= test(tl->on_expr->used_tables() & OUTER_REF_TABLE_BIT); + for (TABLE_LIST *embedding= tl->embedding ; embedding ; + embedding= embedding->embedding) + { + if (embedding->on_expr) + is_correlated|= test(embedding->on_expr->used_tables() & + OUTER_REF_TABLE_BIT); + } + } + + if (join->conds) + is_correlated|= test(join->conds->used_tables() & OUTER_REF_TABLE_BIT); + + if (join->having) + is_correlated|= test(join->having->used_tables() & OUTER_REF_TABLE_BIT); + + if (join->tmp_having) + is_correlated|= test(join->tmp_having->used_tables() & OUTER_REF_TABLE_BIT); + + Item *item; + List_iterator_fast it(join->fields_list); + while ((item= it++)) + is_correlated|= test(item->used_tables() & OUTER_REF_TABLE_BIT); + + for (ORDER *order= group_list.first; order; order= order->next) + is_correlated|= test((*order->item)->used_tables() & OUTER_REF_TABLE_BIT); + + if (!master_unit()->is_union()) + { + for (ORDER *order= order_list.first; order; order= order->next) + is_correlated|= test((*order->item)->used_tables() & OUTER_REF_TABLE_BIT); + } + + if (!is_correlated) + uncacheable&= ~UNCACHEABLE_DEPENDENT; +} + + /** Set the EXPLAIN type for this subquery. */ diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 922386151f8..bcc07f98586 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1018,6 +1018,7 @@ public: void mark_as_belong_to_derived(TABLE_LIST *derived); void increase_derived_records(ha_rows records); void update_used_tables(); + void update_correlated_cache(); void mark_const_derived(bool empty); bool save_leaf_tables(THD *thd); -- cgit v1.2.1 From 7ddd5418d01e60dba2ae69a668e7c9f811613451 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Jun 2012 14:10:15 +0300 Subject: Fixed bug MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin Analysis: The memory leak was a result of the interaction of semi-join optimization with early optimization of constant subqueries. The function: setup_jtbm_semi_joins() created a dummy temporary table "dummy_table" in order to make some JOIN_TAB objects complete. Normally, such temporary tables are freed inside JOIN_TAB::cleanup. However, the inner-most subquery is pre-optimized, which allows the optimization fo the MAX subquery to determine that its WHERE is TRUE, and thus to compute the result of the MAX during optimization. This ultimately allows the optimize phase of the outer query to find that it WHERE clause is FALSE. Once JOIN::optimize finds that the result set is empty, it sets zero_result_cause, and returns *before* it ever reached make_join_statistics(). As a result the query plan has no JOIN_TABs at all. Since the temporary table is supposed to be cleanup via JOIN_TAB::cleanup, this never happens because there is no JOIN_TAB for this table. Hence we get a memory leak. Solution: Whenever there are no JOIN_TABs, iterate over all table reference in JOIN::join_list, and free the ones that contain semi-join temporary tables. --- mysql-test/r/subselect.result | 16 ++++++++++++++++ mysql-test/r/subselect_no_mat.result | 16 ++++++++++++++++ mysql-test/r/subselect_no_opts.result | 16 ++++++++++++++++ mysql-test/r/subselect_no_scache.result | 16 ++++++++++++++++ mysql-test/r/subselect_no_semijoin.result | 16 ++++++++++++++++ mysql-test/t/subselect.test | 17 +++++++++++++++++ sql/sql_select.cc | 16 ++++++++++++++++ 7 files changed, 113 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index c90596315e1..bce5afaec43 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -6700,5 +6700,21 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 16 drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 0722ca7ba88..4ffb4600f77 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -6698,6 +6698,22 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 16 drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 27cf1f70864..c8251f67d2a 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -6695,6 +6695,22 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 16 drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 9994ede79de..07652189bfe 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -6706,6 +6706,22 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 16 drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 1973262cdaf..ecef51beb07 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -6695,6 +6695,22 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 16 drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 1cbb15b0b95..1074416cea6 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -5624,5 +5624,22 @@ show status like '%Handler_read%'; drop table t1, t2, t3; +--echo # +--echo # MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); + +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); + +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); + +drop table t1,t2; + + --echo # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 10c841639a9..865f3a9d425 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10595,6 +10595,22 @@ void JOIN::cleanup(bool full) tmp_join->tmp_table_param.save_copy_field= 0; } tmp_table_param.cleanup(); + + if (!join_tab) + { + List_iterator li(*join_list); + TABLE_LIST *table_ref; + while ((table_ref= li++)) + { + if (table_ref->table && + table_ref->jtbm_subselect && + table_ref->jtbm_subselect->is_jtbm_const_tab) + { + free_tmp_table(thd, table_ref->table); + table_ref->table= NULL; + } + } + } } DBUG_VOID_RETURN; } -- cgit v1.2.1 From 34f2f8ea41726d98e50752ff3453ebde70912c35 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 1 Jun 2012 17:53:59 +0200 Subject: MDEV-256 lp:995501 - mysqltest attempts to parse Perl code inside a block with false condition, gets confused and throws wrong errors --- client/mysqltest.cc | 11 +++++++---- mysql-test/r/mysqltest_256.result | 1 + mysql-test/t/mysqltest_256.test | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 mysql-test/r/mysqltest_256.result create mode 100644 mysql-test/t/mysqltest_256.test diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 68f076818dd..8f955ff586b 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -8259,8 +8259,12 @@ int main(int argc, char **argv) command->abort_on_error= (command->expected_errors.count == 0 && abort_on_error); - /* delimiter needs to be executed so we can continue to parse */ - ok_to_do= cur_block->ok || command->type == Q_DELIMITER; + /* + some commmands need to be executed or at least parsed unconditionally, + because they change the grammar. + */ + ok_to_do= cur_block->ok || command->type == Q_DELIMITER + || command->type == Q_PERL; /* Some commands need to be "done" the first time if they may get re-iterated over in a true context. This can only happen if there's @@ -8271,8 +8275,7 @@ int main(int argc, char **argv) if (command->type == Q_SOURCE || command->type == Q_ERROR || command->type == Q_WRITE_FILE || - command->type == Q_APPEND_FILE || - command->type == Q_PERL) + command->type == Q_APPEND_FILE) { for (struct st_block *stb= cur_block-1; stb >= block_stack; stb--) { diff --git a/mysql-test/r/mysqltest_256.result b/mysql-test/r/mysqltest_256.result new file mode 100644 index 00000000000..043c7208382 --- /dev/null +++ b/mysql-test/r/mysqltest_256.result @@ -0,0 +1 @@ +# Done diff --git a/mysql-test/t/mysqltest_256.test b/mysql-test/t/mysqltest_256.test new file mode 100644 index 00000000000..fd9447cd2d8 --- /dev/null +++ b/mysql-test/t/mysqltest_256.test @@ -0,0 +1,17 @@ +# +# MDEV-256 lp:995501 - mysqltest attempts to parse Perl code inside a block +# with false condition, gets confused and throws wrong errors +# + +let $run = 0; +if ($run) +{ + --perl + foreach (1) + { + print "In perl\n"; + } + EOF + SELECT 1; +} +--echo # Done -- cgit v1.2.1 From 38c4ef63b862fd59b4285fc3bfd9f5dff536649d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 6 Jun 2012 14:15:29 +0200 Subject: MDEV-302 lp:988204 MariaDB 5.5.23 binaries don't use libaio simplify debian/dist/*/rules slightly. move hard-coded config value to cmake files. (the actual fix is -DBUILD_CONFIG=mysql_release) --- CMakeLists.txt | 4 ++++ cmake/build_configurations/mysql_release.cmake | 15 +++++++++++++-- debian/dist/Debian/rules | 23 ++--------------------- debian/dist/Ubuntu/rules | 23 ++--------------------- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b0c4898785..2599a025e27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,10 @@ IF (NOT CPACK_GENERATOR) ENDIF(WIN32) ENDIF(NOT CPACK_GENERATOR) +IF(DEB) + SET(INSTALL_LAYOUT "DEB") +ENDIF(DEB) + INCLUDE(mysql_version) INCLUDE(cpack_rpm) INCLUDE(cpack_source_ignore_files) diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake index 87fe47cac12..5b2596491ad 100644 --- a/cmake/build_configurations/mysql_release.cmake +++ b/cmake/build_configurations/mysql_release.cmake @@ -94,8 +94,19 @@ IF(FEATURE_SET) ENDIF() OPTION(ENABLED_LOCAL_INFILE "" ON) -SET(WITH_SSL bundled CACHE STRING "") -SET(WITH_ZLIB bundled CACHE STRING "") +IF(RPM) + SET(WITH_SSL system CACHE STRING "") + SET(WITH_ZLIB system CACHE STRING "") +ELSEIF(DEB) + SET(WITH_SSL system CACHE STRING "") + SET(WITH_ZLIB system CACHE STRING "") + SET(WITH_LIBWRAP ON) + SET(WITH_MAX ON) + SET(HAVE_EMBEDDED_PRIVILEGE_CONTROL ON) +ELSE() + SET(WITH_SSL bundled CACHE STRING "") + SET(WITH_ZLIB bundled CACHE STRING "") +ENDIF() IF(NOT COMPILATION_COMMENT) SET(COMPILATION_COMMENT "MariaDB Server") diff --git a/debian/dist/Debian/rules b/debian/dist/Debian/rules index 5cb22ae60d6..96ad527542d 100755 --- a/debian/dist/Debian/rules +++ b/debian/dist/Debian/rules @@ -70,30 +70,11 @@ endif CXX=$${MYSQL_BUILD_CXX:-g++} \ CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \ cmake .. \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DINSTALL_SBINDIR=sbin \ - -DMYSQL_DATADIR=/var/lib/mysql \ - -DINSTALL_INCLUDEDIR=include/mysql \ - -DINSTALL_INFODIR=share/info \ - -DINSTALL_MANDIR=share/man \ - \ -DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \ + -DBUILD_CONFIG=mysql_release \ -DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DSYSTEM_TYPE="debian-linux-gnu" \ - -DINSTALL_LAYOUT=DEB \ - \ - -DENABLED_LOCAL_INFILE=1 \ - -DWITH_FAST_MUTEXES=1 \ - \ - -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \ - \ - -DEXTRA_CHARSETS=all \ - -DWITH_LIBWRAP=1 \ - -DWITH_SSL=system \ - -DWITH_ZLIB=system \ - -DWITH_EMBEDDED_SERVER=1 \ - -DHAVE_EMBEDDED_PRIVILEGE_CONTROL=ON \ - -DWITH_MAX=1' + -DDEB=debian' touch $@ diff --git a/debian/dist/Ubuntu/rules b/debian/dist/Ubuntu/rules index 592b2e4d7d1..bb413ad83cc 100755 --- a/debian/dist/Ubuntu/rules +++ b/debian/dist/Ubuntu/rules @@ -70,30 +70,11 @@ endif CXX=$${MYSQL_BUILD_CXX:-g++} \ CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \ cmake .. \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DINSTALL_SBINDIR=sbin \ - -DMYSQL_DATADIR=/var/lib/mysql \ - -DINSTALL_INCLUDEDIR=include/mysql \ - -DINSTALL_INFODIR=share/info \ - -DINSTALL_MANDIR=share/man \ - \ -DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \ + -DBUILD_CONFIG=mysql_release \ -DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DSYSTEM_TYPE="debian-linux-gnu" \ - -DINSTALL_LAYOUT=DEB \ - \ - -DENABLED_LOCAL_INFILE=1 \ - -DWITH_FAST_MUTEXES=1 \ - \ - -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \ - \ - -DEXTRA_CHARSETS=all \ - -DWITH_LIBWRAP=1 \ - -DWITH_SSL=system \ - -DWITH_ZLIB=system \ - -DWITH_EMBEDDED_SERVER=1 \ - -DHAVE_EMBEDDED_PRIVILEGE_CONTROL=ON \ - -DWITH_MAX=1' + -DDEB=ubuntu' touch $@ -- cgit v1.2.1 From 1838938671197b0ae40bed0a99ea62dbf4be2595 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 6 Jun 2012 16:41:13 +0200 Subject: fixes for bintar mtr failures: look for plugins in the correct path. skip --plugin-load if it has the empty soname part, not only if the whole argument is empty. --- mysql-test/mysql-test-run.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index ebe7af3641d..0f9006cad69 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2717,6 +2717,7 @@ sub setup_vardir() { # hm, what paths work for debs and for rpms ? for (<$bindir/lib64/mysql/plugin/*.so>, <$bindir/lib/mysql/plugin/*.so>, + <$bindir/lib/plugin/*.so>, # bintar <$bindir/lib/plugin/*.dll>) { my $pname=basename($_); @@ -5292,6 +5293,7 @@ sub mysqld_arguments ($$$) { } elsif ($plugin = mtr_match_prefix($arg, "--plugin-load=")) { + next if $plugin =~ /=$/; push @plugins, $plugin unless $seen{$plugin}; $seen{$plugin} = 1; } -- cgit v1.2.1 From e326a3893f1386875e82b0233b30434a4d296af5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Jun 2012 23:02:21 +0300 Subject: Fixed pbxt test case not run by default. --- mysql-test/suite/pbxt/r/subselect.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/pbxt/r/subselect.result b/mysql-test/suite/pbxt/r/subselect.result index 96e14cdf785..7ce54f02327 100644 --- a/mysql-test/suite/pbxt/r/subselect.result +++ b/mysql-test/suite/pbxt/r/subselect.result @@ -1188,7 +1188,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` INSERT INTO t1 (pseudo) VALUES ('test1'); @@ -1198,7 +1198,7 @@ SELECT 0 IN (SELECT 1 FROM t1 a); EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used -2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Note 1003 select (0,(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; -- cgit v1.2.1 From 7fcfdf7c16f44aed7eab293e020e7a5ee12ccb12 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 7 Jun 2012 19:15:41 +0200 Subject: client's option is default-character-set, server's is character-set-server --- debian/additions/mariadb.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/additions/mariadb.cnf b/debian/additions/mariadb.cnf index e3803c4aaeb..927e9d1ce88 100644 --- a/debian/additions/mariadb.cnf +++ b/debian/additions/mariadb.cnf @@ -3,7 +3,7 @@ [client] # Default is Latin1, if you need UTF-8 set this (also in server section) -#character-set-server = utf8 +#default-character-set = utf8 [mysqld] # -- cgit v1.2.1 From d2ca6d2e7ff028f6abbab52e36530046b3f84a49 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 8 Jun 2012 14:50:50 +0200 Subject: apply mysql fix for bug#58421 to XtraDB --- mysql-test/mysql-test-run.pl | 14 +------ storage/xtradb/os/os0file.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 14 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 0f9006cad69..2e02ab759ee 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -3464,12 +3464,6 @@ sub mysql_install_db { mtr_add_arg($args, "--lc-messages-dir=%s", $install_lang); mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir); - # On some old linux kernels, aio on tmpfs is not supported - # Remove this if/when Bug #58421 fixes this in the server - if ($^O eq "linux" && $opt_mem) { - mtr_add_arg($args, "--loose-skip-innodb-use-native-aio"); - } - # InnoDB arguments that affect file location and sizes may # need to be given to the bootstrap process as well as the # server process. @@ -4743,6 +4737,7 @@ sub extract_warning_lines ($$) { qr|Access denied for user|, qr|Aborted connection|, qr|table.*is full|, + qr|Linux Native AIO|, # warning that aio does not work on /dev/shm ); my $matched_lines= []; @@ -5246,13 +5241,6 @@ sub mysqld_arguments ($$$) { mtr_add_arg($args, "--user=root"); } - # On some old linux kernels, aio on tmpfs is not supported - # Remove this if/when Bug #58421 fixes this in the server - if ($^O eq "linux" && $opt_mem) - { - mtr_add_arg($args, "--loose-skip-innodb-use-native-aio"); - } - if (!using_extern() and !$opt_user_args) { # Turn on logging to file diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index 0c9b116b932..eefe17df740 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -3318,7 +3318,91 @@ retry: fprintf(stderr, "InnoDB: You can disable Linux Native AIO by" - " setting innodb_native_aio = off in my.cnf\n"); + " setting innodb_use_native_aio = 0 in my.cnf\n"); + return(FALSE); +} + +/******************************************************************//** +Checks if the system supports native linux aio. On some kernel +versions where native aio is supported it won't work on tmpfs. In such +cases we can't use native aio as it is not possible to mix simulated +and native aio. +@return: TRUE if supported, FALSE otherwise. */ +static +ibool +os_aio_native_aio_supported(void) +/*=============================*/ +{ + int fd; + byte* buf; + byte* ptr; + struct io_event io_event; + io_context_t io_ctx; + struct iocb iocb; + struct iocb* p_iocb; + int err; + + if (!os_aio_linux_create_io_ctx(1, &io_ctx)) { + /* The platform does not support native aio. */ + return(FALSE); + } + + /* Now check if tmpdir supports native aio ops. */ + fd = innobase_mysql_tmpfile(); + + if (fd < 0) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Error: unable to create " + "temp file to check native AIO support.\n"); + + return(FALSE); + } + + memset(&io_event, 0x0, sizeof(io_event)); + + buf = (byte*) ut_malloc(UNIV_PAGE_SIZE * 2); + ptr = (byte*) ut_align(buf, UNIV_PAGE_SIZE); + + /* Suppress valgrind warning. */ + memset(buf, 0x00, UNIV_PAGE_SIZE * 2); + + memset(&iocb, 0x0, sizeof(iocb)); + p_iocb = &iocb; + io_prep_pwrite(p_iocb, fd, ptr, UNIV_PAGE_SIZE, 0); + + err = io_submit(io_ctx, 1, &p_iocb); + if (err >= 1) { + /* Now collect the submitted IO request. */ + err = io_getevents(io_ctx, 1, 1, &io_event, NULL); + } + + ut_free(buf); + close(fd); + + switch (err) { + case 1: + return(TRUE); + + case -EINVAL: + case -ENOSYS: + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: Linux Native AIO is not" + " supported on tmpdir.\n" + "InnoDB: You can either move tmpdir to a" + " file system that supports native AIO\n" + "InnoDB: or you can set" + " innodb_use_native_aio to FALSE to avoid" + " this message.\n"); + + /* fall through. */ + default: + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: Linux Native AIO check" + " on tmpdir returned error[%d]\n", -err); + } + return(FALSE); } #endif /* LINUX_NATIVE_AIO */ @@ -3458,6 +3542,19 @@ os_aio_init( os_io_init_simple(); +#if defined(LINUX_NATIVE_AIO) + /* Check if native aio is supported on this system and tmpfs */ + if (srv_use_native_aio + && !os_aio_native_aio_supported()) { + + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Warning: Linux Native AIO" + " disabled.\n"); + srv_use_native_aio = FALSE; + } +#endif /* LINUX_NATIVE_AIO */ + for (i = 0; i < n_segments; i++) { srv_set_io_thread_op_info(i, "not started yet"); } -- cgit v1.2.1 From afe1ef5e3a1824ebbfd31fa95b6a198045a0ed34 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 8 Jun 2012 19:15:01 +0200 Subject: LP1008334 : Speedup specific datetime queries that got slower with introduction of microseconds in 5.3 - Item::get_seconds() now skips decimal arithmetic, if decimals is 0. This significantly speeds up from_unixtime() if no fractional part is passed. - replace sprintfs used to format temporal values by hand-coded formatting Query1 (original query in the bug report) BENCHMARK(10000000,DATE_SUB(FROM_UNIXTIME(RAND() * 2147483648), INTERVAL (FLOOR(1 + RAND() * 365)) DAY)) Query2 (Variation of query1 that does not use fractional part in FROM_UNIXTIME parameter) BENCHMARK(10000000,DATE_SUB(FROM_UNIXTIME(FLOOR(RAND() * 2147483648)), INTERVAL (FLOOR(1 + RAND() * 365)) DAY)) Prior to the patch, the runtimes were (32 bit compilation/AMD machine) Query1: 41.53 sec Query2: 23.90 sec With the patch, the runtimes are Query1: 32.32 sec (speed up due to removing sprintf) Query2: 12.06 sec (speed up due to skipping decimal arithmetic) --- sql-common/my_time.c | 97 +++++++++++++++++++++++++++++++++++++++++++--------- sql/item.cc | 2 +- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/sql-common/my_time.c b/sql-common/my_time.c index b009f8da7b9..5ad037ab6c9 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -1043,6 +1043,27 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type) } +/* + Helper function for datetime formatting. + Format number as string, left-padded with 0. + + The reason to use own formatting rather than sprintf() is performance - in a + datetime benchmark it helped to reduced the datetime formatting overhead + from ~30% down to ~4%. +*/ + +static char* fmt_number(uint val, char *out, uint digits) +{ + uint i; + for(i= 0; i < digits; i++) + { + out[digits-i-1]= '0' + val%10; + val/=10; + } + return out + digits; +} + + /* Functions to convert time/date/datetime value to a string, using default format. @@ -1056,42 +1077,84 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type) int my_time_to_str(const MYSQL_TIME *l_time, char *to, uint digits) { - ulong day= (l_time->year || l_time->month) ? 0 : l_time->day; + uint day= (l_time->year || l_time->month) ? 0 : l_time->day; + uint hour= day * 24 + l_time->hour; + char*pos= to; if (digits == AUTO_SEC_PART_DIGITS) digits= l_time->second_part ? TIME_SECOND_PART_DIGITS : 0; DBUG_ASSERT(digits <= TIME_SECOND_PART_DIGITS); - return sprintf(to, - digits ? "%s%02lu:%02u:%02u.%0*lu" - : "%s%02lu:%02u:%02u", - (l_time->neg ? "-" : ""), - day * 24L + l_time->hour, l_time->minute, l_time->second, - digits, (ulong)sec_part_shift(l_time->second_part, digits)); + if(l_time->neg) + *pos++= '-'; + + if(hour > 99) + /* Need more than 2 digits for hours in string representation. */ + pos= longlong10_to_str((longlong)hour, pos, 10); + else + pos= fmt_number(hour, pos, 2); + + *pos++= ':'; + pos= fmt_number(l_time->minute, pos, 2); + *pos++= ':'; + pos= fmt_number(l_time->second, pos, 2); + + if (digits) + { + *pos++= '.'; + pos= fmt_number((uint)sec_part_shift(l_time->second_part, digits), + pos, digits); + } + + *pos= 0; + return (int) (pos-to); } + int my_date_to_str(const MYSQL_TIME *l_time, char *to) { - return my_sprintf(to, (to, "%04u-%02u-%02u", - l_time->year, - l_time->month, - l_time->day)); + char *pos=to; + pos= fmt_number(l_time->year, pos, 4); + *pos++='-'; + pos= fmt_number(l_time->month, pos, 2); + *pos++='-'; + pos= fmt_number(l_time->day, pos, 2); + *pos= 0; + return (int)(pos - to); } + int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint digits) { + char *pos= to; + if (digits == AUTO_SEC_PART_DIGITS) digits= l_time->second_part ? TIME_SECOND_PART_DIGITS : 0; DBUG_ASSERT(digits <= TIME_SECOND_PART_DIGITS); - return sprintf(to, - digits ? "%04u-%02u-%02u %02u:%02u:%02u.%0*lu" - : "%04u-%02u-%02u %02u:%02u:%02u", - l_time->year, l_time->month, l_time->day, - l_time->hour, l_time->minute, l_time->second, - digits, (ulong)sec_part_shift(l_time->second_part, digits)); + pos= fmt_number(l_time->year, pos, 4); + *pos++='-'; + pos= fmt_number(l_time->month, pos, 2); + *pos++='-'; + pos= fmt_number(l_time->day, pos, 2); + *pos++=' '; + pos= fmt_number(l_time->hour, pos, 2); + *pos++= ':'; + pos= fmt_number(l_time->minute, pos, 2); + *pos++= ':'; + pos= fmt_number(l_time->second, pos, 2); + + if (digits) + { + *pos++='.'; + pos= fmt_number((uint) sec_part_shift(l_time->second_part, digits), pos, + digits); + } + + *pos= 0; + return (int)(pos - to); } diff --git a/sql/item.cc b/sql/item.cc index 15c4cf7aadf..a549fde3f5c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1190,7 +1190,7 @@ err: bool Item::get_seconds(ulonglong *sec, ulong *sec_part) { - if (result_type() == INT_RESULT) + if (decimals == 0) { // optimize for an important special case longlong val= val_int(); bool neg= val < 0 && !unsigned_flag; -- cgit v1.2.1 From 10f42e2c33dff630559299e4151e10a84ce39fd8 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 8 Jun 2012 22:15:49 -0700 Subject: Fixed LP bug #1010729. The bug prevented acceptance of UNION queries whose non-first select clauses contained join expressions with degenerated single-table nests as valid queries. The bug was introduced into mysql-5.5 code line by the patch for bug 33204. --- mysql-test/r/union.result | 17 +++++++++++++++++ mysql-test/t/union.test | 20 ++++++++++++++++++++ sql/sql_parse.cc | 1 + sql/sql_yacc.yy | 4 +++- sql/table.h | 2 ++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 1ac688787c6..75255d558c4 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -1845,3 +1845,20 @@ dev SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev; dev 1 +# +# LP bug#1010729: Unexpected syntax error from UNION +# (bug #54382) with single-table join nest +# +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +CREATE TABLE t3 (c int); +SELECT a FROM t1 UNION SELECT b FROM t2 JOIN (t3) ON ( t2.b = t3.c ); +a +DROP TABLE t1, t2, t3; +CREATE TABLE t1 (pk int NOT NULL); +CREATE TABLE t2 (pk int NOT NULL, fk int NOT NULL); +SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk) +UNION +SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk); +pk +DROP TABLE t1,t2; diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 9c03f93028c..94860ceec2d 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -1237,3 +1237,23 @@ SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a DESC LIM SELECT(SELECT 1 AS a ORDER BY a) AS dev; SELECT(SELECT 1 AS a LIMIT 1) AS dev; SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev; + +--echo # +--echo # LP bug#1010729: Unexpected syntax error from UNION +--echo # (bug #54382) with single-table join nest +--echo # +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int); +CREATE TABLE t3 (c int); +SELECT a FROM t1 UNION SELECT b FROM t2 JOIN (t3) ON ( t2.b = t3.c ); + +DROP TABLE t1, t2, t3; + +CREATE TABLE t1 (pk int NOT NULL); +CREATE TABLE t2 (pk int NOT NULL, fk int NOT NULL); +SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk) +UNION +SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk); + +DROP TABLE t1,t2; + diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 70258629197..4ee458c9806 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6192,6 +6192,7 @@ TABLE_LIST *st_select_lex::end_nested_join(THD *thd) embedded->embedding= embedding; join_list->push_front(embedded); ptr= embedded; + embedded->lifted= 1; } else if (nested_join->join_list.elements == 0) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 34e015e1f9b..6b580f2450c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9823,7 +9823,9 @@ table_factor: lex->nest_level--; } else if (($3->select_lex && - $3->select_lex->master_unit()->is_union()) || $5) + $3->select_lex->master_unit()->is_union() && + ($3->select_lex->master_unit()->first_select() == + $3->select_lex || !$3->lifted)) || $5) { /* simple nested joins cannot have aliases or unions */ my_parse_error(ER(ER_SYNTAX_ERROR)); diff --git a/sql/table.h b/sql/table.h index f3f9d5ac036..87affe984fc 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1800,6 +1800,8 @@ struct TABLE_LIST struct st_nested_join *nested_join; /* if the element is a nested join */ TABLE_LIST *embedding; /* nested join containing the table */ List *join_list;/* join list the table belongs to */ + bool lifted; /* set to true when the table is moved to + the upper level at the parsing stage */ bool cacheable_table; /* stop PS caching */ /* used in multi-upd/views privilege check */ bool table_in_first_from_clause; -- cgit v1.2.1 From 7b32d88c05756a37b15e7f11f4cd83fec25f42e2 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 11 Jun 2012 22:12:47 -0700 Subject: Fixed LP bug #1008293. One of the reported problems manifested itself in the scenario when one thread tried to to get statistics on a key cache while the second thread had not finished initialization of the key cache structure yet. The problem was resolved by forcing serialization of such operations on key caches. To serialize function calls to perform certain operations over a key cache a new mutex associated with the key cache now is used. It is stored in the field op_lock of the KEY_CACHE structure. It is locked when the operation is performed. Some of the serialized key cache operations utilize calls for other key cache operations. To avoid recursive locking of op_lock the new functions that perform the operations of key cache initialization, destruction and re-partitioning with an additional parameter were introduced. The parameter says whether the operation over op_lock are to be performed or are to be omitted. The old functions for the operations of key cache initialization, destruction,and re-partitioning now just call the corresponding new functions with the additional parameter set to true requesting to use op_lock while all other calls of these new function have this parameter set to false. Another problem reported in the bug entry concerned the operation of assigning an index to a key cache. This operation can be called while the key cache structures are not initialized yet. In this case any call of flush_key_blocks() should return without any actions. No test case is provided with this patch. --- include/keycache.h | 3 +- mysys/mf_keycache.c | 252 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 199 insertions(+), 56 deletions(-) diff --git a/include/keycache.h b/include/keycache.h index 12338037ea1..c19fa5988f8 100644 --- a/include/keycache.h +++ b/include/keycache.h @@ -150,9 +150,10 @@ typedef struct st_key_cache ulong param_partitions; /* number of the key cache partitions */ my_bool key_cache_inited; /* <=> key cache has been created */ my_bool can_be_used; /* usage of cache for read/write is allowed */ - my_bool in_init; /* Set to 1 in MySQL during init/resize */ + my_bool in_init; /* set to 1 in MySQL during init/resize */ uint partitions; /* actual number of partitions */ size_t key_cache_mem_size; /* specified size of the cache memory */ + pthread_mutex_t op_lock; /* to serialize operations like 'resize' */ } KEY_CACHE; diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index e0d495ce8e0..dc2d7fdd127 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -5863,31 +5863,31 @@ static KEY_CACHE_FUNCS partitioned_key_cache_funcs = ******************************************************************************/ +static +int repartition_key_cache_internal(KEY_CACHE *keycache, + uint key_cache_block_size, size_t use_mem, + uint division_limit, uint age_threshold, + uint partitions, my_bool use_op_lock); /* - Initialize a key cache + Initialize a key cache : internal SYNOPSIS - init_key_cache() + init_key_cache_internal() keycache pointer to the key cache to be initialized key_cache_block_size size of blocks to keep cached data use_mem total memory to use for cache buffers/structures division_limit division limit (may be zero) age_threshold age threshold (may be zero) partitions number of partitions in the key cache + use_op_lock if TRUE use keycache->op_lock, otherwise - ignore it DESCRIPTION - The function creates a control block structure for a key cache and - places the pointer to this block in the structure keycache. - If the value of the parameter 'partitions' is 0 then a simple key cache - is created. Otherwise a partitioned key cache with the specified number - of partitions is created. - The parameter key_cache_block_size specifies the size of the blocks in - the key cache to be created. The parameters division_limit and - age_threshold determine the initial values of those characteristics of - the key cache that are used for midpoint insertion strategy. The parameter - use_mem specifies the total amount of memory to be allocated for the - key cache buffers and for all auxiliary structures. + The function performs the actions required from init_key_cache(). + It has an additional parameter: use_op_lock. When the parameter + is TRUE than the function initializes keycache->op_lock if needed, + then locks it, and unlocks it before the return. Otherwise the actions + with the lock are omitted. RETURN VALUE total number of blocks in key cache partitions, if successful, @@ -5896,19 +5896,22 @@ static KEY_CACHE_FUNCS partitioned_key_cache_funcs = NOTES if keycache->key_cache_inited != 0 we assume that the memory for the control block of the key cache has been already allocated. - - It's assumed that no two threads call this function simultaneously - referring to the same key cache handle. */ -int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, - size_t use_mem, uint division_limit, - uint age_threshold, uint partitions) +static +int init_key_cache_internal(KEY_CACHE *keycache, uint key_cache_block_size, + size_t use_mem, uint division_limit, + uint age_threshold, uint partitions, + my_bool use_op_lock) { void *keycache_cb; int blocks; if (keycache->key_cache_inited) + { + if (use_op_lock) + pthread_mutex_lock(&keycache->op_lock); keycache_cb= keycache->keycache_cb; + } else { if (partitions == 0) @@ -5929,8 +5932,17 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, keycache->key_cache_type= PARTITIONED_KEY_CACHE; keycache->interface_funcs= &partitioned_key_cache_funcs; } + /* + Initialize op_lock if it's not initialized before. + The mutex may have been initialized before if we are being called + from repartition_key_cache_internal(). + */ + if (use_op_lock) + pthread_mutex_init(&keycache->op_lock, MY_MUTEX_INIT_FAST); keycache->keycache_cb= keycache_cb; keycache->key_cache_inited= 1; + if (use_op_lock) + pthread_mutex_lock(&keycache->op_lock); } if (partitions != 0) @@ -5951,10 +5963,57 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, ((SIMPLE_KEY_CACHE_CB *) keycache_cb)->key_cache_mem_size; if (blocks > 0) keycache->can_be_used= 1; + if (use_op_lock) + pthread_mutex_unlock(&keycache->op_lock); return blocks; } +/* + Initialize a key cache + + SYNOPSIS + init_key_cache() + keycache pointer to the key cache to be initialized + key_cache_block_size size of blocks to keep cached data + use_mem total memory to use for cache buffers/structures + division_limit division limit (may be zero) + age_threshold age threshold (may be zero) + partitions number of partitions in the key cache + + DESCRIPTION + The function creates a control block structure for a key cache and + places the pointer to this block in the structure keycache. + If the value of the parameter 'partitions' is 0 then a simple key cache + is created. Otherwise a partitioned key cache with the specified number + of partitions is created. + The parameter key_cache_block_size specifies the size of the blocks in + the key cache to be created. The parameters division_limit and + age_threshold determine the initial values of those characteristics of + the key cache that are used for midpoint insertion strategy. The parameter + use_mem specifies the total amount of memory to be allocated for the + key cache buffers and for all auxiliary structures. + The function calls init_key_cache_internal() to perform all these actions + with the last parameter set to TRUE. + + RETURN VALUE + total number of blocks in key cache partitions, if successful, + <= 0 - otherwise. + + NOTES + It's assumed that no two threads call this function simultaneously + referring to the same key cache handle. +*/ + +int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, + size_t use_mem, uint division_limit, + uint age_threshold, uint partitions) +{ + return init_key_cache_internal(keycache, key_cache_block_size, use_mem, + division_limit, age_threshold, partitions, 1); +} + + /* Resize a key cache @@ -5995,11 +6054,13 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, int blocks= -1; if (keycache->key_cache_inited) { + pthread_mutex_lock(&keycache->op_lock); if ((uint) keycache->param_partitions != keycache->partitions && use_mem) - blocks= repartition_key_cache(keycache, - key_cache_block_size, use_mem, - division_limit, age_threshold, - (uint) keycache->param_partitions); + blocks= repartition_key_cache_internal(keycache, + key_cache_block_size, use_mem, + division_limit, age_threshold, + (uint) keycache->param_partitions, + 0); else { blocks= keycache->interface_funcs->resize(keycache->keycache_cb, @@ -6018,6 +6079,7 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, ((SIMPLE_KEY_CACHE_CB *)(keycache->keycache_cb))->key_cache_mem_size; keycache->can_be_used= (blocks >= 0); + pthread_mutex_unlock(&keycache->op_lock); } return blocks; } @@ -6051,33 +6113,37 @@ void change_key_cache_param(KEY_CACHE *keycache, uint division_limit, { if (keycache->key_cache_inited) { - + pthread_mutex_lock(&keycache->op_lock); keycache->interface_funcs->change_param(keycache->keycache_cb, division_limit, - age_threshold); + age_threshold); + pthread_mutex_unlock(&keycache->op_lock); } } /* - Destroy a key cache + Destroy a key cache : internal SYNOPSIS - end_key_cache() + end_key_cache_internal() keycache pointer to the key cache to be destroyed cleanup <=> complete free + use_op_lock if TRUE use keycache->op_lock, otherwise - ignore it DESCRIPTION - The function frees the memory allocated for the cache blocks and - auxiliary structures used by the key cache keycache. If the value - of the parameter cleanup is TRUE then all resources used by the key - cache are to be freed. + The function performs the actions required from end_key_cache(). + It has an additional parameter: use_op_lock. When the parameter + is TRUE than the function destroys keycache->op_lock if cleanup is true. + Otherwise the action with the lock is omitted. RETURN VALUE none */ -void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) +static +void end_key_cache_internal(KEY_CACHE *keycache, my_bool cleanup, + my_bool use_op_lock) { if (keycache->key_cache_inited) { @@ -6089,6 +6155,12 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) my_free((uchar *) keycache->keycache_cb, MYF(0)); keycache->keycache_cb= 0; } + /* + We do not destroy op_lock if we are going to reuse the same key cache. + This happens if we are called from repartition_key_cache_internal(). + */ + if (use_op_lock) + pthread_mutex_destroy(&keycache->op_lock); keycache->key_cache_inited= 0; } keycache->can_be_used= 0; @@ -6096,6 +6168,32 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) } +/* + Destroy a key cache + + SYNOPSIS + end_key_cache() + keycache pointer to the key cache to be destroyed + cleanup <=> complete free + + DESCRIPTION + The function frees the memory allocated for the cache blocks and + auxiliary structures used by the key cache keycache. If the value + of the parameter cleanup is TRUE then all resources used by the key + cache are to be freed. + The function calls end_key_cache_internal() to perform all these actions + with the last parameter set to TRUE. + + RETURN VALUE + none +*/ + +void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) +{ + end_key_cache_internal(keycache, cleanup, 1); +} + + /* Read a block of data from a key cache into a buffer @@ -6140,7 +6238,7 @@ uchar *key_cache_read(KEY_CACHE *keycache, uchar *buff, uint length, uint block_length, int return_buffer) { - if (keycache->key_cache_inited && keycache->can_be_used) + if (keycache->can_be_used) return keycache->interface_funcs->read(keycache->keycache_cb, file, filepos, level, buff, length, @@ -6192,7 +6290,7 @@ int key_cache_insert(KEY_CACHE *keycache, File file, my_off_t filepos, int level, uchar *buff, uint length) { - if (keycache->key_cache_inited && keycache->can_be_used) + if (keycache->can_be_used) return keycache->interface_funcs->insert(keycache->keycache_cb, file, filepos, level, buff, length); @@ -6247,7 +6345,7 @@ int key_cache_write(KEY_CACHE *keycache, uchar *buff, uint length, uint block_length, int force_write) { - if (keycache->key_cache_inited && keycache->can_be_used) + if (keycache->can_be_used) return keycache->interface_funcs->write(keycache->keycache_cb, file, file_extra, filepos, level, @@ -6299,7 +6397,7 @@ int flush_key_blocks(KEY_CACHE *keycache, int file, void *file_extra, enum flush_type type) { - if (keycache->key_cache_inited) + if (keycache->can_be_used) return keycache->interface_funcs->flush(keycache->keycache_cb, file, file_extra, type); return 0; @@ -6330,13 +6428,15 @@ int flush_key_blocks(KEY_CACHE *keycache, int reset_key_cache_counters(const char *name __attribute__((unused)), KEY_CACHE *keycache) { + int rc= 0; if (keycache->key_cache_inited) { - - return keycache->interface_funcs->reset_counters(name, - keycache->keycache_cb); + pthread_mutex_lock(&keycache->op_lock); + rc= keycache->interface_funcs->reset_counters(name, + keycache->keycache_cb); + pthread_mutex_unlock(&keycache->op_lock); } - return 0; + return rc; } @@ -6366,11 +6466,63 @@ void get_key_cache_statistics(KEY_CACHE *keycache, uint partition_no, { if (keycache->key_cache_inited) { + pthread_mutex_lock(&keycache->op_lock); keycache->interface_funcs->get_stats(keycache->keycache_cb, partition_no, key_cache_stats); + pthread_mutex_unlock(&keycache->op_lock); } } + +/* + Repartition a key cache : internal + + SYNOPSIS + repartition_key_cache_internal() + keycache pointer to the key cache to be repartitioned + key_cache_block_size size of blocks to keep cached data + use_mem total memory to use for the new key cache + division_limit new division limit (if not zero) + age_threshold new age threshold (if not zero) + partitions new number of partitions in the key cache + use_op_lock if TRUE use keycache->op_lock, otherwise - ignore it + + DESCRIPTION + The function performs the actions required from repartition_key_cache(). + It has an additional parameter: use_op_lock. When the parameter + is TRUE then the function locks keycache->op_lock at start and + unlocks it before the return. Otherwise the actions with the lock + are omitted. + + RETURN VALUE + number of blocks in the key cache, if successful, + 0 - otherwise. +*/ + +static +int repartition_key_cache_internal(KEY_CACHE *keycache, + uint key_cache_block_size, size_t use_mem, + uint division_limit, uint age_threshold, + uint partitions, my_bool use_op_lock) +{ + uint blocks= -1; + if (keycache->key_cache_inited) + { + if (use_op_lock) + pthread_mutex_lock(&keycache->op_lock); + keycache->interface_funcs->resize(keycache->keycache_cb, + key_cache_block_size, 0, + division_limit, age_threshold); + end_key_cache_internal(keycache, 1, 0); + blocks= init_key_cache_internal(keycache, key_cache_block_size, use_mem, + division_limit, age_threshold, partitions, + 0); + if (use_op_lock) + pthread_mutex_unlock(&keycache->op_lock); + } + return blocks; +} + /* Repartition a key cache @@ -6394,16 +6546,14 @@ void get_key_cache_statistics(KEY_CACHE *keycache, uint partition_no, that are used for midpoint insertion strategy. The parameter use_mem specifies the total amount of memory to be allocated for the new key cache buffers and for all auxiliary structures. + The function calls repartition_key_cache_internal() to perform all these + actions with the last parameter set to TRUE. RETURN VALUE number of blocks in the key cache, if successful, 0 - otherwise. NOTES - The function does not block the calls and executions of other functions - from the key cache interface. However it assumes that the calls of - resize_key_cache itself are serialized. - Currently the function is called when the value of the variable key_cache_partitions is being reset for the key cache keycache. */ @@ -6412,16 +6562,8 @@ int repartition_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold, uint partitions) { - uint blocks= -1; - if (keycache->key_cache_inited) - { - keycache->interface_funcs->resize(keycache->keycache_cb, - key_cache_block_size, 0, - division_limit, age_threshold); - end_key_cache(keycache, 1); - blocks= init_key_cache(keycache, key_cache_block_size, use_mem, - division_limit, age_threshold, partitions); - } - return blocks; + return repartition_key_cache_internal(keycache, key_cache_block_size, use_mem, + division_limit, age_threshold, + partitions, 1); } -- cgit v1.2.1 From 64aa1fcb1354ffa24999a1512258c897116b0928 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 12 Jun 2012 10:06:26 -0700 Subject: Adjusted results in pbxt.negation_elimination after the fix for lp bug 992380. --- mysql-test/suite/pbxt/r/negation_elimination.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/pbxt/r/negation_elimination.result b/mysql-test/suite/pbxt/r/negation_elimination.result index 80225cd6044..3b968e396c5 100644 --- a/mysql-test/suite/pbxt/r/negation_elimination.result +++ b/mysql-test/suite/pbxt/r/negation_elimination.result @@ -321,7 +321,7 @@ select * from t1 where not(NULL or a); a explain select * from t1 where not(NULL and a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 5 NULL 21 Using where; Using index +1 SIMPLE t1 ref a a 5 const 1 Using where; Using index select * from t1 where not(NULL and a); a 0 @@ -390,5 +390,5 @@ explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like " id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index a a 5 NULL 5 40.00 Using where; Using index Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or `test`.`t1`.`a`) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) +Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or (`test`.`t1`.`a` <> 0)) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) drop table t1; -- cgit v1.2.1 From 88d3d853f4802ea48bcbe0b017d9e2403895632d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Jun 2012 17:03:09 +0300 Subject: Fix bug lp:1008773 Analysis: Queries with implicit grouping (there is aggregate, but no group by) follow some non-obvious semantics in the case of empty result set. Aggregate functions produce some special "natural" value depending on the function. For instance MIN/MAX return NULL, COUNT returns 0. The complexity comes from non-aggregate expressions in the select list. If the non-aggregate expression is a constant, it can be computed, so we should return its value, however if the expression is non-constant, and depends on columns from the empty result set, then the only meaningful value is NULL. The cause of the wrong result was that for subqueries the optimizer didn't make a difference between constant and non-constant ones in the case of empty result for implicit grouping. Solution: In all implementations of Item_subselect::no_rows_in_result() check if the subquery predicate is constant. If it is constant, do not set it to the default value for implicit grouping, instead let it be evaluated. --- mysql-test/r/subselect4.result | 55 ++++++++++++++++++++++++++++++++++++++++++ mysql-test/t/subselect4.test | 34 ++++++++++++++++++++++++++ sql/item_subselect.cc | 8 ++++++ 3 files changed, 97 insertions(+) diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index 5e2baf47aec..8573b5bb8c4 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -2139,6 +2139,61 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 10 Using where 2 SUBQUERY five ALL NULL NULL NULL NULL 5 Using where drop table ten, t1, five; +# +# LP BUG#1008773 Wrong result (NULL instead of a value) with no matching rows, subquery in FROM and HAVING +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1); +EXPLAIN +SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 1 +SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1; +MAX(a) bb +NULL 1 +EXPLAIN +SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY t2 system NULL NULL NULL NULL 1 +SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1; +MAX(a) bb +NULL 1 +EXPLAIN +SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +MAX(a) bb +NULL 1 +EXPLAIN +SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1; +MAX(a) bb +NULL NULL +EXPLAIN +SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1; +MAX(a) bb +NULL NULL +EXPLAIN +SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +MAX(a) bb +NULL NULL +drop table t1, t2; set optimizer_switch=@subselect4_tmp; SET optimizer_switch= @@global.optimizer_switch; set @@tmp_table_size= @@global.tmp_table_size; diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test index 92b34db05e4..e978ebdbfcc 100644 --- a/mysql-test/t/subselect4.test +++ b/mysql-test/t/subselect4.test @@ -1777,6 +1777,40 @@ explain select * from t1 where 33 in (select b from five) or c > 11; drop table ten, t1, five; +--echo # +--echo # LP BUG#1008773 Wrong result (NULL instead of a value) with no matching rows, subquery in FROM and HAVING +--echo # + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1); + +EXPLAIN +SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1; +SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1; + +EXPLAIN +SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1; +SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1; + +EXPLAIN +SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; + + +EXPLAIN +SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1; +SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1; + +EXPLAIN +SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1; +SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1; + +EXPLAIN +SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; +SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1; + +drop table t1, t2; set optimizer_switch=@subselect4_tmp; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index cae1a9f7541..5af8eb9ebc9 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -892,6 +892,8 @@ void Item_maxmin_subselect::print(String *str, enum_query_type query_type) void Item_maxmin_subselect::no_rows_in_result() { + if (const_item()) + return; value= Item_cache::get_cache(new Item_null()); null_value= 0; was_values= 0; @@ -901,6 +903,8 @@ void Item_maxmin_subselect::no_rows_in_result() void Item_singlerow_subselect::no_rows_in_result() { + if (const_item()) + return; value= Item_cache::get_cache(new Item_null()); reset(); make_const(); @@ -1363,6 +1367,8 @@ Item* Item_exists_subselect::expr_cache_insert_transformer(uchar *thd_arg) void Item_exists_subselect::no_rows_in_result() { + if (const_item()) + return; value= 0; null_value= 0; make_const(); @@ -2707,6 +2713,8 @@ void Item_allany_subselect::print(String *str, enum_query_type query_type) void Item_allany_subselect::no_rows_in_result() { + if (const_item()) + return; value= 0; null_value= 0; was_null= 0; -- cgit v1.2.1 From 1d74ae6b42296edb585d42439ca472632c57d06e Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 15 Jun 2012 00:01:20 -0700 Subject: Fixed LP bug #1002157. The class Item_func missed an implementation of the virtual function update_null_value. Back-ported the fix for bug 62125 from mysql 5.6 code line. The test case was also back-ported. --- mysql-test/r/sp.result | 33 +++++++++++++++++++++++++++++++++ mysql-test/t/sp.test | 41 +++++++++++++++++++++++++++++++++++++++++ sql/item_func.h | 6 ++++++ 3 files changed, 80 insertions(+) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 05f9000bb33..414eeada0de 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -7849,3 +7849,36 @@ c1 c2 count(c3) 2012-03-01 01:00:00 3 1 2012-03-01 02:00:00 3 1 DROP PROCEDURE p1; +# +# LP bug#1002157 : testing stored function +# bug#62125 result for null incorrectly yields 1292 warning. +# +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +CREATE FUNCTION f1() RETURNS VARCHAR(1) +BEGIN RETURN 'X'; END;/ +CREATE FUNCTION f2() RETURNS CHAR(1) +BEGIN RETURN 'X'; END;/ +CREATE FUNCTION f3() RETURNS VARCHAR(1) +BEGIN RETURN NULL; END;/ +CREATE FUNCTION f4() RETURNS CHAR(1) +BEGIN RETURN NULL; END;/ +SELECT f1() IS NULL; +f1() IS NULL +0 +SELECT f2() IS NULL; +f2() IS NULL +0 +SELECT f3() IS NULL; +f3() IS NULL +1 +SELECT f4() IS NULL; +f4() IS NULL +1 +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; +# End of 5.5 test diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 5d92fea0bf1..08421040109 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9145,3 +9145,44 @@ CALL p1(2); CALL p1(1); DROP PROCEDURE p1; + +--echo # +--echo # LP bug#1002157 : testing stored function +--echo # bug#62125 result for null incorrectly yields 1292 warning. +--echo # + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +--enable_warnings + +delimiter /; + +CREATE FUNCTION f1() RETURNS VARCHAR(1) +BEGIN RETURN 'X'; END;/ + +CREATE FUNCTION f2() RETURNS CHAR(1) +BEGIN RETURN 'X'; END;/ + +CREATE FUNCTION f3() RETURNS VARCHAR(1) +BEGIN RETURN NULL; END;/ + +CREATE FUNCTION f4() RETURNS CHAR(1) +BEGIN RETURN NULL; END;/ + +delimiter ;/ + +SELECT f1() IS NULL; +SELECT f2() IS NULL; +SELECT f3() IS NULL; +SELECT f4() IS NULL; + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; + +--echo # End of 5.5 test + diff --git a/sql/item_func.h b/sql/item_func.h index f91107c5445..cb9c1929d7d 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1941,6 +1941,11 @@ public: return str; } + void update_null_value() + { + execute(); + } + virtual bool change_context_processor(uchar *cntx) { context= (Name_resolution_context *)cntx; return FALSE; } @@ -1955,6 +1960,7 @@ public: { return sp_result_field; } + bool check_vcol_func_processor(uchar *int_arg) { return trace_unsupported_by_check_vcol_func_processor(func_name()); -- cgit v1.2.1 From 6de579241ed0bf01dfad1a7cede9fde36a1c5c03 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 15 Jun 2012 10:23:33 +0200 Subject: XtraDB 1.1.8-20.1 from Percona-Server 5.5.24-rel26.0 --- btr/btr0btr.c | 315 ++++++++++++++++++++++---------- btr/btr0cur.c | 264 ++++++++++++++++++--------- btr/btr0pcur.c | 89 ++++++--- btr/btr0sea.c | 8 +- buf/buf0buf.c | 81 +++++---- buf/buf0flu.c | 19 +- buf/buf0lru.c | 463 +++++++++++++++++++++++++++++++++++++---------- dict/dict0boot.c | 221 ++++++++++++++++------ dict/dict0dict.c | 42 ++++- dict/dict0load.c | 42 ++--- fil/fil0fil.c | 108 ++++++----- fsp/fsp0fsp.c | 440 ++++++++++++++++++++++++-------------------- handler/ha_innodb.cc | 429 +++++++++++++++++++++++++++++++------------ handler/ha_innodb.h | 13 +- handler/handler0alter.cc | 21 ++- ibuf/ibuf0ibuf.c | 130 ++++++++----- include/btr0btr.h | 58 ++++-- include/btr0btr.ic | 2 +- include/btr0cur.h | 88 ++++----- include/btr0cur.ic | 29 ++- include/btr0pcur.h | 10 + include/buf0buf.h | 52 +++++- include/buf0buf.ic | 21 +-- include/buf0lru.h | 11 +- include/buf0types.h | 9 + include/data0data.h | 23 ++- include/data0data.ic | 53 ++++-- include/db0err.h | 8 +- include/dict0boot.h | 20 ++ include/dict0dict.h | 14 +- include/dict0dict.ic | 21 +-- include/dict0mem.h | 10 +- include/fil0fil.h | 19 +- include/fsp0fsp.h | 40 ++-- include/log0log.h | 6 +- include/mem0mem.ic | 4 - include/mtr0log.ic | 3 +- include/mtr0mtr.h | 13 +- include/mtr0mtr.ic | 11 +- include/page0page.h | 43 ++++- include/page0page.ic | 38 +++- include/row0mysql.h | 8 +- include/row0sel.h | 7 +- include/srv0srv.h | 18 +- include/sync0rw.h | 18 ++ include/sync0rw.ic | 8 +- include/sync0sync.h | 10 +- include/trx0purge.h | 4 +- include/trx0rec.ic | 7 +- include/trx0rseg.ic | 9 +- include/trx0sys.h | 6 + include/trx0undo.h | 13 +- include/univ.i | 33 ++-- include/ut0mem.h | 31 +--- include/ut0rnd.ic | 2 +- lock/lock0lock.c | 141 +++++++++------ log/log0log.c | 175 +++++++++++++----- mem/mem0pool.c | 6 +- mtr/mtr0mtr.c | 6 +- os/os0file.c | 99 +++++++++- os/os0proc.c | 3 - page/page0cur.c | 23 ++- page/page0page.c | 73 ++++---- pars/pars0pars.c | 2 +- row/row0ins.c | 90 ++++++++- row/row0merge.c | 127 +++++++++---- row/row0mysql.c | 156 +++++++++++++--- row/row0row.c | 25 ++- row/row0sel.c | 36 ++-- row/row0umod.c | 3 +- row/row0upd.c | 65 +++++-- srv/srv0srv.c | 109 ++++++++--- srv/srv0start.c | 11 +- sync/sync0rw.c | 10 +- sync/sync0sync.c | 16 +- trx/trx0purge.c | 5 +- trx/trx0rec.c | 42 +++-- trx/trx0sys.c | 62 +++---- trx/trx0trx.c | 2 + trx/trx0undo.c | 43 +++-- ut/ut0mem.c | 82 +-------- ut/ut0ut.c | 8 +- 82 files changed, 3299 insertions(+), 1586 deletions(-) diff --git a/btr/btr0btr.c b/btr/btr0btr.c index 433b062bcec..1fa6df44f7c 100644 --- a/btr/btr0btr.c +++ b/btr/btr0btr.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -42,6 +42,28 @@ Created 6/2/1994 Heikki Tuuri #include "ibuf0ibuf.h" #include "trx0trx.h" +/**************************************************************//** +Report that an index page is corrupted. */ +UNIV_INTERN +void +btr_corruption_report( +/*==================*/ + const buf_block_t* block, /*!< in: corrupted block */ + const dict_index_t* index) /*!< in: index tree */ +{ + fprintf(stderr, "InnoDB: flag mismatch in space %u page %u" + " index %s of table %s\n", + (unsigned) buf_block_get_space(block), + (unsigned) buf_block_get_page_no(block), + index->name, index->table_name); + if (block->page.zip.data) { + buf_page_print(block->page.zip.data, + buf_block_get_zip_size(block), + BUF_PAGE_PRINT_NO_CRASH); + } + buf_page_print(buf_block_get_frame(block), 0, 0); +} + #ifdef UNIV_BLOB_DEBUG # include "srv0srv.h" # include "ut0rbt.h" @@ -664,6 +686,12 @@ btr_root_fseg_validate( { ulint offset = mach_read_from_2(seg_header + FSEG_HDR_OFFSET); + if (UNIV_UNLIKELY(srv_pass_corrupt_table)) { + return (mach_read_from_4(seg_header + FSEG_HDR_SPACE) == space) + && (offset >= FIL_PAGE_DATA) + && (offset <= UNIV_PAGE_SIZE - FIL_PAGE_DATA_END); + } + ut_a(mach_read_from_4(seg_header + FSEG_HDR_SPACE) == space); ut_a(offset >= FIL_PAGE_DATA); ut_a(offset <= UNIV_PAGE_SIZE - FIL_PAGE_DATA_END); @@ -698,12 +726,22 @@ btr_root_block_get( } ut_a(block); - ut_a((ibool)!!page_is_comp(buf_block_get_frame(block)) - == dict_table_is_comp(index->table)); + btr_assert_not_corrupted(block, index); #ifdef UNIV_BTR_DEBUG if (!dict_index_is_ibuf(index)) { const page_t* root = buf_block_get_frame(block); + if (UNIV_UNLIKELY(srv_pass_corrupt_table)) { + if (!btr_root_fseg_validate(FIL_PAGE_DATA + + PAGE_BTR_SEG_LEAF + + root, space)) + return(NULL); + if (!btr_root_fseg_validate(FIL_PAGE_DATA + + PAGE_BTR_SEG_TOP + + root, space)) + return(NULL); + return(block); + } ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_LEAF + root, space)); ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_TOP @@ -912,28 +950,31 @@ btr_page_alloc_for_ibuf( /**************************************************************//** Allocates a new file page to be used in an index tree. NOTE: we assume that the caller has made the reservation for free extents! -@return new allocated block, x-latched; NULL if out of space */ -UNIV_INTERN +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ +static __attribute__((nonnull, warn_unused_result)) buf_block_t* -btr_page_alloc( -/*===========*/ +btr_page_alloc_low( +/*===============*/ dict_index_t* index, /*!< in: index */ ulint hint_page_no, /*!< in: hint of a good page */ byte file_direction, /*!< in: direction where a possible page split is made */ ulint level, /*!< in: level where the page is placed in the tree */ - mtr_t* mtr) /*!< in: mtr */ + mtr_t* mtr, /*!< in/out: mini-transaction + for the allocation */ + mtr_t* init_mtr) /*!< in/out: mtr or another + mini-transaction in which the + page should be initialized. + If init_mtr!=mtr, but the page + is already X-latched in mtr, do + not initialize the page. */ { fseg_header_t* seg_header; page_t* root; - buf_block_t* new_block; - ulint new_page_no; - - if (dict_index_is_ibuf(index)) { - - return(btr_page_alloc_for_ibuf(index, mtr)); - } root = btr_root_get(index, mtr); @@ -947,45 +988,81 @@ btr_page_alloc( reservation for free extents, and thus we know that a page can be allocated: */ - new_page_no = fseg_alloc_free_page_general(seg_header, hint_page_no, - file_direction, TRUE, mtr); - if (new_page_no == FIL_NULL) { + return(fseg_alloc_free_page_general( + seg_header, hint_page_no, file_direction, + TRUE, mtr, init_mtr)); +} - return(NULL); +/**************************************************************//** +Allocates a new file page to be used in an index tree. NOTE: we assume +that the caller has made the reservation for free extents! +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ +UNIV_INTERN +buf_block_t* +btr_page_alloc( +/*===========*/ + dict_index_t* index, /*!< in: index */ + ulint hint_page_no, /*!< in: hint of a good page */ + byte file_direction, /*!< in: direction where a possible + page split is made */ + ulint level, /*!< in: level where the page is placed + in the tree */ + mtr_t* mtr, /*!< in/out: mini-transaction + for the allocation */ + mtr_t* init_mtr) /*!< in/out: mini-transaction + for x-latching and initializing + the page */ +{ + buf_block_t* new_block; + + if (dict_index_is_ibuf(index)) { + + return(btr_page_alloc_for_ibuf(index, mtr)); } - new_block = buf_page_get(dict_index_get_space(index), - dict_table_zip_size(index->table), - new_page_no, RW_X_LATCH, mtr); - buf_block_dbg_add_level(new_block, SYNC_TREE_NODE_NEW); + new_block = btr_page_alloc_low( + index, hint_page_no, file_direction, level, mtr, init_mtr); + + if (new_block) { + buf_block_dbg_add_level(new_block, SYNC_TREE_NODE_NEW); + } return(new_block); } /**************************************************************//** Gets the number of pages in a B-tree. -@return number of pages */ +@return number of pages, or ULINT_UNDEFINED if the index is unavailable */ UNIV_INTERN ulint btr_get_size( /*=========*/ dict_index_t* index, /*!< in: index */ - ulint flag) /*!< in: BTR_N_LEAF_PAGES or BTR_TOTAL_SIZE */ + ulint flag, /*!< in: BTR_N_LEAF_PAGES or BTR_TOTAL_SIZE */ + mtr_t* mtr) /*!< in/out: mini-transaction where index + is s-latched */ { fseg_header_t* seg_header; page_t* root; ulint n; ulint dummy; - mtr_t mtr; - mtr_start(&mtr); + ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index), + MTR_MEMO_S_LOCK)); - mtr_s_lock(dict_index_get_lock(index), &mtr); + if (index->page == FIL_NULL + || index->to_be_dropped + || *index->name == TEMP_INDEX_PREFIX) { + return(ULINT_UNDEFINED); + } - root = btr_root_get(index, &mtr); + root = btr_root_get(index, mtr); if (srv_pass_corrupt_table && !root) { - mtr_commit(&mtr); + mtr_commit(mtr); return(0); } ut_a(root); @@ -993,22 +1070,20 @@ btr_get_size( if (flag == BTR_N_LEAF_PAGES) { seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF; - fseg_n_reserved_pages(seg_header, &n, &mtr); + fseg_n_reserved_pages(seg_header, &n, mtr); } else if (flag == BTR_TOTAL_SIZE) { seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_TOP; - n = fseg_n_reserved_pages(seg_header, &dummy, &mtr); + n = fseg_n_reserved_pages(seg_header, &dummy, mtr); seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF; - n += fseg_n_reserved_pages(seg_header, &dummy, &mtr); + n += fseg_n_reserved_pages(seg_header, &dummy, mtr); } else { ut_error; } - mtr_commit(&mtr); - return(n); } @@ -1090,10 +1165,10 @@ btr_page_free( buf_block_t* block, /*!< in: block to be freed, x-latched */ mtr_t* mtr) /*!< in: mtr */ { - ulint level; - - level = btr_page_get_level(buf_block_get_frame(block), mtr); + const page_t* page = buf_block_get_frame(block); + ulint level = btr_page_get_level(page, mtr); + ut_ad(fil_page_get_type(block->frame) == FIL_PAGE_INDEX); btr_page_free_low(index, block, level, mtr); } @@ -1207,9 +1282,11 @@ btr_page_get_father_node_ptr_func( != page_no)) { rec_t* print_rec; fputs("InnoDB: Dump of the child page:\n", stderr); - buf_page_print(page_align(user_rec), 0); + buf_page_print(page_align(user_rec), 0, + BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: Dump of the parent page:\n", stderr); - buf_page_print(page_align(node_ptr), 0); + buf_page_print(page_align(node_ptr), 0, + BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: Corruption of an index tree: table ", stderr); ut_print_name(stderr, NULL, TRUE, index->table_name); @@ -1333,16 +1410,12 @@ btr_create( /* Allocate then the next page to the segment: it will be the tree root page */ - page_no = fseg_alloc_free_page(buf_block_get_frame( - ibuf_hdr_block) - + IBUF_HEADER - + IBUF_TREE_SEG_HEADER, - IBUF_TREE_ROOT_PAGE_NO, - FSP_UP, mtr); - ut_ad(page_no == IBUF_TREE_ROOT_PAGE_NO); - - block = buf_page_get(space, zip_size, page_no, - RW_X_LATCH, mtr); + block = fseg_alloc_free_page( + buf_block_get_frame(ibuf_hdr_block) + + IBUF_HEADER + IBUF_TREE_SEG_HEADER, + IBUF_TREE_ROOT_PAGE_NO, + FSP_UP, mtr); + ut_ad(buf_block_get_page_no(block) == IBUF_TREE_ROOT_PAGE_NO); } else { #ifdef UNIV_BLOB_DEBUG if ((type & DICT_CLUSTERED) && !index->blobs) { @@ -1562,7 +1635,7 @@ btr_page_reorganize_low( ibool success = FALSE; ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX)); - ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table)); + btr_assert_not_corrupted(block, index); #ifdef UNIV_ZIP_DEBUG ut_a(!page_zip || page_zip_validate(page_zip, page)); #endif /* UNIV_ZIP_DEBUG */ @@ -1664,8 +1737,8 @@ btr_page_reorganize_low( if (UNIV_UNLIKELY(data_size1 != data_size2) || UNIV_UNLIKELY(max_ins_size1 != max_ins_size2)) { - buf_page_print(page, 0); - buf_page_print(temp_page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(temp_page, 0, BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "InnoDB: Error: page old data size %lu" " new data size %lu\n" @@ -1676,6 +1749,7 @@ btr_page_reorganize_low( (unsigned long) data_size1, (unsigned long) data_size2, (unsigned long) max_ins_size1, (unsigned long) max_ins_size2); + ut_ad(0); } else { success = TRUE; } @@ -1839,7 +1913,7 @@ btr_root_raise_and_insert( level = btr_page_get_level(root, mtr); - new_block = btr_page_alloc(index, 0, FSP_NO_DIR, level, mtr); + new_block = btr_page_alloc(index, 0, FSP_NO_DIR, level, mtr, mtr); new_page = buf_block_get_frame(new_block); new_page_zip = buf_block_get_page_zip(new_block); ut_a(!new_page_zip == !root_page_zip); @@ -2575,7 +2649,7 @@ func_start: /* 2. Allocate a new page to the index */ new_block = btr_page_alloc(cursor->index, hint_page_no, direction, - btr_page_get_level(page, mtr), mtr); + btr_page_get_level(page, mtr), mtr, mtr); new_page = buf_block_get_frame(new_block); new_page_zip = buf_block_get_page_zip(new_block); btr_page_create(new_block, new_page_zip, cursor->index, @@ -3025,15 +3099,16 @@ btr_node_ptr_delete( ut_a(err == DB_SUCCESS); if (!compressed) { - btr_cur_compress_if_useful(&cursor, mtr); + btr_cur_compress_if_useful(&cursor, FALSE, mtr); } } /*************************************************************//** If page is the only on its level, this function moves its records to the -father page, thus reducing the tree height. */ +father page, thus reducing the tree height. +@return father block */ static -void +buf_block_t* btr_lift_page_up( /*=============*/ dict_index_t* index, /*!< in: index tree */ @@ -3150,6 +3225,8 @@ btr_lift_page_up( } ut_ad(page_validate(father_page, index)); ut_ad(btr_check_node_ptr(index, father_block, mtr)); + + return(father_block); } /*************************************************************//** @@ -3166,11 +3243,13 @@ UNIV_INTERN ibool btr_compress( /*=========*/ - btr_cur_t* cursor, /*!< in: cursor on the page to merge or lift; - the page must not be empty: in record delete - use btr_discard_page if the page would become - empty */ - mtr_t* mtr) /*!< in: mtr */ + btr_cur_t* cursor, /*!< in/out: cursor on the page to merge + or lift; the page must not be empty: + when deleting records, use btr_discard_page() + if the page would become empty */ + ibool adjust, /*!< in: TRUE if should adjust the + cursor position even if compression occurs */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { dict_index_t* index; ulint space; @@ -3188,13 +3267,15 @@ btr_compress( ulint* offsets; ulint data_size; ulint n_recs; + ulint nth_rec = 0; /* remove bogus warning */ ulint max_ins_size; ulint max_ins_size_reorg; block = btr_cur_get_block(cursor); page = btr_cur_get_page(cursor); index = btr_cur_get_index(cursor); - ut_a((ibool) !!page_is_comp(page) == dict_table_is_comp(index->table)); + + btr_assert_not_corrupted(block, index); ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index), MTR_MEMO_X_LOCK)); @@ -3214,6 +3295,10 @@ btr_compress( offsets = btr_page_get_father_block(NULL, heap, index, block, mtr, &father_cursor); + if (adjust) { + nth_rec = page_rec_get_n_recs_before(btr_cur_get_rec(cursor)); + } + /* Decide the page to which we try to merge and which will inherit the locks */ @@ -3240,9 +3325,9 @@ btr_compress( } else { /* The page is the only one on the level, lift the records to the father */ - btr_lift_page_up(index, block, mtr); - mem_heap_free(heap); - return(TRUE); + + merge_block = btr_lift_page_up(index, block, mtr); + goto func_exit; } n_recs = page_get_n_recs(page); @@ -3324,6 +3409,10 @@ err_exit: btr_node_ptr_delete(index, block, mtr); lock_update_merge_left(merge_block, orig_pred, block); + + if (adjust) { + nth_rec += page_rec_get_n_recs_before(orig_pred); + } } else { rec_t* orig_succ; #ifdef UNIV_BTR_DEBUG @@ -3388,7 +3477,6 @@ err_exit: } btr_blob_dbg_remove(page, index, "btr_compress"); - mem_heap_free(heap); if (!dict_index_is_clust(index) && page_is_leaf(merge_page)) { /* Update the free bits of the B-tree page in the @@ -3440,6 +3528,16 @@ err_exit: btr_page_free(index, block, mtr); ut_ad(btr_check_node_ptr(index, merge_block, mtr)); +func_exit: + mem_heap_free(heap); + + if (adjust) { + btr_cur_position( + index, + page_rec_get_nth(merge_block->frame, nth_rec), + merge_block, cursor); + } + return(TRUE); } @@ -3876,7 +3974,7 @@ btr_index_rec_validate( (ulong) rec_get_n_fields_old(rec), (ulong) n); if (dump_on_error) { - buf_page_print(page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: corrupt record ", stderr); rec_print_old(stderr, rec); @@ -3914,7 +4012,8 @@ btr_index_rec_validate( (ulong) i, (ulong) len, (ulong) fixed_size); if (dump_on_error) { - buf_page_print(page, 0); + buf_page_print(page, 0, + BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: corrupt record ", stderr); rec_print_new(stderr, rec, offsets); @@ -4124,8 +4223,8 @@ loop: btr_validate_report2(index, level, block, right_block); fputs("InnoDB: broken FIL_PAGE_NEXT" " or FIL_PAGE_PREV links\n", stderr); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(right_page, 0, BUF_PAGE_PRINT_NO_CRASH); ret = FALSE; } @@ -4134,8 +4233,8 @@ loop: != page_is_comp(page))) { btr_validate_report2(index, level, block, right_block); fputs("InnoDB: 'compact' flag mismatch\n", stderr); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(right_page, 0, BUF_PAGE_PRINT_NO_CRASH); ret = FALSE; @@ -4158,8 +4257,8 @@ loop: fputs("InnoDB: records in wrong order" " on adjacent pages\n", stderr); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(right_page, 0, BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: record ", stderr); rec = page_rec_get_prev(page_get_supremum_rec(page)); @@ -4208,8 +4307,8 @@ loop: fputs("InnoDB: node pointer to the page is wrong\n", stderr); - buf_page_print(father_page, 0); - buf_page_print(page, 0); + buf_page_print(father_page, 0, BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: node ptr ", stderr); rec_print(stderr, node_ptr, index); @@ -4241,8 +4340,10 @@ loop: btr_validate_report1(index, level, block); - buf_page_print(father_page, 0); - buf_page_print(page, 0); + buf_page_print(father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(page, 0, + BUF_PAGE_PRINT_NO_CRASH); fputs("InnoDB: Error: node ptrs differ" " on levels > 0\n" @@ -4287,9 +4388,15 @@ loop: btr_validate_report1(index, level, block); - buf_page_print(father_page, 0); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print( + father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + right_page, 0, + BUF_PAGE_PRINT_NO_CRASH); } } else { page_t* right_father_page @@ -4307,10 +4414,18 @@ loop: btr_validate_report1(index, level, block); - buf_page_print(father_page, 0); - buf_page_print(right_father_page, 0); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print( + father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + right_father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + right_page, 0, + BUF_PAGE_PRINT_NO_CRASH); } if (page_get_page_no(right_father_page) @@ -4324,10 +4439,18 @@ loop: btr_validate_report1(index, level, block); - buf_page_print(father_page, 0); - buf_page_print(right_father_page, 0); - buf_page_print(page, 0); - buf_page_print(right_page, 0); + buf_page_print( + father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + right_father_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print( + right_page, 0, + BUF_PAGE_PRINT_NO_CRASH); } } } @@ -4372,6 +4495,12 @@ btr_validate_index( mtr_x_lock(dict_index_get_lock(index), &mtr); root = btr_root_get(index, &mtr); + + if (UNIV_UNLIKELY(srv_pass_corrupt_table && !root)) { + mtr_commit(&mtr); + return(FALSE); + } + n = btr_page_get_level(root, &mtr); for (i = 0; i <= n && !trx_is_interrupted(trx); i++) { diff --git a/btr/btr0cur.c b/btr/btr0cur.c index 43313474071..e093dabebf1 100644 --- a/btr/btr0cur.c +++ b/btr/btr0cur.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -438,7 +438,12 @@ btr_cur_search_to_nth_level( ut_ad(dict_index_check_search_tuple(index, tuple)); ut_ad(!dict_index_is_ibuf(index) || ibuf_inside(mtr)); ut_ad(dtuple_check_typed(tuple)); + ut_ad(index->page != FIL_NULL); + UNIV_MEM_INVALID(&cursor->up_match, sizeof cursor->up_match); + UNIV_MEM_INVALID(&cursor->up_bytes, sizeof cursor->up_bytes); + UNIV_MEM_INVALID(&cursor->low_match, sizeof cursor->low_match); + UNIV_MEM_INVALID(&cursor->low_bytes, sizeof cursor->low_bytes); #ifdef UNIV_DEBUG cursor->up_match = ULINT_UNDEFINED; cursor->low_match = ULINT_UNDEFINED; @@ -810,11 +815,11 @@ retry_page_get: if (level != 0) { /* x-latch the page */ - page = btr_page_get( + buf_block_t* child_block = btr_block_get( space, zip_size, page_no, RW_X_LATCH, index, mtr); - ut_a((ibool)!!page_is_comp(page) - == dict_table_is_comp(index->table)); + page = buf_block_get_frame(child_block); + btr_assert_not_corrupted(child_block, index); } else { cursor->low_match = low_match; cursor->low_bytes = low_bytes; @@ -1959,7 +1964,7 @@ btr_cur_update_in_place( page_zip = buf_block_get_page_zip(block); /* Check that enough space is available on the compressed page. */ - if (UNIV_LIKELY_NULL(page_zip) + if (page_zip && !btr_cur_update_alloc_zip(page_zip, block, index, rec_offs_size(offsets), FALSE, mtr)) { return(DB_ZIP_OVERFLOW); @@ -2158,7 +2163,7 @@ any_extern: ut_a(!page_zip || page_zip_validate(page_zip, page)); #endif /* UNIV_ZIP_DEBUG */ - if (UNIV_LIKELY_NULL(page_zip) + if (page_zip && !btr_cur_update_alloc_zip(page_zip, block, index, new_rec_size, TRUE, mtr)) { err = DB_ZIP_OVERFLOW; @@ -2321,7 +2326,9 @@ btr_cur_pessimistic_update( /*=======================*/ ulint flags, /*!< in: undo logging, locking, and rollback flags */ - btr_cur_t* cursor, /*!< in: cursor on the record to update */ + btr_cur_t* cursor, /*!< in/out: cursor on the record to update; + cursor may become invalid if *big_rec == NULL + || !(flags & BTR_KEEP_POS_FLAG) */ mem_heap_t** heap, /*!< in/out: pointer to memory heap, or NULL */ big_rec_t** big_rec,/*!< out: big rec vector whose fields have to be stored externally by the caller, or NULL */ @@ -2463,10 +2470,10 @@ btr_cur_pessimistic_update( record to be inserted: we have to remember which fields were such */ ut_ad(!page_is_comp(page) || !rec_get_node_ptr_flag(rec)); - offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, heap); + ut_ad(rec_offs_validate(rec, index, offsets)); n_ext += btr_push_update_extern_fields(new_entry, update, *heap); - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { ut_ad(page_is_comp(page)); if (page_zip_rec_needs_ext( rec_get_converted_size(index, new_entry, n_ext), @@ -2486,6 +2493,10 @@ make_external: err = DB_TOO_BIG_RECORD; goto return_after_reservations; } + + ut_ad(page_is_leaf(page)); + ut_ad(dict_index_is_clust(index)); + ut_ad(flags & BTR_KEEP_POS_FLAG); } if (trx->fake_changes) { @@ -2519,6 +2530,8 @@ make_external: rec = btr_cur_insert_if_possible(cursor, new_entry, n_ext, mtr); if (rec) { + page_cursor->rec = rec; + lock_rec_restore_from_page_infimum(btr_cur_get_block(cursor), rec, block); @@ -2532,7 +2545,10 @@ make_external: rec, index, offsets, mtr); } - btr_cur_compress_if_useful(cursor, mtr); + btr_cur_compress_if_useful( + cursor, + big_rec_vec != NULL && (flags & BTR_KEEP_POS_FLAG), + mtr); if (page_zip && !dict_index_is_clust(index) && page_is_leaf(page)) { @@ -2552,6 +2568,21 @@ make_external: } } + if (big_rec_vec) { + ut_ad(page_is_leaf(page)); + ut_ad(dict_index_is_clust(index)); + ut_ad(flags & BTR_KEEP_POS_FLAG); + + /* btr_page_split_and_insert() in + btr_cur_pessimistic_insert() invokes + mtr_memo_release(mtr, index->lock, MTR_MEMO_X_LOCK). + We must keep the index->lock when we created a + big_rec, so that row_upd_clust_rec() can store the + big_rec in the same mini-transaction. */ + + mtr_x_lock(dict_index_get_lock(index), mtr); + } + /* Was the record to be updated positioned as the first user record on its page? */ was_first = page_cur_is_before_first(page_cursor); @@ -2567,6 +2598,7 @@ make_external: ut_a(rec); ut_a(err == DB_SUCCESS); ut_a(dummy_big_rec == NULL); + page_cursor->rec = rec; if (dict_index_is_sec_or_ibuf(index)) { /* Update PAGE_MAX_TRX_ID in the index page header. @@ -3011,10 +3043,12 @@ UNIV_INTERN ibool btr_cur_compress_if_useful( /*=======================*/ - btr_cur_t* cursor, /*!< in: cursor on the page to compress; - cursor does not stay valid if compression - occurs */ - mtr_t* mtr) /*!< in: mtr */ + btr_cur_t* cursor, /*!< in/out: cursor on the page to compress; + cursor does not stay valid if !adjust and + compression occurs */ + ibool adjust, /*!< in: TRUE if should adjust the + cursor position even if compression occurs */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(btr_cur_get_index(cursor)), @@ -3023,7 +3057,7 @@ btr_cur_compress_if_useful( MTR_MEMO_PAGE_X_FIX)); return(btr_cur_compress_recommendation(cursor, mtr) - && btr_compress(cursor, mtr)); + && btr_compress(cursor, adjust, mtr)); } /*******************************************************//** @@ -3270,7 +3304,7 @@ return_after_reservations: mem_heap_free(heap); if (ret == FALSE) { - ret = btr_cur_compress_if_useful(cursor, mtr); + ret = btr_cur_compress_if_useful(cursor, FALSE, mtr); } if (n_extents > 0) { @@ -4011,10 +4045,10 @@ btr_cur_set_ownership_of_extern_field( byte_val = byte_val | BTR_EXTERN_OWNER_FLAG; } - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { mach_write_to_1(data + local_len + BTR_EXTERN_LEN, byte_val); page_zip_write_blob_ptr(page_zip, rec, index, offsets, i, mtr); - } else if (UNIV_LIKELY(mtr != NULL)) { + } else if (mtr != NULL) { mlog_write_ulint(data + local_len + BTR_EXTERN_LEN, byte_val, MLOG_1BYTE, mtr); @@ -4253,9 +4287,9 @@ The fields are stored on pages allocated from leaf node file segment of the index tree. @return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */ UNIV_INTERN -ulint -btr_store_big_rec_extern_fields_func( -/*=================================*/ +enum db_err +btr_store_big_rec_extern_fields( +/*============================*/ dict_index_t* index, /*!< in: index of rec; the index tree MUST be X-latched */ buf_block_t* rec_block, /*!< in/out: block containing rec */ @@ -4264,38 +4298,37 @@ btr_store_big_rec_extern_fields_func( the "external storage" flags in offsets will not correspond to rec when this function returns */ -#ifdef UNIV_DEBUG - mtr_t* local_mtr, /*!< in: mtr containing the - latch to rec and to the tree */ -#endif /* UNIV_DEBUG */ -#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG - ibool update_in_place,/*! in: TRUE if the record is updated - in place (not delete+insert) */ -#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */ - const big_rec_t*big_rec_vec) /*!< in: vector containing fields + const big_rec_t*big_rec_vec, /*!< in: vector containing fields to be stored externally */ - + mtr_t* btr_mtr, /*!< in: mtr containing the + latches to the clustered index */ + enum blob_op op) /*! in: operation code */ { - ulint rec_page_no; - byte* field_ref; - ulint extern_len; - ulint store_len; - ulint page_no; - ulint space_id; - ulint zip_size; - ulint prev_page_no; - ulint hint_page_no; - ulint i; - mtr_t mtr; - mem_heap_t* heap = NULL; + ulint rec_page_no; + byte* field_ref; + ulint extern_len; + ulint store_len; + ulint page_no; + ulint space_id; + ulint zip_size; + ulint prev_page_no; + ulint hint_page_no; + ulint i; + mtr_t mtr; + mtr_t* alloc_mtr; + mem_heap_t* heap = NULL; page_zip_des_t* page_zip; - z_stream c_stream; + z_stream c_stream; + buf_block_t** freed_pages = NULL; + ulint n_freed_pages = 0; + enum db_err error = DB_SUCCESS; ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(rec_offs_any_extern(offsets)); - ut_ad(mtr_memo_contains(local_mtr, dict_index_get_lock(index), + 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(local_mtr, rec_block, MTR_MEMO_PAGE_X_FIX)); + ut_ad(mtr_memo_contains(btr_mtr, rec_block, MTR_MEMO_PAGE_X_FIX)); ut_ad(buf_block_get_frame(rec_block) == page_align(rec)); ut_a(dict_index_is_clust(index)); @@ -4308,7 +4341,7 @@ btr_store_big_rec_extern_fields_func( rec_page_no = buf_block_get_page_no(rec_block); ut_a(fil_page_get_type(page_align(rec)) == FIL_PAGE_INDEX); - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { int err; /* Zlib deflate needs 128 kilobytes for the default @@ -4324,6 +4357,42 @@ btr_store_big_rec_extern_fields_func( ut_a(err == Z_OK); } + if (btr_blob_op_is_update(op)) { + /* Avoid reusing pages that have been previously freed + in btr_mtr. */ + if (btr_mtr->n_freed_pages) { + if (heap == NULL) { + heap = mem_heap_create( + btr_mtr->n_freed_pages + * sizeof *freed_pages); + } + + freed_pages = mem_heap_alloc( + heap, + btr_mtr->n_freed_pages + * sizeof *freed_pages); + n_freed_pages = 0; + } + + /* Because btr_mtr will be committed after mtr, it is + possible that the tablespace has been extended when + the B-tree record was updated or inserted, or it will + be extended while allocating pages for big_rec. + + TODO: In mtr (not btr_mtr), write a redo log record + about extending the tablespace to its current size, + and remember the current size. Whenever the tablespace + grows as pages are allocated, write further redo log + records to mtr. (Currently tablespace extension is not + covered by the redo log. If it were, the record would + only be written to btr_mtr, which is committed after + mtr.) */ + alloc_mtr = btr_mtr; + } else { + /* Use the local mtr for allocations. */ + alloc_mtr = &mtr; + } + #if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG /* All pointers to externally stored columns in the record must either be zero or they must be pointers to inherited @@ -4338,7 +4407,7 @@ btr_store_big_rec_extern_fields_func( /* Either this must be an update in place, or the BLOB must be inherited, or the BLOB pointer must be zero (will be written in this function). */ - ut_a(update_in_place + ut_a(op == BTR_STORE_UPDATE || (field_ref[BTR_EXTERN_LEN] & BTR_EXTERN_INHERITED_FLAG) || !memcmp(field_ref, field_ref_zero, BTR_EXTERN_FIELD_REF_SIZE)); @@ -4363,7 +4432,7 @@ btr_store_big_rec_extern_fields_func( prev_page_no = FIL_NULL; - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { int err = deflateReset(&c_stream); ut_a(err == Z_OK); @@ -4383,18 +4452,24 @@ btr_store_big_rec_extern_fields_func( hint_page_no = prev_page_no + 1; } +alloc_another: block = btr_page_alloc(index, hint_page_no, - FSP_NO_DIR, 0, &mtr); + FSP_NO_DIR, 0, alloc_mtr, &mtr); if (UNIV_UNLIKELY(block == NULL)) { - mtr_commit(&mtr); + error = DB_OUT_OF_FILE_SPACE; + goto func_exit; + } - if (UNIV_LIKELY_NULL(page_zip)) { - deflateEnd(&c_stream); - mem_heap_free(heap); - } - - return(DB_OUT_OF_FILE_SPACE); + if (rw_lock_get_x_lock_count(&block->lock) > 1) { + /* This page must have been freed in + btr_mtr previously. Put it aside, and + allocate another page for the BLOB data. */ + ut_ad(alloc_mtr == btr_mtr); + ut_ad(btr_blob_op_is_update(op)); + ut_ad(n_freed_pages < btr_mtr->n_freed_pages); + freed_pages[n_freed_pages++] = block; + goto alloc_another; } page_no = buf_block_get_page_no(block); @@ -4411,7 +4486,7 @@ btr_store_big_rec_extern_fields_func( SYNC_EXTERN_STORAGE); prev_page = buf_block_get_frame(prev_block); - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { mlog_write_ulint( prev_page + FIL_PAGE_NEXT, page_no, MLOG_4BYTES, &mtr); @@ -4428,7 +4503,7 @@ btr_store_big_rec_extern_fields_func( } - if (UNIV_LIKELY_NULL(page_zip)) { + if (page_zip) { int err; page_zip_des_t* blob_page_zip; @@ -4511,11 +4586,15 @@ btr_store_big_rec_extern_fields_func( goto next_zip_page; } - rec_block = buf_page_get(space_id, zip_size, - rec_page_no, - RW_X_LATCH, &mtr); - buf_block_dbg_add_level(rec_block, - SYNC_NO_ORDER_CHECK); + if (alloc_mtr == &mtr) { + rec_block = buf_page_get( + space_id, zip_size, + rec_page_no, + RW_X_LATCH, &mtr); + buf_block_dbg_add_level( + rec_block, + SYNC_NO_ORDER_CHECK); + } if (err == Z_STREAM_END) { mach_write_to_4(field_ref @@ -4549,7 +4628,8 @@ btr_store_big_rec_extern_fields_func( page_zip_write_blob_ptr( page_zip, rec, index, offsets, - big_rec_vec->fields[i].field_no, &mtr); + big_rec_vec->fields[i].field_no, + alloc_mtr); next_zip_page: prev_page_no = page_no; @@ -4594,19 +4674,23 @@ next_zip_page: extern_len -= store_len; - rec_block = buf_page_get(space_id, zip_size, - rec_page_no, - RW_X_LATCH, &mtr); - buf_block_dbg_add_level(rec_block, - SYNC_NO_ORDER_CHECK); + if (alloc_mtr == &mtr) { + rec_block = buf_page_get( + space_id, zip_size, + rec_page_no, + RW_X_LATCH, &mtr); + buf_block_dbg_add_level( + rec_block, + SYNC_NO_ORDER_CHECK); + } mlog_write_ulint(field_ref + BTR_EXTERN_LEN, 0, - MLOG_4BYTES, &mtr); + MLOG_4BYTES, alloc_mtr); mlog_write_ulint(field_ref + BTR_EXTERN_LEN + 4, big_rec_vec->fields[i].len - extern_len, - MLOG_4BYTES, &mtr); + MLOG_4BYTES, alloc_mtr); if (prev_page_no == FIL_NULL) { btr_blob_dbg_add_blob( @@ -4616,18 +4700,19 @@ next_zip_page: mlog_write_ulint(field_ref + BTR_EXTERN_SPACE_ID, - space_id, - MLOG_4BYTES, &mtr); + space_id, MLOG_4BYTES, + alloc_mtr); mlog_write_ulint(field_ref + BTR_EXTERN_PAGE_NO, - page_no, - MLOG_4BYTES, &mtr); + page_no, MLOG_4BYTES, + alloc_mtr); mlog_write_ulint(field_ref + BTR_EXTERN_OFFSET, FIL_PAGE_DATA, - MLOG_4BYTES, &mtr); + MLOG_4BYTES, + alloc_mtr); } prev_page_no = page_no; @@ -4641,8 +4726,23 @@ next_zip_page: } } - if (UNIV_LIKELY_NULL(page_zip)) { +func_exit: + if (page_zip) { deflateEnd(&c_stream); + } + + if (n_freed_pages) { + ulint i; + + ut_ad(alloc_mtr == btr_mtr); + ut_ad(btr_blob_op_is_update(op)); + + for (i = 0; i < n_freed_pages; i++) { + btr_page_free_low(index, freed_pages[i], 0, alloc_mtr); + } + } + + if (heap != NULL) { mem_heap_free(heap); } @@ -4663,7 +4763,7 @@ next_zip_page: ut_a(!(field_ref[BTR_EXTERN_LEN] & BTR_EXTERN_OWNER_FLAG)); } #endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */ - return(DB_SUCCESS); + return(error); } /*******************************************************************//** @@ -4866,7 +4966,7 @@ btr_free_externally_stored_field( btr_page_free_low(index, ext_block, 0, &mtr); - if (UNIV_LIKELY(page_zip != NULL)) { + if (page_zip) { mach_write_to_4(field_ref + BTR_EXTERN_PAGE_NO, next_page_no); mach_write_to_4(field_ref + BTR_EXTERN_LEN + 4, diff --git a/btr/btr0pcur.c b/btr/btr0pcur.c index e6a9ddcf43e..0de7b63f92d 100644 --- a/btr/btr0pcur.c +++ b/btr/btr0pcur.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -52,12 +52,13 @@ btr_pcur_create_for_mysql(void) } /**************************************************************//** -Frees the memory for a persistent cursor object. */ +Resets a persistent cursor object, freeing ::old_rec_buf if it is +allocated and resetting the other members to their initial values. */ UNIV_INTERN void -btr_pcur_free_for_mysql( -/*====================*/ - btr_pcur_t* cursor) /*!< in, own: persistent cursor */ +btr_pcur_reset( +/*===========*/ + btr_pcur_t* cursor) /*!< in, out: persistent cursor */ { if (cursor->old_rec_buf != NULL) { @@ -66,6 +67,7 @@ btr_pcur_free_for_mysql( cursor->old_rec_buf = NULL; } + cursor->btr_cur.index = NULL; cursor->btr_cur.page_cur.rec = NULL; cursor->old_rec = NULL; cursor->old_n_fields = 0; @@ -73,7 +75,17 @@ btr_pcur_free_for_mysql( cursor->latch_mode = BTR_NO_LATCHES; cursor->pos_state = BTR_PCUR_NOT_POSITIONED; +} +/**************************************************************//** +Frees the memory for a persistent cursor object. */ +UNIV_INTERN +void +btr_pcur_free_for_mysql( +/*====================*/ + btr_pcur_t* cursor) /*!< in, own: persistent cursor */ +{ + btr_pcur_reset(cursor); mem_free(cursor); } @@ -127,6 +139,8 @@ btr_pcur_store_position( ut_a(btr_page_get_next(page, mtr) == FIL_NULL); ut_a(btr_page_get_prev(page, mtr) == FIL_NULL); + ut_ad(page_is_leaf(page)); + ut_ad(page_get_page_no(page) == index->page); cursor->old_stored = BTR_PCUR_OLD_STORED; @@ -319,13 +333,19 @@ btr_pcur_restore_position_func( /* Save the old search mode of the cursor */ old_mode = cursor->search_mode; - if (UNIV_LIKELY(cursor->rel_pos == BTR_PCUR_ON)) { + switch (cursor->rel_pos) { + case BTR_PCUR_ON: mode = PAGE_CUR_LE; - } else if (cursor->rel_pos == BTR_PCUR_AFTER) { + break; + case BTR_PCUR_AFTER: mode = PAGE_CUR_G; - } else { - ut_ad(cursor->rel_pos == BTR_PCUR_BEFORE); + break; + case BTR_PCUR_BEFORE: mode = PAGE_CUR_L; + break; + default: + ut_error; + mode = 0; } btr_pcur_open_with_no_init_func(index, tuple, mode, latch_mode, @@ -334,25 +354,44 @@ btr_pcur_restore_position_func( /* Restore the old search mode */ cursor->search_mode = old_mode; - if (cursor->rel_pos == BTR_PCUR_ON - && btr_pcur_is_on_user_rec(cursor) - && 0 == cmp_dtuple_rec(tuple, btr_pcur_get_rec(cursor), - rec_get_offsets( - btr_pcur_get_rec(cursor), index, - NULL, ULINT_UNDEFINED, &heap))) { - - /* We have to store the NEW value for the modify clock, since - the cursor can now be on a different page! But we can retain - the value of old_rec */ + if (btr_pcur_is_on_user_rec(cursor)) { + switch (cursor->rel_pos) { + case BTR_PCUR_ON: + if (!cmp_dtuple_rec( + tuple, btr_pcur_get_rec(cursor), + rec_get_offsets(btr_pcur_get_rec(cursor), + index, NULL, + ULINT_UNDEFINED, &heap))) { + + /* We have to store the NEW value for + the modify clock, since the cursor can + now be on a different page! But we can + retain the value of old_rec */ + + cursor->block_when_stored = + btr_pcur_get_block(cursor); + cursor->modify_clock = + buf_block_get_modify_clock( + cursor->block_when_stored); + cursor->old_stored = BTR_PCUR_OLD_STORED; - cursor->block_when_stored = btr_pcur_get_block(cursor); - cursor->modify_clock = buf_block_get_modify_clock( - cursor->block_when_stored); - cursor->old_stored = BTR_PCUR_OLD_STORED; + mem_heap_free(heap); - mem_heap_free(heap); + return(TRUE); + } - return(TRUE); + break; + case BTR_PCUR_BEFORE: + page_cur_move_to_next(btr_pcur_get_page_cur(cursor)); + break; + case BTR_PCUR_AFTER: + page_cur_move_to_prev(btr_pcur_get_page_cur(cursor)); + break; +#ifdef UNIV_DEBUG + default: + ut_error; +#endif /* UNIV_DEBUG */ + } } mem_heap_free(heap); diff --git a/btr/btr0sea.c b/btr/btr0sea.c index bddbcc79dd6..855ab62c42f 100644 --- a/btr/btr0sea.c +++ b/btr/btr0sea.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -1240,7 +1240,7 @@ cleanup: index->name, (ulong) block->n_pointers); rw_lock_x_unlock(btr_search_get_latch(index->id)); - btr_search_validate(); + ut_ad(btr_search_validate()); } else { rw_lock_x_unlock(btr_search_get_latch(index->id)); } @@ -2143,7 +2143,9 @@ btr_search_validate(void) (ulong) block->curr_left_side); if (n_page_dumps < 20) { - buf_page_print(page, 0); + buf_page_print( + page, 0, + BUF_PAGE_PRINT_NO_CRASH); n_page_dumps++; } } diff --git a/buf/buf0buf.c b/buf/buf0buf.c index b3f6600dca6..fd7b8959473 100644 --- a/buf/buf0buf.c +++ b/buf/buf0buf.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -57,7 +57,9 @@ Created 11/5/1995 Heikki Tuuri /* prototypes for new functions added to ha_innodb.cc */ trx_t* innobase_get_trx(); -inline void _increment_page_get_statistics(buf_block_t* block, trx_t* trx) +static inline +void +_increment_page_get_statistics(buf_block_t* block, trx_t* trx) { ulint block_hash; ulint block_hash_byte; @@ -680,8 +682,12 @@ void buf_page_print( /*===========*/ const byte* read_buf, /*!< in: a database page */ - ulint zip_size) /*!< in: compressed page size, or - 0 for uncompressed pages */ + ulint zip_size, /*!< in: compressed page size, or + 0 for uncompressed pages */ + ulint flags) /*!< in: 0 or + BUF_PAGE_PRINT_NO_CRASH or + BUF_PAGE_PRINT_NO_FULL */ + { #ifndef UNIV_HOTBACKUP dict_index_t* index; @@ -695,11 +701,14 @@ buf_page_print( size = UNIV_PAGE_SIZE; } - ut_print_timestamp(stderr); - fprintf(stderr, " InnoDB: Page dump in ascii and hex (%lu bytes):\n", - (ulong) size); - ut_print_buf(stderr, read_buf, size); - fputs("\nInnoDB: End of page dump\n", stderr); + if (!(flags & BUF_PAGE_PRINT_NO_FULL)) { + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Page dump in ascii and hex (%lu bytes):\n", + (ulong) size); + ut_print_buf(stderr, read_buf, size); + fputs("\nInnoDB: End of page dump\n", stderr); + } if (zip_size) { /* Print compressed page. */ @@ -873,6 +882,8 @@ buf_page_print( stderr); break; } + + ut_ad(flags & BUF_PAGE_PRINT_NO_CRASH); } #ifndef UNIV_HOTBACKUP @@ -1078,11 +1089,8 @@ buf_chunk_init( for (i = chunk->size; i--; ) { buf_block_init(buf_pool, block, frame); + UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE); -#ifdef HAVE_purify - /* Wipe contents of frame to eliminate a Purify warning */ - memset(block->frame, '\0', UNIV_PAGE_SIZE); -#endif /* Add the block to the free list */ mutex_enter(&buf_pool->free_list_mutex); UT_LIST_ADD_LAST(free, buf_pool->free, (&block->page)); @@ -2768,7 +2776,7 @@ wait_until_unfixed: block->page.buf_fix_count = 1; buf_block_set_io_fix(block, BUF_IO_READ); - rw_lock_x_lock_func(&block->lock, 0, file, line); + rw_lock_x_lock_inline(&block->lock, 0, file, line); UNIV_MEM_INVALID(bpage, sizeof *bpage); @@ -2931,14 +2939,14 @@ wait_until_unfixed: break; case RW_S_LATCH: - rw_lock_s_lock_func(&(block->lock), 0, file, line); + rw_lock_s_lock_inline(&(block->lock), 0, file, line); fix_type = MTR_MEMO_PAGE_S_FIX; break; default: ut_ad(rw_latch == RW_X_LATCH); - rw_lock_x_lock_func(&(block->lock), 0, file, line); + rw_lock_x_lock_inline(&(block->lock), 0, file, line); fix_type = MTR_MEMO_PAGE_X_FIX; break; @@ -3023,8 +3031,8 @@ buf_page_optimistic_get( file, line); fix_type = MTR_MEMO_PAGE_S_FIX; } else { - success = rw_lock_x_lock_func_nowait(&(block->lock), - file, line); + success = rw_lock_x_lock_func_nowait_inline(&(block->lock), + file, line); fix_type = MTR_MEMO_PAGE_X_FIX; } @@ -3165,8 +3173,8 @@ buf_page_get_known_nowait( file, line); fix_type = MTR_MEMO_PAGE_S_FIX; } else { - success = rw_lock_x_lock_func_nowait(&(block->lock), - file, line); + success = rw_lock_x_lock_func_nowait_inline(&(block->lock), + file, line); fix_type = MTR_MEMO_PAGE_X_FIX; } @@ -3186,7 +3194,7 @@ buf_page_get_known_nowait( ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */ #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG - ut_a(block->page.file_page_was_freed == FALSE); + ut_a(mode == BUF_KEEP_OLD || !block->page.file_page_was_freed); #endif #ifdef UNIV_IBUF_COUNT_DEBUG @@ -3261,8 +3269,8 @@ buf_page_try_get_func( S-latch. */ fix_type = MTR_MEMO_PAGE_X_FIX; - success = rw_lock_x_lock_func_nowait(&block->lock, - file, line); + success = rw_lock_x_lock_func_nowait_inline(&block->lock, + file, line); } if (!success) { @@ -3997,7 +4005,8 @@ corrupt: "InnoDB: You may have to recover" " from a backup.\n", (ulong) bpage->offset); - buf_page_print(frame, buf_page_get_zip_size(bpage)); + buf_page_print(frame, buf_page_get_zip_size(bpage), + BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "InnoDB: Database page corruption on disk" " or a failed\n" @@ -5285,34 +5294,32 @@ buf_all_freed(void) /*********************************************************************//** Checks that there currently are no pending i/o-operations for the buffer pool. -@return TRUE if there is no pending i/o */ +@return number of pending i/o */ UNIV_INTERN -ibool -buf_pool_check_no_pending_io(void) -/*==============================*/ +ulint +buf_pool_check_num_pending_io(void) +/*===============================*/ { ulint i; - ibool ret = TRUE; + ulint pending_io = 0; buf_pool_mutex_enter_all(); - for (i = 0; i < srv_buf_pool_instances && ret; i++) { + for (i = 0; i < srv_buf_pool_instances; i++) { const buf_pool_t* buf_pool; buf_pool = buf_pool_from_array(i); - if (buf_pool->n_pend_reads - + buf_pool->n_flush[BUF_FLUSH_LRU] - + buf_pool->n_flush[BUF_FLUSH_LIST] - + buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE]) { + pending_io += buf_pool->n_pend_reads + + buf_pool->n_flush[BUF_FLUSH_LRU] + + buf_pool->n_flush[BUF_FLUSH_LIST] + + buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE]; - ret = FALSE; - } } buf_pool_mutex_exit_all(); - return(ret); + return(pending_io); } #if 0 diff --git a/buf/buf0flu.c b/buf/buf0flu.c index d776a274d14..bb921928653 100644 --- a/buf/buf0flu.c +++ b/buf/buf0flu.c @@ -767,7 +767,8 @@ buf_flush_buffered_writes(void) if (UNIV_UNLIKELY (!page_simple_validate_new(block->frame))) { corrupted_page: - buf_page_print(block->frame, 0); + buf_page_print(block->frame, 0, + BUF_PAGE_PRINT_NO_CRASH); ut_print_timestamp(stderr); fprintf(stderr, @@ -2036,22 +2037,6 @@ buf_flush_list( buf_pool = buf_pool_from_array(i); - if (lsn_limit != IB_ULONGLONG_MAX) { - buf_page_t* bpage; - - buf_flush_list_mutex_enter(buf_pool); - bpage = UT_LIST_GET_LAST(buf_pool->flush_list); - if (!bpage - || bpage->oldest_modification >= lsn_limit) { - - buf_flush_list_mutex_exit(buf_pool); - continue; - } else { - - buf_flush_list_mutex_exit(buf_pool); - } - } - if (!buf_flush_start(buf_pool, BUF_FLUSH_LIST)) { /* We have two choices here. If lsn_limit was specified then skipping an instance of buffer diff --git a/buf/buf0lru.c b/buf/buf0lru.c index daa2cd93255..132b12899b4 100644 --- a/buf/buf0lru.c +++ b/buf/buf0lru.c @@ -48,6 +48,7 @@ Created 11/5/1995 Heikki Tuuri #include "page0zip.h" #include "log0recv.h" #include "srv0srv.h" +#include "srv0start.h" /** The number of blocks from the LRU_old pointer onward, including the block pointed to, must be buf_pool->LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV @@ -371,42 +372,278 @@ next_page: ut_free(page_arr); } +/******************************************************************//** +While flushing (or removing dirty) pages from a tablespace we don't +want to hog the CPU and resources. Release the buffer pool and block +mutex and try to force a context switch. Then reacquire the same mutexes. +The current page is "fixed" before the release of the mutexes and then +"unfixed" again once we have reacquired the mutexes. */ +static +void +buf_flush_yield( +/*============*/ + buf_pool_t* buf_pool, /*!< in/out: buffer pool instance */ + buf_page_t* bpage) /*!< in/out: current page */ +{ + mutex_t* block_mutex; + + ut_ad(buf_pool_mutex_own(buf_pool)); + ut_ad(buf_page_in_file(bpage)); + + block_mutex = buf_page_get_mutex(bpage); + + mutex_enter(block_mutex); + /* "Fix" the block so that the position cannot be + changed after we release the buffer pool and + block mutexes. */ + buf_page_set_sticky(bpage); + + /* Now it is safe to release the buf_pool->mutex. */ + buf_pool_mutex_exit(buf_pool); + + mutex_exit(block_mutex); + /* Try and force a context switch. */ + os_thread_yield(); + + buf_pool_mutex_enter(buf_pool); + + mutex_enter(block_mutex); + /* "Unfix" the block now that we have both the + buffer pool and block mutex again. */ + buf_page_unset_sticky(bpage); + mutex_exit(block_mutex); +} + +/******************************************************************//** +If we have hogged the resources for too long then release the buffer +pool and flush list mutex and do a thread yield. Set the current page +to "sticky" so that it is not relocated during the yield. +@return TRUE if yielded */ +static +ibool +buf_flush_try_yield( +/*================*/ + buf_pool_t* buf_pool, /*!< in/out: buffer pool instance */ + buf_page_t* bpage, /*!< in/out: bpage to remove */ + ulint processed) /*!< in: number of pages processed */ +{ + /* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the + loop we release buf_pool->mutex to let other threads + do their job but only if the block is not IO fixed. This + ensures that the block stays in its position in the + flush_list. */ + + if (bpage != NULL + && processed >= BUF_LRU_DROP_SEARCH_SIZE + && buf_page_get_io_fix(bpage) == BUF_IO_NONE) { + + buf_flush_list_mutex_exit(buf_pool); + + /* Release the buffer pool and block mutex + to give the other threads a go. */ + + buf_flush_yield(buf_pool, bpage); + + buf_flush_list_mutex_enter(buf_pool); + + /* Should not have been removed from the flush + list during the yield. However, this check is + not sufficient to catch a remove -> add. */ + + ut_ad(bpage->in_flush_list); + + return(TRUE); + } + + return(FALSE); +} + +/******************************************************************//** +Removes a single page from a given tablespace inside a specific +buffer pool instance. +@return TRUE if page was removed. */ +static +ibool +buf_flush_or_remove_page( +/*=====================*/ + buf_pool_t* buf_pool, /*!< in/out: buffer pool instance */ + buf_page_t* bpage) /*!< in/out: bpage to remove */ +{ + mutex_t* block_mutex; + ibool processed = FALSE; + + ut_ad(buf_pool_mutex_own(buf_pool)); + ut_ad(buf_flush_list_mutex_own(buf_pool)); + + block_mutex = buf_page_get_mutex(bpage); + + /* bpage->space and bpage->io_fix are protected by + buf_pool->mutex and block_mutex. It is safe to check + them while holding buf_pool->mutex only. */ + + if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) { + + /* We cannot remove this page during this scan + yet; maybe the system is currently reading it + in, or flushing the modifications to the file */ + + } else { + + /* We have to release the flush_list_mutex to obey the + latching order. We are however guaranteed that the page + will stay in the flush_list because buf_flush_remove() + needs buf_pool->mutex as well (for the non-flush case). */ + + buf_flush_list_mutex_exit(buf_pool); + + mutex_enter(block_mutex); + + ut_ad(bpage->oldest_modification != 0); + + if (bpage->buf_fix_count == 0) { + + buf_flush_remove(bpage); + + processed = TRUE; + } + + mutex_exit(block_mutex); + + buf_flush_list_mutex_enter(buf_pool); + } + + ut_ad(!mutex_own(block_mutex)); + + return(processed); +} + /******************************************************************//** Remove all dirty pages belonging to a given tablespace inside a specific buffer pool instance when we are deleting the data file(s) of that tablespace. The pages still remain a part of LRU and are evicted from -the list as they age towards the tail of the LRU. */ +the list as they age towards the tail of the LRU. +@return TRUE if all freed. */ +static +ibool +buf_flush_or_remove_pages( +/*======================*/ + buf_pool_t* buf_pool, /*!< buffer pool instance */ + ulint id) /*!< in: target space id for which + to remove or flush pages */ +{ + buf_page_t* prev; + buf_page_t* bpage; + ulint processed = 0; + ibool all_freed = TRUE; + + buf_flush_list_mutex_enter(buf_pool); + + for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list); + bpage != NULL; + bpage = prev) { + + ut_a(buf_page_in_file(bpage)); + ut_ad(bpage->in_flush_list); + + /* Save the previous link because once we free the + page we can't rely on the links. */ + + prev = UT_LIST_GET_PREV(flush_list, bpage); + + if (buf_page_get_space(bpage) != id) { + + /* Skip this block, as it does not belong to + the target space. */ + + } else if (!buf_flush_or_remove_page(buf_pool, bpage)) { + + /* Remove was unsuccessful, we have to try again + by scanning the entire list from the end. */ + + all_freed = FALSE; + } + + ++processed; + + /* Yield if we have hogged the CPU and mutexes for too long. */ + if (buf_flush_try_yield(buf_pool, prev, processed)) { + + /* Reset the batch size counter if we had to yield. */ + + processed = 0; + } + + } + + buf_flush_list_mutex_exit(buf_pool); + + return(all_freed); +} + +/******************************************************************//** +Remove or flush all the dirty pages that belong to a given tablespace +inside a specific buffer pool instance. The pages will remain in the LRU +list and will be evicted from the LRU list as they age and move towards +the tail of the LRU list. */ +static +void +buf_flush_dirty_pages( +/*==================*/ + buf_pool_t* buf_pool, /*!< buffer pool instance */ + ulint id) /*!< in: space id */ +{ + ibool all_freed; + + do { + buf_pool_mutex_enter(buf_pool); + + all_freed = buf_flush_or_remove_pages(buf_pool, id); + + buf_pool_mutex_exit(buf_pool); + + ut_ad(buf_flush_validate(buf_pool)); + + if (!all_freed) { + os_thread_sleep(20000); + } + + } while (!all_freed); +} + +/******************************************************************//** +Remove all pages that belong to a given tablespace inside a specific +buffer pool instance when we are DISCARDing the tablespace. */ static void -buf_LRU_remove_dirty_pages_for_tablespace( -/*======================================*/ +buf_LRU_remove_all_pages( +/*=====================*/ buf_pool_t* buf_pool, /*!< buffer pool instance */ ulint id) /*!< in: space id */ { buf_page_t* bpage; ibool all_freed; - ulint i; scan_again: //buf_pool_mutex_enter(buf_pool); mutex_enter(&buf_pool->LRU_list_mutex); rw_lock_x_lock(&buf_pool->page_hash_latch); - buf_flush_list_mutex_enter(buf_pool); all_freed = TRUE; - for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list), i = 0; - bpage != NULL; ++i) { + for (bpage = UT_LIST_GET_LAST(buf_pool->LRU); + bpage != NULL; + /* No op */) { buf_page_t* prev_bpage; mutex_t* block_mutex = NULL; ut_a(buf_page_in_file(bpage)); + ut_ad(bpage->in_LRU_list); - prev_bpage = UT_LIST_GET_PREV(flush_list, bpage); + prev_bpage = UT_LIST_GET_PREV(LRU, bpage); /* bpage->space and bpage->io_fix are protected by - buf_pool->mutex and block_mutex. It is safe to check + buf_pool->mutex and the block_mutex. It is safe to check them while holding buf_pool->mutex only. */ if (buf_page_get_space(bpage) != id) { @@ -420,97 +657,89 @@ scan_again: all_freed = FALSE; goto next_page; - } + } else { - /* We have to release the flush_list_mutex to obey the - latching order. We are however guaranteed that the page - will stay in the flush_list because buf_flush_remove() - needs buf_pool->mutex as well. */ - buf_flush_list_mutex_exit(buf_pool); - block_mutex = buf_page_get_mutex_enter(bpage); + block_mutex = buf_page_get_mutex(bpage); + mutex_enter(block_mutex); - if (!block_mutex) { - /* It may be impossible case... - Something wrong, so will be scan_again */ - all_freed = FALSE; - goto next_page; - } + if (bpage->buf_fix_count > 0) { - if (bpage->buf_fix_count > 0) { - mutex_exit(block_mutex); - buf_flush_list_mutex_enter(buf_pool); + mutex_exit(block_mutex); - /* We cannot remove this page during - this scan yet; maybe the system is - currently reading it in, or flushing - the modifications to the file */ + /* We cannot remove this page during + this scan yet; maybe the system is + currently reading it in, or flushing + the modifications to the file */ - all_freed = FALSE; - goto next_page; + all_freed = FALSE; + + goto next_page; + } } - ut_ad(bpage->oldest_modification != 0); + ut_ad(mutex_own(block_mutex)); - buf_flush_remove(bpage); +#ifdef UNIV_DEBUG + if (buf_debug_prints) { + fprintf(stderr, + "Dropping space %lu page %lu\n", + (ulong) buf_page_get_space(bpage), + (ulong) buf_page_get_page_no(bpage)); + } +#endif + if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE) { + /* Do nothing, because the adaptive hash index + covers uncompressed pages only. */ + } else if (((buf_block_t*) bpage)->index) { + ulint page_no; + ulint zip_size; - mutex_exit(block_mutex); - buf_flush_list_mutex_enter(buf_pool); -next_page: - bpage = prev_bpage; + buf_pool_mutex_exit(buf_pool); - if (!bpage) { - break; - } + zip_size = buf_page_get_zip_size(bpage); + page_no = buf_page_get_page_no(bpage); - /* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the - loop we release buf_pool->mutex to let other threads - do their job. */ - if (i < BUF_LRU_DROP_SEARCH_SIZE) { - continue; + mutex_exit(block_mutex); + + /* Note that the following call will acquire + and release block->lock X-latch. */ + + btr_search_drop_page_hash_when_freed( + id, zip_size, page_no); + + goto scan_again; } - /* We IO-fix the block to make sure that the block - stays in its position in the flush_list. */ - if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) { - /* Block is already IO-fixed. We don't - want to change the value. Lets leave - this block alone. */ - continue; + if (bpage->oldest_modification != 0) { + buf_flush_remove(bpage); } - buf_flush_list_mutex_exit(buf_pool); - block_mutex = buf_page_get_mutex(bpage); - mutex_enter(block_mutex); - buf_page_set_sticky(bpage); - mutex_exit(block_mutex); + ut_ad(!bpage->in_flush_list); - /* Now it is safe to release the buf_pool->mutex. */ - //buf_pool_mutex_exit(buf_pool); - mutex_exit(&buf_pool->LRU_list_mutex); - rw_lock_x_unlock(&buf_pool->page_hash_latch); + /* Remove from the LRU list. */ - os_thread_yield(); - //buf_pool_mutex_enter(buf_pool); - mutex_enter(&buf_pool->LRU_list_mutex); - rw_lock_x_lock(&buf_pool->page_hash_latch); + if (buf_LRU_block_remove_hashed_page(bpage, TRUE) + != BUF_BLOCK_ZIP_FREE) { + buf_LRU_block_free_hashed_page((buf_block_t*) bpage, TRUE); + mutex_exit(block_mutex); - mutex_enter(block_mutex); - buf_page_unset_sticky(bpage); - mutex_exit(block_mutex); + } else { + /* The block_mutex should have been released + by buf_LRU_block_remove_hashed_page() when it + returns BUF_BLOCK_ZIP_FREE. */ + ut_ad(block_mutex == &buf_pool->zip_mutex); + } - buf_flush_list_mutex_enter(buf_pool); - ut_ad(bpage->in_flush_list); + ut_ad(!mutex_own(block_mutex)); - i = 0; +next_page: + bpage = prev_bpage; } // buf_pool_mutex_exit(buf_pool); mutex_exit(&buf_pool->LRU_list_mutex); rw_lock_x_unlock(&buf_pool->page_hash_latch); - buf_flush_list_mutex_exit(buf_pool); - - ut_ad(buf_flush_validate(buf_pool)); if (!all_freed) { os_thread_sleep(20000); @@ -520,28 +749,46 @@ next_page: } /******************************************************************//** -Invalidates all pages belonging to a given tablespace when we are deleting -the data file(s) of that tablespace. */ +Removes all pages belonging to a given tablespace. */ UNIV_INTERN void -buf_LRU_invalidate_tablespace( +buf_LRU_flush_or_remove_pages( /*==========================*/ - ulint id) /*!< in: space id */ + ulint id, /*!< in: space id */ + enum buf_remove_t buf_remove)/*!< in: remove or flush + strategy */ { - ulint i; + ulint i; - /* Before we attempt to drop pages one by one we first - attempt to drop page hash index entries in batches to make - it more efficient. The batching attempt is a best effort - attempt and does not guarantee that all pages hash entries - will be dropped. We get rid of remaining page hash entries - one by one below. */ for (i = 0; i < srv_buf_pool_instances; i++) { buf_pool_t* buf_pool; buf_pool = buf_pool_from_array(i); - buf_LRU_drop_page_hash_for_tablespace(buf_pool, id); - buf_LRU_remove_dirty_pages_for_tablespace(buf_pool, id); + + switch (buf_remove) { + case BUF_REMOVE_ALL_NO_WRITE: + /* A DISCARD tablespace case. Remove AHI entries + and evict all pages from LRU. */ + + /* Before we attempt to drop pages hash entries + one by one we first attempt to drop page hash + index entries in batches to make it more + efficient. The batching attempt is a best effort + attempt and does not guarantee that all pages + hash entries will be dropped. We get rid of + remaining page hash entries one by one below. */ + buf_LRU_drop_page_hash_for_tablespace(buf_pool, id); + buf_LRU_remove_all_pages(buf_pool, id); + break; + + case BUF_REMOVE_FLUSH_NO_WRITE: + /* A DROP table case. AHI entries are already + removed. No need to evict all pages from LRU + list. Just evict pages from flush list without + writing. */ + buf_flush_dirty_pages(buf_pool, id); + break; + } } } @@ -2260,6 +2507,7 @@ func_exit: /********************************************************************//** Dump the LRU page list to the specific file. */ #define LRU_DUMP_FILE "ib_lru_dump" +#define LRU_DUMP_TEMP_FILE "ib_lru_dump.tmp" UNIV_INTERN ibool @@ -2294,8 +2542,10 @@ buf_LRU_file_dump(void) goto end; } - dump_file = os_file_create(innodb_file_temp_key, LRU_DUMP_FILE, OS_FILE_OVERWRITE, - OS_FILE_NORMAL, OS_DATA_FILE, &success); + dump_file = os_file_create(innodb_file_temp_key, LRU_DUMP_TEMP_FILE, + OS_FILE_OVERWRITE, OS_FILE_NORMAL, OS_DATA_FILE, + &success); + if (!success) { os_file_get_last_error(TRUE); fprintf(stderr, @@ -2324,6 +2574,13 @@ buf_LRU_file_dump(void) offset++; if (offset == UNIV_PAGE_SIZE/4) { + if (srv_shutdown_state != SRV_SHUTDOWN_NONE) { + success = 0; + fprintf(stderr, + " InnoDB: stopped dumping lru" + " pages because of server" + " shutdown.\n"); + } success = os_file_write(LRU_DUMP_FILE, dump_file, buffer, (buffers << UNIV_PAGE_SIZE_SHIFT) & 0xFFFFFFFFUL, (buffers >> (32 - UNIV_PAGE_SIZE_SHIFT)), @@ -2363,8 +2620,16 @@ buf_LRU_file_dump(void) ret = TRUE; end: - if (dump_file != -1) + if (dump_file != -1) { + if (success) { + success = os_file_flush(dump_file, TRUE); + } os_file_close(dump_file); + } + if (success) { + success = os_file_rename(innodb_file_temp_key, + LRU_DUMP_TEMP_FILE, LRU_DUMP_FILE); + } if (buffer_base) ut_free(buffer_base); @@ -2410,6 +2675,7 @@ buf_LRU_file_restore(void) dump_record_t* records = NULL; ulint size; ulint size_high; + ulint recsize = sizeof(dump_record_t); ulint length; dump_file = os_file_create_simple_no_error_handling(innodb_file_temp_key, @@ -2417,7 +2683,14 @@ buf_LRU_file_restore(void) if (!success || !os_file_get_size(dump_file, &size, &size_high)) { os_file_get_last_error(TRUE); fprintf(stderr, - " InnoDB: cannot open %s\n", LRU_DUMP_FILE); + " InnoDB: cannot open %s, " + " buffer pool preload not done.\n", LRU_DUMP_FILE); + goto end; + } + + if (size == 0 || size_high > 0 || size % recsize) { + fprintf(stderr, " InnoDB: broken LRU dump file," + " buffer pool preload not done\n"); goto end; } @@ -2501,6 +2774,14 @@ buf_LRU_file_restore(void) if (offset % 16 == 15) { os_aio_simulated_wake_handler_threads(); buf_flush_free_margins(FALSE); + /* skip loading of the rest of the file if we are + terminating anyway */ + if(srv_shutdown_state != SRV_SHUTDOWN_NONE) { + fprintf(stderr, + " InnoDB: stopped loading lru pages" + " because of server shutdown\n"); + break; + } } zip_size = fil_space_get_zip_size(space_id); diff --git a/dict/dict0boot.c b/dict/dict0boot.c index fd08fa759ee..4bf69fa4e0b 100644 --- a/dict/dict0boot.c +++ b/dict/dict0boot.c @@ -239,6 +239,166 @@ dict_hdr_create( return(TRUE); } +/*****************************************************************//** +Verifies the SYS_STATS table by scanning its clustered index. This +function may only be called at InnoDB startup time. + +@return TRUE if SYS_STATS was verified successfully */ +UNIV_INTERN +ibool +dict_verify_xtradb_sys_stats(void) +/*==============================*/ +{ + dict_index_t* sys_stats_index; + ulint saved_srv_pass_corrupt_table = srv_pass_corrupt_table; + ibool result; + + sys_stats_index = dict_table_get_first_index(dict_sys->sys_stats); + + /* Since this may be called only during server startup, avoid hitting + various asserts by using XtraDB pass_corrupt_table option. */ + srv_pass_corrupt_table = 1; + result = btr_validate_index(sys_stats_index, NULL); + srv_pass_corrupt_table = saved_srv_pass_corrupt_table; + + return result; +} + +/*****************************************************************//** +Creates the B-tree for the SYS_STATS clustered index, adds the XtraDB +mark and the id of the index to the dictionary header page. Rewrites +both passed args. */ +static +void +dict_create_xtradb_sys_stats( +/*=========================*/ + dict_hdr_t** dict_hdr, /*!< in/out: dictionary header */ + mtr_t* mtr) /*!< in/out: mtr */ +{ + ulint root_page_no; + + root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, + DICT_HDR_SPACE, 0, DICT_STATS_ID, + dict_ind_redundant, mtr); + if (root_page_no == FIL_NULL) { + fprintf(stderr, "InnoDB: Warning: failed to create SYS_STATS btr.\n"); + srv_use_sys_stats_table = FALSE; + } else { + mlog_write_ulint(*dict_hdr + DICT_HDR_STATS, root_page_no, + MLOG_4BYTES, mtr); + mlog_write_ull(*dict_hdr + DICT_HDR_XTRADB_MARK, + DICT_HDR_XTRADB_FLAG, mtr); + } + mtr_commit(mtr); + /* restart mtr */ + mtr_start(mtr); + *dict_hdr = dict_hdr_get(mtr); +} + +/*****************************************************************//** +Create the table and index structure of SYS_STATS for the dictionary +cache and add it there. If called for the first time, also support +wrong root page id injection for testing purposes. */ +static +void +dict_add_to_cache_xtradb_sys_stats( +/*===============================*/ + ibool first_time __attribute__((unused)), + /*!< in: first invocation flag. If + TRUE, optionally inject wrong root page + id */ + mem_heap_t* heap, /*!< in: memory heap for table/index + allocation */ + dict_hdr_t* dict_hdr, /*!< in: dictionary header */ + mtr_t* mtr) /*!< in: mtr */ +{ + dict_table_t* table; + dict_index_t* index; + ulint root_page_id; + ulint error; + + table = dict_mem_table_create("SYS_STATS", DICT_HDR_SPACE, 4, 0); + table->n_mysql_handles_opened = 1; /* for pin */ + + dict_mem_table_add_col(table, heap, "INDEX_ID", DATA_BINARY, 0, 0); + dict_mem_table_add_col(table, heap, "KEY_COLS", DATA_INT, 0, 4); + dict_mem_table_add_col(table, heap, "DIFF_VALS", DATA_BINARY, 0, 0); + dict_mem_table_add_col(table, heap, "NON_NULL_VALS", DATA_BINARY, 0, 0); + + /* The '+ 2' below comes from the fields DB_TRX_ID, DB_ROLL_PTR */ +#if DICT_SYS_STATS_DIFF_VALS_FIELD != 2 + 2 +#error "DICT_SYS_STATS_DIFF_VALS_FIELD != 2 + 2" +#endif +#if DICT_SYS_STATS_NON_NULL_VALS_FIELD != 3 + 2 +#error "DICT_SYS_STATS_NON_NULL_VALS_FIELD != 3 + 2" +#endif + + table->id = DICT_STATS_ID; + dict_table_add_to_cache(table, heap); + dict_sys->sys_stats = table; + mem_heap_empty(heap); + + index = dict_mem_index_create("SYS_STATS", "CLUST_IND", + DICT_HDR_SPACE, + DICT_UNIQUE | DICT_CLUSTERED, 2); + + dict_mem_index_add_field(index, "INDEX_ID", 0); + dict_mem_index_add_field(index, "KEY_COLS", 0); + + index->id = DICT_STATS_ID; + + root_page_id = mtr_read_ulint(dict_hdr + DICT_HDR_STATS, MLOG_4BYTES, + mtr); +#ifdef UNIV_DEBUG + if ((srv_sys_stats_root_page != 0) && first_time) + root_page_id = srv_sys_stats_root_page; +#endif + error = dict_index_add_to_cache(table, index, root_page_id, FALSE); + ut_a(error == DB_SUCCESS); + + mem_heap_empty(heap); +} + +/*****************************************************************//** +Discard the existing dictionary cache SYS_STATS information, create and +add it there anew. Does not touch the old SYS_STATS tablespace page +under the assumption that they are corrupted or overwritten for other +purposes. */ +UNIV_INTERN +void +dict_recreate_xtradb_sys_stats(void) +/*================================*/ +{ + mtr_t mtr; + dict_hdr_t* dict_hdr; + dict_index_t* sys_stats_clust_idx; + mem_heap_t* heap; + + heap = mem_heap_create(450); + + mutex_enter(&(dict_sys->mutex)); + + sys_stats_clust_idx = dict_table_get_first_index(dict_sys->sys_stats); + dict_index_remove_from_cache(dict_sys->sys_stats, sys_stats_clust_idx); + + dict_table_remove_from_cache(dict_sys->sys_stats); + + dict_sys->sys_stats = NULL; + + mtr_start(&mtr); + + dict_hdr = dict_hdr_get(&mtr); + + dict_create_xtradb_sys_stats(&dict_hdr, &mtr); + dict_add_to_cache_xtradb_sys_stats(FALSE, heap, dict_hdr, &mtr); + + mem_heap_free(heap); + + mtr_commit(&mtr); + + mutex_exit(&(dict_sys->mutex)); +} + /*****************************************************************//** Initializes the data dictionary memory structures when the database is started. This function is also called when the data dictionary is created. */ @@ -254,13 +414,13 @@ dict_boot(void) mtr_t mtr; ulint error; + heap = mem_heap_create(450); + mtr_start(&mtr); /* Create the hash tables etc. */ dict_init(); - heap = mem_heap_create(450); - mutex_enter(&(dict_sys->mutex)); /* Get the dictionary header */ @@ -268,25 +428,9 @@ dict_boot(void) if (mach_read_from_8(dict_hdr + DICT_HDR_XTRADB_MARK) != DICT_HDR_XTRADB_FLAG) { + /* not extended yet by XtraDB, need to be extended */ - ulint root_page_no; - - root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, - DICT_HDR_SPACE, 0, DICT_STATS_ID, - dict_ind_redundant, &mtr); - if (root_page_no == FIL_NULL) { - fprintf(stderr, "InnoDB: Warning: failed to create SYS_STATS btr.\n"); - srv_use_sys_stats_table = FALSE; - } else { - mlog_write_ulint(dict_hdr + DICT_HDR_STATS, root_page_no, - MLOG_4BYTES, &mtr); - mlog_write_ull(dict_hdr + DICT_HDR_XTRADB_MARK, - DICT_HDR_XTRADB_FLAG, &mtr); - } - mtr_commit(&mtr); - /* restart mtr */ - mtr_start(&mtr); - dict_hdr = dict_hdr_get(&mtr); + dict_create_xtradb_sys_stats(&dict_hdr, &mtr); } /* Because we only write new row ids to disk-based data structure @@ -465,42 +609,7 @@ dict_boot(void) FALSE); ut_a(error == DB_SUCCESS); - /*-------------------------*/ - table = dict_mem_table_create("SYS_STATS", DICT_HDR_SPACE, 4, 0); - table->n_mysql_handles_opened = 1; /* for pin */ - - dict_mem_table_add_col(table, heap, "INDEX_ID", DATA_BINARY, 0, 0); - dict_mem_table_add_col(table, heap, "KEY_COLS", DATA_INT, 0, 4); - dict_mem_table_add_col(table, heap, "DIFF_VALS", DATA_BINARY, 0, 0); - dict_mem_table_add_col(table, heap, "NON_NULL_VALS", DATA_BINARY, 0, 0); - - /* The '+ 2' below comes from the fields DB_TRX_ID, DB_ROLL_PTR */ -#if DICT_SYS_STATS_DIFF_VALS_FIELD != 2 + 2 -#error "DICT_SYS_STATS_DIFF_VALS_FIELD != 2 + 2" -#endif -#if DICT_SYS_STATS_NON_NULL_VALS_FIELD != 3 + 2 -#error "DICT_SYS_STATS_NON_NULL_VALS_FIELD != 3 + 2" -#endif - - table->id = DICT_STATS_ID; - dict_table_add_to_cache(table, heap); - dict_sys->sys_stats = table; - mem_heap_empty(heap); - - index = dict_mem_index_create("SYS_STATS", "CLUST_IND", - DICT_HDR_SPACE, - DICT_UNIQUE | DICT_CLUSTERED, 2); - - dict_mem_index_add_field(index, "INDEX_ID", 0); - dict_mem_index_add_field(index, "KEY_COLS", 0); - - index->id = DICT_STATS_ID; - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_STATS, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + dict_add_to_cache_xtradb_sys_stats(TRUE, heap, dict_hdr, &mtr); mem_heap_free(heap); diff --git a/dict/dict0dict.c b/dict/dict0dict.c index 43f28751a31..4c84a22c4b5 100644 --- a/dict/dict0dict.c +++ b/dict/dict0dict.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -56,6 +56,8 @@ UNIV_INTERN dict_index_t* dict_ind_compact; #include "ha_prototypes.h" /* innobase_strcasecmp(), innobase_casedn_str()*/ #include "row0upd.h" #include "srv0start.h" /* SRV_LOG_SPACE_FIRST_ID */ +#include "m_string.h" +#include "my_sys.h" #include @@ -2397,6 +2399,8 @@ dict_foreign_free( /*==============*/ dict_foreign_t* foreign) /*!< in, own: foreign key struct */ { + ut_a(foreign->foreign_table->n_foreign_key_checks_running == 0); + mem_heap_free(foreign->heap); } @@ -4378,25 +4382,32 @@ dict_reload_statistics( heap = mem_heap_create(1000); while (index) { + mtr_t mtr; + if (table->is_corrupt) { ut_a(srv_pass_corrupt_table); mem_heap_free(heap); return(FALSE); } - size = btr_get_size(index, BTR_TOTAL_SIZE); + mtr_start(&mtr); + mtr_s_lock(dict_index_get_lock(index), &mtr); + + size = btr_get_size(index, BTR_TOTAL_SIZE, &mtr); index->stat_index_size = size; *sum_of_index_sizes += size; - size = btr_get_size(index, BTR_N_LEAF_PAGES); + size = btr_get_size(index, BTR_N_LEAF_PAGES, &mtr); if (size == 0) { /* The root node of the tree is a leaf */ size = 1; } + mtr_commit(&mtr); + index->stat_n_leaf_pages = size; /*===========================================*/ @@ -4728,6 +4739,7 @@ dict_update_statistics( (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE || (srv_force_recovery < SRV_FORCE_NO_LOG_REDO && dict_index_is_clust(index)))) { + mtr_t mtr; ulint size; if (table->is_corrupt) { @@ -4736,15 +4748,24 @@ dict_update_statistics( return; } - size = btr_get_size(index, BTR_TOTAL_SIZE); + mtr_start(&mtr); + mtr_s_lock(dict_index_get_lock(index), &mtr); - index->stat_index_size = size; + size = btr_get_size(index, BTR_TOTAL_SIZE, &mtr); - sum_of_index_sizes += size; + if (size != ULINT_UNDEFINED) { + sum_of_index_sizes += size; + index->stat_index_size = size; + size = btr_get_size( + index, BTR_N_LEAF_PAGES, &mtr); + } - size = btr_get_size(index, BTR_N_LEAF_PAGES); + mtr_commit(&mtr); - if (size == 0) { + switch (size) { + case ULINT_UNDEFINED: + goto fake_statistics; + case 0: /* The root node of the tree is a leaf */ size = 1; } @@ -4761,6 +4782,7 @@ dict_update_statistics( various means, also via secondary indexes. */ ulint i; +fake_statistics: sum_of_index_sizes++; index->stat_index_size = index->stat_n_leaf_pages = 1; diff --git a/dict/dict0load.c b/dict/dict0load.c index 0e7c777ea1f..6029e6f0070 100644 --- a/dict/dict0load.c +++ b/dict/dict0load.c @@ -2138,8 +2138,9 @@ static void dict_load_foreign_cols( /*===================*/ - const char* id, /*!< in: foreign constraint id as a - null-terminated string */ + const char* id, /*!< in: foreign constraint id, not + necessary '\0'-terminated */ + ulint id_len, /*!< in: id length */ dict_foreign_t* foreign)/*!< in: foreign constraint object */ { dict_table_t* sys_foreign_cols; @@ -2169,7 +2170,7 @@ dict_load_foreign_cols( tuple = dtuple_create(foreign->heap, 1); dfield = dtuple_get_nth_field(tuple, 0); - dfield_set_data(dfield, id, ut_strlen(id)); + dfield_set_data(dfield, id, id_len); dict_index_copy_types(tuple, sys_index, 1); btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, @@ -2182,7 +2183,7 @@ dict_load_foreign_cols( ut_a(!rec_get_deleted_flag(rec, 0)); field = rec_get_nth_field_old(rec, 0, &len); - ut_a(len == ut_strlen(id)); + ut_a(len == id_len); ut_a(ut_memcmp(id, field, len) == 0); field = rec_get_nth_field_old(rec, 1, &len); @@ -2211,8 +2212,9 @@ static ulint dict_load_foreign( /*==============*/ - const char* id, /*!< in: foreign constraint id as a - null-terminated string */ + const char* id, /*!< in: foreign constraint id, not + necessary '\0'-terminated */ + ulint id_len, /*!< in: id length */ ibool check_charsets, /*!< in: TRUE=check charset compatibility */ ibool check_recursive) @@ -2248,7 +2250,7 @@ dict_load_foreign( tuple = dtuple_create(heap2, 1); dfield = dtuple_get_nth_field(tuple, 0); - dfield_set_data(dfield, id, ut_strlen(id)); + dfield_set_data(dfield, id, id_len); dict_index_copy_types(tuple, sys_index, 1); btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, @@ -2260,8 +2262,8 @@ dict_load_foreign( /* Not found */ fprintf(stderr, - "InnoDB: Error A: cannot load foreign constraint %s\n", - id); + "InnoDB: Error A: cannot load foreign constraint " + "%.*s\n", (int) id_len, id); btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -2273,11 +2275,11 @@ dict_load_foreign( field = rec_get_nth_field_old(rec, 0, &len); /* Check if the id in record is the searched one */ - if (len != ut_strlen(id) || ut_memcmp(id, field, len) != 0) { + if (len != id_len || ut_memcmp(id, field, len) != 0) { fprintf(stderr, - "InnoDB: Error B: cannot load foreign constraint %s\n", - id); + "InnoDB: Error B: cannot load foreign constraint " + "%.*s\n", (int) id_len, id); btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -2303,7 +2305,7 @@ dict_load_foreign( foreign->type = (unsigned int) (n_fields_and_type >> 24); foreign->n_fields = (unsigned int) (n_fields_and_type & 0x3FFUL); - foreign->id = mem_heap_strdup(foreign->heap, id); + foreign->id = mem_heap_strdupl(foreign->heap, id, id_len); field = rec_get_nth_field_old(rec, 3, &len); @@ -2319,7 +2321,7 @@ dict_load_foreign( btr_pcur_close(&pcur); mtr_commit(&mtr); - dict_load_foreign_cols(id, foreign); + dict_load_foreign_cols(id, id_len, foreign); ref_table = dict_table_check_if_in_cache_low( foreign->referenced_table_name_lookup); @@ -2398,8 +2400,8 @@ dict_load_foreigns( ibool check_charsets) /*!< in: TRUE=check charset compatibility */ { + char tuple_buf[DTUPLE_EST_ALLOC(1)]; btr_pcur_t pcur; - mem_heap_t* heap; dtuple_t* tuple; dfield_t* dfield; dict_index_t* sec_index; @@ -2407,7 +2409,6 @@ dict_load_foreigns( const rec_t* rec; const byte* field; ulint len; - char* id ; ulint err; mtr_t mtr; @@ -2434,9 +2435,8 @@ dict_load_foreigns( sec_index = dict_table_get_next_index( dict_table_get_first_index(sys_foreign)); start_load: - heap = mem_heap_create(256); - tuple = dtuple_create(heap, 1); + tuple = dtuple_create_from_mem(tuple_buf, sizeof(tuple_buf), 1); dfield = dtuple_get_nth_field(tuple, 0); dfield_set_data(dfield, table_name, ut_strlen(table_name)); @@ -2490,7 +2490,6 @@ loop: /* Now we get a foreign key constraint id */ field = rec_get_nth_field_old(rec, 1, &len); - id = mem_heap_strdupl(heap, (char*) field, len); btr_pcur_store_position(&pcur, &mtr); @@ -2498,11 +2497,11 @@ loop: /* Load the foreign constraint definition to the dictionary cache */ - err = dict_load_foreign(id, check_charsets, check_recursive); + err = dict_load_foreign((char*) field, len, check_charsets, + check_recursive); if (err != DB_SUCCESS) { btr_pcur_close(&pcur); - mem_heap_free(heap); return(err); } @@ -2518,7 +2517,6 @@ next_rec: load_next_index: btr_pcur_close(&pcur); mtr_commit(&mtr); - mem_heap_free(heap); sec_index = dict_table_get_next_index(sec_index); diff --git a/fil/fil0fil.c b/fil/fil0fil.c index 649b6c36bcd..66cbdf51140 100644 --- a/fil/fil0fil.c +++ b/fil/fil0fil.c @@ -193,7 +193,7 @@ struct fil_space_struct { .ibd file of tablespace and want to stop temporarily posting of new i/o requests on the file */ - ibool stop_ibuf_merges; + ibool stop_new_ops; /*!< we set this TRUE when we start deleting a single-table tablespace */ ibool is_being_deleted; @@ -218,12 +218,13 @@ struct fil_space_struct { ulint n_pending_flushes; /*!< this is positive when flushing the tablespace to disk; dropping of the tablespace is forbidden if this is positive */ - ulint n_pending_ibuf_merges;/*!< this is positive - when merging insert buffer entries to - a page so that we may need to access - the ibuf bitmap page in the - tablespade: dropping of the tablespace - is forbidden if this is positive */ + ulint n_pending_ops;/*!< this is positive when we + have pending operations against this + tablespace. The pending operations can + be ibuf merges or lock validation code + trying to read a block. + Dropping of the tablespace is forbidden + if this is positive */ hash_node_t hash; /*!< hash chain node */ hash_node_t name_hash;/*!< hash chain the name_hash table */ #ifndef UNIV_HOTBACKUP @@ -974,11 +975,6 @@ retry: return; } - if (fil_system->n_open < fil_system->max_n_open) { - - return; - } - space = fil_space_get_by_id(space_id); if (space != NULL && space->stop_ios) { @@ -995,6 +991,25 @@ retry: mutex_exit(&fil_system->mutex); +#ifndef UNIV_HOTBACKUP + + /* Wake the i/o-handler threads to make sure pending + i/o's are performed */ + os_aio_simulated_wake_handler_threads(); + + /* The sleep here is just to give IO helper threads a + bit of time to do some work. It is not required that + all IO related to the tablespace being renamed must + be flushed here as we do fil_flush() in + fil_rename_tablespace() as well. */ + os_thread_sleep(20000); + +#endif /* UNIV_HOTBACKUP */ + + /* Flush tablespaces so that we can close modified + files in the LRU list */ + fil_flush_file_spaces(FIL_TABLESPACE); + os_thread_sleep(20000); count2++; @@ -1002,6 +1017,11 @@ retry: goto retry; } + if (fil_system->n_open < fil_system->max_n_open) { + + return; + } + /* If the file is already open, no need to do anything; if the space does not exist, we handle the situation in the function which called this function */ @@ -1274,7 +1294,7 @@ try_again: } space->stop_ios = FALSE; - space->stop_ibuf_merges = FALSE; + space->stop_new_ops = FALSE; space->is_being_deleted = FALSE; space->purpose = purpose; space->size = 0; @@ -1283,7 +1303,7 @@ try_again: space->n_reserved_extents = 0; space->n_pending_flushes = 0; - space->n_pending_ibuf_merges = 0; + space->n_pending_ops = 0; UT_LIST_INIT(space->chain); space->magic_n = FIL_SPACE_MAGIC_N; @@ -1896,13 +1916,12 @@ fil_read_first_page( #ifndef UNIV_HOTBACKUP /*******************************************************************//** -Increments the count of pending insert buffer page merges, if space is not -being deleted. -@return TRUE if being deleted, and ibuf merges should be skipped */ +Increments the count of pending operation, if space is not being deleted. +@return TRUE if being deleted, and operation should be skipped */ UNIV_INTERN ibool -fil_inc_pending_ibuf_merges( -/*========================*/ +fil_inc_pending_ops( +/*================*/ ulint id) /*!< in: space id */ { fil_space_t* space; @@ -1918,13 +1937,13 @@ fil_inc_pending_ibuf_merges( (ulong) id); } - if (space == NULL || space->stop_ibuf_merges) { + if (space == NULL || space->stop_new_ops) { mutex_exit(&fil_system->mutex); return(TRUE); } - space->n_pending_ibuf_merges++; + space->n_pending_ops++; mutex_exit(&fil_system->mutex); @@ -1932,11 +1951,11 @@ fil_inc_pending_ibuf_merges( } /*******************************************************************//** -Decrements the count of pending insert buffer page merges. */ +Decrements the count of pending operations. */ UNIV_INTERN void -fil_decr_pending_ibuf_merges( -/*=========================*/ +fil_decr_pending_ops( +/*=================*/ ulint id) /*!< in: space id */ { fil_space_t* space; @@ -1947,13 +1966,13 @@ fil_decr_pending_ibuf_merges( if (space == NULL) { fprintf(stderr, - "InnoDB: Error: decrementing ibuf merge of a" - " dropped tablespace %lu\n", + "InnoDB: Error: decrementing pending operation" + " of a dropped tablespace %lu\n", (ulong) id); } if (space != NULL) { - space->n_pending_ibuf_merges--; + space->n_pending_ops--; } mutex_exit(&fil_system->mutex); @@ -2164,7 +2183,7 @@ fil_op_log_parse_or_replay( switch (type) { case MLOG_FILE_DELETE: if (fil_tablespace_exists_in_mem(space_id)) { - ut_a(fil_delete_tablespace(space_id)); + ut_a(fil_delete_tablespace(space_id, TRUE)); } break; @@ -2234,7 +2253,9 @@ UNIV_INTERN ibool fil_delete_tablespace( /*==================*/ - ulint id) /*!< in: space id */ + ulint id, /*!< in: space id */ + ibool evict_all) /*!< in: TRUE if we want all pages + evicted from LRU. */ { ibool success; fil_space_t* space; @@ -2243,15 +2264,15 @@ fil_delete_tablespace( char* path; ut_a(id != 0); -stop_ibuf_merges: +stop_new_ops: mutex_enter(&fil_system->mutex); space = fil_space_get_by_id(id); if (space != NULL) { - space->stop_ibuf_merges = TRUE; + space->stop_new_ops = TRUE; - if (space->n_pending_ibuf_merges == 0) { + if (space->n_pending_ops == 0) { mutex_exit(&fil_system->mutex); count = 0; @@ -2265,9 +2286,10 @@ stop_ibuf_merges: ut_print_filename(stderr, space->name); fprintf(stderr, ",\n" "InnoDB: but there are %lu pending" - " ibuf merges on it.\n" + " operations (most likely ibuf merges)" + " on it.\n" "InnoDB: Loop %lu.\n", - (ulong) space->n_pending_ibuf_merges, + (ulong) space->n_pending_ops, (ulong) count); } @@ -2276,7 +2298,7 @@ stop_ibuf_merges: os_thread_sleep(20000); count++; - goto stop_ibuf_merges; + goto stop_new_ops; } } @@ -2302,7 +2324,7 @@ try_again: } ut_a(space); - ut_a(space->n_pending_ibuf_merges == 0); + ut_a(space->n_pending_ops == 0); space->is_being_deleted = TRUE; @@ -2358,7 +2380,11 @@ try_again: if (srv_lazy_drop_table) { buf_LRU_mark_space_was_deleted(id); } else { - buf_LRU_invalidate_tablespace(id); + buf_LRU_flush_or_remove_pages( + id, evict_all + ? BUF_REMOVE_ALL_NO_WRITE + : BUF_REMOVE_FLUSH_NO_WRITE); + } #endif /* printf("Deleting tablespace %s id %lu\n", space->name, id); */ @@ -2447,7 +2473,7 @@ fil_discard_tablespace( { ibool success; - success = fil_delete_tablespace(id); + success = fil_delete_tablespace(id, TRUE); if (!success) { fprintf(stderr, @@ -2579,7 +2605,7 @@ fil_rename_tablespace( retry: count++; - if (count > 1000) { + if (!(count % 1000)) { ut_print_timestamp(stderr); fputs(" InnoDB: Warning: problems renaming ", stderr); ut_print_filename(stderr, old_name); @@ -3905,7 +3931,7 @@ convert_err_exit: level = btr_page_get_level(page, &mtr); - new_block = btr_page_alloc(index, 0, FSP_NO_DIR, level, &mtr); + new_block = btr_page_alloc(index, 0, FSP_NO_DIR, level, &mtr, &mtr); new_page = buf_block_get_frame(new_block); new_page_zip = buf_block_get_page_zip(new_block); btr_page_create(new_block, new_page_zip, index, level, &mtr); @@ -3953,7 +3979,7 @@ convert_err_exit: split_rec = page_get_middle_rec(page); new_block = btr_page_alloc(index, page_no + 1, FSP_UP, - btr_page_get_level(page, &mtr), &mtr); + btr_page_get_level(page, &mtr), &mtr, &mtr); new_page = buf_block_get_frame(new_block); new_page_zip = buf_block_get_page_zip(new_block); btr_page_create(new_block, new_page_zip, index, diff --git a/fsp/fsp0fsp.c b/fsp/fsp0fsp.c index 6102c5decd8..858721e62b9 100644 --- a/fsp/fsp0fsp.c +++ b/fsp/fsp0fsp.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -211,15 +211,13 @@ fseg_n_reserved_pages_low( /********************************************************************//** Marks a page used. The page must reside within the extents of the given segment. */ -static +static __attribute__((nonnull)) void fseg_mark_page_used( /*================*/ fseg_inode_t* seg_inode,/*!< in: segment inode */ - ulint space, /*!< in: space id */ - ulint zip_size,/*!< in: compressed page size in bytes - or 0 for uncompressed pages */ ulint page, /*!< in: page offset */ + xdes_t* descr, /* extent descriptor */ mtr_t* mtr); /*!< in: mtr */ /**********************************************************************//** Returns the first extent descriptor for a segment. We think of the extent @@ -250,28 +248,38 @@ fsp_fill_free_list( descriptor page and ibuf bitmap page; then we do not allocate more extents */ ulint space, /*!< in: space */ - fsp_header_t* header, /*!< in: space header */ - mtr_t* mtr); /*!< in: mtr */ + fsp_header_t* header, /*!< in/out: space header */ + mtr_t* mtr) /*!< in/out: mini-transaction */ + __attribute__((nonnull)); /**********************************************************************//** Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation. -@return the allocated page number, FIL_NULL if no page could be allocated */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ static -ulint +buf_block_t* fseg_alloc_free_page_low( /*=====================*/ ulint space, /*!< in: space */ ulint zip_size,/*!< in: compressed page size in bytes or 0 for uncompressed pages */ - fseg_inode_t* seg_inode, /*!< in: segment inode */ - ulint hint, /*!< in: hint of which page would be desirable */ + fseg_inode_t* seg_inode, /*!< in/out: segment inode */ + ulint hint, /*!< in: hint of which page would be + desirable */ byte direction, /*!< in: if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR */ - mtr_t* mtr); /*!< in: mtr handle */ + mtr_t* mtr, /*!< in/out: mini-transaction */ + mtr_t* init_mtr)/*!< in/out: mtr or another mini-transaction + in which the page should be initialized. + If init_mtr!=mtr, but the page is already + latched in mtr, do not initialize the page. */ + __attribute__((warn_unused_result, nonnull)); #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** @@ -641,23 +649,22 @@ xdes_calc_descriptor_index( /********************************************************************//** Gets pointer to a the extent descriptor of a page. The page where the extent -descriptor resides is x-locked. If the page offset is equal to the free limit -of the space, adds new extents from above the free limit to the space free -list, if not free limit == space size. This adding is necessary to make the -descriptor defined, as they are uninitialized above the free limit. +descriptor resides is x-locked. This function no longer extends the data +file. @return pointer to the extent descriptor, NULL if the page does not -exist in the space or if the offset exceeds the free limit */ -UNIV_INLINE +exist in the space or if the offset is >= the free limit */ +UNIV_INLINE __attribute__((nonnull, warn_unused_result)) xdes_t* xdes_get_descriptor_with_space_hdr( /*===============================*/ - fsp_header_t* sp_header,/*!< in/out: space header, x-latched */ - ulint space, /*!< in: space id */ - ulint offset, /*!< in: page offset; - if equal to the free limit, - we try to add new extents to - the space free list */ - mtr_t* mtr) /*!< in: mtr handle */ + fsp_header_t* sp_header, /*!< in/out: space header, x-latched + in mtr */ + ulint space, /*!< in: space id */ + ulint offset, /*!< in: page offset; if equal + to the free limit, we try to + add new extents to the space + free list */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { ulint limit; ulint size; @@ -665,11 +672,9 @@ xdes_get_descriptor_with_space_hdr( ulint descr_page_no; page_t* descr_page; - ut_ad(mtr); ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL), MTR_MEMO_X_LOCK)); - ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_S_FIX) - || mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_X_FIX)); + ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_X_FIX)); ut_ad(page_offset(sp_header) == FSP_HEADER_OFFSET); /* Read free limit and space size */ limit = mach_read_from_4(sp_header + FSP_FREE_LIMIT); @@ -677,19 +682,10 @@ xdes_get_descriptor_with_space_hdr( zip_size = dict_table_flags_to_zip_size( mach_read_from_4(sp_header + FSP_SPACE_FLAGS)); - /* If offset is >= size or > limit, return NULL */ - - if ((offset >= size) || (offset > limit)) { - + if ((offset >= size) || (offset >= limit)) { return(NULL); } - /* If offset is == limit, fill free list of the space. */ - - if (offset == limit) { - fsp_fill_free_list(FALSE, space, sp_header, mtr); - } - descr_page_no = xdes_calc_descriptor_page(zip_size, offset); if (descr_page_no == 0) { @@ -719,7 +715,7 @@ is necessary to make the descriptor defined, as they are uninitialized above the free limit. @return pointer to the extent descriptor, NULL if the page does not exist in the space or if the offset exceeds the free limit */ -static +static __attribute__((nonnull, warn_unused_result)) xdes_t* xdes_get_descriptor( /*================*/ @@ -728,7 +724,7 @@ xdes_get_descriptor( or 0 for uncompressed pages */ ulint offset, /*!< in: page offset; if equal to the free limit, we try to add new extents to the space free list */ - mtr_t* mtr) /*!< in: mtr handle */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { buf_block_t* block; fsp_header_t* sp_header; @@ -1112,14 +1108,14 @@ fsp_header_get_tablespace_size(void) Tries to extend a single-table tablespace so that a page would fit in the data file. @return TRUE if success */ -static +static __attribute__((nonnull, warn_unused_result)) ibool fsp_try_extend_data_file_with_pages( /*================================*/ ulint space, /*!< in: space */ ulint page_no, /*!< in: page number */ - fsp_header_t* header, /*!< in: space header */ - mtr_t* mtr) /*!< in: mtr */ + fsp_header_t* header, /*!< in/out: space header */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { ibool success; ulint actual_size; @@ -1144,7 +1140,7 @@ fsp_try_extend_data_file_with_pages( /***********************************************************************//** Tries to extend the last data file of a tablespace if it is auto-extending. @return FALSE if not auto-extending */ -static +static __attribute__((nonnull)) ibool fsp_try_extend_data_file( /*=====================*/ @@ -1154,8 +1150,8 @@ fsp_try_extend_data_file( the actual file size rounded down to megabyte */ ulint space, /*!< in: space */ - fsp_header_t* header, /*!< in: space header */ - mtr_t* mtr) /*!< in: mtr */ + fsp_header_t* header, /*!< in/out: space header */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { ulint size; ulint zip_size; @@ -1291,7 +1287,7 @@ fsp_fill_free_list( then we do not allocate more extents */ ulint space, /*!< in: space */ fsp_header_t* header, /*!< in/out: space header */ - mtr_t* mtr) /*!< in: mtr */ + mtr_t* mtr) /*!< in/out: mini-transaction */ { ulint limit; ulint size; @@ -1490,29 +1486,120 @@ fsp_alloc_free_extent( } /**********************************************************************//** -Allocates a single free page from a space. The page is marked as used. -@return the page offset, FIL_NULL if no page could be allocated */ +Allocates a single free page from a space. */ +static __attribute__((nonnull)) +void +fsp_alloc_from_free_frag( +/*=====================*/ + fsp_header_t* header, /*!< in/out: tablespace header */ + xdes_t* descr, /*!< in/out: extent descriptor */ + ulint bit, /*!< in: slot to allocate in the extent */ + mtr_t* mtr) /*!< in/out: mini-transaction */ +{ + ulint frag_n_used; + + ut_ad(xdes_get_state(descr, mtr) == XDES_FREE_FRAG); + ut_a(xdes_get_bit(descr, XDES_FREE_BIT, bit, mtr)); + xdes_set_bit(descr, XDES_FREE_BIT, bit, FALSE, mtr); + + /* Update the FRAG_N_USED field */ + frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES, + mtr); + frag_n_used++; + mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used, MLOG_4BYTES, + mtr); + if (xdes_is_full(descr, mtr)) { + /* The fragment is full: move it to another list */ + flst_remove(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE, + mtr); + xdes_set_state(descr, XDES_FULL_FRAG, mtr); + + flst_add_last(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE, + mtr); + mlog_write_ulint(header + FSP_FRAG_N_USED, + frag_n_used - FSP_EXTENT_SIZE, MLOG_4BYTES, + mtr); + } +} + +/**********************************************************************//** +Gets a buffer block for an allocated page. + +NOTE: If init_mtr != mtr, the block will only be initialized if it was +not previously x-latched. It is assumed that the block has been +x-latched only by mtr, and freed in mtr in that case. + +@return block, initialized if init_mtr==mtr +or rw_lock_x_lock_count(&block->lock) == 1 */ static -ulint +buf_block_t* +fsp_page_create( +/*============*/ + ulint space, /*!< in: space id of the allocated page */ + ulint zip_size, /*!< in: compressed page size in bytes + or 0 for uncompressed pages */ + ulint page_no, /*!< in: page number of the allocated page */ + mtr_t* mtr, /*!< in: mini-transaction of the allocation */ + mtr_t* init_mtr) /*!< in: mini-transaction for initializing + the page */ +{ + buf_block_t* block + = buf_page_create(space, page_no, zip_size, init_mtr); +#ifdef UNIV_SYNC_DEBUG + ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX) + == rw_lock_own(&block->lock, RW_LOCK_EX)); +#endif /* UNIV_SYNC_DEBUG */ + + /* Mimic buf_page_get(), but avoid the buf_pool->page_hash lookup. */ + rw_lock_x_lock(&block->lock); + mutex_enter(&block->mutex); + buf_block_buf_fix_inc(block, __FILE__, __LINE__); + mutex_exit(&block->mutex); + mtr_memo_push(init_mtr, block, MTR_MEMO_PAGE_X_FIX); + + if (init_mtr == mtr + || rw_lock_get_x_lock_count(&block->lock) == 1) { + + /* Initialize the page, unless it was already + X-latched in mtr. (In this case, we would want to + allocate another page that has not been freed in mtr.) */ + ut_ad(init_mtr == mtr + || !mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX)); + + fsp_init_file_page(block, init_mtr); + } + + return(block); +} + +/**********************************************************************//** +Allocates a single free page from a space. The page is marked as used. +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ +static __attribute__((nonnull, warn_unused_result)) +buf_block_t* fsp_alloc_free_page( /*================*/ ulint space, /*!< in: space id */ ulint zip_size,/*!< in: compressed page size in bytes or 0 for uncompressed pages */ ulint hint, /*!< in: hint of which page would be desirable */ - mtr_t* mtr) /*!< in: mtr handle */ + mtr_t* mtr, /*!< in/out: mini-transaction */ + mtr_t* init_mtr)/*!< in/out: mini-transaction in which the + page should be initialized + (may be the same as mtr) */ { fsp_header_t* header; fil_addr_t first; xdes_t* descr; - buf_block_t* block; ulint free; - ulint frag_n_used; ulint page_no; ulint space_size; - ibool success; ut_ad(mtr); + ut_ad(init_mtr); header = fsp_get_space_header(space, zip_size, mtr); @@ -1539,7 +1626,7 @@ fsp_alloc_free_page( if (descr == NULL) { /* No free space left */ - return(FIL_NULL); + return(NULL); } xdes_set_state(descr, XDES_FREE_FRAG, mtr); @@ -1584,50 +1671,18 @@ fsp_alloc_free_page( " space size %lu. Page no %lu.\n", (ulong) space, (ulong) space_size, (ulong) page_no); - return(FIL_NULL); + return(NULL); } - success = fsp_try_extend_data_file_with_pages(space, page_no, - header, mtr); - if (!success) { + if (!fsp_try_extend_data_file_with_pages(space, page_no, + header, mtr)) { /* No disk space left */ - return(FIL_NULL); + return(NULL); } } - xdes_set_bit(descr, XDES_FREE_BIT, free, FALSE, mtr); + fsp_alloc_from_free_frag(header, descr, free, mtr); - /* Update the FRAG_N_USED field */ - frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES, - mtr); - frag_n_used++; - mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used, MLOG_4BYTES, - mtr); - if (xdes_is_full(descr, mtr)) { - /* The fragment is full: move it to another list */ - flst_remove(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE, - mtr); - xdes_set_state(descr, XDES_FULL_FRAG, mtr); - - flst_add_last(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE, - mtr); - mlog_write_ulint(header + FSP_FRAG_N_USED, - frag_n_used - FSP_EXTENT_SIZE, MLOG_4BYTES, - mtr); - } - - /* Initialize the allocated page to the buffer pool, so that it can - be obtained immediately with buf_page_get without need for a disk - read. */ - - buf_page_create(space, page_no, zip_size, mtr); - - block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr); - buf_block_dbg_add_level(block, SYNC_FSP_PAGE); - - /* Prior contents of the page should be ignored */ - fsp_init_file_page(block, mtr); - - return(page_no); + return(fsp_page_create(space, zip_size, page_no, mtr, init_mtr)); } /**********************************************************************//** @@ -1666,6 +1721,9 @@ fsp_free_page( fputs("InnoDB: Dump of descriptor: ", stderr); ut_print_buf(stderr, ((byte*)descr) - 50, 200); putc('\n', stderr); + /* Crash in debug version, so that we get a core dump + of this corruption. */ + ut_ad(0); if (state == XDES_FREE) { /* We put here some fault tolerance: if the page @@ -1684,6 +1742,9 @@ fsp_free_page( "InnoDB: Dump of descriptor: ", (ulong) page); ut_print_buf(stderr, ((byte*)descr) - 50, 200); putc('\n', stderr); + /* Crash in debug version, so that we get a core dump + of this corruption. */ + ut_ad(0); /* We put here some fault tolerance: if the page is already free, return without doing anything! */ @@ -1718,6 +1779,8 @@ fsp_free_page( mtr); fsp_free_extent(space, zip_size, page, mtr); } + + mtr->n_freed_pages++; } /**********************************************************************//** @@ -1855,7 +1918,6 @@ fsp_alloc_seg_inode_page( fseg_inode_t* inode; buf_block_t* block; page_t* page; - ulint page_no; ulint space; ulint zip_size; ulint i; @@ -1866,15 +1928,15 @@ fsp_alloc_seg_inode_page( zip_size = dict_table_flags_to_zip_size( mach_read_from_4(FSP_SPACE_FLAGS + space_header)); - page_no = fsp_alloc_free_page(space, zip_size, 0, mtr); + block = fsp_alloc_free_page(space, zip_size, 0, mtr, mtr); - if (page_no == FIL_NULL) { + if (block == NULL) { return(FALSE); } - block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); + ut_ad(rw_lock_get_x_lock_count(&block->lock) == 1); block->check_index_page_at_flush = FALSE; @@ -2287,19 +2349,20 @@ fseg_create_general( } if (page == 0) { - page = fseg_alloc_free_page_low(space, zip_size, - inode, 0, FSP_UP, mtr); + block = fseg_alloc_free_page_low(space, zip_size, + inode, 0, FSP_UP, mtr, mtr); - if (page == FIL_NULL) { + if (block == NULL) { fsp_free_seg_inode(space, zip_size, inode, mtr); goto funct_exit; } - block = buf_page_get(space, zip_size, page, RW_X_LATCH, mtr); + ut_ad(rw_lock_get_x_lock_count(&block->lock) == 1); + header = byte_offset + buf_block_get_frame(block); - mlog_write_ulint(header - byte_offset + FIL_PAGE_TYPE, + mlog_write_ulint(buf_block_get_frame(block) + FIL_PAGE_TYPE, FIL_PAGE_TYPE_SYS, MLOG_2BYTES, mtr); } @@ -2476,8 +2539,10 @@ fseg_fill_free_list( Allocates a free extent for the segment: looks first in the free list of the segment, then tries to allocate from the space free list. NOTE that the extent returned still resides in the segment free list, it is not yet taken off it! -@return allocated extent, still placed in the segment free list, NULL -if could not be allocated */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ static xdes_t* fseg_alloc_free_extent( @@ -2529,22 +2594,30 @@ fseg_alloc_free_extent( Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation. -@return the allocated page number, FIL_NULL if no page could be allocated */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ static -ulint +buf_block_t* fseg_alloc_free_page_low( /*=====================*/ ulint space, /*!< in: space */ ulint zip_size,/*!< in: compressed page size in bytes or 0 for uncompressed pages */ - fseg_inode_t* seg_inode, /*!< in: segment inode */ - ulint hint, /*!< in: hint of which page would be desirable */ + fseg_inode_t* seg_inode, /*!< in/out: segment inode */ + ulint hint, /*!< in: hint of which page would be + desirable */ byte direction, /*!< in: if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR */ - mtr_t* mtr) /*!< in: mtr handle */ + mtr_t* mtr, /*!< in/out: mini-transaction */ + mtr_t* init_mtr)/*!< in/out: mtr or another mini-transaction + in which the page should be initialized. + If init_mtr!=mtr, but the page is already + latched in mtr, do not initialize the page. */ { fsp_header_t* space_header; ulint space_size; @@ -2555,7 +2628,6 @@ fseg_alloc_free_page_low( ulint ret_page; /*!< the allocated page offset, FIL_NULL if could not be allocated */ xdes_t* ret_descr; /*!< the extent of the allocated page */ - ibool frag_page_allocated = FALSE; ibool success; ulint n; @@ -2577,6 +2649,7 @@ fseg_alloc_free_page_low( if (descr == NULL) { /* Hint outside space or too high above free limit: reset hint */ + /* The file space header page is always allocated. */ hint = 0; descr = xdes_get_descriptor(space, zip_size, hint, mtr); } @@ -2587,15 +2660,19 @@ fseg_alloc_free_page_low( && mach_read_from_8(descr + XDES_ID) == seg_id && (xdes_get_bit(descr, XDES_FREE_BIT, hint % FSP_EXTENT_SIZE, mtr) == TRUE)) { - +take_hinted_page: /* 1. We can take the hinted page =================================*/ ret_descr = descr; ret_page = hint; + /* Skip the check for extending the tablespace. If the + page hint were not within the size of the tablespace, + we would have got (descr == NULL) above and reset the hint. */ + goto got_hinted_page; /*-----------------------------------------------------------*/ - } else if ((xdes_get_state(descr, mtr) == XDES_FREE) - && ((reserved - used) < reserved / FSEG_FILLFACTOR) - && (used >= FSEG_FRAG_LIMIT)) { + } else if (xdes_get_state(descr, mtr) == XDES_FREE + && reserved - used < reserved / FSEG_FILLFACTOR + && used >= FSEG_FRAG_LIMIT) { /* 2. We allocate the free extent from space and can take ========================================================= @@ -2613,7 +2690,7 @@ fseg_alloc_free_page_low( /* Try to fill the segment free list */ fseg_fill_free_list(seg_inode, space, zip_size, hint + FSP_EXTENT_SIZE, mtr); - ret_page = hint; + goto take_hinted_page; /*-----------------------------------------------------------*/ } else if ((direction != FSP_NO_DIR) && ((reserved - used) < reserved / FSEG_FILLFACTOR) @@ -2661,7 +2738,7 @@ fseg_alloc_free_page_low( first = flst_get_first(seg_inode + FSEG_FREE, mtr); } else { ut_error; - return(FIL_NULL); + return(NULL); } ret_descr = xdes_lst_get_descriptor(space, zip_size, @@ -2673,20 +2750,23 @@ fseg_alloc_free_page_low( } else if (used < FSEG_FRAG_LIMIT) { /* 6. We allocate an individual page from the space ===================================================*/ - ret_page = fsp_alloc_free_page(space, zip_size, hint, mtr); - ret_descr = NULL; - - frag_page_allocated = TRUE; + buf_block_t* block = fsp_alloc_free_page( + space, zip_size, hint, mtr, init_mtr); - if (ret_page != FIL_NULL) { + if (block != NULL) { /* Put the page in the fragment page array of the segment */ n = fseg_find_free_frag_page_slot(seg_inode, mtr); - ut_a(n != FIL_NULL); + ut_a(n != ULINT_UNDEFINED); - fseg_set_nth_frag_page_no(seg_inode, n, ret_page, - mtr); + fseg_set_nth_frag_page_no( + seg_inode, n, buf_block_get_page_no(block), + mtr); } + + /* fsp_alloc_free_page() invoked fsp_init_file_page() + already. */ + return(block); /*-----------------------------------------------------------*/ } else { /* 7. We allocate a new extent and take its first page @@ -2704,7 +2784,7 @@ fseg_alloc_free_page_low( if (ret_page == FIL_NULL) { /* Page could not be allocated */ - return(FIL_NULL); + return(NULL); } if (space != 0) { @@ -2722,38 +2802,22 @@ fseg_alloc_free_page_low( " the space size %lu. Page no %lu.\n", (ulong) space, (ulong) space_size, (ulong) ret_page); - return(FIL_NULL); + return(NULL); } success = fsp_try_extend_data_file_with_pages( space, ret_page, space_header, mtr); if (!success) { /* No disk space left */ - return(FIL_NULL); + return(NULL); } } } - if (!frag_page_allocated) { - /* Initialize the allocated page to buffer pool, so that it - can be obtained immediately with buf_page_get without need - for a disk read */ - buf_block_t* block; - ulint zip_size = dict_table_flags_to_zip_size( - mach_read_from_4(FSP_SPACE_FLAGS + space_header)); - - block = buf_page_create(space, ret_page, zip_size, mtr); - buf_block_dbg_add_level(block, SYNC_FSP_PAGE); - - if (UNIV_UNLIKELY(block != buf_page_get(space, zip_size, - ret_page, RW_X_LATCH, - mtr))) { - ut_error; - } - - /* The prior contents of the page should be ignored */ - fsp_init_file_page(block, mtr); - +got_hinted_page: + /* ret_descr == NULL if the block was allocated from free_frag + (XDES_FREE_FRAG) */ + if (ret_descr != NULL) { /* At this point we know the extent and the page offset. The extent is still in the appropriate list (FSEG_NOT_FULL or FSEG_FREE), and the page is not yet marked as used. */ @@ -2763,25 +2827,31 @@ fseg_alloc_free_page_low( ut_ad(xdes_get_bit(ret_descr, XDES_FREE_BIT, ret_page % FSP_EXTENT_SIZE, mtr) == TRUE); - fseg_mark_page_used(seg_inode, space, zip_size, ret_page, mtr); + fseg_mark_page_used(seg_inode, ret_page, ret_descr, mtr); } - buf_reset_check_index_page_at_flush(space, ret_page); - - return(ret_page); + return(fsp_page_create( + space, dict_table_flags_to_zip_size( + mach_read_from_4(FSP_SPACE_FLAGS + + space_header)), + ret_page, mtr, init_mtr)); } /**********************************************************************//** Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation. -@return allocated page offset, FIL_NULL if no page could be allocated */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ UNIV_INTERN -ulint +buf_block_t* fseg_alloc_free_page_general( /*=========================*/ - fseg_header_t* seg_header,/*!< in: segment header */ - ulint hint, /*!< in: hint of which page would be desirable */ + fseg_header_t* seg_header,/*!< in/out: segment header */ + ulint hint, /*!< in: hint of which page would be + desirable */ byte direction,/*!< in: if the new page is needed because of an index page split, and records are inserted there in order, into which @@ -2792,15 +2862,18 @@ fseg_alloc_free_page_general( with fsp_reserve_free_extents, then there is no need to do the check for this individual page */ - mtr_t* mtr) /*!< in: mtr handle */ + mtr_t* mtr, /*!< in/out: mini-transaction handle */ + mtr_t* init_mtr)/*!< in/out: mtr or another mini-transaction + in which the page should be initialized. + If init_mtr!=mtr, but the page is already + latched in mtr, do not initialize the page. */ { fseg_inode_t* inode; ulint space; ulint flags; ulint zip_size; rw_lock_t* latch; - ibool success; - ulint page_no; + buf_block_t* block; ulint n_reserved; space = page_get_space_id(page_align(seg_header)); @@ -2825,43 +2898,20 @@ fseg_alloc_free_page_general( inode = fseg_inode_get(seg_header, space, zip_size, mtr); - if (!has_done_reservation) { - success = fsp_reserve_free_extents(&n_reserved, space, 2, - FSP_NORMAL, mtr); - if (!success) { - return(FIL_NULL); - } + if (!has_done_reservation + && !fsp_reserve_free_extents(&n_reserved, space, 2, + FSP_NORMAL, mtr)) { + return(NULL); } - page_no = fseg_alloc_free_page_low(space, zip_size, - inode, hint, direction, mtr); + block = fseg_alloc_free_page_low(space, zip_size, + inode, hint, direction, + mtr, init_mtr); if (!has_done_reservation) { fil_space_release_free_extents(space, n_reserved); } - return(page_no); -} - -/**********************************************************************//** -Allocates a single free page from a segment. This function implements -the intelligent allocation strategy which tries to minimize file space -fragmentation. -@return allocated page offset, FIL_NULL if no page could be allocated */ -UNIV_INTERN -ulint -fseg_alloc_free_page( -/*=================*/ - fseg_header_t* seg_header,/*!< in: segment header */ - ulint hint, /*!< in: hint of which page would be desirable */ - byte direction,/*!< in: if the new page is needed because - of an index page split, and records are - inserted there in order, into which - direction they go alphabetically: FSP_DOWN, - FSP_UP, FSP_NO_DIR */ - mtr_t* mtr) /*!< in: mtr handle */ -{ - return(fseg_alloc_free_page_general(seg_header, hint, direction, - FALSE, mtr)); + return(block); } /**********************************************************************//** @@ -3183,27 +3233,21 @@ fsp_get_available_space_in_free_extents( /********************************************************************//** Marks a page used. The page must reside within the extents of the given segment. */ -static +static __attribute__((nonnull)) void fseg_mark_page_used( /*================*/ fseg_inode_t* seg_inode,/*!< in: segment inode */ - ulint space, /*!< in: space id */ - ulint zip_size,/*!< in: compressed page size in bytes - or 0 for uncompressed pages */ ulint page, /*!< in: page offset */ + xdes_t* descr, /* extent descriptor */ mtr_t* mtr) /*!< in: mtr */ { - xdes_t* descr; ulint not_full_n_used; - ut_ad(seg_inode && mtr); ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE)); ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE); - descr = xdes_get_descriptor(space, zip_size, page, mtr); - ut_ad(mtr_read_ulint(seg_inode + FSEG_ID, MLOG_4BYTES, mtr) == mtr_read_ulint(descr + XDES_ID, MLOG_4BYTES, mtr)); @@ -3378,6 +3422,8 @@ crash: descr + XDES_FLST_NODE, mtr); fsp_free_extent(space, zip_size, page, mtr); } + + mtr->n_freed_pages++; } /**********************************************************************//** diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc index 9b07c82c037..0d08cd2c1b6 100644 --- a/handler/ha_innodb.cc +++ b/handler/ha_innodb.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. @@ -26,8 +26,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -195,6 +195,9 @@ static my_bool innobase_create_status_file = FALSE; static my_bool innobase_stats_on_metadata = TRUE; static my_bool innobase_large_prefix = FALSE; static my_bool innobase_use_sys_stats_table = FALSE; +#ifdef UNIV_DEBUG +static ulong innobase_sys_stats_root_page = 0; +#endif static my_bool innobase_buffer_pool_shm_checksum = TRUE; static uint innobase_buffer_pool_shm_key = 0; @@ -1174,6 +1177,9 @@ convert_error_code_to_mysql( case DB_OUT_OF_FILE_SPACE: return(HA_ERR_RECORD_FILE_FULL); + case DB_TABLE_IN_FK_CHECK: + return(HA_ERR_TABLE_IN_FK_CHECK); + case DB_TABLE_IS_BEING_USED: return(HA_ERR_WRONG_COMMAND); @@ -1623,70 +1629,87 @@ values we want to reserve for multi-value inserts e.g., INSERT INTO T VALUES(), (), (); -innobase_next_autoinc() will be called with increment set to -n * 3 where autoinc_lock_mode != TRADITIONAL because we want -to reserve 3 values for the multi-value INSERT above. +innobase_next_autoinc() will be called with increment set to 3 where +autoinc_lock_mode != TRADITIONAL because we want to reserve 3 values for +the multi-value INSERT above. @return the next value */ static ulonglong innobase_next_autoinc( /*==================*/ ulonglong current, /*!< in: Current value */ - ulonglong increment, /*!< in: increment current by */ + ulonglong need, /*!< in: count of values needed */ + ulonglong step, /*!< in: AUTOINC increment step */ ulonglong offset, /*!< in: AUTOINC offset */ ulonglong max_value) /*!< in: max value for type */ { ulonglong next_value; + ulonglong block = need * step; /* Should never be 0. */ - ut_a(increment > 0); + ut_a(need > 0); + ut_a(block > 0); + ut_a(max_value > 0); + + /* Current value should never be greater than the maximum. */ + ut_a(current <= max_value); /* According to MySQL documentation, if the offset is greater than - the increment then the offset is ignored. */ - if (offset > increment) { + the step then the offset is ignored. */ + if (offset > block) { offset = 0; } - if (max_value <= current) { + /* Check for overflow. */ + if (block >= max_value + || offset > max_value + || current == max_value + || max_value - offset <= offset) { + next_value = max_value; - } else if (offset <= 1) { - /* Offset 0 and 1 are the same, because there must be at - least one node in the system. */ - if (max_value - current <= increment) { + } else { + ut_a(max_value > current); + + ulonglong free = max_value - current; + + if (free < offset || free - offset <= block) { next_value = max_value; } else { - next_value = current + increment; + next_value = 0; } - } else if (max_value > current) { + } + + if (next_value == 0) { + ulonglong next; + if (current > offset) { - next_value = ((current - offset) / increment) + 1; + next = (current - offset) / step; } else { - next_value = ((offset - current) / increment) + 1; + next = (offset - current) / step; } - ut_a(increment > 0); - ut_a(next_value > 0); - + ut_a(max_value > next); + next_value = next * step; /* Check for multiplication overflow. */ - if (increment > (max_value / next_value)) { + ut_a(next_value >= next); + ut_a(max_value > next_value); - next_value = max_value; - } else { - next_value *= increment; + /* Check for overflow */ + if (max_value - next_value >= block) { - ut_a(max_value >= next_value); + next_value += block; - /* Check for overflow. */ - if (max_value - next_value <= offset) { - next_value = max_value; - } else { + if (max_value - next_value >= offset) { next_value += offset; + } else { + next_value = max_value; } + } else { + next_value = max_value; } - } else { - next_value = max_value; } + ut_a(next_value != 0); ut_a(next_value <= max_value); return(next_value); @@ -2731,6 +2754,10 @@ mem_free_and_error: srv_use_sys_stats_table = (ibool) innobase_use_sys_stats_table; +#ifdef UNIV_DEBUG + srv_sys_stats_root_page = innobase_sys_stats_root_page; +#endif + /* -------------- Log files ---------------------------*/ /* The default dir for log files is the datadir of MySQL */ @@ -3905,51 +3932,139 @@ ha_innobase::primary_key_is_clustered() return(true); } +/** Always normalize table name to lower case on Windows */ +#ifdef __WIN__ +#define normalize_table_name(norm_name, name) \ + normalize_table_name_low(norm_name, name, TRUE) +#else +#define normalize_table_name(norm_name, name) \ + normalize_table_name_low(norm_name, name, FALSE) +#endif /* __WIN__ */ + /*****************************************************************//** Normalizes a table name string. A normalized name consists of the database name catenated to '/' and table name. An example: test/mytable. On Windows normalization puts both the database name and the -table name always to lower case. */ +table name always to lower case if "set_lower_case" is set to TRUE. */ static void -normalize_table_name( -/*=================*/ +normalize_table_name_low( +/*=====================*/ char* norm_name, /*!< out: normalized name as a null-terminated string */ - const char* name) /*!< in: table name string */ + const char* name, /*!< in: table name string */ + ibool set_lower_case) /*!< in: TRUE if we want to set + name to lower case */ { char* name_ptr; char* db_ptr; + ulint db_len; char* ptr; /* Scan name from the end */ - ptr = strend(name)-1; + ptr = strend(name) - 1; + /* seek to the last path separator */ while (ptr >= name && *ptr != '\\' && *ptr != '/') { ptr--; } name_ptr = ptr + 1; - DBUG_ASSERT(ptr > name); + /* skip any number of path separators */ + while (ptr >= name && (*ptr == '\\' || *ptr == '/')) { + ptr--; + } - ptr--; + DBUG_ASSERT(ptr >= name); + /* seek to the last but one path separator or one char before + the beginning of name */ + db_len = 0; while (ptr >= name && *ptr != '\\' && *ptr != '/') { ptr--; + db_len++; } db_ptr = ptr + 1; - memcpy(norm_name, db_ptr, strlen(name) + 1 - (db_ptr - name)); + memcpy(norm_name, db_ptr, db_len); - norm_name[name_ptr - db_ptr - 1] = '/'; + norm_name[db_len] = '/'; -#ifdef __WIN__ - innobase_casedn_str(norm_name); -#endif + memcpy(norm_name + db_len + 1, name_ptr, strlen(name_ptr) + 1); + + if (set_lower_case) { + innobase_casedn_str(norm_name); + } +} + +#if !defined(DBUG_OFF) +/********************************************************************* +Test normalize_table_name_low(). */ +static +void +test_normalize_table_name_low() +/*===========================*/ +{ + char norm_name[128]; + const char* test_data[][2] = { + /* input, expected result */ + {"./mysqltest/t1", "mysqltest/t1"}, + {"./test/#sql-842b_2", "test/#sql-842b_2"}, + {"./test/#sql-85a3_10", "test/#sql-85a3_10"}, + {"./test/#sql2-842b-2", "test/#sql2-842b-2"}, + {"./test/bug29807", "test/bug29807"}, + {"./test/foo", "test/foo"}, + {"./test/innodb_bug52663", "test/innodb_bug52663"}, + {"./test/t", "test/t"}, + {"./test/t1", "test/t1"}, + {"./test/t10", "test/t10"}, + {"/a/b/db/table", "db/table"}, + {"/a/b/db///////table", "db/table"}, + {"/a/b////db///////table", "db/table"}, + {"/var/tmp/mysqld.1/#sql842b_2_10", "mysqld.1/#sql842b_2_10"}, + {"db/table", "db/table"}, + {"ddd/t", "ddd/t"}, + {"d/ttt", "d/ttt"}, + {"d/t", "d/t"}, + {".\\mysqltest\\t1", "mysqltest/t1"}, + {".\\test\\#sql-842b_2", "test/#sql-842b_2"}, + {".\\test\\#sql-85a3_10", "test/#sql-85a3_10"}, + {".\\test\\#sql2-842b-2", "test/#sql2-842b-2"}, + {".\\test\\bug29807", "test/bug29807"}, + {".\\test\\foo", "test/foo"}, + {".\\test\\innodb_bug52663", "test/innodb_bug52663"}, + {".\\test\\t", "test/t"}, + {".\\test\\t1", "test/t1"}, + {".\\test\\t10", "test/t10"}, + {"C:\\a\\b\\db\\table", "db/table"}, + {"C:\\a\\b\\db\\\\\\\\\\\\\\table", "db/table"}, + {"C:\\a\\b\\\\\\\\db\\\\\\\\\\\\\\table", "db/table"}, + {"C:\\var\\tmp\\mysqld.1\\#sql842b_2_10", "mysqld.1/#sql842b_2_10"}, + {"db\\table", "db/table"}, + {"ddd\\t", "ddd/t"}, + {"d\\ttt", "d/ttt"}, + {"d\\t", "d/t"}, + }; + + for (size_t i = 0; i < UT_ARR_SIZE(test_data); i++) { + printf("test_normalize_table_name_low(): " + "testing \"%s\", expected \"%s\"... ", + test_data[i][0], test_data[i][1]); + + normalize_table_name_low(norm_name, test_data[i][0], FALSE); + + if (strcmp(norm_name, test_data[i][1]) == 0) { + printf("ok\n"); + } else { + printf("got \"%s\"\n", norm_name); + ut_error; + } + } } +#endif /* !DBUG_OFF */ /********************************************************************//** Get the upper limit of the MySQL integral and floating-point type. @@ -4297,7 +4412,7 @@ ha_innobase::innobase_initialize_autoinc() nor the offset, so use a default increment of 1. */ auto_inc = innobase_next_autoinc( - read_auto_inc, 1, 1, col_max_value); + read_auto_inc, 1, 1, 0, col_max_value); break; } @@ -4352,6 +4467,8 @@ ha_innobase::open( THD* thd; ulint retries = 0; char* is_part = NULL; + ibool par_case_name_set = FALSE; + char par_case_name[MAX_FULL_NAME_LEN + 1]; DBUG_ENTER("ha_innobase::open"); @@ -4382,51 +4499,107 @@ ha_innobase::open( DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); } - /* Create buffers for packing the fields of a record. Why - table->reclength did not work here? Obviously, because char - fields when packed actually became 1 byte longer, when we also - stored the string length as the first byte. */ - - upd_and_key_val_buff_len = - table->s->reclength + table->s->max_key_length - + MAX_REF_PARTS * 3; - if (!(uchar*) my_multi_malloc(MYF(MY_WME), - &upd_buff, upd_and_key_val_buff_len, - &key_val_buff, upd_and_key_val_buff_len, - NullS)) { - free_share(share); - - DBUG_RETURN(1); - } + /* Will be allocated if it is needed in ::update_row() */ + upd_buf = NULL; + upd_buf_size = 0; /* We look for pattern #P# to see if the table is partitioned MySQL table. The retry logic for partitioned tables is a workaround for http://bugs.mysql.com/bug.php?id=33349. Look at support issue https://support.mysql.com/view.php?id=21080 for more details. */ +#ifdef __WIN__ + is_part = strstr(norm_name, "#p#"); +#else is_part = strstr(norm_name, "#P#"); +#endif /* __WIN__ */ + retry: /* Get pointer to a table object in InnoDB dictionary cache */ ib_table = dict_table_get(norm_name, TRUE); - + if (srv_pass_corrupt_table <= 1 && ib_table && ib_table->is_corrupt) { free_share(share); - my_free(upd_buff); + my_free(upd_buf); + upd_buf = NULL; + upd_buf_size = 0; DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); } share->ib_table = ib_table; - - - - if (NULL == ib_table) { if (is_part && retries < 10) { - ++retries; - os_thread_sleep(100000); - goto retry; + /* MySQL partition engine hard codes the file name + separator as "#P#". The text case is fixed even if + lower_case_table_names is set to 1 or 2. This is true + for sub-partition names as well. InnoDB always + normalises file names to lower case on Windows, this + can potentially cause problems when copying/moving + tables between platforms. + + 1) If boot against an installation from Windows + platform, then its partition table name could + be all be in lower case in system tables. So we + will need to check lower case name when load table. + + 2) If we boot an installation from other case + sensitive platform in Windows, we might need to + check the existence of table name without lowering + case them in the system table. */ + if (innobase_get_lower_case_table_names() == 1) { + + if (!par_case_name_set) { +#ifndef __WIN__ + /* Check for the table using lower + case name, including the partition + separator "P" */ + memcpy(par_case_name, norm_name, + strlen(norm_name)); + par_case_name[strlen(norm_name)] = 0; + innobase_casedn_str(par_case_name); +#else + /* On Windows platfrom, check + whether there exists table name in + system table whose name is + not being normalized to lower case */ + normalize_table_name_low( + par_case_name, name, FALSE); +#endif + par_case_name_set = TRUE; + } + + ib_table = dict_table_get( + par_case_name, FALSE); + } + if (!ib_table) { + ++retries; + os_thread_sleep(100000); + goto retry; + } else { +#ifndef __WIN__ + sql_print_warning("Partition table %s opened " + "after converting to lower " + "case. The table may have " + "been moved from a case " + "in-sensitive file system. " + "Please recreate table in " + "the current file system\n", + norm_name); +#else + sql_print_warning("Partition table %s opened " + "after skipping the step to " + "lower case the table name. " + "The table may have been " + "moved from a case sensitive " + "file system. Please " + "recreate table in the " + "current file system\n", + norm_name); +#endif + goto table_opened; + } } if (is_part) { @@ -4451,12 +4624,13 @@ retry: "how you can resolve the problem.\n", norm_name); free_share(share); - my_free(upd_buff); my_errno = ENOENT; DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); } +table_opened: + if (ib_table->ibd_file_missing && !thd_tablespace_op(thd)) { sql_print_error("MySQL is trying to open a table handle but " "the .ibd file for\ntable %s does not exist.\n" @@ -4467,16 +4641,14 @@ retry: "how you can resolve the problem.\n", norm_name); free_share(share); - my_free(upd_buff); my_errno = ENOENT; dict_table_decrement_handle_count(ib_table, FALSE); DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); } - prebuilt = row_create_prebuilt(ib_table); + prebuilt = row_create_prebuilt(ib_table, table->s->reclength); - prebuilt->mysql_row_len = table->s->reclength; prebuilt->default_rec = table->s->default_values; ut_ad(prebuilt->default_rec); @@ -4665,7 +4837,13 @@ ha_innobase::close(void) row_prebuilt_free(prebuilt, FALSE); - my_free(upd_buff); + if (upd_buf != NULL) { + ut_ad(upd_buf_size != 0); + my_free(upd_buf); + upd_buf = NULL; + upd_buf_size = 0; + } + free_share(share); /* Tell InnoDB server that there might be work for @@ -5759,15 +5937,16 @@ set_max_autoinc: if (auto_inc <= col_max_value) { ut_a(prebuilt->autoinc_increment > 0); - ulonglong need; ulonglong offset; + ulonglong increment; offset = prebuilt->autoinc_offset; - need = prebuilt->autoinc_increment; + increment = prebuilt->autoinc_increment; auto_inc = innobase_next_autoinc( auto_inc, - need, offset, col_max_value); + 1, increment, offset, + col_max_value); err = innobase_set_max_autoinc( auto_inc); @@ -5970,6 +6149,23 @@ ha_innobase::update_row( ut_a(prebuilt->trx == trx); + if (upd_buf == NULL) { + ut_ad(upd_buf_size == 0); + + /* Create a buffer for packing the fields of a record. Why + table->reclength did not work here? Obviously, because char + fields when packed actually became 1 byte longer, when we also + stored the string length as the first byte. */ + + upd_buf_size = table->s->reclength + table->s->max_key_length + + MAX_REF_PARTS * 3; + upd_buf = (uchar*) my_malloc(upd_buf_size, MYF(MY_WME)); + if (upd_buf == NULL) { + upd_buf_size = 0; + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + ha_statistic_increment(&SSV::ha_update_count); if (share->ib_table->is_corrupt) { @@ -5986,11 +6182,10 @@ ha_innobase::update_row( } /* Build an update vector from the modified fields in the rows - (uses upd_buff of the handle) */ + (uses upd_buf of the handle) */ calc_row_difference(uvect, (uchar*) old_row, new_row, table, - upd_buff, (ulint)upd_and_key_val_buff_len, - prebuilt, user_thd); + upd_buf, upd_buf_size, prebuilt, user_thd); /* This is not a delete */ prebuilt->upd_node->is_delete = FALSE; @@ -6027,14 +6222,14 @@ ha_innobase::update_row( if (auto_inc <= col_max_value && auto_inc != 0) { - ulonglong need; ulonglong offset; + ulonglong increment; offset = prebuilt->autoinc_offset; - need = prebuilt->autoinc_increment; + increment = prebuilt->autoinc_increment; auto_inc = innobase_next_autoinc( - auto_inc, need, offset, col_max_value); + auto_inc, 1, increment, offset, col_max_value); error = innobase_set_max_autoinc(auto_inc); } @@ -6359,6 +6554,7 @@ ha_innobase::index_read( DBUG_ENTER("index_read"); ut_a(prebuilt->trx == thd_to_trx(user_thd)); + ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); ha_statistic_increment(&SSV::ha_read_key_count); @@ -6391,8 +6587,7 @@ ha_innobase::index_read( row_sel_convert_mysql_key_to_innobase( prebuilt->search_tuple, - (byte*) key_val_buff, - (ulint)upd_and_key_val_buff_len, + srch_key_val1, sizeof(srch_key_val1), index, (byte*) key_ptr, (ulint) key_len, @@ -7559,6 +7754,8 @@ ha_innobase::create( DBUG_RETURN(HA_ERR_TO_BIG_ROW); } + ut_a(strlen(name) < sizeof(name2)); + strcpy(name2, name); normalize_table_name(norm_name, name2); @@ -8002,6 +8199,11 @@ ha_innobase::delete_table( DBUG_ENTER("ha_innobase::delete_table"); + DBUG_EXECUTE_IF( + "test_normalize_table_name_low", + test_normalize_table_name_low(); + ); + /* Strangely, MySQL passes the table name without the '.frm' extension, in contrast to ::create */ normalize_table_name(norm_name, name); @@ -8162,6 +8364,8 @@ innobase_rename_table( normalize_table_name(norm_to, to); normalize_table_name(norm_from, from); + DEBUG_SYNC_C("innodb_rename_table_ready"); + /* Serialize data dictionary operations with dictionary mutex: no deadlocks can occur then in these operations */ @@ -8279,12 +8483,6 @@ ha_innobase::records_in_range( { KEY* key; dict_index_t* index; - uchar* key_val_buff2 = (uchar*) my_malloc( - table->s->reclength - + table->s->max_key_length + 100, - MYF(MY_FAE)); - ulint buff2_len = table->s->reclength - + table->s->max_key_length + 100; dtuple_t* range_start; dtuple_t* range_end; ib_int64_t n_rows; @@ -8293,7 +8491,6 @@ ha_innobase::records_in_range( mem_heap_t* heap; DBUG_ENTER("records_in_range"); - DBUG_ASSERT(min_key || max_key); ut_a(prebuilt->trx == thd_to_trx(ha_thd())); @@ -8336,8 +8533,8 @@ ha_innobase::records_in_range( dict_index_copy_types(range_end, index, key->key_parts); row_sel_convert_mysql_key_to_innobase( - range_start, (byte*) key_val_buff, - (ulint)upd_and_key_val_buff_len, + range_start, + srch_key_val1, sizeof(srch_key_val1), index, (byte*) (min_key ? min_key->key : (const uchar*) 0), @@ -8348,8 +8545,9 @@ ha_innobase::records_in_range( : range_start->n_fields == 0); row_sel_convert_mysql_key_to_innobase( - range_end, (byte*) key_val_buff2, - buff2_len, index, + range_end, + srch_key_val2, sizeof(srch_key_val2), + index, (byte*) (max_key ? max_key->key : (const uchar*) 0), (ulint) (max_key ? max_key->length : 0), @@ -8376,7 +8574,6 @@ ha_innobase::records_in_range( mem_heap_free(heap); func_exit: - my_free(key_val_buff2); prebuilt->trx->op_info = (char*)""; @@ -10801,16 +10998,15 @@ ha_innobase::get_auto_increment( /* With old style AUTOINC locking we only update the table's AUTOINC counter after attempting to insert the row. */ if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) { - ulonglong need; ulonglong current; ulonglong next_value; current = *first_value > col_max_value ? autoinc : *first_value; - need = *nb_reserved_values * increment; /* Compute the last value in the interval */ next_value = innobase_next_autoinc( - current, need, offset, col_max_value); + current, *nb_reserved_values, increment, offset, + col_max_value); prebuilt->autoinc_last_value = next_value; @@ -12209,6 +12405,13 @@ static MYSQL_SYSVAR_BOOL(use_sys_stats_table, innobase_use_sys_stats_table, "So you should use ANALYZE TABLE command intentionally.", NULL, NULL, FALSE); +#ifdef UNIV_DEBUG +static MYSQL_SYSVAR_ULONG(sys_stats_root_page, innobase_sys_stats_root_page, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Override the SYS_STATS root page id, 0 = no override (for testing only)", + NULL, NULL, 0, 0, ULONG_MAX, 0); +#endif + static MYSQL_SYSVAR_BOOL(adaptive_hash_index, btr_search_enabled, PLUGIN_VAR_OPCMDARG, "Enable InnoDB adaptive hash index (enabled by default). " @@ -12426,6 +12629,13 @@ static MYSQL_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold, "trigger a readahead.", NULL, NULL, 56, 0, 64, 0); +#ifdef UNIV_DEBUG +static MYSQL_SYSVAR_UINT(trx_rseg_n_slots_debug, trx_rseg_n_slots_debug, + PLUGIN_VAR_RQCMDARG, + "Debug flags for InnoDB to limit TRX_RSEG_N_SLOTS for trx_rsegf_undo_find_free()", + NULL, NULL, 0, 0, 1024, 0); +#endif /* UNIV_DEBUG */ + static MYSQL_SYSVAR_LONGLONG(ibuf_max_size, srv_ibuf_max_size, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "The maximum size of the insert buffer. (in bytes)", @@ -12547,14 +12757,6 @@ static MYSQL_SYSVAR_ENUM(adaptive_flushing_method, srv_adaptive_flushing_method, "Choose method of innodb_adaptive_flushing. (native, [estimate], keep_average)", NULL, innodb_adaptive_flushing_method_update, 1, &adaptive_flushing_method_typelib); -#ifdef UNIV_DEBUG -static MYSQL_SYSVAR_ULONG(flush_checkpoint_debug, srv_flush_checkpoint_debug, - PLUGIN_VAR_RQCMDARG, - "Debug flags for InnoDB flushing and checkpointing (0=none," - "1=stop preflush and checkpointing)", - NULL, NULL, 0, 0, 1, 0); -#endif - static MYSQL_SYSVAR_ULONG(import_table_from_xtrabackup, srv_expand_import, PLUGIN_VAR_RQCMDARG, "Enable/Disable converting automatically *.ibd files when import tablespace.", @@ -12660,6 +12862,9 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(stats_auto_update), MYSQL_SYSVAR(stats_update_need_lock), MYSQL_SYSVAR(use_sys_stats_table), +#ifdef UNIV_DEBUG + MYSQL_SYSVAR(sys_stats_root_page), +#endif MYSQL_SYSVAR(stats_sample_pages), MYSQL_SYSVAR(adaptive_hash_index), MYSQL_SYSVAR(adaptive_hash_index_partitions), @@ -12702,8 +12907,8 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(purge_batch_size), MYSQL_SYSVAR(rollback_segments), #ifdef UNIV_DEBUG - MYSQL_SYSVAR(flush_checkpoint_debug), -#endif + MYSQL_SYSVAR(trx_rseg_n_slots_debug), +#endif /* UNIV_DEBUG */ MYSQL_SYSVAR(corrupt_table_action), MYSQL_SYSVAR(lazy_drop_table), MYSQL_SYSVAR(fake_changes), diff --git a/handler/ha_innodb.h b/handler/ha_innodb.h index 9506f309827..39ef3631138 100644 --- a/handler/ha_innodb.h +++ b/handler/ha_innodb.h @@ -79,13 +79,14 @@ class ha_innobase: public handler INNOBASE_SHARE* share; /*!< information for MySQL table locking */ - uchar* upd_buff; /*!< buffer used in updates */ - uchar* key_val_buff; /*!< buffer used in converting + uchar* upd_buf; /*!< buffer used in updates */ + ulint upd_buf_size; /*!< the size of upd_buf in bytes */ + uchar srch_key_val1[REC_VERSION_56_MAX_INDEX_COL_LEN + 2]; + uchar srch_key_val2[REC_VERSION_56_MAX_INDEX_COL_LEN + 2]; + /*!< buffers used in converting search key values from MySQL format - to Innodb format */ - ulong upd_and_key_val_buff_len; - /* the length of each of the previous - two buffers */ + to InnoDB format. "+ 2" for the two + bytes where the length is stored */ Table_flags int_table_flags; uint primary_key; ulong start_of_scan; /*!< this is set to 1 when we are diff --git a/handler/handler0alter.cc b/handler/handler0alter.cc index 8c5783fa8b9..398e8bee425 100644 --- a/handler/handler0alter.cc +++ b/handler/handler0alter.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2005, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -877,6 +877,8 @@ ha_innobase::add_index( prebuilt->table, indexed_table, index, num_of_idx, table); + DBUG_EXECUTE_IF("crash_innodb_add_index_after", DBUG_SUICIDE();); + error_handling: /* After an error, remove all those index definitions from the dictionary which were defined. */ @@ -1019,7 +1021,12 @@ ha_innobase::final_add_index( row_prebuilt_free(prebuilt, TRUE); error = row_merge_drop_table(trx, old_table); add->indexed_table->n_mysql_handles_opened++; - prebuilt = row_create_prebuilt(add->indexed_table); + prebuilt = row_create_prebuilt(add->indexed_table, + 0 /* XXX Do we know the mysql_row_len here? + Before the addition of this parameter to + row_create_prebuilt() the mysql_row_len + member was left 0 (from zalloc) in the + prebuilt object. */); } err = convert_error_code_to_mysql( @@ -1153,7 +1160,9 @@ ha_innobase::prepare_drop_index( goto func_exit; } + rw_lock_x_lock(dict_index_get_lock(index)); index->to_be_dropped = TRUE; + rw_lock_x_unlock(dict_index_get_lock(index)); } /* If FOREIGN_KEY_CHECKS = 1 you may not drop an index defined @@ -1272,7 +1281,9 @@ func_exit: = dict_table_get_first_index(prebuilt->table); do { + rw_lock_x_lock(dict_index_get_lock(index)); index->to_be_dropped = FALSE; + rw_lock_x_unlock(dict_index_get_lock(index)); index = dict_table_get_next_index(index); } while (index); } @@ -1338,7 +1349,9 @@ ha_innobase::final_drop_index( for (index = dict_table_get_first_index(prebuilt->table); index; index = dict_table_get_next_index(index)) { + rw_lock_x_lock(dict_index_get_lock(index)); index->to_be_dropped = FALSE; + rw_lock_x_unlock(dict_index_get_lock(index)); } goto func_exit; diff --git a/ibuf/ibuf0ibuf.c b/ibuf/ibuf0ibuf.c index 00b7ea7347d..562f207268a 100644 --- a/ibuf/ibuf0ibuf.c +++ b/ibuf/ibuf0ibuf.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -1523,7 +1523,7 @@ ibuf_add_ops( for (i = 0; i < IBUF_OP_COUNT; i++) { #ifdef HAVE_ATOMIC_BUILTINS - os_atomic_increment_ulint(&arr[i], ops[i]); + (void) os_atomic_increment_ulint(&arr[i], ops[i]); #else /* HAVE_ATOMIC_BUILTINS */ arr[i] += ops[i]; #endif /* HAVE_ATOMIC_BUILTINS */ @@ -2222,14 +2222,14 @@ ibool ibuf_add_free_page(void) /*====================*/ { - mtr_t mtr; - page_t* header_page; - ulint flags; - ulint zip_size; - ulint page_no; - page_t* page; - page_t* root; - page_t* bitmap_page; + mtr_t mtr; + page_t* header_page; + ulint flags; + ulint zip_size; + buf_block_t* block; + page_t* page; + page_t* root; + page_t* bitmap_page; mtr_start(&mtr); @@ -2250,28 +2250,23 @@ ibuf_add_free_page(void) of a deadlock. This is the reason why we created a special ibuf header page apart from the ibuf tree. */ - page_no = fseg_alloc_free_page( + block = fseg_alloc_free_page( header_page + IBUF_HEADER + IBUF_TREE_SEG_HEADER, 0, FSP_UP, &mtr); - if (UNIV_UNLIKELY(page_no == FIL_NULL)) { + if (block == NULL) { mtr_commit(&mtr); return(FALSE); - } else { - buf_block_t* block = buf_page_get( - IBUF_SPACE_ID, 0, page_no, RW_X_LATCH, &mtr); - - ibuf_enter(&mtr); - - mutex_enter(&ibuf_mutex); - - root = ibuf_tree_root_get(&mtr); + } - buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE_NEW); + ut_ad(rw_lock_get_x_lock_count(&block->lock) == 1); + ibuf_enter(&mtr); + mutex_enter(&ibuf_mutex); + root = ibuf_tree_root_get(&mtr); - page = buf_block_get_frame(block); - } + buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE_NEW); + page = buf_block_get_frame(block); /* Add the page to the free list and update the ibuf size data */ @@ -2288,12 +2283,13 @@ ibuf_add_free_page(void) (level 2 page) */ bitmap_page = ibuf_bitmap_get_map_page( - IBUF_SPACE_ID, page_no, zip_size, &mtr); + IBUF_SPACE_ID, buf_block_get_page_no(block), zip_size, &mtr); mutex_exit(&ibuf_mutex); ibuf_bitmap_page_set_bits( - bitmap_page, page_no, zip_size, IBUF_BITMAP_IBUF, TRUE, &mtr); + bitmap_page, buf_block_get_page_no(block), zip_size, + IBUF_BITMAP_IBUF, TRUE, &mtr); ibuf_mtr_commit(&mtr); @@ -2588,7 +2584,15 @@ ibuf_get_merge_page_nos_func( } else { rec_page_no = ibuf_rec_get_page_no(mtr, rec); rec_space_id = ibuf_rec_get_space(mtr, rec); - ut_ad(rec_page_no > IBUF_TREE_ROOT_PAGE_NO); + /* In the system tablespace, the smallest + possible secondary index leaf page number is + bigger than IBUF_TREE_ROOT_PAGE_NO (4). In + other tablespaces, the clustered index tree is + created at page 3, which makes page 4 the + smallest possible secondary index leaf page + (and that only after DROP INDEX). */ + ut_ad(rec_page_no + > IBUF_TREE_ROOT_PAGE_NO - (rec_space_id != 0)); } #ifdef UNIV_IBUF_DEBUG @@ -3920,6 +3924,7 @@ ibuf_insert_to_index_page_low( fputs("InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); } /************************************************************************ @@ -3970,9 +3975,10 @@ ibuf_insert_to_index_page( "InnoDB: but the number of fields does not match!\n", stderr); dump: - buf_page_print(page, 0); + buf_page_print(page, 0, BUF_PAGE_PRINT_NO_CRASH); dtuple_print(stderr, entry); + ut_ad(0); fputs("InnoDB: The table where where" " this index record belongs\n" @@ -4113,6 +4119,11 @@ ibuf_set_del_mark( TRUE, mtr); } } else { + const page_t* page + = page_cur_get_page(&page_cur); + const buf_block_t* block + = page_cur_get_block(&page_cur); + ut_print_timestamp(stderr); fputs(" InnoDB: unable to find a record to delete-mark\n", stderr); @@ -4121,10 +4132,14 @@ ibuf_set_del_mark( fputs("\n" "InnoDB: record ", stderr); rec_print(stderr, page_cur_get_rec(&page_cur), index); - putc('\n', stderr); - fputs("\n" - "InnoDB: Submit a detailed bug report" - " to http://bugs.mysql.com\n", stderr); + fprintf(stderr, "\nspace %u offset %u" + " (%u records, index id %llu)\n" + "InnoDB: Submit a detailed bug report" + " to http://bugs.mysql.com\n", + (unsigned) buf_block_get_space(block), + (unsigned) buf_block_get_page_no(block), + (unsigned) page_get_n_recs(page), + (ulonglong) btr_page_get_index_id(page)); ut_ad(0); } } @@ -4168,12 +4183,31 @@ ibuf_delete( offsets = rec_get_offsets( rec, index, offsets, ULINT_UNDEFINED, &heap); - /* Refuse to delete the last record. */ - ut_a(page_get_n_recs(page) > 1); - - /* The record should have been marked for deletion. */ - ut_ad(REC_INFO_DELETED_FLAG - & rec_get_info_bits(rec, page_is_comp(page))); + if (page_get_n_recs(page) <= 1 + || !(REC_INFO_DELETED_FLAG + & rec_get_info_bits(rec, page_is_comp(page)))) { + /* Refuse to purge the last record or a + record that has not been marked for deletion. */ + ut_print_timestamp(stderr); + fputs(" InnoDB: unable to purge a record\n", + stderr); + fputs("InnoDB: tuple ", stderr); + dtuple_print(stderr, entry); + fputs("\n" + "InnoDB: record ", stderr); + rec_print_new(stderr, rec, offsets); + fprintf(stderr, "\nspace %u offset %u" + " (%u records, index id %llu)\n" + "InnoDB: Submit a detailed bug report" + " to http://bugs.mysql.com\n", + (unsigned) buf_block_get_space(block), + (unsigned) buf_block_get_page_no(block), + (unsigned) page_get_n_recs(page), + (ulonglong) btr_page_get_index_id(page)); + + ut_ad(0); + return; + } lock_update_delete(block, rec); @@ -4259,6 +4293,7 @@ ibuf_restore_pos( fprintf(stderr, "InnoDB: ibuf tree ok\n"); fflush(stderr); + ut_ad(0); } return(FALSE); @@ -4441,7 +4476,7 @@ ibuf_merge_or_delete_for_page( function. When the counter is > 0, that prevents tablespace from being dropped. */ - tablespace_being_deleted = fil_inc_pending_ibuf_merges(space); + tablespace_being_deleted = fil_inc_pending_ops(space); if (UNIV_UNLIKELY(tablespace_being_deleted)) { /* Do not try to read the bitmap page from space; @@ -4467,7 +4502,7 @@ ibuf_merge_or_delete_for_page( /* No inserts buffered for this page */ if (!tablespace_being_deleted) { - fil_decr_pending_ibuf_merges(space); + fil_decr_pending_ops(space); } return; @@ -4516,12 +4551,14 @@ ibuf_merge_or_delete_for_page( bitmap_page = ibuf_bitmap_get_map_page(space, page_no, zip_size, &mtr); - buf_page_print(bitmap_page, 0); + buf_page_print(bitmap_page, 0, + BUF_PAGE_PRINT_NO_CRASH); ibuf_mtr_commit(&mtr); fputs("\nInnoDB: Dump of the page:\n", stderr); - buf_page_print(block->frame, 0); + buf_page_print(block->frame, 0, + BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "InnoDB: Error: corruption in the tablespace." @@ -4541,6 +4578,7 @@ ibuf_merge_or_delete_for_page( (ulong) page_no, (ulong) fil_page_get_type(block->frame)); + ut_ad(0); } } @@ -4747,7 +4785,7 @@ reset_bit: mem_heap_free(heap); #ifdef HAVE_ATOMIC_BUILTINS - os_atomic_increment_ulint(&ibuf->n_merges, 1); + (void) os_atomic_increment_ulint(&ibuf->n_merges, 1); ibuf_add_ops(ibuf->n_merged_ops, mops); ibuf_add_ops(ibuf->n_discarded_ops, dops); #else /* HAVE_ATOMIC_BUILTINS */ @@ -4763,7 +4801,7 @@ reset_bit: if (update_ibuf_bitmap && !tablespace_being_deleted) { - fil_decr_pending_ibuf_merges(space); + fil_decr_pending_ops(space); } #ifdef UNIV_IBUF_COUNT_DEBUG diff --git a/include/btr0btr.h b/include/btr0btr.h index 058fcfb64de..520527d0375 100644 --- a/include/btr0btr.h +++ b/include/btr0btr.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -92,6 +92,26 @@ insert/delete buffer when the record is not in the buffer pool. */ buffer when the record is not in the buffer pool. */ #define BTR_DELETE 8192 +/**************************************************************//** +Report that an index page is corrupted. */ +UNIV_INTERN +void +btr_corruption_report( +/*==================*/ + const buf_block_t* block, /*!< in: corrupted block */ + const dict_index_t* index) /*!< in: index tree */ + UNIV_COLD __attribute__((nonnull)); + +/** Assert that a B-tree page is not corrupted. +@param block buffer block containing a B-tree page +@param index the B-tree index */ +#define btr_assert_not_corrupted(block, index) \ + if ((ibool) !!page_is_comp(buf_block_get_frame(block)) \ + != dict_table_is_comp((index)->table)) { \ + btr_corruption_report(block, index); \ + ut_error; \ + } + #ifdef UNIV_BLOB_DEBUG # include "ut0rbt.h" /** An index->blobs entry for keeping track of off-page column references */ @@ -569,11 +589,14 @@ UNIV_INTERN ibool btr_compress( /*=========*/ - btr_cur_t* cursor, /*!< in: cursor on the page to merge or lift; - the page must not be empty: in record delete - use btr_discard_page if the page would become - empty */ - mtr_t* mtr); /*!< in: mtr */ + btr_cur_t* cursor, /*!< in/out: cursor on the page to merge + or lift; the page must not be empty: + when deleting records, use btr_discard_page() + if the page would become empty */ + ibool adjust, /*!< in: TRUE if should adjust the + cursor position even if compression occurs */ + mtr_t* mtr) /*!< in/out: mini-transaction */ + __attribute__((nonnull)); /*************************************************************//** Discards a page from a B-tree. This is used to remove the last record from a B-tree page: the whole page must be removed at the same time. This cannot @@ -614,17 +637,23 @@ btr_parse_page_reorganize( #ifndef UNIV_HOTBACKUP /**************************************************************//** Gets the number of pages in a B-tree. -@return number of pages */ +@return number of pages, or ULINT_UNDEFINED if the index is unavailable */ UNIV_INTERN ulint btr_get_size( /*=========*/ dict_index_t* index, /*!< in: index */ - ulint flag); /*!< in: BTR_N_LEAF_PAGES or BTR_TOTAL_SIZE */ + ulint flag, /*!< in: BTR_N_LEAF_PAGES or BTR_TOTAL_SIZE */ + mtr_t* mtr) /*!< in/out: mini-transaction where index + is s-latched */ + __attribute__((nonnull, warn_unused_result)); /**************************************************************//** Allocates a new file page to be used in an index tree. NOTE: we assume that the caller has made the reservation for free extents! -@return new allocated block, x-latched; NULL if out of space */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ UNIV_INTERN buf_block_t* btr_page_alloc( @@ -635,7 +664,12 @@ btr_page_alloc( page split is made */ ulint level, /*!< in: level where the page is placed in the tree */ - mtr_t* mtr); /*!< in: mtr */ + mtr_t* mtr, /*!< in/out: mini-transaction + for the allocation */ + mtr_t* init_mtr) /*!< in/out: mini-transaction + for x-latching and initializing + the page */ + __attribute__((nonnull, warn_unused_result)); /**************************************************************//** Frees a file page used in an index tree. NOTE: cannot free field external storage pages because the page must contain info on its level. */ diff --git a/include/btr0btr.ic b/include/btr0btr.ic index f446ecb69d3..53c8159c448 100644 --- a/include/btr0btr.ic +++ b/include/btr0btr.ic @@ -279,7 +279,7 @@ btr_node_ptr_get_child_page_no( "InnoDB: a nonsensical page number 0" " in a node ptr record at offset %lu\n", (ulong) page_offset(rec)); - buf_page_print(page_align(rec), 0); + buf_page_print(page_align(rec), 0, 0); } return(page_no); diff --git a/include/btr0cur.h b/include/btr0cur.h index 4f33aacc48e..cbc6103c2ee 100644 --- a/include/btr0cur.h +++ b/include/btr0cur.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -36,6 +36,9 @@ Created 10/16/1994 Heikki Tuuri #define BTR_NO_LOCKING_FLAG 2 /* do no record lock checking */ #define BTR_KEEP_SYS_FLAG 4 /* sys fields will be found from the update vector or inserted entry */ +#define BTR_KEEP_POS_FLAG 8 /* btr_cur_pessimistic_update() + must keep cursor position when + moving columns to big_rec */ #ifndef UNIV_HOTBACKUP #include "que0types.h" @@ -310,7 +313,9 @@ btr_cur_pessimistic_update( /*=======================*/ ulint flags, /*!< in: undo logging, locking, and rollback flags */ - btr_cur_t* cursor, /*!< in: cursor on the record to update */ + btr_cur_t* cursor, /*!< in/out: cursor on the record to update; + cursor may become invalid if *big_rec == NULL + || !(flags & BTR_KEEP_POS_FLAG) */ mem_heap_t** heap, /*!< in/out: pointer to memory heap, or NULL */ big_rec_t** big_rec,/*!< out: big rec vector whose fields have to be stored externally by the caller, or NULL */ @@ -364,10 +369,13 @@ UNIV_INTERN ibool btr_cur_compress_if_useful( /*=======================*/ - btr_cur_t* cursor, /*!< in: cursor on the page to compress; + btr_cur_t* cursor, /*!< in/out: cursor on the page to compress; cursor does not stay valid if compression occurs */ - mtr_t* mtr); /*!< in: mtr */ + ibool adjust, /*!< in: TRUE if should adjust the + cursor position even if compression occurs */ + mtr_t* mtr) /*!< in/out: mini-transaction */ + __attribute__((nonnull)); /*******************************************************//** Removes the record on which the tree cursor is positioned. It is assumed that the mtr has an x-latch on the page where the cursor is positioned, @@ -492,6 +500,27 @@ btr_cur_disown_inherited_fields( const upd_t* update, /*!< in: update vector */ mtr_t* mtr) /*!< in/out: mini-transaction */ __attribute__((nonnull(2,3,4,5,6))); + +/** Operation code for btr_store_big_rec_extern_fields(). */ +enum blob_op { + /** Store off-page columns for a freshly inserted record */ + BTR_STORE_INSERT = 0, + /** Store off-page columns for an insert by update */ + BTR_STORE_INSERT_UPDATE, + /** Store off-page columns for an update */ + BTR_STORE_UPDATE +}; + +/*******************************************************************//** +Determine if an operation on off-page columns is an update. +@return TRUE if op != BTR_STORE_INSERT */ +UNIV_INLINE +ibool +btr_blob_op_is_update( +/*==================*/ + enum blob_op op) /*!< in: operation */ + __attribute__((warn_unused_result)); + /*******************************************************************//** Stores the fields in big_rec_vec to the tablespace and puts pointers to them in rec. The extern flags in rec will have to be set beforehand. @@ -499,52 +528,23 @@ The fields are stored on pages allocated from leaf node file segment of the index tree. @return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */ UNIV_INTERN -ulint -btr_store_big_rec_extern_fields_func( -/*=================================*/ +enum db_err +btr_store_big_rec_extern_fields( +/*============================*/ dict_index_t* index, /*!< in: index of rec; the index tree MUST be X-latched */ buf_block_t* rec_block, /*!< in/out: block containing rec */ - rec_t* rec, /*!< in: record */ + rec_t* rec, /*!< in/out: record */ const ulint* offsets, /*!< in: rec_get_offsets(rec, index); the "external storage" flags in offsets will not correspond to rec when this function returns */ -#ifdef UNIV_DEBUG - mtr_t* local_mtr, /*!< in: mtr containing the - latch to rec and to the tree */ -#endif /* UNIV_DEBUG */ -#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG - ibool update_in_place,/*! in: TRUE if the record is updated - in place (not delete+insert) */ -#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */ - const big_rec_t*big_rec_vec) /*!< in: vector containing fields + const big_rec_t*big_rec_vec, /*!< in: vector containing fields to be stored externally */ - __attribute__((nonnull)); - -/** Stores the fields in big_rec_vec to the tablespace and puts pointers to -them in rec. The extern flags in rec will have to be set beforehand. -The fields are stored on pages allocated from leaf node -file segment of the index tree. -@param index in: clustered index; MUST be X-latched by mtr -@param b in/out: block containing rec; MUST be X-latched by mtr -@param rec in/out: clustered index record -@param offsets in: rec_get_offsets(rec, index); - the "external storage" flags in offsets will not be adjusted -@param mtr in: mini-transaction that holds x-latch on index and b -@param upd in: TRUE if the record is updated in place (not delete+insert) -@param big in: vector containing fields to be stored externally -@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */ -#ifdef UNIV_DEBUG -# define btr_store_big_rec_extern_fields(index,b,rec,offsets,mtr,upd,big) \ - btr_store_big_rec_extern_fields_func(index,b,rec,offsets,mtr,upd,big) -#elif defined UNIV_BLOB_LIGHT_DEBUG -# define btr_store_big_rec_extern_fields(index,b,rec,offsets,mtr,upd,big) \ - btr_store_big_rec_extern_fields_func(index,b,rec,offsets,upd,big) -#else -# define btr_store_big_rec_extern_fields(index,b,rec,offsets,mtr,upd,big) \ - btr_store_big_rec_extern_fields_func(index,b,rec,offsets,big) -#endif + mtr_t* btr_mtr, /*!< in: mtr containing the + latches to the clustered index */ + enum blob_op op) /*! in: operation code */ + __attribute__((nonnull, warn_unused_result)); /*******************************************************************//** Frees the space in an externally stored field to the file space diff --git a/include/btr0cur.ic b/include/btr0cur.ic index 280583f6ccf..e31f77c77eb 100644 --- a/include/btr0cur.ic +++ b/include/btr0cur.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -139,7 +139,7 @@ btr_cur_compress_recommendation( btr_cur_t* cursor, /*!< in: btr cursor */ mtr_t* mtr) /*!< in: mtr */ { - page_t* page; + const page_t* page; ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor), MTR_MEMO_PAGE_X_FIX)); @@ -197,4 +197,25 @@ btr_cur_can_delete_without_compress( return(TRUE); } + +/*******************************************************************//** +Determine if an operation on off-page columns is an update. +@return TRUE if op != BTR_STORE_INSERT */ +UNIV_INLINE +ibool +btr_blob_op_is_update( +/*==================*/ + enum blob_op op) /*!< in: operation */ +{ + switch (op) { + case BTR_STORE_INSERT: + return(FALSE); + case BTR_STORE_INSERT_UPDATE: + case BTR_STORE_UPDATE: + return(TRUE); + } + + ut_ad(0); + return(FALSE); +} #endif /* !UNIV_HOTBACKUP */ diff --git a/include/btr0pcur.h b/include/btr0pcur.h index 140f94466db..2ebd70a6f23 100644 --- a/include/btr0pcur.h +++ b/include/btr0pcur.h @@ -53,6 +53,16 @@ UNIV_INTERN btr_pcur_t* btr_pcur_create_for_mysql(void); /*============================*/ + +/**************************************************************//** +Resets a persistent cursor object, freeing ::old_rec_buf if it is +allocated and resetting the other members to their initial values. */ +UNIV_INTERN +void +btr_pcur_reset( +/*===========*/ + btr_pcur_t* cursor);/*!< in, out: persistent cursor */ + /**************************************************************//** Frees the memory for a persistent cursor object. */ UNIV_INTERN diff --git a/include/buf0buf.h b/include/buf0buf.h index 0ea74fb9eb2..7502942d681 100644 --- a/include/buf0buf.h +++ b/include/buf0buf.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -611,6 +611,31 @@ buf_block_get_modify_clock( #else /* !UNIV_HOTBACKUP */ # define buf_block_modify_clock_inc(block) ((void) 0) #endif /* !UNIV_HOTBACKUP */ +/*******************************************************************//** +Increments the bufferfix count. */ +UNIV_INLINE +void +buf_block_buf_fix_inc_func( +/*=======================*/ +#ifdef UNIV_SYNC_DEBUG + const char* file, /*!< in: file name */ + ulint line, /*!< in: line */ +#endif /* UNIV_SYNC_DEBUG */ + buf_block_t* block) /*!< in/out: block to bufferfix */ + __attribute__((nonnull)); +#ifdef UNIV_SYNC_DEBUG +/** Increments the bufferfix count. +@param b in/out: block to bufferfix +@param f in: file name where requested +@param l in: line number where requested */ +# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b) +#else /* UNIV_SYNC_DEBUG */ +/** Increments the bufferfix count. +@param b in/out: block to bufferfix +@param f in: file name where requested +@param l in: line number where requested */ +# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b) +#endif /* UNIV_SYNC_DEBUG */ /********************************************************************//** Calculates a page checksum which is stored to the page when it is written to a file. Note that we must be careful to calculate the same value @@ -700,6 +725,13 @@ buf_print(void); /*============*/ #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */ #endif /* !UNIV_HOTBACKUP */ +enum buf_page_print_flags { + /** Do not crash at the end of buf_page_print(). */ + BUF_PAGE_PRINT_NO_CRASH = 1, + /** Do not print the full page dump. */ + BUF_PAGE_PRINT_NO_FULL = 2 +}; + /********************************************************************//** Prints a page to stderr. */ UNIV_INTERN @@ -707,8 +739,12 @@ void buf_page_print( /*===========*/ const byte* read_buf, /*!< in: a database page */ - ulint zip_size); /*!< in: compressed page size, or + ulint zip_size, /*!< in: compressed page size, or 0 for uncompressed pages */ + ulint flags) /*!< in: 0 or + BUF_PAGE_PRINT_NO_CRASH or + BUF_PAGE_PRINT_NO_FULL */ + __attribute__((nonnull)); /********************************************************************//** Decompress a block. @return TRUE if successful */ @@ -773,11 +809,11 @@ buf_all_freed(void); /*********************************************************************//** Checks that there currently are no pending i/o-operations for the buffer pool. -@return TRUE if there is no pending i/o */ +@return number of pending i/o operations */ UNIV_INTERN -ibool -buf_pool_check_no_pending_io(void); -/*==============================*/ +ulint +buf_pool_check_num_pending_io(void); +/*===============================*/ /*********************************************************************//** Invalidates the file pages in the buffer pool when an archive recovery is completed. All the file pages buffered must be in a replaceable state when diff --git a/include/buf0buf.ic b/include/buf0buf.ic index 55d89b66375..66006d366c6 100644 --- a/include/buf0buf.ic +++ b/include/buf0buf.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -1026,19 +1026,6 @@ buf_block_buf_fix_inc_func( block->page.buf_fix_count++; } -#ifdef UNIV_SYNC_DEBUG -/** Increments the bufferfix count. -@param b in/out: block to bufferfix -@param f in: file name where requested -@param l in: line number where requested */ -# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b) -#else /* UNIV_SYNC_DEBUG */ -/** Increments the bufferfix count. -@param b in/out: block to bufferfix -@param f in: file name where requested -@param l in: line number where requested */ -# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b) -#endif /* UNIV_SYNC_DEBUG */ /*******************************************************************//** Decrements the bufferfix count. */ @@ -1295,7 +1282,7 @@ buf_block_dbg_add_level( where we have acquired latch */ ulint level) /*!< in: latching order level */ { - sync_thread_add_level(&block->lock, level); + sync_thread_add_level(&block->lock, level, FALSE); } #endif /* UNIV_SYNC_DEBUG */ /********************************************************************//** diff --git a/include/buf0lru.h b/include/buf0lru.h index 700136ec488..c3672a65ed7 100644 --- a/include/buf0lru.h +++ b/include/buf0lru.h @@ -64,15 +64,14 @@ These are low-level functions #define BUF_LRU_FREE_SEARCH_LEN(b) (5 + 2 * BUF_READ_AHEAD_AREA(b)) /******************************************************************//** -Invalidates all pages belonging to a given tablespace when we are deleting -the data file(s) of that tablespace. A PROBLEM: if readahead is being started, -what guarantees that it will not try to read in pages after this operation has -completed? */ +Removes all pages belonging to a given tablespace. */ UNIV_INTERN void -buf_LRU_invalidate_tablespace( +buf_LRU_flush_or_remove_pages( /*==========================*/ - ulint id); /*!< in: space id */ + ulint id, /*!< in: space id */ + enum buf_remove_t buf_remove);/*!< in: remove or flush + strategy */ /******************************************************************//** */ diff --git a/include/buf0types.h b/include/buf0types.h index d140936a886..a6e947dc21a 100644 --- a/include/buf0types.h +++ b/include/buf0types.h @@ -63,6 +63,15 @@ enum buf_io_fix { the flush_list */ }; +/** Algorithm to remove the pages for a tablespace from the buffer pool. +@See buf_LRU_flush_or_remove_pages(). */ +enum buf_remove_t { + BUF_REMOVE_ALL_NO_WRITE, /*!< Remove all pages from the buffer + pool, don't write or sync to disk */ + BUF_REMOVE_FLUSH_NO_WRITE /*!< Remove only, from the flush list, + don't write or sync to disk */ +}; + /** Parameters of binary buddy system for compressed pages (buf0buddy.h) */ /* @{ */ #define BUF_BUDDY_LOW_SHIFT PAGE_ZIP_MIN_SIZE_SHIFT diff --git a/include/data0data.h b/include/data0data.h index f7bdd29ed90..6d3c2988fdc 100644 --- a/include/data0data.h +++ b/include/data0data.h @@ -231,6 +231,26 @@ dtuple_set_n_fields_cmp( dtuple_t* tuple, /*!< in: tuple */ ulint n_fields_cmp); /*!< in: number of fields used in comparisons in rem0cmp.* */ + +/* Estimate the number of bytes that are going to be allocated when +creating a new dtuple_t object */ +#define DTUPLE_EST_ALLOC(n_fields) \ + (sizeof(dtuple_t) + (n_fields) * sizeof(dfield_t)) + +/**********************************************************//** +Creates a data tuple from an already allocated chunk of memory. +The size of the chunk must be at least DTUPLE_EST_ALLOC(n_fields). +The default value for number of fields used in record comparisons +for this tuple is n_fields. +@return created tuple (inside buf) */ +UNIV_INLINE +dtuple_t* +dtuple_create_from_mem( +/*===================*/ + void* buf, /*!< in, out: buffer to use */ + ulint buf_size, /*!< in: buffer size */ + ulint n_fields); /*!< in: number of fields */ + /**********************************************************//** Creates a data tuple to a memory heap. The default value for number of fields used in record comparisons for this tuple is n_fields. @@ -240,7 +260,8 @@ dtuple_t* dtuple_create( /*==========*/ mem_heap_t* heap, /*!< in: memory heap where the tuple - is created */ + is created, DTUPLE_EST_ALLOC(n_fields) + bytes will be allocated from this heap */ ulint n_fields); /*!< in: number of fields */ /**********************************************************//** diff --git a/include/data0data.ic b/include/data0data.ic index 5c0f8039c80..205fa397987 100644 --- a/include/data0data.ic +++ b/include/data0data.ic @@ -348,23 +348,25 @@ dtuple_get_nth_field( #endif /* UNIV_DEBUG */ /**********************************************************//** -Creates a data tuple to a memory heap. The default value for number -of fields used in record comparisons for this tuple is n_fields. -@return own: created tuple */ +Creates a data tuple from an already allocated chunk of memory. +The size of the chunk must be at least DTUPLE_EST_ALLOC(n_fields). +The default value for number of fields used in record comparisons +for this tuple is n_fields. +@return created tuple (inside buf) */ UNIV_INLINE dtuple_t* -dtuple_create( -/*==========*/ - mem_heap_t* heap, /*!< in: memory heap where the tuple - is created */ - ulint n_fields) /*!< in: number of fields */ +dtuple_create_from_mem( +/*===================*/ + void* buf, /*!< in, out: buffer to use */ + ulint buf_size, /*!< in: buffer size */ + ulint n_fields) /*!< in: number of fields */ { dtuple_t* tuple; - ut_ad(heap); + ut_ad(buf != NULL); + ut_a(buf_size >= DTUPLE_EST_ALLOC(n_fields)); - tuple = (dtuple_t*) mem_heap_alloc(heap, sizeof(dtuple_t) - + n_fields * sizeof(dfield_t)); + tuple = (dtuple_t*) buf; tuple->info_bits = 0; tuple->n_fields = n_fields; tuple->n_fields_cmp = n_fields; @@ -386,9 +388,38 @@ dtuple_create( dfield_get_type(field)->mtype = DATA_ERROR; } } +#endif + return(tuple); +} + +/**********************************************************//** +Creates a data tuple to a memory heap. The default value for number +of fields used in record comparisons for this tuple is n_fields. +@return own: created tuple */ +UNIV_INLINE +dtuple_t* +dtuple_create( +/*==========*/ + mem_heap_t* heap, /*!< in: memory heap where the tuple + is created, DTUPLE_EST_ALLOC(n_fields) + bytes will be allocated from this heap */ + ulint n_fields) /*!< in: number of fields */ +{ + void* buf; + ulint buf_size; + dtuple_t* tuple; + + ut_ad(heap); + + buf_size = DTUPLE_EST_ALLOC(n_fields); + buf = mem_heap_alloc(heap, buf_size); + tuple = dtuple_create_from_mem(buf, buf_size, n_fields); + +#ifdef UNIV_DEBUG UNIV_MEM_INVALID(tuple->fields, n_fields * sizeof *tuple->fields); #endif + return(tuple); } diff --git a/include/db0err.h b/include/db0err.h index e0952f0709d..95ccef16be0 100644 --- a/include/db0err.h +++ b/include/db0err.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -112,6 +112,8 @@ enum db_err { limit */ DB_INDEX_CORRUPT, /* we have corrupted index */ DB_UNDO_RECORD_TOO_BIG, /* the undo log record is too big */ + DB_TABLE_IN_FK_CHECK, /* table is being used in foreign + key check */ /* The following are partial failure codes */ DB_FAIL = 1000, diff --git a/include/dict0boot.h b/include/dict0boot.h index a817775c93c..9905217ccf7 100644 --- a/include/dict0boot.h +++ b/include/dict0boot.h @@ -94,6 +94,26 @@ void dict_create(void); /*=============*/ +/*****************************************************************//** +Verifies the SYS_STATS table by scanning its clustered index. This +function may only be called at InnoDB startup time. + +@return TRUE if SYS_STATS was verified successfully */ +UNIV_INTERN +ibool +dict_verify_xtradb_sys_stats(void); +/*==============================*/ + +/*****************************************************************//** +Discard the existing dictionary cache SYS_STATS information, create and +add it there anew. Does not touch the old SYS_STATS tablespace page +under the assumption that they are corrupted or overwritten for other +purposes. */ +UNIV_INTERN +void +dict_recreate_xtradb_sys_stats(void); +/*================================*/ + /* Space id and page no where the dictionary header resides */ #define DICT_HDR_SPACE 0 /* the SYSTEM tablespace */ diff --git a/include/dict0dict.h b/include/dict0dict.h index fb5285fae0b..6ce1aed17b7 100644 --- a/include/dict0dict.h +++ b/include/dict0dict.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -1087,14 +1087,6 @@ dict_index_get_page( /*================*/ const dict_index_t* tree); /*!< in: index */ /*********************************************************************//** -Sets the page number of the root of index tree. */ -UNIV_INLINE -void -dict_index_set_page( -/*================*/ - dict_index_t* index, /*!< in/out: index */ - ulint page); /*!< in: page number */ -/*********************************************************************//** Gets the read-write lock of the index tree. @return read-write lock */ UNIV_INLINE diff --git a/include/dict0dict.ic b/include/dict0dict.ic index ecb5ec0a408..1c09722e8d7 100644 --- a/include/dict0dict.ic +++ b/include/dict0dict.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -761,21 +761,6 @@ dict_index_get_page( return(index->page); } -/*********************************************************************//** -Sets the page number of the root of index tree. */ -UNIV_INLINE -void -dict_index_set_page( -/*================*/ - dict_index_t* index, /*!< in/out: index */ - ulint page) /*!< in: page number */ -{ - ut_ad(index); - ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); - - index->page = page; -} - /*********************************************************************//** Gets the read-write lock of the index tree. @return read-write lock */ diff --git a/include/dict0mem.h b/include/dict0mem.h index 4701fcd87f9..54593a0b9c7 100644 --- a/include/dict0mem.h +++ b/include/dict0mem.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -396,7 +396,9 @@ struct dict_index_struct{ unsigned to_be_dropped:1; /*!< TRUE if this index is marked to be dropped in ha_innobase::prepare_drop_index(), - otherwise FALSE */ + otherwise FALSE. Protected by + dict_sys->mutex, dict_operation_lock and + index->lock.*/ dict_field_t* fields; /*!< array of field descriptions */ #ifndef UNIV_HOTBACKUP UT_LIST_NODE_T(dict_index_t) diff --git a/include/fil0fil.h b/include/fil0fil.h index 92fdca0db1b..19bf5960ae4 100644 --- a/include/fil0fil.h +++ b/include/fil0fil.h @@ -348,20 +348,19 @@ fil_read_first_page( ib_uint64_t* max_flushed_lsn); /*!< out: max of flushed lsn values in data files */ /*******************************************************************//** -Increments the count of pending insert buffer page merges, if space is not -being deleted. -@return TRUE if being deleted, and ibuf merges should be skipped */ +Increments the count of pending operation, if space is not being deleted. +@return TRUE if being deleted, and operation should be skipped */ UNIV_INTERN ibool -fil_inc_pending_ibuf_merges( -/*========================*/ +fil_inc_pending_ops( +/*================*/ ulint id); /*!< in: space id */ /*******************************************************************//** -Decrements the count of pending insert buffer page merges. */ +Decrements the count of pending operations. */ UNIV_INTERN void -fil_decr_pending_ibuf_merges( -/*=========================*/ +fil_decr_pending_ops( +/*=================*/ ulint id); /*!< in: space id */ #endif /* !UNIV_HOTBACKUP */ /*******************************************************************//** @@ -400,7 +399,9 @@ UNIV_INTERN ibool fil_delete_tablespace( /*==================*/ - ulint id); /*!< in: space id */ + ulint id, /*!< in: space id */ + ibool evict_all); /*!< in: TRUE if we want all pages + evicted from LRU. */ #ifndef UNIV_HOTBACKUP /*******************************************************************//** Discards a single-table tablespace. The tablespace must be cached in the diff --git a/include/fsp0fsp.h b/include/fsp0fsp.h index d5e235aa870..f07e3decc66 100644 --- a/include/fsp0fsp.h +++ b/include/fsp0fsp.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -260,30 +260,33 @@ fseg_n_reserved_pages( Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation. -@return the allocated page offset FIL_NULL if no page could be allocated */ -UNIV_INTERN -ulint -fseg_alloc_free_page( -/*=================*/ - fseg_header_t* seg_header, /*!< in: segment header */ - ulint hint, /*!< in: hint of which page would be desirable */ - byte direction, /*!< in: if the new page is needed because +@param[in/out] seg_header segment header +@param[in] hint hint of which page would be desirable +@param[in] direction if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, - FSP_UP, FSP_NO_DIR */ - mtr_t* mtr); /*!< in: mtr handle */ + FSP_UP, FSP_NO_DIR +@param[in/out] mtr mini-transaction +@return X-latched block, or NULL if no page could be allocated */ +#define fseg_alloc_free_page(seg_header, hint, direction, mtr) \ + fseg_alloc_free_page_general(seg_header, hint, direction, \ + FALSE, mtr, mtr) /**********************************************************************//** Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation. -@return allocated page offset, FIL_NULL if no page could be allocated */ +@retval NULL if no page could be allocated +@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded +(init_mtr == mtr, or the page was not previously freed in mtr) +@retval block (not allocated or initialized) otherwise */ UNIV_INTERN -ulint +buf_block_t* fseg_alloc_free_page_general( /*=========================*/ - fseg_header_t* seg_header,/*!< in: segment header */ - ulint hint, /*!< in: hint of which page would be desirable */ + fseg_header_t* seg_header,/*!< in/out: segment header */ + ulint hint, /*!< in: hint of which page would be + desirable */ byte direction,/*!< in: if the new page is needed because of an index page split, and records are inserted there in order, into which @@ -294,7 +297,12 @@ fseg_alloc_free_page_general( with fsp_reserve_free_extents, then there is no need to do the check for this individual page */ - mtr_t* mtr); /*!< in: mtr handle */ + mtr_t* mtr, /*!< in/out: mini-transaction */ + mtr_t* init_mtr)/*!< in/out: mtr or another mini-transaction + in which the page should be initialized. + If init_mtr!=mtr, but the page is already + latched in mtr, do not initialize the page. */ + __attribute__((warn_unused_result, nonnull)); /**********************************************************************//** Reserves free pages from a tablespace. All mini-transactions which may use several pages from the tablespace should call this function beforehand diff --git a/include/log0log.h b/include/log0log.h index e0bffe6f725..c39c7b0c126 100644 --- a/include/log0log.h +++ b/include/log0log.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2010, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ diff --git a/include/mem0mem.ic b/include/mem0mem.ic index d214c3fe6c9..c70615e1ca9 100644 --- a/include/mem0mem.ic +++ b/include/mem0mem.ic @@ -208,10 +208,6 @@ mem_heap_alloc( caller */ buf = (byte*)buf + MEM_FIELD_HEADER_SIZE; -#endif -#ifdef UNIV_SET_MEM_TO_ZERO - UNIV_MEM_ALLOC(buf, n); - memset(buf, '\0', n); #endif UNIV_MEM_ALLOC(buf, n); return(buf); diff --git a/include/mtr0log.ic b/include/mtr0log.ic index fa9ac014f4e..3ed1183f5c0 100644 --- a/include/mtr0log.ic +++ b/include/mtr0log.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -217,6 +217,7 @@ mlog_write_initial_log_record_fast( "Please post a bug report to " "bugs.mysql.com.\n", type, offset, space); + ut_ad(0); } } diff --git a/include/mtr0mtr.h b/include/mtr0mtr.h index 7f608546cc2..46f1ff9310c 100644 --- a/include/mtr0mtr.h +++ b/include/mtr0mtr.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -50,7 +50,9 @@ first 3 values must be RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */ #define MTR_MEMO_PAGE_S_FIX RW_S_LATCH #define MTR_MEMO_PAGE_X_FIX RW_X_LATCH #define MTR_MEMO_BUF_FIX RW_NO_LATCH -#define MTR_MEMO_MODIFY 54 +#ifdef UNIV_DEBUG +# define MTR_MEMO_MODIFY 54 +#endif /* UNIV_DEBUG */ #define MTR_MEMO_S_LOCK 55 #define MTR_MEMO_X_LOCK 56 @@ -376,6 +378,9 @@ struct mtr_struct{ ulint n_log_recs; /* count of how many page initial log records have been written to the mtr log */ + ulint n_freed_pages; + /* number of pages that have been freed in + this mini-transaction */ ulint log_mode; /* specifies which operations should be logged; default value MTR_LOG_ALL */ ib_uint64_t start_lsn;/* start lsn of the possible log entry for diff --git a/include/mtr0mtr.ic b/include/mtr0mtr.ic index 1db4a4bd735..a03a0271535 100644 --- a/include/mtr0mtr.ic +++ b/include/mtr0mtr.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -46,6 +46,7 @@ mtr_start( mtr->modifications = FALSE; mtr->inside_ibuf = FALSE; mtr->n_log_recs = 0; + mtr->n_freed_pages = 0; ut_d(mtr->state = MTR_ACTIVE); ut_d(mtr->magic_n = MTR_MAGIC_N); @@ -248,7 +249,7 @@ mtr_s_lock_func( ut_ad(mtr); ut_ad(lock); - rw_lock_s_lock_func(lock, 0, file, line); + rw_lock_s_lock_inline(lock, 0, file, line); mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK); } @@ -267,7 +268,7 @@ mtr_x_lock_func( ut_ad(mtr); ut_ad(lock); - rw_lock_x_lock_func(lock, 0, file, line); + rw_lock_x_lock_inline(lock, 0, file, line); mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK); } diff --git a/include/page0page.h b/include/page0page.h index 616939586e0..b4755dce61d 100644 --- a/include/page0page.h +++ b/include/page0page.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -281,16 +281,42 @@ page_get_supremum_offset( const page_t* page); /*!< in: page which must have record(s) */ #define page_get_infimum_rec(page) ((page) + page_get_infimum_offset(page)) #define page_get_supremum_rec(page) ((page) + page_get_supremum_offset(page)) + /************************************************************//** -Returns the middle record of record list. If there are an even number -of records in the list, returns the first record of upper half-list. -@return middle record */ +Returns the nth record of the record list. +This is the inverse function of page_rec_get_n_recs_before(). +@return nth record */ UNIV_INTERN +const rec_t* +page_rec_get_nth_const( +/*===================*/ + const page_t* page, /*!< in: page */ + ulint nth) /*!< in: nth record */ + __attribute__((nonnull, warn_unused_result)); +/************************************************************//** +Returns the nth record of the record list. +This is the inverse function of page_rec_get_n_recs_before(). +@return nth record */ +UNIV_INLINE +rec_t* +page_rec_get_nth( +/*=============*/ + page_t* page, /*< in: page */ + ulint nth) /*!< in: nth record */ + __attribute__((nonnull, warn_unused_result)); + +#ifndef UNIV_HOTBACKUP +/************************************************************//** +Returns the middle record of the records on the page. If there is an +even number of records in the list, returns the first record of the +upper half-list. +@return middle record */ +UNIV_INLINE rec_t* page_get_middle_rec( /*================*/ - page_t* page); /*!< in: page */ -#ifndef UNIV_HOTBACKUP + page_t* page) /*!< in: page */ + __attribute__((nonnull, warn_unused_result)); /*************************************************************//** Compares a data tuple to a physical record. Differs from the function cmp_dtuple_rec_with_match in the way that the record must reside on an @@ -345,6 +371,7 @@ page_get_n_recs( /***************************************************************//** Returns the number of records before the given record in chain. The number includes infimum and supremum records. +This is the inverse function of page_rec_get_nth(). @return number of records */ UNIV_INTERN ulint diff --git a/include/page0page.ic b/include/page0page.ic index 1bac2fb53fb..c1b99b8f187 100644 --- a/include/page0page.ic +++ b/include/page0page.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -422,7 +422,37 @@ page_rec_is_infimum( return(page_rec_is_infimum_low(page_offset(rec))); } +/************************************************************//** +Returns the nth record of the record list. +This is the inverse function of page_rec_get_n_recs_before(). +@return nth record */ +UNIV_INLINE +rec_t* +page_rec_get_nth( +/*=============*/ + page_t* page, /*!< in: page */ + ulint nth) /*!< in: nth record */ +{ + return((rec_t*) page_rec_get_nth_const(page, nth)); +} + #ifndef UNIV_HOTBACKUP +/************************************************************//** +Returns the middle record of the records on the page. If there is an +even number of records in the list, returns the first record of the +upper half-list. +@return middle record */ +UNIV_INLINE +rec_t* +page_get_middle_rec( +/*================*/ + page_t* page) /*!< in: page */ +{ + ulint middle = (page_get_n_recs(page) + PAGE_HEAP_NO_USER_LOW) / 2; + + return(page_rec_get_nth(page, middle)); +} + /*************************************************************//** Compares a data tuple to a physical record. Differs from the function cmp_dtuple_rec_with_match in the way that the record must reside on an @@ -713,7 +743,7 @@ page_rec_get_next_low( (void*) rec, (ulong) page_get_space_id(page), (ulong) page_get_page_no(page)); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); ut_error; } diff --git a/include/row0mysql.h b/include/row0mysql.h index 652adea167f..5b1d130d480 100644 --- a/include/row0mysql.h +++ b/include/row0mysql.h @@ -168,7 +168,9 @@ UNIV_INTERN row_prebuilt_t* row_create_prebuilt( /*================*/ - dict_table_t* table); /*!< in: Innobase table handle */ + dict_table_t* table, /*!< in: Innobase table handle */ + ulint mysql_row_len); /*!< in: length in bytes of a row in + the MySQL format */ /********************************************************************//** Free a prebuilt struct for a MySQL table handle. */ UNIV_INTERN @@ -688,9 +690,9 @@ struct row_prebuilt_struct { in inserts */ que_fork_t* upd_graph; /*!< Innobase SQL query graph used in updates or deletes */ - btr_pcur_t* pcur; /*!< persistent cursor used in selects + btr_pcur_t pcur; /*!< persistent cursor used in selects and updates */ - btr_pcur_t* clust_pcur; /*!< persistent cursor used in + btr_pcur_t clust_pcur; /*!< persistent cursor used in some selects and updates */ que_fork_t* sel_graph; /*!< dummy query graph used in selects */ diff --git a/include/row0sel.h b/include/row0sel.h index 8544b9d08ba..1c4ea6f7244 100644 --- a/include/row0sel.h +++ b/include/row0sel.h @@ -128,7 +128,12 @@ row_sel_convert_mysql_key_to_innobase( in the tuple is already according to index! */ byte* buf, /*!< in: buffer to use in field - conversions */ + conversions; NOTE that dtuple->data + may end up pointing inside buf so + do not discard that buffer while + the tuple is being used. See + row_mysql_store_col_in_innobase_format() + in the case of DATA_INT */ ulint buf_len, /*!< in: buffer length */ dict_index_t* index, /*!< in: index of the key value */ const byte* key_ptr, /*!< in: MySQL key value */ diff --git a/include/srv0srv.h b/include/srv0srv.h index 248e1efff00..9e860ef285c 100644 --- a/include/srv0srv.h +++ b/include/srv0srv.h @@ -226,6 +226,9 @@ extern unsigned long long srv_stats_sample_pages; extern ulint srv_stats_auto_update; extern ulint srv_stats_update_need_lock; extern ibool srv_use_sys_stats_table; +#ifdef UNIV_DEBUG +extern ulong srv_sys_stats_root_page; +#endif extern ibool srv_use_doublewrite_buf; extern ibool srv_use_checksums; @@ -285,9 +288,6 @@ extern ibool srv_print_lock_waits; extern ibool srv_print_buf_io; extern ibool srv_print_log_io; extern ibool srv_print_latch_waits; - -extern ulint srv_flush_checkpoint_debug; - #else /* UNIV_DEBUG */ # define srv_print_thread_releases FALSE # define srv_print_lock_waits FALSE @@ -734,12 +734,14 @@ srv_que_task_enqueue_low( que_thr_t* thr); /*!< in: query thread */ /**********************************************************************//** -Check whether any background thread is active. -@return FALSE if all are are suspended or have exited. */ +Check whether any background thread is active. If so, return the thread +type. +@return ULINT_UNDEFINED if all are are suspended or have exited, thread +type if any are still active. */ UNIV_INTERN -ibool -srv_is_any_background_thread_active(void); -/*======================================*/ +ulint +srv_get_active_thread_type(void); +/*============================*/ /** Status variables to be passed to MySQL */ struct export_var_struct{ diff --git a/include/sync0rw.h b/include/sync0rw.h index 971099c91f5..6159d8d0c81 100644 --- a/include/sync0rw.h +++ b/include/sync0rw.h @@ -155,6 +155,9 @@ unlocking, not the corresponding function. */ # define rw_lock_s_lock(M) \ rw_lock_s_lock_func((M), 0, __FILE__, __LINE__) +# define rw_lock_s_lock_inline(M, P, F, L) \ + rw_lock_s_lock_func((M), (P), (F), (L)) + # define rw_lock_s_lock_gen(M, P) \ rw_lock_s_lock_func((M), (P), __FILE__, __LINE__) @@ -171,12 +174,18 @@ unlocking, not the corresponding function. */ # define rw_lock_x_lock(M) \ rw_lock_x_lock_func((M), 0, __FILE__, __LINE__) +# define rw_lock_x_lock_inline(M, P, F, L) \ + rw_lock_x_lock_func((M), (P), (F), (L)) + # define rw_lock_x_lock_gen(M, P) \ rw_lock_x_lock_func((M), (P), __FILE__, __LINE__) # define rw_lock_x_lock_nowait(M) \ rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__) +# define rw_lock_x_lock_func_nowait_inline(M, F, L) \ + rw_lock_x_lock_func_nowait((M), (F), (L)) + # ifdef UNIV_SYNC_DEBUG # define rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(P, L) # else @@ -208,6 +217,9 @@ unlocking, not the corresponding function. */ # define rw_lock_s_lock(M) \ pfs_rw_lock_s_lock_func((M), 0, __FILE__, __LINE__) +# define rw_lock_s_lock_inline(M, P, F, L) \ + pfs_rw_lock_s_lock_func((M), (P), (F), (L)) + # define rw_lock_s_lock_gen(M, P) \ pfs_rw_lock_s_lock_func((M), (P), __FILE__, __LINE__) @@ -223,12 +235,18 @@ unlocking, not the corresponding function. */ # define rw_lock_x_lock(M) \ pfs_rw_lock_x_lock_func((M), 0, __FILE__, __LINE__) +# define rw_lock_x_lock_inline(M, P, F, L) \ + pfs_rw_lock_x_lock_func((M), (P), (F), (L)) + # define rw_lock_x_lock_gen(M, P) \ pfs_rw_lock_x_lock_func((M), (P), __FILE__, __LINE__) # define rw_lock_x_lock_nowait(M) \ pfs_rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__) +# define rw_lock_x_lock_func_nowait_inline(M, F, L) \ + pfs_rw_lock_x_lock_func_nowait((M), (F), (L)) + # ifdef UNIV_SYNC_DEBUG # define rw_lock_x_unlock_gen(L, P) pfs_rw_lock_x_unlock_func(P, L) # else diff --git a/include/sync0rw.ic b/include/sync0rw.ic index 3eaa6172631..73e1f880aad 100644 --- a/include/sync0rw.ic +++ b/include/sync0rw.ic @@ -90,7 +90,7 @@ rw_lock_set_waiter_flag( rw_lock_t* lock) /*!< in/out: rw-lock */ { #ifdef INNODB_RW_LOCKS_USE_ATOMICS - os_compare_and_swap_ulint(&lock->waiters, 0, 1); + (void) os_compare_and_swap_ulint(&lock->waiters, 0, 1); #else /* INNODB_RW_LOCKS_USE_ATOMICS */ lock->waiters = 1; #endif /* INNODB_RW_LOCKS_USE_ATOMICS */ @@ -107,7 +107,7 @@ rw_lock_reset_waiter_flag( rw_lock_t* lock) /*!< in/out: rw-lock */ { #ifdef INNODB_RW_LOCKS_USE_ATOMICS - os_compare_and_swap_ulint(&lock->waiters, 1, 0); + (void) os_compare_and_swap_ulint(&lock->waiters, 1, 0); #else /* INNODB_RW_LOCKS_USE_ATOMICS */ lock->waiters = 0; #endif /* INNODB_RW_LOCKS_USE_ATOMICS */ @@ -564,8 +564,6 @@ rw_lock_x_unlock_func( if (lock->lock_word == 0) { /* Last caller in a possible recursive chain. */ lock->recursive = FALSE; - UNIV_MEM_INVALID(&lock->writer_thread, - sizeof lock->writer_thread); } #ifdef UNIV_SYNC_DEBUG @@ -610,8 +608,6 @@ rw_lock_x_unlock_direct( if (lock->lock_word == 0) { lock->recursive = FALSE; - UNIV_MEM_INVALID(&lock->writer_thread, - sizeof lock->writer_thread); } lock->lock_word += X_LOCK_DECR; diff --git a/include/sync0sync.h b/include/sync0sync.h index 1437e797f6f..33c95a94804 100644 --- a/include/sync0sync.h +++ b/include/sync0sync.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -404,8 +404,10 @@ void sync_thread_add_level( /*==================*/ void* latch, /*!< in: pointer to a mutex or an rw-lock */ - ulint level); /*!< in: level in the latching order; if + ulint level, /*!< in: level in the latching order; if SYNC_LEVEL_VARYING, nothing is done */ + ibool relock) /*!< in: TRUE if re-entering an x-lock */ + __attribute__((nonnull)); /******************************************************************//** Removes a latch from the thread level array if it is found there. @return TRUE if found in the array; it is no error if the latch is diff --git a/include/trx0purge.h b/include/trx0purge.h index 0b83a76cab7..2bd9e64476b 100644 --- a/include/trx0purge.h +++ b/include/trx0purge.h @@ -143,9 +143,9 @@ struct trx_purge_struct{ obtaining an s-latch here. */ read_view_t* view; /*!< The purge will not remove undo logs which are >= this view (purge view) */ - ulint n_pages_handled;/*!< Approximate number of undo log + ulonglong n_pages_handled;/*!< Approximate number of undo log pages processed in purge */ - ulint handle_limit; /*!< Target of how many pages to get + ulonglong handle_limit; /*!< Target of how many pages to get processed in the current purge */ /*------------------------------*/ /* The following two fields form the 'purge pointer' which advances diff --git a/include/trx0rec.ic b/include/trx0rec.ic index f0b3276ed44..4fc5a7147f9 100644 --- a/include/trx0rec.ic +++ b/include/trx0rec.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -107,6 +107,7 @@ trx_undo_rec_copy( len = mach_read_from_2(undo_rec) - ut_align_offset(undo_rec, UNIV_PAGE_SIZE); + ut_ad(len < UNIV_PAGE_SIZE); return(mem_heap_dup(heap, undo_rec, len)); } #endif /* !UNIV_HOTBACKUP */ diff --git a/include/trx0rseg.ic b/include/trx0rseg.ic index daffa92fc7d..5e8d2b41120 100644 --- a/include/trx0rseg.ic +++ b/include/trx0rseg.ic @@ -25,6 +25,7 @@ Created 3/26/1996 Heikki Tuuri #include "srv0srv.h" #include "mtr0log.h" +#include "trx0sys.h" /******************************************************************//** Gets a rollback segment header. @@ -131,7 +132,13 @@ trx_rsegf_undo_find_free( ulint i; ulint page_no; - for (i = 0; i < TRX_RSEG_N_SLOTS; i++) { + for (i = 0; +#ifndef UNIV_DEBUG + i < TRX_RSEG_N_SLOTS; +#else + i < (trx_rseg_n_slots_debug ? trx_rseg_n_slots_debug : TRX_RSEG_N_SLOTS); +#endif + i++) { page_no = trx_rsegf_get_nth_undo(rsegf, i, mtr); diff --git a/include/trx0sys.h b/include/trx0sys.h index 495ce0e1184..976cb31563f 100644 --- a/include/trx0sys.h +++ b/include/trx0sys.h @@ -249,6 +249,12 @@ trx_id_t trx_sys_get_new_trx_id(void); /*========================*/ #endif /* !UNIV_HOTBACKUP */ + +#ifdef UNIV_DEBUG +/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ +extern uint trx_rseg_n_slots_debug; +#endif + /*****************************************************************//** Writes a trx id to an index page. In case that the id size changes in some future version, this function should be used instead of diff --git a/include/trx0undo.h b/include/trx0undo.h index 50aa6d0ac09..4a1e40af505 100644 --- a/include/trx0undo.h +++ b/include/trx0undo.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -194,16 +194,17 @@ trx_undo_get_first_rec( mtr_t* mtr); /*!< in: mtr */ /********************************************************************//** Tries to add a page to the undo log segment where the undo log is placed. -@return page number if success, else FIL_NULL */ +@return X-latched block if success, else NULL */ UNIV_INTERN -ulint +buf_block_t* trx_undo_add_page( /*==============*/ trx_t* trx, /*!< in: transaction */ trx_undo_t* undo, /*!< in: undo log memory object */ - mtr_t* mtr); /*!< in: mtr which does not have a latch to any + mtr_t* mtr) /*!< in: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex */ + __attribute__((nonnull, warn_unused_result)); /********************************************************************//** Frees the last undo log page. The caller must hold the rollback segment mutex. */ diff --git a/include/univ.i b/include/univ.i index 195c09c8163..003f61ceb95 100644 --- a/include/univ.i +++ b/include/univ.i @@ -160,14 +160,6 @@ resolved */ /* DEBUG VERSION CONTROL ===================== */ -/* The following flag will make InnoDB to initialize -all memory it allocates to zero. It hides Purify -warnings about reading unallocated memory unless -memory is read outside the allocated blocks. */ -/* -#define UNIV_INIT_MEM_TO_ZERO -*/ - /* When this macro is defined then additional test functions will be compiled. These functions live at the end of each relevant source file and have "test_" prefix. These functions are not called from anywhere in @@ -237,15 +229,6 @@ operations (very slow); also UNIV_DEBUG must be defined */ #define UNIV_BTR_DEBUG /* check B-tree links */ #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ -#ifdef HAVE_purify -/* The following sets all new allocated memory to zero before use: -this can be used to eliminate unnecessary Purify warnings, but note that -it also masks many bugs Purify could detect. For detailed Purify analysis it -is best to remove the define below and look through the warnings one -by one. */ -#define UNIV_SET_MEM_TO_ZERO -#endif - /* #define UNIV_SQL_DEBUG #define UNIV_LOG_DEBUG @@ -330,11 +313,17 @@ management to ensure correct alignment for doubles etc. */ /* Maximum number of parallel threads in a parallelized operation */ #define UNIV_MAX_PARALLELISM 32 -/* The maximum length of a table name. This is the MySQL limit and is -defined in mysql_com.h like NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN, the -number does not include a terminating '\0'. InnoDB probably can handle -longer names internally */ -#define MAX_TABLE_NAME_LEN 192 +/** This is the "mbmaxlen" for my_charset_filename (defined in +strings/ctype-utf8.c), which is used to encode File and Database names. */ +#define FILENAME_CHARSET_MAXNAMLEN 5 + +/** The maximum length of an encode table name in bytes. The max +table and database names are NAME_CHAR_LEN (64) characters. After the +encoding, the max length would be NAME_CHAR_LEN (64) * +FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a +terminating '\0'. InnoDB can handle longer names internally */ +#define MAX_TABLE_NAME_LEN 320 + /* The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is the MySQL's NAME_LEN, see check_and_convert_db_name(). */ diff --git a/include/ut0mem.h b/include/ut0mem.h index faf6f242883..39f5f20dc6d 100644 --- a/include/ut0mem.h +++ b/include/ut0mem.h @@ -78,40 +78,19 @@ ut_mem_init(void); /*=============*/ /**********************************************************************//** -Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is -defined and set_to_zero is TRUE. +Allocates memory. @return own: allocated memory */ UNIV_INTERN void* ut_malloc_low( /*==========*/ ulint n, /*!< in: number of bytes to allocate */ - ibool set_to_zero, /*!< in: TRUE if allocated memory - should be set to zero if - UNIV_SET_MEM_TO_ZERO is defined */ - ibool assert_on_error); /*!< in: if TRUE, we crash mysqld if + ibool assert_on_error) /*!< in: if TRUE, we crash mysqld if the memory cannot be allocated */ + __attribute__((malloc)); /**********************************************************************//** -Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is -defined. -@return own: allocated memory */ -UNIV_INTERN -void* -ut_malloc( -/*======*/ - ulint n); /*!< in: number of bytes to allocate */ -#ifndef UNIV_HOTBACKUP -/**********************************************************************//** -Tests if malloc of n bytes would succeed. ut_malloc() asserts if memory runs -out. It cannot be used if we want to return an error message. Prints to -stderr a message if fails. -@return TRUE if succeeded */ -UNIV_INTERN -ibool -ut_test_malloc( -/*===========*/ - ulint n); /*!< in: try to allocate this many bytes */ -#endif /* !UNIV_HOTBACKUP */ +Allocates memory. */ +#define ut_malloc(n) ut_malloc_low(n, TRUE) /**********************************************************************//** Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is a nop. */ diff --git a/include/ut0rnd.ic b/include/ut0rnd.ic index 2c8c959d804..60e213dd19f 100644 --- a/include/ut0rnd.ic +++ b/include/ut0rnd.ic @@ -114,7 +114,7 @@ ut_rnd_interval( rnd = ut_rnd_gen_ulint(); - return(low + (rnd % (high - low + 1))); + return(low + (rnd % (high - low))); } /*********************************************************//** diff --git a/lock/lock0lock.c b/lock/lock0lock.c index 5fce345d0fe..414d3ae2c49 100644 --- a/lock/lock0lock.c +++ b/lock/lock0lock.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -38,6 +38,7 @@ Created 5/7/1996 Heikki Tuuri #include "trx0purge.h" #include "dict0mem.h" #include "trx0sys.h" +#include "btr0btr.h" /* Restricts the length of search we will do in the waits-for graph of transactions */ @@ -1615,7 +1616,7 @@ lock_sec_rec_some_has_impl_off_kernel( if (!lock_check_trx_id_sanity(page_get_max_trx_id(page), rec, index, offsets, TRUE)) { - buf_page_print(page, 0); + buf_page_print(page, 0, 0); /* The page is corrupt: try to avoid a crash by returning NULL */ @@ -1691,7 +1692,7 @@ lock_rec_create( page_no = buf_block_get_page_no(block); page = block->frame; - ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table)); + btr_assert_not_corrupted(block, index); /* If rec is the supremum record, then we reset the gap and LOCK_REC_NOT_GAP bits, as all locks on the supremum are @@ -1799,6 +1800,7 @@ lock_rec_enqueue_waiting( "InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); } /* Enqueue the lock request that will wait to be granted */ @@ -3808,6 +3810,7 @@ lock_table_enqueue_waiting( "InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); } /* Enqueue the lock request that will wait to be granted */ @@ -4984,6 +4987,79 @@ function_exit: return(TRUE); } +/*********************************************************************//** +Validate record locks up to a limit. +@return lock at limit or NULL if no more locks in the hash bucket */ +static __attribute__((nonnull, warn_unused_result)) +const lock_t* +lock_rec_validate( +/*==============*/ + ulint start, /*!< in: lock_sys->rec_hash + bucket */ + ib_uint64_t* limit) /*!< in/out: upper limit of + (space, page_no) */ +{ + lock_t* lock; + ut_ad(mutex_own(&kernel_mutex)); + + for (lock = HASH_GET_FIRST(lock_sys->rec_hash, start); + lock != NULL; + lock = HASH_GET_NEXT(hash, lock)) { + + ib_uint64_t current; + + ut_a(trx_in_trx_list(lock->trx)); + ut_a(lock_get_type(lock) == LOCK_REC); + + current = ut_ull_create( + lock->un_member.rec_lock.space, + lock->un_member.rec_lock.page_no); + + if (current > *limit) { + *limit = current + 1; + return(lock); + } + } + + return(NULL); +} + +/*********************************************************************//** +Validate a record lock's block */ +static +void +lock_rec_block_validate( +/*====================*/ + ulint space, + ulint page_no) +{ + /* The lock and the block that it is referring to may be freed at + this point. We pass BUF_GET_POSSIBLY_FREED to skip a debug check. + If the lock exists in lock_rec_validate_page() we assert + !block->page.file_page_was_freed. */ + + mtr_t mtr; + buf_block_t* block; + + /* Make sure that the tablespace is not deleted while we are + trying to access the page. */ + if (!fil_inc_pending_ops(space)) { + mtr_start(&mtr); + block = buf_page_get_gen( + space, fil_space_get_zip_size(space), + page_no, RW_X_LATCH, NULL, + BUF_GET_POSSIBLY_FREED, + __FILE__, __LINE__, &mtr); + + buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK); + + ut_ad(lock_rec_validate_page(block)); + mtr_commit(&mtr); + + fil_decr_pending_ops(space); + } +} + /*********************************************************************//** Validates the lock system. @return TRUE if ok */ @@ -5016,60 +5092,21 @@ lock_validate(void) trx = UT_LIST_GET_NEXT(trx_list, trx); } - for (i = 0; i < hash_get_n_cells(lock_sys->rec_hash); i++) { - - ulint space; - ulint page_no; - ib_uint64_t limit = 0; - - for (;;) { - mtr_t mtr; - buf_block_t* block; - - lock = HASH_GET_FIRST(lock_sys->rec_hash, i); - - while (lock) { - ib_uint64_t space_page; - ut_a(trx_in_trx_list(lock->trx)); - - space = lock->un_member.rec_lock.space; - page_no = lock->un_member.rec_lock.page_no; - - space_page = ut_ull_create(space, page_no); + /* Iterate over all the record locks and validate the locks. We + don't want to hog the lock_sys_t::mutex and the trx_sys_t::mutex. + Release both mutexes during the validation check. */ - if (space_page >= limit) { - break; - } - - lock = HASH_GET_NEXT(hash, lock); - } + for (i = 0; i < hash_get_n_cells(lock_sys->rec_hash); i++) { + const lock_t* lock; + ib_uint64_t limit = 0; - if (!lock) { + while ((lock = lock_rec_validate(i, &limit)) != NULL) { - break; - } + ulint space = lock->un_member.rec_lock.space; + ulint page_no = lock->un_member.rec_lock.page_no; lock_mutex_exit_kernel(); - - /* The lock and the block that it is referring - to may be freed at this point. We pass - BUF_GET_POSSIBLY_FREED to skip a debug check. - If the lock exists in lock_rec_validate_page() - we assert !block->page.file_page_was_freed. */ - - mtr_start(&mtr); - block = buf_page_get_gen( - space, fil_space_get_zip_size(space), - page_no, RW_X_LATCH, NULL, - BUF_GET_POSSIBLY_FREED, - __FILE__, __LINE__, &mtr); - buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK); - - ut_ad(lock_rec_validate_page(block)); - mtr_commit(&mtr); - - limit++; - + lock_rec_block_validate(space, page_no); lock_mutex_enter_kernel(); } } diff --git a/log/log0log.c b/log/log0log.c index 8ba34ef8a83..002de967f82 100644 --- a/log/log0log.c +++ b/log/log0log.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2010, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -1691,13 +1691,10 @@ log_preflush_pool_modified_pages( recv_apply_hashed_log_recs(TRUE); } - retry: n_pages = buf_flush_list(ULINT_MAX, new_oldest); - if (sync && n_pages != 0) { - //buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST); - os_thread_sleep(100000); - goto retry; + if (sync) { + buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST); } if (n_pages == ULINT_UNDEFINED) { @@ -2019,13 +2016,6 @@ log_checkpoint( { ib_uint64_t oldest_lsn; -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug == 1) { - - return TRUE; - } -#endif - if (recv_recovery_is_on()) { recv_apply_hashed_log_recs(TRUE); } @@ -2117,11 +2107,7 @@ log_make_checkpoint_at( physical write will always be made to log files */ { -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug == 1) - return; -#endif -/* Preflush pages synchronously */ + /* Preflush pages synchronously */ while (!log_preflush_pool_modified_pages(lsn, TRUE)); @@ -2147,13 +2133,7 @@ log_checkpoint_margin(void) ibool checkpoint_sync; ibool do_checkpoint; ibool success; - -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug == 1) - return; -#endif - - loop: +loop: sync = FALSE; checkpoint_sync = FALSE; do_checkpoint = FALSE; @@ -2176,15 +2156,13 @@ log_checkpoint_margin(void) /* A flush is urgent: we have to do a synchronous preflush */ sync = TRUE; - advance = age - log->max_modified_age_sync; + advance = 2 * (age - log->max_modified_age_sync); } else if (age > log_max_modified_age_async()) { /* A flush is not urgent: we do an asynchronous preflush */ advance = age - log_max_modified_age_async(); - log->check_flush_or_checkpoint = FALSE; } else { advance = 0; - log->check_flush_or_checkpoint = FALSE; } checkpoint_age = log->lsn - log->last_checkpoint_lsn; @@ -2201,9 +2179,9 @@ log_checkpoint_margin(void) do_checkpoint = TRUE; - //log->check_flush_or_checkpoint = FALSE; + log->check_flush_or_checkpoint = FALSE; } else { - //log->check_flush_or_checkpoint = FALSE; + log->check_flush_or_checkpoint = FALSE; } mutex_exit(&(log->mutex)); @@ -2211,7 +2189,6 @@ log_checkpoint_margin(void) if (advance) { ib_uint64_t new_oldest = oldest_lsn + advance; -retry: success = log_preflush_pool_modified_pages(new_oldest, sync); /* If the flush succeeded, this thread has done its part @@ -2226,7 +2203,7 @@ retry: log->check_flush_or_checkpoint = TRUE; mutex_exit(&(log->mutex)); - goto retry; + goto loop; } } @@ -3104,11 +3081,7 @@ void log_check_margins(void) /*===================*/ { -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug == 1) - return; -#endif - loop: +loop: log_flush_margin(); log_checkpoint_margin(); @@ -3140,9 +3113,12 @@ void logs_empty_and_mark_files_at_shutdown(void) /*=======================================*/ { - ib_uint64_t lsn; - ulint arch_log_no; - ibool server_busy; + ib_uint64_t lsn; + ulint arch_log_no; + ibool server_busy; + ulint count = 0; + ulint pending_io; + ulint active_thd; if (srv_print_verbose_log) { ut_print_timestamp(stderr); @@ -3155,6 +3131,8 @@ logs_empty_and_mark_files_at_shutdown(void) loop: os_thread_sleep(100000); + count++; + mutex_enter(&kernel_mutex); /* We need the monitor threads to stop before we proceed with @@ -3163,6 +3141,21 @@ loop: if (srv_error_monitor_active || srv_lock_timeout_active || srv_monitor_active) { + const char* thread_active = NULL; + + /* Print a message every 60 seconds if we are waiting + for the monitor thread to exit. Master and worker threads + check will be done later. */ + if (srv_print_verbose_log && count > 600) { + + if (srv_error_monitor_active) { + thread_active = "srv_error_monitor_thread"; + } else if (srv_lock_timeout_active) { + thread_active = "srv_lock_timeout thread"; + } else if (srv_monitor_active) { + thread_active = "srv_monitor_thread"; + } + } mutex_exit(&kernel_mutex); @@ -3170,6 +3163,13 @@ loop: os_event_set(srv_monitor_event); os_event_set(srv_timeout_event); + if (thread_active) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for %s to exit\n", + thread_active); + count = 0; + } + goto loop; } @@ -3180,9 +3180,54 @@ loop: server_busy = trx_n_mysql_transactions > 0 || UT_LIST_GET_LEN(trx_sys->trx_list) > trx_n_prepared; + + if (server_busy) { + ulint total_trx = UT_LIST_GET_LEN(trx_sys->trx_list) + + trx_n_mysql_transactions; + + mutex_exit(&kernel_mutex); + + if (srv_print_verbose_log && count > 600) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for %lu " + "active transactions to finish\n", + (ulong) total_trx); + count = 0; + } + + goto loop; + } + mutex_exit(&kernel_mutex); - if (server_busy || srv_is_any_background_thread_active()) { + /* Check that the background threads are suspended */ + active_thd = srv_get_active_thread_type(); + + if (active_thd != ULINT_UNDEFINED) { + + /* The srv_lock_timeout_thread, srv_error_monitor_thread + and srv_monitor_thread should already exit by now. The + only threads to be suspended are the master threads + and worker threads (purge threads). Print the thread + type if any of such threads not in suspended mode */ + if (srv_print_verbose_log && count > 600) { + const char* thread_type = ""; + + switch (active_thd) { + case SRV_WORKER: + thread_type = "worker threads"; + break; + case SRV_MASTER: + thread_type = "master thread"; + break; + } + + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for %s " + "to be suspended\n", thread_type); + count = 0; + } + goto loop; } @@ -3194,10 +3239,35 @@ loop: || log_sys->n_pending_writes; mutex_exit(&log_sys->mutex); - if (server_busy || !buf_pool_check_no_pending_io()) { + if (server_busy) { + if (srv_print_verbose_log && count > 600) { + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Pending checkpoint_writes: %lu\n" + " InnoDB: Pending log flush writes: %lu\n", + (ulong) log_sys->n_pending_checkpoint_writes, + (ulong) log_sys->n_pending_writes); + count = 0; + } + goto loop; } + pending_io = buf_pool_check_num_pending_io(); + + if (pending_io) { + if (srv_print_verbose_log && count > 600) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for %lu buffer page " + "I/Os to complete\n", + (ulong) pending_io); + count = 0; + } + + goto loop; + } + + #ifdef UNIV_LOG_ARCHIVE log_archive_all(); #endif /* UNIV_LOG_ARCHIVE */ @@ -3221,7 +3291,7 @@ loop: log_buffer_flush_to_disk(); /* Check that the background threads stay suspended */ - if (srv_is_any_background_thread_active()) { + if (srv_get_active_thread_type() != ULINT_UNDEFINED) { fprintf(stderr, "InnoDB: Warning: some background thread" " woke up during shutdown\n"); @@ -3230,7 +3300,7 @@ loop: srv_shutdown_state = SRV_SHUTDOWN_LAST_PHASE; fil_close_all_files(); - ut_a(!srv_is_any_background_thread_active()); + ut_a(srv_get_active_thread_type() == ULINT_UNDEFINED); return; } @@ -3268,7 +3338,7 @@ loop: mutex_exit(&log_sys->mutex); /* Check that the background threads stay suspended */ - if (srv_is_any_background_thread_active()) { + if (srv_get_active_thread_type() != ULINT_UNDEFINED) { fprintf(stderr, "InnoDB: Warning: some background thread woke up" " during shutdown\n"); @@ -3286,13 +3356,20 @@ loop: if (!buf_all_freed()) { + if (srv_print_verbose_log && count > 600) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for dirty buffer " + "pages to be flushed\n"); + count = 0; + } + goto loop; } srv_shutdown_state = SRV_SHUTDOWN_LAST_PHASE; /* Make some checks that the server really is quiet */ - ut_a(!srv_is_any_background_thread_active()); + ut_a(srv_get_active_thread_type() == ULINT_UNDEFINED); ut_a(buf_all_freed()); ut_a(lsn == log_sys->lsn); @@ -3314,7 +3391,7 @@ loop: fil_close_all_files(); /* Make some checks that the server really is quiet */ - ut_a(!srv_is_any_background_thread_active()); + ut_a(srv_get_active_thread_type() == ULINT_UNDEFINED); ut_a(buf_all_freed()); ut_a(lsn == log_sys->lsn); diff --git a/mem/mem0pool.c b/mem/mem0pool.c index dc68cf8eb24..50dbe526d64 100644 --- a/mem/mem0pool.c +++ b/mem/mem0pool.c @@ -228,11 +228,7 @@ mem_pool_create( pool = ut_malloc(sizeof(mem_pool_t)); - /* We do not set the memory to zero (FALSE) in the pool, - but only when allocated at a higher level in mem0mem.c. - This is to avoid masking useful Purify warnings. */ - - pool->buf = ut_malloc_low(size, FALSE, TRUE); + pool->buf = ut_malloc_low(size, TRUE); pool->size = size; mutex_create(mem_pool_mutex_key, &pool->mutex, SYNC_MEM_POOL); diff --git a/mtr/mtr0mtr.c b/mtr/mtr0mtr.c index 08234609ff0..d852ed6f496 100644 --- a/mtr/mtr0mtr.c +++ b/mtr/mtr0mtr.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ diff --git a/os/os0file.c b/os/os0file.c index 0b1294a169e..26636c8a6cb 100644 --- a/os/os0file.c +++ b/os/os0file.c @@ -3308,7 +3308,91 @@ retry: fprintf(stderr, "InnoDB: You can disable Linux Native AIO by" - " setting innodb_native_aio = off in my.cnf\n"); + " setting innodb_use_native_aio = 0 in my.cnf\n"); + return(FALSE); +} + +/******************************************************************//** +Checks if the system supports native linux aio. On some kernel +versions where native aio is supported it won't work on tmpfs. In such +cases we can't use native aio as it is not possible to mix simulated +and native aio. +@return: TRUE if supported, FALSE otherwise. */ +static +ibool +os_aio_native_aio_supported(void) +/*=============================*/ +{ + int fd; + byte* buf; + byte* ptr; + struct io_event io_event; + io_context_t io_ctx; + struct iocb iocb; + struct iocb* p_iocb; + int err; + + if (!os_aio_linux_create_io_ctx(1, &io_ctx)) { + /* The platform does not support native aio. */ + return(FALSE); + } + + /* Now check if tmpdir supports native aio ops. */ + fd = innobase_mysql_tmpfile(); + + if (fd < 0) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Error: unable to create " + "temp file to check native AIO support.\n"); + + return(FALSE); + } + + memset(&io_event, 0x0, sizeof(io_event)); + + buf = (byte*) ut_malloc(UNIV_PAGE_SIZE * 2); + ptr = (byte*) ut_align(buf, UNIV_PAGE_SIZE); + + /* Suppress valgrind warning. */ + memset(buf, 0x00, UNIV_PAGE_SIZE * 2); + + memset(&iocb, 0x0, sizeof(iocb)); + p_iocb = &iocb; + io_prep_pwrite(p_iocb, fd, ptr, UNIV_PAGE_SIZE, 0); + + err = io_submit(io_ctx, 1, &p_iocb); + if (err >= 1) { + /* Now collect the submitted IO request. */ + err = io_getevents(io_ctx, 1, 1, &io_event, NULL); + } + + ut_free(buf); + close(fd); + + switch (err) { + case 1: + return(TRUE); + + case -EINVAL: + case -ENOSYS: + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: Linux Native AIO is not" + " supported on tmpdir.\n" + "InnoDB: You can either move tmpdir to a" + " file system that supports native AIO\n" + "InnoDB: or you can set" + " innodb_use_native_aio to FALSE to avoid" + " this message.\n"); + + /* fall through. */ + default: + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: Linux Native AIO check" + " on tmpdir returned error[%d]\n", -err); + } + return(FALSE); } #endif /* LINUX_NATIVE_AIO */ @@ -3475,6 +3559,19 @@ os_aio_init( os_io_init_simple(); +#if defined(LINUX_NATIVE_AIO) + /* Check if native aio is supported on this system and tmpfs */ + if (srv_use_native_aio + && !os_aio_native_aio_supported()) { + + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Warning: Linux Native AIO" + " disabled.\n"); + srv_use_native_aio = FALSE; + } +#endif /* LINUX_NATIVE_AIO */ + for (i = 0; i < n_segments; i++) { srv_set_io_thread_op_info(i, "not started yet"); } diff --git a/os/os0proc.c b/os/os0proc.c index 0f56a608f38..68321e1aaf9 100644 --- a/os/os0proc.c +++ b/os/os0proc.c @@ -111,9 +111,6 @@ os_mem_alloc_large( os_fast_mutex_lock(&ut_list_mutex); ut_total_allocated_memory += size; os_fast_mutex_unlock(&ut_list_mutex); -# ifdef UNIV_SET_MEM_TO_ZERO - memset(ptr, '\0', size); -# endif UNIV_MEM_ALLOC(ptr, size); return(ptr); } diff --git a/page/page0cur.c b/page/page0cur.c index 936762b986a..d49b121afab 100644 --- a/page/page0cur.c +++ b/page/page0cur.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -900,7 +900,7 @@ page_cur_parse_insert_rec( ut_print_buf(stderr, ptr2, 300); putc('\n', stderr); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); ut_error; } @@ -1180,14 +1180,15 @@ page_cur_insert_rec_zip_reorg( /* Before trying to reorganize the page, store the number of preceding records on the page. */ pos = page_rec_get_n_recs_before(rec); + ut_ad(pos > 0); if (page_zip_reorganize(block, index, mtr)) { /* The page was reorganized: Find rec by seeking to pos, and update *current_rec. */ - rec = page + PAGE_NEW_INFIMUM; - - while (--pos) { - rec = page + rec_get_next_offs(rec, TRUE); + if (pos > 1) { + rec = page_rec_get_nth(page, pos - 1); + } else { + rec = page + PAGE_NEW_INFIMUM; } *current_rec = rec; @@ -1283,6 +1284,12 @@ page_cur_insert_rec_zip( insert_rec = page_cur_insert_rec_zip_reorg( current_rec, block, index, insert_rec, page, page_zip, mtr); +#ifdef UNIV_DEBUG + if (insert_rec) { + rec_offs_make_valid( + insert_rec, index, offsets); + } +#endif /* UNIV_DEBUG */ } return(insert_rec); diff --git a/page/page0page.c b/page/page0page.c index 4858929082a..4a389bbe5b8 100644 --- a/page/page0page.c +++ b/page/page0page.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1994, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -148,7 +148,7 @@ page_dir_find_owner_slot( fputs("\n" "InnoDB: on that page!\n", stderr); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); ut_error; } @@ -549,8 +549,7 @@ page_copy_rec_list_end_no_locks( page_cur_move_to_next(&cur1); } - ut_a((ibool)!!page_is_comp(new_page) - == dict_table_is_comp(index->table)); + btr_assert_not_corrupted(new_block, index); ut_a(page_is_comp(new_page) == page_rec_is_comp(rec)); ut_a(mach_read_from_2(new_page + UNIV_PAGE_SIZE - 10) == (ulint) (page_is_comp(new_page) ? PAGE_NEW_INFIMUM : PAGE_OLD_INFIMUM)); @@ -570,8 +569,10 @@ page_copy_rec_list_end_no_locks( /* Track an assertion failure reported on the mailing list on June 18th, 2003 */ - buf_page_print(new_page, 0); - buf_page_print(page_align(rec), 0); + buf_page_print(new_page, 0, + BUF_PAGE_PRINT_NO_CRASH); + buf_page_print(page_align(rec), 0, + BUF_PAGE_PRINT_NO_CRASH); ut_print_timestamp(stderr); fprintf(stderr, @@ -1453,55 +1454,54 @@ page_dir_balance_slot( } } -#ifndef UNIV_HOTBACKUP /************************************************************//** -Returns the middle record of the record list. If there are an even number -of records in the list, returns the first record of the upper half-list. -@return middle record */ +Returns the nth record of the record list. +This is the inverse function of page_rec_get_n_recs_before(). +@return nth record */ UNIV_INTERN -rec_t* -page_get_middle_rec( -/*================*/ - page_t* page) /*!< in: page */ +const rec_t* +page_rec_get_nth_const( +/*===================*/ + const page_t* page, /*!< in: page */ + ulint nth) /*!< in: nth record */ { - page_dir_slot_t* slot; - ulint middle; + const page_dir_slot_t* slot; ulint i; ulint n_owned; - ulint count; - rec_t* rec; - - /* This many records we must leave behind */ - middle = (page_get_n_recs(page) + PAGE_HEAP_NO_USER_LOW) / 2; + const rec_t* rec; - count = 0; + ut_ad(nth < UNIV_PAGE_SIZE / (REC_N_NEW_EXTRA_BYTES + 1)); for (i = 0;; i++) { slot = page_dir_get_nth_slot(page, i); n_owned = page_dir_slot_get_n_owned(slot); - if (count + n_owned > middle) { + if (n_owned > nth) { break; } else { - count += n_owned; + nth -= n_owned; } } ut_ad(i > 0); slot = page_dir_get_nth_slot(page, i - 1); - rec = (rec_t*) page_dir_slot_get_rec(slot); - rec = page_rec_get_next(rec); - - /* There are now count records behind rec */ + rec = page_dir_slot_get_rec(slot); - for (i = 0; i < middle - count; i++) { - rec = page_rec_get_next(rec); + if (page_is_comp(page)) { + do { + rec = page_rec_get_next_low(rec, TRUE); + ut_ad(rec); + } while (nth--); + } else { + do { + rec = page_rec_get_next_low(rec, FALSE); + ut_ad(rec); + } while (nth--); } return(rec); } -#endif /* !UNIV_HOTBACKUP */ /***************************************************************//** Returns the number of records before the given record in chain. @@ -1563,6 +1563,7 @@ page_rec_get_n_recs_before( n--; ut_ad(n >= 0); + ut_ad((ulint)n < UNIV_PAGE_SIZE / (REC_N_NEW_EXTRA_BYTES + 1)); return((ulint) n); } @@ -1835,7 +1836,7 @@ page_check_dir( fprintf(stderr, "InnoDB: Page directory corruption:" " infimum not pointed to\n"); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); } if (UNIV_UNLIKELY(!page_rec_is_supremum_low(supremum_offs))) { @@ -1843,7 +1844,7 @@ page_check_dir( fprintf(stderr, "InnoDB: Page directory corruption:" " supremum not pointed to\n"); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); } } #endif /* !UNIV_HOTBACKUP */ @@ -2547,7 +2548,7 @@ func_exit2: (ulong) page_get_space_id(page), (ulong) page_get_page_no(page), index->name); - buf_page_print(page, 0); + buf_page_print(page, 0, 0); } return(ret); diff --git a/pars/pars0pars.c b/pars/pars0pars.c index ef107f2896f..86f54195682 100644 --- a/pars/pars0pars.c +++ b/pars/pars0pars.c @@ -1857,7 +1857,7 @@ pars_sql( ut_ad(str); - heap = mem_heap_create(256); + heap = mem_heap_create(16000); /* Currently, the parser is not reentrant: */ ut_ad(mutex_own(&(dict_sys->mutex))); diff --git a/row/row0ins.c b/row/row0ins.c index adc75bd5760..a629a4fb195 100644 --- a/row/row0ins.c +++ b/row/row0ins.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -23,6 +23,8 @@ Insert into a table Created 4/20/1996 Heikki Tuuri *******************************************************/ +#include "m_string.h" /* for my_sys.h */ +#include "my_sys.h" /* DEBUG_SYNC_C */ #include "row0ins.h" #ifdef UNIV_NONINL @@ -47,6 +49,8 @@ Created 4/20/1996 Heikki Tuuri #include "data0data.h" #include "usr0sess.h" #include "buf0lru.h" +#include "m_string.h" +#include "my_sys.h" #define ROW_INS_PREV 1 #define ROW_INS_NEXT 2 @@ -348,9 +352,9 @@ row_ins_clust_index_entry_by_modify( return(DB_LOCK_TABLE_FULL); } - err = btr_cur_pessimistic_update(0, cursor, - heap, big_rec, update, - 0, thr, mtr); + err = btr_cur_pessimistic_update( + BTR_KEEP_POS_FLAG, cursor, heap, big_rec, update, + 0, thr, mtr); } return(err); @@ -950,7 +954,7 @@ row_ins_foreign_check_on_constraint( fputs("\n" "InnoDB: Submit a detailed bug report to" " http://bugs.mysql.com\n", stderr); - + ut_ad(0); err = DB_SUCCESS; goto nonstandard_exit_func; @@ -1083,6 +1087,9 @@ row_ins_foreign_check_on_constraint( release the latch. */ row_mysql_unfreeze_data_dictionary(thr_get_trx(thr)); + + DEBUG_SYNC_C("innodb_dml_cascade_dict_unfreeze"); + row_mysql_freeze_data_dictionary(thr_get_trx(thr)); mtr_start(mtr); @@ -1990,6 +1997,7 @@ row_ins_index_entry_low( ulint modify = 0; /* remove warning */ rec_t* insert_rec; rec_t* rec; + ulint* offsets; ulint err; ulint n_unique; big_rec_t* big_rec = NULL; @@ -2099,6 +2107,64 @@ row_ins_index_entry_low( err = row_ins_clust_index_entry_by_modify( mode, &cursor, &heap, &big_rec, entry, thr, &mtr); + + if (big_rec) { + ut_a(err == DB_SUCCESS); + /* Write out the externally stored + columns while still x-latching + index->lock and block->lock. Allocate + pages for big_rec in the mtr that + modified the B-tree, but be sure to skip + any pages that were freed in mtr. We will + write out the big_rec pages before + committing the B-tree mini-transaction. If + the system crashes so that crash recovery + will not replay the mtr_commit(&mtr), the + big_rec pages will be left orphaned until + the pages are allocated for something else. + + TODO: If the allocation extends the + tablespace, it will not be redo + logged, in either mini-transaction. + Tablespace extension should be + redo-logged in the big_rec + mini-transaction, so that recovery + will not fail when the big_rec was + written to the extended portion of the + file, in case the file was somehow + truncated in the crash. */ + + rec = btr_cur_get_rec(&cursor); + offsets = rec_get_offsets( + rec, index, NULL, + ULINT_UNDEFINED, &heap); + + DEBUG_SYNC_C("before_row_ins_upd_extern"); + err = btr_store_big_rec_extern_fields( + index, btr_cur_get_block(&cursor), + rec, offsets, big_rec, &mtr, + BTR_STORE_INSERT_UPDATE); + DEBUG_SYNC_C("after_row_ins_upd_extern"); + /* If writing big_rec fails (for + example, because of DB_OUT_OF_FILE_SPACE), + the record will be corrupted. Even if + we did not update any externally + stored columns, our update could cause + the record to grow so that a + non-updated column was selected for + external storage. This non-update + would not have been written to the + undo log, and thus the record cannot + be rolled back. + + However, because we have not executed + mtr_commit(mtr) yet, the update will + not be replayed in crash recovery, and + the following assertion failure will + effectively "roll back" the operation. */ + ut_a(err == DB_SUCCESS); + goto stored_big_rec; + } } else { ut_ad(!n_ext); err = row_ins_sec_index_entry_by_modify( @@ -2145,8 +2211,13 @@ function_exit: return(err); } + DBUG_EXECUTE_IF( + "row_ins_extern_checkpoint", + log_make_checkpoint_at(IB_ULONGLONG_MAX, TRUE);); + mtr_start(&mtr); + DEBUG_SYNC_C("before_row_ins_extern_latch"); btr_cur_search_to_nth_level(index, 0, entry, PAGE_CUR_LE, BTR_MODIFY_TREE, &cursor, 0, __FILE__, __LINE__, &mtr); @@ -2154,10 +2225,13 @@ function_exit: offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap); + DEBUG_SYNC_C("before_row_ins_extern"); err = btr_store_big_rec_extern_fields( index, btr_cur_get_block(&cursor), - rec, offsets, &mtr, FALSE, big_rec); + rec, offsets, big_rec, &mtr, BTR_STORE_INSERT); + DEBUG_SYNC_C("after_row_ins_extern"); +stored_big_rec: if (modify) { dtuple_big_rec_free(big_rec); } else { diff --git a/row/row0merge.c b/row/row0merge.c index ed5c0abc884..c303a372ed0 100644 --- a/row/row0merge.c +++ b/row/row0merge.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2005, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. 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 @@ -583,7 +583,7 @@ row_merge_buf_write( REC_STATUS_ORDINARY, entry, n_fields, &extra_size); - ut_ad(size > extra_size); + ut_ad(size >= extra_size); ut_ad(extra_size >= REC_N_NEW_EXTRA_BYTES); extra_size -= REC_N_NEW_EXTRA_BYTES; size -= REC_N_NEW_EXTRA_BYTES; @@ -1607,22 +1607,28 @@ row_merge( const dict_index_t* index, /*!< in: index being created */ merge_file_t* file, /*!< in/out: file containing index entries */ - ulint* half, /*!< in/out: half the file */ row_merge_block_t* block, /*!< in/out: 3 buffers */ int* tmpfd, /*!< in/out: temporary file handle */ - struct TABLE* table) /*!< in/out: MySQL table, for + struct TABLE* table, /*!< in/out: MySQL table, for reporting erroneous key value if applicable */ + ulint* num_run,/*!< in/out: Number of runs remain + to be merged */ + ulint* run_offset) /*!< in/out: Array contains the + first offset number for each merge + run */ { ulint foffs0; /*!< first input offset */ ulint foffs1; /*!< second input offset */ ulint error; /*!< error code */ merge_file_t of; /*!< output file */ - const ulint ihalf = *half; + const ulint ihalf = run_offset[*num_run / 2]; /*!< half the input file */ - ulint ohalf; /*!< half the output file */ + ulint n_run = 0; + /*!< num of runs generated from this merge */ UNIV_MEM_ASSERT_W(block[0], 3 * sizeof block[0]); + ut_ad(ihalf < file->offset); of.fd = *tmpfd; @@ -1638,17 +1644,20 @@ row_merge( #endif /* POSIX_FADV_SEQUENTIAL */ /* Merge blocks to the output file. */ - ohalf = 0; foffs0 = 0; foffs1 = ihalf; + UNIV_MEM_INVALID(run_offset, *num_run * sizeof *run_offset); + for (; foffs0 < ihalf && foffs1 < file->offset; foffs0++, foffs1++) { - ulint ahalf; /*!< arithmetic half the input file */ if (UNIV_UNLIKELY(trx_is_interrupted(trx))) { return(DB_INTERRUPTED); } + /* Remember the offset number for this run */ + run_offset[n_run++] = of.offset; + error = row_merge_blocks(index, file, block, &foffs0, &foffs1, &of, table); @@ -1656,21 +1665,6 @@ row_merge( return(error); } - /* Record the offset of the output file when - approximately half the output has been generated. In - this way, the next invocation of row_merge() will - spend most of the time in this loop. The initial - estimate is ohalf==0. */ - ahalf = file->offset / 2; - ut_ad(ohalf <= of.offset); - - /* Improve the estimate until reaching half the input - file size, or we can not get any closer to it. All - comparands should be non-negative when !(ohalf < ahalf) - because ohalf <= of.offset. */ - if (ohalf < ahalf || of.offset - ahalf < ohalf - ahalf) { - ohalf = of.offset; - } } /* Copy the last blocks, if there are any. */ @@ -1680,6 +1674,9 @@ row_merge( return(DB_INTERRUPTED); } + /* Remember the offset number for this run */ + run_offset[n_run++] = of.offset; + if (!row_merge_blocks_copy(index, file, block, &foffs0, &of)) { return(DB_CORRUPTION); } @@ -1692,6 +1689,9 @@ row_merge( return(DB_INTERRUPTED); } + /* Remember the offset number for this run */ + run_offset[n_run++] = of.offset; + if (!row_merge_blocks_copy(index, file, block, &foffs1, &of)) { return(DB_CORRUPTION); } @@ -1703,10 +1703,23 @@ row_merge( return(DB_CORRUPTION); } + ut_ad(n_run <= *num_run); + + *num_run = n_run; + + /* Each run can contain one or more offsets. As merge goes on, + the number of runs (to merge) will reduce until we have one + single run. So the number of runs will always be smaller than + the number of offsets in file */ + ut_ad((*num_run) <= file->offset); + + /* The number of offsets in output file is always equal or + smaller than input file */ + ut_ad(of.offset <= file->offset); + /* Swap file descriptors for the next pass. */ *tmpfd = file->fd; *file = of; - *half = ohalf; UNIV_MEM_INVALID(block[0], 3 * sizeof block[0]); @@ -1731,27 +1744,44 @@ row_merge_sort( if applicable */ { ulint half = file->offset / 2; + ulint num_runs; + ulint* run_offset; + ulint error = DB_SUCCESS; + + /* Record the number of merge runs we need to perform */ + num_runs = file->offset; + + /* If num_runs are less than 1, nothing to merge */ + if (num_runs <= 1) { + return(error); + } + + /* "run_offset" records each run's first offset number */ + run_offset = (ulint*) mem_alloc(file->offset * sizeof(ulint)); + + /* This tells row_merge() where to start for the first round + of merge. */ + run_offset[half] = half; /* The file should always contain at least one byte (the end of file marker). Thus, it must be at least one block. */ ut_ad(file->offset > 0); + /* Merge the runs until we have one big run */ do { - ulint error; + error = row_merge(trx, index, file, block, tmpfd, + table, &num_runs, run_offset); - error = row_merge(trx, index, file, &half, - block, tmpfd, table); + UNIV_MEM_ASSERT_RW(run_offset, num_runs * sizeof *run_offset); if (error != DB_SUCCESS) { - return(error); + break; } + } while (num_runs > 1); - /* half > 0 should hold except when the file consists - of one block. No need to merge further then. */ - ut_ad(half > 0 || file->offset == 1); - } while (half < file->offset && half > 0); + mem_free(run_offset); - return(DB_SUCCESS); + return(error); } /*************************************************************//** @@ -2018,7 +2048,7 @@ row_merge_drop_index( tables in Innobase. Deleting a row from SYS_INDEXES table also frees the file segments of the B-tree associated with the index. */ - static const char str1[] = + static const char sql[] = "PROCEDURE DROP_INDEX_PROC () IS\n" "BEGIN\n" /* Rename the index, so that it will be dropped by @@ -2044,9 +2074,19 @@ row_merge_drop_index( ut_a(trx->dict_operation_lock_mode == RW_X_LATCH); - err = que_eval_sql(info, str1, FALSE, trx); + err = que_eval_sql(info, sql, FALSE, trx); + - ut_a(err == DB_SUCCESS); + if (err != DB_SUCCESS) { + /* Even though we ensure that DDL transactions are WAIT + and DEADLOCK free, we could encounter other errors e.g., + DB_TOO_MANY_TRANSACTIONS. */ + trx->error_state = DB_SUCCESS; + + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Error: row_merge_drop_index failed " + "with error code: %lu.\n", (ulint) err); + } /* Replace this index with another equivalent index for all foreign key constraints on this table where this index is used */ @@ -2346,7 +2386,7 @@ row_merge_rename_indexes( /* We use the private SQL parser of Innobase to generate the query graphs needed in renaming indexes. */ - static const char rename_indexes[] = + static const char sql[] = "PROCEDURE RENAME_INDEXES_PROC () IS\n" "BEGIN\n" "UPDATE SYS_INDEXES SET NAME=SUBSTR(NAME,1,LENGTH(NAME)-1)\n" @@ -2362,7 +2402,7 @@ row_merge_rename_indexes( pars_info_add_ull_literal(info, "tableid", table->id); - err = que_eval_sql(info, rename_indexes, FALSE, trx); + err = que_eval_sql(info, sql, FALSE, trx); if (err == DB_SUCCESS) { dict_index_t* index = dict_table_get_first_index(table); @@ -2372,6 +2412,15 @@ row_merge_rename_indexes( } index = dict_table_get_next_index(index); } while (index); + } else { + /* Even though we ensure that DDL transactions are WAIT + and DEADLOCK free, we could encounter other errors e.g., + DB_TOO_MANY_TRANSACTIONS. */ + trx->error_state = DB_SUCCESS; + + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Error: row_merge_rename_indexes " + "failed with error code: %lu.\n", (ulint) err); } trx->op_info = ""; @@ -2409,7 +2458,7 @@ row_merge_rename_tables( memcpy(old_name, old_table->name, strlen(old_table->name) + 1); } else { ut_print_timestamp(stderr); - fprintf(stderr, "InnoDB: too long table name: '%s', " + fprintf(stderr, " InnoDB: too long table name: '%s', " "max length is %d\n", old_table->name, MAX_FULL_NAME_LEN); ut_error; diff --git a/row/row0mysql.c b/row/row0mysql.c index 5e75e487f6b..eb1eb095fd1 100644 --- a/row/row0mysql.c +++ b/row/row0mysql.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -52,6 +52,8 @@ Created 9/17/2000 Heikki Tuuri #include "fil0fil.h" #include "ibuf0ibuf.h" #include "ha_prototypes.h" +#include "m_string.h" +#include "my_sys.h" /** Provide optional 4.x backwards compatibility for 5.0 and above */ UNIV_INTERN ibool row_rollback_on_timeout = FALSE; @@ -668,17 +670,60 @@ UNIV_INTERN row_prebuilt_t* row_create_prebuilt( /*================*/ - dict_table_t* table) /*!< in: Innobase table handle */ + dict_table_t* table, /*!< in: Innobase table handle */ + ulint mysql_row_len) /*!< in: length in bytes of a row in + the MySQL format */ { row_prebuilt_t* prebuilt; mem_heap_t* heap; dict_index_t* clust_index; dtuple_t* ref; ulint ref_len; + ulint search_tuple_n_fields; + + search_tuple_n_fields = 2 * dict_table_get_n_cols(table); - heap = mem_heap_create(sizeof *prebuilt + 128); + clust_index = dict_table_get_first_index(table); - prebuilt = mem_heap_zalloc(heap, sizeof *prebuilt); + /* Make sure that search_tuple is long enough for clustered index */ + ut_a(2 * dict_table_get_n_cols(table) >= clust_index->n_fields); + + ref_len = dict_index_get_n_unique(clust_index); + +#define PREBUILT_HEAP_INITIAL_SIZE \ + ( \ + sizeof(*prebuilt) \ + /* allocd in this function */ \ + + DTUPLE_EST_ALLOC(search_tuple_n_fields) \ + + DTUPLE_EST_ALLOC(ref_len) \ + /* allocd in row_prebuild_sel_graph() */ \ + + sizeof(sel_node_t) \ + + sizeof(que_fork_t) \ + + sizeof(que_thr_t) \ + /* allocd in row_get_prebuilt_update_vector() */ \ + + sizeof(upd_node_t) \ + + sizeof(upd_t) \ + + sizeof(upd_field_t) \ + * dict_table_get_n_cols(table) \ + + sizeof(que_fork_t) \ + + sizeof(que_thr_t) \ + /* allocd in row_get_prebuilt_insert_row() */ \ + + sizeof(ins_node_t) \ + /* mysql_row_len could be huge and we are not \ + sure if this prebuilt instance is going to be \ + used in inserts */ \ + + (mysql_row_len < 256 ? mysql_row_len : 0) \ + + DTUPLE_EST_ALLOC(dict_table_get_n_cols(table)) \ + + sizeof(que_fork_t) \ + + sizeof(que_thr_t) \ + ) + + /* We allocate enough space for the objects that are likely to + be created later in order to minimize the number of malloc() + calls */ + heap = mem_heap_create(PREBUILT_HEAP_INITIAL_SIZE); + + prebuilt = mem_heap_zalloc(heap, sizeof(*prebuilt)); prebuilt->magic_n = ROW_PREBUILT_ALLOCATED; prebuilt->magic_n2 = ROW_PREBUILT_ALLOCATED; @@ -688,23 +733,15 @@ row_create_prebuilt( prebuilt->sql_stat_start = TRUE; prebuilt->heap = heap; - prebuilt->pcur = btr_pcur_create_for_mysql(); - prebuilt->clust_pcur = btr_pcur_create_for_mysql(); + btr_pcur_reset(&prebuilt->pcur); + btr_pcur_reset(&prebuilt->clust_pcur); prebuilt->select_lock_type = LOCK_NONE; prebuilt->stored_select_lock_type = 99999999; UNIV_MEM_INVALID(&prebuilt->stored_select_lock_type, sizeof prebuilt->stored_select_lock_type); - prebuilt->search_tuple = dtuple_create( - heap, 2 * dict_table_get_n_cols(table)); - - clust_index = dict_table_get_first_index(table); - - /* Make sure that search_tuple is long enough for clustered index */ - ut_a(2 * dict_table_get_n_cols(table) >= clust_index->n_fields); - - ref_len = dict_index_get_n_unique(clust_index); + prebuilt->search_tuple = dtuple_create(heap, search_tuple_n_fields); ref = dtuple_create(heap, ref_len); @@ -721,6 +758,8 @@ row_create_prebuilt( prebuilt->autoinc_last_value = 0; + prebuilt->mysql_row_len = mysql_row_len; + return(prebuilt); } @@ -756,8 +795,8 @@ row_prebuilt_free( prebuilt->magic_n = ROW_PREBUILT_FREED; prebuilt->magic_n2 = ROW_PREBUILT_FREED; - btr_pcur_free_for_mysql(prebuilt->pcur); - btr_pcur_free_for_mysql(prebuilt->clust_pcur); + btr_pcur_reset(&prebuilt->pcur); + btr_pcur_reset(&prebuilt->clust_pcur); if (prebuilt->mysql_template) { mem_free(prebuilt->mysql_template); @@ -1418,6 +1457,8 @@ row_update_for_mysql( return(DB_ERROR); } + DEBUG_SYNC_C("innodb_row_update_for_mysql_begin"); + trx->op_info = "updating or deleting"; row_mysql_delay_if_needed(); @@ -1428,11 +1469,11 @@ row_update_for_mysql( clust_index = dict_table_get_first_index(table); - if (prebuilt->pcur->btr_cur.index == clust_index) { - btr_pcur_copy_stored_position(node->pcur, prebuilt->pcur); + if (prebuilt->pcur.btr_cur.index == clust_index) { + btr_pcur_copy_stored_position(node->pcur, &prebuilt->pcur); } else { btr_pcur_copy_stored_position(node->pcur, - prebuilt->clust_pcur); + &prebuilt->clust_pcur); } ut_a(node->pcur->rel_pos == BTR_PCUR_ON); @@ -1537,8 +1578,8 @@ row_unlock_for_mysql( clust_pcur, and we do not need to reposition the cursors. */ { - btr_pcur_t* pcur = prebuilt->pcur; - btr_pcur_t* clust_pcur = prebuilt->clust_pcur; + btr_pcur_t* pcur = &prebuilt->pcur; + btr_pcur_t* clust_pcur = &prebuilt->clust_pcur; trx_t* trx = prebuilt->trx; ut_ad(prebuilt && trx); @@ -1760,7 +1801,7 @@ row_mysql_freeze_data_dictionary_func( { ut_a(trx->dict_operation_lock_mode == 0); - rw_lock_s_lock_func(&dict_operation_lock, 0, file, line); + rw_lock_s_lock_inline(&dict_operation_lock, 0, file, line); trx->dict_operation_lock_mode = RW_S_LATCH; } @@ -1797,7 +1838,7 @@ row_mysql_lock_data_dictionary_func( /* Serialize data dictionary operations with dictionary mutex: no deadlocks or lock waits can occur then in these operations */ - rw_lock_x_lock_func(&dict_operation_lock, 0, file, line); + rw_lock_x_lock_inline(&dict_operation_lock, 0, file, line); trx->dict_operation_lock_mode = RW_X_LATCH; mutex_enter(&(dict_sys->mutex)); @@ -1968,6 +2009,21 @@ err_exit: } break; + case DB_TOO_MANY_CONCURRENT_TRXS: + /* We already have .ibd file here. it should be deleted. */ + + if (table->space && !fil_delete_tablespace(table->space, + FALSE)) { + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: not able to" + " delete tablespace %lu of table ", + (ulong) table->space); + ut_print_name(stderr, trx, TRUE, table->name); + fputs("!\n", stderr); + } + /* fall through */ + case DB_DUPLICATE_KEY: default: /* We may also get err == DB_ERROR if the .ibd file for the @@ -3145,6 +3201,7 @@ row_drop_table_for_mysql( { dict_foreign_t* foreign; dict_table_t* table; + dict_index_t* index; ulint space_id; ulint err; const char* table_name; @@ -3352,6 +3409,18 @@ check_next_foreign: trx_set_dict_operation(trx, TRX_DICT_OP_TABLE); trx->table_id = table->id; + /* Mark all indexes unavailable in the data dictionary cache + before starting to drop the table. */ + + for (index = dict_table_get_first_index(table); + index != NULL; + index = dict_table_get_next_index(index)) { + rw_lock_x_lock(dict_index_get_lock(index)); + ut_ad(!index->to_be_dropped); + index->to_be_dropped = TRUE; + rw_lock_x_unlock(dict_index_get_lock(index)); + } + /* We use the private SQL parser of Innobase to generate the query graphs needed in deleting the dictionary data from system tables in Innobase. Deleting a row from SYS_INDEXES table also @@ -3492,7 +3561,7 @@ check_next_foreign: "InnoDB: of table "); ut_print_name(stderr, trx, TRUE, name); fprintf(stderr, ".\n"); - } else if (!fil_delete_tablespace(space_id)) { + } else if (!fil_delete_tablespace(space_id, FALSE)) { fprintf(stderr, "InnoDB: We removed now the InnoDB" " internal data dictionary entry\n" @@ -3519,6 +3588,17 @@ check_next_foreign: the undo log. We can directly exit here and return the DB_TOO_MANY_CONCURRENT_TRXS error. */ + + /* Mark all indexes available in the data dictionary + cache again. */ + + for (index = dict_table_get_first_index(table); + index != NULL; + index = dict_table_get_next_index(index)) { + rw_lock_x_lock(dict_index_get_lock(index)); + index->to_be_dropped = FALSE; + rw_lock_x_unlock(dict_index_get_lock(index)); + } break; case DB_OUT_OF_FILE_SPACE: @@ -3613,7 +3693,7 @@ row_mysql_drop_temp_tables(void) btr_pcur_store_position(&pcur, &mtr); btr_pcur_commit_specify_mtr(&pcur, &mtr); - table = dict_load_table(table_name, TRUE, DICT_ERR_IGNORE_NONE); + table = dict_table_get_low(table_name); if (table) { row_drop_table_for_mysql(table_name, trx, FALSE); @@ -3875,6 +3955,7 @@ row_rename_table_for_mysql( ulint n_constraints_to_drop = 0; ibool old_is_tmp, new_is_tmp; pars_info_t* info = NULL; + int retry; ut_a(old_name != NULL); ut_a(new_name != NULL); @@ -3957,6 +4038,25 @@ row_rename_table_for_mysql( } } + /* Is a foreign key check running on this table? */ + for (retry = 0; retry < 100 + && table->n_foreign_key_checks_running > 0; ++retry) { + row_mysql_unlock_data_dictionary(trx); + os_thread_yield(); + row_mysql_lock_data_dictionary(trx); + } + + if (table->n_foreign_key_checks_running > 0) { + ut_print_timestamp(stderr); + fputs(" InnoDB: Error: in ALTER TABLE ", stderr); + ut_print_name(stderr, trx, TRUE, old_name); + fprintf(stderr, "\n" + "InnoDB: a FOREIGN KEY check is running.\n" + "InnoDB: Cannot rename table.\n"); + err = DB_TABLE_IN_FK_CHECK; + goto funct_exit; + } + /* We use the private SQL parser of Innobase to generate the query graphs needed in updating the dictionary data from system tables. */ diff --git a/row/row0row.c b/row/row0row.c index 0462f280858..2c33bdc4b15 100644 --- a/row/row0row.c +++ b/row/row0row.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -241,13 +241,18 @@ row_build( ut_ad(rec_offs_validate(rec, index, offsets)); } -#if 0 && defined UNIV_BLOB_NULL_DEBUG - /* This one can fail in trx_rollback_active() if - the server crashed during an insert before the - btr_store_big_rec_extern_fields() did mtr_commit() - all BLOB pointers to the clustered index record. */ - ut_a(!rec_offs_any_null_extern(rec, offsets)); -#endif /* 0 && UNIV_BLOB_NULL_DEBUG */ +#ifdef UNIV_BLOB_NULL_DEBUG + if (rec_offs_any_null_extern(rec, offsets)) { + /* This condition can occur during crash recovery + before trx_rollback_active() has completed execution, + or when a concurrently executing + row_ins_index_entry_low() has committed the B-tree + mini-transaction but has not yet managed to restore + the cursor position for writing the big_rec. */ + ut_a(trx_undo_roll_ptr_is_insert( + row_get_rec_roll_ptr(rec, index, offsets))); + } +#endif /* UNIV_BLOB_NULL_DEBUG */ if (type != ROW_COPY_POINTERS) { /* Take a copy of rec to heap */ diff --git a/row/row0sel.c b/row/row0sel.c index 7079e96bb12..a3ea482ad4a 100644 --- a/row/row0sel.c +++ b/row/row0sel.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1997, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -2301,7 +2301,12 @@ row_sel_convert_mysql_key_to_innobase( in the tuple is already according to index! */ byte* buf, /*!< in: buffer to use in field - conversions */ + conversions; NOTE that dtuple->data + may end up pointing inside buf so + do not discard that buffer while + the tuple is being used. See + row_mysql_store_col_in_innobase_format() + in the case of DATA_INT */ ulint buf_len, /*!< in: buffer length */ dict_index_t* index, /*!< in: index of the key value */ const byte* key_ptr, /*!< in: MySQL key value */ @@ -2433,6 +2438,7 @@ row_sel_convert_mysql_key_to_innobase( /* Storing may use at most data_len bytes of buf */ if (UNIV_LIKELY(!is_null)) { + ut_a(buf + data_len <= original_buf + buf_len); row_mysql_store_col_in_innobase_format( dfield, buf, FALSE, /* MySQL key value format col */ @@ -2915,17 +2921,17 @@ row_sel_get_clust_rec_for_mysql( btr_pcur_open_with_no_init(clust_index, prebuilt->clust_ref, PAGE_CUR_LE, BTR_SEARCH_LEAF, - prebuilt->clust_pcur, 0, mtr); + &prebuilt->clust_pcur, 0, mtr); - clust_rec = btr_pcur_get_rec(prebuilt->clust_pcur); + clust_rec = btr_pcur_get_rec(&prebuilt->clust_pcur); - prebuilt->clust_pcur->trx_if_known = trx; + prebuilt->clust_pcur.trx_if_known = trx; /* Note: only if the search ends up on a non-infimum record is the low_match value the real match to the search tuple */ if (!page_rec_is_user_rec(clust_rec) - || btr_pcur_get_low_match(prebuilt->clust_pcur) + || btr_pcur_get_low_match(&prebuilt->clust_pcur) < dict_index_get_n_unique(clust_index)) { /* In a rare case it is possible that no clust rec is found @@ -2957,6 +2963,7 @@ row_sel_get_clust_rec_for_mysql( fputs("\n" "InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); } clust_rec = NULL; @@ -2974,7 +2981,7 @@ row_sel_get_clust_rec_for_mysql( we set a LOCK_REC_NOT_GAP type lock */ err = lock_clust_rec_read_check_and_lock( - 0, btr_pcur_get_block(prebuilt->clust_pcur), + 0, btr_pcur_get_block(&prebuilt->clust_pcur), clust_rec, clust_index, *offsets, prebuilt->select_lock_type, LOCK_REC_NOT_GAP, thr); switch (err) { @@ -3052,7 +3059,7 @@ func_exit: /* We may use the cursor in update or in unlock_row(): store its position */ - btr_pcur_store_position(prebuilt->clust_pcur, mtr); + btr_pcur_store_position(&prebuilt->clust_pcur, mtr); } err_exit: @@ -3300,7 +3307,7 @@ row_sel_try_search_shortcut_for_mysql( { dict_index_t* index = prebuilt->index; const dtuple_t* search_tuple = prebuilt->search_tuple; - btr_pcur_t* pcur = prebuilt->pcur; + btr_pcur_t* pcur = &prebuilt->pcur; trx_t* trx = prebuilt->trx; const rec_t* rec; @@ -3389,7 +3396,7 @@ row_search_for_mysql( dict_index_t* index = prebuilt->index; ibool comp = dict_table_is_comp(index->table); const dtuple_t* search_tuple = prebuilt->search_tuple; - btr_pcur_t* pcur = prebuilt->pcur; + btr_pcur_t* pcur = &prebuilt->pcur; trx_t* trx = prebuilt->trx; dict_index_t* clust_index; que_thr_t* thr; @@ -4073,7 +4080,8 @@ wrong_offs: if ((srv_force_recovery == 0 || moves_up == FALSE) && srv_pass_corrupt_table <= 1) { ut_print_timestamp(stderr); - buf_page_print(page_align(rec), 0); + buf_page_print(page_align(rec), 0, + BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "\nInnoDB: rec address %p," " buf block fix count %lu\n", @@ -4092,7 +4100,7 @@ wrong_offs: "InnoDB: restore from a backup, or" " dump + drop + reimport the table.\n", stderr); - + ut_ad(0); err = DB_CORRUPTION; goto lock_wait_or_error; @@ -4445,7 +4453,9 @@ no_gap_lock: applicable to unique secondary indexes. Current behaviour is to widen the scope of a lock on an already delete marked record if the same record is deleted twice by the same transaction */ - if (index == clust_index && unique_search) { + if (index == clust_index && unique_search + && !prebuilt->used_in_HANDLER) { + err = DB_RECORD_NOT_FOUND; goto normal_return; diff --git a/row/row0umod.c b/row/row0umod.c index b86ce9eeabd..9597c476125 100644 --- a/row/row0umod.c +++ b/row/row0umod.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1997, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -509,6 +509,7 @@ row_undo_mod_del_unmark_sec_and_undo_update( fputs("\n" "InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); break; case ROW_FOUND: btr_cur = btr_pcur_get_btr_cur(&pcur); diff --git a/row/row0upd.c b/row/row0upd.c index 45c19b0ead0..28c770460ff 100644 --- a/row/row0upd.c +++ b/row/row0upd.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -23,6 +23,8 @@ Update of a row Created 12/27/1996 Heikki Tuuri *******************************************************/ +#include "m_string.h" /* for my_sys.h */ +#include "my_sys.h" /* DEBUG_SYNC_C */ #include "row0upd.h" #ifdef UNIV_NONINL @@ -1636,6 +1638,7 @@ row_upd_sec_index_entry( fputs("\n" "InnoDB: Submit a detailed bug report" " to http://bugs.mysql.com\n", stderr); + ut_ad(0); break; case ROW_FOUND: /* Delete mark the old index record; it can already be @@ -2021,29 +2024,65 @@ row_upd_clust_rec( ut_ad(!rec_get_deleted_flag(btr_pcur_get_rec(pcur), dict_table_is_comp(index->table))); - err = btr_cur_pessimistic_update(BTR_NO_LOCKING_FLAG, btr_cur, - &heap, &big_rec, node->update, - node->cmpl_info, thr, mtr); - mtr_commit(mtr); + err = btr_cur_pessimistic_update( + BTR_NO_LOCKING_FLAG | BTR_KEEP_POS_FLAG, btr_cur, + &heap, &big_rec, node->update, + node->cmpl_info, thr, mtr); /* skip store extern for fake_changes */ if (err == DB_SUCCESS && big_rec && !(thr_get_trx(thr)->fake_changes)) { - ulint offsets_[REC_OFFS_NORMAL_SIZE]; - rec_t* rec; + ulint offsets_[REC_OFFS_NORMAL_SIZE]; + rec_t* rec; rec_offs_init(offsets_); - mtr_start(mtr); + ut_a(err == DB_SUCCESS); + /* Write out the externally stored + columns while still x-latching + index->lock and block->lock. Allocate + pages for big_rec in the mtr that + modified the B-tree, but be sure to skip + any pages that were freed in mtr. We will + write out the big_rec pages before + committing the B-tree mini-transaction. If + the system crashes so that crash recovery + will not replay the mtr_commit(&mtr), the + big_rec pages will be left orphaned until + the pages are allocated for something else. + + TODO: If the allocation extends the tablespace, it + will not be redo logged, in either mini-transaction. + Tablespace extension should be redo-logged in the + big_rec mini-transaction, so that recovery will not + fail when the big_rec was written to the extended + portion of the file, in case the file was somehow + truncated in the crash. */ - ut_a(btr_pcur_restore_position(BTR_MODIFY_TREE, pcur, mtr)); rec = btr_cur_get_rec(btr_cur); + DEBUG_SYNC_C("before_row_upd_extern"); err = btr_store_big_rec_extern_fields( index, btr_cur_get_block(btr_cur), rec, rec_get_offsets(rec, index, offsets_, ULINT_UNDEFINED, &heap), - mtr, TRUE, big_rec); - mtr_commit(mtr); + big_rec, mtr, BTR_STORE_UPDATE); + DEBUG_SYNC_C("after_row_upd_extern"); + /* If writing big_rec fails (for example, because of + DB_OUT_OF_FILE_SPACE), the record will be corrupted. + Even if we did not update any externally stored + columns, our update could cause the record to grow so + that a non-updated column was selected for external + storage. This non-update would not have been written + to the undo log, and thus the record cannot be rolled + back. + + However, because we have not executed mtr_commit(mtr) + yet, the update will not be replayed in crash + recovery, and the following assertion failure will + effectively "roll back" the operation. */ + ut_a(err == DB_SUCCESS); } + mtr_commit(mtr); + if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } diff --git a/srv/srv0srv.c b/srv/srv0srv.c index d5f94768dba..0a72eb106a3 100644 --- a/srv/srv0srv.c +++ b/srv/srv0srv.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. @@ -433,6 +433,9 @@ UNIV_INTERN unsigned long long srv_stats_sample_pages = 8; UNIV_INTERN ulint srv_stats_auto_update = 1; UNIV_INTERN ulint srv_stats_update_need_lock = 1; UNIV_INTERN ibool srv_use_sys_stats_table = FALSE; +#ifdef UNIV_DEBUG +UNIV_INTERN ulong srv_sys_stats_root_page = 0; +#endif UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE; UNIV_INTERN ibool srv_use_checksums = TRUE; @@ -471,9 +474,6 @@ UNIV_INTERN ibool srv_print_lock_waits = FALSE; UNIV_INTERN ibool srv_print_buf_io = FALSE; UNIV_INTERN ibool srv_print_log_io = FALSE; UNIV_INTERN ibool srv_print_latch_waits = FALSE; - -UNIV_INTERN ulong srv_flush_checkpoint_debug = 0; - #endif /* UNIV_DEBUG */ UNIV_INTERN ulint srv_n_rows_inserted = 0; @@ -2802,6 +2802,7 @@ loop: "InnoDB: Please submit a bug report" " to http://bugs.mysql.com\n", old_lsn, new_lsn); + ut_ad(0); } old_lsn = new_lsn; @@ -2953,21 +2954,23 @@ exit_func: } /**********************************************************************//** -Check whether any background thread is active. -@return FALSE if all are are suspended or have exited. */ +Check whether any background thread is active. If so return the thread +type +@return ULINT_UNDEFINED if all are suspended or have exited, thread +type if any are still active. */ UNIV_INTERN -ibool -srv_is_any_background_thread_active(void) -/*=====================================*/ +ulint +srv_get_active_thread_type(void) +/*============================*/ { ulint i; - ibool ret = FALSE; + ibool ret = ULINT_UNDEFINED; mutex_enter(&kernel_mutex); for (i = 0; i <= SRV_MASTER; ++i) { if (srv_n_threads_active[i] != 0) { - ret = TRUE; + ret = i; break; } } @@ -2977,6 +2980,57 @@ srv_is_any_background_thread_active(void) return(ret); } +/*********************************************************************//** +This function prints progress message every 60 seconds during server +shutdown, for any activities that master thread is pending on. */ +static +void +srv_shutdown_print_master_pending( +/*==============================*/ + ib_time_t* last_print_time, /*!< last time the function + print the message */ + ulint n_tables_to_drop, /*!< number of tables to + be dropped */ + ulint n_bytes_merged, /*!< number of change buffer + just merged */ + ulint n_pages_flushed) /*!< number of pages flushed */ +{ + ib_time_t current_time; + double time_elapsed; + + current_time = ut_time(); + time_elapsed = ut_difftime(current_time, *last_print_time); + + if (time_elapsed > 60) { + *last_print_time = ut_time(); + + if (n_tables_to_drop) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for " + "%lu table(s) to be dropped\n", + (ulong) n_tables_to_drop); + } + + /* Check change buffer merge, we only wait for change buffer + merge if it is a slow shutdown */ + if (!srv_fast_shutdown && n_bytes_merged) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for change " + "buffer merge to complete\n" + " InnoDB: number of bytes of change buffer " + "just merged: %lu\n", + n_bytes_merged); + } + + if (n_pages_flushed) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Waiting for " + "%lu pages to be flushed\n", + (ulong) n_pages_flushed); + } + } +} + /*******************************************************************//** Tells the InnoDB server that there has been activity in the database and wakes up the master thread if it is suspended (not sleeping). Used @@ -3146,6 +3200,7 @@ srv_master_thread( ib_uint64_t lsn_old; ib_uint64_t oldest_lsn; + ib_time_t last_print_time; #ifdef UNIV_DEBUG_THREAD_CREATION fprintf(stderr, "Master thread starts, id %lu\n", @@ -3170,6 +3225,9 @@ srv_master_thread( mutex_enter(&(log_sys->mutex)); lsn_old = log_sys->lsn; mutex_exit(&(log_sys->mutex)); + + last_print_time = ut_time(); + loop: /*****************************************************************/ /* ---- When there is database activity by users, we cycle in this @@ -3620,18 +3678,11 @@ retry_flush_batch: PCT_IO(10), IB_ULONGLONG_MAX); } -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug != 1) { -#endif - - srv_main_thread_op_info = "making checkpoint"; + srv_main_thread_op_info = "making checkpoint"; - /* Make a new checkpoint about once in 10 seconds */ + /* Make a new checkpoint about once in 10 seconds */ - log_checkpoint(TRUE, FALSE); -#ifdef UNIV_DEBUG - } -#endif + log_checkpoint(TRUE, FALSE); srv_main_thread_op_info = "reserving kernel mutex"; @@ -3710,10 +3761,6 @@ background_loop: } mutex_exit(&kernel_mutex); -#ifdef UNIV_DEBUG - if (srv_flush_checkpoint_debug == 1) - goto skip_flush; -#endif flush_loop: srv_main_thread_op_info = "flushing buffer pool pages"; srv_main_flush_loops++; @@ -3754,9 +3801,6 @@ flush_loop: goto flush_loop; } -#ifdef UNIV_DEBUG -skip_flush: -#endif srv_main_thread_op_info = "reserving kernel mutex"; mutex_enter(&kernel_mutex); @@ -3772,6 +3816,14 @@ skip_flush: */ n_bytes_archived = 0; + /* Print progress message every 60 seconds during shutdown */ + if (srv_shutdown_state > 0 && srv_print_verbose_log) { + srv_shutdown_print_master_pending(&last_print_time, + n_tables_to_drop, + n_bytes_merged, + n_pages_flushed); + } + /* Keep looping in the background loop if still work to do */ if (srv_fast_shutdown && srv_shutdown_state > 0) { @@ -3790,6 +3842,7 @@ skip_flush: } else if (n_tables_to_drop + n_pages_purged + n_bytes_merged + n_pages_flushed + n_bytes_archived != 0) { + /* In a 'slow' shutdown we run purge and the insert buffer merge to completion */ diff --git a/srv/srv0start.c b/srv/srv0start.c index b11e63a8e56..34a2fdaa42a 100644 --- a/srv/srv0start.c +++ b/srv/srv0start.c @@ -925,8 +925,9 @@ skip_size_check: #endif /* UNIV_LOG_ARCHIVE */ min_flushed_lsn, max_flushed_lsn); - if (UNIV_PAGE_SIZE - != fsp_flags_get_page_size(flags)) { + if (!one_opened + && UNIV_PAGE_SIZE + != fsp_flags_get_page_size(flags)) { ut_print_timestamp(stderr); fprintf(stderr, @@ -1936,6 +1937,12 @@ innobase_start_or_create_for_mysql(void) trx_sys_dummy_create(TRX_DOUBLEWRITE_SPACE); } + + if (UNIV_UNLIKELY(!dict_verify_xtradb_sys_stats())) { + fprintf(stderr, "InnoDB: Warning: " + "SYS_STATS table corrupted, recreating\n"); + dict_recreate_xtradb_sys_stats(); + } } if (!create_new_db && sum_of_new_sizes > 0) { diff --git a/sync/sync0rw.c b/sync/sync0rw.c index 8884812d84d..5068d1679c0 100644 --- a/sync/sync0rw.c +++ b/sync/sync0rw.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -780,7 +780,9 @@ rw_lock_add_debug_info( rw_lock_debug_mutex_exit(); if ((pass == 0) && (lock_type != RW_LOCK_WAIT_EX)) { - sync_thread_add_level(lock, lock->level); + sync_thread_add_level(lock, lock->level, + lock_type == RW_LOCK_EX + && lock->lock_word < 0); } } diff --git a/sync/sync0sync.c b/sync/sync0sync.c index d2c4617d65c..7654fade6e8 100644 --- a/sync/sync0sync.c +++ b/sync/sync0sync.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2011, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -18,8 +18,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -700,7 +700,7 @@ mutex_set_debug_info( ut_ad(mutex); ut_ad(file_name); - sync_thread_add_level(mutex, mutex->level); + sync_thread_add_level(mutex, mutex->level, FALSE); mutex->file_name = file_name; mutex->line = line; @@ -1142,8 +1142,9 @@ void sync_thread_add_level( /*==================*/ void* latch, /*!< in: pointer to a mutex or an rw-lock */ - ulint level) /*!< in: level in the latching order; if + ulint level, /*!< in: level in the latching order; if SYNC_LEVEL_VARYING, nothing is done */ + ibool relock) /*!< in: TRUE if re-entering an x-lock */ { ulint i; sync_level_t* slot; @@ -1194,6 +1195,10 @@ sync_thread_add_level( array = thread_slot->levels; + if (relock) { + goto levels_ok; + } + /* NOTE that there is a problem with _NODE and _LEAF levels: if the B-tree height changes, then a leaf can change to an internal node or the other way around. We do not know at present if this can cause @@ -1376,6 +1381,7 @@ sync_thread_add_level( ut_error; } +levels_ok: if (array->next_free == ULINT_UNDEFINED) { ut_a(array->n_elems < array->max_elems); diff --git a/trx/trx0purge.c b/trx/trx0purge.c index eb4fa80fa40..122aab119ba 100644 --- a/trx/trx0purge.c +++ b/trx/trx0purge.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -730,6 +730,7 @@ trx_purge_rseg_get_next_history_log( "InnoDB: report, and submit it" " to http://bugs.mysql.com\n", (ulong) trx_sys->rseg_history_len); + ut_ad(0); } mutex_exit(&kernel_mutex); @@ -1200,7 +1201,7 @@ trx_purge( (ulong) purge_sys->n_pages_handled); } - return(purge_sys->n_pages_handled - old_pages_handled); + return((ulint) (purge_sys->n_pages_handled - old_pages_handled)); } /******************************************************************//** diff --git a/trx/trx0rec.c b/trx/trx0rec.c index 104b80f5d96..db4897c368d 100644 --- a/trx/trx0rec.c +++ b/trx/trx0rec.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -1016,6 +1016,7 @@ trx_undo_update_rec_get_update( fprintf(stderr, "\n" "InnoDB: n_fields = %lu, i = %lu, ptr %p\n", (ulong) n_fields, (ulong) i, ptr); + ut_ad(0); *upd = NULL; return(NULL); } @@ -1210,6 +1211,7 @@ trx_undo_report_row_operation( trx_t* trx; trx_undo_t* undo; ulint page_no; + buf_block_t* undo_block; trx_rseg_t* rseg; mtr_t mtr; ulint err = DB_SUCCESS; @@ -1252,10 +1254,13 @@ trx_undo_report_row_operation( if (UNIV_UNLIKELY(!undo)) { /* Did not succeed */ + ut_ad(err != DB_SUCCESS); mutex_exit(&(trx->undo_mutex)); return(err); } + + ut_ad(err == DB_SUCCESS); } else { ut_ad(op_type == TRX_UNDO_MODIFY_OP); @@ -1269,30 +1274,30 @@ trx_undo_report_row_operation( if (UNIV_UNLIKELY(!undo)) { /* Did not succeed */ + ut_ad(err != DB_SUCCESS); mutex_exit(&(trx->undo_mutex)); return(err); } + ut_ad(err == DB_SUCCESS); offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap); } - page_no = undo->last_page_no; - mtr_start(&mtr); + page_no = undo->last_page_no; + undo_block = buf_page_get_gen( + undo->space, undo->zip_size, page_no, RW_X_LATCH, + undo->guess_block, BUF_GET, __FILE__, __LINE__, &mtr); + buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE); + do { - buf_block_t* undo_block; page_t* undo_page; ulint offset; - undo_block = buf_page_get_gen(undo->space, undo->zip_size, - page_no, RW_X_LATCH, - undo->guess_block, BUF_GET, - __FILE__, __LINE__, &mtr); - buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE); - undo_page = buf_block_get_frame(undo_block); + ut_ad(page_no == buf_block_get_page_no(undo_block)); if (op_type == TRX_UNDO_INSERT_OP) { offset = trx_undo_page_report_insert( @@ -1369,12 +1374,11 @@ trx_undo_report_row_operation( a pessimistic insert in a B-tree, and we must reserve the counterpart of the tree latch, which is the rseg mutex. */ - mutex_enter(&(rseg->mutex)); - - page_no = trx_undo_add_page(trx, undo, &mtr); - - mutex_exit(&(rseg->mutex)); - } while (UNIV_LIKELY(page_no != FIL_NULL)); + mutex_enter(&rseg->mutex); + undo_block = trx_undo_add_page(trx, undo, &mtr); + mutex_exit(&rseg->mutex); + page_no = undo->last_page_no; + } while (undo_block != NULL); /* Did not succeed: out of space */ err = DB_OUT_OF_FILE_SPACE; @@ -1526,6 +1530,7 @@ trx_undo_prev_version_build( "InnoDB: record version ", stderr); rec_print_new(stderr, rec, offsets); putc('\n', stderr); + ut_ad(0); return(DB_ERROR); } @@ -1631,6 +1636,7 @@ trx_undo_prev_version_build( (ullint) old_roll_ptr, (ullint) roll_ptr); trx_purge_sys_print(); + ut_ad(0); return(DB_ERROR); } diff --git a/trx/trx0sys.c b/trx/trx0sys.c index 548f383742f..89fab47a0ad 100644 --- a/trx/trx0sys.c +++ b/trx/trx0sys.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2011, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -137,6 +137,11 @@ UNIV_INTERN mysql_pfs_key_t trx_doublewrite_mutex_key; UNIV_INTERN mysql_pfs_key_t file_format_max_mutex_key; #endif /* UNIV_PFS_MUTEX */ +#ifdef UNIV_DEBUG +/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ +uint trx_rseg_n_slots_debug = 0; +#endif + #ifndef UNIV_HOTBACKUP /** This is used to track the maximum file format id known to InnoDB. It's updated via SET GLOBAL innodb_file_format_max = 'x' or when we open @@ -253,9 +258,7 @@ trx_sys_create_doublewrite_buf(void) { buf_block_t* block; buf_block_t* block2; -#ifdef UNIV_SYNC_DEBUG buf_block_t* new_block; -#endif /* UNIV_SYNC_DEBUG */ byte* doublewrite; byte* fseg_header; ulint page_no; @@ -334,10 +337,9 @@ start_again: for (i = 0; i < 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE + FSP_EXTENT_SIZE / 2; i++) { - page_no = fseg_alloc_free_page(fseg_header, - prev_page_no + 1, - FSP_UP, &mtr); - if (page_no == FIL_NULL) { + new_block = fseg_alloc_free_page( + fseg_header, prev_page_no + 1, FSP_UP, &mtr); + if (new_block == NULL) { fprintf(stderr, "InnoDB: Cannot create doublewrite" " buffer: you must\n" @@ -358,13 +360,8 @@ start_again: the page position in the tablespace, then the page has not been written to in doublewrite. */ -#ifdef UNIV_SYNC_DEBUG - new_block = -#endif /* UNIV_SYNC_DEBUG */ - buf_page_get(TRX_SYS_SPACE, 0, page_no, - RW_X_LATCH, &mtr); - buf_block_dbg_add_level(new_block, - SYNC_NO_ORDER_CHECK); + ut_ad(rw_lock_get_x_lock_count(&new_block->lock) == 1); + page_no = buf_block_get_page_no(new_block); if (i == FSP_EXTENT_SIZE / 2) { ut_a(page_no == FSP_EXTENT_SIZE); @@ -434,7 +431,10 @@ start_again: /* The doublewrite buffer has already been created: just read in some numbers */ + trx_doublewrite_init(doublewrite); + mtr_commit(&mtr); + trx_doublewrite_buf_is_being_created = FALSE; } else { fprintf(stderr, "InnoDB: Doublewrite buffer not found in the doublewrite file:" @@ -481,13 +481,12 @@ start_again: for (i = 0; i < 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE + FSP_EXTENT_SIZE / 2; i++) { - page_no = fseg_alloc_free_page(fseg_header, - prev_page_no + 1, - FSP_UP, &mtr); - if (page_no == FIL_NULL) { + new_block = fseg_alloc_free_page( + fseg_header, prev_page_no + 1, FSP_UP, &mtr); + if (new_block == NULL) { fprintf(stderr, - "InnoDB: Cannot create the doublewrite" - " buffer: You must\n" + "InnoDB: Cannot create doublewrite" + " buffer: you must\n" "InnoDB: increase your" " tablespace size.\n" "InnoDB: Cannot continue operation.\n" @@ -505,13 +504,8 @@ start_again: the page position in the tablespace, then the page has not been written to in doublewrite. */ -#ifdef UNIV_SYNC_DEBUG - new_block = -#endif /* UNIV_SYNC_DEBUG */ - buf_page_get(TRX_DOUBLEWRITE_SPACE, 0, page_no, - RW_X_LATCH, &mtr); - buf_block_dbg_add_level(new_block, - SYNC_NO_ORDER_CHECK); + ut_ad(rw_lock_get_x_lock_count(&new_block->lock) == 1); + page_no = buf_block_get_page_no(new_block); if (i == FSP_EXTENT_SIZE / 2) { ut_a(page_no == FSP_EXTENT_SIZE); @@ -746,12 +740,16 @@ trx_sys_doublewrite_init_or_restore_pages( if (buf_page_is_corrupted(page, zip_size)) { fprintf(stderr, "InnoDB: Dump of the page:\n"); - buf_page_print(read_buf, zip_size); + buf_page_print( + read_buf, zip_size, + BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "InnoDB: Dump of" " corresponding page" " in doublewrite buffer:\n"); - buf_page_print(page, zip_size); + buf_page_print( + page, zip_size, + BUF_PAGE_PRINT_NO_CRASH); fprintf(stderr, "InnoDB: Also the page in the" @@ -765,7 +763,7 @@ trx_sys_doublewrite_init_or_restore_pages( "InnoDB: option:\n" "InnoDB:" " innodb_force_recovery=6\n"); - exit(1); + ut_error; } /* Write the good page from the diff --git a/trx/trx0trx.c b/trx/trx0trx.c index a14f5db8176..6cf97f65dd0 100644 --- a/trx/trx0trx.c +++ b/trx/trx0trx.c @@ -1140,6 +1140,8 @@ trx_commit_off_kernel( ut_ad(UT_LIST_GET_LEN(trx->trx_locks) == 0); UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx); + + trx->error_state = DB_SUCCESS; } /****************************************************************//** diff --git a/trx/trx0undo.c b/trx/trx0undo.c index dae0637f72c..3d794c69c8b 100644 --- a/trx/trx0undo.c +++ b/trx/trx0undo.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -876,9 +876,9 @@ trx_undo_discard_latest_update_undo( #ifndef UNIV_HOTBACKUP /********************************************************************//** Tries to add a page to the undo log segment where the undo log is placed. -@return page number if success, else FIL_NULL */ +@return X-latched block if success, else NULL */ UNIV_INTERN -ulint +buf_block_t* trx_undo_add_page( /*==============*/ trx_t* trx, /*!< in: transaction */ @@ -888,11 +888,10 @@ trx_undo_add_page( the rollback segment mutex */ { page_t* header_page; + buf_block_t* new_block; page_t* new_page; trx_rseg_t* rseg; - ulint page_no; ulint n_reserved; - ibool success; ut_ad(mutex_own(&(trx->undo_mutex))); ut_ad(!mutex_own(&kernel_mutex)); @@ -902,37 +901,37 @@ trx_undo_add_page( if (rseg->curr_size == rseg->max_size) { - return(FIL_NULL); + return(NULL); } header_page = trx_undo_page_get(undo->space, undo->zip_size, undo->hdr_page_no, mtr); - success = fsp_reserve_free_extents(&n_reserved, undo->space, 1, - FSP_UNDO, mtr); - if (!success) { + if (!fsp_reserve_free_extents(&n_reserved, undo->space, 1, + FSP_UNDO, mtr)) { - return(FIL_NULL); + return(NULL); } - page_no = fseg_alloc_free_page_general(header_page + TRX_UNDO_SEG_HDR - + TRX_UNDO_FSEG_HEADER, - undo->top_page_no + 1, FSP_UP, - TRUE, mtr); + new_block = fseg_alloc_free_page_general( + TRX_UNDO_SEG_HDR + TRX_UNDO_FSEG_HEADER + + header_page, + undo->top_page_no + 1, FSP_UP, TRUE, mtr, mtr); fil_space_release_free_extents(undo->space, n_reserved); - if (page_no == FIL_NULL) { + if (new_block == NULL) { /* No space left */ - return(FIL_NULL); + return(NULL); } - undo->last_page_no = page_no; + ut_ad(rw_lock_get_x_lock_count(&new_block->lock) == 1); + buf_block_dbg_add_level(new_block, SYNC_TRX_UNDO_PAGE); + undo->last_page_no = buf_block_get_page_no(new_block); - new_page = trx_undo_page_get(undo->space, undo->zip_size, - page_no, mtr); + new_page = buf_block_get_frame(new_block); trx_undo_page_init(new_page, undo->type, mtr); @@ -941,7 +940,7 @@ trx_undo_add_page( undo->size++; rseg->curr_size++; - return(page_no); + return(new_block); } /********************************************************************//** diff --git a/ut/ut0mem.c b/ut/ut0mem.c index 303fdd6dd44..cb6b050beca 100644 --- a/ut/ut0mem.c +++ b/ut/ut0mem.c @@ -84,17 +84,13 @@ ut_mem_init(void) #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** -Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is -defined and set_to_zero is TRUE. +Allocates memory. @return own: allocated memory */ UNIV_INTERN void* ut_malloc_low( /*==========*/ ulint n, /*!< in: number of bytes to allocate */ - ibool set_to_zero, /*!< in: TRUE if allocated memory should be - set to zero if UNIV_SET_MEM_TO_ZERO is - defined */ ibool assert_on_error)/*!< in: if TRUE, we crash mysqld if the memory cannot be allocated */ { @@ -106,12 +102,6 @@ ut_malloc_low( ret = malloc(n); ut_a(ret || !assert_on_error); -#ifdef UNIV_SET_MEM_TO_ZERO - if (set_to_zero) { - memset(ret, '\0', n); - UNIV_MEM_ALLOC(ret, n); - } -#endif return(ret); } @@ -193,12 +183,6 @@ retry: } } - if (set_to_zero) { -#ifdef UNIV_SET_MEM_TO_ZERO - memset(ret, '\0', n + sizeof(ut_mem_block_t)); -#endif - } - UNIV_MEM_ALLOC(ret, n + sizeof(ut_mem_block_t)); ((ut_mem_block_t*)ret)->size = n + sizeof(ut_mem_block_t); @@ -215,74 +199,10 @@ retry: void* ret = malloc(n); ut_a(ret || !assert_on_error); -# ifdef UNIV_SET_MEM_TO_ZERO - if (set_to_zero) { - memset(ret, '\0', n); - } -# endif return(ret); #endif /* !UNIV_HOTBACKUP */ } -/**********************************************************************//** -Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is -defined. -@return own: allocated memory */ -UNIV_INTERN -void* -ut_malloc( -/*======*/ - ulint n) /*!< in: number of bytes to allocate */ -{ -#ifndef UNIV_HOTBACKUP - return(ut_malloc_low(n, TRUE, TRUE)); -#else /* !UNIV_HOTBACKUP */ - return(malloc(n)); -#endif /* !UNIV_HOTBACKUP */ -} - -#ifndef UNIV_HOTBACKUP -/**********************************************************************//** -Tests if malloc of n bytes would succeed. ut_malloc() asserts if memory runs -out. It cannot be used if we want to return an error message. Prints to -stderr a message if fails. -@return TRUE if succeeded */ -UNIV_INTERN -ibool -ut_test_malloc( -/*===========*/ - ulint n) /*!< in: try to allocate this many bytes */ -{ - void* ret; - - ret = malloc(n); - - if (ret == NULL) { - ut_print_timestamp(stderr); - fprintf(stderr, - " InnoDB: Error: cannot allocate" - " %lu bytes of memory for\n" - "InnoDB: a BLOB with malloc! Total allocated memory\n" - "InnoDB: by InnoDB %lu bytes." - " Operating system errno: %d\n" - "InnoDB: Check if you should increase" - " the swap file or\n" - "InnoDB: ulimits of your operating system.\n" - "InnoDB: On FreeBSD check you have" - " compiled the OS with\n" - "InnoDB: a big enough maximum process size.\n", - (ulong) n, - (ulong) ut_total_allocated_memory, - (int) errno); - return(FALSE); - } - - free(ret); - - return(TRUE); -} -#endif /* !UNIV_HOTBACKUP */ - /**********************************************************************//** Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is a nop. */ diff --git a/ut/ut0ut.c b/ut/ut0ut.c index f6dfb3ba0b3..117a777cb98 100644 --- a/ut/ut0ut.c +++ b/ut/ut0ut.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2011, Oracle Corpn. All Rights Reserved. +Copyright (c) 2011, 2012, Oracle and/or its affiliates. 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 @@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -718,6 +718,8 @@ ut_strerr( return("Undo record too big"); case DB_END_OF_INDEX: return("End of index"); + case DB_TABLE_IN_FK_CHECK: + return("Table is being used in foreign key check"); /* do not add default: in order to produce a warning if new code is added to the enum but not added here */ } -- cgit v1.2.1 From 13982b5a118ab9060d786da646af94d81638bc3b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 15 Jun 2012 10:26:06 +0200 Subject: comments --- storage/xtradb/include/univ.i | 3 +++ support-files/rpm/server.cnf | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index 1a48d68d0d7..dd108bcbfe3 100644 --- a/storage/xtradb/include/univ.i +++ b/storage/xtradb/include/univ.i @@ -54,6 +54,9 @@ Created 1/20/1994 Heikki Tuuri #define INNODB_VERSION_BUGFIX 8 #ifndef PERCONA_INNODB_VERSION +/* this is *not* the version of XtraDB as in Percona-Server sources, + but the version of Percona-Server, where this XtraDB was taken from. + Because Percona does not update XtraDB version for every release */ #define PERCONA_INNODB_VERSION 24.1 #endif diff --git a/support-files/rpm/server.cnf b/support-files/rpm/server.cnf index 8cf2c74dbe4..2025a8b811a 100644 --- a/support-files/rpm/server.cnf +++ b/support-files/rpm/server.cnf @@ -1,14 +1,17 @@ # -# These groups are read by MariaDB server +# These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # -[mysqld] - +# this is read by the standalone daemon and embedded servers [server] +# this is only for the mysqld standalone daemon +[mysqld] + +# this is only for embedded server [embedded] # This group is only read by MariaDB-5.5 servers. -- cgit v1.2.1 From db6dbadb5a9edd9e93398b6afe8e3196eb768e0a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Jun 2012 11:33:24 +0300 Subject: Fix bug lp:1008686 Analysis: The fix for bug lp:985667 implements the method Item_subselect::no_rows_in_result() for all main kinds of subqueries. The purpose of this method is to be called from return_zero_rows() and set Items to some default value in the case when a query returns no rows. Aggregates and subqueries require special treatment in this case. Every implementation of Item_subselect::no_rows_in_result() called Item_subselect::make_const() to set the subquery predicate to its default value irrespective of where the predicate was located in the query. Once the predicate was set to a constant it was never executed. At the same time, the JOIN object of the fake select for UNIONs (the one used for the final result of the UNION), was set after all subqueries in the union were executed. Since we set the subquery as constant, it was never executed, and the corresponding JOIN was never created. In order to decide whether the result of NOT IN is NULL or FALSE, Item_in_optimizer needs to check if the subquery result was empty or not. This is where we got the crash, because subselect_union_engine::no_rows() checks for unit->fake_select_lex->join->send_records, and the join object was NULL. Solution: If a subquery is in the HAVING clause it must be evaluated in order to know its result, so that we can properly filter the result records. Once subqueries in the HAVING clause are executed even in the case of no result rows, this specific crash will be solved, because the UNION will be executed, and its JOIN will be constructed. Therefore the fix for this crash is to narrow the fix for lp:985667, and to apply Item_subselect::no_rows_in_result() only when the subquery predicate is in the SELECT clause. --- mysql-test/r/subselect.result | 25 +++++++++++++++++++++ mysql-test/r/subselect_no_mat.result | 25 +++++++++++++++++++++ mysql-test/r/subselect_no_opts.result | 25 +++++++++++++++++++++ mysql-test/r/subselect_no_scache.result | 25 +++++++++++++++++++++ mysql-test/r/subselect_no_semijoin.result | 25 +++++++++++++++++++++ mysql-test/t/subselect.test | 18 ++++++++++++++++ sql/item_subselect.cc | 36 +++++++++++++++++++++++++++---- sql/item_subselect.h | 4 ++-- 8 files changed, 177 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 70096a68a34..024dca5d1bb 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -6112,5 +6112,30 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; f1 f2 drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 671a5df213b..e8c084f9700 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -6111,6 +6111,31 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; f1 f2 drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index e70c07a5894..ace1f198853 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -6107,6 +6107,31 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; f1 f2 drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 253be05cc5b..32f24f9cf14 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -6118,6 +6118,31 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; f1 f2 drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set optimizer_switch=default; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index a6e87097c66..3860bb9fb18 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -6107,6 +6107,31 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; f1 f2 drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index e2d829996b7..a476551ff08 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -5190,5 +5190,23 @@ SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELE drop table t1,t2; +--echo # +--echo # LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +--echo # WHERE and UNION in HAVING +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); + +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; + +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; + +drop table t1; + --echo # return optimizer switch changed in the beginning of this test set optimizer_switch=@subselect_tmp; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 5af8eb9ebc9..16f754575f5 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -892,7 +892,14 @@ void Item_maxmin_subselect::print(String *str, enum_query_type query_type) void Item_maxmin_subselect::no_rows_in_result() { - if (const_item()) + /* + Subquery predicates outside of the SELECT list must be evaluated in order + to possibly filter the special result row generated for implicit grouping + if the subquery is in the HAVING clause. + If the predicate is constant, we need its actual value in the only result + row for queries with implicit grouping. + */ + if (parsing_place != SELECT_LIST || const_item()) return; value= Item_cache::get_cache(new Item_null()); null_value= 0; @@ -903,7 +910,14 @@ void Item_maxmin_subselect::no_rows_in_result() void Item_singlerow_subselect::no_rows_in_result() { - if (const_item()) + /* + Subquery predicates outside of the SELECT list must be evaluated in order + to possibly filter the special result row generated for implicit grouping + if the subquery is in the HAVING clause. + If the predicate is constant, we need its actual value in the only result + row for queries with implicit grouping. + */ + if (parsing_place != SELECT_LIST || const_item()) return; value= Item_cache::get_cache(new Item_null()); reset(); @@ -1367,7 +1381,14 @@ Item* Item_exists_subselect::expr_cache_insert_transformer(uchar *thd_arg) void Item_exists_subselect::no_rows_in_result() { - if (const_item()) + /* + Subquery predicates outside of the SELECT list must be evaluated in order + to possibly filter the special result row generated for implicit grouping + if the subquery is in the HAVING clause. + If the predicate is constant, we need its actual value in the only result + row for queries with implicit grouping. + */ + if (parsing_place != SELECT_LIST || const_item()) return; value= 0; null_value= 0; @@ -2713,7 +2734,14 @@ void Item_allany_subselect::print(String *str, enum_query_type query_type) void Item_allany_subselect::no_rows_in_result() { - if (const_item()) + /* + Subquery predicates outside of the SELECT list must be evaluated in order + to possibly filter the special result row generated for implicit grouping + if the subquery is in the HAVING clause. + If the predicate is constant, we need its actual value in the only result + row for queries with implicit grouping. + */ + if (parsing_place != SELECT_LIST || const_item()) return; value= 0; null_value= 0; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 7f2aa857459..0735df2fb5c 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -147,8 +147,8 @@ public: null_value= 1; } /** - Set the subquery result to the default value for the predicate when the - subquery is known to produce an empty result. + Set the subquery result to a default value consistent with the semantics of + the result row produced for queries with implicit grouping. */ void no_rows_in_result()= 0; virtual bool select_transformer(JOIN *join); -- cgit v1.2.1 From acba7d2f9f131a7726138608fd260ddbf5973f65 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 15 Jun 2012 12:52:58 +0300 Subject: Fixed MDEV-306 / LP:1007967 - Assertion `table->file->stats.records > 0 || error' failed join_read_const_table on concurrent SELECT and DROP/ADD INDEX sql/sql_table.cc: Added comment storage/maria/ma_close.c: Don't store history if it's visible to all. This fixed the MDEV-306 bug storage/maria/ma_delete_table.c: Removed old comment Delete history state for deleted tables storage/maria/ma_info.c: More DBUG_PRINT storage/maria/ma_open.c: More DBUG_PRINT --- sql/sql_table.cc | 3 +++ storage/maria/ma_close.c | 3 ++- storage/maria/ma_delete_table.c | 12 ++++-------- storage/maria/ma_info.c | 1 + storage/maria/ma_open.c | 4 ++++ 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 13411bea8a3..2a1682aee12 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7360,7 +7360,10 @@ err: thd_progress_next_stage(thd); if (error > 0) + { + /* We are going to drop the temporary table */ to->file->extra(HA_EXTRA_PREPARE_FOR_DROP); + } if (errpos >= 3 && to->file->ha_end_bulk_insert() && error <= 0) { to->file->print_error(my_errno,MYF(0)); diff --git a/storage/maria/ma_close.c b/storage/maria/ma_close.c index 973adf2b91e..d1b90dc826e 100644 --- a/storage/maria/ma_close.c +++ b/storage/maria/ma_close.c @@ -193,9 +193,10 @@ int maria_close(register MARIA_HA *info) else share_can_be_freed= TRUE; - if (share->state_history) + if (share->state_history && share->state_history->trid) { MARIA_STATE_HISTORY_CLOSED *history; + DBUG_PRINT("info", ("Storing state history")); /* Here we ignore the unlikely case that we don't have memory to store the state. In the worst case what happens is that any transaction diff --git a/storage/maria/ma_delete_table.c b/storage/maria/ma_delete_table.c index 9e91638fa27..09d5cde5ad0 100644 --- a/storage/maria/ma_delete_table.c +++ b/storage/maria/ma_delete_table.c @@ -38,14 +38,8 @@ int maria_delete_table(const char *name) /** @todo LOCK take X-lock on table */ /* We need to know if this table is transactional. - When built with RAID support, we also need to determine if this table - makes use of the raid feature. If yes, we need to remove all raid - chunks. This is done with my_raid_delete(). Unfortunately it is - necessary to open the table just to check this. We use - 'open_for_repair' to be able to open even a crashed table. If even - this open fails, we assume no raid configuration for this table - and try to remove the normal data file only. This may however - leave the raid chunks behind. + Unfortunately it is necessary to open the table just to check this. We use + 'open_for_repair' to be able to open even a crashed table. */ if (!(info= maria_open(name, O_RDONLY, HA_OPEN_FOR_REPAIR))) { @@ -56,6 +50,8 @@ int maria_delete_table(const char *name) sync_dir= (info->s->now_transactional && !info->s->temporary && !maria_in_recovery) ? MY_SYNC_DIR : 0; + /* Remove history for table */ + _ma_reset_state(info); maria_close(info); } diff --git a/storage/maria/ma_info.c b/storage/maria/ma_info.c index 97b5b8b7f7b..341ea147785 100644 --- a/storage/maria/ma_info.c +++ b/storage/maria/ma_info.c @@ -42,6 +42,7 @@ int maria_status(MARIA_HA *info, register MARIA_INFO *x, uint flag) MY_STAT state; MARIA_SHARE *share= info->s; DBUG_ENTER("maria_status"); + DBUG_PRINT("info", ("records: %lld", info->state->records)); x->recpos= info->cur_row.lastpos; if (flag == HA_STATUS_POS) diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index a526c0d4276..5f90f61c786 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -866,6 +866,9 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) _ma_remove_not_visible_states(history->state_history, 0, 0); history->state_history= 0; (void) my_hash_delete(&maria_stored_state, (uchar*) history); + DBUG_PRINT("info", ("Reading state history. trid: %lu records: %lld", + (ulong) share->state_history->trid, + share->state_history->state.records)); } else { @@ -988,6 +991,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) mysql_mutex_unlock(&THR_LOCK_maria); m_info->open_flags= open_flags; + DBUG_PRINT("exit", ("table: %p name: %s",m_info, name)); DBUG_RETURN(m_info); err: -- cgit v1.2.1 From 7cd1dc5de2051d59798ce50f417f301fa1df356f Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 15 Jun 2012 13:08:10 +0300 Subject: Fix for: lp:1013432 and MySQL#64800: mysqldump with --include-master-host-port putting quotes around port number Patch from Stewart Smith client/mysqldump.c: Remove quotes from MASTER_PORT --- client/mysqldump.c | 2 +- mysql-test/r/rpl_mysqldump_slave.result | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 6834d16bde7..9f34b2556a9 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -4773,7 +4773,7 @@ static int do_show_slave_status(MYSQL *mysql_con) if (row[1]) fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]); if (row[3]) - fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]); + fprintf(md_result_file, "MASTER_PORT=%s, ", row[3]); } fprintf(md_result_file, "MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]); diff --git a/mysql-test/r/rpl_mysqldump_slave.result b/mysql-test/r/rpl_mysqldump_slave.result index 76caab5fcfa..1b13ebb79c1 100644 --- a/mysql-test/r/rpl_mysqldump_slave.result +++ b/mysql-test/r/rpl_mysqldump_slave.result @@ -9,6 +9,6 @@ STOP SLAVE; CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; START SLAVE; STOP SLAVE; -CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT='MASTER_MYPORT', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; +CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; START SLAVE; include/rpl_end.inc -- cgit v1.2.1 From 4a23bb90748cf7274e3058da07a7082072c28a12 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 15 Jun 2012 13:36:34 +0300 Subject: Removed one variable from the test output that was depending on timing. mysql-test/suite/sphinx/sphinx.result: Removed sphinx_time, as it was depending on timing. mysql-test/suite/sphinx/sphinx.test: Removed sphinx_time, as it was depending on timing. --- mysql-test/suite/sphinx/sphinx.result | 7 +++++-- mysql-test/suite/sphinx/sphinx.test | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/sphinx/sphinx.result b/mysql-test/suite/sphinx/sphinx.result index 50f1f513e31..a671028bbe2 100644 --- a/mysql-test/suite/sphinx/sphinx.result +++ b/mysql-test/suite/sphinx/sphinx.result @@ -46,14 +46,17 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition SET optimizer_switch=@save_optimizer_switch; drop table ts; -show status like "sphinx_%"; +show status like "sphinx_error%"; Variable_name Value sphinx_error_commits 0 sphinx_error_group_commits 0 sphinx_error_snapshot_file sphinx_error_snapshot_position 0 -sphinx_time 0 +show status like "sphinx_total%"; +Variable_name Value sphinx_total 2 sphinx_total_found 2 +show status like "sphinx_word%"; +Variable_name Value sphinx_word_count 0 sphinx_words diff --git a/mysql-test/suite/sphinx/sphinx.test b/mysql-test/suite/sphinx/sphinx.test index bc5daec8fe5..648eec07f63 100644 --- a/mysql-test/suite/sphinx/sphinx.test +++ b/mysql-test/suite/sphinx/sphinx.test @@ -26,4 +26,6 @@ explain select * from ts where q=';groupby=attr:gid'; SET optimizer_switch=@save_optimizer_switch; drop table ts; -show status like "sphinx_%"; +show status like "sphinx_error%"; +show status like "sphinx_total%"; +show status like "sphinx_word%"; -- cgit v1.2.1 From 99edca97f453cb88f80a62be1bc8c38b05c9ec79 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 15 Jun 2012 17:21:06 +0200 Subject: MDEV-339, LP1001340 - system_time_zone is wrong on Windows On localized Windows versions, Windows uses localized time zone names and contain non-ASCII characters. non-ASCII characters appear broken when displayed by clients The fix is to declare system_time_zone variable to have UTF8 encoding and to convert tzname to UTF8. --- sql/mysqld.cc | 23 ++++++++++++++++------- sql/sys_vars.cc | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index c001991effc..c01aebf99f9 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3418,14 +3418,23 @@ static int init_common_variables() return 1; #ifdef HAVE_TZNAME - { - struct tm tm_tmp; - localtime_r(&server_start_time,&tm_tmp); - strmake(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0], - sizeof(system_time_zone)-1); + struct tm tm_tmp; + localtime_r(&server_start_time,&tm_tmp); + const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]; +#ifdef _WIN32 + /* + Time zone name may be localized and contain non-ASCII characters, + Convert from ANSI encoding to UTF8. + */ + wchar_t wtz_name[sizeof(system_time_zone)]; + mbstowcs(wtz_name, tz_name, sizeof(system_time_zone)-1); + WideCharToMultiByte(CP_UTF8,0, wtz_name, -1, system_time_zone, + sizeof(system_time_zone) - 1, NULL, NULL); +#else + strmake(system_time_zone, tz_name, sizeof(system_time_zone)-1); +#endif /* _WIN32 */ +#endif /* HAVE_TZNAME */ - } -#endif /* We set SYSTEM time zone as reasonable default and also for failure of my_tz_init() and bootstrap mode. diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index c8af1422388..bbe6d45b533 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2246,7 +2246,7 @@ static char *system_time_zone_ptr; static Sys_var_charptr Sys_system_time_zone( "system_time_zone", "The server system time zone", READ_ONLY GLOBAL_VAR(system_time_zone_ptr), NO_CMD_LINE, - IN_FS_CHARSET, DEFAULT(system_time_zone)); + IN_SYSTEM_CHARSET, DEFAULT(system_time_zone)); static Sys_var_ulong Sys_table_def_size( "table_definition_cache", -- cgit v1.2.1 From a247b12fe6d3356a2f9b115e3cd850bd004b4bd3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 15 Jun 2012 17:22:49 +0200 Subject: MDEV-316 lp:1009085 Assertion failed: warn_item, file item_cmpfunc.cc, line 3613 make sure that find_date_time_item() is called before agg_arg_charsets_for_comparison(). optimize Item_func_conv_charset to avoid conversion if no string result is needed --- mysql-test/r/mdev316.result | 7 +++++++ mysql-test/t/mdev316.test | 6 ++++++ sql/item_cmpfunc.cc | 19 ++++++++++--------- sql/item_strfunc.h | 8 ++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 mysql-test/r/mdev316.result create mode 100644 mysql-test/t/mdev316.test diff --git a/mysql-test/r/mdev316.result b/mysql-test/r/mdev316.result new file mode 100644 index 00000000000..a035f85f106 --- /dev/null +++ b/mysql-test/r/mdev316.result @@ -0,0 +1,7 @@ +set names swe7; +select '' in ('',convert(0,time)); +'' in ('',convert(0,time)) +1 +select case '' when '' then 1 when convert(0,time) then 2 end; +case '' when '' then 1 when convert(0,time) then 2 end +1 diff --git a/mysql-test/t/mdev316.test b/mysql-test/t/mdev316.test new file mode 100644 index 00000000000..376fd9ffc25 --- /dev/null +++ b/mysql-test/t/mdev316.test @@ -0,0 +1,6 @@ +# +# MDEV-316 lp:1009085 Assertion failed: warn_item, file item_cmpfunc.cc, line 3613 +# +set names swe7; +select '' in ('',convert(0,time)); +select case '' when '' then 1 when convert(0,time) then 2 end; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 5f1a863d8fd..e38fe057356 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -3032,6 +3032,11 @@ void Item_func_case::fix_length_and_dec() nagg++; if (!(found_types= collect_cmp_types(agg, nagg))) return; + + Item *date_arg= 0; + if (found_types & (1 << TIME_RESULT)) + date_arg= find_date_time_item(args, arg_count, 0); + if (found_types & (1 << STRING_RESULT)) { /* @@ -3071,16 +3076,12 @@ void Item_func_case::fix_length_and_dec() change_item_tree_if_needed(thd, &args[nagg * 2], agg[nagg + 1]); } - Item *date_arg= 0; for (i= 0; i <= (uint)TIME_RESULT; i++) { if (found_types & (1 << i) && !cmp_items[i]) { DBUG_ASSERT((Item_result)i != ROW_RESULT); - if ((Item_result)i == TIME_RESULT) - date_arg= find_date_time_item(args, arg_count, 0); - if (!(cmp_items[i]= cmp_item::get_comparator((Item_result)i, date_arg, cmp_collation.collation))) @@ -4051,15 +4052,15 @@ void Item_func_in::fix_length_and_dec() } else { + if (found_types & (1 << TIME_RESULT)) + date_arg= find_date_time_item(args, arg_count, 0); + if (found_types & (1 << STRING_RESULT) && + agg_arg_charsets_for_comparison(cmp_collation, args, arg_count)) + return; for (i= 0; i <= (uint) TIME_RESULT; i++) { if (found_types & (1 << i) && !cmp_items[i]) { - if ((Item_result)i == STRING_RESULT && - agg_arg_charsets_for_comparison(cmp_collation, args, arg_count)) - return; - if ((Item_result)i == TIME_RESULT) - date_arg= find_date_time_item(args, arg_count, 0); if (!cmp_items[i] && !(cmp_items[i]= cmp_item::get_comparator((Item_result)i, date_arg, cmp_collation.collation))) diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index ad854b02765..3361464814e 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -854,6 +854,14 @@ public: } } String *val_str(String *); + longlong val_int() + { return args[0]->val_int(); } + double val_real() + { return args[0]->val_real(); } + my_decimal *val_decimal(my_decimal *d) + { return args[0]->val_decimal(d); } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + { return args[0]->get_date(ltime, fuzzydate); } void fix_length_and_dec(); const char *func_name() const { return "convert"; } virtual void print(String *str, enum_query_type query_type); -- cgit v1.2.1 From 6cf8672f432ed3afe71fcbe3cd7a45cec974f729 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 16 Jun 2012 14:58:00 +0200 Subject: fix innodb_bug12902967 to pass when aio check on /dev/shm fails --- mysql-test/suite/innodb/r/innodb_bug12902967.result | 2 +- mysql-test/suite/innodb/t/innodb_bug12902967.test | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb_bug12902967.result b/mysql-test/suite/innodb/r/innodb_bug12902967.result index b20710f08fb..da1d94d69f5 100644 --- a/mysql-test/suite/innodb/r/innodb_bug12902967.result +++ b/mysql-test/suite/innodb/r/innodb_bug12902967.result @@ -1,6 +1,6 @@ create table t1 (f1 integer primary key) engine innodb; alter table t1 add constraint c1 foreign key (f1) references t1(f1); ERROR HY000: Error on rename of '#sql-temporary' to './test/t1' (errno: 150) -InnoDB: which are not compatible with the new table definition. InnoDB: has or is referenced in foreign key constraints +InnoDB: which are not compatible with the new table definition. drop table t1; diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test index e9d832f3c19..1183c4ceff6 100644 --- a/mysql-test/suite/innodb/t/innodb_bug12902967.test +++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test @@ -22,21 +22,9 @@ create table t1 (f1 integer primary key) engine innodb; alter table t1 add constraint c1 foreign key (f1) references t1(f1); --source include/restart_mysqld.inc perl; - -$file = "$ENV{'error_log'}"; -open ( FILE, $file) || die "can't open file! ($file)\n"; -@lines = ; -close (FILE); -$count = 0; -foreach $line (reverse @lines) { - if ($line =~ "^InnoDB:") { - ++$count; - print "$line"; - if ($count == 2) { - last; - } - } -} +$file = $ENV{error_log}; +open (FILE, '<', $file) or die "can't open(< $file): $!\n"; +print ((grep { /^InnoDB:/ and not /aio/i } )[-2..-1]); EOF drop table t1; -- cgit v1.2.1 From b8153269f1df2945953b0c96f7f1c539b2a5a0de Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 17 Jun 2012 16:09:16 +0200 Subject: fix an overly agressive optimization in Item_func_conv_charset --- mysql-test/r/mdev316.result | 15 +++++++++++++++ mysql-test/t/mdev316.test | 8 ++++++++ sql/item_strfunc.h | 24 ++++++++++++++++++++---- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/mdev316.result b/mysql-test/r/mdev316.result index a035f85f106..43082769872 100644 --- a/mysql-test/r/mdev316.result +++ b/mysql-test/r/mdev316.result @@ -5,3 +5,18 @@ select '' in ('',convert(0,time)); select case '' when '' then 1 when convert(0,time) then 2 end; case '' when '' then 1 when convert(0,time) then 2 end 1 +select convert(0x0030 using ucs2) div 1, concat(convert(0x0030 using ucs2)) div 1; +convert(0x0030 using ucs2) div 1 concat(convert(0x0030 using ucs2)) div 1 +0 0 +select cast(convert(0x0030 using ucs2) as double), cast(concat(convert(0x0030 using ucs2)) as double); +cast(convert(0x0030 using ucs2) as double) cast(concat(convert(0x0030 using ucs2)) as double) +0 0 +select cast(convert(0x0030 using ucs2) as decimal(5.2)), cast(concat(convert(0x0030 using ucs2)) as decimal(5.2)); +cast(convert(0x0030 using ucs2) as decimal(5.2)) cast(concat(convert(0x0030 using ucs2)) as decimal(5.2)) +0 0 +select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date); +cast(convert(_ucs2 0x0030 using latin1) as date) cast(concat(convert(_ucs2 0x0030 using latin1)) as date) +NULL NULL +Warnings: +Warning 1292 Incorrect datetime value: '0' +Warning 1292 Incorrect datetime value: '0' diff --git a/mysql-test/t/mdev316.test b/mysql-test/t/mdev316.test index 376fd9ffc25..5843b06a60e 100644 --- a/mysql-test/t/mdev316.test +++ b/mysql-test/t/mdev316.test @@ -4,3 +4,11 @@ set names swe7; select '' in ('',convert(0,time)); select case '' when '' then 1 when convert(0,time) then 2 end; + +# +# Excessive optimization of Item_func_conv_charset: +# +select convert(0x0030 using ucs2) div 1, concat(convert(0x0030 using ucs2)) div 1; +select cast(convert(0x0030 using ucs2) as double), cast(concat(convert(0x0030 using ucs2)) as double); +select cast(convert(0x0030 using ucs2) as decimal(5.2)), cast(concat(convert(0x0030 using ucs2)) as decimal(5.2)); +select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date); diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 3361464814e..eb764bf7791 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -855,13 +855,29 @@ public: } String *val_str(String *); longlong val_int() - { return args[0]->val_int(); } + { + if (args[0]->result_type() == STRING_RESULT) + return Item_str_func::val_int(); + return args[0]->val_int(); + } double val_real() - { return args[0]->val_real(); } + { + if (args[0]->result_type() == STRING_RESULT) + return Item_str_func::val_real(); + return args[0]->val_real(); + } my_decimal *val_decimal(my_decimal *d) - { return args[0]->val_decimal(d); } + { + if (args[0]->result_type() == STRING_RESULT) + return Item_str_func::val_decimal(d); + return args[0]->val_decimal(d); + } bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return args[0]->get_date(ltime, fuzzydate); } + { + if (args[0]->result_type() == STRING_RESULT) + return Item_str_func::get_date(ltime, fuzzydate); + return args[0]->get_date(ltime, fuzzydate); + } void fix_length_and_dec(); const char *func_name() const { return "convert"; } virtual void print(String *str, enum_query_type query_type); -- cgit v1.2.1 From 11f723401c9946910630e7478e5639736630e67e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Jun 2012 14:26:36 +0200 Subject: MDEV-346: 5.5 upgrade test fails on precise. Attempt to make it easier to upgrade mysql->mariadb on Ubuntu precise. It looks like we were missing conflicts: and replaces: on packages mysql-server-5.5 and mysql-client-5.5. --- debian/dist/Debian/control | 7 ++++--- debian/dist/Ubuntu/control | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/debian/dist/Debian/control b/debian/dist/Debian/control index 562459618ec..7a324c93895 100644 --- a/debian/dist/Debian/control +++ b/debian/dist/Debian/control @@ -124,8 +124,9 @@ Provides: virtual-mysql-client, mysql-client, mysql-client-4.1, mysql-client-5.1, mysql-client-5.5 Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, mariadb-client (<< ${source:Version}), - mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 + mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3, mysql-client-5.5 Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, + mysql-client-5.5, mariadb-client (<< ${source:Version}), mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 Description: MariaDB database client binaries @@ -185,10 +186,10 @@ Pre-Depends: mariadb-common, adduser (>= 3.40), debconf Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version}) Provides: mariadb-server, mysql-server, virtual-mysql-server Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), - mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, + mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3 Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), - mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, + mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3, libmariadbclient16 (<< 5.3.4), libmariadbclient-dev (<< 5.5.0) diff --git a/debian/dist/Ubuntu/control b/debian/dist/Ubuntu/control index 8594ee9616b..8a8a93c37aa 100644 --- a/debian/dist/Ubuntu/control +++ b/debian/dist/Ubuntu/control @@ -124,8 +124,9 @@ Provides: virtual-mysql-client, mysql-client, mysql-client-4.1, mysql-client-5.1, mysql-client-5.5 Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, mariadb-client (<< ${source:Version}), - mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 + mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3, mysql-client-5.5 Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, + mysql-client-5.5, mariadb-client (<< ${source:Version}), mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 Description: MariaDB database client binaries @@ -179,10 +180,10 @@ Pre-Depends: mariadb-common, adduser (>= 3.40), debconf Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version}) Provides: mariadb-server, mysql-server, virtual-mysql-server Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), - mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, + mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3 Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), - mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, + mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3, libmariadbclient16 (<< 5.3.4), libmariadbclient-dev (<< 5.5.0) -- cgit v1.2.1 From bdc68e5baf9eafdc1956ff555770b010a6260102 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Mon, 18 Jun 2012 16:57:58 -0400 Subject: various documentation updates --- BUILD-CMAKE | 11 ++++++---- Docs/mysql.info | 7 ++++--- INSTALL-SOURCE | 11 ++++++++++ INSTALL-WIN-SOURCE | 3 ++- KNOWN_BUGS.txt | 50 ++++++++++++++++++++++----------------------- README | 8 ++++---- client/mysql.cc | 2 +- scripts/mysql_install_db.sh | 9 ++++---- 8 files changed, 59 insertions(+), 42 deletions(-) diff --git a/BUILD-CMAKE b/BUILD-CMAKE index 060d2481241..c95482cf619 100644 --- a/BUILD-CMAKE +++ b/BUILD-CMAKE @@ -1,6 +1,7 @@ Copyright (c) 2009, 2010 Sun Microsystems, Inc. +Copyright (c) 2012 Monty Program Ab -How to Build MySQL server with CMake +How to Build MariaDB server with CMake WHAT YOU NEED --------------------------------------------------------------- @@ -11,7 +12,7 @@ HOW TO INSTALL: Linux distributions: shell> sudo apt-get install cmake -The above works on do Debian/Ubuntu based distributions.On others, command +The above works on Debian/Ubuntu based distributions. On others, the command line needs to be modified to e.g "yum install" on Fedora or "zypper install" on OpenSUSE. @@ -20,8 +21,9 @@ shell> pfexec pkgadd install SUNWcmake Windows and Mac OSX: Download and install the latest distribution from -http://www.cmake.org/cmake/resources/software.html.On Windows, download -installer exe file and run it. On Mac, download the .dmg image and open it. +http://www.cmake.org/cmake/resources/software.html +On Windows, download installer exe file and run it. On MacOS, download +the .dmg image and open it. Other Unixes: Precompiled packages for other Unix flavors (HPUX, AIX) are available from @@ -243,3 +245,4 @@ later corrected, the cached result is still used. If you encounter this situation, which should be a rare occation, you need either to remove the offending entry from CMakeCache.txt (if test was for HAVE_FOO, remove lines containing HAVE_FOO from CMakeCache.txt) or just remove the cache file. + diff --git a/Docs/mysql.info b/Docs/mysql.info index 3b9d298a684..95d97438993 100644 --- a/Docs/mysql.info +++ b/Docs/mysql.info @@ -1,10 +1,11 @@ MariaDB is in most aspects identical to MySQL. Differences between MySQL and MariaDB can be found at: -http://askmonty.org/wiki/index.php/MariaDB_versus_MySQL +http://kb.askmonty.org/en/mariadb-versus-mysql-features/ +http://kb.askmonty.org/en/mariadb-versus-mysql-compatibility/ -The MariaDB references manual can be found at: -http://askmonty.org/wiki/index.php/Manual +The MariaDB manual can be found at: +http://kb.askmonty.org/ The MySQL Reference Manual is available in various formats on http://dev.mysql.com/doc; if you're interested in the DocBook XML diff --git a/INSTALL-SOURCE b/INSTALL-SOURCE index cfcc285cf67..b6f4fe546c7 100644 --- a/INSTALL-SOURCE +++ b/INSTALL-SOURCE @@ -1,3 +1,14 @@ +Installing and Upgrading MariaDB + +This file contains chapter two of the MySQL manual and describes how +to obtain and install MySQL. The instructions below are generally +applicable to both MySQL and MariaDB, but differ in some particulars +(like, for example, the GPG signing key we use is different). + +Detailed, MariaDB-specific instructions are available at: +http://kb.askmonty.org/en/getting-installing-and-upgrading-mariadb/ + +- - - - Chapter 2. Installing and Upgrading MySQL diff --git a/INSTALL-WIN-SOURCE b/INSTALL-WIN-SOURCE index 2e77959d69c..269bc2c3d1c 100644 --- a/INSTALL-WIN-SOURCE +++ b/INSTALL-WIN-SOURCE @@ -1,2 +1,3 @@ -Up-to-date instructions on MariaDB building on Windows can be found in http://kb.askmonty.org/en/building-mariadb-on-windows. +Up-to-date instructions about building MariaDB on Windows can be found +at: http://kb.askmonty.org/en/building-mariadb-on-windows diff --git a/KNOWN_BUGS.txt b/KNOWN_BUGS.txt index 38472fc978c..56c9102b0cd 100644 --- a/KNOWN_BUGS.txt +++ b/KNOWN_BUGS.txt @@ -1,35 +1,35 @@ -This file should contain all know fatal bugs in the Mariadb and the -Maria storage engine for the last source or binary release. Minor -bugs, extensions and feature request and bugs found since this release -can be find in the MariaDB bugs database at: -https://bugs.launchpad.net/maria and in the MySQL bugs databases at: -http://bugs.mysql.com/ (category "Maria storage engine"). +This file should contain all known fatal bugs in Mariadb and the Aria +storage engine for the last source or binary release. Minor bugs, +extensions and feature requests, and bugs found since this release can +be found in the MariaDB bugs database at: http://mariadb.org/jira and +in the MySQL bugs databases at: http://bugs.mysql.com/ (category +"Maria storage engine"). -There shouldn't normally be any bugs that affects normal operations in -any MariaDB release. Still, there are always exceptions and edge cases -and that's what this file is for. +There should not normally be any bugs which affect normal operations +in any MariaDB release. Still, there are always exceptions and edge +cases and that is what this file is for. If you have found a bug that is not listed here, please add it to -http://bugs.launchpad.net/maria so that we can either fix it for next -release or in the worst case add it here for others to know! +http://mariadb.org/jira so we can either fix it for next release or in +the worst case add it here for others to know! + IMPORTANT: -If you have been using the Maria storage engine with -MySQL-5.1-Maria-alpha build and upgrading to a newer MariaDB you MUST -run maria_chk --recover on all your Maria tables. This is because we -made an incompatible change of how transaction id is stored and old -transaction id's must be reset! +If you have been using the Maria (now Aria) storage engine with the +MySQL-5.1-Maria-alpha build and are upgrading to a newer MariaDB you +MUST run [m]aria_chk --recover on all your Aria tables. This is because +we made an incompatible change with how the transaction id is stored +and old transaction id's must be reset! cd mysql-data-directory -maria_chk --recover */*.MAI +aria_chk --recover */*.MAI -As the Maria storage engine is now in beta we will do our best to not -introduce any incompatible changes in the data format for the Maria -tables; If this would be ever be needed, we will, if possible, support -both the old and the new version to make upgrades as easy as possible. +Going forward, we will do our best to not introduce any incompatible +changes in the data format for Aria tables. If this would be ever be +needed, we will, if possible, support both the old and the new version +to make upgrades as easy as possible. -Note that for the MariaDB 5.1 release the Maria storage engine is -classified as 'beta'; It should work, but use it with caution. Please -report all bugs to https://bugs.launchpad.net/maria so that we can fix -them! +Note that for the MariaDB 5.1 release the Aria storage engine is +classified as 'beta'; It should work, but use it with caution. Please +report all bugs to http://mariadb.org/jira so we can fix them! diff --git a/README b/README index c6624cf43fa..7daeec0495f 100644 --- a/README +++ b/README @@ -13,9 +13,9 @@ see the Credits appendix. You can also do 'SHOW authors' to get a list of active contributors. A description of the MariaDB project and a manual can be found at: -http://askmonty.org/wiki/index.php/MariaDB -http://askmonty.org/wiki/index.php/MariaDB_versus_MySQL -http://askmonty.org/wiki/index.php/Manual:Contents +http://kb.askmonty.org/ +http://kb.askmonty.org/en/mariadb-versus-mysql-features/ +http://kb.askmonty.org/en/mariadb-versus-mysql-compatibility/ As MariaDB is a full replacement of MySQL, the MySQL manual at http://dev.mysql.com/doc is generally applicable. @@ -41,7 +41,7 @@ EXCEPTIONS-CLIENT file. IMPORTANT: Bug and/or error reports regarding MariaDB should be submitted at -https://bugs.launchpad.net/maria +http://mariadb.org/jira Bugs in the MySQL code can also be submitted at http://bugs.mysql.com diff --git a/client/mysql.cc b/client/mysql.cc index e74495dcf8d..d39e765a99a 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2916,7 +2916,7 @@ com_help(String *buffer __attribute__((unused)), } put_info("\nGeneral information about MariaDB can be found at\n" - "http://askmonty.org/wiki/index.php/Manual:Contents\n", INFO_INFO); + "http://mariadb.org\n", INFO_INFO); put_info("List of all MySQL commands:", INFO_INFO); if (!named_cmds) put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO); diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 1dd6b787c43..0ed94d0ffa3 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -484,7 +484,8 @@ then echo "databases and anonymous user created by default. This is" echo "strongly recommended for production servers." echo - echo "See the MariaDB knowledge or the MySQL manual for more instructions." + echo "See the MariaDB Knowledgebase at http://kb.askmonty.org or the" + echo "MySQL manual for more instructions." if test "$in_rpm" -eq 0 then @@ -499,13 +500,13 @@ then echo echo "Please report any problems with the $scriptdir/mysqlbug script!" echo - echo "The latest information about MariaDB is available at http://www.askmonty.org/." + echo "The latest information about MariaDB is available at http://mariadb.org/." echo "You can find additional information about the MySQL part at:" echo "http://dev.mysql.com" echo "Support MariaDB development by buying support/new features from" - echo "Monty Program Ab. You can contact us about this at sales@askmonty.org". + echo "Monty Program Ab. You can contact us about this at sales@montyprogram.com". echo "Alternatively consider joining our community based development effort:" - echo "http://askmonty.org/wiki/index.php/MariaDB#How_can_I_participate_in_the_development_of_MariaDB" + echo "http://kb.askmonty.org/en/contributing-to-the-mariadb-project/" echo fi -- cgit v1.2.1 From 37f8094652c438360b66aa04a46acb96d3eea6b7 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Mon, 18 Jun 2012 17:29:05 -0400 Subject: fixed some urls that the previous update missed --- Docs/INSTALL-BINARY | 2 +- mysql-test/README | 6 +++--- sql/mysql_install_db.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Docs/INSTALL-BINARY b/Docs/INSTALL-BINARY index 01ac65950a9..7ff33c7051e 100644 --- a/Docs/INSTALL-BINARY +++ b/Docs/INSTALL-BINARY @@ -31,7 +31,7 @@ also applies. first. If you run into problems and need to file a bug report, - please report them to: http://bugs.launchpad.net/maria + please report them to: http://mariadb.org/jira See the instructions in Section 1.6, "How to Report Bugs or Problems." diff --git a/mysql-test/README b/mysql-test/README index 0e147f83bd1..162551ad69c 100644 --- a/mysql-test/README +++ b/mysql-test/README @@ -69,10 +69,10 @@ extension. For example: If you want to submit your test case you can send it to maria-developers@lists.launchpad.com or attach it to a bug report on -https://bugs.launchpad.net/maria/. +http://mariadb.org/jira/. If the test case is really big or if it contains 'not public' data, then put your .test file and .result file(s) into a tar.gz archive, add a README that explains the problem, ftp the archive to -ftp://ftp.askmonty.org/private and send a mail to -https://bugs.launchpad.net/maria/ about it. +ftp://ftp.askmonty.org/private and submit a report to +http://mariadb.org/jira about it. diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 364dca9120a..bde81d915b2 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -119,8 +119,8 @@ static void die(const char *fmt, ...) fprintf(stderr, "http://kb.askmonty.org/v/installation-issues-on-windows contains some help\n" "for solving the most common problems. If this doesn't help you, please\n" - "leave a comment in the knowledge base or file a bug report at\n" - "https://bugs.launchpad.net/maria"); + "leave a comment in the Knowledgebase or file a bug report at\n" + "http://mariadb.org/jira"); } fflush(stderr); va_end(args); -- cgit v1.2.1 From 0c69f22032abd6f162829ee31c5ee7d34b84e107 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 18 Jun 2012 22:32:17 -0700 Subject: Fixed bug mdev-354. Virtual columns of ENUM and SET data types were not supported properly in the original patch that introduced virtual columns into MariaDB 5.2. The problem was that for any virtual column the patch used the interval_id field of the definition of the column in the frm file as a reference to the virtual column expression. The fix stores the optional interval_id of the virtual column in the extended header of the virtual column expression. --- mysql-test/suite/vcol/r/vcol_misc.result | 36 ++++++++++++++++++++++++++++++++ mysql-test/suite/vcol/t/vcol_misc.test | 24 +++++++++++++++++++++ sql/field.h | 4 ++++ sql/table.cc | 20 ++++++++++++------ sql/unireg.cc | 23 ++++++++++++-------- sql/unireg.h | 5 +---- 6 files changed, 93 insertions(+), 19 deletions(-) diff --git a/mysql-test/suite/vcol/r/vcol_misc.result b/mysql-test/suite/vcol/r/vcol_misc.result index d5061fa4d5f..a4b2cee4bf6 100644 --- a/mysql-test/suite/vcol/r/vcol_misc.result +++ b/mysql-test/suite/vcol/r/vcol_misc.result @@ -146,3 +146,39 @@ table_schema table_name column_name column_type extra test t2 a int(11) test t2 b int(11) VIRTUAL DROP TABLE t1,t2; +create table t1 ( +a int not null, b char(2) not null, +c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent +); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` char(2) NOT NULL, + `c` enum('Y','N') AS (case when b = 'aa' then 'Y' else 'N' end) PERSISTENT +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc'); +select * from t1; +a b c +1 bb N +2 aa Y +3 cc N +create table t2 ( +a int, b int, +c set("y","n") +as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent +); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` set('y','n') AS (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) PERSISTENT +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t2(a,b) values (7,0), (2,3), (0,1); +select * from t2; +a b c +7 0 y,n +2 3 y +0 1 y,n +drop table t1,t2; diff --git a/mysql-test/suite/vcol/t/vcol_misc.test b/mysql-test/suite/vcol/t/vcol_misc.test index 495432fdb4c..732003da992 100644 --- a/mysql-test/suite/vcol/t/vcol_misc.test +++ b/mysql-test/suite/vcol/t/vcol_misc.test @@ -154,3 +154,27 @@ SELECT table_schema, table_name, column_name, column_type, extra FROM information_schema.columns WHERE table_name = 't2'; DROP TABLE t1,t2; + + +# +# Bug mdev-354: virtual columns of ENUM and SET types +# + +create table t1 ( + a int not null, b char(2) not null, + c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent +); +show create table t1; +insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc'); +select * from t1; + +create table t2 ( + a int, b int, + c set("y","n") + as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent +); +show create table t2; +insert into t2(a,b) values (7,0), (2,3), (0,1); +select * from t2; + +drop table t1,t2; diff --git a/sql/field.h b/sql/field.h index 3cfcf308282..308ef788f9e 100644 --- a/sql/field.h +++ b/sql/field.h @@ -2199,6 +2199,10 @@ public: { return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0; } + uint virtual_col_expr_maxlen() + { + return 255 - FRM_VCOL_HEADER_SIZE(interval != NULL); + } }; diff --git a/sql/table.cc b/sql/table.cc index 5b1db9ef1e4..d950b7a3a4e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1257,25 +1257,33 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, { /* Get virtual column data stored in the .frm file as follows: - byte 1 = 1 (always 1 to allow for future extensions) + byte 1 = 1 | 2 byte 2 = sql_type byte 3 = flags (as of now, 0 - no flags, 1 - field is physically stored) - byte 4-... = virtual column expression (text data) + [byte 4] = optional interval_id for sql_type (only if byte 1 == 2) + next byte ... = virtual column expression (text data) */ vcol_info= new Virtual_column_info(); - if ((uint)vcol_screen_pos[0] != 1) + bool opt_interval_id= (uint)vcol_screen_pos[0] == 2; + field_type= (enum_field_types) (uchar) vcol_screen_pos[1]; + if (opt_interval_id) + interval_nr= (uint)vcol_screen_pos[3]; + else if ((uint)vcol_screen_pos[0] != 1) { error= 4; goto free_and_err; } - field_type= (enum_field_types) (uchar) vcol_screen_pos[1]; fld_stored_in_db= (bool) (uint) vcol_screen_pos[2]; - vcol_expr_length= vcol_info_length-(uint)FRM_VCOL_HEADER_SIZE; + vcol_expr_length= vcol_info_length - + (uint)(FRM_VCOL_HEADER_SIZE(opt_interval_id)); if (!(vcol_info->expr_str.str= (char *)memdup_root(&share->mem_root, - vcol_screen_pos+(uint)FRM_VCOL_HEADER_SIZE, + vcol_screen_pos + + (uint) FRM_VCOL_HEADER_SIZE(opt_interval_id), vcol_expr_length))) goto free_and_err; + if (opt_interval_id) + interval_nr= (uint) vcol_screen_pos[3]; vcol_info->expr_str.length= vcol_expr_length; vcol_screen_pos+= vcol_info_length; share->vfields++; diff --git a/sql/unireg.cc b/sql/unireg.cc index dde755462dd..537066fa528 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -670,18 +670,19 @@ static bool pack_header(uchar *forminfo, enum legacy_db_type table_type, } if (field->vcol_info) { + uint col_expr_maxlen= field->virtual_col_expr_maxlen(); tmp_len= system_charset_info->cset->charpos(system_charset_info, field->vcol_info->expr_str.str, field->vcol_info->expr_str.str + field->vcol_info->expr_str.length, - VIRTUAL_COLUMN_EXPRESSION_MAXLEN); + col_expr_maxlen); if (tmp_len < field->vcol_info->expr_str.length) { my_error(ER_WRONG_STRING_LENGTH, MYF(0), field->vcol_info->expr_str.str,"VIRTUAL COLUMN EXPRESSION", - (uint) VIRTUAL_COLUMN_EXPRESSION_MAXLEN); + col_expr_maxlen); DBUG_RETURN(1); } /* @@ -690,7 +691,7 @@ static bool pack_header(uchar *forminfo, enum legacy_db_type table_type, expressions saved in the frm file for virtual columns. */ vcol_info_length+= field->vcol_info->expr_str.length+ - (uint)FRM_VCOL_HEADER_SIZE; + FRM_VCOL_HEADER_SIZE(field->interval!=NULL); } totlength+= field->length; @@ -886,8 +887,9 @@ static bool pack_fields(File file, List &create_fields, the additional data saved for the virtual field */ buff[12]= cur_vcol_expr_len= field->vcol_info->expr_str.length + - (uint)FRM_VCOL_HEADER_SIZE; - vcol_info_length+= cur_vcol_expr_len+(uint)FRM_VCOL_HEADER_SIZE; + FRM_VCOL_HEADER_SIZE(field->interval!=NULL); + vcol_info_length+= cur_vcol_expr_len + + FRM_VCOL_HEADER_SIZE(field->interval!=NULL); buff[13]= (uchar) MYSQL_TYPE_VIRTUAL; } int2store(buff+15, field->comment.length); @@ -992,17 +994,20 @@ static bool pack_fields(File file, List &create_fields, { /* Pack each virtual field as follows: - byte 1 = 1 (always 1 to allow for future extensions) + byte 1 = interval_id == 0 ? 1 : 2 byte 2 = sql_type byte 3 = flags (as of now, 0 - no flags, 1 - field is physically stored) - byte 4-... = virtual column expression (text data) + [byte 4] = possible interval_id for sql_type + next byte ... = virtual column expression (text data) */ if (field->vcol_info && field->vcol_info->expr_str.length) { - buff[0]= (uchar)1; + buff[0]= (uchar)(1 + test(field->interval_id)); buff[1]= (uchar) field->sql_type; buff[2]= (uchar) field->stored_in_db; - if (my_write(file, buff, 3, MYF_RW)) + if (field->interval_id) + buff[3]= (uchar) field->interval_id; + if (my_write(file, buff, 3 + test(field->interval_id), MYF_RW)) DBUG_RETURN(1); if (my_write(file, (uchar*) field->vcol_info->expr_str.str, diff --git a/sql/unireg.h b/sql/unireg.h index b22ec23cd51..64763992537 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -214,10 +214,7 @@ #define DEFAULT_KEY_CACHE_NAME "default" /* The length of the header part for each virtual column in the .frm file */ -#define FRM_VCOL_HEADER_SIZE 3 - -/* Maximum length of the defining expression for a virtual columns */ -#define VIRTUAL_COLUMN_EXPRESSION_MAXLEN 255 - FRM_VCOL_HEADER_SIZE +#define FRM_VCOL_HEADER_SIZE(b) (3 + test(b)) /* Include prototypes for unireg */ -- cgit v1.2.1 From 584d923c3292395a2e8288adcf4795992789f27c Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 20 Jun 2012 13:41:31 +0400 Subject: Post-merge fixes: - put back the result encoding in func_in.result (messed up by kdiff3) - update .result for other tests (checked) --- mysql-test/r/derived_view.result | 4 ++-- mysql-test/r/func_in.result | 5 +++-- mysql-test/r/negation_elimination.result | 2 +- mysql-test/r/view.result | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 9e6d6db9314..a4f7a71dcb5 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -1672,7 +1672,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) Warnings: -Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(multiple equal(NULL, `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and `test`.`t2`.`b`) +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(multiple equal(NULL, `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`b` <> 0)) SELECT t.b, t.c, t1.a FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t WHERE t.b AND t.c = t1.a; @@ -1703,7 +1703,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on((`test`.`t3`.`b` = `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and `test`.`t2`.`b`) +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on((`test`.`t3`.`b` = `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`b` <> 0)) SELECT t.b, t.c, t1.a FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t WHERE t.b AND t.c = t1.a; diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index f6d50764cc9..d25dcd40117 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -150,8 +150,8 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` A drop table t1; set names utf8; create table t1 (a char(10) character set utf8 not null); -insert into t1 values ('bbbb'),(_koi8r'ÃÃÃÃ'),(_latin1'ÄÄÄÄ'); -select a from t1 where a in ('bbbb',_koi8r'ÃÃÃÃ',_latin1'ÄÄÄÄ') order by a; +insert into t1 values ('bbbb'),(_koi8r'ÃÃÃÃ'),(_latin1'ÄÄÄÄ'); +select a from t1 where a in ('bbbb',_koi8r'ÃÃÃÃ',_latin1'ÄÄÄÄ') order by a; a ÄÄÄÄ bbbb @@ -811,3 +811,4 @@ a b select * from t1 where IF(1,a,a)='2.1'; a b drop table t1; +# End of 5.3 tests diff --git a/mysql-test/r/negation_elimination.result b/mysql-test/r/negation_elimination.result index d32f8a0c3f9..aea6518b676 100644 --- a/mysql-test/r/negation_elimination.result +++ b/mysql-test/r/negation_elimination.result @@ -321,7 +321,7 @@ select * from t1 where not(NULL or a); a explain select * from t1 where not(NULL and a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a a 5 const 1 Using where; Using index +1 SIMPLE t1 ref a a 5 const 1 Using index select * from t1 where not(NULL and a); a 0 diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index a1b36c323c7..86ebc9a8ee7 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -4207,13 +4207,13 @@ MM ZZ ZZ Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'VV' +Warning 1292 Truncated incorrect DOUBLE value: 'VV' EXPLAIN EXTENDED SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'VV' +Warning 1292 Truncated incorrect DOUBLE value: 'VV' Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 'JJ') DROP VIEW v1; DROP TABLE t1; -- cgit v1.2.1 From 4f703fe70ba65056971cfcce979fc3407f921288 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 20 Jun 2012 14:37:37 +0300 Subject: Fixed MDEV-348: 5.5 valgrind warinings on maria tests --- storage/maria/ma_close.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/storage/maria/ma_close.c b/storage/maria/ma_close.c index d1b90dc826e..c355f1f1def 100644 --- a/storage/maria/ma_close.c +++ b/storage/maria/ma_close.c @@ -193,23 +193,29 @@ int maria_close(register MARIA_HA *info) else share_can_be_freed= TRUE; - if (share->state_history && share->state_history->trid) + if (share->state_history) { - MARIA_STATE_HISTORY_CLOSED *history; - DBUG_PRINT("info", ("Storing state history")); - /* - Here we ignore the unlikely case that we don't have memory to - store the state. In the worst case what happens is that any transaction - that tries to access this table will get a wrong status information. - */ - if ((history= (MARIA_STATE_HISTORY_CLOSED *) - my_malloc(sizeof(*history), MYF(MY_WME)))) + if (share->state_history->trid) /* If not visible for all */ { - history->create_rename_lsn= share->state.create_rename_lsn; - history->state_history= share->state_history; - if (my_hash_insert(&maria_stored_state, (uchar*) history)) - my_free(history); + MARIA_STATE_HISTORY_CLOSED *history; + DBUG_PRINT("info", ("Storing state history")); + /* + Here we ignore the unlikely case that we don't have memory + to store the state. In the worst case what happens is that + any transaction that tries to access this table will get a + wrong status information. + */ + if ((history= (MARIA_STATE_HISTORY_CLOSED *) + my_malloc(sizeof(*history), MYF(MY_WME)))) + { + history->create_rename_lsn= share->state.create_rename_lsn; + history->state_history= share->state_history; + if (my_hash_insert(&maria_stored_state, (uchar*) history)) + my_free(history); + } } + else + my_free(share->state_history); /* Marker for concurrent checkpoint */ share->state_history= 0; } -- cgit v1.2.1 From 166d4c1feb24b2d819af0b13fbf5dbad2b48c731 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Jun 2012 14:23:23 +0200 Subject: Fix memory leak introduced with merge of mysql 5.5. MySQL introduced a class Deferred_log_events. This class keeps a pointer last_added. The code was keeping this pointer around even after the memory pointed to was freed, and later comparing the bogus pointer against other allocated memory. This is illegal, and can randomly produce false equal comparisons depending on whatever the malloc() subsystem decides to return. --- sql/rpl_utility.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index 8b5df149539..388a6c9f9bb 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -1174,6 +1174,7 @@ void Deferred_log_events::rewind() freeze_size(&array); reset_dynamic(&array); } + last_added= NULL; } #endif -- cgit v1.2.1 From 20de3c896819016f55f14e37245c60f721834d40 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 20 Jun 2012 22:30:24 +0400 Subject: Update test results. --- mysql-test/suite/pbxt/r/negation_elimination.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/pbxt/r/negation_elimination.result b/mysql-test/suite/pbxt/r/negation_elimination.result index 0818d2b812e..886a4215d11 100644 --- a/mysql-test/suite/pbxt/r/negation_elimination.result +++ b/mysql-test/suite/pbxt/r/negation_elimination.result @@ -321,7 +321,7 @@ select * from t1 where not(NULL or a); a explain select * from t1 where not(NULL and a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a a 5 const 1 Using where; Using index +1 SIMPLE t1 ref a a 5 const 1 Using index select * from t1 where not(NULL and a); a 0 -- cgit v1.2.1 From 49cadc9114ab41cd853727c1b38b26fa901c49ca Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 21 Jun 2012 00:49:24 +0200 Subject: MDEV-361 - Fix handle leak in os_thread_create (Windows) --- storage/innobase/os/os0thread.c | 6 ++++-- storage/xtradb/os/os0thread.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/storage/innobase/os/os0thread.c b/storage/innobase/os/os0thread.c index 12b6805d98e..b19b5378fcd 100644 --- a/storage/innobase/os/os0thread.c +++ b/storage/innobase/os/os0thread.c @@ -136,8 +136,10 @@ os_thread_create( if (thread_id) { *thread_id = win_thread_id; } - - return(thread); + if (thread) { + CloseHandle(thread); + } + return((os_thread_t)win_thread_id); #else int ret; os_thread_t pthread; diff --git a/storage/xtradb/os/os0thread.c b/storage/xtradb/os/os0thread.c index 12b6805d98e..b19b5378fcd 100644 --- a/storage/xtradb/os/os0thread.c +++ b/storage/xtradb/os/os0thread.c @@ -136,8 +136,10 @@ os_thread_create( if (thread_id) { *thread_id = win_thread_id; } - - return(thread); + if (thread) { + CloseHandle(thread); + } + return((os_thread_t)win_thread_id); #else int ret; os_thread_t pthread; -- cgit v1.2.1 From 39005ea06f1c5d0aa9d7e55c8f4000477f26b74b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 21 Jun 2012 11:26:53 +0200 Subject: MDEV-349 5.5 xtradb innodb_prefix_index_liftedlimit crash with valgrind This is XtraDB bug lp:1015109, introduced by innodb_split_buf_pool_mutex.patch Comment the offending assertion, until the fixed XtraDB is available --- storage/xtradb/buf/buf0lru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/xtradb/buf/buf0lru.c b/storage/xtradb/buf/buf0lru.c index bf61f4e05f5..f7b5db2d0cc 100644 --- a/storage/xtradb/buf/buf0lru.c +++ b/storage/xtradb/buf/buf0lru.c @@ -861,7 +861,7 @@ buf_LRU_insert_zip_clean( buf_pool_t* buf_pool = buf_pool_from_bpage(bpage); //ut_ad(buf_pool_mutex_own(buf_pool)); - ut_ad(mutex_own(&buf_pool->LRU_list_mutex)); + //ut_ad(mutex_own(&buf_pool->LRU_list_mutex)); ut_ad(mutex_own(&buf_pool->zip_mutex)); ut_ad(buf_page_get_state(bpage) == BUF_BLOCK_ZIP_PAGE); -- cgit v1.2.1 From 5e13093df198bc171e1e43c03a36970ecf9a77f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Jun 2012 11:52:54 +0200 Subject: MDEV-359: Server crash when SET GLOBAL rpl_semi_sync_master_enabled = OFF The semisync code does a fast-but-unsafe check for enabled or not without lock, followed by a slow-but-safe check under lock. However, if the slow check failed, the code still referenced not valid data (in an assert() expression), causing a crash. Fixed by not running the incorrect assert when semisync is disabled. --- mysql-test/suite/rpl/r/rpl_mdev359.result | 13 +++++++++++ mysql-test/suite/rpl/t/rpl_mdev359.test | 36 +++++++++++++++++++++++++++++++ plugin/semisync/semisync_master.cc | 3 ++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_mdev359.result create mode 100644 mysql-test/suite/rpl/t/rpl_mdev359.test diff --git a/mysql-test/suite/rpl/r/rpl_mdev359.result b/mysql-test/suite/rpl/r/rpl_mdev359.result new file mode 100644 index 00000000000..15db17c86b3 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_mdev359.result @@ -0,0 +1,13 @@ +include/master-slave.inc +[connection master] +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; +SET GLOBAL rpl_semi_sync_master_enabled = ON; +SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont"; +INSERT INTO t1 SELECT * FROM t1; +SET DEBUG_SYNC= "now WAIT_FOR m1_ready"; +SET GLOBAL rpl_semi_sync_master_enabled = OFF; +SET DEBUG_SYNC= "now SIGNAL m1_cont"; +DROP TABLE t1; +UNINSTALL PLUGIN rpl_semi_sync_master; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_mdev359.test b/mysql-test/suite/rpl/t/rpl_mdev359.test new file mode 100644 index 00000000000..27990a36188 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_mdev359.test @@ -0,0 +1,36 @@ +--source include/have_semisync_plugin.inc +--source include/not_embedded.inc +--source include/have_binlog_format_mixed_or_statement.inc +--source include/master-slave.inc +--source include/have_debug_sync.inc + +# MDEV-359: There was a server crash when the code first checks if semisync +# is enabled without lock, then if so takes the lock and tests again. +# If semisync was disabled in-between the first and the second test, an +# assert was incorrectly made that referenced a NULL pointer. +# +# This tests uses debug_sync to pause one thread at the critical point in +# the code, disable the semisync, and then continue the paused thread. + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; +SET GLOBAL rpl_semi_sync_master_enabled = ON; +--connection master1 +SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont"; +--send +INSERT INTO t1 SELECT * FROM t1; +--connection master +SET DEBUG_SYNC= "now WAIT_FOR m1_ready"; +SET GLOBAL rpl_semi_sync_master_enabled = OFF; +SET DEBUG_SYNC= "now SIGNAL m1_cont"; +--connection master1 +--reap + +connection master; +DROP TABLE t1; + +disable_warnings; +UNINSTALL PLUGIN rpl_semi_sync_master; +enable_warnings; + +--source include/rpl_end.inc diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc index 9e857f83d39..cb60d8e67d3 100644 --- a/plugin/semisync/semisync_master.cc +++ b/plugin/semisync/semisync_master.cc @@ -608,6 +608,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, set_timespec(start_ts, 0); + DEBUG_SYNC(current_thd, "rpl_semisync_master_commit_trx_before_lock"); /* Acquire the mutex. */ lock(); @@ -738,7 +739,6 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, } } - l_end: /* At this point, the binlog file and position of this transaction must have been removed from ActiveTranx. @@ -747,6 +747,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, !active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name, trx_wait_binlog_pos)); + l_end: /* Update the status counter. */ if (is_on()) rpl_semi_sync_master_yes_transactions++; -- cgit v1.2.1 From eeea010fdc9248acb3dc8c58762fb4f697fc00fd Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 21 Jun 2012 14:33:36 +0400 Subject: Update test results (checked) --- mysql-test/suite/pbxt/r/read_only.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/pbxt/r/read_only.result b/mysql-test/suite/pbxt/r/read_only.result index 2eecb0a891d..32648cebfcc 100644 --- a/mysql-test/suite/pbxt/r/read_only.result +++ b/mysql-test/suite/pbxt/r/read_only.result @@ -48,7 +48,7 @@ unlock tables ; set global read_only=1; select @@global.read_only; @@global.read_only -0 +1 unlock tables ; select @@global.read_only; @@global.read_only @@ -62,7 +62,7 @@ unlock tables ; set global read_only=1; select @@global.read_only; @@global.read_only -0 +1 unlock tables ; select @@global.read_only; @@global.read_only -- cgit v1.2.1 From c2ca301cd8a5bee80a03ef3da04c02d83b2e9685 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 21 Jun 2012 14:00:19 +0200 Subject: fixing the order of includes in the rpl_mdev359.test --- mysql-test/suite/rpl/t/rpl_mdev359.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/t/rpl_mdev359.test b/mysql-test/suite/rpl/t/rpl_mdev359.test index 27990a36188..4f8cc378973 100644 --- a/mysql-test/suite/rpl/t/rpl_mdev359.test +++ b/mysql-test/suite/rpl/t/rpl_mdev359.test @@ -1,8 +1,8 @@ --source include/have_semisync_plugin.inc --source include/not_embedded.inc --source include/have_binlog_format_mixed_or_statement.inc ---source include/master-slave.inc --source include/have_debug_sync.inc +--source include/master-slave.inc # MDEV-359: There was a server crash when the code first checks if semisync # is enabled without lock, then if so takes the lock and tests again. -- cgit v1.2.1 From 14b756c7392daecefdf025d8a06998279926aaf2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 21 Jun 2012 17:39:21 +0200 Subject: Use the portable form of INSTALL PLUGIN in rpl_mdev359.test --- mysql-test/suite/rpl/r/rpl_mdev359.result | 2 +- mysql-test/suite/rpl/t/rpl_mdev359.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_mdev359.result b/mysql-test/suite/rpl/r/rpl_mdev359.result index 15db17c86b3..f4382f672e4 100644 --- a/mysql-test/suite/rpl/r/rpl_mdev359.result +++ b/mysql-test/suite/rpl/r/rpl_mdev359.result @@ -1,7 +1,7 @@ include/master-slave.inc [connection master] CREATE TABLE t1 (a INT) ENGINE=MyISAM; -INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; +INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master'; SET GLOBAL rpl_semi_sync_master_enabled = ON; SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont"; INSERT INTO t1 SELECT * FROM t1; diff --git a/mysql-test/suite/rpl/t/rpl_mdev359.test b/mysql-test/suite/rpl/t/rpl_mdev359.test index 4f8cc378973..fecb5c492b1 100644 --- a/mysql-test/suite/rpl/t/rpl_mdev359.test +++ b/mysql-test/suite/rpl/t/rpl_mdev359.test @@ -13,7 +13,7 @@ # the code, disable the semisync, and then continue the paused thread. CREATE TABLE t1 (a INT) ENGINE=MyISAM; -INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; +INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master'; SET GLOBAL rpl_semi_sync_master_enabled = ON; --connection master1 SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont"; -- cgit v1.2.1 From e7362d457a41a8c8a1925c2d0be59df450511320 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Jun 2012 19:02:53 +0200 Subject: MDEV-359: Fix another case where switch-off semisync could cause a race that ended with server crash. This one was when the code releases and reaquires the lock with pthread_cond_wait() - and semisync is switched off meanwhile. --- mysql-test/suite/rpl/t/rpl_mdev359.test | 2 +- plugin/semisync/semisync_master.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/t/rpl_mdev359.test b/mysql-test/suite/rpl/t/rpl_mdev359.test index fecb5c492b1..ef4e41f5291 100644 --- a/mysql-test/suite/rpl/t/rpl_mdev359.test +++ b/mysql-test/suite/rpl/t/rpl_mdev359.test @@ -1,7 +1,7 @@ --source include/have_semisync_plugin.inc --source include/not_embedded.inc ---source include/have_binlog_format_mixed_or_statement.inc --source include/have_debug_sync.inc +--source include/have_binlog_format_mixed_or_statement.inc --source include/master-slave.inc # MDEV-359: There was a server crash when the code first checks if semisync diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc index cb60d8e67d3..8573c4dcbde 100644 --- a/plugin/semisync/semisync_master.cc +++ b/plugin/semisync/semisync_master.cc @@ -744,6 +744,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, must have been removed from ActiveTranx. */ assert(thd_killed(NULL) || + !getMasterEnabled() || !active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name, trx_wait_binlog_pos)); -- cgit v1.2.1 From a5731b27b7eb9e0c30659219a00d92bcb8e08246 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Jun 2012 21:17:34 +0200 Subject: MDEV-342: Do not mark old binlog file as cleanly closed during rotate until the new file is fully synced to disk and binlog index. This fixes a window where a crash would leave next server restart unable to detect that a crash occured, causing recovery to fail. --- mysql-test/suite/binlog/r/binlog_mdev342.result | 29 ++++++++++ .../suite/binlog/t/binlog_mdev342-master.opt | 1 + mysql-test/suite/binlog/t/binlog_mdev342.test | 62 ++++++++++++++++++++++ sql/handler.cc | 1 + sql/log.cc | 60 +++++++++++++++++---- sql/log.h | 2 + 6 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 mysql-test/suite/binlog/r/binlog_mdev342.result create mode 100644 mysql-test/suite/binlog/t/binlog_mdev342-master.opt create mode 100644 mysql-test/suite/binlog/t/binlog_mdev342.test diff --git a/mysql-test/suite/binlog/r/binlog_mdev342.result b/mysql-test/suite/binlog/r/binlog_mdev342.result new file mode 100644 index 00000000000..2346ccc2e3d --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_mdev342.result @@ -0,0 +1,29 @@ +SET GLOBAL max_binlog_size= 4096; +SET GLOBAL innodb_flush_log_at_trx_commit= 1; +CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; +SET DEBUG_SYNC= "binlog_open_before_update_index SIGNAL con1_ready WAIT_FOR con1_cont"; +SET SESSION debug_dbug="+d,crash_create_critical_before_update_index"; +INSERT INTO t1 VALUES (1, REPEAT("x", 4100)); +SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; +SET DEBUG_SYNC= "ha_commit_trans_after_prepare SIGNAL con2_ready"; +INSERT INTO t1 VALUES (2, NULL); +SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; +SET DEBUG_SYNC= "now SIGNAL con1_cont"; +Got one of the listed errors +SELECT a FROM t1 ORDER BY a; +a +1 +show binary logs; +Log_name File_size +master-bin.000001 # +master-bin.000002 # +show binlog events in 'master-bin.000001' from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Format_desc # # SERVER_VERSION, BINLOG_VERSION +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb +master-bin.000001 # Query # # BEGIN +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F +master-bin.000001 # Xid # # COMMIT /* XID */ +master-bin.000001 # Rotate # # master-bin.000002;pos= +DROP TABLE t1; diff --git a/mysql-test/suite/binlog/t/binlog_mdev342-master.opt b/mysql-test/suite/binlog/t/binlog_mdev342-master.opt new file mode 100644 index 00000000000..425fda95086 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_mdev342-master.opt @@ -0,0 +1 @@ +--skip-stack-trace --skip-core-file diff --git a/mysql-test/suite/binlog/t/binlog_mdev342.test b/mysql-test/suite/binlog/t/binlog_mdev342.test new file mode 100644 index 00000000000..cae915b302b --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_mdev342.test @@ -0,0 +1,62 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/have_binlog_format_row.inc +# Valgrind does not work well with test that crashes the server +--source include/not_valgrind.inc + +# (We do not need to restore these settings, as we crash the server). +SET GLOBAL max_binlog_size= 4096; +SET GLOBAL innodb_flush_log_at_trx_commit= 1; + +CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; + +# One connection does an insert that causes a binlog rotate. +# The rotate is paused after writing new file but before updating index. +connect(con1,localhost,root,,); +SET DEBUG_SYNC= "binlog_open_before_update_index SIGNAL con1_ready WAIT_FOR con1_cont"; +SET SESSION debug_dbug="+d,crash_create_critical_before_update_index"; +send INSERT INTO t1 VALUES (1, REPEAT("x", 4100)); + +connection default; +SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; + +# Another connection creates a prepared transaction. +# After the transaction is prepared, it will hang waiting for LOCK_log. +connect(con2,localhost,root,,); +SET DEBUG_SYNC= "ha_commit_trans_after_prepare SIGNAL con2_ready"; +send INSERT INTO t1 VALUES (2, NULL); + +connection default; +SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; + +# Now crash the server in con1, with old binlog closed, new binlog not yet in +# index, and one transaction in prepared-but-not-committed state. +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +wait-binlog_mdev342.test +EOF +SET DEBUG_SYNC= "now SIGNAL con1_cont"; +connection con1; +--error 2006,2013 +reap; + +--remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +restart-binlog_mdev342.test +EOF + +connection default; +--enable_reconnect +--source include/wait_until_connected_again.inc + +# Check that all transactions are recovered. +SELECT a FROM t1 ORDER BY a; + +--source include/show_binary_logs.inc +--let $binlog_file= master-bin.000001 +--let $binlog_start= 4 +--source include/show_binlog_events.inc + +# Cleanup +connection default; +DROP TABLE t1; diff --git a/sql/handler.cc b/sql/handler.cc index 2c9cc388006..b7d545a75dc 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1276,6 +1276,7 @@ int ha_commit_trans(THD *thd, bool all) need_prepare_ordered|= (ht->prepare_ordered != NULL); need_commit_ordered|= (ht->commit_ordered != NULL); } + DEBUG_SYNC(thd, "ha_commit_trans_after_prepare"); DBUG_EXECUTE_IF("crash_commit_after_prepare", DBUG_SUICIDE();); if (!is_real_trans) diff --git a/sql/log.cc b/sql/log.cc index e80a2aaec51..801d945f3f0 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2464,9 +2464,10 @@ void MYSQL_LOG::init_pthread_objects() SYNOPSIS close() - exiting Bitmask. For the slow and general logs the only used bit is - LOG_CLOSE_TO_BE_OPENED. This is used if we intend to call - open at once after close. + exiting Bitmask. LOG_CLOSE_TO_BE_OPENED is used if we intend to call + open at once after close. LOG_CLOSE_DELAYED_CLOSE is used for + binlog rotation, to delay actual close of the old file until + we have successfully created the new file. NOTES One can do an open on the object at once after doing a close. @@ -2487,7 +2488,8 @@ void MYSQL_LOG::close(uint exiting) sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } - if (mysql_file_close(log_file.file, MYF(MY_WME)) && ! write_error) + if (!(exiting & LOG_CLOSE_DELAYED_CLOSE) && + mysql_file_close(log_file.file, MYF(MY_WME)) && ! write_error) { write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); @@ -3189,6 +3191,10 @@ bool MYSQL_BIN_LOG::open(const char *log_name, if (write_file_name_to_index_file) { #ifdef HAVE_REPLICATION +#ifdef ENABLED_DEBUG_SYNC + if (current_thd) + DEBUG_SYNC(current_thd, "binlog_open_before_update_index"); +#endif DBUG_EXECUTE_IF("crash_create_critical_before_update_index", DBUG_SUICIDE();); #endif @@ -4297,6 +4303,10 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) { int error= 0, close_on_error= FALSE; char new_name[FN_REFLEN], *new_name_ptr, *old_name, *file_to_open; + uint close_flag; + bool delay_close= false; + File old_file; + LINT_INIT(old_file); DBUG_ENTER("MYSQL_BIN_LOG::new_file_impl"); if (!is_open()) @@ -4380,7 +4390,20 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) } old_name=name; name=0; // Don't free name - close(LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX); + close_flag= LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX; + if (!is_relay_log) + { + /* + We need to keep the old binlog file open (and marked as in-use) until + the new one is fully created and synced to disk and index. Otherwise we + leave a window where if we crash, there is no binlog file marked as + crashed for server restart to detect the need for recovery. + */ + old_file= log_file.file; + close_flag|= LOG_CLOSE_DELAYED_CLOSE; + delay_close= true; + } + close(close_flag); if (log_type == LOG_BIN && checksum_alg_reset != BINLOG_CHECKSUM_ALG_UNDEF) { DBUG_ASSERT(!is_relay_log); @@ -4423,6 +4446,12 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) end: + if (delay_close) + { + clear_inuse_flag_when_closing(old_file); + mysql_file_close(old_file, MYF(MY_WME)); + } + if (error && close_on_error /* rotate or reopen failed */) { /* @@ -6275,6 +6304,8 @@ int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd, - LOG_CLOSE_TO_BE_OPENED : if we intend to call open at once after close. - LOG_CLOSE_STOP_EVENT : write a 'stop' event to the log + - LOG_CLOSE_DELAYED_CLOSE : do not yet close the file and clear the + LOG_EVENT_BINLOG_IN_USE_F flag @note One can do an open on the object at once after doing a close. @@ -6304,12 +6335,11 @@ void MYSQL_BIN_LOG::close(uint exiting) #endif /* HAVE_REPLICATION */ /* don't pwrite in a file opened with O_APPEND - it doesn't work */ - if (log_file.type == WRITE_CACHE && log_type == LOG_BIN) + if (log_file.type == WRITE_CACHE && log_type == LOG_BIN + && !(exiting & LOG_CLOSE_DELAYED_CLOSE)) { - my_off_t offset= BIN_LOG_HEADER_SIZE + FLAGS_OFFSET; my_off_t org_position= mysql_file_tell(log_file.file, MYF(0)); - uchar flags= 0; // clearing LOG_EVENT_BINLOG_IN_USE_F - mysql_file_pwrite(log_file.file, &flags, 1, offset, MYF(0)); + clear_inuse_flag_when_closing(log_file.file); /* Restore position so that anything we have in the IO_cache is written to the correct position. @@ -6344,6 +6374,18 @@ void MYSQL_BIN_LOG::close(uint exiting) } +/* + Clear the LOG_EVENT_BINLOG_IN_USE_F; this marks the binlog file as cleanly + closed and not needing crash recovery. +*/ +void MYSQL_BIN_LOG::clear_inuse_flag_when_closing(File file) +{ + my_off_t offset= BIN_LOG_HEADER_SIZE + FLAGS_OFFSET; + uchar flags= 0; // clearing LOG_EVENT_BINLOG_IN_USE_F + mysql_file_pwrite(file, &flags, 1, offset, MYF(0)); +} + + void MYSQL_BIN_LOG::set_max_size(ulong max_size_arg) { /* diff --git a/sql/log.h b/sql/log.h index 3ac7091a4e6..b350f3882fa 100644 --- a/sql/log.h +++ b/sql/log.h @@ -202,6 +202,7 @@ extern TC_LOG_DUMMY tc_log_dummy; #define LOG_CLOSE_INDEX 1 #define LOG_CLOSE_TO_BE_OPENED 2 #define LOG_CLOSE_STOP_EVENT 4 +#define LOG_CLOSE_DELAYED_CLOSE 8 /* Maximum unique log filename extension. @@ -665,6 +666,7 @@ public: bool need_mutex); bool reset_logs(THD* thd); void close(uint exiting); + void clear_inuse_flag_when_closing(File file); // iterating through the log index file int find_log_pos(LOG_INFO* linfo, const char* log_name, -- cgit v1.2.1 From 048cc420521b9187adcb89026c72601db0a07d01 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 Jun 2012 10:42:55 +0200 Subject: MDEV-342: fix two race conditions in the test case that could occasionally cause spurious failures. --- mysql-test/suite/binlog/r/binlog_mdev342.result | 1 + mysql-test/suite/binlog/t/binlog_mdev342.test | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/mysql-test/suite/binlog/r/binlog_mdev342.result b/mysql-test/suite/binlog/r/binlog_mdev342.result index 2346ccc2e3d..0e1d8f8ac78 100644 --- a/mysql-test/suite/binlog/r/binlog_mdev342.result +++ b/mysql-test/suite/binlog/r/binlog_mdev342.result @@ -1,5 +1,6 @@ SET GLOBAL max_binlog_size= 4096; SET GLOBAL innodb_flush_log_at_trx_commit= 1; +RESET MASTER; CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; SET DEBUG_SYNC= "binlog_open_before_update_index SIGNAL con1_ready WAIT_FOR con1_cont"; SET SESSION debug_dbug="+d,crash_create_critical_before_update_index"; diff --git a/mysql-test/suite/binlog/t/binlog_mdev342.test b/mysql-test/suite/binlog/t/binlog_mdev342.test index cae915b302b..02310b87a76 100644 --- a/mysql-test/suite/binlog/t/binlog_mdev342.test +++ b/mysql-test/suite/binlog/t/binlog_mdev342.test @@ -8,6 +8,7 @@ # (We do not need to restore these settings, as we crash the server). SET GLOBAL max_binlog_size= 4096; SET GLOBAL innodb_flush_log_at_trx_commit= 1; +RESET MASTER; CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; @@ -35,6 +36,9 @@ SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; --write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect wait-binlog_mdev342.test EOF +# If con1 manages to race ahead and crash, we can see the crash already in the +# SET DEBUG_SYNC statement, so need --error here also. +--error 0,2006,2013 SET DEBUG_SYNC= "now SIGNAL con1_cont"; connection con1; --error 2006,2013 -- cgit v1.2.1 From e7bfda3b3cc59ba3fe4fe7e7e4307704a464f97f Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Fri, 22 Jun 2012 14:14:22 +0400 Subject: Added comment about QUICK_RANGE_SELECT::free_cond being unused. --- sql/opt_range.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/opt_range.h b/sql/opt_range.h index 57a62bbc143..d4b92015042 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -902,7 +902,7 @@ class SQL_SELECT :public Sql_alloc { key_map quick_keys; // Possible quick keys key_map needed_reg; // Possible quick keys after prev tables. table_map const_tables,read_tables; - bool free_cond; + bool free_cond; /* Currently not used and always FALSE */ SQL_SELECT(); ~SQL_SELECT(); -- cgit v1.2.1 From f8f65accf99821386ad2cffdf0c3f473e8f33064 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Sat, 23 Jun 2012 20:12:54 +0400 Subject: Add back testcase for lp:817966 (was lost in the merge) --- mysql-test/r/func_in.result | 13 +++++++++++++ mysql-test/t/func_in.test | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index 800b9a976b4..fc56660ac62 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -789,6 +789,19 @@ DROP TABLE t1; # End of test BUG#13012483 # End of 5.1 tests +create table t1 (a bigint, b int); +insert t1 values (1,1),(2,2),(3,3); +select * from t1 where a in ('2.1'); +a b +select * from t1 where b in ('2.1'); +a b +select * from t1 where a='2.1'; +a b +select * from t1 where b='2.1'; +a b +select * from t1 where IF(1,a,a)='2.1'; +a b +drop table t1; # # LP bug#992380 Crash when creating PS for a query with # subquery in WHERE (see also mysql bug#13012483) diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index e6d991e097d..1e695142d90 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -577,6 +577,24 @@ DROP TABLE t1; --echo # --echo End of 5.1 tests +# +# lp:817966 int_column IN (string_constant) +# +# rather illogically, when BIGINT field is compared to a string, +# the string is converted to an integer, not to a double. +# When some other integer field (not BIGINT) is compared to a string, +# or when the BIGINT is not a field, but an expression, both +# operands are compared as doubles. The latter behavior is correct, +# according to the manual. +# +create table t1 (a bigint, b int); +insert t1 values (1,1),(2,2),(3,3); +select * from t1 where a in ('2.1'); +select * from t1 where b in ('2.1'); +select * from t1 where a='2.1'; +select * from t1 where b='2.1'; +select * from t1 where IF(1,a,a)='2.1'; +drop table t1; --echo # --echo # LP bug#992380 Crash when creating PS for a query with --echo # subquery in WHERE (see also mysql bug#13012483) -- cgit v1.2.1 From d9c3a3e39e4c5a6f060b7bbc1646ca74c123fbab Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 23 Jun 2012 12:19:07 -0700 Subject: Fixed bug mdev-360. The bug was the result of the incomplete fix for bug lp bug 1008293. --- storage/myisam/mi_keycache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/myisam/mi_keycache.c b/storage/myisam/mi_keycache.c index be0cdc470f1..eed8cc666eb 100644 --- a/storage/myisam/mi_keycache.c +++ b/storage/myisam/mi_keycache.c @@ -75,6 +75,7 @@ int mi_assign_to_key_cache(MI_INFO *info, in the old key cache. */ + pthread_mutex_lock(&share->key_cache->op_lock); if (flush_key_blocks(share->key_cache, share->kfile, &share->dirty_part_map, FLUSH_RELEASE)) { @@ -82,6 +83,7 @@ int mi_assign_to_key_cache(MI_INFO *info, mi_print_error(info->s, HA_ERR_CRASHED); mi_mark_crashed(info); /* Mark that table must be checked */ } + pthread_mutex_unlock(&share->key_cache->op_lock); /* Flush the new key cache for this file. This is needed to ensure -- cgit v1.2.1 From 072097174c8b91299fe74a3cd7c5248e6e3cfc57 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 25 Jun 2012 18:17:24 +0200 Subject: fix compile error, when building with oqgraph --- sql/field.h | 3 +++ sql/unireg.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/field.h b/sql/field.h index 3838c924419..f22bab0409d 100644 --- a/sql/field.h +++ b/sql/field.h @@ -63,6 +63,9 @@ enum Derivation #define my_charset_numeric my_charset_latin1 #define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII +/* The length of the header part for each virtual column in the .frm file */ +#define FRM_VCOL_HEADER_SIZE(b) (3 + test(b)) + struct ha_field_option_struct; struct st_cache_field; diff --git a/sql/unireg.h b/sql/unireg.h index 950cfc2cc31..da510bb4e6d 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -161,9 +161,6 @@ typedef struct st_ha_create_information HA_CREATE_INFO; #define DEFAULT_KEY_CACHE_NAME "default" -/* The length of the header part for each virtual column in the .frm file */ -#define FRM_VCOL_HEADER_SIZE(b) (3 + test(b)) - /* Include prototypes for unireg */ -- cgit v1.2.1 From 1b84c0cfee4db6f0a6c97459a47444ed1f0d6ce1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Jun 2012 21:43:34 +0300 Subject: Fix for LP bug#1007622 TABLE_LIST::check_single_table made aware about fact that now if table attached to a merged view it can be (unopened) temporary table (in 5.2 it was always leaf table or non (in case of several tables)). --- mysql-test/r/view.result | 13 +++++++++++++ mysql-test/t/view.test | 13 +++++++++++++ sql/table.cc | 9 ++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 86ebc9a8ee7..56598583bb6 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -4472,6 +4472,19 @@ INSERT INTO t2 VALUES (1); DROP TRIGGER tr; DROP VIEW v1; DROP TABLE t1,t2,t3; +# +# LP bug#1007622 Server crashes in handler::increment_statistics on +# inserting into a view over a view +# +CREATE TABLE t1 (a INT); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.* FROM t1 AS a1, t1 AS a2; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; +INSERT INTO v2 (a) VALUES (1) ; +select * from t1; +a +1 +drop view v2,v1; +drop table t1; # ----------------------------------------------------------------- # -- End of 5.3 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 93e0cce8a5d..6f11d6909ea 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -4420,6 +4420,19 @@ DROP TRIGGER tr; DROP VIEW v1; DROP TABLE t1,t2,t3; +--echo # +--echo # LP bug#1007622 Server crashes in handler::increment_statistics on +--echo # inserting into a view over a view +--echo # + +CREATE TABLE t1 (a INT); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.* FROM t1 AS a1, t1 AS a2; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; +INSERT INTO v2 (a) VALUES (1) ; +select * from t1; +drop view v2,v1; +drop table t1; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.3 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/table.cc b/sql/table.cc index 05fb5593842..2eb7eca6fb0 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4041,7 +4041,14 @@ bool TABLE_LIST::check_single_table(TABLE_LIST **table_arg, tbl; tbl= tbl->next_local) { - if (tbl->table) + /* + Merged view has also temporary table attached (in 5.2 if it has table + then it was real table), so we have filter such temporary tables out + by checking that it is not merged view + */ + if (tbl->table && + !(tbl->is_view() && + tbl->is_merged_derived())) { if (tbl->table->map & map) { -- cgit v1.2.1 From 44d8fe96461c0605a53159fcdc4bf04a8e5c52b3 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 27 Jun 2012 17:13:12 +0300 Subject: Don't abort InnoDB/XtraDB if one can't allocate resources for AIO - Better error messages This fixes that one again can run the test systems with many threads without having to increase fs.aio-max-nr. mysql-test/include/mtr_check.sql: Ignore the INNODB_USE_NATIVE_AIO variable (may change during execution) mysql-test/mysql-test-run.pl: Ignore warnings for failure to setup AIO storage/innobase/os/os0file.c: Continue without AIO even if we can't allocate resources for AIO storage/xtradb/os/os0file.c: Continue without AIO even if we can't allocate resources for AIO storage/xtradb/srv/srv0start.c: Give an error message (instead of core dump) if AIO can't be initialized --- mysql-test/include/mtr_check.sql | 1 + mysql-test/mysql-test-run.pl | 3 +++ storage/innobase/os/os0file.c | 23 +++++++++++++++++------ storage/xtradb/os/os0file.c | 23 +++++++++++++++++------ storage/xtradb/srv/srv0start.c | 18 ++++++++++++++---- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/mysql-test/include/mtr_check.sql b/mysql-test/include/mtr_check.sql index 82c0514b7cd..6c1a3513324 100644 --- a/mysql-test/include/mtr_check.sql +++ b/mysql-test/include/mtr_check.sql @@ -30,6 +30,7 @@ BEGIN WHERE variable_name NOT IN ('timestamp', 'innodb_file_format_max') AND variable_name not like "Last_IO_Err*" AND variable_name != 'INNODB_IBUF_MAX_SIZE' + AND variable_name != 'INNODB_USE_NATIVE_AIO' ORDER BY variable_name; -- Dump all databases, there should be none diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 6e463f35bf5..a2802916fe4 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4738,6 +4738,9 @@ sub extract_warning_lines ($$) { qr|Aborted connection|, qr|table.*is full|, qr|Linux Native AIO|, # warning that aio does not work on /dev/shm + qr|Error: io_setup\(\) failed|, + qr|Warning: io_setup\(\) failed|, + qr|Warning: io_setup\(\) attempt|, ); my $matched_lines= []; diff --git a/storage/innobase/os/os0file.c b/storage/innobase/os/os0file.c index ed5b3116daa..15e66167f26 100644 --- a/storage/innobase/os/os0file.c +++ b/storage/innobase/os/os0file.c @@ -3361,12 +3361,23 @@ os_aio_array_create( if (!os_aio_linux_create_io_ctx(n/n_segments, &array->aio_ctx[i])) { /* If something bad happened during aio setup - we should call it a day and return right away. - We don't care about any leaks because a failure - to initialize the io subsystem means that the - server (or atleast the innodb storage engine) - is not going to startup. */ - return(NULL); + we disable linux native aio. + The disadvantage will be a small memory leak + at shutdown but that's ok compared to a crash + or a not working server. + This frequently happens when running the test suite + with many threads on a system with low fs.aio-max-nr! + */ + + fprintf(stderr, + " InnoDB: Warning: Linux Native AIO disabled " + "because os_aio_linux_create_io_ctx() " + "failed. To get rid of this warning you can " + "try increasing system " + "fs.aio-max-nr to 1048576 or larger or " + "setting innodb_use_native_aio = 0 in my.cnf\n"); + srv_use_native_aio = FALSE; + goto skip_native_aio; } } diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index eefe17df740..5d249d52ce9 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -3463,12 +3463,23 @@ os_aio_array_create( if (!os_aio_linux_create_io_ctx(n/n_segments, &array->aio_ctx[i])) { /* If something bad happened during aio setup - we should call it a day and return right away. - We don't care about any leaks because a failure - to initialize the io subsystem means that the - server (or atleast the innodb storage engine) - is not going to startup. */ - return(NULL); + we disable linux native aio. + The disadvantage will be a small memory leak + at shutdown but that's ok compared to a crash + or a not working server. + This frequently happens when running the test suite + with many threads on a system with low fs.aio-max-nr! + */ + + fprintf(stderr, + " InnoDB: Warning: Linux Native AIO disabled " + "because os_aio_linux_create_io_ctx() " + "failed. To get rid of this warning you can " + "try increasing system " + "fs.aio-max-nr to 1048576 or larger or " + "setting innodb_use_native_aio = 0 in my.cnf\n"); + srv_use_native_aio = FALSE; + goto skip_native_aio; } } diff --git a/storage/xtradb/srv/srv0start.c b/storage/xtradb/srv/srv0start.c index 59697731e6c..75e8097ee0b 100644 --- a/storage/xtradb/srv/srv0start.c +++ b/storage/xtradb/srv/srv0start.c @@ -1509,10 +1509,20 @@ innobase_start_or_create_for_mysql(void) } # endif /* __WIN__ */ - os_aio_init(io_limit, - srv_n_read_io_threads, - srv_n_write_io_threads, - SRV_MAX_N_PENDING_SYNC_IOS); + if (!os_aio_init(io_limit, + srv_n_read_io_threads, + srv_n_write_io_threads, + SRV_MAX_N_PENDING_SYNC_IOS)) + { + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Fatal error: cannot initialize AIO" + " sub-system\n"); +#if defined(LINUX_NATIVE_AIO) + fprintf(stderr, "You can try increasing system fs.aio-max-nr to 1048576 or larger or setting innodb_use_native_aio = 0 in my.cnf\n"); +#endif + return(DB_ERROR); + } fil_init(srv_file_per_table ? 50000 : 5000, srv_max_n_open_files); -- cgit v1.2.1 From 46525c35b084a8af4dc99c8da78cf9e40e69dee1 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 4 Jul 2012 14:34:45 +0400 Subject: MDEV-376: Wrong result (missing rows) with index_merge+index_merge_intersection, join - Let QUICK_RANGE_SELECT::init_ror_merged_scan() call quick->reset() only after we've set the column read bitmaps. --- mysql-test/r/index_merge_innodb.result | 15 +++++++++++++++ mysql-test/t/index_merge_innodb.test | 15 +++++++++++++++ sql/opt_range.cc | 17 ++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result index b8eda092291..92bcb2e88f0 100644 --- a/mysql-test/r/index_merge_innodb.result +++ b/mysql-test/r/index_merge_innodb.result @@ -777,4 +777,19 @@ commit; select * from t1 where t1.zone_id=830 AND modified=9; pk zone_id modified drop table t0, t1; +# +# MDEV-376: Wrong result (missing rows) with index_merge+index_merge_intersection, join +# +CREATE TABLE t1 ( +a INT, b CHAR(1), c CHAR(1), KEY(a), KEY(b) +) ENGINE=InnoDB; +INSERT INTO t1 VALUES (8,'v','v'),(8,'m','m'),(9,'d','d'); +SELECT ta.* FROM t1 AS ta, t1 AS tb +WHERE ( tb.b != ta.b OR tb.a = ta.a ) +AND ( tb.b = ta.c OR tb.b = ta.b ); +a b c +8 v v +8 m m +9 d d +DROP TABLE t1; set optimizer_switch= @optimizer_switch_save; diff --git a/mysql-test/t/index_merge_innodb.test b/mysql-test/t/index_merge_innodb.test index 0fd3c54c787..6a1cb53dc40 100644 --- a/mysql-test/t/index_merge_innodb.test +++ b/mysql-test/t/index_merge_innodb.test @@ -156,6 +156,21 @@ select * from t1 where t1.zone_id=830 AND modified=9; drop table t0, t1; +--echo # +--echo # MDEV-376: Wrong result (missing rows) with index_merge+index_merge_intersection, join +--echo # +CREATE TABLE t1 ( + a INT, b CHAR(1), c CHAR(1), KEY(a), KEY(b) +) ENGINE=InnoDB; + +INSERT INTO t1 VALUES (8,'v','v'),(8,'m','m'),(9,'d','d'); + + +SELECT ta.* FROM t1 AS ta, t1 AS tb +WHERE ( tb.b != ta.b OR tb.a = ta.a ) + AND ( tb.b = ta.c OR tb.b = ta.b ); + +DROP TABLE t1; set optimizer_switch= @optimizer_switch_save; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 0390ac1101e..da328063e56 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2008,7 +2008,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) if (reuse_handler) { DBUG_PRINT("info", ("Reusing handler 0x%lx", (long) file)); - if (init() || reset()) + if (init()) { DBUG_RETURN(1); } @@ -2043,7 +2043,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) if (file->ha_external_lock(thd, F_RDLCK)) goto failure; - if (init() || reset()) + if (init()) { file->ha_external_lock(thd, F_UNLCK); file->ha_close(); @@ -2090,7 +2090,18 @@ end: head->key_read= org_key_read; bitmap_copy(&column_bitmap, head->read_set); head->column_bitmaps_set(&column_bitmap, &column_bitmap); - + + if (reset()) + { + if (!reuse_handler) + { + file->ha_external_lock(thd, F_UNLCK); + file->ha_close(); + goto failure; + } + else + DBUG_RETURN(1); + } DBUG_RETURN(0); failure: -- cgit v1.2.1 From 19e03c683edb4de91756c11f11e3528dd064ce7b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Jul 2012 09:29:34 +0200 Subject: The variable "table_cache" is deprecated, use the new name "table_open_cache" instead. Thanks to Ivoz for pointing this out. --- debian/additions/my.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/additions/my.cnf b/debian/additions/my.cnf index fd9bcf19977..a27f8543f0b 100644 --- a/debian/additions/my.cnf +++ b/debian/additions/my.cnf @@ -65,7 +65,7 @@ max_heap_table_size = 32M myisam_recover = BACKUP key_buffer_size = 128M #open-files-limit = 2000 -table_cache = 400 +table_open_cache = 400 myisam_sort_buffer_size = 512M concurrent_insert = 2 read_buffer_size = 2M -- cgit v1.2.1 From 703ee1ad1b0a2ae3af65236f03e588493f09f5d8 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 10 Jul 2012 09:02:12 +0300 Subject: Fixed MDEV-385: mysqltest running with continue-on-error crashes on a non-SQL command producing an error client/mysqltest.cc: Added missing DBUG_VOID_RETURN --- client/mysqltest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 01613223d64..961114c9a40 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1285,7 +1285,7 @@ void handle_command_error(struct st_command *command, uint error, "errno: %d", command->first_word_len, command->query, error, my_errno, sys_errno); - return; + DBUG_VOID_RETURN; } i= match_expected_error(command, error, NULL); -- cgit v1.2.1 From a08631d6964141577fd345f34292de4ba90421ba Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 11 Jul 2012 16:19:05 +0200 Subject: lp:1023404 problems with savepoints and tokudb with 5.5 fix incorrect merge --- sql/handler.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index b7d545a75dc..ecd02e2a1be 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -504,10 +504,6 @@ int ha_initialize_handlerton(st_plugin_int *plugin) "Assigning value %d.", plugin->plugin->name, idx); hton->db_type= (enum legacy_db_type) idx; } - installed_htons[hton->db_type]= hton; - tmp= hton->savepoint_offset; - hton->savepoint_offset= savepoint_alloc_size; - savepoint_alloc_size+= tmp; /* In case a plugin is uninstalled and re-installed later, it should -- cgit v1.2.1 From 718bbcbfd0dd1aa858e4e3ba0583e85d81414df0 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 12 Jul 2012 15:32:35 +0200 Subject: MDEV-393. Remove --loose-pbxt=OFF/loose-skip-pbxt from bootstrapper calls to avoid "unknown parameter" warning --- debian/dist/Debian/mariadb-server-5.5.postinst | 2 +- debian/dist/Ubuntu/mariadb-server-5.5.postinst | 2 +- sql/mysql_install_db.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/dist/Debian/mariadb-server-5.5.postinst b/debian/dist/Debian/mariadb-server-5.5.postinst index e3f2df13b4b..2e15b121db9 100644 --- a/debian/dist/Debian/mariadb-server-5.5.postinst +++ b/debian/dist/Debian/mariadb-server-5.5.postinst @@ -21,7 +21,7 @@ invoke() { fi } -MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --loose-innodb=OFF --loose-pbxt=OFF --default-storage-engine=myisam" +MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --loose-innodb=OFF --default-storage-engine=myisam" test_mysql_access() { mysql --no-defaults -u root -h localhost /dev/null 2>&1 diff --git a/debian/dist/Ubuntu/mariadb-server-5.5.postinst b/debian/dist/Ubuntu/mariadb-server-5.5.postinst index a0c351194bb..1c7aa37f69f 100644 --- a/debian/dist/Ubuntu/mariadb-server-5.5.postinst +++ b/debian/dist/Ubuntu/mariadb-server-5.5.postinst @@ -21,7 +21,7 @@ invoke() { fi } -MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --loose-innodb=OFF --loose-pbxt=OFF --default-storage-engine=myisam" +MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --loose-innodb=OFF --default-storage-engine=myisam" test_mysql_access() { mysql --no-defaults -u root -h localhost /dev/null 2>&1 diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index bde81d915b2..6e2c6ec07f3 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -247,7 +247,7 @@ static char *init_bootstrap_command_line(char *cmdline, size_t size) "\"\"%s\" --no-defaults --bootstrap" " \"--language=%s\\share\\english\"" " --basedir=. --datadir=. --default-storage-engine=myisam" - " --max_allowed_packet=9M --loose-skip-innodb --loose-skip-pbxt" + " --max_allowed_packet=9M --loose-skip-innodb" " --net-buffer-length=16k\"", mysqld_path, basedir); return cmdline; } -- cgit v1.2.1 From 9f6a1c5842fc8f71463d48e4da4ec692aadeacc1 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jul 2012 22:17:32 +0300 Subject: fixed MySQL bug#53775: Now partition engine adds underlying tables to the QC and ask underlying tables engine permittion to cache the query and return result of the query. Incorrect QC cleanup in case of table registration failure fixe. Unified interface for myisammrg & partitioned engnes for QC. --- mysql-test/include/query_cache_partitions.inc | 126 +++++++++++++++++++++ mysql-test/r/partition_cache.result | 18 +-- mysql-test/r/partition_cache_innodb.result | 151 +++++++++++++++++++++++++ mysql-test/r/partition_cache_myisam.result | 153 ++++++++++++++++++++++++++ mysql-test/t/partition_cache_innodb.test | 14 +++ mysql-test/t/partition_cache_myisam.test | 14 +++ sql/ha_partition.cc | 116 +++++++++++++++++++ sql/ha_partition.h | 26 ++--- sql/handler.h | 42 +++++++ sql/sql_cache.cc | 94 ++++++---------- sql/sql_cache.h | 31 ++++-- storage/myisammrg/ha_myisammrg.cc | 41 +++++++ storage/myisammrg/ha_myisammrg.h | 6 + 13 files changed, 739 insertions(+), 93 deletions(-) create mode 100644 mysql-test/include/query_cache_partitions.inc create mode 100644 mysql-test/r/partition_cache_innodb.result create mode 100644 mysql-test/r/partition_cache_myisam.result create mode 100644 mysql-test/t/partition_cache_innodb.test create mode 100644 mysql-test/t/partition_cache_myisam.test diff --git a/mysql-test/include/query_cache_partitions.inc b/mysql-test/include/query_cache_partitions.inc new file mode 100644 index 00000000000..e5bb7406c10 --- /dev/null +++ b/mysql-test/include/query_cache_partitions.inc @@ -0,0 +1,126 @@ +# include/query_cache_partitions.inc +# +# The variables +# $engine_type -- storage engine to be tested +# have to be set before sourcing this script. + +eval SET SESSION STORAGE_ENGINE = $engine_type; + +# Initialise +--disable_warnings +drop table if exists t1; +--enable_warnings + +set @save_query_cache_size = @@global.query_cache_size; + +--echo # Test that partitions works with query cache + +flush query cache; + +SET GLOBAL query_cache_size=1024*1024*512; + CREATE TABLE `t1` ( + `id` int(11) NOT NULL , + `created_at` datetime NOT NULL, + `cool` tinyint default 0 + ); + + ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( + PARTITION month_2010_4 VALUES LESS THAN (734258), + PARTITION month_2010_5 VALUES LESS THAN (734289), + PARTITION month_max VALUES LESS THAN MAXVALUE + ); + +show create table t1; + +INSERT INTO t1 VALUES (1, now(), 0); + +flush status; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + + +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; + +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +drop table t1; + +--echo # Test that sub-partitions works with query cache + +flush query cache; + +SET GLOBAL query_cache_size=1024*1024*512; + CREATE TABLE `t1` ( + `id` int(11) NOT NULL , + `created_at` datetime NOT NULL, + `cool` tinyint default 0 + ) + PARTITION BY RANGE (TO_DAYS(created_at)) + subpartition by hash(cool) subpartitions 3 ( + PARTITION month_2010_4 VALUES LESS THAN (734258), + PARTITION month_2010_5 VALUES LESS THAN (734289), + PARTITION month_max VALUES LESS THAN MAXVALUE + ); + +show create table t1; + +INSERT INTO t1 VALUES (1, now(), 0); + +flush status; +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; + +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +drop table t1; + +--echo # +--echo # MySQL bug#53775 Query on partitioned table returns cached result +--echo # from previous transaction +--echo # + +flush query cache; +flush status; + +SET GLOBAL query_cache_size=1024*1024*512; + CREATE TABLE `t1` ( + `id` int(11) NOT NULL , + `created_at` datetime NOT NULL, + `cool` tinyint default 0 + ); + + ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( + PARTITION month_2010_4 VALUES LESS THAN (734258), + PARTITION month_2010_5 VALUES LESS THAN (734289), + PARTITION month_max VALUES LESS THAN MAXVALUE + ); + +INSERT INTO t1 VALUES (1, now(), 0); + +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +BEGIN; +UPDATE `t1` SET `cool` = 1 WHERE `id` = 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +ROLLBACK; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +BEGIN; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +ROLLBACK; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; + +show status like "Qcache_queries_in_cache"; +show status like "Qcache_hits"; + +drop table t1; + +set @@global.query_cache_size = @save_query_cache_size; diff --git a/mysql-test/r/partition_cache.result b/mysql-test/r/partition_cache.result index ac2da9bb78a..cd579d00952 100644 --- a/mysql-test/r/partition_cache.result +++ b/mysql-test/r/partition_cache.result @@ -27,7 +27,7 @@ a 3 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 1 drop table t1; commit; create table t1 (a int not null) PARTITION BY KEY (a) PARTITIONS 3; @@ -50,7 +50,7 @@ a 2 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 3 show status like "Qcache_hits"; Variable_name Value Qcache_hits 0 @@ -69,7 +69,7 @@ a 2 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 6 show status like "Qcache_hits"; Variable_name Value Qcache_hits 0 @@ -93,14 +93,14 @@ a 2 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 2 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 0 +Qcache_hits 1 commit; show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 2 drop table t3,t2,t1; CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id)) PARTITION BY HASH (id) PARTITIONS 3; select count(*) from t1; @@ -164,7 +164,7 @@ count(*) 2 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 1 connection connection1 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w'; count(*) @@ -197,9 +197,9 @@ count(*) 2 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 0 +Qcache_queries_in_cache 1 show status like "Qcache_hits"; Variable_name Value -Qcache_hits 0 +Qcache_hits 1 set @@global.query_cache_size = @save_query_cache_size; drop table t2; diff --git a/mysql-test/r/partition_cache_innodb.result b/mysql-test/r/partition_cache_innodb.result new file mode 100644 index 00000000000..0d0abbb096c --- /dev/null +++ b/mysql-test/r/partition_cache_innodb.result @@ -0,0 +1,151 @@ +SET SESSION STORAGE_ENGINE = innodb; +drop table if exists t1; +set @save_query_cache_size = @@global.query_cache_size; +# Test that partitions works with query cache +flush query cache; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +); +ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `created_at` datetime NOT NULL, + `cool` tinyint(4) DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY RANGE (TO_DAYS(created_at)) +(PARTITION month_2010_4 VALUES LESS THAN (734258) ENGINE = InnoDB, + PARTITION month_2010_5 VALUES LESS THAN (734289) ENGINE = InnoDB, + PARTITION month_max VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ +INSERT INTO t1 VALUES (1, now(), 0); +flush status; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 1 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 2 +drop table t1; +# Test that sub-partitions works with query cache +flush query cache; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +) +PARTITION BY RANGE (TO_DAYS(created_at)) +subpartition by hash(cool) subpartitions 3 ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `created_at` datetime NOT NULL, + `cool` tinyint(4) DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY RANGE (TO_DAYS(created_at)) +SUBPARTITION BY HASH (cool) +SUBPARTITIONS 3 +(PARTITION month_2010_4 VALUES LESS THAN (734258) ENGINE = InnoDB, + PARTITION month_2010_5 VALUES LESS THAN (734289) ENGINE = InnoDB, + PARTITION month_max VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ +INSERT INTO t1 VALUES (1, now(), 0); +flush status; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 1 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 2 +drop table t1; +# +# MySQL bug#53775 Query on partitioned table returns cached result +# from previous transaction +# +flush query cache; +flush status; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +); +ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +INSERT INTO t1 VALUES (1, now(), 0); +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +BEGIN; +UPDATE `t1` SET `cool` = 1 WHERE `id` = 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +1 +ROLLBACK; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +BEGIN; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +ROLLBACK; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 2 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 1 +drop table t1; +set @@global.query_cache_size = @save_query_cache_size; diff --git a/mysql-test/r/partition_cache_myisam.result b/mysql-test/r/partition_cache_myisam.result new file mode 100644 index 00000000000..0b617c03590 --- /dev/null +++ b/mysql-test/r/partition_cache_myisam.result @@ -0,0 +1,153 @@ +SET SESSION STORAGE_ENGINE = myisam; +drop table if exists t1; +set @save_query_cache_size = @@global.query_cache_size; +# Test that partitions works with query cache +flush query cache; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +); +ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `created_at` datetime NOT NULL, + `cool` tinyint(4) DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY RANGE (TO_DAYS(created_at)) +(PARTITION month_2010_4 VALUES LESS THAN (734258) ENGINE = MyISAM, + PARTITION month_2010_5 VALUES LESS THAN (734289) ENGINE = MyISAM, + PARTITION month_max VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */ +INSERT INTO t1 VALUES (1, now(), 0); +flush status; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 1 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 2 +drop table t1; +# Test that sub-partitions works with query cache +flush query cache; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +) +PARTITION BY RANGE (TO_DAYS(created_at)) +subpartition by hash(cool) subpartitions 3 ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `created_at` datetime NOT NULL, + `cool` tinyint(4) DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!50100 PARTITION BY RANGE (TO_DAYS(created_at)) +SUBPARTITION BY HASH (cool) +SUBPARTITIONS 3 +(PARTITION month_2010_4 VALUES LESS THAN (734258) ENGINE = MyISAM, + PARTITION month_2010_5 VALUES LESS THAN (734289) ENGINE = MyISAM, + PARTITION month_max VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */ +INSERT INTO t1 VALUES (1, now(), 0); +flush status; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +0 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 1 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 2 +drop table t1; +# +# MySQL bug#53775 Query on partitioned table returns cached result +# from previous transaction +# +flush query cache; +flush status; +SET GLOBAL query_cache_size=1024*1024*512; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`created_at` datetime NOT NULL, +`cool` tinyint default 0 +); +ALTER TABLE t1 PARTITION BY RANGE (TO_DAYS(created_at)) ( +PARTITION month_2010_4 VALUES LESS THAN (734258), +PARTITION month_2010_5 VALUES LESS THAN (734289), +PARTITION month_max VALUES LESS THAN MAXVALUE +); +INSERT INTO t1 VALUES (1, now(), 0); +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 0 +BEGIN; +UPDATE `t1` SET `cool` = 1 WHERE `id` = 1; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +1 +ROLLBACK; +Warnings: +Warning 1196 Some non-transactional changed tables couldn't be rolled back +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +1 +BEGIN; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +1 +ROLLBACK; +SELECT cool FROM `t1` WHERE (`t1`.id = 1) LIMIT 1; +cool +1 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 2 +show status like "Qcache_hits"; +Variable_name Value +Qcache_hits 2 +drop table t1; +set @@global.query_cache_size = @save_query_cache_size; diff --git a/mysql-test/t/partition_cache_innodb.test b/mysql-test/t/partition_cache_innodb.test new file mode 100644 index 00000000000..dbcfea3088c --- /dev/null +++ b/mysql-test/t/partition_cache_innodb.test @@ -0,0 +1,14 @@ +# t/cache_innodb.test +# +# Last update: +# 2006-07-26 ML test refactored (MySQL 5.1) +# main code t/innodb_cache.test --> include/query_cache.inc +# new wrapper t/cache_innodb.test +# + +--source include/have_query_cache.inc +--source include/have_innodb.inc +--source include/have_partition.inc +let $engine_type= innodb; + +--source include/query_cache_partitions.inc diff --git a/mysql-test/t/partition_cache_myisam.test b/mysql-test/t/partition_cache_myisam.test new file mode 100644 index 00000000000..5347225f6da --- /dev/null +++ b/mysql-test/t/partition_cache_myisam.test @@ -0,0 +1,14 @@ +# t/cache_innodb.test +# +# Last update: +# 2006-07-26 ML test refactored (MySQL 5.1) +# main code t/innodb_cache.test --> include/query_cache.inc +# new wrapper t/cache_innodb.test +# + +--source include/have_query_cache.inc + +--source include/have_partition.inc +let $engine_type= myisam; + +--source include/query_cache_partitions.inc diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b4181fc6d7f..7c2ffeb1b44 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -2076,6 +2076,122 @@ partition_element *ha_partition::find_partition_element(uint part_id) return NULL; } +uint ha_partition::count_query_cache_dependant_tables(uint8 *tables_type) +{ + DBUG_ENTER("ha_partition::count_query_cache_dependant_tables"); + /* Here we rely on the fact that all tables are of the same type */ + (*tables_type)|= m_file[0]->table_cache_type(); + DBUG_PRINT("info", ("cnt: %u", (uint)m_tot_parts)); + DBUG_RETURN(m_tot_parts); +} + +my_bool ha_partition::reg_query_cache_dependant_table(THD *thd, + char *key, uint key_len, + uint8 type, + Query_cache *cache, + Query_cache_block_table **block_table, + handler *file, + uint *n) +{ + DBUG_ENTER("ha_partition::reg_query_cache_dependant_table"); + qc_engine_callback engine_callback; + ulonglong engine_data; + /* ask undelying engine */ + if (!file->register_query_cache_table(thd, key, + key_len, + &engine_callback, + &engine_data)) + { + DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s", + key, + key + table_share->db.length + 1)); + /* + As this can change from call to call, don't reset set + thd->lex->safe_to_cache_query + */ + thd->query_cache_is_applicable= 0; // Query can't be cached + DBUG_RETURN(TRUE); + } + (++(*block_table))->n= ++(*n); + if (!cache->insert_table(key_len, + key, (*block_table), + table_share->db.length, + type, + engine_callback, engine_data, + FALSE)) + DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); +} + + +my_bool ha_partition::register_query_cache_dependant_tables(THD *thd, + Query_cache *cache, + Query_cache_block_table **block_table, + uint *n) +{ + char *name; + uint prefix_length= table_share->table_cache_key.length + 3; + uint num_parts= m_part_info->num_parts; + uint num_subparts= m_part_info->num_subparts; + uint i= 0; + List_iterator part_it(m_part_info->partitions); + char key[FN_REFLEN]; + + DBUG_ENTER("ha_partition::register_query_cache_dependant_tables"); + + /* prepare static part of the key */ + memmove(key, table_share->table_cache_key.str, + table_share->table_cache_key.length); + + name= key + table_share->table_cache_key.length - 1; + name[0]= name[2]= '#'; + name[1]= 'P'; + name+= 3; + + do + { + partition_element *part_elem= part_it++; + uint part_len= strmov(name, part_elem->partition_name) - name; + if (m_is_sub_partitioned) + { + List_iterator subpart_it(part_elem->subpartitions); + partition_element *sub_elem; + char *sname= name + part_len; + uint j= 0, part; + sname[0]= sname[3]= '#'; + sname[1]= 'S'; + sname[2]= 'P'; + sname += 4; + do + { + sub_elem= subpart_it++; + part= i * num_subparts + j; + uint spart_len= strmov(sname, sub_elem->partition_name) - name + 1; + if (reg_query_cache_dependant_table(thd, key, + prefix_length + part_len + 4 + + spart_len, + m_file[part]->table_cache_type(), + cache, + block_table, m_file[part], + n)) + DBUG_RETURN(TRUE); + } while (++j < num_subparts); + } + else + { + if (reg_query_cache_dependant_table(thd, key, + prefix_length + part_len + 1, + m_file[i]->table_cache_type(), + cache, + block_table, m_file[i], + n)) + DBUG_RETURN(TRUE); + } + } while (++i < num_parts); + DBUG_PRINT("info", ("cnt: %u", (uint)m_tot_parts)); + DBUG_RETURN(FALSE); +} + /* Set up table share object before calling create on underlying handler diff --git a/sql/ha_partition.h b/sql/ha_partition.h index aa9179f9f69..0f922394ec5 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -544,22 +544,20 @@ public: virtual int extra(enum ha_extra_function operation); virtual int extra_opt(enum ha_extra_function operation, ulong cachesize); virtual int reset(void); - /* - Do not allow caching of partitioned tables, since we cannot return - a callback or engine_data that would work for a generic engine. - */ - virtual my_bool register_query_cache_table(THD *thd, char *table_key, - uint key_length, - qc_engine_callback - *engine_callback, - ulonglong *engine_data) - { - *engine_callback= NULL; - *engine_data= 0; - return FALSE; - } + virtual uint count_query_cache_dependant_tables(uint8 *tables_type); + virtual my_bool + register_query_cache_dependant_tables(THD *thd, + Query_cache *cache, + Query_cache_block_table **block, + uint *n); private: + my_bool reg_query_cache_dependant_table(THD *thd, + char *key, uint key_len, uint8 type, + Query_cache *cache, + Query_cache_block_table + **block_table, + handler *file, uint *n); static const uint NO_CURRENT_PART_ID; int loop_extra(enum ha_extra_function operation); void late_extra_cache(uint partition_id); diff --git a/sql/handler.h b/sql/handler.h index ee1731af563..217c8103cd7 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1689,6 +1689,8 @@ public: virtual ~handler_add_index() {} }; +class Query_cache; +class Query_cache_block_table; /** The handler class is the interface for dynamically loadable storage engines. Do not add ifdefs and take care when adding or @@ -2522,6 +2524,46 @@ public: return TRUE; } + /* + Count tables invisible from all tables list on which current one built + (like myisammrg and partitioned tables) + + tables_type mask for the tables should be added herdde + + returns number of such tables + */ + + virtual uint count_query_cache_dependant_tables(uint8 *tables_type + __attribute__((unused))) + { + return 0; + } + + /* + register tables invisible from all tables list on which current one built + (like myisammrg and partitioned tables). + + @note they should be counted by method above + + cache Query cache pointer + block Query cache block to write the table + n Number of the table + + @retval FALSE - OK + @retval TRUE - Error + */ + + virtual my_bool + register_query_cache_dependant_tables(THD *thd + __attribute__((unused)), + Query_cache *cache + __attribute__((unused)), + Query_cache_block_table **block + __attribute__((unused)), + uint *n __attribute__((unused))) + { + return FALSE; + } /* Check if the primary key (if there is one) is a clustered and a diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 96814562757..7edd28446a2 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1533,7 +1533,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", unlock(); goto end; } - if (!register_all_tables(query_block, tables_used, local_tables)) + if (!register_all_tables(thd, query_block, tables_used, local_tables)) { refused++; DBUG_PRINT("warning", ("tables list including failed")); @@ -3203,6 +3203,7 @@ Query_cache::invalidate_query_block_list(THD *thd, SYNOPSIS Query_cache::register_tables_from_list + thd thread handle tables_used given table list counter number current position in table of tables of block block_table pointer to current position in tables table of block @@ -3213,24 +3214,24 @@ Query_cache::invalidate_query_block_list(THD *thd, */ TABLE_COUNTER_TYPE -Query_cache::register_tables_from_list(TABLE_LIST *tables_used, +Query_cache::register_tables_from_list(THD *thd, TABLE_LIST *tables_used, TABLE_COUNTER_TYPE counter, - Query_cache_block_table *block_table) + Query_cache_block_table **block_table) { TABLE_COUNTER_TYPE n; DBUG_ENTER("Query_cache::register_tables_from_list"); for (n= counter; tables_used; - tables_used= tables_used->next_global, n++, block_table++) + tables_used= tables_used->next_global, n++, (*block_table)++) { if (tables_used->is_anonymous_derived_table()) { DBUG_PRINT("qcache", ("derived table skipped")); n--; - block_table--; + (*block_table)--; continue; } - block_table->n= n; + (*block_table)->n= n; if (tables_used->view) { char key[MAX_DBKEY_LENGTH]; @@ -3243,9 +3244,9 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used, /* There are not callback function for for VIEWs */ - if (!insert_table(key_length, key, block_table, + if (!insert_table(key_length, key, (*block_table), tables_used->view_db.length + 1, - HA_CACHE_TBL_NONTRANSACT, 0, 0)) + HA_CACHE_TBL_NONTRANSACT, 0, 0, TRUE)) DBUG_RETURN(0); /* We do not need to register view tables here because they are already @@ -3264,42 +3265,17 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used, if (!insert_table(tables_used->table->s->table_cache_key.length, tables_used->table->s->table_cache_key.str, - block_table, + (*block_table), tables_used->db_length, tables_used->table->file->table_cache_type(), tables_used->callback_func, - tables_used->engine_data)) + tables_used->engine_data, + TRUE)) DBUG_RETURN(0); -#ifdef WITH_MYISAMMRG_STORAGE_ENGINE - /* - XXX FIXME: Some generic mechanism is required here instead of this - MYISAMMRG-specific implementation. - */ - if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM) - { - ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file; - MYRG_INFO *file = handler->myrg_info(); - for (MYRG_TABLE *table = file->open_tables; - table != file->end_table ; - table++) - { - char key[MAX_DBKEY_LENGTH]; - uint32 db_length; - uint key_length= filename_2_table_key(key, table->table->filename, - &db_length); - (++block_table)->n= ++n; - /* - There are not callback function for for MyISAM, and engine data - */ - if (!insert_table(key_length, key, block_table, - db_length, - tables_used->table->file->table_cache_type(), - 0, 0)) - DBUG_RETURN(0); - } - } -#endif + if (tables_used->table->file-> + register_query_cache_dependant_tables(thd, this, block_table, &n)) + DBUG_RETURN(0); } } DBUG_RETURN(n - counter); @@ -3310,12 +3286,14 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used, SYNOPSIS register_all_tables() + thd Thread handle block Store tables in this block tables_used List if used tables tables_arg Not used ? */ -my_bool Query_cache::register_all_tables(Query_cache_block *block, +my_bool Query_cache::register_all_tables(THD *thd, + Query_cache_block *block, TABLE_LIST *tables_used, TABLE_COUNTER_TYPE tables_arg) { @@ -3326,7 +3304,7 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block, Query_cache_block_table *block_table = block->table(0); - n= register_tables_from_list(tables_used, 0, block_table); + n= register_tables_from_list(thd, tables_used, 0, &block_table); if (n==0) { @@ -3335,6 +3313,8 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block, tmp != block_table; tmp++) unlink_table(tmp); + if (block_table->parent) + unlink_table(block_table); } return test(n); } @@ -3353,7 +3333,8 @@ Query_cache::insert_table(uint key_len, char *key, Query_cache_block_table *node, uint32 db_length, uint8 cache_type, qc_engine_callback callback, - ulonglong engine_data) + ulonglong engine_data, + my_bool hash) { DBUG_ENTER("Query_cache::insert_table"); DBUG_PRINT("qcache", ("insert table node 0x%lx, len %d", @@ -3361,8 +3342,10 @@ Query_cache::insert_table(uint key_len, char *key, THD *thd= current_thd; - Query_cache_block *table_block= - (Query_cache_block *) my_hash_search(&tables, (uchar*) key, key_len); + Query_cache_block *table_block= + (hash ? + (Query_cache_block *) my_hash_search(&tables, (uchar*) key, key_len) : + NULL); if (table_block && table_block->table()->engine_data() != engine_data) @@ -3412,7 +3395,8 @@ Query_cache::insert_table(uint key_len, char *key, */ list_root->next= list_root->prev= list_root; - if (my_hash_insert(&tables, (const uchar *) table_block)) + if (hash && + my_hash_insert(&tables, (const uchar *) table_block)) { DBUG_PRINT("qcache", ("Can't insert table to hash")); // write_block_data return locked block @@ -3425,6 +3409,7 @@ Query_cache::insert_table(uint key_len, char *key, header->type(cache_type); header->callback(callback); header->engine_data(engine_data); + header->set_hashed(hash); /* We insert this table without the assumption that it isn't refrenenced by @@ -3478,7 +3463,9 @@ void Query_cache::unlink_table(Query_cache_block_table *node) Query_cache_block *table_block= neighbour->block(); double_linked_list_exclude(table_block, &tables_blocks); - my_hash_delete(&tables,(uchar *) table_block); + Query_cache_table *header= table_block->table(); + if (header->is_hashed()) + my_hash_delete(&tables,(uchar *) table_block); free_memory_block(table_block); } DBUG_VOID_RETURN; @@ -3951,6 +3938,9 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, table_alias_charset used here because it depends of lower_case_table_names variable */ + table_count+= tables_used->table->file-> + count_query_cache_dependant_tables(tables_type); + if (tables_used->table->s->tmp_table != NO_TMP_TABLE || (*tables_type & HA_CACHE_TBL_NOCACHE) || (tables_used->db_length == 5 && @@ -3963,18 +3953,6 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, "other non-cacheable table(s)")); DBUG_RETURN(0); } -#ifdef WITH_MYISAMMRG_STORAGE_ENGINE - /* - XXX FIXME: Some generic mechanism is required here instead of this - MYISAMMRG-specific implementation. - */ - if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM) - { - ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file; - MYRG_INFO *file = handler->myrg_info(); - table_count+= (file->end_table - file->open_tables); - } -#endif } } DBUG_RETURN(table_count); diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 87291e80a85..7444d444cf9 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -200,6 +200,10 @@ struct Query_cache_table The number of queries depending of this table. */ int32 m_cached_query_count; + /** + If table included in the table hash to be found by other queries + */ + my_bool hashed; inline char *db() { return (char *) data(); } inline char *table() { return tbl; } @@ -212,6 +216,8 @@ struct Query_cache_table inline void callback(qc_engine_callback fn){ callback_func= fn; } inline ulonglong engine_data() { return engine_data_buff; } inline void engine_data(ulonglong data_arg){ engine_data_buff= data_arg; } + inline my_bool is_hashed() { return hashed; } + inline void set_hashed(my_bool hash) { hashed= hash; } inline uchar* data() { return (uchar*)(((uchar*)this)+ @@ -343,10 +349,6 @@ protected: static void double_linked_list_join(Query_cache_block *head_tail, Query_cache_block *tail_head); - /* Table key generation */ - static uint filename_2_table_key (char *key, const char *filename, - uint32 *db_langth); - /* The following functions require that structure_guard_mutex is locked */ void flush_cache(); my_bool free_old_query(); @@ -363,17 +365,12 @@ protected: Query_cache_block_table *list_root); TABLE_COUNTER_TYPE - register_tables_from_list(TABLE_LIST *tables_used, + register_tables_from_list(THD *thd, TABLE_LIST *tables_used, TABLE_COUNTER_TYPE counter, - Query_cache_block_table *block_table); - my_bool register_all_tables(Query_cache_block *block, + Query_cache_block_table **block_table); + my_bool register_all_tables(THD *thd, Query_cache_block *block, TABLE_LIST *tables_used, TABLE_COUNTER_TYPE tables); - my_bool insert_table(uint key_len, char *key, - Query_cache_block_table *node, - uint32 db_length, uint8 cache_type, - qc_engine_callback callback, - ulonglong engine_data); void unlink_table(Query_cache_block_table *node); Query_cache_block *get_free_block (ulong len, my_bool not_less, ulong min); @@ -491,6 +488,12 @@ protected: const char *packet, ulong length, unsigned pkt_nr); + my_bool insert_table(uint key_len, char *key, + Query_cache_block_table *node, + uint32 db_length, uint8 cache_type, + qc_engine_callback callback, + ulonglong engine_data, + my_bool hash); void end_of_result(THD *thd); void abort(Query_cache_tls *query_cache_tls); @@ -513,6 +516,10 @@ protected: const char *name); my_bool in_blocks(Query_cache_block * point); + /* Table key generation */ + static uint filename_2_table_key (char *key, const char *filename, + uint32 *db_langth); + enum Cache_try_lock_mode {WAIT, TIMEOUT, TRY}; bool try_lock(THD *thd, Cache_try_lock_mode mode= WAIT); void lock(THD *thd); diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index e6bece5b7ff..47a3abb78d2 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1652,6 +1652,47 @@ ha_rows ha_myisammrg::records() return myrg_records(file); } +uint ha_myisammrg::count_query_cache_dependant_tables(uint8 *tables_type) +{ + MYRG_INFO *file = myrg_info(); + /* + Here should be following statement + (*tables_type)|= HA_CACHE_TBL_NONTRANSACT; + but it has no effect because HA_CACHE_TBL_NONTRANSACT is 0 + */ + return (file->end_table - file->open_tables); +} + + +my_bool ha_myisammrg::register_query_cache_dependant_tables(THD *thd + __attribute__((unused)), + Query_cache *cache, + Query_cache_block_table **block_table, + uint *n) +{ + MYRG_INFO *file =myrg_info(); + DBUG_ENTER("ha_myisammrg::register_query_cache_dependant_tables"); + + for (MYRG_TABLE *table =file->open_tables; + table != file->end_table ; + table++) + { + char key[MAX_DBKEY_LENGTH]; + uint32 db_length; + uint key_length= cache->filename_2_table_key(key, table->table->filename, + &db_length); + (++(*block_table))->n= ++(*n); + /* + There are not callback function for for MyISAM, and engine data + */ + if (!cache->insert_table(key_length, key, (*block_table), + db_length, + table_cache_type(), + 0, 0, TRUE)) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} extern int myrg_panic(enum ha_panic_function flag); int myisammrg_panic(handlerton *hton, ha_panic_function flag) diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index e0dc6e07542..f5ba2ffef38 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -149,4 +149,10 @@ public: bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); int check(THD* thd, HA_CHECK_OPT* check_opt); ha_rows records(); + virtual uint count_query_cache_dependant_tables(uint8 *tables_type); + virtual my_bool + register_query_cache_dependant_tables(THD *thd, + Query_cache *cache, + Query_cache_block_table **block, + uint *n); }; -- cgit v1.2.1 From 49da8e7e212ec2ba739b9a7e2f512f1f71c62f1e Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Mon, 16 Jul 2012 06:12:11 +0400 Subject: Export sys_errno and errno to variables --- client/mysqltest.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 961114c9a40..57b7ff5fa0a 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -621,6 +621,8 @@ void free_all_replace(){ free_replace_column(); } +void var_set_int(const char* name, int value); + class LogFile { FILE* m_file; @@ -1275,6 +1277,8 @@ void handle_command_error(struct st_command *command, uint error, { DBUG_ENTER("handle_command_error"); DBUG_PRINT("enter", ("error: %d", error)); + var_set_int("$sys_errno",sys_errno); + var_set_int("$errno",error); if (error != 0) { int i; -- cgit v1.2.1 From 403cac0fe710bbd65a65f5b409cff6194ce6bace Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Mon, 16 Jul 2012 06:14:53 +0400 Subject: Allow multiple error codes inside a variable in --error command --- client/mysqltest.cc | 33 +++++++++++++++++++++++++++------ mysql-test/r/mysqltest.result | 1 + mysql-test/t/mysqltest.test | 5 +++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 57b7ff5fa0a..f204f359656 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5205,15 +5205,32 @@ const char *get_errname_from_code (uint error_code) void do_get_errcodes(struct st_command *command) { struct st_match_err *to= saved_expected_errors.err; - char *p= command->first_argument; - uint count= 0; - char *next; - DBUG_ENTER("do_get_errcodes"); - if (!*p) + if (!*command->first_argument) die("Missing argument(s) to 'error'"); + /* TODO: Potentially, there is a possibility of variables + being expanded twice, e.g. + + let $errcodes = 1,\$a; + let $a = 1051; + error $errcodes; + DROP TABLE unknown_table; + ... + Got one of the listed errors + + But since it requires manual escaping, it does not seem + particularly dangerous or error-prone. + */ + DYNAMIC_STRING ds; + init_dynamic_string(&ds, 0, command->query_len + 64, 256); + do_eval(&ds, command->first_argument, command->end, !is_windows); + char *p= ds.str; + + uint count= 0; + char *next; + do { char *end; @@ -5323,11 +5340,15 @@ void do_get_errcodes(struct st_command *command) } while (*p); - command->last_argument= p; + command->last_argument= command->first_argument; + while (*command->last_argument) + command->last_argument++; + to->type= ERR_EMPTY; /* End of data */ DBUG_PRINT("info", ("Expected errors: %d", count)); saved_expected_errors.count= count; + dynstr_free(&ds); DBUG_VOID_RETURN; } diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 25345227d59..fdb3029059f 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -690,6 +690,7 @@ Got one of the listed errors insert into t1 values ("Abcd"); Got one of the listed errors garbage; +SELECT * FROM non_existing_table; drop table t2; create table t1 ( f1 char(10)); insert into t1 values ("Abcd"); diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index a7585bea4f8..ffbec36873e 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -2120,6 +2120,11 @@ insert into t1 values ("Abcd"); --error $errno1,ER_PARSE_ERROR garbage; +let $errno_multi = $errno1,ER_NO_SUCH_TABLE,$errno2,1062; + +--error $errno_multi +SELECT * FROM non_existing_table; + drop table t2; -- cgit v1.2.1 From 72a5542f0ef1fbc36aabc511f18855f302906501 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Mon, 16 Jul 2012 06:17:56 +0400 Subject: MDEV-11: Generic storage engine test suite --- mysql-test/suite/storage_engine/1st.result | 11 + mysql-test/suite/storage_engine/1st.test | 81 + mysql-test/suite/storage_engine/alter_table.inc | 91 + mysql-test/suite/storage_engine/alter_table.result | 147 ++ mysql-test/suite/storage_engine/alter_table.test | 148 ++ .../suite/storage_engine/alter_table_online.result | 35 + .../suite/storage_engine/alter_table_online.test | 160 ++ .../suite/storage_engine/alter_tablespace.result | 19 + .../suite/storage_engine/alter_tablespace.test | 91 + mysql-test/suite/storage_engine/analyze_table.inc | 43 + .../suite/storage_engine/analyze_table.result | 29 + mysql-test/suite/storage_engine/analyze_table.test | 14 + .../suite/storage_engine/autoinc_secondary.result | 40 + .../suite/storage_engine/autoinc_secondary.test | 73 + .../suite/storage_engine/autoinc_vars.result | 55 + mysql-test/suite/storage_engine/autoinc_vars.test | 68 + .../suite/storage_engine/autoincrement.result | 133 ++ mysql-test/suite/storage_engine/autoincrement.test | 114 ++ mysql-test/suite/storage_engine/cache_index.result | 69 + mysql-test/suite/storage_engine/cache_index.test | 142 ++ mysql-test/suite/storage_engine/check_errors.inc | 80 + mysql-test/suite/storage_engine/check_table.inc | 62 + mysql-test/suite/storage_engine/check_table.result | 68 + mysql-test/suite/storage_engine/check_table.test | 14 + mysql-test/suite/storage_engine/checksum_table.inc | 31 + .../suite/storage_engine/checksum_table.result | 20 + .../suite/storage_engine/checksum_table.test | 11 + .../suite/storage_engine/checksum_table_live.inc | 30 + .../storage_engine/checksum_table_live.result | 20 + .../suite/storage_engine/checksum_table_live.test | 13 + mysql-test/suite/storage_engine/cleanup_engine.inc | 11 + mysql-test/suite/storage_engine/col_not_null.inc | 92 + mysql-test/suite/storage_engine/col_null.inc | 65 + .../suite/storage_engine/col_opt_default.result | 20 + .../suite/storage_engine/col_opt_default.test | 49 + .../suite/storage_engine/col_opt_not_null.result | 2062 ++++++++++++++++++++ .../suite/storage_engine/col_opt_not_null.test | 260 +++ .../suite/storage_engine/col_opt_null.result | 1991 +++++++++++++++++++ mysql-test/suite/storage_engine/col_opt_null.test | 208 ++ .../suite/storage_engine/col_opt_unsigned.result | 697 +++++++ .../suite/storage_engine/col_opt_unsigned.test | 95 + .../suite/storage_engine/col_opt_zerofill.result | 679 +++++++ .../suite/storage_engine/col_opt_zerofill.test | 88 + mysql-test/suite/storage_engine/create_table.inc | 174 ++ .../suite/storage_engine/create_table.result | 45 + mysql-test/suite/storage_engine/create_table.test | 107 + mysql-test/suite/storage_engine/define_engine.inc | 45 + mysql-test/suite/storage_engine/delete.result | 77 + mysql-test/suite/storage_engine/delete.test | 68 + .../suite/storage_engine/delete_ignore.result | 59 + mysql-test/suite/storage_engine/delete_ignore.test | 44 + .../suite/storage_engine/delete_low_prio.result | 59 + .../suite/storage_engine/delete_low_prio.test | 162 ++ .../suite/storage_engine/delete_quick.result | 25 + mysql-test/suite/storage_engine/delete_quick.test | 55 + .../suite/storage_engine/delete_with_keys.result | 38 + .../suite/storage_engine/delete_with_keys.test | 74 + mysql-test/suite/storage_engine/describe.result | 18 + mysql-test/suite/storage_engine/describe.test | 50 + mysql-test/suite/storage_engine/disabled.def | 0 .../suite/storage_engine/foreign_keys.result | 71 + mysql-test/suite/storage_engine/foreign_keys.test | 148 ++ .../suite/storage_engine/fulltext_search.result | 132 ++ .../suite/storage_engine/fulltext_search.test | 187 ++ mysql-test/suite/storage_engine/handler.result | 77 + mysql-test/suite/storage_engine/handler.test | 81 + .../suite/storage_engine/have_default_index.inc | 20 + mysql-test/suite/storage_engine/have_engine.inc | 127 ++ mysql-test/suite/storage_engine/index.inc | 194 ++ mysql-test/suite/storage_engine/index.result | 67 + mysql-test/suite/storage_engine/index.test | 23 + .../storage_engine/index_enable_disable.result | 45 + .../suite/storage_engine/index_enable_disable.test | 88 + .../storage_engine/index_key_block_size.result | 43 + .../suite/storage_engine/index_key_block_size.test | 125 ++ .../suite/storage_engine/index_primary.result | 53 + mysql-test/suite/storage_engine/index_primary.test | 136 ++ .../suite/storage_engine/index_type_btree.result | 67 + .../suite/storage_engine/index_type_btree.test | 12 + .../suite/storage_engine/index_type_hash.result | 67 + .../suite/storage_engine/index_type_hash.test | 12 + mysql-test/suite/storage_engine/insert.result | 149 ++ mysql-test/suite/storage_engine/insert.test | 78 + .../suite/storage_engine/insert_delayed.result | 25 + .../suite/storage_engine/insert_delayed.test | 62 + .../suite/storage_engine/insert_high_prio.result | 64 + .../suite/storage_engine/insert_high_prio.test | 143 ++ .../suite/storage_engine/insert_low_prio.result | 39 + .../suite/storage_engine/insert_low_prio.test | 95 + .../suite/storage_engine/insert_with_keys.result | 148 ++ .../suite/storage_engine/insert_with_keys.test | 143 ++ mysql-test/suite/storage_engine/loaddata.result | 68 + mysql-test/suite/storage_engine/loaddata.test | 88 + mysql-test/suite/storage_engine/lock.result | 111 ++ mysql-test/suite/storage_engine/lock.test | 244 +++ .../suite/storage_engine/lock_concurrent.result | 12 + .../suite/storage_engine/lock_concurrent.test | 52 + mysql-test/suite/storage_engine/mask_engine.inc | 14 + mysql-test/suite/storage_engine/misc.result | 79 + mysql-test/suite/storage_engine/misc.test | 47 + mysql-test/suite/storage_engine/my.cnf | 7 + mysql-test/suite/storage_engine/obfuscate.inc | 4 + mysql-test/suite/storage_engine/optimize_table.inc | 42 + .../suite/storage_engine/optimize_table.result | 29 + .../suite/storage_engine/optimize_table.test | 14 + .../suite/storage_engine/parts/alter_table.result | 42 + .../suite/storage_engine/parts/alter_table.test | 107 + .../storage_engine/parts/analyze_table.result | 47 + .../suite/storage_engine/parts/analyze_table.test | 61 + .../suite/storage_engine/parts/check_table.result | 104 + .../suite/storage_engine/parts/check_table.test | 82 + .../storage_engine/parts/checksum_table.result | 40 + .../suite/storage_engine/parts/checksum_table.test | 13 + .../suite/storage_engine/parts/create_table.result | 91 + .../suite/storage_engine/parts/create_table.test | 179 ++ mysql-test/suite/storage_engine/parts/my.cnf | 9 + .../storage_engine/parts/optimize_table.result | 54 + .../suite/storage_engine/parts/optimize_table.test | 69 + .../suite/storage_engine/parts/repair_table.result | 236 +++ .../suite/storage_engine/parts/repair_table.test | 78 + .../storage_engine/parts/truncate_table.result | 68 + .../suite/storage_engine/parts/truncate_table.test | 111 ++ mysql-test/suite/storage_engine/repair_table.inc | 155 ++ .../suite/storage_engine/repair_table.result | 106 + mysql-test/suite/storage_engine/repair_table.test | 14 + mysql-test/suite/storage_engine/replace.result | 47 + mysql-test/suite/storage_engine/replace.test | 67 + mysql-test/suite/storage_engine/se-innodb.out | 1 + mysql-test/suite/storage_engine/select.result | 390 ++++ mysql-test/suite/storage_engine/select.test | 210 ++ .../suite/storage_engine/select_high_prio.result | 45 + .../suite/storage_engine/select_high_prio.test | 139 ++ mysql-test/suite/storage_engine/show_engine.result | 11 + mysql-test/suite/storage_engine/show_engine.test | 31 + .../suite/storage_engine/show_table_status.result | 62 + .../suite/storage_engine/show_table_status.test | 30 + .../suite/storage_engine/strict_check_errors.inc | 23 + mysql-test/suite/storage_engine/tbl_opt_ai.result | 14 + mysql-test/suite/storage_engine/tbl_opt_ai.test | 35 + .../storage_engine/tbl_opt_avg_row_length.result | 16 + .../storage_engine/tbl_opt_avg_row_length.test | 35 + .../suite/storage_engine/tbl_opt_checksum.result | 16 + .../suite/storage_engine/tbl_opt_checksum.test | 30 + .../suite/storage_engine/tbl_opt_connection.result | 24 + .../suite/storage_engine/tbl_opt_connection.test | 52 + .../storage_engine/tbl_opt_data_index_dir.result | 16 + .../storage_engine/tbl_opt_data_index_dir.test | 51 + .../storage_engine/tbl_opt_delay_key_write.result | 16 + .../storage_engine/tbl_opt_delay_key_write.test | 35 + .../storage_engine/tbl_opt_insert_method.result | 16 + .../storage_engine/tbl_opt_insert_method.test | 35 + .../storage_engine/tbl_opt_key_block_size.result | 16 + .../storage_engine/tbl_opt_key_block_size.test | 35 + .../suite/storage_engine/tbl_opt_max_rows.result | 16 + .../suite/storage_engine/tbl_opt_max_rows.test | 35 + .../suite/storage_engine/tbl_opt_min_rows.result | 16 + .../suite/storage_engine/tbl_opt_min_rows.test | 35 + .../suite/storage_engine/tbl_opt_pack_keys.result | 16 + .../suite/storage_engine/tbl_opt_pack_keys.test | 35 + .../suite/storage_engine/tbl_opt_password.result | 16 + .../suite/storage_engine/tbl_opt_password.test | 40 + .../suite/storage_engine/tbl_opt_row_format.result | 16 + .../suite/storage_engine/tbl_opt_row_format.test | 35 + .../suite/storage_engine/tbl_opt_union.result | 14 + mysql-test/suite/storage_engine/tbl_opt_union.test | 41 + .../suite/storage_engine/tbl_standard_opts.result | 40 + .../suite/storage_engine/tbl_standard_opts.test | 60 + .../suite/storage_engine/tbl_temporary.result | 11 + mysql-test/suite/storage_engine/tbl_temporary.test | 32 + .../suite/storage_engine/truncate_table.result | 41 + .../suite/storage_engine/truncate_table.test | 81 + .../trx/cons_snapshot_repeatable_read.result | 18 + .../trx/cons_snapshot_repeatable_read.test | 9 + .../trx/cons_snapshot_serializable.result | 18 + .../trx/cons_snapshot_serializable.test | 9 + .../storage_engine/trx/consistent_snapshot.inc | 50 + mysql-test/suite/storage_engine/trx/delete.result | 72 + mysql-test/suite/storage_engine/trx/delete.test | 51 + mysql-test/suite/storage_engine/trx/insert.result | 55 + mysql-test/suite/storage_engine/trx/insert.test | 44 + .../storage_engine/trx/level_read_committed.result | 91 + .../storage_engine/trx/level_read_committed.test | 10 + .../trx/level_read_uncommitted.result | 116 ++ .../storage_engine/trx/level_read_uncommitted.test | 9 + .../trx/level_repeatable_read.result | 69 + .../storage_engine/trx/level_repeatable_read.test | 8 + .../storage_engine/trx/level_serializable.result | 56 + .../storage_engine/trx/level_serializable.test | 8 + mysql-test/suite/storage_engine/trx/my.cnf | 7 + .../storage_engine/trx/select_for_update.result | 35 + .../storage_engine/trx/select_for_update.test | 87 + .../trx/select_lock_in_share_mode.result | 37 + .../trx/select_lock_in_share_mode.test | 82 + .../storage_engine/trx/support_savepoints.inc | 10 + .../storage_engine/trx/support_transactions.inc | 10 + mysql-test/suite/storage_engine/trx/support_xa.inc | 12 + .../storage_engine/trx/transaction_isolation.inc | 99 + mysql-test/suite/storage_engine/trx/update.result | 48 + mysql-test/suite/storage_engine/trx/update.test | 50 + mysql-test/suite/storage_engine/trx/xa.result | 96 + mysql-test/suite/storage_engine/trx/xa.test | 118 ++ .../suite/storage_engine/trx/xa_recovery.result | 29 + .../suite/storage_engine/trx/xa_recovery.test | 71 + mysql-test/suite/storage_engine/type_binary.inc | 52 + mysql-test/suite/storage_engine/type_binary.result | 62 + mysql-test/suite/storage_engine/type_binary.test | 10 + .../storage_engine/type_binary_indexes.result | 126 ++ .../suite/storage_engine/type_binary_indexes.test | 149 ++ mysql-test/suite/storage_engine/type_bit.inc | 76 + mysql-test/suite/storage_engine/type_bit.result | 47 + mysql-test/suite/storage_engine/type_bit.test | 10 + .../suite/storage_engine/type_bit_indexes.result | 132 ++ .../suite/storage_engine/type_bit_indexes.test | 175 ++ mysql-test/suite/storage_engine/type_blob.inc | 65 + mysql-test/suite/storage_engine/type_blob.result | 54 + mysql-test/suite/storage_engine/type_blob.test | 10 + .../suite/storage_engine/type_blob_indexes.result | 152 ++ .../suite/storage_engine/type_blob_indexes.test | 188 ++ mysql-test/suite/storage_engine/type_bool.inc | 81 + mysql-test/suite/storage_engine/type_bool.result | 70 + mysql-test/suite/storage_engine/type_bool.test | 10 + mysql-test/suite/storage_engine/type_char.inc | 59 + mysql-test/suite/storage_engine/type_char.result | 56 + mysql-test/suite/storage_engine/type_char.test | 10 + .../suite/storage_engine/type_char_indexes.result | 144 ++ .../suite/storage_engine/type_char_indexes.test | 186 ++ mysql-test/suite/storage_engine/type_date_time.inc | 55 + .../suite/storage_engine/type_date_time.result | 48 + .../suite/storage_engine/type_date_time.test | 11 + .../storage_engine/type_date_time_indexes.result | 278 +++ .../storage_engine/type_date_time_indexes.test | 366 ++++ mysql-test/suite/storage_engine/type_enum.inc | 69 + mysql-test/suite/storage_engine/type_enum.result | 46 + mysql-test/suite/storage_engine/type_enum.test | 10 + .../suite/storage_engine/type_enum_indexes.result | 108 + .../suite/storage_engine/type_enum_indexes.test | 146 ++ mysql-test/suite/storage_engine/type_fixed.inc | 89 + mysql-test/suite/storage_engine/type_fixed.result | 116 ++ mysql-test/suite/storage_engine/type_fixed.test | 10 + .../suite/storage_engine/type_fixed_indexes.result | 148 ++ .../suite/storage_engine/type_fixed_indexes.test | 167 ++ mysql-test/suite/storage_engine/type_float.inc | 111 ++ mysql-test/suite/storage_engine/type_float.result | 286 +++ mysql-test/suite/storage_engine/type_float.test | 10 + .../suite/storage_engine/type_float_indexes.result | 146 ++ .../suite/storage_engine/type_float_indexes.test | 203 ++ mysql-test/suite/storage_engine/type_int.inc | 84 + mysql-test/suite/storage_engine/type_int.result | 209 ++ mysql-test/suite/storage_engine/type_int.test | 10 + .../suite/storage_engine/type_int_indexes.result | 133 ++ .../suite/storage_engine/type_int_indexes.test | 146 ++ mysql-test/suite/storage_engine/type_set.inc | 69 + mysql-test/suite/storage_engine/type_set.result | 48 + mysql-test/suite/storage_engine/type_set.test | 10 + .../suite/storage_engine/type_set_indexes.result | 137 ++ .../suite/storage_engine/type_set_indexes.test | 167 ++ mysql-test/suite/storage_engine/type_spatial.inc | 738 +++++++ .../suite/storage_engine/type_spatial.result | 700 +++++++ mysql-test/suite/storage_engine/type_spatial.test | 10 + .../storage_engine/type_spatial_indexes.result | 1400 +++++++++++++ .../suite/storage_engine/type_spatial_indexes.test | 15 + mysql-test/suite/storage_engine/type_text.inc | 65 + mysql-test/suite/storage_engine/type_text.result | 54 + mysql-test/suite/storage_engine/type_text.test | 10 + .../suite/storage_engine/type_text_indexes.result | 137 ++ .../suite/storage_engine/type_text_indexes.test | 175 ++ mysql-test/suite/storage_engine/type_varbinary.inc | 101 + .../suite/storage_engine/type_varbinary.result | 92 + .../suite/storage_engine/type_varbinary.test | 10 + mysql-test/suite/storage_engine/type_varchar.inc | 100 + .../suite/storage_engine/type_varchar.result | 127 ++ mysql-test/suite/storage_engine/type_varchar.test | 10 + .../suite/storage_engine/unexpected_result.inc | 50 + mysql-test/suite/storage_engine/update.result | 50 + mysql-test/suite/storage_engine/update.test | 43 + .../suite/storage_engine/update_ignore.result | 54 + mysql-test/suite/storage_engine/update_ignore.test | 43 + .../suite/storage_engine/update_low_prio.result | 66 + .../suite/storage_engine/update_low_prio.test | 167 ++ .../suite/storage_engine/update_multi.result | 65 + mysql-test/suite/storage_engine/update_multi.test | 44 + .../suite/storage_engine/update_with_keys.result | 90 + .../suite/storage_engine/update_with_keys.test | 152 ++ mysql-test/suite/storage_engine/vcol.result | 69 + mysql-test/suite/storage_engine/vcol.test | 72 + .../mysql-test/storage_engine/alter_tablespace.opt | 2 + .../storage_engine/autoinc_secondary.rdiff | 30 + .../mysql-test/storage_engine/cache_index.rdiff | 71 + .../storage_engine/checksum_table_live.rdiff | 13 + .../mysql-test/storage_engine/define_engine.inc | 45 + .../mysql-test/storage_engine/disabled.def | 9 + .../storage_engine/fulltext_search.rdiff | 150 ++ .../storage_engine/index_enable_disable.rdiff | 33 + .../storage_engine/index_type_hash.rdiff | 60 + .../mysql-test/storage_engine/insert_delayed.rdiff | 26 + .../storage_engine/lock_concurrent.rdiff | 22 + .../mysql-test/storage_engine/optimize_table.rdiff | 37 + .../storage_engine/parts/checksum_table.rdiff | 22 + .../storage_engine/parts/create_table.rdiff | 20 + .../storage_engine/parts/optimize_table.rdiff | 58 + .../storage_engine/parts/repair_table.rdiff | 228 +++ .../mysql-test/storage_engine/parts/suite.opt | 4 + .../mysql-test/storage_engine/repair_table.rdiff | 129 ++ .../innobase/mysql-test/storage_engine/suite.opt | 4 + .../storage_engine/tbl_opt_data_index_dir.rdiff | 18 + .../storage_engine/tbl_opt_insert_method.rdiff | 11 + .../storage_engine/tbl_opt_key_block_size.opt | 3 + .../storage_engine/tbl_opt_row_format.opt | 3 + .../storage_engine/tbl_opt_row_format.rdiff | 10 + .../mysql-test/storage_engine/tbl_opt_union.rdiff | 16 + .../mysql-test/storage_engine/trx/disabled.def | 2 + .../mysql-test/storage_engine/trx/suite.opt | 5 + .../storage_engine/type_char_indexes.rdiff | 20 + .../storage_engine/type_float_indexes.rdiff | 11 + .../storage_engine/type_spatial_indexes.rdiff | 712 +++++++ .../innobase/mysql-test/storage_engine/vcol.rdiff | 82 + .../storage_engine/alter_tablespace.rdiff | 32 + .../mysql-test/storage_engine/check_table.rdiff | 20 + .../mysql-test/storage_engine/define_engine.inc | 45 + .../mysql-test/storage_engine/foreign_keys.rdiff | 145 ++ .../storage_engine/index_type_hash.rdiff | 60 + .../mysql-test/storage_engine/show_engine.rdiff | 10 + .../storage_engine/tbl_opt_insert_method.rdiff | 11 + .../mysql-test/storage_engine/tbl_opt_union.rdiff | 16 + .../trx/cons_snapshot_repeatable_read.rdiff | 9 + .../trx/cons_snapshot_serializable.rdiff | 9 + .../mysql-test/storage_engine/trx/delete.rdiff | 50 + .../mysql-test/storage_engine/trx/insert.rdiff | 65 + .../storage_engine/trx/level_read_committed.rdiff | 44 + .../trx/level_read_uncommitted.rdiff | 7 + .../storage_engine/trx/level_repeatable_read.rdiff | 53 + .../storage_engine/trx/level_serializable.rdiff | 69 + .../storage_engine/trx/select_for_update.rdiff | 50 + .../trx/select_lock_in_share_mode.rdiff | 37 + .../mysql-test/storage_engine/trx/update.rdiff | 58 + .../myisam/mysql-test/storage_engine/trx/xa.rdiff | 89 + .../storage_engine/trx/xa_recovery.rdiff | 33 + .../mysql-test/storage_engine/alter_table.inc | 116 ++ .../mysql-test/storage_engine/alter_table.rdiff | 68 + .../storage_engine/alter_tablespace.rdiff | 27 + .../mysql-test/storage_engine/analyze_table.rdiff | 22 + .../mysql-test/storage_engine/autoincrement.rdiff | 34 + .../mysql-test/storage_engine/cache_index.rdiff | 46 + .../mysql-test/storage_engine/char_indexes.rdiff | 0 .../storage_engine/checksum_table_live.rdiff | 6 + .../mysql-test/storage_engine/cleanup_engine.inc | 16 + .../mysql-test/storage_engine/create_table.inc | 208 ++ .../mysql-test/storage_engine/create_table.rdiff | 37 + .../mysql-test/storage_engine/define_engine.inc | 49 + .../mysql-test/storage_engine/disabled.def | 2 + .../mysql-test/storage_engine/foreign_keys.rdiff | 138 ++ .../storage_engine/fulltext_search.rdiff | 142 ++ .../mysql-test/storage_engine/handler.rdiff | 79 + .../mysql-test/storage_engine/index.rdiff | 6 + .../storage_engine/index_enable_disable.rdiff | 17 + .../storage_engine/index_type_btree.rdiff | 6 + .../storage_engine/index_type_hash.rdiff | 34 + .../mysql-test/storage_engine/insert_delayed.rdiff | 14 + .../myisammrg/mysql-test/storage_engine/lock.rdiff | 62 + .../mysql-test/storage_engine/optimize_table.rdiff | 24 + .../storage_engine/parts/alter_table.rdiff | 63 + .../storage_engine/parts/analyze_table.rdiff | 83 + .../storage_engine/parts/check_table.rdiff | 172 ++ .../storage_engine/parts/checksum_table.rdiff | 81 + .../storage_engine/parts/create_table.rdiff | 156 ++ .../storage_engine/parts/optimize_table.rdiff | 91 + .../storage_engine/parts/repair_table.rdiff | 295 +++ .../storage_engine/parts/truncate_table.rdiff | 100 + .../mysql-test/storage_engine/repair_table.rdiff | 103 + .../mysql-test/storage_engine/show_engine.rdiff | 2 + .../mysql-test/storage_engine/tbl_opt_ai.rdiff | 8 + .../storage_engine/tbl_opt_avg_row_length.rdiff | 8 + .../storage_engine/tbl_opt_checksum.rdiff | 8 + .../storage_engine/tbl_opt_connection.rdiff | 8 + .../storage_engine/tbl_opt_data_index_dir.rdiff | 8 + .../storage_engine/tbl_opt_delay_key_write.rdiff | 8 + .../storage_engine/tbl_opt_insert_method.rdiff | 8 + .../storage_engine/tbl_opt_key_block_size.rdiff | 8 + .../storage_engine/tbl_opt_max_rows.rdiff | 8 + .../storage_engine/tbl_opt_min_rows.rdiff | 8 + .../storage_engine/tbl_opt_pack_keys.rdiff | 8 + .../storage_engine/tbl_opt_password.rdiff | 8 + .../storage_engine/tbl_opt_row_format.rdiff | 8 + .../mysql-test/storage_engine/tbl_opt_union.rdiff | 8 + .../storage_engine/tbl_standard_opts.rdiff | 8 + .../mysql-test/storage_engine/tbl_temporary.rdiff | 4 + .../mysql-test/storage_engine/truncate_table.rdiff | 35 + .../trx/cons_snapshot_repeatable_read.rdiff | 9 + .../trx/cons_snapshot_serializable.rdiff | 9 + .../mysql-test/storage_engine/trx/delete.rdiff | 34 + .../mysql-test/storage_engine/trx/insert.rdiff | 32 + .../storage_engine/trx/level_read_committed.rdiff | 44 + .../trx/level_read_uncommitted.rdiff | 7 + .../storage_engine/trx/level_repeatable_read.rdiff | 53 + .../storage_engine/trx/level_serializable.rdiff | 69 + .../storage_engine/trx/select_for_update.rdiff | 40 + .../trx/select_lock_in_share_mode.rdiff | 26 + .../mysql-test/storage_engine/trx/update.rdiff | 41 + .../mysql-test/storage_engine/trx/xa.rdiff | 34 + .../storage_engine/trx/xa_recovery.rdiff | 22 + .../storage_engine/type_char_indexes.rdiff | 8 + .../storage_engine/type_float_indexes.rdiff | 4 + .../mysql-test/storage_engine/type_spatial.rdiff | 706 +++++++ .../storage_engine/type_spatial_indexes.rdiff | 1412 ++++++++++++++ .../myisammrg/mysql-test/storage_engine/vcol.rdiff | 79 + 405 files changed, 36013 insertions(+) create mode 100644 mysql-test/suite/storage_engine/1st.result create mode 100644 mysql-test/suite/storage_engine/1st.test create mode 100644 mysql-test/suite/storage_engine/alter_table.inc create mode 100644 mysql-test/suite/storage_engine/alter_table.result create mode 100644 mysql-test/suite/storage_engine/alter_table.test create mode 100644 mysql-test/suite/storage_engine/alter_table_online.result create mode 100644 mysql-test/suite/storage_engine/alter_table_online.test create mode 100644 mysql-test/suite/storage_engine/alter_tablespace.result create mode 100644 mysql-test/suite/storage_engine/alter_tablespace.test create mode 100644 mysql-test/suite/storage_engine/analyze_table.inc create mode 100644 mysql-test/suite/storage_engine/analyze_table.result create mode 100644 mysql-test/suite/storage_engine/analyze_table.test create mode 100644 mysql-test/suite/storage_engine/autoinc_secondary.result create mode 100644 mysql-test/suite/storage_engine/autoinc_secondary.test create mode 100644 mysql-test/suite/storage_engine/autoinc_vars.result create mode 100644 mysql-test/suite/storage_engine/autoinc_vars.test create mode 100644 mysql-test/suite/storage_engine/autoincrement.result create mode 100644 mysql-test/suite/storage_engine/autoincrement.test create mode 100644 mysql-test/suite/storage_engine/cache_index.result create mode 100644 mysql-test/suite/storage_engine/cache_index.test create mode 100644 mysql-test/suite/storage_engine/check_errors.inc create mode 100644 mysql-test/suite/storage_engine/check_table.inc create mode 100644 mysql-test/suite/storage_engine/check_table.result create mode 100644 mysql-test/suite/storage_engine/check_table.test create mode 100644 mysql-test/suite/storage_engine/checksum_table.inc create mode 100644 mysql-test/suite/storage_engine/checksum_table.result create mode 100644 mysql-test/suite/storage_engine/checksum_table.test create mode 100644 mysql-test/suite/storage_engine/checksum_table_live.inc create mode 100644 mysql-test/suite/storage_engine/checksum_table_live.result create mode 100644 mysql-test/suite/storage_engine/checksum_table_live.test create mode 100644 mysql-test/suite/storage_engine/cleanup_engine.inc create mode 100644 mysql-test/suite/storage_engine/col_not_null.inc create mode 100644 mysql-test/suite/storage_engine/col_null.inc create mode 100644 mysql-test/suite/storage_engine/col_opt_default.result create mode 100644 mysql-test/suite/storage_engine/col_opt_default.test create mode 100644 mysql-test/suite/storage_engine/col_opt_not_null.result create mode 100644 mysql-test/suite/storage_engine/col_opt_not_null.test create mode 100644 mysql-test/suite/storage_engine/col_opt_null.result create mode 100644 mysql-test/suite/storage_engine/col_opt_null.test create mode 100644 mysql-test/suite/storage_engine/col_opt_unsigned.result create mode 100644 mysql-test/suite/storage_engine/col_opt_unsigned.test create mode 100644 mysql-test/suite/storage_engine/col_opt_zerofill.result create mode 100644 mysql-test/suite/storage_engine/col_opt_zerofill.test create mode 100644 mysql-test/suite/storage_engine/create_table.inc create mode 100644 mysql-test/suite/storage_engine/create_table.result create mode 100644 mysql-test/suite/storage_engine/create_table.test create mode 100644 mysql-test/suite/storage_engine/define_engine.inc create mode 100644 mysql-test/suite/storage_engine/delete.result create mode 100644 mysql-test/suite/storage_engine/delete.test create mode 100644 mysql-test/suite/storage_engine/delete_ignore.result create mode 100644 mysql-test/suite/storage_engine/delete_ignore.test create mode 100644 mysql-test/suite/storage_engine/delete_low_prio.result create mode 100644 mysql-test/suite/storage_engine/delete_low_prio.test create mode 100644 mysql-test/suite/storage_engine/delete_quick.result create mode 100644 mysql-test/suite/storage_engine/delete_quick.test create mode 100644 mysql-test/suite/storage_engine/delete_with_keys.result create mode 100644 mysql-test/suite/storage_engine/delete_with_keys.test create mode 100644 mysql-test/suite/storage_engine/describe.result create mode 100644 mysql-test/suite/storage_engine/describe.test create mode 100644 mysql-test/suite/storage_engine/disabled.def create mode 100644 mysql-test/suite/storage_engine/foreign_keys.result create mode 100644 mysql-test/suite/storage_engine/foreign_keys.test create mode 100644 mysql-test/suite/storage_engine/fulltext_search.result create mode 100644 mysql-test/suite/storage_engine/fulltext_search.test create mode 100644 mysql-test/suite/storage_engine/handler.result create mode 100644 mysql-test/suite/storage_engine/handler.test create mode 100644 mysql-test/suite/storage_engine/have_default_index.inc create mode 100644 mysql-test/suite/storage_engine/have_engine.inc create mode 100644 mysql-test/suite/storage_engine/index.inc create mode 100644 mysql-test/suite/storage_engine/index.result create mode 100644 mysql-test/suite/storage_engine/index.test create mode 100644 mysql-test/suite/storage_engine/index_enable_disable.result create mode 100644 mysql-test/suite/storage_engine/index_enable_disable.test create mode 100644 mysql-test/suite/storage_engine/index_key_block_size.result create mode 100644 mysql-test/suite/storage_engine/index_key_block_size.test create mode 100644 mysql-test/suite/storage_engine/index_primary.result create mode 100644 mysql-test/suite/storage_engine/index_primary.test create mode 100644 mysql-test/suite/storage_engine/index_type_btree.result create mode 100644 mysql-test/suite/storage_engine/index_type_btree.test create mode 100644 mysql-test/suite/storage_engine/index_type_hash.result create mode 100644 mysql-test/suite/storage_engine/index_type_hash.test create mode 100644 mysql-test/suite/storage_engine/insert.result create mode 100644 mysql-test/suite/storage_engine/insert.test create mode 100644 mysql-test/suite/storage_engine/insert_delayed.result create mode 100644 mysql-test/suite/storage_engine/insert_delayed.test create mode 100644 mysql-test/suite/storage_engine/insert_high_prio.result create mode 100644 mysql-test/suite/storage_engine/insert_high_prio.test create mode 100644 mysql-test/suite/storage_engine/insert_low_prio.result create mode 100644 mysql-test/suite/storage_engine/insert_low_prio.test create mode 100644 mysql-test/suite/storage_engine/insert_with_keys.result create mode 100644 mysql-test/suite/storage_engine/insert_with_keys.test create mode 100644 mysql-test/suite/storage_engine/loaddata.result create mode 100644 mysql-test/suite/storage_engine/loaddata.test create mode 100644 mysql-test/suite/storage_engine/lock.result create mode 100644 mysql-test/suite/storage_engine/lock.test create mode 100644 mysql-test/suite/storage_engine/lock_concurrent.result create mode 100644 mysql-test/suite/storage_engine/lock_concurrent.test create mode 100644 mysql-test/suite/storage_engine/mask_engine.inc create mode 100644 mysql-test/suite/storage_engine/misc.result create mode 100644 mysql-test/suite/storage_engine/misc.test create mode 100644 mysql-test/suite/storage_engine/my.cnf create mode 100644 mysql-test/suite/storage_engine/obfuscate.inc create mode 100644 mysql-test/suite/storage_engine/optimize_table.inc create mode 100644 mysql-test/suite/storage_engine/optimize_table.result create mode 100644 mysql-test/suite/storage_engine/optimize_table.test create mode 100644 mysql-test/suite/storage_engine/parts/alter_table.result create mode 100644 mysql-test/suite/storage_engine/parts/alter_table.test create mode 100644 mysql-test/suite/storage_engine/parts/analyze_table.result create mode 100644 mysql-test/suite/storage_engine/parts/analyze_table.test create mode 100644 mysql-test/suite/storage_engine/parts/check_table.result create mode 100644 mysql-test/suite/storage_engine/parts/check_table.test create mode 100644 mysql-test/suite/storage_engine/parts/checksum_table.result create mode 100644 mysql-test/suite/storage_engine/parts/checksum_table.test create mode 100644 mysql-test/suite/storage_engine/parts/create_table.result create mode 100644 mysql-test/suite/storage_engine/parts/create_table.test create mode 100644 mysql-test/suite/storage_engine/parts/my.cnf create mode 100644 mysql-test/suite/storage_engine/parts/optimize_table.result create mode 100644 mysql-test/suite/storage_engine/parts/optimize_table.test create mode 100644 mysql-test/suite/storage_engine/parts/repair_table.result create mode 100644 mysql-test/suite/storage_engine/parts/repair_table.test create mode 100644 mysql-test/suite/storage_engine/parts/truncate_table.result create mode 100644 mysql-test/suite/storage_engine/parts/truncate_table.test create mode 100644 mysql-test/suite/storage_engine/repair_table.inc create mode 100644 mysql-test/suite/storage_engine/repair_table.result create mode 100644 mysql-test/suite/storage_engine/repair_table.test create mode 100644 mysql-test/suite/storage_engine/replace.result create mode 100644 mysql-test/suite/storage_engine/replace.test create mode 100644 mysql-test/suite/storage_engine/se-innodb.out create mode 100644 mysql-test/suite/storage_engine/select.result create mode 100644 mysql-test/suite/storage_engine/select.test create mode 100644 mysql-test/suite/storage_engine/select_high_prio.result create mode 100644 mysql-test/suite/storage_engine/select_high_prio.test create mode 100644 mysql-test/suite/storage_engine/show_engine.result create mode 100644 mysql-test/suite/storage_engine/show_engine.test create mode 100644 mysql-test/suite/storage_engine/show_table_status.result create mode 100644 mysql-test/suite/storage_engine/show_table_status.test create mode 100644 mysql-test/suite/storage_engine/strict_check_errors.inc create mode 100644 mysql-test/suite/storage_engine/tbl_opt_ai.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_ai.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_avg_row_length.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_avg_row_length.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_checksum.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_checksum.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_connection.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_connection.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_data_index_dir.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_data_index_dir.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_delay_key_write.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_delay_key_write.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_insert_method.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_insert_method.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_key_block_size.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_key_block_size.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_max_rows.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_max_rows.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_min_rows.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_min_rows.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_pack_keys.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_pack_keys.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_password.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_password.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_row_format.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_row_format.test create mode 100644 mysql-test/suite/storage_engine/tbl_opt_union.result create mode 100644 mysql-test/suite/storage_engine/tbl_opt_union.test create mode 100644 mysql-test/suite/storage_engine/tbl_standard_opts.result create mode 100644 mysql-test/suite/storage_engine/tbl_standard_opts.test create mode 100644 mysql-test/suite/storage_engine/tbl_temporary.result create mode 100644 mysql-test/suite/storage_engine/tbl_temporary.test create mode 100644 mysql-test/suite/storage_engine/truncate_table.result create mode 100644 mysql-test/suite/storage_engine/truncate_table.test create mode 100644 mysql-test/suite/storage_engine/trx/cons_snapshot_repeatable_read.result create mode 100644 mysql-test/suite/storage_engine/trx/cons_snapshot_repeatable_read.test create mode 100644 mysql-test/suite/storage_engine/trx/cons_snapshot_serializable.result create mode 100644 mysql-test/suite/storage_engine/trx/cons_snapshot_serializable.test create mode 100644 mysql-test/suite/storage_engine/trx/consistent_snapshot.inc create mode 100644 mysql-test/suite/storage_engine/trx/delete.result create mode 100644 mysql-test/suite/storage_engine/trx/delete.test create mode 100644 mysql-test/suite/storage_engine/trx/insert.result create mode 100644 mysql-test/suite/storage_engine/trx/insert.test create mode 100644 mysql-test/suite/storage_engine/trx/level_read_committed.result create mode 100644 mysql-test/suite/storage_engine/trx/level_read_committed.test create mode 100644 mysql-test/suite/storage_engine/trx/level_read_uncommitted.result create mode 100644 mysql-test/suite/storage_engine/trx/level_read_uncommitted.test create mode 100644 mysql-test/suite/storage_engine/trx/level_repeatable_read.result create mode 100644 mysql-test/suite/storage_engine/trx/level_repeatable_read.test create mode 100644 mysql-test/suite/storage_engine/trx/level_serializable.result create mode 100644 mysql-test/suite/storage_engine/trx/level_serializable.test create mode 100644 mysql-test/suite/storage_engine/trx/my.cnf create mode 100644 mysql-test/suite/storage_engine/trx/select_for_update.result create mode 100644 mysql-test/suite/storage_engine/trx/select_for_update.test create mode 100644 mysql-test/suite/storage_engine/trx/select_lock_in_share_mode.result create mode 100644 mysql-test/suite/storage_engine/trx/select_lock_in_share_mode.test create mode 100644 mysql-test/suite/storage_engine/trx/support_savepoints.inc create mode 100644 mysql-test/suite/storage_engine/trx/support_transactions.inc create mode 100644 mysql-test/suite/storage_engine/trx/support_xa.inc create mode 100644 mysql-test/suite/storage_engine/trx/transaction_isolation.inc create mode 100644 mysql-test/suite/storage_engine/trx/update.result create mode 100644 mysql-test/suite/storage_engine/trx/update.test create mode 100644 mysql-test/suite/storage_engine/trx/xa.result create mode 100644 mysql-test/suite/storage_engine/trx/xa.test create mode 100644 mysql-test/suite/storage_engine/trx/xa_recovery.result create mode 100644 mysql-test/suite/storage_engine/trx/xa_recovery.test create mode 100644 mysql-test/suite/storage_engine/type_binary.inc create mode 100644 mysql-test/suite/storage_engine/type_binary.result create mode 100644 mysql-test/suite/storage_engine/type_binary.test create mode 100644 mysql-test/suite/storage_engine/type_binary_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_binary_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_bit.inc create mode 100644 mysql-test/suite/storage_engine/type_bit.result create mode 100644 mysql-test/suite/storage_engine/type_bit.test create mode 100644 mysql-test/suite/storage_engine/type_bit_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_bit_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_blob.inc create mode 100644 mysql-test/suite/storage_engine/type_blob.result create mode 100644 mysql-test/suite/storage_engine/type_blob.test create mode 100644 mysql-test/suite/storage_engine/type_blob_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_blob_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_bool.inc create mode 100644 mysql-test/suite/storage_engine/type_bool.result create mode 100644 mysql-test/suite/storage_engine/type_bool.test create mode 100644 mysql-test/suite/storage_engine/type_char.inc create mode 100644 mysql-test/suite/storage_engine/type_char.result create mode 100644 mysql-test/suite/storage_engine/type_char.test create mode 100644 mysql-test/suite/storage_engine/type_char_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_char_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_date_time.inc create mode 100644 mysql-test/suite/storage_engine/type_date_time.result create mode 100644 mysql-test/suite/storage_engine/type_date_time.test create mode 100644 mysql-test/suite/storage_engine/type_date_time_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_date_time_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_enum.inc create mode 100644 mysql-test/suite/storage_engine/type_enum.result create mode 100644 mysql-test/suite/storage_engine/type_enum.test create mode 100644 mysql-test/suite/storage_engine/type_enum_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_enum_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_fixed.inc create mode 100644 mysql-test/suite/storage_engine/type_fixed.result create mode 100644 mysql-test/suite/storage_engine/type_fixed.test create mode 100644 mysql-test/suite/storage_engine/type_fixed_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_fixed_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_float.inc create mode 100644 mysql-test/suite/storage_engine/type_float.result create mode 100644 mysql-test/suite/storage_engine/type_float.test create mode 100644 mysql-test/suite/storage_engine/type_float_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_float_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_int.inc create mode 100644 mysql-test/suite/storage_engine/type_int.result create mode 100644 mysql-test/suite/storage_engine/type_int.test create mode 100644 mysql-test/suite/storage_engine/type_int_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_int_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_set.inc create mode 100644 mysql-test/suite/storage_engine/type_set.result create mode 100644 mysql-test/suite/storage_engine/type_set.test create mode 100644 mysql-test/suite/storage_engine/type_set_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_set_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_spatial.inc create mode 100644 mysql-test/suite/storage_engine/type_spatial.result create mode 100644 mysql-test/suite/storage_engine/type_spatial.test create mode 100644 mysql-test/suite/storage_engine/type_spatial_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_spatial_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_text.inc create mode 100644 mysql-test/suite/storage_engine/type_text.result create mode 100644 mysql-test/suite/storage_engine/type_text.test create mode 100644 mysql-test/suite/storage_engine/type_text_indexes.result create mode 100644 mysql-test/suite/storage_engine/type_text_indexes.test create mode 100644 mysql-test/suite/storage_engine/type_varbinary.inc create mode 100644 mysql-test/suite/storage_engine/type_varbinary.result create mode 100644 mysql-test/suite/storage_engine/type_varbinary.test create mode 100644 mysql-test/suite/storage_engine/type_varchar.inc create mode 100644 mysql-test/suite/storage_engine/type_varchar.result create mode 100644 mysql-test/suite/storage_engine/type_varchar.test create mode 100644 mysql-test/suite/storage_engine/unexpected_result.inc create mode 100644 mysql-test/suite/storage_engine/update.result create mode 100644 mysql-test/suite/storage_engine/update.test create mode 100644 mysql-test/suite/storage_engine/update_ignore.result create mode 100644 mysql-test/suite/storage_engine/update_ignore.test create mode 100644 mysql-test/suite/storage_engine/update_low_prio.result create mode 100644 mysql-test/suite/storage_engine/update_low_prio.test create mode 100644 mysql-test/suite/storage_engine/update_multi.result create mode 100644 mysql-test/suite/storage_engine/update_multi.test create mode 100644 mysql-test/suite/storage_engine/update_with_keys.result create mode 100644 mysql-test/suite/storage_engine/update_with_keys.test create mode 100644 mysql-test/suite/storage_engine/vcol.result create mode 100644 mysql-test/suite/storage_engine/vcol.test create mode 100644 storage/innobase/mysql-test/storage_engine/alter_tablespace.opt create mode 100644 storage/innobase/mysql-test/storage_engine/autoinc_secondary.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/cache_index.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/checksum_table_live.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/define_engine.inc create mode 100644 storage/innobase/mysql-test/storage_engine/disabled.def create mode 100644 storage/innobase/mysql-test/storage_engine/fulltext_search.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/index_enable_disable.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/index_type_hash.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/insert_delayed.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/lock_concurrent.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/optimize_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/parts/checksum_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/parts/create_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/parts/optimize_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/parts/repair_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/parts/suite.opt create mode 100644 storage/innobase/mysql-test/storage_engine/repair_table.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/suite.opt create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_data_index_dir.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_insert_method.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_key_block_size.opt create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_row_format.opt create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_row_format.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/tbl_opt_union.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/trx/disabled.def create mode 100644 storage/innobase/mysql-test/storage_engine/trx/suite.opt create mode 100644 storage/innobase/mysql-test/storage_engine/type_char_indexes.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/type_float_indexes.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/type_spatial_indexes.rdiff create mode 100644 storage/innobase/mysql-test/storage_engine/vcol.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/alter_tablespace.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/check_table.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/define_engine.inc create mode 100644 storage/myisam/mysql-test/storage_engine/foreign_keys.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/index_type_hash.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/show_engine.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/tbl_opt_insert_method.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/tbl_opt_union.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/cons_snapshot_repeatable_read.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/cons_snapshot_serializable.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/delete.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/insert.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/level_read_committed.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/level_read_uncommitted.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/level_repeatable_read.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/level_serializable.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/select_for_update.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/select_lock_in_share_mode.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/update.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/xa.rdiff create mode 100644 storage/myisam/mysql-test/storage_engine/trx/xa_recovery.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/alter_table.inc create mode 100644 storage/myisammrg/mysql-test/storage_engine/alter_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/alter_tablespace.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/analyze_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/autoincrement.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/cache_index.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/char_indexes.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/checksum_table_live.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/cleanup_engine.inc create mode 100644 storage/myisammrg/mysql-test/storage_engine/create_table.inc create mode 100644 storage/myisammrg/mysql-test/storage_engine/create_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/define_engine.inc create mode 100644 storage/myisammrg/mysql-test/storage_engine/disabled.def create mode 100644 storage/myisammrg/mysql-test/storage_engine/foreign_keys.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/fulltext_search.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/handler.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/index.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/index_enable_disable.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/index_type_btree.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/index_type_hash.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/insert_delayed.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/lock.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/optimize_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/alter_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/analyze_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/check_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/checksum_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/create_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/optimize_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/repair_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/parts/truncate_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/repair_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/show_engine.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_ai.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_avg_row_length.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_checksum.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_connection.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_data_index_dir.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_delay_key_write.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_insert_method.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_key_block_size.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_max_rows.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_min_rows.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_pack_keys.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_password.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_row_format.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_opt_union.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_standard_opts.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/tbl_temporary.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/truncate_table.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/cons_snapshot_repeatable_read.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/cons_snapshot_serializable.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/delete.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/insert.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/level_read_committed.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/level_read_uncommitted.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/level_repeatable_read.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/level_serializable.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/select_for_update.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/select_lock_in_share_mode.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/update.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/xa.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/trx/xa_recovery.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/type_char_indexes.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/type_float_indexes.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/type_spatial.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/type_spatial_indexes.rdiff create mode 100644 storage/myisammrg/mysql-test/storage_engine/vcol.rdiff diff --git a/mysql-test/suite/storage_engine/1st.result b/mysql-test/suite/storage_engine/1st.result new file mode 100644 index 00000000000..6b686c2b2b4 --- /dev/null +++ b/mysql-test/suite/storage_engine/1st.result @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a , b ) ENGINE= ; +SHOW CREATE TABLE t1; +SHOW COLUMNS IN t1; +INSERT INTO t1 VALUES (1,'a'); +INSERT INTO t1 (a,b) VALUES (2,'b'); +SELECT * FROM t1; +a b +1 a +2 b +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/1st.test b/mysql-test/suite/storage_engine/1st.test new file mode 100644 index 00000000000..af7a4503948 --- /dev/null +++ b/mysql-test/suite/storage_engine/1st.test @@ -0,0 +1,81 @@ +# +# This test checks some very basic capabilities +# which will be used in almost every other test, +# and will not be checked through support* variables. +# If this test does not pass, there is no point +# at executing other ones. +# +# Minimal requirements: +# - supported column types: INT, CHAR (default CHAR(8), INT(11)); +# - column attributes as declared in define_engine.inc ($default_col_opts) +# (by default empty, which means no additional attributes apart from the type); +# - table attributes as declared in define_engine.inc ($default_tbl_opts) +# (by default empty, which means no additional attributes apart from ENGINE); +# - CREATE TABLE .. (column1 , column2 ) ENGINE=; +# - INSERT INTO TABLE .. VALUES (val1,val2); +# - DROP TABLE .. +# - SELECT * FROM .. +# - SHOW CREATE TABLE .. +# - SHOW COLUMNS IN ... +# + +--source have_engine.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = CREATE TABLE + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --disable_result_log + SHOW CREATE TABLE t1; + if ($mysql_errname) + { + --let $functionality = SHOW CREATE TABLE + --source unexpected_result.inc + } + SHOW COLUMNS IN t1; + if ($mysql_errname) + { + --let $functionality = SHOW COLUMNS + --source unexpected_result.inc + } + --enable_result_log + + INSERT INTO t1 VALUES (1,'a'); + if ($mysql_errname) + { + --let $functionality = INSERT INTO .. VALUES + --source unexpected_result.inc + } + + INSERT INTO t1 (a,b) VALUES (2,'b'); + if ($mysql_errname) + { + --let $functionality = INSERT INTO .. (column_list) VALUES + --source unexpected_result.inc + } + + SELECT * FROM t1; + if ($mysql_errname) + { + --let $functionality = SELECT * FROM .. + --source unexpected_result.inc + } + + DROP TABLE t1; + if ($mysql_errname) + { + --let $functionality = DROP TABLE + --source unexpected_result.inc + } + +} +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/alter_table.inc b/mysql-test/suite/storage_engine/alter_table.inc new file mode 100644 index 00000000000..0f78c597455 --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_table.inc @@ -0,0 +1,91 @@ +################################## +# +# This include file will be used for all ALTER TABLE statements in the suite. +# If you need to add additional steps or change the logic, copy the file +# to storage//mysql-test/storage_engine/ folder and modify it there. +# +################## +# +# Parameters: +# +# --let $alter_definition = # mandatory, everything that goes after the table name in ALTER statement +# --let $table_name = # optional, default t1 +# --let $error_codes = # optional, default 0 +# --let $online = [0|1] # optional, default 0 (1 adds ONLINE) +# --let $rename_to = # optional, default empty. +# # If set, means we are running RENAME TO, then alter definition is ignored +# +# Usage examples: +# +# --let $alter_definition = ADD COLUMN b $char_col DEFAULT '' +# + +if ($rename_to) +{ + --let $alter_definition = RENAME TO $rename_to +} + +if (!$alter_definition) +{ + --die # The ALTER statement is empty +} + +--let $alter_statement = ALTER + +if ($online) +{ + --let $alter_statement = $alter_statement ONLINE +} + +if (!$table_name) +{ + --let $table_name = t1 +} + +--let $alter_statement = $alter_statement TABLE $table_name $alter_definition + + +# We now have the complete ALTER statement in $alter_statement. +# If your ALTER statement should be composed differently, +# modify the logic above. + +##################### +# Here you can add logic needed BEFORE the main statement +# (e.g. base tables need to be altered, etc.). +# Surround it by --disable_query_log/--enable_query_log +# if you don't want it to appear in the result output. +##################### + +--source obfuscate.inc + +eval $alter_statement; +--source check_errors.inc + +# Make sure you don't add any statements between the main ALTER (above) +# and saving mysql_errno and mysql_errname (below) +# They are saved in case you want to add more logic after the main ALTER, +# because we need the result code of the statement. +# Also, do not change $alter_statement after it is executed! + +--let $my_errno = $mysql_errno +--let $my_errname = $mysql_errname + +##################### +# Here you can add logic needed AFTER the main statement. +# Surround it by --disable_query_log/--enable_query_log +# if you don't want it to appear in the result output. +##################### + +# Unset the parameters, we don't want them to be accidentally reused later +--let $alter_definition = +--let $table_name = +--let $error_codes = +--let $online = 0 +--let $rename_to = + +# Restore the error codes of the main statement +--let $mysql_errno = $my_errno +--let $mysql_errname = $my_errname +# Make sure you don't add any SQL statements after restoring +# mysql_errno and mysql_errname (above) + diff --git a/mysql-test/suite/storage_engine/alter_table.result b/mysql-test/suite/storage_engine/alter_table.result new file mode 100644 index 00000000000..6d868a27a36 --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_table.result @@ -0,0 +1,147 @@ +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (a , c ) ENGINE= ; +INSERT INTO t1 (a,c) VALUES (1,'a'),(5,'z'); +ALTER TABLE t1 ADD COLUMN b ; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `c` char(8) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 ALTER COLUMN a SET DEFAULT '0'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT '0', + `c` char(8) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 ALTER a DROP DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `c` char(8) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 CHANGE COLUMN b b1 FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b1` char(8) DEFAULT NULL, + `a` int(11), + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 CHANGE b1 b AFTER c; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `c` char(8) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 CHANGE b b ; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `c` char(8) DEFAULT NULL, + `b` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY COLUMN b ; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `c` char(8) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY COLUMN b FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` char(8) DEFAULT NULL, + `a` int(11), + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY COLUMN b AFTER a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `b` int(11) DEFAULT NULL, + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 DROP COLUMN b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11), + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME TO t2; +SHOW CREATE TABLE t1; +ERROR 42S02: Table 'test.t1' doesn't exist +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11), + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +DROP TABLE t2; +CREATE TABLE t1 (a , b ) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (1,5),(2,2),(4,3); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +ALTER TABLE t1 ORDER BY b ASC, a DESC; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 +SELECT * FROM t1; +a b +2 2 +4 3 +1 5 +DROP TABLE t1; +CREATE TABLE t1 (a , b , c ) ENGINE= CHARACTER SET latin1 COLLATE latin1_general_cs; +INSERT INTO t1 (a,b,c) VALUES (5,'z','t'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` char(8) COLLATE latin1_general_cs DEFAULT NULL, + `c` char(8) COLLATE latin1_general_cs DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs +ALTER TABLE t1 CONVERT TO CHARACTER SET utf8; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` char(8) DEFAULT NULL, + `c` char(8) DEFAULT NULL +) ENGINE= DEFAULT CHARSET=utf8 +ALTER TABLE t1 DEFAULT CHARACTER SET = latin1 COLLATE latin1_general_ci; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` char(8) CHARACTER SET utf8 DEFAULT NULL, + `c` char(8) CHARACTER SET utf8 DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci +ALTER TABLE t1 FORCE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` char(8) CHARACTER SET utf8 DEFAULT NULL, + `c` char(8) CHARACTER SET utf8 DEFAULT NULL +) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/alter_table.test b/mysql-test/suite/storage_engine/alter_table.test new file mode 100644 index 00000000000..023d8927e16 --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_table.test @@ -0,0 +1,148 @@ +# +# Basic ALTER TABLE statements. +# +# USAGE of table options in ALTER statements +# is covered in tbl_standard_opts and tbl_opt*.tests. +# +# Index operations are covered in index* tests. +# +# ALTER ONLINE syntax is covered in alter_online_table.test +# ALTER OFFLINE is not covered as it is not supported, as of 5.5.23 +# +# ALTER TABLE ... DISCARD|IMPORT TABLESPACE is covered in alter_tablespace.test +# + +--source have_engine.inc + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +--let $create_definition = a $int_col, c $char_col +--source create_table.inc +INSERT INTO t1 (a,c) VALUES (1,'a'),(5,'z'); + +# Column operations + +--let $alter_definition = ADD COLUMN b $int_col +--source alter_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc +} + +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = ALTER COLUMN a SET DEFAULT '0' +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = ALTER a DROP DEFAULT +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = CHANGE COLUMN b b1 $char_col FIRST +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = CHANGE b1 b $int_col AFTER c +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = CHANGE b b $char_col +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = MODIFY COLUMN b $int_col +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = MODIFY COLUMN b $char_col FIRST +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = MODIFY COLUMN b $int_col AFTER a +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = DROP COLUMN b +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + + +# Rename table + +--let $rename_to = t2 +--source alter_table.inc +--let $error_codes = ER_NO_SUCH_TABLE +SHOW CREATE TABLE t1; +--source check_errors.inc +if ($mysql_errname != 'ER_NO_SUCH_TABLE') +{ + --let $functionality = ALTER TABLE + --source unexpected_result.inc + DROP TABLE t1; +} +if ($mysql_errname == ER_NO_SUCH_TABLE) +{ + --source mask_engine.inc + SHOW CREATE TABLE t2; + DROP TABLE t2; +} + +# ORDER BY +--let $create_definition = a $int_col, b $int_col +--source create_table.inc +INSERT INTO t1 (a,b) VALUES (1,5),(2,2),(4,3); +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = ORDER BY b ASC, a DESC +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +# Character set, collate + +--let $table_options = CHARACTER SET latin1 COLLATE latin1_general_cs +--let $create_definition = a $int_col, b $char_col, c $char_col +--source create_table.inc +INSERT INTO t1 (a,b,c) VALUES (5,'z','t'); + +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = CONVERT TO CHARACTER SET utf8 +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +--let $alter_definition = DEFAULT CHARACTER SET = latin1 COLLATE latin1_general_ci +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +# A 'null' ALTER operation + +--let $alter_definition = FORCE +--source alter_table.inc +--source mask_engine.inc +SHOW CREATE TABLE t1; + +# Cleanup +DROP TABLE t1; + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/alter_table_online.result b/mysql-test/suite/storage_engine/alter_table_online.result new file mode 100644 index 00000000000..0e606bf1f7e --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_table_online.result @@ -0,0 +1,35 @@ +DROP TABLE IF EXISTS t1,t2,t3; +CREATE TABLE t1 (a , b , c ) ENGINE= ; +INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c'); +ALTER ONLINE TABLE t1 MODIFY b DEFAULT 5; +ALTER ONLINE TABLE t1 CHANGE b new_name ; +ALTER ONLINE TABLE t1 COMMENT 'new comment'; +ALTER ONLINE TABLE t1 RENAME TO t2; +DROP TABLE IF EXISTS t2; +CREATE TEMPORARY TABLE t1 (a , b ) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'); +ALTER ONLINE TABLE t1 MODIFY b DEFAULT 5; +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER ONLINE TABLE t1 CHANGE b new_name ; +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER ONLINE TABLE t1 COMMENT 'new comment'; +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER ONLINE TABLE t1 RENAME TO t2; +ERROR HY000: Can't execute the given 'ALTER' command as online +DROP TABLE t1; +CREATE TABLE t1 (a , b , c ) ENGINE= ; +INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c'); +ALTER ONLINE TABLE t1 DROP COLUMN b, ADD b ; +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER ONLINE TABLE t1 MODIFY b BIGINT ; +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER ONLINE TABLE t1 ENGINE=MEMORY; +ERROR HY000: Can't execute the given 'ALTER' command as online +DROP TABLE t1; +CREATE TABLE t1 (a , b , c ) ENGINE= ; +ALTER ONLINE TABLE t1 ADD INDEX (b); +ERROR HY000: Can't execute the given 'ALTER' command as online +ALTER TABLE t1 ADD INDEX (b); +ALTER ONLINE TABLE t1 DROP INDEX b; +ERROR HY000: Can't execute the given 'ALTER' command as online +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/alter_table_online.test b/mysql-test/suite/storage_engine/alter_table_online.test new file mode 100644 index 00000000000..94dec2a72bb --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_table_online.test @@ -0,0 +1,160 @@ +# +# ALTER ONLINE TABLE +# + +--source have_engine.inc + +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +--enable_warnings + +# +# Test of things that can be done online +# We are repeating notification here, because for some engines +# only a part of these ALTER ONLINE statements might be supported. +# + +let $create_definition = a $int_col, b $int_col, c $char_col; +--source create_table.inc + +INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c'); + +--let $online = 1 +--let $alter_definition = MODIFY b $int_col DEFAULT 5 +--source alter_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc +} + +--let $online = 1 +--let $alter_definition = CHANGE b new_name $int_col +--source alter_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc +} + +--let $online = 1 +--let $alter_definition = COMMENT 'new comment' +--source alter_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc +} + +--let $online = 1 +--let $rename_to = t2 +--source alter_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc + DROP TABLE t1; +} +DROP TABLE IF EXISTS t2; + +# +# temporary tables always require a copy +# + +--let $temporary = 1 +--source create_table.inc + +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'); + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = MODIFY b $int_col DEFAULT 5 +--source alter_table.inc +if ($mysql_errname != ER_CANT_DO_ONLINE) +{ + --source unexpected_result.inc +} + + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = CHANGE b new_name $int_col +--source alter_table.inc + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = COMMENT 'new comment' +--source alter_table.inc + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $rename_to = t2 +--source alter_table.inc + +DROP TABLE t1; + +# +# Test of things that is not possible to do online +# + +--let $create_definition = a $int_col, b $int_col, c $char_col +--source create_table.inc + +INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c'); + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = DROP COLUMN b, ADD b $int_col +--source alter_table.inc +if ($mysql_errname!=ER_CANT_DO_ONLINE) +{ + --source unexpected_result.inc +} + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = MODIFY b BIGINT $default_col_opts +--source alter_table.inc + +--let $alternative_engine = `SELECT engine FROM information_schema.engines WHERE engine != '$storage_engine' AND support IN ('YES','DEFAULT')` + +--let $error_codes = ER_CANT_DO_ONLINE +--let $online = 1 +--let $alter_definition = ENGINE=$alternative_engine +--source alter_table.inc + +DROP TABLE t1; + +--let $create_definition = a $int_col, b $int_indexed_col, c $char_col +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Column options + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --let $error_codes = ER_CANT_DO_ONLINE + --let $online = 1 + --let $alter_definition = ADD INDEX (b) + --source alter_table.inc + if ($mysql_errname!=ER_CANT_DO_ONLINE) + { + --let $functionality = Adding an index or ALTER ONLINE + --source unexpected_result.inc + } + + --let $alter_definition = ADD INDEX (b) + --source alter_table.inc + if ($mysql_errname) + { + --let $functionality = Adding an index or ALTER TABLE + --source unexpected_result.inc + } + if (!$mysql_errname) + { + --let $error_codes = ER_CANT_DO_ONLINE + --let $online = 1 + --let $alter_definition = DROP INDEX b + --source alter_table.inc + } + DROP TABLE t1; +} + +--source cleanup_engine.inc diff --git a/mysql-test/suite/storage_engine/alter_tablespace.result b/mysql-test/suite/storage_engine/alter_tablespace.result new file mode 100644 index 00000000000..5d8709b2357 --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_tablespace.result @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (a ) ENGINE= ; +ALTER TABLE t1 DISCARD TABLESPACE; +DROP TABLE t1; +CREATE TABLE t1 (a ) ENGINE= ; +INSERT INTO t1 (a) VALUES (1),(2); +SELECT * FROM t1; +a +1 +2 +ALTER TABLE t1 DISCARD TABLESPACE; +SELECT * FROM t1; +ERROR HY000: Got error -1 from storage engine +ALTER TABLE t1 IMPORT TABLESPACE; +SELECT * FROM t1; +a +1 +2 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/alter_tablespace.test b/mysql-test/suite/storage_engine/alter_tablespace.test new file mode 100644 index 00000000000..6c429bb98ea --- /dev/null +++ b/mysql-test/suite/storage_engine/alter_tablespace.test @@ -0,0 +1,91 @@ +# +# IMPORT / DISCARD TABLESPACE +# +# The test might require additional engine options, +# e.g. for InnoDB it is --innodb-file-per-table + +--source have_engine.inc + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +--let $create_definition = a $int_col +--source create_table.inc + +--let $alter_definition = DISCARD TABLESPACE + +--source alter_table.inc +if ($mysql_errname) +{ + --let $my_last_stmt = $alter_statement + --let $functionality = Tablespace operations + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + DROP TABLE t1; + + --let $create_definition = a $int_col + --source create_table.inc + INSERT INTO t1 (a) VALUES (1),(2); + --sorted_result + SELECT * FROM t1; + +# http://dev.mysql.com/doc/mysql-enterprise-backup/3.5/en/partial.restoring.single.html +# To get a "clean" backup we need to either use innobackup, or to monitor show engine innodb status, +# and the documented conditions do not look exactly feasible. So, we will go a simple way: +# just restart the server, and take the backup while the server is down. +# (And we need to have a really clean backup, see MySQL:65429 / LP:1004910) + + --let $datadir = `SELECT @@datadir` + + --write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +restart +wait +EOF + + --enable_reconnect + --shutdown_server 60 + + --source include/wait_until_disconnected.inc + + --replace_result $datadir + --copy_file $datadir/test/t1.ibd $datadir/test/t1.ibd.save + + --remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + --write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +restart +EOF + + --source include/wait_until_connected_again.inc + + --let $alter_definition = DISCARD TABLESPACE + --source alter_table.inc + + --let $error_codes = ER_GET_ERRNO + SELECT * FROM t1; + --source check_errors.inc + if ($mysql_errname != ER_GET_ERRNO) + { + --let $functionality = Tablespace operations + --source unexpected_result.inc + } + + --move_file $datadir/test/t1.ibd.save $datadir/test/t1.ibd + --let $alter_definition = IMPORT TABLESPACE + --source alter_table.inc + --sorted_result + SELECT * FROM t1; + + # Adding a warning suppression based on what InnoDB currently does + # when it attempts to access a table without an *.ibd file + --disable_query_log + eval CALL mtr.add_suppression('$storage_engine: Error:.*'); + --enable_query_log +} + +DROP TABLE t1; + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/analyze_table.inc b/mysql-test/suite/storage_engine/analyze_table.inc new file mode 100644 index 00000000000..2cbfc17aaa9 --- /dev/null +++ b/mysql-test/suite/storage_engine/analyze_table.inc @@ -0,0 +1,43 @@ +# +# ANALYZE TABLE statements +# +# Note: the output is likely to be different for the engine under test, +# in which case rdiff will be needed. Or, the output might say that +# the storage engine does not support ANALYZE. +# + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +--let $create_definition = a $int_col, b $char_col +--source create_table.inc +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +--let $create_definition = a $int_col, b $char_col +--let $table_name = t2 +--source create_table.inc + +INSERT INTO t1 (a,b) VALUES (3,'c'); +ANALYZE TABLE t1; +INSERT INTO t2 (a,b) VALUES (4,'d'); +ANALYZE NO_WRITE_TO_BINLOG TABLE t2; +INSERT INTO t1 (a,b) VALUES (5,'e'); +INSERT INTO t2 (a,b) VALUES (6,'f'); +ANALYZE LOCAL TABLE t1, t2; + +DROP TABLE t1, t2; + +--let $continue = 1 +--source have_default_index.inc + +if ($have_default_index) +{ + --let $create_definition = a $int_indexed_col, $default_index(a) + --source create_table.inc + INSERT INTO t1 (a) VALUES (1),(2),(4),(7); + ANALYZE TABLE t1; + INSERT INTO t1 (a) VALUES (8),(10),(11),(12); + ANALYZE TABLE t1; + DROP TABLE t1; +} + diff --git a/mysql-test/suite/storage_engine/analyze_table.result b/mysql-test/suite/storage_engine/analyze_table.result new file mode 100644 index 00000000000..42904ed334d --- /dev/null +++ b/mysql-test/suite/storage_engine/analyze_table.result @@ -0,0 +1,29 @@ +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (a , b ) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +CREATE TABLE t2 (a , b ) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (3,'c'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +INSERT INTO t2 (a,b) VALUES (4,'d'); +ANALYZE NO_WRITE_TO_BINLOG TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +INSERT INTO t1 (a,b) VALUES (5,'e'); +INSERT INTO t2 (a,b) VALUES (6,'f'); +ANALYZE LOCAL TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +DROP TABLE t1, t2; +CREATE TABLE t1 (a , (a)) ENGINE= ; +INSERT INTO t1 (a) VALUES (1),(2),(4),(7); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +INSERT INTO t1 (a) VALUES (8),(10),(11),(12); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/analyze_table.test b/mysql-test/suite/storage_engine/analyze_table.test new file mode 100644 index 00000000000..5222ec8af54 --- /dev/null +++ b/mysql-test/suite/storage_engine/analyze_table.test @@ -0,0 +1,14 @@ +# +# ANALYZE TABLE statements +# +# Note: the output is likely to be different for the engine under test, +# in which case rdiff will be needed. Or, the output might say that +# the storage engine does not support ANALYZE. +# + +--source have_engine.inc + +--source analyze_table.inc + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/autoinc_secondary.result b/mysql-test/suite/storage_engine/autoinc_secondary.result new file mode 100644 index 00000000000..ad2b43bc6fe --- /dev/null +++ b/mysql-test/suite/storage_engine/autoinc_secondary.result @@ -0,0 +1,40 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a AUTO_INCREMENT, b , PRIMARY KEY (a,b)) ENGINE= ; +INSERT INTO t1 (b) VALUES ('a'),('b'),('b'),('c'),('a'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +SELECT * FROM t1; +a b +1 a +2 b +3 b +4 c +5 a +DROP TABLE t1; +CREATE TABLE t1 (a , b AUTO_INCREMENT, PRIMARY KEY (a,b)) ENGINE= ; +INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +SELECT * FROM t1; +a b +a 1 +a 2 +b 1 +b 2 +c 1 +DROP TABLE t1; +CREATE TABLE t1 (a , b AUTO_INCREMENT, PRIMARY KEY (a,b), (b)) ENGINE= ; +INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +SELECT * FROM t1; +a b +a 1 +a 5 +b 2 +b 3 +c 4 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/autoinc_secondary.test b/mysql-test/suite/storage_engine/autoinc_secondary.test new file mode 100644 index 00000000000..8b95f1d859e --- /dev/null +++ b/mysql-test/suite/storage_engine/autoinc_secondary.test @@ -0,0 +1,73 @@ +# +# AUTO_INCREMENT on a secondary column in a multi-part key +# + +--source have_engine.inc +--source have_default_index.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# AUTO_INCREMENT is the primary column in a multiple-column index +# + +--let $create_definition = a $int_col AUTO_INCREMENT, b $char_col, PRIMARY KEY (a,b) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Multi-part keys or PK or AUTO_INCREMENT (on a primary column) + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (b) VALUES ('a'),('b'),('b'),('c'),('a'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +# +# AUTO_INCREMENT is the secondary column in a multiple-column index +# + +--let $create_definition = a $char_col, b $int_col AUTO_INCREMENT, PRIMARY KEY (a,b) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Multi-part keys or PK or AUTO_INCREMENT (on a secondary column) + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +# AUTO_INCREMENT is the secondary column in a multiple-column index, +# and primary in another index +# + +--let $create_definition = a $char_col, b $int_indexed_col AUTO_INCREMENT, PRIMARY KEY (a,b), $default_index(b) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Multi-part keys or AUTO_INCREMENT (on the secondary column) or multiple keys + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/autoinc_vars.result b/mysql-test/suite/storage_engine/autoinc_vars.result new file mode 100644 index 00000000000..60e7d74a22a --- /dev/null +++ b/mysql-test/suite/storage_engine/autoinc_vars.result @@ -0,0 +1,55 @@ +DROP TABLE IF EXISTS t1; +SET auto_increment_offset = 200; +CREATE TABLE t1 (a AUTO_INCREMENT, b , (a)) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'),(NULL,'c'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +SELECT * FROM t1; +a b +1 a +2 b +3 c +SET auto_increment_increment = 300; +INSERT INTO t1 (a,b) VALUES (NULL,'d'),(NULL,'e'),(NULL,'f'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +200 +SELECT * FROM t1; +a b +1 a +2 b +200 d +3 c +500 e +800 f +SET auto_increment_increment = 50; +INSERT INTO t1 (a,b) VALUES (NULL,'g'),(NULL,'h'),(NULL,'i'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +850 +SELECT * FROM t1; +a b +1 a +2 b +200 d +3 c +500 e +800 f +850 g +900 h +950 i +DROP TABLE t1; +SET auto_increment_increment = 500; +SET auto_increment_offset = 300; +CREATE TABLE t1 (a TINYINT AUTO_INCREMENT, (a)) ENGINE= ; +INSERT INTO t1 (a) VALUES (NULL); +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +127 +SELECT * FROM t1; +a +127 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/autoinc_vars.test b/mysql-test/suite/storage_engine/autoinc_vars.test new file mode 100644 index 00000000000..ceafcd7138f --- /dev/null +++ b/mysql-test/suite/storage_engine/autoinc_vars.test @@ -0,0 +1,68 @@ +# +# auto-increment-offset and auto-increment-increment +# + +--source have_engine.inc +--source have_default_index.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# auto_increment_offset +SET auto_increment_offset = 200; +--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = AUTO_INCREMENT + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + # If auto_increment_offset is greater than auto_increment_increment, + # the offset is ignored + INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'),(NULL,'c'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + + # auto_increment_increment + + SET auto_increment_increment = 300; + # offset should not be ignored anymore + INSERT INTO t1 (a,b) VALUES (NULL,'d'),(NULL,'e'),(NULL,'f'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + + SET auto_increment_increment = 50; + INSERT INTO t1 (a,b) VALUES (NULL,'g'),(NULL,'h'),(NULL,'i'); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +# offset is greater than the max value + +SET auto_increment_increment = 500; +SET auto_increment_offset = 300; +--let $create_definition = a TINYINT $default_col_indexed_opts AUTO_INCREMENT, $default_index(a) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = AUTO_INCREMENT + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (a) VALUES (NULL); + SELECT LAST_INSERT_ID(); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/autoincrement.result b/mysql-test/suite/storage_engine/autoincrement.result new file mode 100644 index 00000000000..bc51a2a82af --- /dev/null +++ b/mysql-test/suite/storage_engine/autoincrement.result @@ -0,0 +1,133 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a AUTO_INCREMENT, b , (a)) ENGINE= ; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL AUTO_INCREMENT, + `b` char(8) DEFAULT NULL, + KEY `a` (`a`) +) ENGINE= DEFAULT CHARSET=latin1 +INSERT INTO t1 (b) VALUES ('a'),('b'); +SELECT * FROM t1 ORDER BY a; +a b +1 a +2 b +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d'); +SELECT * FROM t1 ORDER BY a; +a b +1 a +2 b +3 c +4 d +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; +INSERT INTO t1 (a,b) VALUES (NULL,'e'); +SELECT * FROM t1 ORDER BY a; +a b +1 a +2 b +3 c +4 d +5 e +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5 +INSERT INTO t1 (a,b) VALUES (0,'f'); +SELECT * FROM t1 ORDER BY a; +a b +0 f +1 a +2 b +3 c +4 d +5 e +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5 +SET sql_mode = ''; +SHOW TABLE STATUS FROM test LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 # # # # # # # # 6 # # # # # # # +INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h'); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5 +SHOW TABLE STATUS FROM test LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 # # # # # # # # # 8 # # # # # # # +INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j'); +SELECT * FROM t1 ORDER BY a; +a b +0 f +1 a +2 b +3 c +4 d +5 e +6 g +7 h +8 i +9 j +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +8 +SHOW TABLE STATUS FROM test LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 # # # # # # # # # 10 # # # # # # # +INSERT INTO t1 (a,b) VALUES (20,'k'); +SHOW TABLE STATUS FROM test LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 # # # # # # # # # 21 # # # # # # # +INSERT INTO t1 (a,b) VALUES (NULL,'l'); +SELECT * FROM t1 ORDER BY a; +a b +0 f +1 a +2 b +3 c +4 d +5 e +6 g +7 h +8 i +9 j +20 k +21 l +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +21 +SHOW TABLE STATUS FROM test LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 # # # # # # # # # 22 # # # # # # # +INSERT INTO t1 (a,b) VALUES (-5,'m'); +SELECT * FROM t1 ORDER BY a; +a b +-5 m +0 f +1 a +2 b +3 c +4 d +5 e +6 g +7 h +8 i +9 j +20 k +21 l +DROP TABLE t1; +CREATE TABLE t1 (a AUTO_INCREMENT, b , (a)) ENGINE= AUTO_INCREMENT = 100; +INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'); +SELECT * FROM t1; +a b +100 a +101 b +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +100 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/autoincrement.test b/mysql-test/suite/storage_engine/autoincrement.test new file mode 100644 index 00000000000..fb07ea55c57 --- /dev/null +++ b/mysql-test/suite/storage_engine/autoincrement.test @@ -0,0 +1,114 @@ +# +# Basic AUTO_INCREMENT capabilities +# + +--source have_engine.inc + +--let $skip = 1 +--source have_default_index.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a) +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = AUTO_INCREMENT + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --source mask_engine.inc + SHOW CREATE TABLE t1; + + # Automatic values + + INSERT INTO t1 (b) VALUES ('a'),('b'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + let $sql_mode = `SELECT @@sql_mode`; + SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; + + INSERT INTO t1 (a,b) VALUES (NULL,'e'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + INSERT INTO t1 (a,b) VALUES (0,'f'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + --replace_result $sql_mode + eval SET sql_mode = '$sql_mode'; + + # SHOW TABLE STATUS shows the auto-increment value in column 11, + # that's all we need here and further + --source mask_engine.inc + --replace_column 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # + SHOW TABLE STATUS FROM test LIKE 't1'; + + # Mix of automatic and explicit values + + INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h'); + SELECT LAST_INSERT_ID(); + + --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # + SHOW TABLE STATUS FROM test LIKE 't1'; + + + INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # + SHOW TABLE STATUS FROM test LIKE 't1'; + + # Creating a gap in the sequence + + INSERT INTO t1 (a,b) VALUES (20,'k'); + + --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # + SHOW TABLE STATUS FROM test LIKE 't1'; + + INSERT INTO t1 (a,b) VALUES (NULL,'l'); + SELECT * FROM t1 ORDER BY a; + SELECT LAST_INSERT_ID(); + + --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # + SHOW TABLE STATUS FROM test LIKE 't1'; + + # Negative values: we will try to insert one just to check that it does not cause a crash, + # but won't check what happens to the sequence after that, since the behavior is undefined + + INSERT INTO t1 (a,b) VALUES (-5,'m'); + SELECT * FROM t1 ORDER BY a; + + DROP TABLE t1; +} + +# Autoincrement with table option AUTO_INCREMENT + +--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a) +--let $table_options = AUTO_INCREMENT = 100 +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = AUTO_INCREMENT column or table option + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'); + --sorted_result + SELECT * FROM t1; + SELECT LAST_INSERT_ID(); + DROP TABLE t1; +} +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/cache_index.result b/mysql-test/suite/storage_engine/cache_index.result new file mode 100644 index 00000000000..c8cf0ce2090 --- /dev/null +++ b/mysql-test/suite/storage_engine/cache_index.result @@ -0,0 +1,69 @@ +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (a , +b , + (a) +) ENGINE= ; +CREATE TABLE t2 (a , +b , + (b) +) ENGINE= ; +CACHE INDEX t1 INDEX (a), t2 IN ; +ERROR HY000: Unknown key cache '' +SET GLOBAL .key_buffer_size=128*1024; +CACHE INDEX t1 INDEX (a), t2 IN ; +Table Op Msg_type Msg_text +test.t1 assign_to_keycache status OK +test.t2 assign_to_keycache status OK +LOAD INDEX INTO CACHE t1, t2; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +test.t2 preload_keys status OK +INSERT INTO t1 (a,b) VALUES (3,'c'),(4,'d'); +SET GLOBAL .key_buffer_size=8*1024; +LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +test.t2 preload_keys status OK +SET GLOBAL .key_cache_age_threshold = 100, .key_cache_block_size = 512, .key_cache_division_limit = 1, .key_cache_segments=2; +INSERT INTO t1 (a,b) VALUES (5,'e'),(6,'f'); +LOAD INDEX INTO CACHE t1; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +SET GLOBAL new_.key_buffer_size=128*1024; +CACHE INDEX t1 IN new_; +Table Op Msg_type Msg_text +test.t1 assign_to_keycache status OK +INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h'); +LOAD INDEX INTO CACHE t1 IGNORE LEAVES; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +INSERT INTO t1 (a,b) VALUES (9,'i'); +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a , +b , + (a), + (b) +) ENGINE= ; +CACHE INDEX t1 IN ; +Table Op Msg_type Msg_text +test.t1 assign_to_keycache status OK +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +LOAD INDEX INTO CACHE t1; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +DROP TABLE t1; +CREATE TABLE t1 (a , +b , + a_b (a,b) +) ENGINE= ; +CACHE INDEX t1 IN ; +Table Op Msg_type Msg_text +test.t1 assign_to_keycache status OK +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +LOAD INDEX INTO CACHE t1; +Table Op Msg_type Msg_text +test.t1 preload_keys status OK +DROP TABLE t1; +SET GLOBAL .key_buffer_size=0; +SET GLOBAL new_.key_buffer_size=0; diff --git a/mysql-test/suite/storage_engine/cache_index.test b/mysql-test/suite/storage_engine/cache_index.test new file mode 100644 index 00000000000..42ba9615a40 --- /dev/null +++ b/mysql-test/suite/storage_engine/cache_index.test @@ -0,0 +1,142 @@ +# +# CACHE INDEX and LOAD INDEX INTO CACHE +# + +--source have_engine.inc +--source have_default_index.inc + + +# Due to ancient MySQL bug#16111 we need to generate a unique cache name +--let $cache_name = `SELECT CONNECTION_ID()` +--let $cache_name = my_cache_$cache_name + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +let $create_definition = + a $int_indexed_col, + b $char_col, + $default_index (a) +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Indexes on INT columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + let $create_definition = + a $int_col, + b $char_indexed_col, + $default_index (b) + ; + let $table_name = t2; + --source create_table.inc + if ($mysql_errname) + { + --let $functionality = Indexes on CHAR columns + --source unexpected_result.inc + } + if (!$mysql_errname) + { + --replace_result $cache_name + --let $error_codes = ER_UNKNOWN_KEY_CACHE + eval CACHE INDEX t1 INDEX (a), t2 IN $cache_name; + --source check_errors.inc + if ($mysql_errname != ER_UNKNOWN_KEY_CACHE) + { + --let $functionality = Key cache or indexes + --source unexpected_result.inc + } + + --replace_result $cache_name + eval SET GLOBAL $cache_name.key_buffer_size=128*1024; + --replace_result $cache_name + eval CACHE INDEX t1 INDEX (a), t2 IN $cache_name; + if ($mysql_errname) + { + --let $functionality = Indexes + --source unexpected_result.inc + } + + LOAD INDEX INTO CACHE t1, t2; + if ($mysql_errname) + { + --let $functionality = Indexes + --source unexpected_result.inc + } + + INSERT INTO t1 (a,b) VALUES (3,'c'),(4,'d'); + --replace_result $cache_name + eval SET GLOBAL $cache_name.key_buffer_size=8*1024; + LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES; + + --replace_result $cache_name + eval SET GLOBAL $cache_name.key_cache_age_threshold = 100, $cache_name.key_cache_block_size = 512, $cache_name.key_cache_division_limit = 1, $cache_name.key_cache_segments=2; + INSERT INTO t1 (a,b) VALUES (5,'e'),(6,'f'); + LOAD INDEX INTO CACHE t1; + + --replace_result $cache_name + eval SET GLOBAL new_$cache_name.key_buffer_size=128*1024; + --replace_result $cache_name + eval CACHE INDEX t1 IN new_$cache_name; + INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h'); + LOAD INDEX INTO CACHE t1 IGNORE LEAVES; + INSERT INTO t1 (a,b) VALUES (9,'i'); + DROP TABLE t2; + } + DROP TABLE t1; +} + +let $create_definition = + a $int_indexed_col, + b $char_indexed_col, + $default_index (a), + $default_index (b) +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Multiple keys or indexes on INT or CHAR columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_result $cache_name + eval CACHE INDEX t1 IN $cache_name; + INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); + LOAD INDEX INTO CACHE t1; + + DROP TABLE t1; + let $create_definition = + a $int_indexed_col, + b $char_indexed_col, + $default_index a_b (a,b) + ; + --source create_table.inc + if ($mysql_errname) + { + --let $functionality = Multi-part keys + --source unexpected_result.inc + } + + --replace_result $cache_name + eval CACHE INDEX t1 IN $cache_name; + INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); + LOAD INDEX INTO CACHE t1; + + DROP TABLE t1; +} + +# Cleanup + +--replace_result $cache_name +eval SET GLOBAL $cache_name.key_buffer_size=0; +--replace_result $cache_name +eval SET GLOBAL new_$cache_name.key_buffer_size=0; + + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/check_errors.inc b/mysql-test/suite/storage_engine/check_errors.inc new file mode 100644 index 00000000000..e38ff2962f1 --- /dev/null +++ b/mysql-test/suite/storage_engine/check_errors.inc @@ -0,0 +1,80 @@ +# +# Since we run tests in disable_abort_on_error mode, we cannot use --error command, +# and need to check the result manually. +# Usage in a test: +# --let $error_codes = # optional, default '' +# --let $mysql_errname = # optional, default current $mysql_errname (from the last SQL command) +# --let $mysql_errno = # optional, default current $mysql_errno (from the last SQL command) +# + +if ($error_codes == '0') +{ + --let $error_codes = +} +if ($error_codes == '') +{ + if ($mysql_errname) + { + --echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected to succeed) + } + + # If both error_codes and mysql_errname are false, all is good, no logic needed +} + +if ($error_codes != '') +{ + # If mysql_errname or mysql_errno is equal to $error_codes, it's good too, nothing to do + + if ($mysql_errname != $error_codes) + { + if ($mysql_errno != $error_codes) + { + --let $save_errno = $mysql_errno + --let $save_errname = $mysql_errname + + --let $codeline = `SELECT CONCAT('\'',REPLACE('$error_codes',',','\',\''),'\'')` + --let $result = `SELECT '$save_errname' IN($codeline) or '$save_errno' IN ($codeline)` + + --let $mysql_errno = $save_errno + --let $mysql_errname = $save_errname + + if (!$result) + { + if ($mysql_errname) + { + --echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected results: $error_codes) + } + if (!$mysql_errname) + { + --echo # ERROR: Statement succeeded (expected results: $error_codes) + } + } + # If a list contained more than one error, it could be on one of two reasons: + # first, we do not care which code it is, as long as it is one of the listed errors. + # In this case we will suggest to add an rdiff file if the message differs. + # Second, check_errors might be called from a generalized include file or test, + # which runs with different parameters and thus might produce different results for the same statement. + # Then, the message will be stricter, as the difference with the result file is actually a problem + # which needs to be checked at least. + if ($result) + { + if (!$strict_check) + { + --echo # Statement ended with one of expected results ($error_codes). + --echo # If you got a difference in error message, just add it to rdiff file + } + if ($strict_check) + { + --echo # WARNING: Statement ended with errno $mysql_errno, errname '$mysql_errname'. + --echo # If it differs from the result file, it might indicate a problem. + } + + } + } + } +} + +# Don't want the variables to be accidentally reused later +--let $error_codes = +--let $strict_check = + diff --git a/mysql-test/suite/storage_engine/check_table.inc b/mysql-test/suite/storage_engine/check_table.inc new file mode 100644 index 00000000000..54bdf511cb8 --- /dev/null +++ b/mysql-test/suite/storage_engine/check_table.inc @@ -0,0 +1,62 @@ +# +# CHECK TABLE statements +# +# Note: the output is likely to be different for the engine under test, +# in which case rdiff will be needed. Or, the output might say that +# the storage engine does not support CHECK. +# + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +--let $create_definition = a $int_col, b $char_col +--source create_table.inc +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); + +--let $table_name = t2 +--let $create_definition = a $int_col, b $char_col +--source create_table.inc + +CHECK TABLE t1; +INSERT INTO t1 (a,b) VALUES (3,'c'); +INSERT INTO t2 (a,b) VALUES (4,'d'); +CHECK TABLE t1, t2 FOR UPGRADE; +INSERT INTO t2 (a,b) VALUES (5,'e'); +CHECK TABLE t2 QUICK; +INSERT INTO t1 (a,b) VALUES (6,'f'); +CHECK TABLE t1 FAST; +INSERT INTO t1 (a,b) VALUES (7,'g'); +INSERT INTO t2 (a,b) VALUES (8,'h'); +CHECK TABLE t2, t1 MEDIUM; +INSERT INTO t1 (a,b) VALUES (9,'i'); +INSERT INTO t2 (a,b) VALUES (10,'j'); +CHECK TABLE t1, t2 EXTENDED; +INSERT INTO t1 (a,b) VALUES (11,'k'); +CHECK TABLE t1 CHANGED; + +DROP TABLE t1, t2; + +--let $continue = 1 +--source have_default_index.inc +if ($have_default_index) +{ + --let $create_definition = a $int_indexed_col, $default_index(a) + --source create_table.inc + INSERT INTO t1 (a) VALUES (1),(2),(5); + CHECK TABLE t1; + INSERT INTO t1 (a) VALUES (6),(8),(12); + CHECK TABLE t1 FOR UPGRADE; + INSERT INTO t1 (a) VALUES (13),(15),(16); + CHECK TABLE t1 QUICK; + INSERT INTO t1 (a) VALUES (17),(120),(132); + CHECK TABLE t1 FAST; + INSERT INTO t1 (a) VALUES (801),(900),(7714); + CHECK TABLE t1 MEDIUM; + INSERT INTO t1 (a) VALUES (8760),(10023),(12000); + CHECK TABLE t1 EXTENDED; + INSERT INTO t1 (a) VALUES (13345),(24456),(78302),(143028); + CHECK TABLE t1 CHANGED; + DROP TABLE t1; +} + diff --git a/mysql-test/suite/storage_engine/check_table.result b/mysql-test/suite/storage_engine/check_table.result new file mode 100644 index 00000000000..83c32778959 --- /dev/null +++ b/mysql-test/suite/storage_engine/check_table.result @@ -0,0 +1,68 @@ +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (a , b ) ENGINE= ; +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +CREATE TABLE t2 (a , b ) ENGINE= ; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a,b) VALUES (3,'c'); +INSERT INTO t2 (a,b) VALUES (4,'d'); +CHECK TABLE t1, t2 FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t2 check status OK +INSERT INTO t2 (a,b) VALUES (5,'e'); +CHECK TABLE t2 QUICK; +Table Op Msg_type Msg_text +test.t2 check status OK +INSERT INTO t1 (a,b) VALUES (6,'f'); +CHECK TABLE t1 FAST; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a,b) VALUES (7,'g'); +INSERT INTO t2 (a,b) VALUES (8,'h'); +CHECK TABLE t2, t1 MEDIUM; +Table Op Msg_type Msg_text +test.t2 check status OK +test.t1 check status OK +INSERT INTO t1 (a,b) VALUES (9,'i'); +INSERT INTO t2 (a,b) VALUES (10,'j'); +CHECK TABLE t1, t2 EXTENDED; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t2 check status OK +INSERT INTO t1 (a,b) VALUES (11,'k'); +CHECK TABLE t1 CHANGED; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1, t2; +CREATE TABLE t1 (a , (a)) ENGINE= ; +INSERT INTO t1 (a) VALUES (1),(2),(5); +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (6),(8),(12); +CHECK TABLE t1 FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (13),(15),(16); +CHECK TABLE t1 QUICK; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (17),(120),(132); +CHECK TABLE t1 FAST; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (801),(900),(7714); +CHECK TABLE t1 MEDIUM; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (8760),(10023),(12000); +CHECK TABLE t1 EXTENDED; +Table Op Msg_type Msg_text +test.t1 check status OK +INSERT INTO t1 (a) VALUES (13345),(24456),(78302),(143028); +CHECK TABLE t1 CHANGED; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/check_table.test b/mysql-test/suite/storage_engine/check_table.test new file mode 100644 index 00000000000..243c8e07161 --- /dev/null +++ b/mysql-test/suite/storage_engine/check_table.test @@ -0,0 +1,14 @@ +# +# CHECK TABLE statements +# +# Note: the output is likely to be different for the engine under test, +# in which case rdiff will be needed. Or, the output might say that +# the storage engine does not support CHECK. +# + +--source have_engine.inc + +--source check_table.inc + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/checksum_table.inc b/mysql-test/suite/storage_engine/checksum_table.inc new file mode 100644 index 00000000000..d4bacce93b7 --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table.inc @@ -0,0 +1,31 @@ +# +# CHECKSUM TABLE statements for standard CHECKSUM properties. +# Live checksums are covered in checksum_table_live.test +# + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +# For most engines CHECKSUM=0 option will be ignored, +# but we are setting it here for those which have it 1 by default +# (there will be another test for live checksum) + +--let $table_options = CHECKSUM=0 +--let $create_definition = a $int_col, b $char_col +--source create_table.inc +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); + +--let $table_name = t2 +--let $table_options = CHECKSUM=0 +--let $create_definition = a $int_col, b $char_col +--source create_table.inc + +CHECKSUM TABLE t1; +CHECKSUM TABLE t2, t1; +CHECKSUM TABLE t1, t2 QUICK; +CHECKSUM TABLE t1, t2 EXTENDED; + +DROP TABLE t1, t2; + + diff --git a/mysql-test/suite/storage_engine/checksum_table.result b/mysql-test/suite/storage_engine/checksum_table.result new file mode 100644 index 00000000000..02d70491fa9 --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table.result @@ -0,0 +1,20 @@ +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (a , b ) ENGINE= CHECKSUM=0; +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +CREATE TABLE t2 (a , b ) ENGINE= CHECKSUM=0; +CHECKSUM TABLE t1; +Table Checksum +test.t1 4272806499 +CHECKSUM TABLE t2, t1; +Table Checksum +test.t2 0 +test.t1 4272806499 +CHECKSUM TABLE t1, t2 QUICK; +Table Checksum +test.t1 NULL +test.t2 NULL +CHECKSUM TABLE t1, t2 EXTENDED; +Table Checksum +test.t1 4272806499 +test.t2 0 +DROP TABLE t1, t2; diff --git a/mysql-test/suite/storage_engine/checksum_table.test b/mysql-test/suite/storage_engine/checksum_table.test new file mode 100644 index 00000000000..5693e9a1ad3 --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table.test @@ -0,0 +1,11 @@ +# +# CHECKSUM TABLE statements for standard CHECKSUM properties. +# Live checksums are covered in checksum_table_live.test +# + +--source have_engine.inc + +--source checksum_table.inc + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/checksum_table_live.inc b/mysql-test/suite/storage_engine/checksum_table_live.inc new file mode 100644 index 00000000000..9614494e620 --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table_live.inc @@ -0,0 +1,30 @@ +# +# CHECKSUM TABLE statements for live CHECKSUM. +# +# Note: the feature is likely to be unsupported, in which case +# instead of numeric values some CHECKSUMs will produce NULL +# + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +# For most engines CHECKSUM=1 option will be ignored, +# and the results will be different + +--let $table_options = CHECKSUM=1 +--let $create_definition = a $int_col, b $char_col +--source create_table.inc +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +--let $table_name = t2 +--let $table_options = CHECKSUM=1 +--let $create_definition = a $int_col, b $char_col +--source create_table.inc + +CHECKSUM TABLE t1; +CHECKSUM TABLE t2, t1; +CHECKSUM TABLE t1, t2 QUICK; +CHECKSUM TABLE t1, t2 EXTENDED; + +DROP TABLE t1, t2; + diff --git a/mysql-test/suite/storage_engine/checksum_table_live.result b/mysql-test/suite/storage_engine/checksum_table_live.result new file mode 100644 index 00000000000..59ab8f1688a --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table_live.result @@ -0,0 +1,20 @@ +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (a , b ) ENGINE= CHECKSUM=1; +INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); +CREATE TABLE t2 (a , b ) ENGINE= CHECKSUM=1; +CHECKSUM TABLE t1; +Table Checksum +test.t1 4272806499 +CHECKSUM TABLE t2, t1; +Table Checksum +test.t2 0 +test.t1 4272806499 +CHECKSUM TABLE t1, t2 QUICK; +Table Checksum +test.t1 4272806499 +test.t2 0 +CHECKSUM TABLE t1, t2 EXTENDED; +Table Checksum +test.t1 4272806499 +test.t2 0 +DROP TABLE t1, t2; diff --git a/mysql-test/suite/storage_engine/checksum_table_live.test b/mysql-test/suite/storage_engine/checksum_table_live.test new file mode 100644 index 00000000000..347755f24df --- /dev/null +++ b/mysql-test/suite/storage_engine/checksum_table_live.test @@ -0,0 +1,13 @@ +# +# CHECKSUM TABLE statements for live CHECKSUM. +# +# Note: the feature is likely to be unsupported, in which case +# instead of numeric values some CHECKSUMs will produce NULL +# + +--source have_engine.inc + +--source checksum_table_live.inc + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/cleanup_engine.inc b/mysql-test/suite/storage_engine/cleanup_engine.inc new file mode 100644 index 00000000000..de3d57eeaeb --- /dev/null +++ b/mysql-test/suite/storage_engine/cleanup_engine.inc @@ -0,0 +1,11 @@ +########################################### +# +# This is a stub of the include file cleanup_engine.inc which +# should be placed in storage//mysql-test/storage_engine folder. +# +################################ +# +# Here you can add whatever is needed to cleanup +# in case your define_engine.inc created any artefacts, +# e.g. an additional schema and/or tables. + diff --git a/mysql-test/suite/storage_engine/col_not_null.inc b/mysql-test/suite/storage_engine/col_not_null.inc new file mode 100644 index 00000000000..5f980b0a915 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_not_null.inc @@ -0,0 +1,92 @@ +# +# NOT NULL attribute in columns +# +# Usage: +# let $col_definition = ; +# let $col_default = ; +# --source col_not_null.inc +# +# We will add NOT NULL at the end of $col; +# +# Also, if $col_default is defined, +# we will create a table with 2 columns +# (one with DEFAULT $col_default, and one without any default), +# and will also attempt to add a column with DEFAULT NULL. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--let $create_definition = c $col_definition NOT NULL +--source create_table.inc +if ($mysql_errname) +{ + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + SHOW COLUMNS IN t1; + + --let $error_codes = ER_BAD_NULL_ERROR + INSERT INTO t1 (c) VALUES (NULL); + --source check_errors.inc + + DROP TABLE t1; +} + +if ($col_default != '') +{ + let $create_definition = + c $col_definition NOT NULL, + c2 $col_definition NOT NULL DEFAULT $col_default + ; + --source create_table.inc + if ($mysql_errname) + { + --source unexpected_result.inc + } + if (!$mysql_errname) + { + SHOW COLUMNS IN t1; + + --let $error_codes = ER_INVALID_DEFAULT + --let $alter_definition = ADD COLUMN err $col_definition NOT NULL DEFAULT NULL + --source alter_table.inc + if ($mysql_errname != ER_INVALID_DEFAULT) + { + --let $functionality = ALTER or DEFAULT + --source unexpected_result.inc + } + + --let $error_codes = ER_BAD_NULL_ERROR + INSERT INTO t1 (c) VALUES (NULL); + --source check_errors.inc + if ($mysql_errname != ER_BAD_NULL_ERROR) + { + --let $functionality = NOT NULL columns + --source unexpected_result.inc + } + + # HEX should be universal for all column types + SELECT HEX(c), HEX(c2) FROM t1; + + --let $error_codes = ER_BAD_NULL_ERROR + INSERT INTO t1 (c2) VALUES (NULL); + --source check_errors.inc + + --eval INSERT INTO t1 (c) VALUES ($col_default) + if ($mysql_errname) + { + --let $functionality = DEFAULT + --source unexpected_result.inc + } + SELECT COUNT(c), COUNT(c2) FROM t1; + + DROP TABLE t1; + } +} + +# We don't want to preserve it +let $col_default = ; + diff --git a/mysql-test/suite/storage_engine/col_null.inc b/mysql-test/suite/storage_engine/col_null.inc new file mode 100644 index 00000000000..6f74609869f --- /dev/null +++ b/mysql-test/suite/storage_engine/col_null.inc @@ -0,0 +1,65 @@ +# +# NULL attribute and DEFAULT NULL in columns +# +# Usage: +# let $col_definition = ; +# let $col_default = ; +# --source col_null.inc +# +# We will add NULL at the end of $col; +# +# Also, if $col_default is defined, +# we will create a table with 3 columns (one with DEFAULT NULL, +# one with DEFAULT $col_default, and one without any default) +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--let $create_definition = c $col_definition NULL +--source create_table.inc +SHOW COLUMNS IN t1; +if ($mysql_errname) +{ + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + INSERT INTO t1 (c) VALUES (NULL); + if ($mysql_errname) + { + --let $functionality = NULLable columns + --source unexpected_result.inc + } + SELECT COUNT(c), COUNT(*) FROM t1; + + DROP TABLE t1; +} + +if ($col_default != '') +{ + let $create_definition = + c $col_definition NULL, + c1 $col_definition NULL DEFAULT NULL, + c2 $col_definition NULL DEFAULT $col_default + ; + --source create_table.inc + if ($mysql_errname) + { + --source unexpected_result.inc + } + if (!$mysql_errname) + { + SHOW COLUMNS IN t1; + + INSERT INTO t1 (c) VALUES (NULL); + SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; + + DROP TABLE t1; + } +} + +# We don't want to preserve it +let $col_default = ; + diff --git a/mysql-test/suite/storage_engine/col_opt_default.result b/mysql-test/suite/storage_engine/col_opt_default.result new file mode 100644 index 00000000000..2d0a8508b99 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_default.result @@ -0,0 +1,20 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a DEFAULT '0') ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a int(11) # 0 +INSERT INTO t1 (a) VALUES (1); +SELECT * FROM t1; +a +1 +ALTER TABLE t1 ADD COLUMN b DEFAULT ''; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a int(11) # 0 +b char(8) # +INSERT INTO t1 (b) VALUES ('a'); +SELECT * FROM t1; +a b +0 a +1 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/col_opt_default.test b/mysql-test/suite/storage_engine/col_opt_default.test new file mode 100644 index 00000000000..f59daef37fc --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_default.test @@ -0,0 +1,49 @@ +# +# Check whether DEFAULT column attribute +# is supported in CREATE and ALTER TABLE. +# If the attribute is supported at all, it will be covered +# in more details in col_option_null and col_option_not_null tests. +# + +--source have_engine.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--let $create_definition = a $int_col DEFAULT '0' +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = DEFAULT values + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (a) VALUES (1); + --sorted_result + SELECT * FROM t1; + + --let $alter_definition = ADD COLUMN b $char_col DEFAULT '' + --source alter_table.inc + if ($mysql_errname) + { + --let $functionality = ALTER or DEFAULT + --source unexpected_result.inc + } + if (!$mysql_errname) + { + --replace_column 3 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (b) VALUES ('a'); + --sorted_result + SELECT * FROM t1; + } + DROP TABLE t1; +} +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/col_opt_not_null.result b/mysql-test/suite/storage_engine/col_opt_not_null.result new file mode 100644 index 00000000000..00a863fccce --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_not_null.result @@ -0,0 +1,2062 @@ +# +# BINARY columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b BINARY NOT NULL, +b0 BINARY(0) NOT NULL, +b1 BINARY(1) NOT NULL, +b20 BINARY(20) NOT NULL, +b255 BINARY(255) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b binary(1) # # # # +b0 binary(0) # # # # +b1 binary(1) # # # # +b20 binary(20) # # # # +b255 binary(255) # # # # +INSERT INTO t1 VALUES ('','','','',''); +INSERT INTO t1 VALUES ('a','','b','abcdefghi klmnopqrst', 'Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn\'t already exist which would work.'); +SELECT HEX(b), HEX(b0), HEX(b1), HEX(b20), HEX(b255) FROM t1; +HEX(b) HEX(b0) HEX(b1) HEX(b20) HEX(b255) +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +61 62 616263646566676869206B6C6D6E6F7071727374 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +INSERT INTO t1 VALUES ('abc', 'a', 'abc', REPEAT('a',21), REPEAT('x',256)); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b20' at row 1 +Warning 1265 Data truncated for column 'b255' at row 1 +INSERT INTO t1 SELECT b255, b255, b255, b255, CONCAT(b255,b255) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b20' at row 1 +Warning 1265 Data truncated for column 'b255' at row 1 +Warning 1265 Data truncated for column 'b' at row 2 +Warning 1265 Data truncated for column 'b0' at row 2 +Warning 1265 Data truncated for column 'b1' at row 2 +Warning 1265 Data truncated for column 'b20' at row 2 +Warning 1265 Data truncated for column 'b255' at row 2 +Warning 1265 Data truncated for column 'b' at row 3 +Warning 1265 Data truncated for column 'b0' at row 3 +Warning 1265 Data truncated for column 'b1' at row 3 +Warning 1265 Data truncated for column 'b20' at row 3 +Warning 1265 Data truncated for column 'b255' at row 3 +SELECT HEX(b), HEX(b0), HEX(b1), HEX(b20), HEX(b255) FROM t1; +HEX(b) HEX(b0) HEX(b1) HEX(b20) HEX(b255) +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +43 43 4372656174696E6720616E2061727469636C6520 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +61 61 6161616161616161616161616161616161616161 787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 +61 62 616263646566676869206B6C6D6E6F7071727374 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +78 78 7878787878787878787878787878787878787878 787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 +ALTER TABLE t1 ADD COLUMN b257 BINARY(257) NOT NULL; +ERROR 42000: Column length too big for column 'b257' (max = 255); use BLOB or TEXT instead +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b binary(1) # # # # +b0 binary(0) # # # # +b1 binary(1) # # # # +b20 binary(20) # # # # +b255 binary(255) # # # # +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BINARY NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c binary(1) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c BINARY NOT NULL, +c2 BINARY NOT NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c binary(1) NO NULL +c2 binary(1) NO 0 +ALTER TABLE t1 ADD COLUMN err BINARY NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (0); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# VARBINARY columns +# +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (v0 VARBINARY(0) NOT NULL, +v1 VARBINARY(1) NOT NULL, +v64 VARBINARY(64) NOT NULL, +v65000 VARBINARY(65000) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varbinary(0) # # # +v1 varbinary(1) # # # +v64 varbinary(64) # # # +v65000 varbinary(65000) # # # +CREATE TABLE t2 (v VARBINARY(65532) NOT NULL) ENGINE= ; +SHOW COLUMNS IN t2; +Field Type Null Key Default Extra +v varbinary(65532) # # # +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','','',''); +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','y','Once there, double check that an article doesn\'t already exist','Here is a list of recommended books on MariaDB and MySQL. We\'ve provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. + For developers who want to code on MariaDB or MySQL + + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + + For MariaDB / MySQL end users + + * MariaDB Crash Course by Ben Forta + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o Free to read in the Knowledgebase! + + * MySQL (4th Edition) by Paul DuBois + o The \'default\' book to read if you wont to learn to use MySQL / MariaDB. + + * MySQL Cookbook by Paul DuBois + o A lot of examples of how to use MySQL. As with all of Paul\'s books, it\'s worth its weight in gold and even enjoyable reading for such a \'dry\' subject. + + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + o \"High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL\'s full power.\" (From the book description at O\'Reilly) + + * MySQL Admin Cookbook + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. '); +SELECT HEX(v0), HEX(v1), HEX(v64), HEX(v65000) FROM t1; +HEX(v0) HEX(v1) HEX(v64) HEX(v65000) + + 79 4F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C7265616479206578697374 486572652069732061206C697374206F66207265636F6D6D656E64656420626F6F6B73206F6E204D61726961444220616E64204D7953514C2E2057652776652070726F7669646564206C696E6B7320746F20416D617A6F6E2E636F6D206865726520666F7220636F6E76656E69656E63652C2062757420746865792063616E20626520666F756E64206174206D616E79206F7468657220626F6F6B73746F7265732C20626F7468206F6E6C696E6520616E64206F66662E0A0A2020496620796F752077616E7420746F206861766520796F7572206661766F72697465204D7953514C202F204D61726961444220626F6F6B206C697374656420686572652C20706C65617365206C65617665206120636F6D6D656E742E0A2020466F7220646576656C6F706572732077686F2077616E7420746F20636F6465206F6E204D617269614442206F72204D7953514C0A0A2020202020202A20556E6465727374616E64696E67204D7953514C20496E7465726E616C73206279205361736861205061636865762C20666F726D6572204D7953514C20646576656C6F706572206174204D7953514C2041422E0A2020202020202020202020206F205468697320697320746865206F6E6C7920626F6F6B207765206B6E6F772061626F75742074686174206465736372696265732074686520696E7465726E616C73206F66204D617269614442202F204D7953514C2E2041206D757374206861766520666F7220616E796F6E652077686F2077616E747320746F20756E6465727374616E6420616E6420646576656C6F70206F6E204D617269614442210A2020202020202020202020206F204E6F7420616C6C20746F706963732061726520636F766572656420616E6420736F6D652070617274732061726520736C696768746C79206F757464617465642C20627574207374696C6C20746865206265737420626F6F6B206F6E207468697320746F7069632E200A2020202020202A204D7953514C20352E3120506C7567696E20446576656C6F706D656E742062792053657267656920476F6C75626368696B20616E6420416E64726577204875746368696E67730A2020202020202020202020206F2041206D757374207265616420666F7220616E796F6E652077616E74696E6720746F207772697465206120706C7567696E20666F72204D6172696144422C207772697474656E20627920746865205365726765692077686F2064657369676E65642074686520706C7567696E20696E7465726661636520666F72204D7953514C20616E64204D61726961444221200A0A2020466F72204D617269614442202F204D7953514C20656E642075736572730A0A2020202020202A204D61726961444220437261736820436F757273652062792042656E20466F7274610A2020202020202020202020206F204669727374204D61726961444220626F6F6B210A2020202020202020202020206F20466F722070656F706C652077686F2077616E7420746F206C6561726E2053514C20616E642074686520626173696373206F66204D6172696144422E0A2020202020202020202020206F204E6F77207368697070696E672E20507572636861736520617420416D617A6F6E2E636F6D206F7220796F7572206661766F7269746520626F6F6B73656C6C65722E200A0A2020202020202A2053514C2D393920436F6D706C6574652C205265616C6C792062792050657465722047756C75747A616E20262054727564792050656C7A65722E0A2020202020202020202020206F2045766572797468696E6720796F752077616E74656420746F206B6E6F772061626F7574207468652053514C203939207374616E646172642E20457863656C6C656E74207265666572656E636520626F6F6B210A2020202020202020202020206F204672656520746F207265616420696E20746865204B6E6F776C656467656261736521200A0A2020202020202A204D7953514C20283474682045646974696F6E29206279205061756C204475426F69730A2020202020202020202020206F20546865202764656661756C742720626F6F6B20746F207265616420696620796F7520776F6E7420746F206C6561726E20746F20757365204D7953514C202F204D6172696144422E200A0A2020202020202A204D7953514C20436F6F6B626F6F6B206279205061756C204475426F69730A2020202020202020202020206F2041206C6F74206F66206578616D706C6573206F6620686F7720746F20757365204D7953514C2E204173207769746820616C6C206F66205061756C277320626F6F6B732C206974277320776F727468206974732077656967687420696E20676F6C6420616E64206576656E20656E6A6F7961626C652072656164696E6720666F7220737563682061202764727927207375626A6563742E200A0A2020202020202A204869676820506572666F726D616E6365204D7953514C2C205365636F6E642045646974696F6E2C204279204261726F6E20536368776172747A2C205065746572205A6169747365762C20566164696D20546B616368656E6B6F2C204A6572656D7920442E205A61776F646E792C2041726A656E204C656E747A2C20446572656B204A2E2042616C6C696E672C20657420616C2E0A2020202020202020202020206F20224869676820506572666F726D616E6365204D7953514C2069732074686520646566696E697469766520677569646520746F206275696C64696E6720666173742C2072656C6961626C652073797374656D732077697468204D7953514C2E205772697474656E206279206E6F74656420657870657274732077697468207965617273206F66207265616C2D776F726C6420657870657269656E6365206275696C64696E672076657279206C617267652073797374656D732C207468697320626F6F6B20636F7665727320657665727920617370656374206F66204D7953514C20706572666F726D616E636520696E2064657461696C2C20616E6420666F6375736573206F6E20726F627573746E6573732C2073656375726974792C20616E64206461746120696E746567726974792E204C6561726E20616476616E63656420746563686E697175657320696E20646570746820736F20796F752063616E206272696E67206F7574204D7953514C27732066756C6C20706F7765722E22202846726F6D2074686520626F6F6B206465736372697074696F6E206174204F275265696C6C7929200A0A2020202020202A204D7953514C2041646D696E20436F6F6B626F6F6B0A2020202020202020202020206F204120717569636B20737465702D62792D7374657020677569646520666F72204D7953514C20757365727320616E642064617461626173652061646D696E6973747261746F727320746F207461636B6C65207265616C2D776F726C64206368616C6C656E6765732077697468204D7953514C20636F6E66696775726174696F6E20616E642061646D696E697374726174696F6E200A0A2020202020202A204D7953514C20352E302043657274696669636174696F6E2053747564792047756964652C204279205061756C204475426F69732C2053746566616E2048696E7A2C204361727374656E20506564657273656E0A2020202020202020202020206F205468697320697320746865206F6666696369616C20677569646520746F20636F766572207468652070617373696E67206F66207468652074776F204D7953514C2043657274696669636174696F6E206578616D696E6174696F6E732E2049742069732076616C69642074696C6C2076657273696F6E20352E30206F6620746865207365727665722C20736F207768696C65206974206D697373657320616C6C2074686520666561747572657320617661696C61626C6520696E204D7953514C20352E3120616E6420677265617465722028696E636C7564696E67204D61726961444220352E3120616E642067726561746572292C2069742070726F7669646573206120676F6F6420626173696320756E6465727374616E64696E67206F66204D7953514C20666F722074686520656E642D757365722E20 +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('y', 'yy', REPEAT('c',65), REPEAT('abcdefghi ',6501)); +Warnings: +Warning 1265 Data truncated for column 'v0' at row 1 +Warning 1265 Data truncated for column 'v1' at row 1 +Warning 1265 Data truncated for column 'v64' at row 1 +Warning 1265 Data truncated for column 'v65000' at row 1 +INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, v65000, CONCAT(v65000,v1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'v0' at row 2 +Warning 1265 Data truncated for column 'v1' at row 2 +Warning 1265 Data truncated for column 'v64' at row 2 +Warning 1265 Data truncated for column 'v0' at row 3 +Warning 1265 Data truncated for column 'v1' at row 3 +Warning 1265 Data truncated for column 'v64' at row 3 +Warning 1265 Data truncated for column 'v65000' at row 3 +SELECT HEX(v0), HEX(v1), HEX(v64), LENGTH(HEX(v65000)) FROM t1; +HEX(v0) HEX(v1) HEX(v64) LENGTH(HEX(v65000)) + 0 + 0 + 48 486572652069732061206C697374206F66207265636F6D6D656E64656420626F6F6B73206F6E204D61726961444220616E64204D7953514C2E20576527766520 5932 + 61 61626364656667686920616263646566676869206162636465666768692061626364656667686920616263646566676869206162636465666768692061626364 130000 + 79 4F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C7265616479206578697374 5930 + 79 63636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363 130000 +ALTER TABLE t1 ADD COLUMN v65536 VARBINARY(65536) NOT NULL; +Warnings: +Note 1246 Converting column 'v65536' from VARBINARY to BLOB +Note 1246 Converting column 'v65536' from VARBINARY to BLOB +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varbinary(0) # # # +v1 varbinary(1) # # # +v64 varbinary(64) # # # +v65000 varbinary(65000) # # # +v65536 mediumblob # # # +DROP TABLE t1, t2; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c VARBINARY(64) NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varbinary(64) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c VARBINARY(64) NOT NULL, +c2 VARBINARY(64) NOT NULL DEFAULT 'test' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varbinary(64) NO NULL +c2 varbinary(64) NO test +ALTER TABLE t1 ADD COLUMN err VARBINARY(64) NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('test'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# BIT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a BIT NOT NULL, +b BIT(20) NOT NULL, +c BIT(64) NOT NULL, +d BIT(1) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a bit(1) # # # +b bit(20) # # # +c bit(64) # # # +d bit(1) # # # +ALTER TABLE t1 DROP COLUMN d; +ALTER TABLE t1 ADD COLUMN d BIT(0) NOT NULL; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a bit(1) # # # +b bit(20) # # # +c bit(64) # # # +d bit(1) # # # +INSERT INTO t1 VALUES (0,POW(2,20)-1,b'1111111111111111111111111111111111111111111111111111111111111111',1); +SELECT BIN(a), HEX(b), c+0 FROM t1 WHERE d>0; +BIN(a) HEX(b) c+0 +0 FFFFF 18446744073709551615 +INSERT INTO t1 VALUES (1,0,-1,0); +SELECT a+0, b+0, c+0 FROM t1 WHERE d<100; +a+0 b+0 c+0 +0 1048575 18446744073709551615 +1 0 18446744073709551615 +INSERT INTO t1 VALUES (b'1', 'f', 0xFF, 0x0); +SELECT a+0, b+0, c+0 FROM t1 WHERE d IN (0, 2); +a+0 b+0 c+0 +1 0 18446744073709551615 +1 102 255 +INSERT INTO t1 VALUES (0x10,0,0,1); +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT * FROM t1; +a b c d +INSERT INTO t1 VALUES (0x01,0,0x10000000000000000,0); +Warnings: +Warning 1264 Out of range value for column 'c' at row 1 +SELECT * FROM t1; +a b c d +DROP TABLE t1; +CREATE TABLE t1 (a BIT(65) NOT NULL) ENGINE= ; +ERROR 42000: Display width out of range for 'a' (max = 64) +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BIT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bit(1) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c BIT NOT NULL, +c2 BIT NOT NULL DEFAULT 1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bit(1) NO NULL +c2 bit(1) NO b'1' +ALTER TABLE t1 ADD COLUMN err BIT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (1); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# BLOB columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b BLOB NOT NULL, +b0 BLOB(0) NOT NULL, +b1 BLOB(1) NOT NULL, +b300 BLOB(300) NOT NULL, +bm BLOB(65535) NOT NULL, +b70k BLOB(70000) NOT NULL, +b17m BLOB(17000000) NOT NULL, +t TINYBLOB NOT NULL, +m MEDIUMBLOB NOT NULL, +l LONGBLOB NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b blob # # # +b0 blob # # # +b1 tinyblob # # # +b300 blob # # # +bm blob # # # +b70k mediumblob # # # +b17m longblob # # # +t tinyblob # # # +m mediumblob # # # +l longblob # # # +INSERT INTO t1 VALUES +('','','','','','','','','',''), +('a','b','c','d','e','f','g','h','i','j'), +('test1','test2','test3','test4','test5','test6','test7','test8','test9','test10'), +( REPEAT('a',65535), REPEAT('b',65535), REPEAT('c',255), REPEAT('d',65535), REPEAT('e',65535), REPEAT('f',1048576), HEX(REPEAT('g',1048576)), REPEAT('h',255), REPEAT('i',1048576), HEX(REPEAT('j',1048576)) ); +SELECT LENGTH(b), LENGTH(b0), LENGTH(b1), LENGTH(b300), LENGTH(bm), LENGTH(b70k), LENGTH(b17m), LENGTH(t), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(b) LENGTH(b0) LENGTH(b1) LENGTH(b300) LENGTH(bm) LENGTH(b70k) LENGTH(b17m) LENGTH(t) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 2097152 255 1048576 2097152 +INSERT INTO t1 VALUES +( REPEAT('a',65536), REPEAT('b',65536), REPEAT('c',256), REPEAT('d',65536), REPEAT('e',65536), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',256), REPEAT('i',1048576), REPEAT('j',1048576) ); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b300' at row 1 +Warning 1265 Data truncated for column 'bm' at row 1 +Warning 1265 Data truncated for column 't' at row 1 +SELECT LENGTH(b), LENGTH(b0), LENGTH(b1), LENGTH(b300), LENGTH(bm), LENGTH(b70k), LENGTH(b17m), LENGTH(t), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(b) LENGTH(b0) LENGTH(b1) LENGTH(b300) LENGTH(bm) LENGTH(b70k) LENGTH(b17m) LENGTH(t) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +65535 65535 255 65535 65535 1048576 2097152 255 1048576 2097152 +ALTER TABLE t1 ADD COLUMN bbb BLOB(4294967296); +ERROR 42000: Display width out of range for 'bbb' (max = 4294967295) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BLOB NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c blob NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYBLOB NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyblob NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMBLOB NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumblob NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c LONGBLOB NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c longblob NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +# +# BOOL columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b1 BOOL NOT NULL, +b2 BOOLEAN NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b1 tinyint(1) # # # +b2 tinyint(1) # # # +INSERT INTO t1 VALUES (1,TRUE); +SELECT * FROM t1; +b1 b2 +1 1 +INSERT INTO t1 VALUES (FALSE,0); +SELECT * FROM t1; +b1 b2 +0 0 +1 1 +INSERT INTO t1 VALUES (2,3); +SELECT * FROM t1; +b1 b2 +0 0 +1 1 +2 3 +INSERT INTO t1 VALUES (-1,-2); +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +1 1 +2 3 +SELECT IF(b1,'true','false') AS a, IF(b2,'true','false') AS b FROM t1; +a b +false false +true true +true true +true true +SELECT * FROM t1 WHERE b1 = TRUE; +b1 b2 +1 1 +SELECT * FROM t1 WHERE b2 = FALSE; +b1 b2 +0 0 +INSERT INTO t1 VALUES ('a','b'); +Warnings: +Warning 1366 Incorrect integer value: 'a' for column 'b1' at row 1 +Warning 1366 Incorrect integer value: 'b' for column 'b2' at row 1 +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +0 0 +1 1 +2 3 +INSERT INTO t1 VALUES (128,-129); +Warnings: +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b2' at row 1 +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +0 0 +1 1 +127 -128 +2 3 +ALTER TABLE t1 ADD COLUMN b3 BOOLEAN UNSIGNED; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNSIGNED' at line 1 +ALTER TABLE t1 ADD COLUMN b3 BOOL ZEROFILL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ZEROFILL' at line 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BOOL NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(1) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c BOOL NOT NULL, +c2 BOOL NOT NULL DEFAULT '0' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(1) NO NULL +c2 tinyint(1) NO 0 +ALTER TABLE t1 ADD COLUMN err BOOL NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('0'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# CHAR columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c CHAR NOT NULL, +c0 CHAR(0) NOT NULL, +c1 CHAR(1) NOT NULL, +c20 CHAR(20) NOT NULL, +c255 CHAR(255) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) # # # +c0 char(0) # # # +c1 char(1) # # # +c20 char(20) # # # +c255 char(255) # # # +INSERT INTO t1 VALUES ('','','','',''); +INSERT INTO t1 VALUES ('a','','b','abcdefghi klmnopqrst', 'Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn\'t already exist which would work.'); +SELECT * FROM t1; +c c0 c1 c20 c255 + +a b abcdefghi klmnopqrst Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work. +INSERT INTO t1 VALUES ('abc', 'a', 'abc', REPEAT('a',21), REPEAT('x',256)); +Warnings: +Warning 1265 Data truncated for column 'c' at row 1 +Warning 1265 Data truncated for column 'c0' at row 1 +Warning 1265 Data truncated for column 'c1' at row 1 +Warning 1265 Data truncated for column 'c20' at row 1 +Warning 1265 Data truncated for column 'c255' at row 1 +INSERT INTO t1 SELECT c255, c255, c255, c255, CONCAT(c255,c1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'c' at row 2 +Warning 1265 Data truncated for column 'c0' at row 2 +Warning 1265 Data truncated for column 'c1' at row 2 +Warning 1265 Data truncated for column 'c20' at row 2 +Warning 1265 Data truncated for column 'c' at row 3 +Warning 1265 Data truncated for column 'c0' at row 3 +Warning 1265 Data truncated for column 'c1' at row 3 +Warning 1265 Data truncated for column 'c20' at row 3 +Warning 1265 Data truncated for column 'c255' at row 3 +SELECT * FROM t1; +c c0 c1 c20 c255 + + +C C Creating an article Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work.b +a a aaaaaaaaaaaaaaaaaaaa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +a b abcdefghi klmnopqrst Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work. +x x xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +SELECT DISTINCT c20, REPEAT('a',LENGTH(c20)), COUNT(*) FROM t1 GROUP BY c1, c20; +c20 REPEAT('a',LENGTH(c20)) COUNT(*) + 2 +Creating an article aaaaaaaaaaaaaaaaaaa 1 +aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 1 +abcdefghi klmnopqrst aaaaaaaaaaaaaaaaaaaa 1 +xxxxxxxxxxxxxxxxxxxx aaaaaaaaaaaaaaaaaaaa 1 +ALTER TABLE t1 ADD COLUMN c257 CHAR(257) NOT NULL; +ERROR 42000: Column length too big for column 'c257' (max = 255); use BLOB or TEXT instead +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c CHAR NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c CHAR NOT NULL, +c2 CHAR NOT NULL DEFAULT '_' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) NO NULL +c2 char(1) NO _ +ALTER TABLE t1 ADD COLUMN err CHAR NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('_'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# VARCHAR columns +# +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (v0 VARCHAR(0) NOT NULL, +v1 VARCHAR(1) NOT NULL, +v64 VARCHAR(64) NOT NULL, +v65000 VARCHAR(65000) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varchar(0) # # # +v1 varchar(1) # # # +v64 varchar(64) # # # +v65000 varchar(65000) # # # +CREATE TABLE t2 (v VARCHAR(65532) NOT NULL) ENGINE= ; +SHOW COLUMNS IN t2; +Field Type Null Key Default Extra +v varchar(65532) # # # +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','','',''); +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','y','Once there, double check that an article doesn\'t already exist','Here is a list of recommended books on MariaDB and MySQL. We\'ve provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. + For developers who want to code on MariaDB or MySQL + + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + + For MariaDB / MySQL end users + + * MariaDB Crash Course by Ben Forta + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o Free to read in the Knowledgebase! + + * MySQL (4th Edition) by Paul DuBois + o The \'default\' book to read if you wont to learn to use MySQL / MariaDB. + + * MySQL Cookbook by Paul DuBois + o A lot of examples of how to use MySQL. As with all of Paul\'s books, it\'s worth its weight in gold and even enjoyable reading for such a \'dry\' subject. + + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + o \"High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL\'s full power.\" (From the book description at O\'Reilly) + + * MySQL Admin Cookbook + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. '); +SELECT * FROM t1; +v0 v1 v64 v65000 + + + + + + + + + + + + y Once there, double check that an article doesn't already exist Here is a list of recommended books on MariaDB and MySQL. We've provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + o "High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL's full power." (From the book description at O'Reilly) + o A lot of examples of how to use MySQL. As with all of Paul's books, it's worth its weight in gold and even enjoyable reading for such a 'dry' subject. + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Free to read in the Knowledgebase! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + o The 'default' book to read if you wont to learn to use MySQL / MariaDB. + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + * MariaDB Crash Course by Ben Forta + * MySQL (4th Edition) by Paul DuBois + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + * MySQL Admin Cookbook + * MySQL Cookbook by Paul DuBois + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + For MariaDB / MySQL end users + For developers who want to code on MariaDB or MySQL + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('y', 'yy', REPEAT('c',65), REPEAT('abcdefghi ',6501)); +Warnings: +Warning 1265 Data truncated for column 'v0' at row 1 +Warning 1265 Data truncated for column 'v1' at row 1 +Warning 1265 Data truncated for column 'v64' at row 1 +Warning 1265 Data truncated for column 'v65000' at row 1 +INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, v65000, CONCAT(v65000,v1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'v0' at row 2 +Warning 1265 Data truncated for column 'v1' at row 2 +Warning 1265 Data truncated for column 'v64' at row 2 +Warning 1265 Data truncated for column 'v0' at row 3 +Warning 1265 Data truncated for column 'v1' at row 3 +Warning 1265 Data truncated for column 'v64' at row 3 +Warning 1265 Data truncated for column 'v65000' at row 3 +SELECT v0, v1, v64, LENGTH(v65000) FROM t1; +v0 v1 v64 LENGTH(v65000) + 0 + 0 + H Here is a list of recommended books on MariaDB and MySQL. We've 2966 + a abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcd 65000 + y Once there, double check that an article doesn't already exist 2965 + y cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 65000 +ALTER TABLE t1 ADD COLUMN v65536 VARCHAR(65536) NOT NULL; +Warnings: +Note 1246 Converting column 'v65536' from VARCHAR to TEXT +Note 1246 Converting column 'v65536' from VARCHAR to TEXT +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varchar(0) # # # +v1 varchar(1) # # # +v64 varchar(64) # # # +v65000 varchar(65000) # # # +v65536 mediumtext # # # +DROP TABLE t1, t2; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c VARCHAR(64) NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varchar(64) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c VARCHAR(64) NOT NULL, +c2 VARCHAR(64) NOT NULL DEFAULT 'test default' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varchar(64) NO NULL +c2 varchar(64) NO test default +ALTER TABLE t1 ADD COLUMN err VARCHAR(64) NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('test default'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# date and time columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DATE NOT NULL, +dt DATETIME NOT NULL, +ts TIMESTAMP NOT NULL, +t TIME NOT NULL, +y YEAR NOT NULL, +y4 YEAR(4) NOT NULL, +y2 YEAR(2) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d date # # # +dt datetime # # # +ts timestamp # # # on update CURRENT_TIMESTAMP +t time # # # +y year(4) # # # +y4 year(4) # # # +y2 year(2) # # # +SET @tm = '2012-04-09 05:27:00'; +INSERT INTO t1 VALUES +('1000-01-01', '1000-01-01 00:00:00', FROM_UNIXTIME(1), '-838:59:59', '1901', '1901', '00'), +('9999-12-31', '9999-12-31 23:59:59', FROM_UNIXTIME(2147483647), '838:59:59', '2155', '2155', '99'), +('0000-00-00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '00:00:00', '0', '0', '0'), +(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm),YEAR(@tm),YEAR(@tm)); +SELECT * FROM t1; +d dt ts t y y4 y2 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 00:00:00 2000 2000 00 +1000-01-01 1000-01-01 00:00:00 1970-01-01 03:00:01 -838:59:59 1901 1901 00 +2012-04-09 2012-04-09 05:27:00 2012-04-09 05:27:00 05:27:00 2012 2012 12 +9999-12-31 9999-12-31 23:59:59 2038-01-19 07:14:07 838:59:59 2155 2155 99 +INSERT INTO t1 VALUES +('999-13-32', '999-11-31 00:00:00', '0', '-839:00:00', '1900', '1900', '-1' ); +Warnings: +Warning 1265 Data truncated for column 'd' at row 1 +Warning 1265 Data truncated for column 'dt' at row 1 +Warning 1265 Data truncated for column 'ts' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 'y' at row 1 +Warning 1264 Out of range value for column 'y4' at row 1 +Warning 1264 Out of range value for column 'y2' at row 1 +SELECT * FROM t1; +d dt ts t y y4 y2 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 -838:59:59 0000 0000 00 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 00:00:00 2000 2000 00 +1000-01-01 1000-01-01 00:00:00 1970-01-01 03:00:01 -838:59:59 1901 1901 00 +2012-04-09 2012-04-09 05:27:00 2012-04-09 05:27:00 05:27:00 2012 2012 12 +9999-12-31 9999-12-31 23:59:59 2038-01-19 07:14:07 838:59:59 2155 2155 99 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DATE NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c date NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c DATE NOT NULL, +c2 DATE NOT NULL DEFAULT '2012-12-21' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c date NO NULL +c2 date NO 2012-12-21 +ALTER TABLE t1 ADD COLUMN err DATE NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('2012-12-21'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DATETIME NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c datetime NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c DATETIME NOT NULL, +c2 DATETIME NOT NULL DEFAULT '2012-12-21 12:21:12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c datetime NO NULL +c2 datetime NO 2012-12-21 12:21:12 +ALTER TABLE t1 ADD COLUMN err DATETIME NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('2012-12-21 12:21:12'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +CREATE TABLE t1 (c TIMESTAMP NOT NULL, +c2 TIMESTAMP NOT NULL DEFAULT '2012-02-21 12:21:12' +) ENGINE= ; +ALTER TABLE t1 ADD COLUMN err TIMESTAMP NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +INSERT INTO t1 (c2) VALUES (NULL); +SELECT c, c2 FROM t1; +c c2 + + +DROP TABLE t1; +CREATE TABLE t1 (c TIMESTAMP NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP +INSERT INTO t1 (c) VALUES (NULL); +SELECT * FROM t1; +c + +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TIME NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c time NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c TIME NOT NULL, +c2 TIME NOT NULL DEFAULT '12:21:12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c time NO NULL +c2 time NO 12:21:12 +ALTER TABLE t1 ADD COLUMN err TIME NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('12:21:12'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c YEAR NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(4) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c YEAR NOT NULL, +c2 YEAR NOT NULL DEFAULT '2012' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(4) NO NULL +c2 year(4) NO 2012 +ALTER TABLE t1 ADD COLUMN err YEAR NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('2012'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c YEAR(2) NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(2) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c YEAR(2) NOT NULL, +c2 YEAR(2) NOT NULL DEFAULT '12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(2) NO NULL +c2 year(2) NO 12 +ALTER TABLE t1 ADD COLUMN err YEAR(2) NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('12'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# ENUM columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a ENUM('') NOT NULL, +b ENUM('test1','test2','test3','test4','test5') NOT NULL, +c ENUM('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a enum('') # # # +b enum('test1','test2','test3','test4','test5') # # # +c enum('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') # # # +INSERT INTO t1 VALUES ('','test2','4'),('',5,2); +SELECT * FROM t1; +a b c + test2 4 + test5 2 +INSERT INTO t1 VALUES (0,'test6',-1); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + + test2 4 + test5 2 +ALTER TABLE t1 ADD COLUMN e ENUM('a','A') NOT NULL; +Warnings: +Note 1291 Column 'e' has duplicated value 'a' in ENUM +Note 1291 Column 'e' has duplicated value 'a' in ENUM +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a enum('') # # # +b enum('test1','test2','test3','test4','test5') # # # +c enum('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') # # # +e enum('a','A') # # # +INSERT INTO t1 VALUES ('','test3','75','A'); +SELECT * FROM t1; +a b c e + a + test2 4 a + test3 75 a + test5 2 a +SELECT * FROM t1 WHERE b='test2' OR a != ''; +a b c e + test2 4 a +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c ENUM('test1','test2','test3') NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c enum('test1','test2','test3') NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c ENUM('test1','test2','test3') NOT NULL, +c2 ENUM('test1','test2','test3') NOT NULL DEFAULT 'test2' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c enum('test1','test2','test3') NO NULL +c2 enum('test1','test2','test3') NO test2 +ALTER TABLE t1 ADD COLUMN err ENUM('test1','test2','test3') NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('test2'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# Fixed point columns (NUMERIC, DECIMAL) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DECIMAL NOT NULL, +d0 DECIMAL(0) NOT NULL, +d1_1 DECIMAL(1,1) NOT NULL, +d10_2 DECIMAL(10,2) NOT NULL, +d60_10 DECIMAL(60,10) NOT NULL, +n NUMERIC NOT NULL, +n0_0 NUMERIC(0,0) NOT NULL, +n1 NUMERIC(1) NOT NULL, +n20_4 NUMERIC(20,4) NOT NULL, +n65_4 NUMERIC(65,4) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d decimal(10,0) # # # +d0 decimal(10,0) # # # +d1_1 decimal(1,1) # # # +d10_2 decimal(10,2) # # # +d60_10 decimal(60,10) # # # +n decimal(10,0) # # # +n0_0 decimal(10,0) # # # +n1 decimal(1,0) # # # +n20_4 decimal(20,4) # # # +n65_4 decimal(65,4) # # # +INSERT INTO t1 VALUES (100,123456,0.3,40000.25,123456789123456789.10001,1024,7000.0,8.0,999999.9,9223372036854775807); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (9999999999.0,9999999999.0,0.9,99999999.99,99999999999999999999999999999999999999999999999999.9999999999,9999999999.0,9999999999.0,9.0,9999999999999999.9999,9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (-100,-123456,-0.3,-40000.25,-123456789123456789.10001,-1024,-7000.0,-8.0,-999999.9,-9223372036854775807); +INSERT INTO t1 VALUES (-9999999999.0,-9999999999.0,-0.9,-99999999.99,-99999999999999999999999999999999999999999999999999.9999999999,-9999999999.0,-9999999999.0,-9.0,-9999999999999999.9999,-9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +SELECT * FROM t1 WHERE n20_4 = 9999999999999999.9999 OR d < 100; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 SELECT n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4 FROM t1 WHERE n65_4 = ( SELECT MAX(n65_4) FROM t1 ); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (10000000000.0,10000000000.0,1.1,100000000.99,100000000000000000000000000000000000000000000000000.0,10000000000.0,10000000000.0,10.0,10000000000000000.9999,10000000000000000000000000000000000000000000000000000000000000.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (9999999999.1,9999999999.1,1.9,99999999.001,99999999999999999999999999999999999999999999999999.99999999991,9999999999.1,9999999999.1,9.1,9999999999999999.00001,9999999999999999999999999999999999999999999999999999999999999.11111); +Warnings: +Note 1265 Data truncated for column 'd' at row 1 +Note 1265 Data truncated for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Note 1265 Data truncated for column 'd10_2' at row 1 +Note 1265 Data truncated for column 'd60_10' at row 1 +Note 1265 Data truncated for column 'n' at row 1 +Note 1265 Data truncated for column 'n0_0' at row 1 +Note 1265 Data truncated for column 'n1' at row 1 +Note 1265 Data truncated for column 'n20_4' at row 1 +Note 1265 Data truncated for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.00 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.0000 9999999999999999999999999999999999999999999999999999999999999.1111 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +ALTER TABLE t1 ADD COLUMN n66 NUMERIC(66); +ERROR 42000: Too big precision 66 specified for 'n66'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(66,6); +ERROR 42000: Too big precision 66 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(66,66); +ERROR 42000: Too big scale 66 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DECIMAL NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c DECIMAL NOT NULL, +c2 DECIMAL NOT NULL DEFAULT 1.1 +) ENGINE= ; +Warnings: +Note 1265 Data truncated for column 'c2' at row 1 +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) NO NULL +c2 decimal(10,0) NO 1 +ALTER TABLE t1 ADD COLUMN err DECIMAL NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (1.1); +Warnings: +Note 1265 Data truncated for column 'c' at row 1 +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c NUMERIC NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c NUMERIC NOT NULL, +c2 NUMERIC NOT NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) NO NULL +c2 decimal(10,0) NO 0 +ALTER TABLE t1 ADD COLUMN err NUMERIC NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (0); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# Floating point columns (FLOAT, DOUBLE) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f FLOAT NOT NULL, +f0 FLOAT(0) NOT NULL, +r1_1 REAL(1,1) NOT NULL, +f23_0 FLOAT(23) NOT NULL, +f20_3 FLOAT(20,3) NOT NULL, +d DOUBLE NOT NULL, +d1_0 DOUBLE(1,0) NOT NULL, +d10_10 DOUBLE PRECISION (10,10) NOT NULL, +d53 DOUBLE(53,0) NOT NULL, +d53_10 DOUBLE(53,10) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +f float # # # +f0 float # # # +r1_1 double(1,1) # # # +f23_0 float # # # +f20_3 float(20,3) # # # +d double # # # +d1_0 double(1,0) # # # +d10_10 double(10,10) # # # +d53 double(53,0) # # # +d53_10 double(53,10) # # # +INSERT INTO t1 VALUES (12345.12345,12345.12345,0.9,123456789.123,56789.987,11111111.111,8.0,0.0123456789,1234566789123456789,99999999999999999.99999999); +SELECT * FROM t1; +f 12345.1 +d 11111111.111 +d10_10 0.0123456789 +d1_0 8 +d53 1234566789123456800 +d53_10 100000000000000000.0000000000 +f0 12345.1 +f20_3 56789.988 +f23_0 123457000 +r1_1 0.9 +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES ( +99999999999999999999999999999999999999, +99999999999999999999999999999999999999.9999999999999999, +0.9, +99999999999999999999999999999999999999.9, +99999999999999999.999, +999999999999999999999999999999999999999999999999999999999999999999999999999999999, +9, +0.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 11111111.111 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 8 +d1_0 9 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 1e38 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES (-999999999999999999999999,-99999999999.999999999999,-0.9,-999.99999999999999999999,-99999999999999999.999,-999999999999999999999999999999999999999999999999999999999999-0.999,-9,-.9999999999,-999999999999999999999999999999.99999999999999999999999,-9999999999999999999999999999999999999999999.9999999999); +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +SELECT MAX(f), MAX(f0), MAX(r1_1), MAX(f23_0), MAX(f20_3), MAX(d), MAX(d1_0), MAX(d10_10), MAX(d53), MAX(d53_10) FROM t1; +MAX(f) 9.999999680285692e37 +MAX(d) 1e81 +MAX(d10_10) 0.9999999999 +MAX(d1_0) 9 +MAX(d53) 100000000000000000000000000000000000000000000000000000 +MAX(d53_10) 10000000000000000000000000000000000000000000.0000000000 +MAX(f0) 9.999999680285692e37 +MAX(f20_3) 99999998430674940.000 +MAX(f23_0) 9.999999680285692e37 +MAX(r1_1) 0.9 +INSERT INTO t1 SELECT d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10 FROM t1 ORDER BY d53_10 DESC LIMIT 1; +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e43 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f 3.40282e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES ( +999999999999999999999999999999999999999, +999999999999999999999999999999999999999.9999999999999999, +1.9, +999999999999999999999999999999999999999.9, +999999999999999999.999, +9999999999999999999999999999999999999999999999999999999999999999999999999999999999, +99, +1.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated. +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e43 +d 1e65 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f 3.40282e38 +f 3.40282e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f0 3.40282e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +f23_0 3.40282e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +ALTER TABLE t1 ADD COLUMN d0_0 DOUBLE(0,0); +ERROR 42000: Display width out of range for 'd0_0' (max = 255) +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(256,1); +ERROR 42000: Too big precision 256 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(40,35); +ERROR 42000: Too big scale 35 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c FLOAT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c float NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c FLOAT NOT NULL, +c2 FLOAT NOT NULL DEFAULT 1.1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c float NO NULL +c2 float NO 1.1 +ALTER TABLE t1 ADD COLUMN err FLOAT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (1.1 ); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DOUBLE NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c double NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c DOUBLE NOT NULL, +c2 DOUBLE NOT NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c double NO NULL +c2 double NO 0 +ALTER TABLE t1 ADD COLUMN err DOUBLE NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (0); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# INT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT NOT NULL, +i0 INT(0) NOT NULL, +i1 INT(1) NOT NULL, +i20 INT(20) NOT NULL, +t TINYINT NOT NULL, +t0 TINYINT(0) NOT NULL, +t1 TINYINT(1) NOT NULL, +t20 TINYINT(20) NOT NULL, +s SMALLINT NOT NULL, +s0 SMALLINT(0) NOT NULL, +s1 SMALLINT(1) NOT NULL, +s20 SMALLINT(20) NOT NULL, +m MEDIUMINT NOT NULL, +m0 MEDIUMINT(0) NOT NULL, +m1 MEDIUMINT(1) NOT NULL, +m20 MEDIUMINT(20) NOT NULL, +b BIGINT NOT NULL, +b0 BIGINT(0) NOT NULL, +b1 BIGINT(1) NOT NULL, +b20 BIGINT(20) NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +i int(11) # # # +i0 int(11) # # # +i1 int(1) # # # +i20 int(20) # # # +t tinyint(4) # # # +t0 tinyint(4) # # # +t1 tinyint(1) # # # +t20 tinyint(20) # # # +s smallint(6) # # # +s0 smallint(6) # # # +s1 smallint(1) # # # +s20 smallint(20) # # # +m mediumint(9) # # # +m0 mediumint(9) # # # +m1 mediumint(1) # # # +m20 mediumint(20) # # # +b bigint(20) # # # +b0 bigint(20) # # # +b1 bigint(1) # # # +b20 bigint(20) # # # +INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (2147483647,2147483647,2147483647,2147483647,127,127,127,127,32767,32767,32767,32767,8388607,8388607,8388607,8388607,9223372036854775807,9223372036854775807,9223372036854775807,9223372036854775807); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +INSERT INTO t1 VALUES (-2147483648,-2147483648,-2147483648,-2147483648,-128,-128,-128,-128,-32768,-32768,-32768,-32768,-8388608,-8388608,-8388608,-8388608,-9223372036854775808,-9223372036854775808,-9223372036854775808,-9223372036854775808); +INSERT INTO t1 VALUES (4294967295,4294967295,4294967295,4294967295,255,255,255,255,65535,65535,65535,65535,16777215,16777215,16777215,16777215,18446744073709551615,18446744073709551615,18446744073709551615,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +INSERT INTO t1 VALUES (-2147483649,-2147483649,-2147483649,-2147483649,-129,-129,-129,-129,-32769,-32769,-32769,-32769,-8388609,-8388609,-8388609,-8388609,-9223372036854775809,-9223372036854775809,-9223372036854775809,-9223372036854775809); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967296,4294967296,4294967296,4294967296,256,256,256,256,65536,65536,65536,65536,16777216,16777216,16777216,16777216,18446744073709551616,18446744073709551616,18446744073709551616,18446744073709551616); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'i' at row 2 +Warning 1264 Out of range value for column 'i0' at row 2 +Warning 1264 Out of range value for column 'i1' at row 2 +Warning 1264 Out of range value for column 'i20' at row 2 +Warning 1264 Out of range value for column 't' at row 2 +Warning 1264 Out of range value for column 't0' at row 2 +Warning 1264 Out of range value for column 't1' at row 2 +Warning 1264 Out of range value for column 't20' at row 2 +Warning 1264 Out of range value for column 's' at row 2 +Warning 1264 Out of range value for column 's0' at row 2 +Warning 1264 Out of range value for column 's1' at row 2 +Warning 1264 Out of range value for column 's20' at row 2 +Warning 1264 Out of range value for column 'm' at row 2 +Warning 1264 Out of range value for column 'm0' at row 2 +Warning 1264 Out of range value for column 'm1' at row 2 +Warning 1264 Out of range value for column 'm20' at row 2 +Warning 1264 Out of range value for column 'i' at row 3 +Warning 1264 Out of range value for column 'i0' at row 3 +Warning 1264 Out of range value for column 'i1' at row 3 +Warning 1264 Out of range value for column 'i20' at row 3 +Warning 1264 Out of range value for column 't' at row 3 +Warning 1264 Out of range value for column 't0' at row 3 +Warning 1264 Out of range value for column 't1' at row 3 +Warning 1264 Out of range value for column 't20' at row 3 +Warning 1264 Out of range value for column 's' at row 3 +Warning 1264 Out of range value for column 's0' at row 3 +Warning 1264 Out of range value for column 's1' at row 3 +Warning 1264 Out of range value for column 's20' at row 3 +Warning 1264 Out of range value for column 'm' at row 3 +Warning 1264 Out of range value for column 'm0' at row 3 +Warning 1264 Out of range value for column 'm1' at row 3 +Warning 1264 Out of range value for column 'm20' at row 3 +Warning 1264 Out of range value for column 'i' at row 4 +Warning 1264 Out of range value for column 'i0' at row 4 +Warning 1264 Out of range value for column 'i1' at row 4 +Warning 1264 Out of range value for column 'i20' at row 4 +Warning 1264 Out of range value for column 't' at row 4 +Warning 1264 Out of range value for column 't0' at row 4 +Warning 1264 Out of range value for column 't1' at row 4 +Warning 1264 Out of range value for column 't20' at row 4 +Warning 1264 Out of range value for column 's' at row 4 +Warning 1264 Out of range value for column 's0' at row 4 +Warning 1264 Out of range value for column 's1' at row 4 +Warning 1264 Out of range value for column 's20' at row 4 +Warning 1264 Out of range value for column 'm' at row 4 +Warning 1264 Out of range value for column 'm0' at row 4 +Warning 1264 Out of range value for column 'm1' at row 4 +Warning 1264 Out of range value for column 'm20' at row 4 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +ALTER TABLE t1 ADD COLUMN i257 INT(257); +ERROR 42000: Display width out of range for 'i257' (max = 255) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c INT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c int(11) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c INT NOT NULL, +c2 INT NOT NULL DEFAULT 2147483647 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c int(11) NO NULL +c2 int(11) NO 2147483647 +ALTER TABLE t1 ADD COLUMN err INT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (2147483647); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYINT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(4) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c TINYINT NOT NULL, +c2 TINYINT NOT NULL DEFAULT 127 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(4) NO NULL +c2 tinyint(4) NO 127 +ALTER TABLE t1 ADD COLUMN err TINYINT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (127 ); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c SMALLINT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c smallint(6) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c SMALLINT NOT NULL, +c2 SMALLINT NOT NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c smallint(6) NO NULL +c2 smallint(6) NO 0 +ALTER TABLE t1 ADD COLUMN err SMALLINT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (0); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMINT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumint(9) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c MEDIUMINT NOT NULL, +c2 MEDIUMINT NOT NULL DEFAULT 1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumint(9) NO NULL +c2 mediumint(9) NO 1 +ALTER TABLE t1 ADD COLUMN err MEDIUMINT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (1); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BIGINT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bigint(20) NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c BIGINT NOT NULL, +c2 BIGINT NOT NULL DEFAULT 9223372036854775807 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bigint(20) NO NULL +c2 bigint(20) NO 9223372036854775807 +ALTER TABLE t1 ADD COLUMN err BIGINT NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES (9223372036854775807); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# SET columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a SET('') NOT NULL, +b SET('test1','test2','test3','test4','test5') NOT NULL, +c SET('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a set('') # # # +b set('test1','test2','test3','test4','test5') # # # +c set('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') # # # +INSERT INTO t1 VALUES +('','test2,test3','01,34,44,,23'), +('',5,2), +(',','test4,test2',''); +Warnings: +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + test1,test3 02 + test2,test3 01,23,34,44 + test2,test4 +INSERT INTO t1 VALUES (0,'test6',-1); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50'51,52,53,54,55,56,57,58,59,60,61,62,63,64 + test1,test3 02 + test2,test3 01,23,34,44 + test2,test4 +ALTER TABLE t1 ADD COLUMN e SET('a','A') NOT NULL; +Warnings: +Note 1291 Column 'e' has duplicated value 'a' in SET +Note 1291 Column 'e' has duplicated value 'a' in SET +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a set('') # # # +b set('test1','test2','test3','test4','test5') # # # +c set('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') # # # +e set('a','A') # # # +ALTER TABLE t1 ADD COLUMN f SET('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i') NOT NULL; +ERROR HY000: Too many strings for column f and SET +SELECT * FROM t1 WHERE FIND_IN_SET('test2',b)>0 OR a != ''; +a b c e + test2,test3 01,23,34,44 + test2,test4 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c SET('test1','test2','test3') NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c set('test1','test2','test3') NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +CREATE TABLE t1 (c SET('test1','test2','test3') NOT NULL, +c2 SET('test1','test2','test3') NOT NULL DEFAULT 'test2,test3' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c set('test1','test2','test3') NO NULL +c2 set('test1','test2','test3') NO test2,test3 +ALTER TABLE t1 ADD COLUMN err SET('test1','test2','test3') NOT NULL DEFAULT NULL; +ERROR 42000: Invalid default value for 'err' +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +SELECT HEX(c), HEX(c2) FROM t1; +HEX(c) HEX(c2) +INSERT INTO t1 (c2) VALUES (NULL); +ERROR 23000: Column 'c2' cannot be null +INSERT INTO t1 (c) VALUES ('test2,test3'); +SELECT COUNT(c), COUNT(c2) FROM t1; +COUNT(c) COUNT(c2) +1 1 +DROP TABLE t1; +# +# TEXT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (t TEXT NOT NULL, +t0 TEXT(0) NOT NULL, +t1 TEXT(1) NOT NULL, +t300 TEXT(300) NOT NULL, +tm TEXT(65535) NOT NULL, +t70k TEXT(70000) NOT NULL, +t17m TEXT(17000000) NOT NULL, +tt TINYTEXT NOT NULL, +m MEDIUMTEXT NOT NULL, +l LONGTEXT NOT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +t text # # # +t0 text # # # +t1 tinytext # # # +t300 text # # # +tm text # # # +t70k mediumtext # # # +t17m longtext # # # +tt tinytext # # # +m mediumtext # # # +l longtext # # # +INSERT INTO t1 VALUES +('','','','','','','','','',''), +('a','b','c','d','e','f','g','h','i','j'), +('test1','test2','test3','test4','test5','test6','test7','test8','test9','test10'), +( REPEAT('a',65535), REPEAT('b',65535), REPEAT('c',255), REPEAT('d',65535), REPEAT('e',65535), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',255), REPEAT('i',1048576), REPEAT('j',1048576) ); +SELECT LENGTH(t), LENGTH(t0), LENGTH(t1), LENGTH(t300), LENGTH(tm), LENGTH(t70k), LENGTH(t17m), LENGTH(tt), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(t) LENGTH(t0) LENGTH(t1) LENGTH(t300) LENGTH(tm) LENGTH(t70k) LENGTH(t17m) LENGTH(tt) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +INSERT INTO t1 VALUES +( REPEAT('a',65536), REPEAT('b',65536), REPEAT('c',256), REPEAT('d',65536), REPEAT('e',65536), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',256), REPEAT('i',1048576), REPEAT('j',1048576) ); +Warnings: +Warning 1265 Data truncated for column 't' at row 1 +Warning 1265 Data truncated for column 't0' at row 1 +Warning 1265 Data truncated for column 't1' at row 1 +Warning 1265 Data truncated for column 't300' at row 1 +Warning 1265 Data truncated for column 'tm' at row 1 +Warning 1265 Data truncated for column 'tt' at row 1 +SELECT LENGTH(t), LENGTH(t0), LENGTH(t1), LENGTH(t300), LENGTH(tm), LENGTH(t70k), LENGTH(t17m), LENGTH(tt), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(t) LENGTH(t0) LENGTH(t1) LENGTH(t300) LENGTH(tm) LENGTH(t70k) LENGTH(t17m) LENGTH(tt) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +ALTER TABLE t1 ADD COLUMN ttt TEXT(4294967296); +ERROR 42000: Display width out of range for 'ttt' (max = 4294967295) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TEXT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c text NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYTEXT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinytext NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMTEXT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumtext NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c LONGTEXT NOT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c longtext NO NULL +INSERT INTO t1 (c) VALUES (NULL); +ERROR 23000: Column 'c' cannot be null +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/col_opt_not_null.test b/mysql-test/suite/storage_engine/col_opt_not_null.test new file mode 100644 index 00000000000..2cd0e909536 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_not_null.test @@ -0,0 +1,260 @@ +# +# NOT NULL column attribute +# + +let $extra_col_opts = NOT NULL; + +--source have_engine.inc + +--echo # +--echo # BINARY columns +--echo # + +--source type_binary.inc +--let $col_definition = BINARY $default_col_opts +--let $col_default = 0 +--source col_not_null.inc + +--echo # +--echo # VARBINARY columns +--echo # + +--source type_varbinary.inc +--let $col_definition = VARBINARY(64) $default_col_opts +--let $col_default = 'test' +--source col_not_null.inc + +--echo # +--echo # BIT columns +--echo # + +--source type_bit.inc +--let $col_definition = BIT $default_col_opts +--let $col_default = 1 +--source col_not_null.inc + +--echo # +--echo # BLOB columns +--echo # + +--source type_blob.inc + +--let $col_definition = BLOB $default_col_opts +--source col_not_null.inc + +--let $col_definition = TINYBLOB $default_col_opts +--source col_not_null.inc + +--let $col_definition = MEDIUMBLOB $default_col_opts +--source col_not_null.inc + +--let $col_definition = LONGBLOB $default_col_opts +--source col_not_null.inc + +--echo # +--echo # BOOL columns +--echo # + +--source type_bool.inc +--let $col_definition = BOOL $default_col_opts +--let $col_default = '0' +--source col_not_null.inc + +--echo # +--echo # CHAR columns +--echo # + +--source type_char.inc +--let $col_definition = CHAR $default_col_opts +--let $col_default = '_' +--source col_not_null.inc + +--echo # +--echo # VARCHAR columns +--echo # + +--source type_varchar.inc +--let $col_definition = VARCHAR(64) $default_col_opts +--let $col_default = 'test default' +--source col_not_null.inc + +--echo # +--echo # date and time columns +--echo # + +--source type_date_time.inc + +--let $col_definition = DATE $default_col_opts +--let $col_default = '2012-12-21' +--source col_not_null.inc + +--let $col_definition = DATETIME $default_col_opts +--let $col_default = '2012-12-21 12:21:12' +--source col_not_null.inc + +# For TIMESTAMP the behavior is non-standard + +# $col_opts already contains NOT NULL part (it's set in have_engine.inc) + +let $create_definition = + c TIMESTAMP $col_opts, + c2 TIMESTAMP $col_opts DEFAULT '2012-02-21 12:21:12' +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = TIMESTAMP type or NOT NULL columns or DEFAULT + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --let $error_codes = ER_INVALID_DEFAULT + --let $alter_definition = ADD COLUMN err TIMESTAMP $col_opts DEFAULT NULL + --source alter_table.inc + if ($mysql_errname!=ER_INVALID_DEFAULT) + { + --let $functionality = ALTER or DEFAULT + --source unexpected_result.inc + } + + INSERT INTO t1 (c) VALUES (NULL); + INSERT INTO t1 (c2) VALUES (NULL); + --replace_regex /2012-02-21 12:21:12// /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}// + SELECT c, c2 FROM t1; + + DROP TABLE t1; +} + +--let $create_definition = c TIMESTAMP $col_opts +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = TIMESTAMP type + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + SHOW COLUMNS IN t1; + + INSERT INTO t1 (c) VALUES (NULL); + if ($mysql_errname) + { + --let $functionality = TIMESTAMP + --source unexpected_result.inc + } + + --replace_regex /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}// + SELECT * FROM t1; + DROP TABLE t1; +} + +# End of TIMESTAMP exception + + +--let $col_definition = TIME $default_col_opts +--let $col_default = '12:21:12' +--source col_not_null.inc + +--let $col_definition = YEAR $default_col_opts +--let $col_default = '2012' +--source col_not_null.inc + +--let $col_definition = YEAR(2) $default_col_opts +--let $col_default = '12' +--source col_not_null.inc + + +--echo # +--echo # ENUM columns +--echo # + +--source type_enum.inc + +--let $col_definition = ENUM('test1','test2','test3') $default_col_opts +--let $col_default = 'test2' +--source col_not_null.inc + + +--echo # +--echo # Fixed point columns (NUMERIC, DECIMAL) +--echo # + +--source type_fixed.inc + +--let $col_definition = DECIMAL $default_col_opts +--let $col_default = 1.1 +--source col_not_null.inc + +--let $col_definition = NUMERIC $default_col_opts +--let $col_default = 0 +--source col_not_null.inc + +--echo # +--echo # Floating point columns (FLOAT, DOUBLE) +--echo # + +--source type_float.inc + +--let $col_definition = FLOAT $default_col_opts +--let $col_default = 1.1 +--source col_not_null.inc + +--let $col_definition = DOUBLE $default_col_opts +--let $col_default = 0 +--source col_not_null.inc + +--echo # +--echo # INT columns +--echo # + +--source type_int.inc + +--let $col_definition = INT $default_col_opts +--let $col_default = 2147483647 +--source col_not_null.inc + +--let $col_definition = TINYINT $default_col_opts +--let $col_default = 127 +--source col_not_null.inc + +--let $col_definition = SMALLINT $default_col_opts +--let $col_default = 0 +--source col_not_null.inc + +--let $col_definition = MEDIUMINT $default_col_opts +--let $col_default = 1 +--source col_not_null.inc + +--let $col_definition = BIGINT $default_col_opts +--let $col_default = 9223372036854775807 +--source col_not_null.inc + +--echo # +--echo # SET columns +--echo # + +--source type_set.inc +--let $col_definition = SET('test1','test2','test3') $default_col_opts +--let $col_default = 'test2,test3' +--source col_not_null.inc + +--echo # +--echo # TEXT columns +--echo # + +--source type_text.inc + +--let $col_definition = TEXT $default_col_opts +--source col_not_null.inc + +--let $col_definition = TINYTEXT $default_col_opts +--source col_not_null.inc + +--let $col_definition = MEDIUMTEXT $default_col_opts +--source col_not_null.inc + +--let $col_definition = LONGTEXT $default_col_opts +--source col_not_null.inc + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/col_opt_null.result b/mysql-test/suite/storage_engine/col_opt_null.result new file mode 100644 index 00000000000..c6a46f8c18f --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_null.result @@ -0,0 +1,1991 @@ +# +# BINARY columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b BINARY NULL, +b0 BINARY(0) NULL, +b1 BINARY(1) NULL, +b20 BINARY(20) NULL, +b255 BINARY(255) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b binary(1) # # # # +b0 binary(0) # # # # +b1 binary(1) # # # # +b20 binary(20) # # # # +b255 binary(255) # # # # +INSERT INTO t1 VALUES ('','','','',''); +INSERT INTO t1 VALUES ('a','','b','abcdefghi klmnopqrst', 'Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn\'t already exist which would work.'); +SELECT HEX(b), HEX(b0), HEX(b1), HEX(b20), HEX(b255) FROM t1; +HEX(b) HEX(b0) HEX(b1) HEX(b20) HEX(b255) +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +61 62 616263646566676869206B6C6D6E6F7071727374 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +INSERT INTO t1 VALUES ('abc', 'a', 'abc', REPEAT('a',21), REPEAT('x',256)); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b20' at row 1 +Warning 1265 Data truncated for column 'b255' at row 1 +INSERT INTO t1 SELECT b255, b255, b255, b255, CONCAT(b255,b255) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b20' at row 1 +Warning 1265 Data truncated for column 'b255' at row 1 +Warning 1265 Data truncated for column 'b' at row 2 +Warning 1265 Data truncated for column 'b0' at row 2 +Warning 1265 Data truncated for column 'b1' at row 2 +Warning 1265 Data truncated for column 'b20' at row 2 +Warning 1265 Data truncated for column 'b255' at row 2 +Warning 1265 Data truncated for column 'b' at row 3 +Warning 1265 Data truncated for column 'b0' at row 3 +Warning 1265 Data truncated for column 'b1' at row 3 +Warning 1265 Data truncated for column 'b20' at row 3 +Warning 1265 Data truncated for column 'b255' at row 3 +SELECT HEX(b), HEX(b0), HEX(b1), HEX(b20), HEX(b255) FROM t1; +HEX(b) HEX(b0) HEX(b1) HEX(b20) HEX(b255) +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00 00 0000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +43 43 4372656174696E6720616E2061727469636C6520 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +61 61 6161616161616161616161616161616161616161 787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 +61 62 616263646566676869206B6C6D6E6F7071727374 4372656174696E6720616E2061727469636C6520666F7220746865204B6E6F776C65646765626173652069732073696D696C617220746F2061736B696E67207175657374696F6E732E2046697273742C206E6176696761746520746F207468652063617465676F727920776865726520796F75206665656C207468652061727469636C652073686F756C642062652E204F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C726561647920657869737420776869636820776F756C6420776F726B2E00000000000000000000000000000000000000000000000000000000000000 +78 78 7878787878787878787878787878787878787878 787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 +ALTER TABLE t1 ADD COLUMN b257 BINARY(257) NULL; +ERROR 42000: Column length too big for column 'b257' (max = 255); use BLOB or TEXT instead +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b binary(1) # # # # +b0 binary(0) # # # # +b1 binary(1) # # # # +b20 binary(20) # # # # +b255 binary(255) # # # # +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BINARY NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c binary(1) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c BINARY NULL, +c1 BINARY NULL DEFAULT NULL, +c2 BINARY NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c binary(1) YES NULL +c1 binary(1) YES NULL +c2 binary(1) YES 0 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# VARBINARY columns +# +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (v0 VARBINARY(0) NULL, +v1 VARBINARY(1) NULL, +v64 VARBINARY(64) NULL, +v65000 VARBINARY(65000) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varbinary(0) # # # +v1 varbinary(1) # # # +v64 varbinary(64) # # # +v65000 varbinary(65000) # # # +CREATE TABLE t2 (v VARBINARY(65532) NULL) ENGINE= ; +SHOW COLUMNS IN t2; +Field Type Null Key Default Extra +v varbinary(65532) # # # +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','','',''); +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','y','Once there, double check that an article doesn\'t already exist','Here is a list of recommended books on MariaDB and MySQL. We\'ve provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. + For developers who want to code on MariaDB or MySQL + + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + + For MariaDB / MySQL end users + + * MariaDB Crash Course by Ben Forta + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o Free to read in the Knowledgebase! + + * MySQL (4th Edition) by Paul DuBois + o The \'default\' book to read if you wont to learn to use MySQL / MariaDB. + + * MySQL Cookbook by Paul DuBois + o A lot of examples of how to use MySQL. As with all of Paul\'s books, it\'s worth its weight in gold and even enjoyable reading for such a \'dry\' subject. + + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + o \"High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL\'s full power.\" (From the book description at O\'Reilly) + + * MySQL Admin Cookbook + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. '); +SELECT HEX(v0), HEX(v1), HEX(v64), HEX(v65000) FROM t1; +HEX(v0) HEX(v1) HEX(v64) HEX(v65000) + + 79 4F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C7265616479206578697374 486572652069732061206C697374206F66207265636F6D6D656E64656420626F6F6B73206F6E204D61726961444220616E64204D7953514C2E2057652776652070726F7669646564206C696E6B7320746F20416D617A6F6E2E636F6D206865726520666F7220636F6E76656E69656E63652C2062757420746865792063616E20626520666F756E64206174206D616E79206F7468657220626F6F6B73746F7265732C20626F7468206F6E6C696E6520616E64206F66662E0A0A2020496620796F752077616E7420746F206861766520796F7572206661766F72697465204D7953514C202F204D61726961444220626F6F6B206C697374656420686572652C20706C65617365206C65617665206120636F6D6D656E742E0A2020466F7220646576656C6F706572732077686F2077616E7420746F20636F6465206F6E204D617269614442206F72204D7953514C0A0A2020202020202A20556E6465727374616E64696E67204D7953514C20496E7465726E616C73206279205361736861205061636865762C20666F726D6572204D7953514C20646576656C6F706572206174204D7953514C2041422E0A2020202020202020202020206F205468697320697320746865206F6E6C7920626F6F6B207765206B6E6F772061626F75742074686174206465736372696265732074686520696E7465726E616C73206F66204D617269614442202F204D7953514C2E2041206D757374206861766520666F7220616E796F6E652077686F2077616E747320746F20756E6465727374616E6420616E6420646576656C6F70206F6E204D617269614442210A2020202020202020202020206F204E6F7420616C6C20746F706963732061726520636F766572656420616E6420736F6D652070617274732061726520736C696768746C79206F757464617465642C20627574207374696C6C20746865206265737420626F6F6B206F6E207468697320746F7069632E200A2020202020202A204D7953514C20352E3120506C7567696E20446576656C6F706D656E742062792053657267656920476F6C75626368696B20616E6420416E64726577204875746368696E67730A2020202020202020202020206F2041206D757374207265616420666F7220616E796F6E652077616E74696E6720746F207772697465206120706C7567696E20666F72204D6172696144422C207772697474656E20627920746865205365726765692077686F2064657369676E65642074686520706C7567696E20696E7465726661636520666F72204D7953514C20616E64204D61726961444221200A0A2020466F72204D617269614442202F204D7953514C20656E642075736572730A0A2020202020202A204D61726961444220437261736820436F757273652062792042656E20466F7274610A2020202020202020202020206F204669727374204D61726961444220626F6F6B210A2020202020202020202020206F20466F722070656F706C652077686F2077616E7420746F206C6561726E2053514C20616E642074686520626173696373206F66204D6172696144422E0A2020202020202020202020206F204E6F77207368697070696E672E20507572636861736520617420416D617A6F6E2E636F6D206F7220796F7572206661766F7269746520626F6F6B73656C6C65722E200A0A2020202020202A2053514C2D393920436F6D706C6574652C205265616C6C792062792050657465722047756C75747A616E20262054727564792050656C7A65722E0A2020202020202020202020206F2045766572797468696E6720796F752077616E74656420746F206B6E6F772061626F7574207468652053514C203939207374616E646172642E20457863656C6C656E74207265666572656E636520626F6F6B210A2020202020202020202020206F204672656520746F207265616420696E20746865204B6E6F776C656467656261736521200A0A2020202020202A204D7953514C20283474682045646974696F6E29206279205061756C204475426F69730A2020202020202020202020206F20546865202764656661756C742720626F6F6B20746F207265616420696620796F7520776F6E7420746F206C6561726E20746F20757365204D7953514C202F204D6172696144422E200A0A2020202020202A204D7953514C20436F6F6B626F6F6B206279205061756C204475426F69730A2020202020202020202020206F2041206C6F74206F66206578616D706C6573206F6620686F7720746F20757365204D7953514C2E204173207769746820616C6C206F66205061756C277320626F6F6B732C206974277320776F727468206974732077656967687420696E20676F6C6420616E64206576656E20656E6A6F7961626C652072656164696E6720666F7220737563682061202764727927207375626A6563742E200A0A2020202020202A204869676820506572666F726D616E6365204D7953514C2C205365636F6E642045646974696F6E2C204279204261726F6E20536368776172747A2C205065746572205A6169747365762C20566164696D20546B616368656E6B6F2C204A6572656D7920442E205A61776F646E792C2041726A656E204C656E747A2C20446572656B204A2E2042616C6C696E672C20657420616C2E0A2020202020202020202020206F20224869676820506572666F726D616E6365204D7953514C2069732074686520646566696E697469766520677569646520746F206275696C64696E6720666173742C2072656C6961626C652073797374656D732077697468204D7953514C2E205772697474656E206279206E6F74656420657870657274732077697468207965617273206F66207265616C2D776F726C6420657870657269656E6365206275696C64696E672076657279206C617267652073797374656D732C207468697320626F6F6B20636F7665727320657665727920617370656374206F66204D7953514C20706572666F726D616E636520696E2064657461696C2C20616E6420666F6375736573206F6E20726F627573746E6573732C2073656375726974792C20616E64206461746120696E746567726974792E204C6561726E20616476616E63656420746563686E697175657320696E20646570746820736F20796F752063616E206272696E67206F7574204D7953514C27732066756C6C20706F7765722E22202846726F6D2074686520626F6F6B206465736372697074696F6E206174204F275265696C6C7929200A0A2020202020202A204D7953514C2041646D696E20436F6F6B626F6F6B0A2020202020202020202020206F204120717569636B20737465702D62792D7374657020677569646520666F72204D7953514C20757365727320616E642064617461626173652061646D696E6973747261746F727320746F207461636B6C65207265616C2D776F726C64206368616C6C656E6765732077697468204D7953514C20636F6E66696775726174696F6E20616E642061646D696E697374726174696F6E200A0A2020202020202A204D7953514C20352E302043657274696669636174696F6E2053747564792047756964652C204279205061756C204475426F69732C2053746566616E2048696E7A2C204361727374656E20506564657273656E0A2020202020202020202020206F205468697320697320746865206F6666696369616C20677569646520746F20636F766572207468652070617373696E67206F66207468652074776F204D7953514C2043657274696669636174696F6E206578616D696E6174696F6E732E2049742069732076616C69642074696C6C2076657273696F6E20352E30206F6620746865207365727665722C20736F207768696C65206974206D697373657320616C6C2074686520666561747572657320617661696C61626C6520696E204D7953514C20352E3120616E6420677265617465722028696E636C7564696E67204D61726961444220352E3120616E642067726561746572292C2069742070726F7669646573206120676F6F6420626173696320756E6465727374616E64696E67206F66204D7953514C20666F722074686520656E642D757365722E20 +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('y', 'yy', REPEAT('c',65), REPEAT('abcdefghi ',6501)); +Warnings: +Warning 1265 Data truncated for column 'v0' at row 1 +Warning 1265 Data truncated for column 'v1' at row 1 +Warning 1265 Data truncated for column 'v64' at row 1 +Warning 1265 Data truncated for column 'v65000' at row 1 +INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, v65000, CONCAT(v65000,v1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'v0' at row 2 +Warning 1265 Data truncated for column 'v1' at row 2 +Warning 1265 Data truncated for column 'v64' at row 2 +Warning 1265 Data truncated for column 'v0' at row 3 +Warning 1265 Data truncated for column 'v1' at row 3 +Warning 1265 Data truncated for column 'v64' at row 3 +Warning 1265 Data truncated for column 'v65000' at row 3 +SELECT HEX(v0), HEX(v1), HEX(v64), LENGTH(HEX(v65000)) FROM t1; +HEX(v0) HEX(v1) HEX(v64) LENGTH(HEX(v65000)) + 0 + 0 + 48 486572652069732061206C697374206F66207265636F6D6D656E64656420626F6F6B73206F6E204D61726961444220616E64204D7953514C2E20576527766520 5932 + 61 61626364656667686920616263646566676869206162636465666768692061626364656667686920616263646566676869206162636465666768692061626364 130000 + 79 4F6E63652074686572652C20646F75626C6520636865636B207468617420616E2061727469636C6520646F65736E277420616C7265616479206578697374 5930 + 79 63636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363 130000 +ALTER TABLE t1 ADD COLUMN v65536 VARBINARY(65536) NULL; +Warnings: +Note 1246 Converting column 'v65536' from VARBINARY to BLOB +Note 1246 Converting column 'v65536' from VARBINARY to BLOB +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varbinary(0) # # # +v1 varbinary(1) # # # +v64 varbinary(64) # # # +v65000 varbinary(65000) # # # +v65536 mediumblob # # # +DROP TABLE t1, t2; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c VARBINARY(64) NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varbinary(64) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c VARBINARY(64) NULL, +c1 VARBINARY(64) NULL DEFAULT NULL, +c2 VARBINARY(64) NULL DEFAULT 'test' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varbinary(64) YES NULL +c1 varbinary(64) YES NULL +c2 varbinary(64) YES test +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# BIT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a BIT NULL, +b BIT(20) NULL, +c BIT(64) NULL, +d BIT(1) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a bit(1) # # # +b bit(20) # # # +c bit(64) # # # +d bit(1) # # # +ALTER TABLE t1 DROP COLUMN d; +ALTER TABLE t1 ADD COLUMN d BIT(0) NULL; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a bit(1) # # # +b bit(20) # # # +c bit(64) # # # +d bit(1) # # # +INSERT INTO t1 VALUES (0,POW(2,20)-1,b'1111111111111111111111111111111111111111111111111111111111111111',1); +SELECT BIN(a), HEX(b), c+0 FROM t1 WHERE d>0; +BIN(a) HEX(b) c+0 +0 FFFFF 18446744073709551615 +INSERT INTO t1 VALUES (1,0,-1,0); +SELECT a+0, b+0, c+0 FROM t1 WHERE d<100; +a+0 b+0 c+0 +0 1048575 18446744073709551615 +1 0 18446744073709551615 +INSERT INTO t1 VALUES (b'1', 'f', 0xFF, 0x0); +SELECT a+0, b+0, c+0 FROM t1 WHERE d IN (0, 2); +a+0 b+0 c+0 +1 0 18446744073709551615 +1 102 255 +INSERT INTO t1 VALUES (0x10,0,0,1); +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT * FROM t1; +a b c d +INSERT INTO t1 VALUES (0x01,0,0x10000000000000000,0); +Warnings: +Warning 1264 Out of range value for column 'c' at row 1 +SELECT * FROM t1; +a b c d +DROP TABLE t1; +CREATE TABLE t1 (a BIT(65) NULL) ENGINE= ; +ERROR 42000: Display width out of range for 'a' (max = 64) +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BIT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bit(1) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c BIT NULL, +c1 BIT NULL DEFAULT NULL, +c2 BIT NULL DEFAULT 1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bit(1) YES NULL +c1 bit(1) YES NULL +c2 bit(1) YES b'1' +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# BLOB columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b BLOB NULL, +b0 BLOB(0) NULL, +b1 BLOB(1) NULL, +b300 BLOB(300) NULL, +bm BLOB(65535) NULL, +b70k BLOB(70000) NULL, +b17m BLOB(17000000) NULL, +t TINYBLOB NULL, +m MEDIUMBLOB NULL, +l LONGBLOB NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b blob # # # +b0 blob # # # +b1 tinyblob # # # +b300 blob # # # +bm blob # # # +b70k mediumblob # # # +b17m longblob # # # +t tinyblob # # # +m mediumblob # # # +l longblob # # # +INSERT INTO t1 VALUES +('','','','','','','','','',''), +('a','b','c','d','e','f','g','h','i','j'), +('test1','test2','test3','test4','test5','test6','test7','test8','test9','test10'), +( REPEAT('a',65535), REPEAT('b',65535), REPEAT('c',255), REPEAT('d',65535), REPEAT('e',65535), REPEAT('f',1048576), HEX(REPEAT('g',1048576)), REPEAT('h',255), REPEAT('i',1048576), HEX(REPEAT('j',1048576)) ); +SELECT LENGTH(b), LENGTH(b0), LENGTH(b1), LENGTH(b300), LENGTH(bm), LENGTH(b70k), LENGTH(b17m), LENGTH(t), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(b) LENGTH(b0) LENGTH(b1) LENGTH(b300) LENGTH(bm) LENGTH(b70k) LENGTH(b17m) LENGTH(t) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 2097152 255 1048576 2097152 +INSERT INTO t1 VALUES +( REPEAT('a',65536), REPEAT('b',65536), REPEAT('c',256), REPEAT('d',65536), REPEAT('e',65536), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',256), REPEAT('i',1048576), REPEAT('j',1048576) ); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'b0' at row 1 +Warning 1265 Data truncated for column 'b1' at row 1 +Warning 1265 Data truncated for column 'b300' at row 1 +Warning 1265 Data truncated for column 'bm' at row 1 +Warning 1265 Data truncated for column 't' at row 1 +SELECT LENGTH(b), LENGTH(b0), LENGTH(b1), LENGTH(b300), LENGTH(bm), LENGTH(b70k), LENGTH(b17m), LENGTH(t), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(b) LENGTH(b0) LENGTH(b1) LENGTH(b300) LENGTH(bm) LENGTH(b70k) LENGTH(b17m) LENGTH(t) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +65535 65535 255 65535 65535 1048576 2097152 255 1048576 2097152 +ALTER TABLE t1 ADD COLUMN bbb BLOB(4294967296); +ERROR 42000: Display width out of range for 'bbb' (max = 4294967295) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BLOB NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c blob YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYBLOB NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyblob YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMBLOB NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumblob YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c LONGBLOB NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c longblob YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +# +# BOOL columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (b1 BOOL NULL, +b2 BOOLEAN NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +b1 tinyint(1) # # # +b2 tinyint(1) # # # +INSERT INTO t1 VALUES (1,TRUE); +SELECT * FROM t1; +b1 b2 +1 1 +INSERT INTO t1 VALUES (FALSE,0); +SELECT * FROM t1; +b1 b2 +0 0 +1 1 +INSERT INTO t1 VALUES (2,3); +SELECT * FROM t1; +b1 b2 +0 0 +1 1 +2 3 +INSERT INTO t1 VALUES (-1,-2); +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +1 1 +2 3 +SELECT IF(b1,'true','false') AS a, IF(b2,'true','false') AS b FROM t1; +a b +false false +true true +true true +true true +SELECT * FROM t1 WHERE b1 = TRUE; +b1 b2 +1 1 +SELECT * FROM t1 WHERE b2 = FALSE; +b1 b2 +0 0 +INSERT INTO t1 VALUES ('a','b'); +Warnings: +Warning 1366 Incorrect integer value: 'a' for column 'b1' at row 1 +Warning 1366 Incorrect integer value: 'b' for column 'b2' at row 1 +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +0 0 +1 1 +2 3 +INSERT INTO t1 VALUES (128,-129); +Warnings: +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b2' at row 1 +SELECT * FROM t1; +b1 b2 +-1 -2 +0 0 +0 0 +1 1 +127 -128 +2 3 +ALTER TABLE t1 ADD COLUMN b3 BOOLEAN UNSIGNED; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNSIGNED' at line 1 +ALTER TABLE t1 ADD COLUMN b3 BOOL ZEROFILL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ZEROFILL' at line 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BOOL NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(1) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c BOOL NULL, +c1 BOOL NULL DEFAULT NULL, +c2 BOOL NULL DEFAULT '0' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(1) YES NULL +c1 tinyint(1) YES NULL +c2 tinyint(1) YES 0 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# CHAR columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c CHAR NULL, +c0 CHAR(0) NULL, +c1 CHAR(1) NULL, +c20 CHAR(20) NULL, +c255 CHAR(255) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) # # # +c0 char(0) # # # +c1 char(1) # # # +c20 char(20) # # # +c255 char(255) # # # +INSERT INTO t1 VALUES ('','','','',''); +INSERT INTO t1 VALUES ('a','','b','abcdefghi klmnopqrst', 'Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn\'t already exist which would work.'); +SELECT * FROM t1; +c c0 c1 c20 c255 + +a b abcdefghi klmnopqrst Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work. +INSERT INTO t1 VALUES ('abc', 'a', 'abc', REPEAT('a',21), REPEAT('x',256)); +Warnings: +Warning 1265 Data truncated for column 'c' at row 1 +Warning 1265 Data truncated for column 'c0' at row 1 +Warning 1265 Data truncated for column 'c1' at row 1 +Warning 1265 Data truncated for column 'c20' at row 1 +Warning 1265 Data truncated for column 'c255' at row 1 +INSERT INTO t1 SELECT c255, c255, c255, c255, CONCAT(c255,c1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'c' at row 2 +Warning 1265 Data truncated for column 'c0' at row 2 +Warning 1265 Data truncated for column 'c1' at row 2 +Warning 1265 Data truncated for column 'c20' at row 2 +Warning 1265 Data truncated for column 'c' at row 3 +Warning 1265 Data truncated for column 'c0' at row 3 +Warning 1265 Data truncated for column 'c1' at row 3 +Warning 1265 Data truncated for column 'c20' at row 3 +Warning 1265 Data truncated for column 'c255' at row 3 +SELECT * FROM t1; +c c0 c1 c20 c255 + + +C C Creating an article Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work.b +a a aaaaaaaaaaaaaaaaaaaa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +a b abcdefghi klmnopqrst Creating an article for the Knowledgebase is similar to asking questions. First, navigate to the category where you feel the article should be. Once there, double check that an article doesn't already exist which would work. +x x xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +SELECT DISTINCT c20, REPEAT('a',LENGTH(c20)), COUNT(*) FROM t1 GROUP BY c1, c20; +c20 REPEAT('a',LENGTH(c20)) COUNT(*) + 2 +Creating an article aaaaaaaaaaaaaaaaaaa 1 +aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa 1 +abcdefghi klmnopqrst aaaaaaaaaaaaaaaaaaaa 1 +xxxxxxxxxxxxxxxxxxxx aaaaaaaaaaaaaaaaaaaa 1 +ALTER TABLE t1 ADD COLUMN c257 CHAR(257) NULL; +ERROR 42000: Column length too big for column 'c257' (max = 255); use BLOB or TEXT instead +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c CHAR NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c CHAR NULL, +c1 CHAR NULL DEFAULT NULL, +c2 CHAR NULL DEFAULT '_' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c char(1) YES NULL +c1 char(1) YES NULL +c2 char(1) YES _ +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# VARCHAR columns +# +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (v0 VARCHAR(0) NULL, +v1 VARCHAR(1) NULL, +v64 VARCHAR(64) NULL, +v65000 VARCHAR(65000) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varchar(0) # # # +v1 varchar(1) # # # +v64 varchar(64) # # # +v65000 varchar(65000) # # # +CREATE TABLE t2 (v VARCHAR(65532) NULL) ENGINE= ; +SHOW COLUMNS IN t2; +Field Type Null Key Default Extra +v varchar(65532) # # # +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','','',''); +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','y','Once there, double check that an article doesn\'t already exist','Here is a list of recommended books on MariaDB and MySQL. We\'ve provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. + For developers who want to code on MariaDB or MySQL + + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + + For MariaDB / MySQL end users + + * MariaDB Crash Course by Ben Forta + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o Free to read in the Knowledgebase! + + * MySQL (4th Edition) by Paul DuBois + o The \'default\' book to read if you wont to learn to use MySQL / MariaDB. + + * MySQL Cookbook by Paul DuBois + o A lot of examples of how to use MySQL. As with all of Paul\'s books, it\'s worth its weight in gold and even enjoyable reading for such a \'dry\' subject. + + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + o \"High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL\'s full power.\" (From the book description at O\'Reilly) + + * MySQL Admin Cookbook + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. '); +SELECT * FROM t1; +v0 v1 v64 v65000 + + + + + + + + + + + + y Once there, double check that an article doesn't already exist Here is a list of recommended books on MariaDB and MySQL. We've provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off. + o "High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL's full power." (From the book description at O'Reilly) + o A lot of examples of how to use MySQL. As with all of Paul's books, it's worth its weight in gold and even enjoyable reading for such a 'dry' subject. + o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! + o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration + o Everything you wanted to know about the SQL 99 standard. Excellent reference book! + o First MariaDB book! + o For people who want to learn SQL and the basics of MariaDB. + o Free to read in the Knowledgebase! + o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. + o Now shipping. Purchase at Amazon.com or your favorite bookseller. + o The 'default' book to read if you wont to learn to use MySQL / MariaDB. + o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. + o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB! + * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al. + * MariaDB Crash Course by Ben Forta + * MySQL (4th Edition) by Paul DuBois + * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen + * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings + * MySQL Admin Cookbook + * MySQL Cookbook by Paul DuBois + * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer. + * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB. + For MariaDB / MySQL end users + For developers who want to code on MariaDB or MySQL + If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment. +INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('y', 'yy', REPEAT('c',65), REPEAT('abcdefghi ',6501)); +Warnings: +Warning 1265 Data truncated for column 'v0' at row 1 +Warning 1265 Data truncated for column 'v1' at row 1 +Warning 1265 Data truncated for column 'v64' at row 1 +Warning 1265 Data truncated for column 'v65000' at row 1 +INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, v65000, CONCAT(v65000,v1) FROM t1; +Warnings: +Warning 1265 Data truncated for column 'v0' at row 2 +Warning 1265 Data truncated for column 'v1' at row 2 +Warning 1265 Data truncated for column 'v64' at row 2 +Warning 1265 Data truncated for column 'v0' at row 3 +Warning 1265 Data truncated for column 'v1' at row 3 +Warning 1265 Data truncated for column 'v64' at row 3 +Warning 1265 Data truncated for column 'v65000' at row 3 +SELECT v0, v1, v64, LENGTH(v65000) FROM t1; +v0 v1 v64 LENGTH(v65000) + 0 + 0 + H Here is a list of recommended books on MariaDB and MySQL. We've 2966 + a abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcd 65000 + y Once there, double check that an article doesn't already exist 2965 + y cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 65000 +ALTER TABLE t1 ADD COLUMN v65536 VARCHAR(65536) NULL; +Warnings: +Note 1246 Converting column 'v65536' from VARCHAR to TEXT +Note 1246 Converting column 'v65536' from VARCHAR to TEXT +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +v0 varchar(0) # # # +v1 varchar(1) # # # +v64 varchar(64) # # # +v65000 varchar(65000) # # # +v65536 mediumtext # # # +DROP TABLE t1, t2; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c VARCHAR(64) NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varchar(64) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c VARCHAR(64) NULL, +c1 VARCHAR(64) NULL DEFAULT NULL, +c2 VARCHAR(64) NULL DEFAULT 'test default' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c varchar(64) YES NULL +c1 varchar(64) YES NULL +c2 varchar(64) YES test default +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# date and time columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DATE NULL, +dt DATETIME NULL, +ts TIMESTAMP NULL, +t TIME NULL, +y YEAR NULL, +y4 YEAR(4) NULL, +y2 YEAR(2) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d date # # # +dt datetime # # # +ts timestamp # # # +t time # # # +y year(4) # # # +y4 year(4) # # # +y2 year(2) # # # +SET @tm = '2012-04-09 05:27:00'; +INSERT INTO t1 VALUES +('1000-01-01', '1000-01-01 00:00:00', FROM_UNIXTIME(1), '-838:59:59', '1901', '1901', '00'), +('9999-12-31', '9999-12-31 23:59:59', FROM_UNIXTIME(2147483647), '838:59:59', '2155', '2155', '99'), +('0000-00-00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '00:00:00', '0', '0', '0'), +(DATE(@tm),@tm,TIMESTAMP(@tm),TIME(@tm),YEAR(@tm),YEAR(@tm),YEAR(@tm)); +SELECT * FROM t1; +d dt ts t y y4 y2 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 00:00:00 2000 2000 00 +1000-01-01 1000-01-01 00:00:00 1970-01-01 03:00:01 -838:59:59 1901 1901 00 +2012-04-09 2012-04-09 05:27:00 2012-04-09 05:27:00 05:27:00 2012 2012 12 +9999-12-31 9999-12-31 23:59:59 2038-01-19 07:14:07 838:59:59 2155 2155 99 +INSERT INTO t1 VALUES +('999-13-32', '999-11-31 00:00:00', '0', '-839:00:00', '1900', '1900', '-1' ); +Warnings: +Warning 1265 Data truncated for column 'd' at row 1 +Warning 1265 Data truncated for column 'dt' at row 1 +Warning 1265 Data truncated for column 'ts' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 'y' at row 1 +Warning 1264 Out of range value for column 'y4' at row 1 +Warning 1264 Out of range value for column 'y2' at row 1 +SELECT * FROM t1; +d dt ts t y y4 y2 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 -838:59:59 0000 0000 00 +0000-00-00 0000-00-00 00:00:00 0000-00-00 00:00:00 00:00:00 2000 2000 00 +1000-01-01 1000-01-01 00:00:00 1970-01-01 03:00:01 -838:59:59 1901 1901 00 +2012-04-09 2012-04-09 05:27:00 2012-04-09 05:27:00 05:27:00 2012 2012 12 +9999-12-31 9999-12-31 23:59:59 2038-01-19 07:14:07 838:59:59 2155 2155 99 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DATE NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c date YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c DATE NULL, +c1 DATE NULL DEFAULT NULL, +c2 DATE NULL DEFAULT '2012-12-21' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c date YES NULL +c1 date YES NULL +c2 date YES 2012-12-21 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DATETIME NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c datetime YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c DATETIME NULL, +c1 DATETIME NULL DEFAULT NULL, +c2 DATETIME NULL DEFAULT '2012-12-21 12:21:12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c datetime YES NULL +c1 datetime YES NULL +c2 datetime YES 2012-12-21 12:21:12 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TIMESTAMP NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c timestamp YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c TIMESTAMP NULL, +c1 TIMESTAMP NULL DEFAULT NULL, +c2 TIMESTAMP NULL DEFAULT '2012-12-21 12:21:12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c timestamp YES NULL +c1 timestamp YES NULL +c2 timestamp YES 2012-12-21 12:21:12 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TIME NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c time YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c TIME NULL, +c1 TIME NULL DEFAULT NULL, +c2 TIME NULL DEFAULT '12:21:12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c time YES NULL +c1 time YES NULL +c2 time YES 12:21:12 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c YEAR NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(4) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c YEAR NULL, +c1 YEAR NULL DEFAULT NULL, +c2 YEAR NULL DEFAULT '2012' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(4) YES NULL +c1 year(4) YES NULL +c2 year(4) YES 2012 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c YEAR(2) NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(2) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c YEAR(2) NULL, +c1 YEAR(2) NULL DEFAULT NULL, +c2 YEAR(2) NULL DEFAULT '12' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c year(2) YES NULL +c1 year(2) YES NULL +c2 year(2) YES 12 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# ENUM columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a ENUM('') NULL, +b ENUM('test1','test2','test3','test4','test5') NULL, +c ENUM('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a enum('') # # # +b enum('test1','test2','test3','test4','test5') # # # +c enum('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') # # # +INSERT INTO t1 VALUES ('','test2','4'),('',5,2); +SELECT * FROM t1; +a b c + test2 4 + test5 2 +INSERT INTO t1 VALUES (0,'test6',-1); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + + test2 4 + test5 2 +ALTER TABLE t1 ADD COLUMN e ENUM('a','A') NULL; +Warnings: +Note 1291 Column 'e' has duplicated value 'a' in ENUM +Note 1291 Column 'e' has duplicated value 'a' in ENUM +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a enum('') # # # +b enum('test1','test2','test3','test4','test5') # # # +c enum('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i','3j','3k','3l','3m','3n','3o','3p','3q','3r','3s','3t','3u','3v','3w','3x','3y','3z','40','41','42','43','44','45','46','47','48','49','4a','4b','4c','4d','4e','4f','4g','4h','4i','4j','4k','4l','4m','4n','4o','4p','4q','4r','4s','4t','4u','4v','4w','4x','4y','4z','50','51','52','53','54','55','56','57','58','59','5a','5b','5c','5d','5e','5f','5g','5h','5i','5j','5k','5l','5m','5n','5o','5p','5q','5r','5s','5t','5u','5v','5w','5x','5y','5z','60','61','62','63','64','65','66','67','68','69','6a','6b','6c','6d','6e','6f','6g','6h','6i','6j','6k','6l','6m','6n','6o','6p','6q','6r','6s','6t','6u','6v','6w','6x','6y','6z','70','71','72','73','74','75') # # # +e enum('a','A') # # # +INSERT INTO t1 VALUES ('','test3','75','A'); +SELECT * FROM t1; +a b c e + NULL + test2 4 NULL + test3 75 a + test5 2 NULL +SELECT * FROM t1 WHERE b='test2' OR a != ''; +a b c e + test2 4 NULL +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c ENUM('test1','test2','test3') NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c enum('test1','test2','test3') YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c ENUM('test1','test2','test3') NULL, +c1 ENUM('test1','test2','test3') NULL DEFAULT NULL, +c2 ENUM('test1','test2','test3') NULL DEFAULT 'test2' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c enum('test1','test2','test3') YES NULL +c1 enum('test1','test2','test3') YES NULL +c2 enum('test1','test2','test3') YES test2 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# Fixed point columns (NUMERIC, DECIMAL) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DECIMAL NULL, +d0 DECIMAL(0) NULL, +d1_1 DECIMAL(1,1) NULL, +d10_2 DECIMAL(10,2) NULL, +d60_10 DECIMAL(60,10) NULL, +n NUMERIC NULL, +n0_0 NUMERIC(0,0) NULL, +n1 NUMERIC(1) NULL, +n20_4 NUMERIC(20,4) NULL, +n65_4 NUMERIC(65,4) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d decimal(10,0) # # # +d0 decimal(10,0) # # # +d1_1 decimal(1,1) # # # +d10_2 decimal(10,2) # # # +d60_10 decimal(60,10) # # # +n decimal(10,0) # # # +n0_0 decimal(10,0) # # # +n1 decimal(1,0) # # # +n20_4 decimal(20,4) # # # +n65_4 decimal(65,4) # # # +INSERT INTO t1 VALUES (100,123456,0.3,40000.25,123456789123456789.10001,1024,7000.0,8.0,999999.9,9223372036854775807); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (9999999999.0,9999999999.0,0.9,99999999.99,99999999999999999999999999999999999999999999999999.9999999999,9999999999.0,9999999999.0,9.0,9999999999999999.9999,9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (-100,-123456,-0.3,-40000.25,-123456789123456789.10001,-1024,-7000.0,-8.0,-999999.9,-9223372036854775807); +INSERT INTO t1 VALUES (-9999999999.0,-9999999999.0,-0.9,-99999999.99,-99999999999999999999999999999999999999999999999999.9999999999,-9999999999.0,-9999999999.0,-9.0,-9999999999999999.9999,-9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +SELECT * FROM t1 WHERE n20_4 = 9999999999999999.9999 OR d < 100; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 SELECT n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4 FROM t1 WHERE n65_4 = ( SELECT MAX(n65_4) FROM t1 ); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (10000000000.0,10000000000.0,1.1,100000000.99,100000000000000000000000000000000000000000000000000.0,10000000000.0,10000000000.0,10.0,10000000000000000.9999,10000000000000000000000000000000000000000000000000000000000000.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (9999999999.1,9999999999.1,1.9,99999999.001,99999999999999999999999999999999999999999999999999.99999999991,9999999999.1,9999999999.1,9.1,9999999999999999.00001,9999999999999999999999999999999999999999999999999999999999999.11111); +Warnings: +Note 1265 Data truncated for column 'd' at row 1 +Note 1265 Data truncated for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Note 1265 Data truncated for column 'd10_2' at row 1 +Note 1265 Data truncated for column 'd60_10' at row 1 +Note 1265 Data truncated for column 'n' at row 1 +Note 1265 Data truncated for column 'n0_0' at row 1 +Note 1265 Data truncated for column 'n1' at row 1 +Note 1265 Data truncated for column 'n20_4' at row 1 +Note 1265 Data truncated for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +-100 -123456 -0.3 -40000.25 -123456789123456789.1000100000 -1024 -7000 -8 -999999.9000 -9223372036854775807.0000 +-9999999999 -9999999999 -0.9 -99999999.99 -99999999999999999999999999999999999999999999999999.9999999999 -9999999999 -9999999999 -9 -9999999999999999.9999 -9999999999999999999999999999999999999999999999999999999999999.9999 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.00 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.0000 9999999999999999999999999999999999999999999999999999999999999.1111 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +ALTER TABLE t1 ADD COLUMN n66 NUMERIC(66); +ERROR 42000: Too big precision 66 specified for 'n66'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(66,6); +ERROR 42000: Too big precision 66 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(66,66); +ERROR 42000: Too big scale 66 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DECIMAL NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c DECIMAL NULL, +c1 DECIMAL NULL DEFAULT NULL, +c2 DECIMAL NULL DEFAULT 1.1 +) ENGINE= ; +Warnings: +Note 1265 Data truncated for column 'c2' at row 1 +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) YES NULL +c1 decimal(10,0) YES NULL +c2 decimal(10,0) YES 1 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c NUMERIC NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c NUMERIC NULL, +c1 NUMERIC NULL DEFAULT NULL, +c2 NUMERIC NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c decimal(10,0) YES NULL +c1 decimal(10,0) YES NULL +c2 decimal(10,0) YES 0 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# Floating point columns (FLOAT, DOUBLE) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f FLOAT NULL, +f0 FLOAT(0) NULL, +r1_1 REAL(1,1) NULL, +f23_0 FLOAT(23) NULL, +f20_3 FLOAT(20,3) NULL, +d DOUBLE NULL, +d1_0 DOUBLE(1,0) NULL, +d10_10 DOUBLE PRECISION (10,10) NULL, +d53 DOUBLE(53,0) NULL, +d53_10 DOUBLE(53,10) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +f float # # # +f0 float # # # +r1_1 double(1,1) # # # +f23_0 float # # # +f20_3 float(20,3) # # # +d double # # # +d1_0 double(1,0) # # # +d10_10 double(10,10) # # # +d53 double(53,0) # # # +d53_10 double(53,10) # # # +INSERT INTO t1 VALUES (12345.12345,12345.12345,0.9,123456789.123,56789.987,11111111.111,8.0,0.0123456789,1234566789123456789,99999999999999999.99999999); +SELECT * FROM t1; +f 12345.1 +d 11111111.111 +d10_10 0.0123456789 +d1_0 8 +d53 1234566789123456800 +d53_10 100000000000000000.0000000000 +f0 12345.1 +f20_3 56789.988 +f23_0 123457000 +r1_1 0.9 +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES ( +99999999999999999999999999999999999999, +99999999999999999999999999999999999999.9999999999999999, +0.9, +99999999999999999999999999999999999999.9, +99999999999999999.999, +999999999999999999999999999999999999999999999999999999999999999999999999999999999, +9, +0.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 11111111.111 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 8 +d1_0 9 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 1e38 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES (-999999999999999999999999,-99999999999.999999999999,-0.9,-999.99999999999999999999,-99999999999999999.999,-999999999999999999999999999999999999999999999999999999999999-0.999,-9,-.9999999999,-999999999999999999999999999999.99999999999999999999999,-9999999999999999999999999999999999999999999.9999999999); +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +SELECT MAX(f), MAX(f0), MAX(r1_1), MAX(f23_0), MAX(f20_3), MAX(d), MAX(d1_0), MAX(d10_10), MAX(d53), MAX(d53_10) FROM t1; +MAX(f) 9.999999680285692e37 +MAX(d) 1e81 +MAX(d10_10) 0.9999999999 +MAX(d1_0) 9 +MAX(d53) 100000000000000000000000000000000000000000000000000000 +MAX(d53_10) 10000000000000000000000000000000000000000000.0000000000 +MAX(f0) 9.999999680285692e37 +MAX(f20_3) 99999998430674940.000 +MAX(f23_0) 9.999999680285692e37 +MAX(r1_1) 0.9 +INSERT INTO t1 SELECT d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10 FROM t1 ORDER BY d53_10 DESC LIMIT 1; +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e43 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f 3.40282e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES ( +999999999999999999999999999999999999999, +999999999999999999999999999999999999999.9999999999999999, +1.9, +999999999999999999999999999999999999999.9, +999999999999999999.999, +9999999999999999999999999999999999999999999999999999999999999999999999999999999999, +99, +1.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated. +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d -1e60 +d 0 +d 11111111.111 +d 1e43 +d 1e65 +d 1e81 +d10_10 -0.9999999999 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 -9 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d1_0 9 +d53 -1000000000000000000000000000000 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 -10000000000000000000000000000000000000000000.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f -1e24 +f 0 +f 1e38 +f 3.40282e38 +f 3.40282e38 +f0 -100000000000 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f0 3.40282e38 +f20_3 -99999998430674940.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 -1000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +f23_0 3.40282e38 +r1_1 -0.9 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +ALTER TABLE t1 ADD COLUMN d0_0 DOUBLE(0,0); +ERROR 42000: Display width out of range for 'd0_0' (max = 255) +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(256,1); +ERROR 42000: Too big precision 256 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(40,35); +ERROR 42000: Too big scale 35 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c FLOAT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c float YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c FLOAT NULL, +c1 FLOAT NULL DEFAULT NULL, +c2 FLOAT NULL DEFAULT 1.1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c float YES NULL +c1 float YES NULL +c2 float YES 1.1 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c DOUBLE NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c double YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c DOUBLE NULL, +c1 DOUBLE NULL DEFAULT NULL, +c2 DOUBLE NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c double YES NULL +c1 double YES NULL +c2 double YES 0 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# INT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT NULL, +i0 INT(0) NULL, +i1 INT(1) NULL, +i20 INT(20) NULL, +t TINYINT NULL, +t0 TINYINT(0) NULL, +t1 TINYINT(1) NULL, +t20 TINYINT(20) NULL, +s SMALLINT NULL, +s0 SMALLINT(0) NULL, +s1 SMALLINT(1) NULL, +s20 SMALLINT(20) NULL, +m MEDIUMINT NULL, +m0 MEDIUMINT(0) NULL, +m1 MEDIUMINT(1) NULL, +m20 MEDIUMINT(20) NULL, +b BIGINT NULL, +b0 BIGINT(0) NULL, +b1 BIGINT(1) NULL, +b20 BIGINT(20) NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +i int(11) # # # +i0 int(11) # # # +i1 int(1) # # # +i20 int(20) # # # +t tinyint(4) # # # +t0 tinyint(4) # # # +t1 tinyint(1) # # # +t20 tinyint(20) # # # +s smallint(6) # # # +s0 smallint(6) # # # +s1 smallint(1) # # # +s20 smallint(20) # # # +m mediumint(9) # # # +m0 mediumint(9) # # # +m1 mediumint(1) # # # +m20 mediumint(20) # # # +b bigint(20) # # # +b0 bigint(20) # # # +b1 bigint(1) # # # +b20 bigint(20) # # # +INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (2147483647,2147483647,2147483647,2147483647,127,127,127,127,32767,32767,32767,32767,8388607,8388607,8388607,8388607,9223372036854775807,9223372036854775807,9223372036854775807,9223372036854775807); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +INSERT INTO t1 VALUES (-2147483648,-2147483648,-2147483648,-2147483648,-128,-128,-128,-128,-32768,-32768,-32768,-32768,-8388608,-8388608,-8388608,-8388608,-9223372036854775808,-9223372036854775808,-9223372036854775808,-9223372036854775808); +INSERT INTO t1 VALUES (4294967295,4294967295,4294967295,4294967295,255,255,255,255,65535,65535,65535,65535,16777215,16777215,16777215,16777215,18446744073709551615,18446744073709551615,18446744073709551615,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +INSERT INTO t1 VALUES (-2147483649,-2147483649,-2147483649,-2147483649,-129,-129,-129,-129,-32769,-32769,-32769,-32769,-8388609,-8388609,-8388609,-8388609,-9223372036854775809,-9223372036854775809,-9223372036854775809,-9223372036854775809); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967296,4294967296,4294967296,4294967296,256,256,256,256,65536,65536,65536,65536,16777216,16777216,16777216,16777216,18446744073709551616,18446744073709551616,18446744073709551616,18446744073709551616); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'i' at row 2 +Warning 1264 Out of range value for column 'i0' at row 2 +Warning 1264 Out of range value for column 'i1' at row 2 +Warning 1264 Out of range value for column 'i20' at row 2 +Warning 1264 Out of range value for column 't' at row 2 +Warning 1264 Out of range value for column 't0' at row 2 +Warning 1264 Out of range value for column 't1' at row 2 +Warning 1264 Out of range value for column 't20' at row 2 +Warning 1264 Out of range value for column 's' at row 2 +Warning 1264 Out of range value for column 's0' at row 2 +Warning 1264 Out of range value for column 's1' at row 2 +Warning 1264 Out of range value for column 's20' at row 2 +Warning 1264 Out of range value for column 'm' at row 2 +Warning 1264 Out of range value for column 'm0' at row 2 +Warning 1264 Out of range value for column 'm1' at row 2 +Warning 1264 Out of range value for column 'm20' at row 2 +Warning 1264 Out of range value for column 'i' at row 3 +Warning 1264 Out of range value for column 'i0' at row 3 +Warning 1264 Out of range value for column 'i1' at row 3 +Warning 1264 Out of range value for column 'i20' at row 3 +Warning 1264 Out of range value for column 't' at row 3 +Warning 1264 Out of range value for column 't0' at row 3 +Warning 1264 Out of range value for column 't1' at row 3 +Warning 1264 Out of range value for column 't20' at row 3 +Warning 1264 Out of range value for column 's' at row 3 +Warning 1264 Out of range value for column 's0' at row 3 +Warning 1264 Out of range value for column 's1' at row 3 +Warning 1264 Out of range value for column 's20' at row 3 +Warning 1264 Out of range value for column 'm' at row 3 +Warning 1264 Out of range value for column 'm0' at row 3 +Warning 1264 Out of range value for column 'm1' at row 3 +Warning 1264 Out of range value for column 'm20' at row 3 +Warning 1264 Out of range value for column 'i' at row 4 +Warning 1264 Out of range value for column 'i0' at row 4 +Warning 1264 Out of range value for column 'i1' at row 4 +Warning 1264 Out of range value for column 'i20' at row 4 +Warning 1264 Out of range value for column 't' at row 4 +Warning 1264 Out of range value for column 't0' at row 4 +Warning 1264 Out of range value for column 't1' at row 4 +Warning 1264 Out of range value for column 't20' at row 4 +Warning 1264 Out of range value for column 's' at row 4 +Warning 1264 Out of range value for column 's0' at row 4 +Warning 1264 Out of range value for column 's1' at row 4 +Warning 1264 Out of range value for column 's20' at row 4 +Warning 1264 Out of range value for column 'm' at row 4 +Warning 1264 Out of range value for column 'm0' at row 4 +Warning 1264 Out of range value for column 'm1' at row 4 +Warning 1264 Out of range value for column 'm20' at row 4 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +ALTER TABLE t1 ADD COLUMN i257 INT(257); +ERROR 42000: Display width out of range for 'i257' (max = 255) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c INT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c int(11) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c INT NULL, +c1 INT NULL DEFAULT NULL, +c2 INT NULL DEFAULT 2147483647 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c int(11) YES NULL +c1 int(11) YES NULL +c2 int(11) YES 2147483647 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYINT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(4) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c TINYINT NULL, +c1 TINYINT NULL DEFAULT NULL, +c2 TINYINT NULL DEFAULT 127 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinyint(4) YES NULL +c1 tinyint(4) YES NULL +c2 tinyint(4) YES 127 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c SMALLINT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c smallint(6) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c SMALLINT NULL, +c1 SMALLINT NULL DEFAULT NULL, +c2 SMALLINT NULL DEFAULT 0 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c smallint(6) YES NULL +c1 smallint(6) YES NULL +c2 smallint(6) YES 0 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMINT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumint(9) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c MEDIUMINT NULL, +c1 MEDIUMINT NULL DEFAULT NULL, +c2 MEDIUMINT NULL DEFAULT 1 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumint(9) YES NULL +c1 mediumint(9) YES NULL +c2 mediumint(9) YES 1 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c BIGINT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bigint(20) YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c BIGINT NULL, +c1 BIGINT NULL DEFAULT NULL, +c2 BIGINT NULL DEFAULT 9223372036854775807 +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c bigint(20) YES NULL +c1 bigint(20) YES NULL +c2 bigint(20) YES 9223372036854775807 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# SET columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a SET('') NULL, +b SET('test1','test2','test3','test4','test5') NULL, +c SET('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a set('') # # # +b set('test1','test2','test3','test4','test5') # # # +c set('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') # # # +INSERT INTO t1 VALUES +('','test2,test3','01,34,44,,23'), +('',5,2), +(',','test4,test2',''); +Warnings: +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + test1,test3 02 + test2,test3 01,23,34,44 + test2,test4 +INSERT INTO t1 VALUES (0,'test6',-1); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +Warning 1265 Data truncated for column 'c' at row 1 +SELECT * FROM t1; +a b c + 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50'51,52,53,54,55,56,57,58,59,60,61,62,63,64 + test1,test3 02 + test2,test3 01,23,34,44 + test2,test4 +ALTER TABLE t1 ADD COLUMN e SET('a','A') NULL; +Warnings: +Note 1291 Column 'e' has duplicated value 'a' in SET +Note 1291 Column 'e' has duplicated value 'a' in SET +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a set('') # # # +b set('test1','test2','test3','test4','test5') # # # +c set('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50''51','52','53','54','55','56','57','58','59','60','61','62','63','64') # # # +e set('a','A') # # # +ALTER TABLE t1 ADD COLUMN f SET('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','11','12','13','14','15','16','17','18','19','1a','1b','1c','1d','1e','1f','1g','1h','1i','1j','1k','1l','1m','1n','1o','1p','1q','1r','1s','1t','1u','1v','1w','1x','1y','1z','20','21','22','23','24','25','26','27','28','29','2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z','30','31','32','33','34','35','36','37','38','39','3a','3b','3c','3d','3e','3f','3g','3h','3i') NULL; +ERROR HY000: Too many strings for column f and SET +SELECT * FROM t1 WHERE FIND_IN_SET('test2',b)>0 OR a != ''; +a b c e + test2,test3 01,23,34,44 NULL + test2,test4 NULL +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c SET('test1','test2','test3') NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c set('test1','test2','test3') YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +CREATE TABLE t1 (c SET('test1','test2','test3') NULL, +c1 SET('test1','test2','test3') NULL DEFAULT NULL, +c2 SET('test1','test2','test3') NULL DEFAULT 'test2,test3' +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c set('test1','test2','test3') YES NULL +c1 set('test1','test2','test3') YES NULL +c2 set('test1','test2','test3') YES test2,test3 +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; +COUNT(c2) COUNT(c1) COUNT(c) COUNT(*) +1 0 0 1 +DROP TABLE t1; +# +# TEXT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (t TEXT NULL, +t0 TEXT(0) NULL, +t1 TEXT(1) NULL, +t300 TEXT(300) NULL, +tm TEXT(65535) NULL, +t70k TEXT(70000) NULL, +t17m TEXT(17000000) NULL, +tt TINYTEXT NULL, +m MEDIUMTEXT NULL, +l LONGTEXT NULL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +t text # # # +t0 text # # # +t1 tinytext # # # +t300 text # # # +tm text # # # +t70k mediumtext # # # +t17m longtext # # # +tt tinytext # # # +m mediumtext # # # +l longtext # # # +INSERT INTO t1 VALUES +('','','','','','','','','',''), +('a','b','c','d','e','f','g','h','i','j'), +('test1','test2','test3','test4','test5','test6','test7','test8','test9','test10'), +( REPEAT('a',65535), REPEAT('b',65535), REPEAT('c',255), REPEAT('d',65535), REPEAT('e',65535), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',255), REPEAT('i',1048576), REPEAT('j',1048576) ); +SELECT LENGTH(t), LENGTH(t0), LENGTH(t1), LENGTH(t300), LENGTH(tm), LENGTH(t70k), LENGTH(t17m), LENGTH(tt), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(t) LENGTH(t0) LENGTH(t1) LENGTH(t300) LENGTH(tm) LENGTH(t70k) LENGTH(t17m) LENGTH(tt) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +INSERT INTO t1 VALUES +( REPEAT('a',65536), REPEAT('b',65536), REPEAT('c',256), REPEAT('d',65536), REPEAT('e',65536), REPEAT('f',1048576), REPEAT('g',1048576), REPEAT('h',256), REPEAT('i',1048576), REPEAT('j',1048576) ); +Warnings: +Warning 1265 Data truncated for column 't' at row 1 +Warning 1265 Data truncated for column 't0' at row 1 +Warning 1265 Data truncated for column 't1' at row 1 +Warning 1265 Data truncated for column 't300' at row 1 +Warning 1265 Data truncated for column 'tm' at row 1 +Warning 1265 Data truncated for column 'tt' at row 1 +SELECT LENGTH(t), LENGTH(t0), LENGTH(t1), LENGTH(t300), LENGTH(tm), LENGTH(t70k), LENGTH(t17m), LENGTH(tt), LENGTH(m), LENGTH(l) FROM t1; +LENGTH(t) LENGTH(t0) LENGTH(t1) LENGTH(t300) LENGTH(tm) LENGTH(t70k) LENGTH(t17m) LENGTH(tt) LENGTH(m) LENGTH(l) +0 0 0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 1 1 1 +5 5 5 5 5 5 5 5 5 6 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +65535 65535 255 65535 65535 1048576 1048576 255 1048576 1048576 +ALTER TABLE t1 ADD COLUMN ttt TEXT(4294967296); +ERROR 42000: Display width out of range for 'ttt' (max = 4294967295) +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TEXT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c text YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c TINYTEXT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c tinytext YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c MEDIUMTEXT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c mediumtext YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c LONGTEXT NULL) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +c longtext YES NULL +INSERT INTO t1 (c) VALUES (NULL); +SELECT COUNT(c), COUNT(*) FROM t1; +COUNT(c) COUNT(*) +0 1 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/col_opt_null.test b/mysql-test/suite/storage_engine/col_opt_null.test new file mode 100644 index 00000000000..29979d29dfd --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_null.test @@ -0,0 +1,208 @@ +# +# NULL column attribute +# + +let $extra_col_opts = NULL; + +--source have_engine.inc + +--echo # +--echo # BINARY columns +--echo # + +--source type_binary.inc +--let $col_definition = BINARY $default_col_opts +--let $col_default = 0 +--source col_null.inc + +--echo # +--echo # VARBINARY columns +--echo # + +--source type_varbinary.inc +--let $col_definition = VARBINARY(64) $default_col_opts +--let $col_default = 'test' +--source col_null.inc + +--echo # +--echo # BIT columns +--echo # + +--source type_bit.inc +--let $col_definition = BIT $default_col_opts +--let $col_default = 1 +--source col_null.inc + +--echo # +--echo # BLOB columns +--echo # + +--source type_blob.inc + +--let $col_definition = BLOB $default_col_opts +--source col_null.inc + +--let $col_definition = TINYBLOB $default_col_opts +--source col_null.inc + +--let $col_definition = MEDIUMBLOB $default_col_opts +--source col_null.inc + +--let $col_definition = LONGBLOB $default_col_opts +--source col_null.inc + +--echo # +--echo # BOOL columns +--echo # + +--source type_bool.inc +--let $col_definition = BOOL $default_col_opts +--let $col_default = '0' +--source col_null.inc + + +--echo # +--echo # CHAR columns +--echo # + +--source type_char.inc +--let $col_definition = CHAR $default_col_opts +--let $col_default = '_' +--source col_null.inc + +--echo # +--echo # VARCHAR columns +--echo # + + +--source type_varchar.inc +--let $col_definition = VARCHAR(64) $default_col_opts +--let $col_default = 'test default' +--source col_null.inc + + +--echo # +--echo # date and time columns +--echo # + +--source type_date_time.inc + +--let $col_definition = DATE $default_col_opts +--let $col_default = '2012-12-21' +--source col_null.inc + +--let $col_definition = DATETIME $default_col_opts +--let $col_default = '2012-12-21 12:21:12' +--source col_null.inc + +--let $col_definition = TIMESTAMP $default_col_opts +--let $col_default = '2012-12-21 12:21:12' +--source col_null.inc + +--let $col_definition = TIME $default_col_opts +--let $col_default = '12:21:12' +--source col_null.inc + +--let $col_definition = YEAR $default_col_opts +--let $col_default = '2012' +--source col_null.inc + +--let $col_definition = YEAR(2) $default_col_opts +--let $col_default = '12' +--source col_null.inc + + +--echo # +--echo # ENUM columns +--echo # + +--source type_enum.inc +--let $col_definition = ENUM('test1','test2','test3') $default_col_opts +--let $col_default = 'test2' +--source col_null.inc + +--echo # +--echo # Fixed point columns (NUMERIC, DECIMAL) +--echo # + +--source type_fixed.inc + +--let $col_definition = DECIMAL $default_col_opts +--let $col_default = 1.1 +--source col_null.inc + +--let $col_definition = NUMERIC $default_col_opts +--let $col_default = 0 +--source col_null.inc + +--echo # +--echo # Floating point columns (FLOAT, DOUBLE) +--echo # + +--source type_float.inc + +--let $col_definition = FLOAT $default_col_opts +--let $col_default = 1.1 +--source col_null.inc + +--let $col_definition = DOUBLE $default_col_opts +--let $col_default = 0 +--source col_null.inc + +--echo # +--echo # INT columns +--echo # + +--source type_int.inc + +--let $col_definition = INT $default_col_opts +--let $col_default = 2147483647 +--source col_null.inc + +--let $col_definition = TINYINT $default_col_opts +--let $col_default = 127 +--source col_null.inc + +--let $col_definition = SMALLINT $default_col_opts +--let $col_default = 0 +--source col_null.inc + +--let $col_definition = MEDIUMINT $default_col_opts +--let $col_default = 1 +--source col_null.inc + +--let $col_definition = BIGINT $default_col_opts +--let $col_default = 9223372036854775807 +--source col_null.inc + +--echo # +--echo # SET columns +--echo # + +--source type_set.inc +--let $col_definition = SET('test1','test2','test3') $default_col_opts +--let $col_default = 'test2,test3' +--source col_null.inc + + +--echo # +--echo # TEXT columns +--echo # + +--source type_text.inc + +--let $col_definition = TEXT $default_col_opts +--source col_null.inc + +--let $col_definition = TINYTEXT $default_col_opts +--source col_null.inc + +--let $col_definition = MEDIUMTEXT $default_col_opts +--source col_null.inc + +--let $col_definition = LONGTEXT $default_col_opts +--source col_null.inc + + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/col_opt_unsigned.result b/mysql-test/suite/storage_engine/col_opt_unsigned.result new file mode 100644 index 00000000000..a68aa48ee79 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_unsigned.result @@ -0,0 +1,697 @@ +# +# Fixed point columns (NUMERIC, DECIMAL) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DECIMAL UNSIGNED , +d0 DECIMAL(0) UNSIGNED , +d1_1 DECIMAL(1,1) UNSIGNED , +d10_2 DECIMAL(10,2) UNSIGNED , +d60_10 DECIMAL(60,10) UNSIGNED , +n NUMERIC UNSIGNED , +n0_0 NUMERIC(0,0) UNSIGNED , +n1 NUMERIC(1) UNSIGNED , +n20_4 NUMERIC(20,4) UNSIGNED , +n65_4 NUMERIC(65,4) UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d decimal(10,0) unsigned # # # +d0 decimal(10,0) unsigned # # # +d1_1 decimal(1,1) unsigned # # # +d10_2 decimal(10,2) unsigned # # # +d60_10 decimal(60,10) unsigned # # # +n decimal(10,0) unsigned # # # +n0_0 decimal(10,0) unsigned # # # +n1 decimal(1,0) unsigned # # # +n20_4 decimal(20,4) unsigned # # # +n65_4 decimal(65,4) unsigned # # # +INSERT INTO t1 VALUES (100,123456,0.3,40000.25,123456789123456789.10001,1024,7000.0,8.0,999999.9,9223372036854775807); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (9999999999.0,9999999999.0,0.9,99999999.99,99999999999999999999999999999999999999999999999999.9999999999,9999999999.0,9999999999.0,9.0,9999999999999999.9999,9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (-100,-123456,-0.3,-40000.25,-123456789123456789.10001,-1024,-7000.0,-8.0,-999999.9,-9223372036854775807); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +INSERT INTO t1 VALUES (-9999999999.0,-9999999999.0,-0.9,-99999999.99,-99999999999999999999999999999999999999999999999999.9999999999,-9999999999.0,-9999999999.0,-9.0,-9999999999999999.9999,-9999999999999999999999999999999999999999999999999999999999999.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +SELECT * FROM t1 WHERE n20_4 = 9999999999999999.9999 OR d < 100; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 SELECT n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4 FROM t1 WHERE n65_4 = ( SELECT MAX(n65_4) FROM t1 ); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (10000000000.0,10000000000.0,1.1,100000000.99,100000000000000000000000000000000000000000000000000.0,10000000000.0,10000000000.0,10.0,10000000000000000.9999,10000000000000000000000000000000000000000000000000000000000000.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (9999999999.1,9999999999.1,1.9,99999999.001,99999999999999999999999999999999999999999999999999.99999999991,9999999999.1,9999999999.1,9.1,9999999999999999.00001,9999999999999999999999999999999999999999999999999999999999999.11111); +Warnings: +Note 1265 Data truncated for column 'd' at row 1 +Note 1265 Data truncated for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Note 1265 Data truncated for column 'd10_2' at row 1 +Note 1265 Data truncated for column 'd60_10' at row 1 +Note 1265 Data truncated for column 'n' at row 1 +Note 1265 Data truncated for column 'n0_0' at row 1 +Note 1265 Data truncated for column 'n1' at row 1 +Note 1265 Data truncated for column 'n20_4' at row 1 +Note 1265 Data truncated for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +0 0 0.0 0.00 0.0000000000 0 0 0 0.0000 0.0000 +100 123456 0.3 40000.25 123456789123456789.1000100000 1024 7000 8 999999.9000 9223372036854775807.0000 +9999999999 9999999999 0.9 99999999.00 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.0000 9999999999999999999999999999999999999999999999999999999999999.1111 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +ALTER TABLE t1 ADD COLUMN n66 NUMERIC(66); +ERROR 42000: Too big precision 66 specified for 'n66'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(66,6); +ERROR 42000: Too big precision 66 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(66,66); +ERROR 42000: Too big scale 66 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL UNSIGNED , +b NUMERIC UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a decimal(10,0) unsigned # # # # +b decimal(10,0) unsigned # # # # +INSERT INTO t1 (a,b) VALUES (1.0,-1.0); +Warnings: +Warning 1264 Out of range value for column 'b' at row 1 +INSERT INTO t1 (a,b) VALUES (-100,100); +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT * FROM t1; +a b +0 100 +1 0 +DROP TABLE t1; +# +# Floating point columns (FLOAT, DOUBLE) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f FLOAT UNSIGNED , +f0 FLOAT(0) UNSIGNED , +r1_1 REAL(1,1) UNSIGNED , +f23_0 FLOAT(23) UNSIGNED , +f20_3 FLOAT(20,3) UNSIGNED , +d DOUBLE UNSIGNED , +d1_0 DOUBLE(1,0) UNSIGNED , +d10_10 DOUBLE PRECISION (10,10) UNSIGNED , +d53 DOUBLE(53,0) UNSIGNED , +d53_10 DOUBLE(53,10) UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +f float unsigned # # # +f0 float unsigned # # # +r1_1 double(1,1) unsigned # # # +f23_0 float unsigned # # # +f20_3 float(20,3) unsigned # # # +d double unsigned # # # +d1_0 double(1,0) unsigned # # # +d10_10 double(10,10) unsigned # # # +d53 double(53,0) unsigned # # # +d53_10 double(53,10) unsigned # # # +INSERT INTO t1 VALUES (12345.12345,12345.12345,0.9,123456789.123,56789.987,11111111.111,8.0,0.0123456789,1234566789123456789,99999999999999999.99999999); +SELECT * FROM t1; +f 12345.1 +d 11111111.111 +d10_10 0.0123456789 +d1_0 8 +d53 1234566789123456800 +d53_10 100000000000000000.0000000000 +f0 12345.1 +f20_3 56789.988 +f23_0 123457000 +r1_1 0.9 +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES ( +99999999999999999999999999999999999999, +99999999999999999999999999999999999999.9999999999999999, +0.9, +99999999999999999999999999999999999999.9, +99999999999999999.999, +999999999999999999999999999999999999999999999999999999999999999999999999999999999, +9, +0.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 11111111.111 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 8 +d1_0 9 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 1e38 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES (-999999999999999999999999,-99999999999.999999999999,-0.9,-999.99999999999999999999,-99999999999999999.999,-999999999999999999999999999999999999999999999999999999999999-0.999,-9,-.9999999999,-999999999999999999999999999999.99999999999999999999999,-9999999999999999999999999999999999999999999.9999999999); +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 0 +d 11111111.111 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d53 0 +d53 0 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 0 +f 1e38 +f0 0 +f0 0 +f0 12345.1 +f0 1e38 +f20_3 0.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +SELECT MAX(f), MAX(f0), MAX(r1_1), MAX(f23_0), MAX(f20_3), MAX(d), MAX(d1_0), MAX(d10_10), MAX(d53), MAX(d53_10) FROM t1; +MAX(f) 9.999999680285692e37 +MAX(d) 1e81 +MAX(d10_10) 0.9999999999 +MAX(d1_0) 9 +MAX(d53) 100000000000000000000000000000000000000000000000000000 +MAX(d53_10) 10000000000000000000000000000000000000000000.0000000000 +MAX(f0) 9.999999680285692e37 +MAX(f20_3) 99999998430674940.000 +MAX(f23_0) 9.999999680285692e37 +MAX(r1_1) 0.9 +INSERT INTO t1 SELECT d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10 FROM t1 ORDER BY d53_10 DESC LIMIT 1; +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 0 +d 11111111.111 +d 1e43 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d53 0 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 0 +f 1e38 +f 3.40282e38 +f0 0 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f20_3 0.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES ( +999999999999999999999999999999999999999, +999999999999999999999999999999999999999.9999999999999999, +1.9, +999999999999999999999999999999999999999.9, +999999999999999999.999, +9999999999999999999999999999999999999999999999999999999999999999999999999999999999, +99, +1.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated. +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 12345.1 +d 0 +d 0 +d 11111111.111 +d 1e43 +d 1e65 +d 1e81 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d1_0 9 +d53 0 +d53 0 +d53 10000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 1234566789123456800 +d53_10 0.0000000000 +d53_10 0.0000000000 +d53_10 100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 0 +f 0 +f 1e38 +f 3.40282e38 +f 3.40282e38 +f0 0 +f0 0 +f0 12345.1 +f0 1e38 +f0 3.40282e38 +f0 3.40282e38 +f20_3 0.000 +f20_3 0.000 +f20_3 56789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 0 +f23_0 0 +f23_0 123457000 +f23_0 1e38 +f23_0 3.40282e38 +f23_0 3.40282e38 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +ALTER TABLE t1 ADD COLUMN d0_0 DOUBLE(0,0); +ERROR 42000: Display width out of range for 'd0_0' (max = 255) +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(256,1); +ERROR 42000: Too big precision 256 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(40,35); +ERROR 42000: Too big scale 35 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +CREATE TABLE t1 (a DOUBLE UNSIGNED , +b FLOAT UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a double unsigned # # # # +b float unsigned # # # # +INSERT INTO t1 (a,b) VALUES (1.0,-1.0); +Warnings: +Warning 1264 Out of range value for column 'b' at row 1 +INSERT INTO t1 (a,b) VALUES (-100,100); +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT * FROM t1; +a b +0 100 +1 0 +DROP TABLE t1; +# +# INT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT UNSIGNED , +i0 INT(0) UNSIGNED , +i1 INT(1) UNSIGNED , +i20 INT(20) UNSIGNED , +t TINYINT UNSIGNED , +t0 TINYINT(0) UNSIGNED , +t1 TINYINT(1) UNSIGNED , +t20 TINYINT(20) UNSIGNED , +s SMALLINT UNSIGNED , +s0 SMALLINT(0) UNSIGNED , +s1 SMALLINT(1) UNSIGNED , +s20 SMALLINT(20) UNSIGNED , +m MEDIUMINT UNSIGNED , +m0 MEDIUMINT(0) UNSIGNED , +m1 MEDIUMINT(1) UNSIGNED , +m20 MEDIUMINT(20) UNSIGNED , +b BIGINT UNSIGNED , +b0 BIGINT(0) UNSIGNED , +b1 BIGINT(1) UNSIGNED , +b20 BIGINT(20) UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +i int(10) unsigned # # # +i0 int(10) unsigned # # # +i1 int(1) unsigned # # # +i20 int(20) unsigned # # # +t tinyint(3) unsigned # # # +t0 tinyint(3) unsigned # # # +t1 tinyint(1) unsigned # # # +t20 tinyint(20) unsigned # # # +s smallint(5) unsigned # # # +s0 smallint(5) unsigned # # # +s1 smallint(1) unsigned # # # +s20 smallint(20) unsigned # # # +m mediumint(8) unsigned # # # +m0 mediumint(8) unsigned # # # +m1 mediumint(1) unsigned # # # +m20 mediumint(20) unsigned # # # +b bigint(20) unsigned # # # +b0 bigint(20) unsigned # # # +b1 bigint(1) unsigned # # # +b20 bigint(20) unsigned # # # +INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (2147483647,2147483647,2147483647,2147483647,127,127,127,127,32767,32767,32767,32767,8388607,8388607,8388607,8388607,9223372036854775807,9223372036854775807,9223372036854775807,9223372036854775807); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +INSERT INTO t1 VALUES (-2147483648,-2147483648,-2147483648,-2147483648,-128,-128,-128,-128,-32768,-32768,-32768,-32768,-8388608,-8388608,-8388608,-8388608,-9223372036854775808,-9223372036854775808,-9223372036854775808,-9223372036854775808); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967295,4294967295,4294967295,4294967295,255,255,255,255,65535,65535,65535,65535,16777215,16777215,16777215,16777215,18446744073709551615,18446744073709551615,18446744073709551615,18446744073709551615); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +INSERT INTO t1 VALUES (-2147483649,-2147483649,-2147483649,-2147483649,-129,-129,-129,-129,-32769,-32769,-32769,-32769,-8388609,-8388609,-8388609,-8388609,-9223372036854775809,-9223372036854775809,-9223372036854775809,-9223372036854775809); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967296,4294967296,4294967296,4294967296,256,256,256,256,65536,65536,65536,65536,16777216,16777216,16777216,16777216,18446744073709551616,18446744073709551616,18446744073709551616,18446744073709551616); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'i' at row 2 +Warning 1264 Out of range value for column 'i0' at row 2 +Warning 1264 Out of range value for column 'i1' at row 2 +Warning 1264 Out of range value for column 'i20' at row 2 +Warning 1264 Out of range value for column 't' at row 2 +Warning 1264 Out of range value for column 't0' at row 2 +Warning 1264 Out of range value for column 't1' at row 2 +Warning 1264 Out of range value for column 't20' at row 2 +Warning 1264 Out of range value for column 's' at row 2 +Warning 1264 Out of range value for column 's0' at row 2 +Warning 1264 Out of range value for column 's1' at row 2 +Warning 1264 Out of range value for column 's20' at row 2 +Warning 1264 Out of range value for column 'm' at row 2 +Warning 1264 Out of range value for column 'm0' at row 2 +Warning 1264 Out of range value for column 'm1' at row 2 +Warning 1264 Out of range value for column 'm20' at row 2 +Warning 1264 Out of range value for column 'i' at row 3 +Warning 1264 Out of range value for column 'i0' at row 3 +Warning 1264 Out of range value for column 'i1' at row 3 +Warning 1264 Out of range value for column 'i20' at row 3 +Warning 1264 Out of range value for column 't' at row 3 +Warning 1264 Out of range value for column 't0' at row 3 +Warning 1264 Out of range value for column 't1' at row 3 +Warning 1264 Out of range value for column 't20' at row 3 +Warning 1264 Out of range value for column 's' at row 3 +Warning 1264 Out of range value for column 's0' at row 3 +Warning 1264 Out of range value for column 's1' at row 3 +Warning 1264 Out of range value for column 's20' at row 3 +Warning 1264 Out of range value for column 'm' at row 3 +Warning 1264 Out of range value for column 'm0' at row 3 +Warning 1264 Out of range value for column 'm1' at row 3 +Warning 1264 Out of range value for column 'm20' at row 3 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +2147483647 2147483647 2147483647 2147483647 127 127 127 127 32767 32767 32767 32767 8388607 8388607 8388607 8388607 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 4294967295 255 255 255 255 65535 65535 65535 65535 16777215 16777215 16777215 16777215 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 +ALTER TABLE t1 ADD COLUMN i257 INT(257); +ERROR 42000: Display width out of range for 'i257' (max = 255) +DROP TABLE t1; +CREATE TABLE t1 (t TINYINT UNSIGNED , +s SMALLINT UNSIGNED , +m MEDIUMINT UNSIGNED , +i INT UNSIGNED , +b BIGINT UNSIGNED +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +t tinyint(3) unsigned # # # # +s smallint(5) unsigned # # # # +m mediumint(8) unsigned # # # # +i int(10) unsigned # # # # +b bigint(20) unsigned # # # # +INSERT INTO t1 (t,s,m,i,b) VALUES (255,65535,16777215,4294967295,18446744073709551615); +INSERT INTO t1 (t,s,m,i,b) VALUES (-1,-1,-1,-1,-1); +Warnings: +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +SELECT * FROM t1; +t s m i b +0 0 0 0 0 +255 65535 16777215 4294967295 18446744073709551615 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/col_opt_unsigned.test b/mysql-test/suite/storage_engine/col_opt_unsigned.test new file mode 100644 index 00000000000..e9d4566de7f --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_unsigned.test @@ -0,0 +1,95 @@ +# +# UNSIGNED column attribute +# + +let $extra_type_opts = UNSIGNED; + +--source have_engine.inc + +--echo # +--echo # Fixed point columns (NUMERIC, DECIMAL) +--echo # + +--source type_fixed.inc +let $create_definition = + a DECIMAL $col_opts, + b NUMERIC $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Fixed point types or UNSIGNED columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (a,b) VALUES (1.0,-1.0); + INSERT INTO t1 (a,b) VALUES (-100,100); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +--echo # +--echo # Floating point columns (FLOAT, DOUBLE) +--echo # + +--source type_float.inc +let $create_definition = + a DOUBLE $col_opts, + b FLOAT $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Floating point types or UNSIGNED columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (a,b) VALUES (1.0,-1.0); + INSERT INTO t1 (a,b) VALUES (-100,100); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; +} + +--echo # +--echo # INT columns +--echo # + +--source type_int.inc +let $create_definition = + t TINYINT $col_opts, + s SMALLINT $col_opts, + m MEDIUMINT $col_opts, + i INT $col_opts, + b BIGINT $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = INT types or UNSIGNED columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (t,s,m,i,b) VALUES (255,65535,16777215,4294967295,18446744073709551615); + INSERT INTO t1 (t,s,m,i,b) VALUES (-1,-1,-1,-1,-1); + --sorted_result + SELECT * FROM t1; + DROP TABLE t1; + +} + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/col_opt_zerofill.result b/mysql-test/suite/storage_engine/col_opt_zerofill.result new file mode 100644 index 00000000000..c2445c5bbc7 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_zerofill.result @@ -0,0 +1,679 @@ +# +# Fixed point columns (NUMERIC, DECIMAL) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (d DECIMAL ZEROFILL , +d0 DECIMAL(0) ZEROFILL , +d1_1 DECIMAL(1,1) ZEROFILL , +d10_2 DECIMAL(10,2) ZEROFILL , +d60_10 DECIMAL(60,10) ZEROFILL , +n NUMERIC ZEROFILL , +n0_0 NUMERIC(0,0) ZEROFILL , +n1 NUMERIC(1) ZEROFILL , +n20_4 NUMERIC(20,4) ZEROFILL , +n65_4 NUMERIC(65,4) ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +d decimal(10,0) unsigned zerofill # # # +d0 decimal(10,0) unsigned zerofill # # # +d1_1 decimal(1,1) unsigned zerofill # # # +d10_2 decimal(10,2) unsigned zerofill # # # +d60_10 decimal(60,10) unsigned zerofill # # # +n decimal(10,0) unsigned zerofill # # # +n0_0 decimal(10,0) unsigned zerofill # # # +n1 decimal(1,0) unsigned zerofill # # # +n20_4 decimal(20,4) unsigned zerofill # # # +n65_4 decimal(65,4) unsigned zerofill # # # +INSERT INTO t1 VALUES (100,123456,0.3,40000.25,123456789123456789.10001,1024,7000.0,8.0,999999.9,9223372036854775807); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (9999999999.0,9999999999.0,0.9,99999999.99,99999999999999999999999999999999999999999999999999.9999999999,9999999999.0,9999999999.0,9.0,9999999999999999.9999,9999999999999999999999999999999999999999999999999999999999999.9999); +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000100 0000123456 0.3 00040000.25 00000000000000000000000000000000123456789123456789.1000100000 0000001024 0000007000 8 0000000000999999.9000 0000000000000000000000000000000000000000009223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (-100,-123456,-0.3,-40000.25,-123456789123456789.10001,-1024,-7000.0,-8.0,-999999.9,-9223372036854775807); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +INSERT INTO t1 VALUES (-9999999999.0,-9999999999.0,-0.9,-99999999.99,-99999999999999999999999999999999999999999999999999.9999999999,-9999999999.0,-9999999999.0,-9.0,-9999999999999999.9999,-9999999999999999999999999999999999999999999999999999999999999.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000100 0000123456 0.3 00040000.25 00000000000000000000000000000000123456789123456789.1000100000 0000001024 0000007000 8 0000000000999999.9000 0000000000000000000000000000000000000000009223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +SELECT * FROM t1 WHERE n20_4 = 9999999999999999.9999 OR d < 100; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 SELECT n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4, n65_4 FROM t1 WHERE n65_4 = ( SELECT MAX(n65_4) FROM t1 ); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000100 0000123456 0.3 00040000.25 00000000000000000000000000000000123456789123456789.1000100000 0000001024 0000007000 8 0000000000999999.9000 0000000000000000000000000000000000000000009223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (10000000000.0,10000000000.0,1.1,100000000.99,100000000000000000000000000000000000000000000000000.0,10000000000.0,10000000000.0,10.0,10000000000000000.9999,10000000000000000000000000000000000000000000000000000000000000.9999); +Warnings: +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Warning 1264 Out of range value for column 'd10_2' at row 1 +Warning 1264 Out of range value for column 'd60_10' at row 1 +Warning 1264 Out of range value for column 'n' at row 1 +Warning 1264 Out of range value for column 'n0_0' at row 1 +Warning 1264 Out of range value for column 'n1' at row 1 +Warning 1264 Out of range value for column 'n20_4' at row 1 +Warning 1264 Out of range value for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000100 0000123456 0.3 00040000.25 00000000000000000000000000000000123456789123456789.1000100000 0000001024 0000007000 8 0000000000999999.9000 0000000000000000000000000000000000000000009223372036854775807.0000 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +INSERT INTO t1 VALUES (9999999999.1,9999999999.1,1.9,99999999.001,99999999999999999999999999999999999999999999999999.99999999991,9999999999.1,9999999999.1,9.1,9999999999999999.00001,9999999999999999999999999999999999999999999999999999999999999.11111); +Warnings: +Note 1265 Data truncated for column 'd' at row 1 +Note 1265 Data truncated for column 'd0' at row 1 +Warning 1264 Out of range value for column 'd1_1' at row 1 +Note 1265 Data truncated for column 'd10_2' at row 1 +Note 1265 Data truncated for column 'd60_10' at row 1 +Note 1265 Data truncated for column 'n' at row 1 +Note 1265 Data truncated for column 'n0_0' at row 1 +Note 1265 Data truncated for column 'n1' at row 1 +Note 1265 Data truncated for column 'n20_4' at row 1 +Note 1265 Data truncated for column 'n65_4' at row 1 +SELECT * FROM t1; +d d0 d1_1 d10_2 d60_10 n n0_0 n1 n20_4 n65_4 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000000 0000000000 0.0 00000000.00 00000000000000000000000000000000000000000000000000.0000000000 0000000000 0000000000 0 0000000000000000.0000 0000000000000000000000000000000000000000000000000000000000000.0000 +0000000100 0000123456 0.3 00040000.25 00000000000000000000000000000000123456789123456789.1000100000 0000001024 0000007000 8 0000000000999999.9000 0000000000000000000000000000000000000000009223372036854775807.0000 +9999999999 9999999999 0.9 99999999.00 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.0000 9999999999999999999999999999999999999999999999999999999999999.1111 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +9999999999 9999999999 0.9 99999999.99 99999999999999999999999999999999999999999999999999.9999999999 9999999999 9999999999 9 9999999999999999.9999 9999999999999999999999999999999999999999999999999999999999999.9999 +ALTER TABLE t1 ADD COLUMN n66 NUMERIC(66); +ERROR 42000: Too big precision 66 specified for 'n66'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(66,6); +ERROR 42000: Too big precision 66 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(66,66); +ERROR 42000: Too big scale 66 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL ZEROFILL , +b NUMERIC ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a decimal(10,0) unsigned zerofill # # # # +b decimal(10,0) unsigned zerofill # # # # +INSERT INTO t1 (a,b) VALUES (1.1,1234); +Warnings: +Note 1265 Data truncated for column 'a' at row 1 +SELECT * FROM t1; +a b +0000000001 0000001234 +DROP TABLE t1; +# +# Floating point columns (FLOAT, DOUBLE) +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f FLOAT ZEROFILL , +f0 FLOAT(0) ZEROFILL , +r1_1 REAL(1,1) ZEROFILL , +f23_0 FLOAT(23) ZEROFILL , +f20_3 FLOAT(20,3) ZEROFILL , +d DOUBLE ZEROFILL , +d1_0 DOUBLE(1,0) ZEROFILL , +d10_10 DOUBLE PRECISION (10,10) ZEROFILL , +d53 DOUBLE(53,0) ZEROFILL , +d53_10 DOUBLE(53,10) ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +f float unsigned zerofill # # # +f0 float unsigned zerofill # # # +r1_1 double(1,1) unsigned zerofill # # # +f23_0 float unsigned zerofill # # # +f20_3 float(20,3) unsigned zerofill # # # +d double unsigned zerofill # # # +d1_0 double(1,0) unsigned zerofill # # # +d10_10 double(10,10) unsigned zerofill # # # +d53 double(53,0) unsigned zerofill # # # +d53_10 double(53,10) unsigned zerofill # # # +INSERT INTO t1 VALUES (12345.12345,12345.12345,0.9,123456789.123,56789.987,11111111.111,8.0,0.0123456789,1234566789123456789,99999999999999999.99999999); +SELECT * FROM t1; +f 0000012345.1 +d 000000000011111111.111 +d10_10 0.0123456789 +d1_0 8 +d53 00000000000000000000000000000000001234566789123456800 +d53_10 000000000000000000000000100000000000000000.0000000000 +f0 0000012345.1 +f20_3 0000000000056789.988 +f23_0 000123457000 +r1_1 0.9 +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES ( +99999999999999999999999999999999999999, +99999999999999999999999999999999999999.9999999999999999, +0.9, +99999999999999999999999999999999999999.9, +99999999999999999.999, +999999999999999999999999999999999999999999999999999999999999999999999999999999999, +9, +0.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 0000012345.1 +d 0000000000000000000000 +d 0000000000000000001e81 +d 000000000011111111.111 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 8 +d1_0 9 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000001234566789123456800 +d53 100000000000000000000000000000000000000000000000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 000000000000 +f 000000001e38 +f0 000000000000 +f0 000000001e38 +f0 0000012345.1 +f20_3 0000000000000000.000 +f20_3 0000000000056789.988 +f20_3 99999998430674940.000 +f23_0 000000000000 +f23_0 000000001e38 +f23_0 000123457000 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES (-999999999999999999999999,-99999999999.999999999999,-0.9,-999.99999999999999999999,-99999999999999999.999,-999999999999999999999999999999999999999999999999999999999999-0.999,-9,-.9999999999,-999999999999999999999999999999.99999999999999999999999,-9999999999999999999999999999999999999999999.9999999999); +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 0000012345.1 +d 0000000000000000000000 +d 0000000000000000000000 +d 0000000000000000001e81 +d 000000000011111111.111 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000001234566789123456800 +d53 100000000000000000000000000000000000000000000000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 000000000000 +f 000000000000 +f 000000001e38 +f0 000000000000 +f0 000000000000 +f0 000000001e38 +f0 0000012345.1 +f20_3 0000000000000000.000 +f20_3 0000000000000000.000 +f20_3 0000000000056789.988 +f20_3 99999998430674940.000 +f23_0 000000000000 +f23_0 000000000000 +f23_0 000000001e38 +f23_0 000123457000 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +SELECT MAX(f), MAX(f0), MAX(r1_1), MAX(f23_0), MAX(f20_3), MAX(d), MAX(d1_0), MAX(d10_10), MAX(d53), MAX(d53_10) FROM t1; +MAX(f) 9.999999680285692e37 +MAX(d) 1e81 +MAX(d10_10) 0.9999999999 +MAX(d1_0) 9 +MAX(d53) 100000000000000000000000000000000000000000000000000000 +MAX(d53_10) 10000000000000000000000000000000000000000000.0000000000 +MAX(f0) 9.999999680285692e37 +MAX(f20_3) 99999998430674940.000 +MAX(f23_0) 9.999999680285692e37 +MAX(r1_1) 0.9 +INSERT INTO t1 SELECT d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10, d53_10 FROM t1 ORDER BY d53_10 DESC LIMIT 1; +Warnings: +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +SELECT * FROM t1; +f 0000012345.1 +d 0000000000000000000000 +d 0000000000000000000000 +d 0000000000000000001e43 +d 0000000000000000001e81 +d 000000000011111111.111 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000001234566789123456800 +d53 00000000010000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 000000000000 +f 000000000000 +f 000000001e38 +f 003.40282e38 +f0 000000000000 +f0 000000000000 +f0 000000001e38 +f0 0000012345.1 +f0 003.40282e38 +f20_3 0000000000000000.000 +f20_3 0000000000000000.000 +f20_3 0000000000056789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 000000000000 +f23_0 000000000000 +f23_0 000000001e38 +f23_0 000123457000 +f23_0 003.40282e38 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +INSERT INTO t1 VALUES ( +999999999999999999999999999999999999999, +999999999999999999999999999999999999999.9999999999999999, +1.9, +999999999999999999999999999999999999999.9, +999999999999999999.999, +9999999999999999999999999999999999999999999999999999999999999999999999999999999999, +99, +1.9999999999, +1999999999999999999999999999999999999999999999999999999, +19999999999999999999999999999999999999999999.9999999999 +); +Warnings: +Warning 1916 Got overflow when converting '' to DECIMAL. Value truncated. +Warning 1264 Out of range value for column 'f' at row 1 +Warning 1264 Out of range value for column 'f0' at row 1 +Warning 1264 Out of range value for column 'r1_1' at row 1 +Warning 1264 Out of range value for column 'f23_0' at row 1 +Warning 1264 Out of range value for column 'f20_3' at row 1 +Warning 1264 Out of range value for column 'd1_0' at row 1 +Warning 1264 Out of range value for column 'd10_10' at row 1 +Warning 1264 Out of range value for column 'd53' at row 1 +Warning 1264 Out of range value for column 'd53_10' at row 1 +SELECT * FROM t1; +f 0000012345.1 +d 0000000000000000000000 +d 0000000000000000000000 +d 0000000000000000001e43 +d 0000000000000000001e65 +d 0000000000000000001e81 +d 000000000011111111.111 +d10_10 0.0000000000 +d10_10 0.0000000000 +d10_10 0.0123456789 +d10_10 0.9999999999 +d10_10 0.9999999999 +d10_10 10000000000000000000000000000000000000000000.0000000000 +d1_0 0 +d1_0 0 +d1_0 8 +d1_0 9 +d1_0 9 +d1_0 9 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000000000000000000000000 +d53 00000000000000000000000000000000001234566789123456800 +d53 00000000010000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53 100000000000000000000000000000000000000000000000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000000000000000000000.0000000000 +d53_10 000000000000000000000000100000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +d53_10 10000000000000000000000000000000000000000000.0000000000 +f 000000000000 +f 000000000000 +f 000000001e38 +f 003.40282e38 +f 003.40282e38 +f0 000000000000 +f0 000000000000 +f0 000000001e38 +f0 0000012345.1 +f0 003.40282e38 +f0 003.40282e38 +f20_3 0000000000000000.000 +f20_3 0000000000000000.000 +f20_3 0000000000056789.988 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f20_3 99999998430674940.000 +f23_0 000000000000 +f23_0 000000000000 +f23_0 000000001e38 +f23_0 000123457000 +f23_0 003.40282e38 +f23_0 003.40282e38 +r1_1 0.0 +r1_1 0.0 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +r1_1 0.9 +ALTER TABLE t1 ADD COLUMN d0_0 DOUBLE(0,0); +ERROR 42000: Display width out of range for 'd0_0' (max = 255) +ALTER TABLE t1 ADD COLUMN n66_6 DECIMAL(256,1); +ERROR 42000: Too big precision 256 specified for 'n66_6'. Maximum is 65. +ALTER TABLE t1 ADD COLUMN n66_66 DECIMAL(40,35); +ERROR 42000: Too big scale 35 specified for 'n66_66'. Maximum is 30. +DROP TABLE t1; +CREATE TABLE t1 (a DOUBLE ZEROFILL , +b FLOAT ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +a double unsigned zerofill # # # # +b float unsigned zerofill # # # # +INSERT INTO t1 (a,b) VALUES (1,1234.5); +SELECT * FROM t1; +a b +0000000000000000000001 0000001234.5 +DROP TABLE t1; +# +# INT columns +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT ZEROFILL , +i0 INT(0) ZEROFILL , +i1 INT(1) ZEROFILL , +i20 INT(20) ZEROFILL , +t TINYINT ZEROFILL , +t0 TINYINT(0) ZEROFILL , +t1 TINYINT(1) ZEROFILL , +t20 TINYINT(20) ZEROFILL , +s SMALLINT ZEROFILL , +s0 SMALLINT(0) ZEROFILL , +s1 SMALLINT(1) ZEROFILL , +s20 SMALLINT(20) ZEROFILL , +m MEDIUMINT ZEROFILL , +m0 MEDIUMINT(0) ZEROFILL , +m1 MEDIUMINT(1) ZEROFILL , +m20 MEDIUMINT(20) ZEROFILL , +b BIGINT ZEROFILL , +b0 BIGINT(0) ZEROFILL , +b1 BIGINT(1) ZEROFILL , +b20 BIGINT(20) ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +i int(10) unsigned zerofill # # # +i0 int(10) unsigned zerofill # # # +i1 int(1) unsigned zerofill # # # +i20 int(20) unsigned zerofill # # # +t tinyint(3) unsigned zerofill # # # +t0 tinyint(3) unsigned zerofill # # # +t1 tinyint(1) unsigned zerofill # # # +t20 tinyint(20) unsigned zerofill # # # +s smallint(5) unsigned zerofill # # # +s0 smallint(5) unsigned zerofill # # # +s1 smallint(1) unsigned zerofill # # # +s20 smallint(20) unsigned zerofill # # # +m mediumint(8) unsigned zerofill # # # +m0 mediumint(8) unsigned zerofill # # # +m1 mediumint(1) unsigned zerofill # # # +m20 mediumint(20) unsigned zerofill # # # +b bigint(20) unsigned zerofill # # # +b0 bigint(20) unsigned zerofill # # # +b1 bigint(1) unsigned zerofill # # # +b20 bigint(20) unsigned zerofill # # # +INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); +INSERT INTO t1 VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); +INSERT INTO t1 VALUES (2147483647,2147483647,2147483647,2147483647,127,127,127,127,32767,32767,32767,32767,8388607,8388607,8388607,8388607,9223372036854775807,9223372036854775807,9223372036854775807,9223372036854775807); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000001 0000000002 3 00000000000000000004 005 006 7 00000000000000000008 00009 00010 11 00000000000000000012 00000013 00000014 15 00000000000000000016 00000000000000000017 00000000000000000018 19 00000000000000000020 +2147483647 2147483647 2147483647 00000000002147483647 127 127 127 00000000000000000127 32767 32767 32767 00000000000000032767 08388607 08388607 8388607 00000000000008388607 09223372036854775807 09223372036854775807 9223372036854775807 09223372036854775807 +INSERT INTO t1 VALUES (-2147483648,-2147483648,-2147483648,-2147483648,-128,-128,-128,-128,-32768,-32768,-32768,-32768,-8388608,-8388608,-8388608,-8388608,-9223372036854775808,-9223372036854775808,-9223372036854775808,-9223372036854775808); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967295,4294967295,4294967295,4294967295,255,255,255,255,65535,65535,65535,65535,16777215,16777215,16777215,16777215,18446744073709551615,18446744073709551615,18446744073709551615,18446744073709551615); +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000001 0000000002 3 00000000000000000004 005 006 7 00000000000000000008 00009 00010 11 00000000000000000012 00000013 00000014 15 00000000000000000016 00000000000000000017 00000000000000000018 19 00000000000000000020 +2147483647 2147483647 2147483647 00000000002147483647 127 127 127 00000000000000000127 32767 32767 32767 00000000000000032767 08388607 08388607 8388607 00000000000008388607 09223372036854775807 09223372036854775807 9223372036854775807 09223372036854775807 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +INSERT INTO t1 VALUES (-2147483649,-2147483649,-2147483649,-2147483649,-129,-129,-129,-129,-32769,-32769,-32769,-32769,-8388609,-8388609,-8388609,-8388609,-9223372036854775809,-9223372036854775809,-9223372036854775809,-9223372036854775809); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 VALUES (4294967296,4294967296,4294967296,4294967296,256,256,256,256,65536,65536,65536,65536,16777216,16777216,16777216,16777216,18446744073709551616,18446744073709551616,18446744073709551616,18446744073709551616); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'b' at row 1 +Warning 1264 Out of range value for column 'b0' at row 1 +Warning 1264 Out of range value for column 'b1' at row 1 +Warning 1264 Out of range value for column 'b20' at row 1 +INSERT INTO t1 SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615); +Warnings: +Warning 1264 Out of range value for column 'i' at row 1 +Warning 1264 Out of range value for column 'i0' at row 1 +Warning 1264 Out of range value for column 'i1' at row 1 +Warning 1264 Out of range value for column 'i20' at row 1 +Warning 1264 Out of range value for column 't' at row 1 +Warning 1264 Out of range value for column 't0' at row 1 +Warning 1264 Out of range value for column 't1' at row 1 +Warning 1264 Out of range value for column 't20' at row 1 +Warning 1264 Out of range value for column 's' at row 1 +Warning 1264 Out of range value for column 's0' at row 1 +Warning 1264 Out of range value for column 's1' at row 1 +Warning 1264 Out of range value for column 's20' at row 1 +Warning 1264 Out of range value for column 'm' at row 1 +Warning 1264 Out of range value for column 'm0' at row 1 +Warning 1264 Out of range value for column 'm1' at row 1 +Warning 1264 Out of range value for column 'm20' at row 1 +Warning 1264 Out of range value for column 'i' at row 2 +Warning 1264 Out of range value for column 'i0' at row 2 +Warning 1264 Out of range value for column 'i1' at row 2 +Warning 1264 Out of range value for column 'i20' at row 2 +Warning 1264 Out of range value for column 't' at row 2 +Warning 1264 Out of range value for column 't0' at row 2 +Warning 1264 Out of range value for column 't1' at row 2 +Warning 1264 Out of range value for column 't20' at row 2 +Warning 1264 Out of range value for column 's' at row 2 +Warning 1264 Out of range value for column 's0' at row 2 +Warning 1264 Out of range value for column 's1' at row 2 +Warning 1264 Out of range value for column 's20' at row 2 +Warning 1264 Out of range value for column 'm' at row 2 +Warning 1264 Out of range value for column 'm0' at row 2 +Warning 1264 Out of range value for column 'm1' at row 2 +Warning 1264 Out of range value for column 'm20' at row 2 +Warning 1264 Out of range value for column 'i' at row 3 +Warning 1264 Out of range value for column 'i0' at row 3 +Warning 1264 Out of range value for column 'i1' at row 3 +Warning 1264 Out of range value for column 'i20' at row 3 +Warning 1264 Out of range value for column 't' at row 3 +Warning 1264 Out of range value for column 't0' at row 3 +Warning 1264 Out of range value for column 't1' at row 3 +Warning 1264 Out of range value for column 't20' at row 3 +Warning 1264 Out of range value for column 's' at row 3 +Warning 1264 Out of range value for column 's0' at row 3 +Warning 1264 Out of range value for column 's1' at row 3 +Warning 1264 Out of range value for column 's20' at row 3 +Warning 1264 Out of range value for column 'm' at row 3 +Warning 1264 Out of range value for column 'm0' at row 3 +Warning 1264 Out of range value for column 'm1' at row 3 +Warning 1264 Out of range value for column 'm20' at row 3 +SELECT * FROM t1; +i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000000 0000000000 0 00000000000000000000 000 000 0 00000000000000000000 00000 00000 0 00000000000000000000 00000000 00000000 0 00000000000000000000 00000000000000000000 00000000000000000000 0 00000000000000000000 +0000000001 0000000002 3 00000000000000000004 005 006 7 00000000000000000008 00009 00010 11 00000000000000000012 00000013 00000014 15 00000000000000000016 00000000000000000017 00000000000000000018 19 00000000000000000020 +2147483647 2147483647 2147483647 00000000002147483647 127 127 127 00000000000000000127 32767 32767 32767 00000000000000032767 08388607 08388607 8388607 00000000000008388607 09223372036854775807 09223372036854775807 9223372036854775807 09223372036854775807 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 09223372036854775807 09223372036854775807 9223372036854775807 09223372036854775807 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +4294967295 4294967295 4294967295 00000000004294967295 255 255 255 00000000000000000255 65535 65535 65535 00000000000000065535 16777215 16777215 16777215 00000000000016777215 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 +ALTER TABLE t1 ADD COLUMN i257 INT(257); +ERROR 42000: Display width out of range for 'i257' (max = 255) +DROP TABLE t1; +CREATE TABLE t1 (t TINYINT ZEROFILL , +s SMALLINT ZEROFILL , +m MEDIUMINT ZEROFILL , +i INT ZEROFILL , +b BIGINT ZEROFILL +) ENGINE= ; +SHOW COLUMNS IN t1; +Field Type Null Key Default Extra +t tinyint(3) unsigned zerofill # # # # +s smallint(5) unsigned zerofill # # # # +m mediumint(8) unsigned zerofill # # # # +i int(10) unsigned zerofill # # # # +b bigint(20) unsigned zerofill # # # # +INSERT INTO t1 (t,s,m,i,b) VALUES (1,10,100,1000,0); +SELECT * FROM t1; +t s m i b +001 00010 00000100 0000001000 00000000000000000000 +DROP TABLE t1; diff --git a/mysql-test/suite/storage_engine/col_opt_zerofill.test b/mysql-test/suite/storage_engine/col_opt_zerofill.test new file mode 100644 index 00000000000..83b7dcf28c1 --- /dev/null +++ b/mysql-test/suite/storage_engine/col_opt_zerofill.test @@ -0,0 +1,88 @@ +# +# ZEROFILL column attribute +# + +let $extra_type_opts = ZEROFILL; + +--source have_engine.inc + +--echo # +--echo # Fixed point columns (NUMERIC, DECIMAL) +--echo # + +--source type_fixed.inc +let $create_definition = + a DECIMAL $col_opts, + b NUMERIC $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Fixed point types or ZEROFILL columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (a,b) VALUES (1.1,1234); + SELECT * FROM t1; + DROP TABLE t1; +} + +--echo # +--echo # Floating point columns (FLOAT, DOUBLE) +--echo # + +--source type_float.inc +let $create_definition = + a DOUBLE $col_opts, + b FLOAT $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = Floating point types or ZEROFILL columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (a,b) VALUES (1,1234.5); + SELECT * FROM t1; + DROP TABLE t1; +} + +--echo # +--echo # INT columns +--echo # + +--source type_int.inc +let $create_definition = + t TINYINT $col_opts, + s SMALLINT $col_opts, + m MEDIUMINT $col_opts, + i INT $col_opts, + b BIGINT $col_opts +; +--source create_table.inc +if ($mysql_errname) +{ + --let $functionality = INT types or UNSIGNED columns + --source unexpected_result.inc +} +if (!$mysql_errname) +{ + --replace_column 3 # 4 # 5 # 6 # + SHOW COLUMNS IN t1; + + INSERT INTO t1 (t,s,m,i,b) VALUES (1,10,100,1000,0); + SELECT * FROM t1; + DROP TABLE t1; +} + +--source cleanup_engine.inc + diff --git a/mysql-test/suite/storage_engine/create_table.inc b/mysql-test/suite/storage_engine/create_table.inc new file mode 100644 index 00000000000..9a1cba5100a --- /dev/null +++ b/mysql-test/suite/storage_engine/create_table.inc @@ -0,0 +1,174 @@ +################################## +# +# This include file will be used for all CREATE TABLE statements in the suite. +# If you need to add additional steps or change the logic, copy the file +# to storage//mysql-test/storage_engine/ folder and modify it there. +# +################## +# +# Parameters: +# +# --let $create_definition = # optional, default t1 +# --let $table_options =
# optional, default based on define_engine.inc +# --let $partition_options = # optional, default none +# --let $as_select =
# optional, default t1 +# --let $error_codes = # optional, default 0 +# --let $online = [0|1] # optional, default 0 (1 adds ONLINE) +# --let $rename_to = # optional, default empty. +# # If set, means we are running RENAME TO, then alter definition is ignored +# +# Usage examples: +# +# --let $alter_definition = ADD COLUMN b $char_col DEFAULT '' +# + +--let $child_alter_definition = $alter_definition + +if ($rename_to) +{ + --let $alter_definition = RENAME TO $rename_to + --let $child_alter_definition = RENAME TO mrg.$rename_to +} + +if (!$alter_definition) +{ + --die # The ALTER statement is empty +} + +--let $alter_statement = ALTER + +if ($online) +{ + --let $alter_statement = $alter_statement ONLINE +} + +if (!$table_name) +{ + --let $table_name = t1 +} + +--let $alter_statement = $alter_statement TABLE $table_name $alter_definition +# We don't want to do ONLINE on underlying tables, we are not testing MyISAM +--let $child_statement = ALTER TABLE mrg.$table_name $child_alter_definition + + + +# We now have the complete ALTER statement in $alter_statement. +# If your ALTER statement should be composed differently, +# modify the logic above. + +##################### +# Here you can add logic needed BEFORE the main statement +# (e.g. base tables need to be altered, etc.). +# Surround it by --disable_query_log/--enable_query_log +# if you don't want it to appear in the result output. +##################### + +--source obfuscate.inc + +eval $alter_statement; +--source check_errors.inc + +# Make sure you don't add any statements between the main ALTER (above) +# and saving mysql_errno and mysql_errname (below) +# They are saved in case you want to add more logic after the main ALTER, +# because we need the result code of the statement. +# Also, do not change $alter_statement after it is executed! + +--let $my_errno = $mysql_errno +--let $my_errname = $mysql_errname + +##################### +# Here you can add logic needed AFTER the main statement. +# Surround it by --disable_query_log/--enable_query_log +# if you don't want it to appear in the result output. +##################### +--disable_query_log +--disable_warnings +--disable_result_log +# We will only try to alter the underlying table if the main alter was successful +if (!$my_errno) +{ + if ($rename_to) + { + eval ALTER TABLE $rename_to UNION(mrg.$rename_to); + } + # In the same section, the manual says that FLUSH TABLES should be performed before altering + # the underlying table, and later also says that it should be done after. We'll do both + FLUSH TABLES; + eval $child_statement; + FLUSH TABLES; +} +--enable_result_log +--enable_warnings +--enable_query_log + +# Unset the parameters, we don't want them to be accidentally reused later +--let $alter_definition = +--let $table_name = +--let $error_codes = +--let $online = 0 +--let $rename_to = + +# Restore the error codes of the main statement +--let $mysql_errno = $my_errno +--let $mysql_errname = $my_errname +# Make sure you don't add any SQL statements after restoring +# mysql_errno and mysql_errname (above) + diff --git a/storage/myisammrg/mysql-test/storage_engine/alter_table.rdiff b/storage/myisammrg/mysql-test/storage_engine/alter_table.rdiff new file mode 100644 index 00000000000..447a38a5b2b --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/alter_table.rdiff @@ -0,0 +1,68 @@ +11c11 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +19c19 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +27c27 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +35c35 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +43c43 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +51c51 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +59c59 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +67c67 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +75c75 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +82c82 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +91c91 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t2`) +100c100 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +107c107 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +122c122 +< ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs +--- +> ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +130c130 +< ) ENGINE= DEFAULT CHARSET=utf8 +--- +> ) ENGINE= DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +138c138 +< ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci +--- +> ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +146c146 +< ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci +--- +> ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci INSERT_METHOD=LAST UNION=(`mrg`.`t1`) diff --git a/storage/myisammrg/mysql-test/storage_engine/alter_tablespace.rdiff b/storage/myisammrg/mysql-test/storage_engine/alter_tablespace.rdiff new file mode 100644 index 00000000000..cfc821582ed --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/alter_tablespace.rdiff @@ -0,0 +1,27 @@ +4,18c4,13 +< DROP TABLE t1; +< CREATE TABLE t1 (a ) ENGINE= ; +< INSERT INTO t1 (a) VALUES (1),(2); +< SELECT * FROM t1; +< a +< 1 +< 2 +< ALTER TABLE t1 DISCARD TABLESPACE; +< SELECT * FROM t1; +< ERROR HY000: Got error -1 from storage engine +< ALTER TABLE t1 IMPORT TABLESPACE; +< SELECT * FROM t1; +< a +< 1 +< 2 +--- +> ERROR HY000: 'test.t1' is not BASE TABLE +> # ERROR: Statement ended with errno 1347, errname ER_WRONG_OBJECT (expected to succeed) +> # ------------ UNEXPECTED RESULT ------------ +> # [ ALTER TABLE t1 DISCARD TABLESPACE ] +> # The statement|command finished with ER_WRONG_OBJECT. +> # Tablespace operations or the mix could be unsupported|malfunctioning, or the problem was caused by previous errors. +> # You can change the engine code, or create an rdiff, or disable the test by adding it to disabled.def. +> # Further in this test, the message might sometimes be suppressed; a part of the test might be skipped. +> # Also, this problem may cause a chain effect (more errors of different kinds in the test). +> # ------------------------------------------- diff --git a/storage/myisammrg/mysql-test/storage_engine/analyze_table.rdiff b/storage/myisammrg/mysql-test/storage_engine/analyze_table.rdiff new file mode 100644 index 00000000000..139bcc00a81 --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/analyze_table.rdiff @@ -0,0 +1,22 @@ +8c8 +< test.t1 analyze status OK +--- +> test.t1 analyze note The storage engine for the table doesn't support analyze +12c12 +< test.t2 analyze status OK +--- +> test.t2 analyze note The storage engine for the table doesn't support analyze +17,18c17,18 +< test.t1 analyze status OK +< test.t2 analyze status OK +--- +> test.t1 analyze note The storage engine for the table doesn't support analyze +> test.t2 analyze note The storage engine for the table doesn't support analyze +24c24 +< test.t1 analyze status OK +--- +> test.t1 analyze note The storage engine for the table doesn't support analyze +28c28 +< test.t1 analyze status OK +--- +> test.t1 analyze note The storage engine for the table doesn't support analyze diff --git a/storage/myisammrg/mysql-test/storage_engine/autoincrement.rdiff b/storage/myisammrg/mysql-test/storage_engine/autoincrement.rdiff new file mode 100644 index 00000000000..e9095aa3944 --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/autoincrement.rdiff @@ -0,0 +1,34 @@ +9c9 +< ) ENGINE= DEFAULT CHARSET=latin1 +--- +> ) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t1`) +55c55 +< t1 # # # # # # # # 6 # # # # # # # +--- +> t1 # # # # # # # # 0 # # # # # # # +62c62 +< t1 # # # # # # # # # 8 # # # # # # # +--- +> t1 # # # # # # # # # 0 # # # # # # # +81c81 +< t1 # # # # # # # # # 10 # # # # # # # +--- +> t1 # # # # # # # # # 0 # # # # # # # +85c85 +< t1 # # # # # # # # # 21 # # # # # # # +--- +> t1 # # # # # # # # # 0 # # # # # # # +106c106 +< t1 # # # # # # # # # 22 # # # # # # # +--- +> t1 # # # # # # # # # 0 # # # # # # # +128,129c128,129 +< 100 a +< 101 b +--- +> 1 a +> 2 b +132c132 +< 100 +--- +> 1 diff --git a/storage/myisammrg/mysql-test/storage_engine/cache_index.rdiff b/storage/myisammrg/mysql-test/storage_engine/cache_index.rdiff new file mode 100644 index 00000000000..e10b22a8e66 --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/cache_index.rdiff @@ -0,0 +1,46 @@ +15,16c15,16 +< test.t1 assign_to_keycache status OK +< test.t2 assign_to_keycache status OK +--- +> test.t1 assign_to_keycache note The storage engine for the table doesn't support assign_to_keycache +> test.t2 assign_to_keycache note The storage engine for the table doesn't support assign_to_keycache +19,20c19,20 +< test.t1 preload_keys status OK +< test.t2 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys +> test.t2 preload_keys note The storage engine for the table doesn't support preload_keys +25,26c25,26 +< test.t1 preload_keys status OK +< test.t2 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys +> test.t2 preload_keys note The storage engine for the table doesn't support preload_keys +31c31 +< test.t1 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys +35c35 +< test.t1 assign_to_keycache status OK +--- +> test.t1 assign_to_keycache note The storage engine for the table doesn't support assign_to_keycache +39c39 +< test.t1 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys +50c50 +< test.t1 assign_to_keycache status OK +--- +> test.t1 assign_to_keycache note The storage engine for the table doesn't support assign_to_keycache +54c54 +< test.t1 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys +62c62 +< test.t1 assign_to_keycache status OK +--- +> test.t1 assign_to_keycache note The storage engine for the table doesn't support assign_to_keycache +66c66 +< test.t1 preload_keys status OK +--- +> test.t1 preload_keys note The storage engine for the table doesn't support preload_keys diff --git a/storage/myisammrg/mysql-test/storage_engine/char_indexes.rdiff b/storage/myisammrg/mysql-test/storage_engine/char_indexes.rdiff new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/myisammrg/mysql-test/storage_engine/checksum_table_live.rdiff b/storage/myisammrg/mysql-test/storage_engine/checksum_table_live.rdiff new file mode 100644 index 00000000000..1710cc18fea --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/checksum_table_live.rdiff @@ -0,0 +1,6 @@ +14,15c14,15 +< test.t1 4272806499 +< test.t2 0 +--- +> test.t1 NULL +> test.t2 NULL diff --git a/storage/myisammrg/mysql-test/storage_engine/cleanup_engine.inc b/storage/myisammrg/mysql-test/storage_engine/cleanup_engine.inc new file mode 100644 index 00000000000..b8f84110c76 --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/cleanup_engine.inc @@ -0,0 +1,16 @@ +########################################### +# +# This is a stub of the include file cleanup_engine.inc which +# should be placed in storage//mysql-test/storage_engine folder. +# +################################ +# +# Here you can add whatever is needed to cleanup +# in case your define_engine.inc created any artefacts, +# e.g. an additional schema and/or tables. +--disable_query_log +--disable_warnings +DROP DATABASE IF EXISTS mrg; +--enable_warnings +--enable_query_log + diff --git a/storage/myisammrg/mysql-test/storage_engine/create_table.inc b/storage/myisammrg/mysql-test/storage_engine/create_table.inc new file mode 100644 index 00000000000..c74460d42fb --- /dev/null +++ b/storage/myisammrg/mysql-test/storage_engine/create_table.inc @@ -0,0 +1,208 @@ +################################## +# +# This include file will be used for all CREATE TABLE statements in the suite. +# If you need to add additional steps or change the logic, copy the file +# to storage//mysql-test/storage_engine/ folder and modify it there. +# +################## +# +# Parameters: +# +# --let $create_definition = # optional, default t1 +# --let $table_options =
# optional, default based on define_engine.inc +# --let $partition_options = # optional, default none +# --let $as_select =