From 9ad42c70a3bc41819c5928c10c585f9e26134237 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Sep 2004 14:24:13 +0300 Subject: [PATCH 01/44] InnoDB: Update links to the user manual innobase/btr/btr0btr.c: Update links to the user manual innobase/buf/buf0buf.c: Update links to the user manual innobase/dict/dict0dict.c: Update links to the user manual innobase/fsp/fsp0fsp.c: Update links to the user manual innobase/log/log0log.c: Update links to the user manual innobase/log/log0recv.c: Update links to the user manual innobase/os/os0file.c: Update links to the user manual innobase/row/row0mysql.c: Update links to the user manual innobase/ut/ut0dbg.c: Update links to the user manual --- innobase/btr/btr0btr.c | 4 ++-- innobase/buf/buf0buf.c | 6 +++--- innobase/dict/dict0dict.c | 9 ++++++--- innobase/fsp/fsp0fsp.c | 6 +++--- innobase/log/log0log.c | 5 ++--- innobase/log/log0recv.c | 6 +++--- innobase/os/os0file.c | 31 +++++++++++++++++++------------ innobase/row/row0mysql.c | 20 ++++++++++++-------- innobase/ut/ut0dbg.c | 5 +++-- 9 files changed, 53 insertions(+), 39 deletions(-) diff --git a/innobase/btr/btr0btr.c b/innobase/btr/btr0btr.c index 81eb32467ad..d1ef1a77a9f 100644 --- a/innobase/btr/btr0btr.c +++ b/innobase/btr/btr0btr.c @@ -609,8 +609,8 @@ btr_page_get_father_for_rec( fputs( "InnoDB: You should dump + drop + reimport the table to fix the\n" "InnoDB: corruption. If the crash happens at the database startup, see\n" -"InnoDB: section 6.1 of http://www.innodb.com/ibman.php about forcing\n" -"InnoDB: recovery. Then dump + drop + reimport.\n", stderr); +"InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html about\n" +"InnoDB: forcing recovery. Then dump + drop + reimport.\n", stderr); } ut_a(btr_node_ptr_get_child_page_no(node_ptr) == diff --git a/innobase/buf/buf0buf.c b/innobase/buf/buf0buf.c index b744430a76e..aea3932eda7 100644 --- a/innobase/buf/buf0buf.c +++ b/innobase/buf/buf0buf.c @@ -1561,9 +1561,9 @@ buf_page_io_complete( "InnoDB: by dumping, dropping, and reimporting\n" "InnoDB: the corrupt table. You can use CHECK\n" "InnoDB: TABLE to scan your table for corruption.\n" - "InnoDB: Look also at section 6.1 of\n" - "InnoDB: http://www.innodb.com/ibman.php about\n" - "InnoDB: forcing recovery.\n", stderr); + "InnoDB: See also " + "http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html\n" + "InnoDB: about forcing recovery.\n", stderr); if (srv_force_recovery < SRV_FORCE_IGNORE_CORRUPT) { fputs( diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index ccaa5720c20..573b9ef49f1 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -2020,7 +2020,8 @@ dict_foreign_error_report( fputs("\nThe index in the foreign key in table is ", file); ut_print_name(file, fk->foreign_index->name); fputs( -"See http://www.innodb.com/ibman.php for correct foreign key definition.\n", +"\nSee http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" +"for correct foreign key definition.\n", file); } mutex_exit(&dict_foreign_err_mutex); @@ -2856,7 +2857,8 @@ col_loop1: ut_print_name(ef, name); fprintf(ef, " where the columns appear\n" "as the first columns. Constraint:\n%s\n" -"See http://www.innodb.com/ibman.php for correct foreign key definition.\n", +"nSee http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" +"for correct foreign key definition.\n", start_of_latest_foreign); mutex_exit(&dict_foreign_err_mutex); @@ -3121,7 +3123,8 @@ try_find_index: "Cannot find an index in the referenced table where the\n" "referenced columns appear as the first columns, or column types\n" "in the table and the referenced table do not match for constraint.\n" -"See http://www.innodb.com/ibman.php for correct foreign key definition.\n", +"See http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" +"for correct foreign key definition.\n", start_of_latest_foreign); mutex_exit(&dict_foreign_err_mutex); diff --git a/innobase/fsp/fsp0fsp.c b/innobase/fsp/fsp0fsp.c index 53f5e885df8..cb74c720ad9 100644 --- a/innobase/fsp/fsp0fsp.c +++ b/innobase/fsp/fsp0fsp.c @@ -2701,9 +2701,9 @@ fseg_free_page_low( "InnoDB: database!\n", page); crash: fputs( -"InnoDB: If the InnoDB recovery crashes here, see section 6.1\n" -"InnoDB: of http://www.innodb.com/ibman.php about forcing recovery.\n", - stderr); +"InnoDB: Please refer to\n" +"InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html\n" +"InnoDB: about forcing recovery.\n", stderr); ut_error; } diff --git a/innobase/log/log0log.c b/innobase/log/log0log.c index 381d11e4cce..79432fbd511 100644 --- a/innobase/log/log0log.c +++ b/innobase/log/log0log.c @@ -685,10 +685,9 @@ failure: "InnoDB: To get mysqld to start up, set innodb_thread_concurrency in my.cnf\n" "InnoDB: to a lower value, for example, to 8. After an ERROR-FREE shutdown\n" "InnoDB: of mysqld you can adjust the size of ib_logfiles, as explained in\n" -"InnoDB: section 5 of http://www.innodb.com/ibman.php", +"InnoDB: http://dev.mysql.com/doc/mysql/en/Adding_and_removing.html\n" +"InnoDB: Cannot continue operation. Calling exit(1).\n", (ulong)srv_thread_concurrency); - fprintf(stderr, -"InnoDB: Cannot continue operation. Calling exit(1).\n"); exit(1); } diff --git a/innobase/log/log0recv.c b/innobase/log/log0recv.c index 51941a14656..52e0b99cb24 100644 --- a/innobase/log/log0recv.c +++ b/innobase/log/log0recv.c @@ -514,8 +514,8 @@ recv_find_max_checkpoint( "InnoDB: If this error appears when you are creating an InnoDB database,\n" "InnoDB: the problem may be that during an earlier attempt you managed\n" "InnoDB: to create the InnoDB data files, but log file creation failed.\n" -"InnoDB: If that is the case, please refer to section 3.1 of\n" -"InnoDB: http://www.innodb.com/ibman.php\n"); +"InnoDB: If that is the case, please refer to\n" +"InnoDB: http://dev.mysql.com/doc/mysql/en/Error_creating_InnoDB.html\n"); return(DB_ERROR); } @@ -1840,7 +1840,7 @@ recv_report_corrupt_log( "InnoDB: far enough in recovery! Please run CHECK TABLE\n" "InnoDB: on your InnoDB tables to check that they are ok!\n" "InnoDB: If mysqld crashes after this recovery, look at\n" - "InnoDB: section 6.1 of http://www.innodb.com/ibman.php\n" + "InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html\n" "InnoDB: about forcing recovery.\n", stderr); fflush(stderr); diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 56f01568ead..9aa077d162e 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -212,7 +212,8 @@ os_file_get_last_error(void) ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Operating system error number %lu in a file operation.\n" - "InnoDB: See http://www.innodb.com/ibman.php for installation help.\n", + "InnoDB: See http://dev.mysql.com/doc/mysql/en/InnoDB.html\n" + "InnoDB: for installation help.\n", err); if (err == ERROR_PATH_NOT_FOUND) { @@ -227,8 +228,9 @@ os_file_get_last_error(void) "InnoDB: of the same name as a data file.\n"); } else { fprintf(stderr, - "InnoDB: See section 13.2 at http://www.innodb.com/ibman.php\n" - "InnoDB: about operating system error numbers.\n"); + "InnoDB: Some operating system error numbers are described at\n" + "InnoDB: " + "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); } } @@ -251,7 +253,8 @@ os_file_get_last_error(void) fprintf(stderr, " InnoDB: Operating system error number %lu in a file operation.\n" - "InnoDB: See http://www.innodb.com/ibman.php for installation help.\n", + "InnoDB: See http://dev.mysql.com/doc/mysql/en/InnoDB.html\n" + "InnoDB: for installation help.\n", err); if (err == ENOENT) { @@ -270,8 +273,9 @@ os_file_get_last_error(void) } fprintf(stderr, - "InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" - "InnoDB: about operating system error numbers.\n"); + "InnoDB: Some operating system error numbers are described at\n" + "InnoDB: " + "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); } } @@ -1465,8 +1469,9 @@ retry: fprintf(stderr, " InnoDB: Error: File pointer positioning to file %s failed at\n" "InnoDB: offset %lu %lu. Operating system error number %lu.\n" -"InnoDB: Look from section 13.2 at http://www.innodb.com/ibman.php\n" -"InnoDB: what the error number means.\n", +"InnoDB: Some operating system error numbers are described at\n" +"InnoDB: " +"http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n", name, offset_high, offset, (ulint)GetLastError()); @@ -1523,8 +1528,9 @@ retry: } fprintf(stderr, -"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" -"InnoDB: about operating system error numbers.\n"); +"InnoDB: Some operating system error numbers are described at\n" +"InnoDB: " +"http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); os_has_said_disk_full = TRUE; } @@ -1558,8 +1564,9 @@ retry: } fprintf(stderr, -"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" -"InnoDB: about operating system error numbers.\n"); +"InnoDB: Some operating system error numbers are described at\n" +"InnoDB: " +"http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); os_has_said_disk_full = TRUE; } diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index 70743e3a753..a23444df4ef 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -310,8 +310,9 @@ handle_new_error: "InnoDB: a case of widespread corruption, dump all InnoDB\n" "InnoDB: tables and recreate the whole InnoDB tablespace.\n" "InnoDB: If the mysqld server crashes after the startup or when\n" - "InnoDB: you dump the tables, look at section 6.1 of\n" - "InnoDB: http://www.innodb.com/ibman.php for help.\n", stderr); + "InnoDB: you dump the tables, look at\n" + "InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html" + " for help.\n", stderr); } else { fprintf(stderr, "InnoDB: unknown error code %lu\n", err); @@ -1551,8 +1552,9 @@ row_create_table_for_mysql( "InnoDB: database and moving the .frm file to the current database.\n" "InnoDB: Then MySQL thinks the table exists, and DROP TABLE will\n" "InnoDB: succeed.\n" - "InnoDB: You can look for further help from section 15.1 of\n" - "InnoDB: http://www.innodb.com/ibman.php\n", stderr); + "InnoDB: You can look for further help from\n" + "InnoDB: http://dev.mysql.com/doc/mysql/en/" + "InnoDB_troubleshooting_datadict.html\n", stderr); } trx->error_state = DB_SUCCESS; @@ -2089,8 +2091,9 @@ row_drop_table_for_mysql( "InnoDB: data dictionary though MySQL is trying to drop it.\n" "InnoDB: Have you copied the .frm file of the table to the\n" "InnoDB: MySQL database directory from another database?\n" - "InnoDB: You can look for further help from section 15.1 of\n" - "InnoDB: http://www.innodb.com/ibman.php\n", stderr); + "InnoDB: You can look for further help from\n" + "InnoDB: http://dev.mysql.com/doc/mysql/en/" + "InnoDB_troubleshooting_datadict.html\n", stderr); goto funct_exit; } @@ -2588,8 +2591,9 @@ row_rename_table_for_mysql( ut_print_name(stderr, old_name); fputs(" to it.\n" "InnoDB: Have you deleted the .frm file and not used DROP TABLE?\n" - "InnoDB: You can look for further help from section 15.1 of\n" - "InnoDB: http://www.innodb.com/ibman.php\n" + "InnoDB: You can look for further help from\n" + "InnoDB: http://dev.mysql.com/doc/mysql/en/" + "InnoDB_troubleshooting_datadict.html\n" "InnoDB: If table ", stderr); ut_print_name(stderr, new_name); fputs( diff --git a/innobase/ut/ut0dbg.c b/innobase/ut/ut0dbg.c index 2a0cfe1f13a..0f6a27d35d9 100644 --- a/innobase/ut/ut0dbg.c +++ b/innobase/ut/ut0dbg.c @@ -31,8 +31,9 @@ const char* ut_dbg_msg_trap = "InnoDB: Submit a detailed bug report to http://bugs.mysql.com.\n" "InnoDB: If you get repeated assertion failures or crashes, even\n" "InnoDB: immediately after the mysqld startup, there may be\n" -"InnoDB: corruption in the InnoDB tablespace. See section 6.1 of\n" -"InnoDB: http://www.innodb.com/ibman.php about forcing recovery.\n"; +"InnoDB: corruption in the InnoDB tablespace. Please refer to\n" +"InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html\n" +"InnoDB: about forcing recovery.\n"; const char* ut_dbg_msg_stop = "InnoDB: Thread %lu stopped in file %s line %lu\n"; From eed990d667df9caac808b17cea3b9eb67af1e33d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Sep 2004 16:45:03 +0500 Subject: [PATCH 02/44] A fix (bug #3120: 'mysqladmin ping' - return error code). --- client/mysqladmin.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/client/mysqladmin.c b/client/mysqladmin.c index 3bc11ec0fb0..153fcdde96d 100644 --- a/client/mysqladmin.c +++ b/client/mysqladmin.c @@ -246,7 +246,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), int main(int argc,char *argv[]) { - int error, ho_error; + int error= 0, ho_error; MYSQL mysql; char **commands, **save_argv; @@ -285,10 +285,25 @@ int main(int argc,char *argv[]) opt_ssl_capath, opt_ssl_cipher); #endif if (sql_connect(&mysql, option_wait)) - error = 1; + { + unsigned int err= mysql_errno(&mysql); + if (err >= CR_MIN_ERROR && err <= CR_MAX_ERROR) + error= 1; + else + { + /* Return 0 if all commands are PING */ + for (; argc > 0; argv++, argc--) + { + if (find_type(argv[0], &command_typelib, 2) != ADMIN_PING) + { + error= 1; + break; + } + } + } + } else { - error = 0; while (!interrupted && (!opt_count_iterations || nr_iterations)) { new_line = 0; From 773a256e89cccd426ed7b9d2a077eeb4c6736355 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Sep 2004 16:31:01 +0200 Subject: [PATCH 03/44] [This patch has already been approved by Serge. I am recommitting and pushing from a new repository because there were other changesets that couldn't be pushed.] BUG# 5229 --password=foobar does not override the empty 'password' option in the my.cnf This is a backport of a change made by jani in the 4.1 tree. mysql.cc: Add tty_password=0 in the p case handling in get_one_option client/mysql.cc: Add tty_password=0 in the p case handling in get_one_option --- client/mysql.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/client/mysql.cc b/client/mysql.cc index 3cc8b41af66..7d1b6af2c37 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -689,6 +689,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), while (*argument) *argument++= 'x'; // Destroy argument if (*start) start[1]=0 ; + tty_password= 0; } else tty_password= 1; From c00c89af7f81841d00af08520d2eef52d40eab60 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Sep 2004 18:26:19 -0700 Subject: [PATCH 04/44] Updating the headers on a few files to include GPL header. sql/repl_failsafe.cc: Removed reference to old maintainer. sql/repl_failsafe.h: Added license header. sql/slave.h: Added license header. sql/sql_repl.cc: Removed old maintainer. sql/sql_repl.h: Added license header BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted --- BitKeeper/etc/logging_ok | 1 + sql/repl_failsafe.cc | 2 -- sql/repl_failsafe.h | 16 ++++++++++++++++ sql/slave.h | 16 ++++++++++++++++ sql/sql_repl.cc | 2 -- sql/sql_repl.h | 16 ++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 698f7655b6e..ca4a56eb210 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -20,6 +20,7 @@ bar@mysql.com bell@laptop.sanja.is.com.ua bell@sanja.is.com.ua bk@admin.bk +brian@brian-akers-computer.local carsten@tsort.bitbybit.dk davida@isil.mysql.com dlenev@brandersnatch.localdomain diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 604938a8ed0..9fa6ea843f1 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -14,8 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// Sasha Pachev is currently in charge of this file - #include "mysql_priv.h" #include "repl_failsafe.h" #include "sql_repl.h" diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h index ae8bb2bc4d5..eb0e97c2820 100644 --- a/sql/repl_failsafe.h +++ b/sql/repl_failsafe.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB & Sasha + + 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; either version 2 of the License, or + (at your option) any later version. + + 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 REPL_FAILSAFE_H #define REPL_FAILSAFE_H diff --git a/sql/slave.h b/sql/slave.h index 0cd8545338d..eb54e258a96 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2000-2003 MySQL AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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 SLAVE_H #define SLAVE_H diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index cff36eaa388..514fed226d2 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -14,8 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// Sasha Pachev is currently in charge of this file - #include "mysql_priv.h" #include "sql_repl.h" #include "sql_acl.h" diff --git a/sql/sql_repl.h b/sql/sql_repl.h index 570c41c98f7..5eac754c25c 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB & Sasha + + 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + #include "slave.h" typedef struct st_slave_info From c36356b6a4ac740f61f2a82a04f87213b06f40f5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Sep 2004 12:23:10 +0500 Subject: [PATCH 05/44] Bug #5447 Select does not find records Note, there is no need to propagate this change into 4.1. mysql-test/r/ctype_latin1_de.result: Bug #5447 Select does not find records mysql-test/t/ctype_latin1_de.test: Bug #5447 Select does not find records strings/ctype-latin1_de.c: Bug #5447 Select does not find records --- mysql-test/r/ctype_latin1_de.result | 15 +++++++++++++++ mysql-test/t/ctype_latin1_de.test | 14 ++++++++++++++ strings/ctype-latin1_de.c | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ctype_latin1_de.result b/mysql-test/r/ctype_latin1_de.result index 28394d9533a..c4bf6b5a3a9 100644 --- a/mysql-test/r/ctype_latin1_de.result +++ b/mysql-test/r/ctype_latin1_de.result @@ -267,3 +267,18 @@ select * from t1 where word like CAST(0xDF as CHAR); word word2 ß ß drop table t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +autor varchar(80) NOT NULL default '', +PRIMARY KEY (autor) +); +INSERT INTO t1 VALUES ('Powell, B.'),('Powell, Bud.'),('Powell, L. H.'),('Power, H.'), +('Poynter, M. A. L. Lane'),('Poynting, J. H. und J. J. Thomson.'),('Pozzi, S(amuel-Jean).'), +('Pozzi, Samuel-Jean.'),('Pozzo, A.'),('Pozzoli, Serge.'); +SELECT * FROM t1 WHERE autor LIKE 'Poz%' ORDER BY autor; +autor +Pozzi, S(amuel-Jean). +Pozzi, Samuel-Jean. +Pozzo, A. +Pozzoli, Serge. +DROP TABLE t1; diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test index 3a0f2658969..d6c12683d94 100644 --- a/mysql-test/t/ctype_latin1_de.test +++ b/mysql-test/t/ctype_latin1_de.test @@ -72,3 +72,17 @@ select * from t1 where word like 'AE'; select * from t1 where word like 0xDF; select * from t1 where word like CAST(0xDF as CHAR); drop table t1; + +# +# Bug #5447 Select does not find records +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( + autor varchar(80) NOT NULL default '', + PRIMARY KEY (autor) +); +INSERT INTO t1 VALUES ('Powell, B.'),('Powell, Bud.'),('Powell, L. H.'),('Power, H.'), +('Poynter, M. A. L. Lane'),('Poynting, J. H. und J. J. Thomson.'),('Pozzi, S(amuel-Jean).'), +('Pozzi, Samuel-Jean.'),('Pozzo, A.'),('Pozzoli, Serge.'); +SELECT * FROM t1 WHERE autor LIKE 'Poz%' ORDER BY autor; +DROP TABLE t1; diff --git a/strings/ctype-latin1_de.c b/strings/ctype-latin1_de.c index 5b7a68fb967..bc4327e921d 100644 --- a/strings/ctype-latin1_de.c +++ b/strings/ctype-latin1_de.c @@ -248,7 +248,7 @@ int my_strxfrm_latin1_de(uchar * dest, const uchar * src, int len) */ #define min_sort_char ((char) 0) -#define max_sort_char ((char) 255) +#define max_sort_char ((char) 0xF7) #define wild_one '_' #define wild_many '%' From f13b746b693d7d801c1d8fce63033eb9cd047671 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Sep 2004 17:00:46 +0200 Subject: [PATCH 06/44] - two small fixups for the mysql-copyright scripts: remove the autom4te.cache directory and update the headers of the message files. Build-tools/mysql-copyright-2: - make sure to fix the copyright in the recently added GPL headers of the message files, too Build-tools/mysql-copyright: - remove the autom4te.cache directory (leftover from running autotools after modifying configure.in) --- Build-tools/mysql-copyright | 4 ++++ Build-tools/mysql-copyright-2 | 1 + 2 files changed, 5 insertions(+) diff --git a/Build-tools/mysql-copyright b/Build-tools/mysql-copyright index ad4547b493c..a1869304ba7 100755 --- a/Build-tools/mysql-copyright +++ b/Build-tools/mysql-copyright @@ -125,6 +125,10 @@ sub main print "\"./configure\" was not produced, exiting!\n"; exit(0); } + if (-d "autom4te.cache") { + print "Trying to delete autom4te.cache dir\n" if $opt_verbose; + system("rm -rf autom4te.cache") or print "Unable to delete autom4te.cache dir: $!\n"; + } } # fix file copyrights diff --git a/Build-tools/mysql-copyright-2 b/Build-tools/mysql-copyright-2 index a1a870526da..2ea2e8ef441 100755 --- a/Build-tools/mysql-copyright-2 +++ b/Build-tools/mysql-copyright-2 @@ -90,6 +90,7 @@ sub add_copyright $ARGV =~ /\.cc$/ || $ARGV =~ /\.h$/ || $ARGV =~ /\.cpp$/ || + $ARGV =~ /\.txt$/ || $ARGV =~ /\.yy$/) { $start_copyright="/* "; From 37e3feba8291661a135ec6d97f443f9d4eef55cc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Sep 2004 19:19:29 +0200 Subject: [PATCH 07/44] Prevent some combinations of autotools and libtool version from generating a non-working top level 'libtool'. ltmain.sh: Some combinations of autotools and libtool leave 'max_cmd'len' (in top-level 'libtool') unset, this eventually causes a 'ld' command without input files to be generated. Prevent this error by supplying a 4 kB default value. --- ltmain.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ltmain.sh b/ltmain.sh index 62b9ed17e3f..92e438cbda6 100644 --- a/ltmain.sh +++ b/ltmain.sh @@ -51,6 +51,9 @@ fi # libtool 1.4.2 workaround SED=${SED:-sed} +# workaround against unset 'max_cmd_len': assume at least 4 kB +max_cmd_len=${max_cmd_len:-4096} + # The name of this program. progname=`$echo "$0" | ${SED} 's%^.*/%%'` modename="$progname" From 8eb1db61a0fedd44497c1e442486f25edc988731 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Sep 2004 00:08:12 +0200 Subject: [PATCH 08/44] configure.in: Updated to 4.0.22 configure.in: Updated to 4.0.22 BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted --- BitKeeper/etc/logging_ok | 1 + configure.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index ca4a56eb210..d65810bb708 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -67,6 +67,7 @@ kostja@oak.local lenz@kallisto.mysql.com lenz@mysql.com marko@hundin.mysql.fi +matt@mysql.com miguel@hegel.(none) miguel@hegel.br miguel@hegel.local diff --git a/configure.in b/configure.in index 30a546ec5d9..c3978ff32d1 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(sql/mysqld.cc) AC_CANONICAL_SYSTEM # The Docs Makefile.am parses this line! -AM_INIT_AUTOMAKE(mysql, 4.0.21) +AM_INIT_AUTOMAKE(mysql, 4.0.22) AM_CONFIG_HEADER(config.h) PROTOCOL_VERSION=10 From 58c98fde65049a9eb75612454f936110ea0ff426 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Sep 2004 13:44:06 +0300 Subject: [PATCH 09/44] dict0dict.c: Fixed typo innobase/dict/dict0dict.c: Fixed typo --- innobase/dict/dict0dict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index 573b9ef49f1..bd07c5abffe 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -2857,7 +2857,7 @@ col_loop1: ut_print_name(ef, name); fprintf(ef, " where the columns appear\n" "as the first columns. Constraint:\n%s\n" -"nSee http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" +"See http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" "for correct foreign key definition.\n", start_of_latest_foreign); mutex_exit(&dict_foreign_err_mutex); From c1e84276868d04c165bca8b7a5fd36fe7ff4aed5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Sep 2004 09:37:16 +0300 Subject: [PATCH 10/44] os0file.c: Add more precise diagnostics about the state of the I/O threads of InnoDB; print in SHOW INNODB STATUS if the event wait semaphore of each I/O thread is set innobase/os/os0file.c: Add more precise diagnostics about the state of the I/O threads of InnoDB; print in SHOW INNODB STATUS if the event wait semaphore of each I/O thread is set --- innobase/os/os0file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 9aa077d162e..70ef8f55b98 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -2588,6 +2588,8 @@ restart: /* NOTE! We only access constant fields in os_aio_array. Therefore we do not have to acquire the protecting mutex yet */ + srv_set_io_thread_op_info(global_segment, + "looking for i/o requests (a)"); ut_ad(os_aio_validate()); ut_ad(segment < array->n_segments); @@ -2606,6 +2608,9 @@ restart: os_mutex_enter(array->mutex); + srv_set_io_thread_op_info(global_segment, + "looking for i/o requests (b)"); + /* Check if there is a slot for which the i/o has already been done */ @@ -2718,6 +2723,8 @@ consecutive_loop: } } + srv_set_io_thread_op_info(global_segment, "consecutive i/o requests"); + /* We have now collected n_consecutive i/o requests in the array; allocate a single buffer which can hold all data, and perform the i/o */ @@ -2861,6 +2868,8 @@ slot_io_done: return(ret); wait_for_io: + srv_set_io_thread_op_info(global_segment, "resetting wait event"); + /* We wait here until there again can be i/os in the segment of this thread */ @@ -2952,9 +2961,15 @@ os_aio_print( ulint i; for (i = 0; i < srv_n_file_io_threads; i++) { - fprintf(file, "I/O thread %lu state: %s (%s)\n", i, + fprintf(file, "I/O thread %lu state: %s (%s)", i, srv_io_thread_op_info[i], srv_io_thread_function[i]); + + if (os_aio_segment_wait_events[i]->is_set) { + fprintf(file, " ev set"); + } + + fprintf(file, "\n"); } fputs("Pending normal aio reads:", file); From 4015c585ad6df0e585d5d4f80f6b27789697e666 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Sep 2004 12:13:24 +0500 Subject: [PATCH 11/44] Fix for bug #4809 (Backticks not handled in mysql) client/mysql.cc: Code added to handle backticks --- client/mysql.cc | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 7d1b6af2c37..4aac548a065 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2201,17 +2201,49 @@ static int com_source(String *buffer, char *line) static int com_use(String *buffer __attribute__((unused)), char *line) { - char *tmp, buff[FN_REFLEN + 1]; + char tmp[FN_REFLEN], buff[FN_REFLEN + 1]; MYSQL_RES *res; MYSQL_ROW row; + char *c_buff, *c_tmp; while (isspace(*line)) line++; strnmov(buff,line,sizeof(buff)-1); // Don't destroy history if (buff[0] == '\\') // Short command buff[1]=' '; - tmp=(char *) strtok(buff," \t;"); // Skip connect command - if (!tmp || !(tmp=(char *) strtok(NullS," \t;"))) + c_buff= buff; + while ((*c_buff != ' ') && (*c_buff != '\t')) // Skip connect command + c_buff++; + c_buff++; + + while ((*c_buff == ' ') || (*c_buff == '\t')) + c_buff++; + c_tmp= tmp; + if (*c_buff == '`') // Handling backticks + { + c_buff++; + for (; *c_buff; c_tmp++) + { + if (*c_buff == '`') + { + if (c_buff[1] == '`') + { + *c_tmp= '`'; + c_buff+= 2; + } + else + break; + } + else + *c_tmp= *(c_buff++); + } + } + else + for (; !strchr(" \t;", *c_buff); c_buff++, c_tmp++) + *c_tmp= *c_buff; + *c_tmp= '\0'; + + if (!*tmp) { put_info("USE must be followed by a database name",INFO_ERROR); return 0; From cc98eea53b3dc9258838bee9528cce9dfc771d72 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Sep 2004 14:25:43 +0500 Subject: [PATCH 12/44] A fix (bug #5498 TRIM fails with LEADING or TRAILING if remstr = str). --- mysql-test/r/func_str.result | 6 ++++++ mysql-test/t/func_str.test | 7 +++++++ sql/item_strfunc.cc | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 12c1cf78f7c..b4d1be5bd54 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -282,3 +282,9 @@ NULL NULL 1 1 n two 'two' 0 0 'two' four 'four' 0 0 'four' drop table t1; +select trim(trailing 'foo' from 'foo'); +trim(trailing 'foo' from 'foo') + +select trim(leading 'foo' from 'foo'); +trim(leading 'foo' from 'foo') + diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 9b0c076f23e..ba6a8b55236 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -172,3 +172,10 @@ create table t1(a char(4)); insert into t1 values ('one'),(NULL),('two'),('four'); select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1; drop table t1; + +# +# Bug #5498: TRIM fails with LEADING or TRAILING if remstr = str +# + +select trim(trailing 'foo' from 'foo'); +select trim(leading 'foo' from 'foo'); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5d017b3a27a..9248cbc0217 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1135,7 +1135,7 @@ String *Item_func_ltrim::val_str(String *str) { const char *r_ptr=remove_str->ptr(); end-=remove_length; - while (ptr < end && !memcmp(ptr,r_ptr,remove_length)) + while (ptr <= end && !memcmp(ptr, r_ptr, remove_length)) ptr+=remove_length; end+=remove_length; } @@ -1206,8 +1206,8 @@ String *Item_func_rtrim::val_str(String *str) else #endif /* USE_MB */ { - while (ptr + remove_length < end && - !memcmp(end-remove_length,r_ptr,remove_length)) + while (ptr + remove_length <= end && + !memcmp(end-remove_length, r_ptr, remove_length)) end-=remove_length; } } From fb91884f33cb66f6834e6e16c7a3f7c850f9f766 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Sep 2004 19:05:39 +0300 Subject: [PATCH 13/44] row0mysql.h: Improve the comment on stored_select_lock_type ha_innodb.cc: Let InnoDB remember select_lock_type inside LOCK TABLES, also over plain consistent read SELECTs; fix Bug #5538 : assertion failure when using mysqldump with the -l option; in MERGING this patch to 4.1, there may be PROBLEMS; that is because previous patch was never merged to 4.1; Heikki Tuuri has to polish the code in 4.1 after this patch has been merged. sql/ha_innodb.cc: Let InnoDB remember select_lock_type inside LOCK TABLES, also over plain consistent read SELECTs; fix Bug #5538 : assertion failure when using mysqldump with the -l option; in MERGING this patch to 4.1, there may be PROBLEMS; that is because previous patch was never merged to 4.1; Heikki Tuuri has to polish the code in 4.1 after this patch has been merged. innobase/include/row0mysql.h: Improve the comment on stored_select_lock_type --- innobase/include/row0mysql.h | 8 +++-- sql/ha_innodb.cc | 65 +++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/innobase/include/row0mysql.h b/innobase/include/row0mysql.h index 0ab70db2dea..bbd90434f39 100644 --- a/innobase/include/row0mysql.h +++ b/innobase/include/row0mysql.h @@ -508,9 +508,11 @@ struct row_prebuilt_struct { dtuple_t* clust_ref; /* prebuilt dtuple used in sel/upd/del */ ulint select_lock_type;/* LOCK_NONE, LOCK_S, or LOCK_X */ - ulint stored_select_lock_type;/* inside LOCK TABLES, either - LOCK_S or LOCK_X depending on the lock - type */ + ulint stored_select_lock_type;/* this field is used to + remember the original select_lock_type + that was decided in ha_innodb.cc, + ::store_lock(), ::external_lock(), + etc. */ ulint mysql_row_len; /* length in bytes of a row in the MySQL format */ ulint n_rows_fetched; /* number of rows fetched after diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 1572e22d6f7..b9d898d5bd1 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -767,6 +767,7 @@ ha_innobase::init_table_handle_for_HANDLER(void) if the trx isolation level would have been specified as SERIALIZABLE */ prebuilt->select_lock_type = LOCK_NONE; + prebuilt->stored_select_lock_type = LOCK_NONE; /* Always fetch all columns in the index record */ @@ -4562,40 +4563,40 @@ ha_innobase::start_stmt( prebuilt->select_lock_type = LOCK_X; } else { - /* When we first come here after LOCK TABLES, - select_lock_type is set to LOCK_S or LOCK_X. Store the value - in case we run also consistent reads and need to restore the - value later. */ + if (trx->isolation_level != TRX_ISO_SERIALIZABLE + && thd->lex.sql_command == SQLCOM_SELECT + && thd->lex.lock_option == TL_READ) { + + /* For other than temporary tables, we obtain + no lock for consistent read (plain SELECT). */ - if (prebuilt->select_lock_type != LOCK_NONE) { - prebuilt->stored_select_lock_type = - prebuilt->select_lock_type; + prebuilt->select_lock_type = LOCK_NONE; + } else { + /* Not a consistent read: restore the + select_lock_type value. The value of + stored_select_lock_type was decided in: + 1) ::store_lock(), + 2) ::external_lock(), and + 3) ::init_table_handle_for_HANDLER(). */ + + prebuilt->select_lock_type = + prebuilt->stored_select_lock_type; } if (prebuilt->stored_select_lock_type != LOCK_S && prebuilt->stored_select_lock_type != LOCK_X) { fprintf(stderr, -"InnoDB: Error: select_lock_type is %lu inside ::start_stmt()!\n", +"InnoDB: Error: stored_select_lock_type is %lu inside ::start_stmt()!\n", prebuilt->stored_select_lock_type); - ut_error; - } + /* Set the value to LOCK_X: this is just fault + tolerance, we do not know what the correct value + should be! */ - if (thd->lex.sql_command == SQLCOM_SELECT - && thd->lex.lock_option == TL_READ) { - - /* For other than temporary tables, we obtain - no lock for consistent read (plain SELECT) */ - - prebuilt->select_lock_type = LOCK_NONE; - } else { - /* Not a consistent read: restore the - select_lock_type value */ - prebuilt->select_lock_type = - prebuilt->stored_select_lock_type; + prebuilt->select_lock_type = LOCK_X; } } - + /* Set the MySQL flag to mark that there is an active transaction */ thd->transaction.all.innodb_active_trans = 1; @@ -4656,6 +4657,7 @@ ha_innobase::external_lock( /* If this is a SELECT, then it is in UPDATE TABLE ... or SELECT ... FOR UPDATE */ prebuilt->select_lock_type = LOCK_X; + prebuilt->stored_select_lock_type = LOCK_X; } if (lock_type != F_UNLCK) { @@ -4910,14 +4912,22 @@ ha_innobase::store_lock( { row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt; - if (lock_type == TL_READ_WITH_SHARED_LOCKS || + if ((lock_type == TL_READ && thd->in_lock_tables) || + (lock_type == TL_READ_HIGH_PRIORITY && thd->in_lock_tables) || + lock_type == TL_READ_WITH_SHARED_LOCKS || lock_type == TL_READ_NO_INSERT) { - /* This is a SELECT ... IN SHARE MODE, or - we are doing a complex SQL statement like + /* The OR cases above are in this order: + 1) MySQL is doing LOCK TABLES ... READ LOCAL, or + 2) (we do not know when TL_READ_HIGH_PRIORITY is used), or + 3) this is a SELECT ... IN SHARE MODE, or + 4) we are doing a complex SQL statement like INSERT INTO ... SELECT ... and the logical logging (MySQL - binlog) requires the use of a locking read */ + binlog) requires the use of a locking read, or + MySQL is doing LOCK TABLES ... READ. */ prebuilt->select_lock_type = LOCK_S; + prebuilt->stored_select_lock_type = LOCK_S; + } else if (lock_type != TL_IGNORE) { /* In ha_berkeley.cc there is a comment that MySQL @@ -4928,6 +4938,7 @@ ha_innobase::store_lock( here even if this would be SELECT ... FOR UPDATE */ prebuilt->select_lock_type = LOCK_NONE; + prebuilt->stored_select_lock_type = LOCK_NONE; } if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) { From e6503e1e531495e1ad2c4e2a39b8cec6ab6a0fe8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Sep 2004 20:08:09 +0300 Subject: [PATCH 14/44] sync0arr.c: Correct the comment on the 'waiting' field in sync_cell_struct innobase/sync/sync0arr.c: Correct the comment on the 'waiting' field in sync_cell_struct --- innobase/sync/sync0arr.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/innobase/sync/sync0arr.c b/innobase/sync/sync0arr.c index 176aedb6ae3..09ddfd1d309 100644 --- a/innobase/sync/sync0arr.c +++ b/innobase/sync/sync0arr.c @@ -61,10 +61,7 @@ struct sync_cell_struct { thread */ ibool waiting; /* TRUE if the thread has already called sync_array_event_wait - on this cell but not yet - sync_array_free_cell (which - actually resets wait_object and thus - whole cell) */ + on this cell */ ibool event_set; /* TRUE if the event is set */ os_event_t event; /* operating system event semaphore handle */ From 1d6ea1611b2de5bec5c91aec958c9ffe7bce8314 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Sep 2004 12:23:18 -0700 Subject: [PATCH 15/44] fixed bug 5531 scripts/mysqlhotcopy.sh: small fix to help options per bug 5531 --- scripts/mysqlhotcopy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh index af4e6084c59..2256e028eb4 100644 --- a/scripts/mysqlhotcopy.sh +++ b/scripts/mysqlhotcopy.sh @@ -77,7 +77,7 @@ Usage: $0 db_name[./table_regex/] [new_db_name | directory] --record_log_pos=# record slave and master status in specified db.table --chroot=# base directory of chroot jail in which mysqld operates - Try \'perldoc $0 for more complete documentation\' + Try \'perldoc $0\' for more complete documentation\' _OPTIONS sub usage { From 8bf8c8596873b534ad4a13eb73152c617c50c21b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Sep 2004 14:10:29 -0700 Subject: [PATCH 16/44] another small change for bug 5531 scripts/mysqlhotcopy.sh: one more \' to remove for bugfix 5531! --- scripts/mysqlhotcopy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh index 2256e028eb4..b90ca4dc7c0 100644 --- a/scripts/mysqlhotcopy.sh +++ b/scripts/mysqlhotcopy.sh @@ -77,7 +77,7 @@ Usage: $0 db_name[./table_regex/] [new_db_name | directory] --record_log_pos=# record slave and master status in specified db.table --chroot=# base directory of chroot jail in which mysqld operates - Try \'perldoc $0\' for more complete documentation\' + Try \'perldoc $0\' for more complete documentation _OPTIONS sub usage { From d47c79a0680ed5dee4d7373495e1481e31808311 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Sep 2004 16:10:14 +0500 Subject: [PATCH 17/44] Fixed Bug #5492 "set @@session.read_rnd_buffer_size=33554432" crashes server on query incremented size of allocated buffer in the init_rr_cache(sql/records.cc) ( We are going to read the last three bytes of the buffer via uint3korr This macro reads actually 4 bytes (for speed) So, we have to allocate one more byte at the end of the buffer to avoid memory assertion fault ) sql/records.cc: incremented size of allocated buffer in the init_rr_cache ( We are going to read the last three bytes of the buffer via uint3korr This macro reads actually 4 bytes (for speed) So, we have to allocate one more byte at the end of the buffer to avoid memory assertion fault ) Fixed Bug #5492 "set @@session.read_rnd_buffer_size=33554432" crashes server on query --- sql/records.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/records.cc b/sql/records.cc index 415e75a467b..a2c6eb0a040 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -249,9 +249,15 @@ static int init_rr_cache(READ_RECORD *info) rec_cache_size=info->cache_records*info->reclength; info->rec_cache_size=info->cache_records*info->ref_length; + /* + We are going to read the last three bytes of the buffer via uint3korr + This macro reads actually 4 bytes (for speed) + So, we have to allocate one more byte at the end of the buffer + to avoid memory assertion fault + */ if (info->cache_records <= 2 || !(info->cache=(byte*) my_malloc_lock(rec_cache_size+info->cache_records* - info->struct_length, + info->struct_length+1, MYF(0)))) DBUG_RETURN(1); #ifdef HAVE_purify From a2d94d92f5b462d64aa33cdef8e0a0c0ae2297ae Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Sep 2004 20:50:24 +0300 Subject: [PATCH 18/44] dict0dict.h, dict0dict.c, row0row.c, pars0opt.c: Fix bug #5180: having a column prefix index in the primary key, and the same column fully in a secondary key could cause an assertion failure in row_build_row_ref() innobase/pars/pars0opt.c: Fix bug #5180: having a column prefix index in the primary key, and the same column fully in a secondary key could cause an assertion failure in row_build_row_ref() innobase/row/row0row.c: Fix bug #5180: having a column prefix index in the primary key, and the same column fully in a secondary key could cause an assertion failure in row_build_row_ref() innobase/dict/dict0dict.c: Fix bug #5180: having a column prefix index in the primary key, and the same column fully in a secondary key could cause an assertion failure in row_build_row_ref() innobase/include/dict0dict.h: Fix bug #5180: having a column prefix index in the primary key, and the same column fully in a secondary key could cause an assertion failure in row_build_row_ref() --- innobase/dict/dict0dict.c | 10 +++++++--- innobase/include/dict0dict.h | 6 ++++-- innobase/pars/pars0opt.c | 13 +++++++++++++ innobase/row/row0row.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index bd07c5abffe..61bf3fae137 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -526,8 +526,10 @@ dict_index_contains_col_or_prefix( } /************************************************************************ -Looks for a matching field in an index. The column and the prefix len have -to be the same. */ +Looks for a matching field in an index. The column has to be the same. The +column in index must be complete, or must contain a prefix longer than the +column in index2. That is, we must be able to construct the prefix in index2 +from the prefix in index. */ ulint dict_index_get_nth_field_pos( @@ -555,7 +557,9 @@ dict_index_get_nth_field_pos( field = dict_index_get_nth_field(index, pos); if (field->col == field2->col - && field->prefix_len == field2->prefix_len) { + && (field->prefix_len == 0 + || (field->prefix_len >= field2->prefix_len + && field2->prefix_len != 0))) { return(pos); } diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h index 835c2c2b2e6..9940be9832d 100644 --- a/innobase/include/dict0dict.h +++ b/innobase/include/dict0dict.h @@ -566,8 +566,10 @@ dict_index_contains_col_or_prefix( dict_index_t* index, /* in: index */ ulint n); /* in: column number */ /************************************************************************ -Looks for a matching field in an index. The column and the prefix len has -to be the same. */ +Looks for a matching field in an index. The column has to be the same. The +column in index must be complete, or must contain a prefix longer than the +column in index2. That is, we must be able to construct the prefix in index2 +from the prefix in index. */ ulint dict_index_get_nth_field_pos( diff --git a/innobase/pars/pars0opt.c b/innobase/pars/pars0opt.c index 5cc2e39b438..51aaf02b736 100644 --- a/innobase/pars/pars0opt.c +++ b/innobase/pars/pars0opt.c @@ -1094,6 +1094,19 @@ opt_clust_access( for (i = 0; i < n_fields; i++) { pos = dict_index_get_nth_field_pos(index, clust_index, i); + ut_a(pos != ULINT_UNDEFINED); + + /* We optimize here only queries to InnoDB's internal system + tables, and they should not contain column prefix indexes. */ + + if (dict_index_get_nth_field(index, pos)->prefix_len != 0 + || dict_index_get_nth_field(clust_index, i) + ->prefix_len != 0) { + fprintf(stderr, +"InnoDB: Error in pars0opt.c: table %s has prefix_len != 0\n", + index->table_name); + } + *(plan->clust_map + i) = pos; ut_ad((pos != ULINT_UNDEFINED) diff --git a/innobase/row/row0row.c b/innobase/row/row0row.c index 680539764fd..f075caa7d75 100644 --- a/innobase/row/row0row.c +++ b/innobase/row/row0row.c @@ -334,6 +334,7 @@ row_build_row_ref( ulint ref_len; ulint pos; byte* buf; + ulint clust_col_prefix_len; ulint i; ut_ad(index && rec && heap); @@ -366,6 +367,22 @@ row_build_row_ref( field = rec_get_nth_field(rec, pos, &len); dfield_set_data(dfield, field, len); + + /* If the primary key contains a column prefix, then the + secondary index may contain a longer prefix of the same + column, or the full column, and we must adjust the length + accordingly. */ + + clust_col_prefix_len = + dict_index_get_nth_field(clust_index, i)->prefix_len; + + if (clust_col_prefix_len > 0) { + if (len != UNIV_SQL_NULL + && len > clust_col_prefix_len) { + + dfield_set_len(dfield, clust_col_prefix_len); + } + } } ut_ad(dtuple_check_typed(ref)); @@ -396,6 +413,7 @@ row_build_row_ref_in_tuple( ulint len; ulint ref_len; ulint pos; + ulint clust_col_prefix_len; ulint i; ut_a(ref && index && rec); @@ -433,6 +451,22 @@ row_build_row_ref_in_tuple( field = rec_get_nth_field(rec, pos, &len); dfield_set_data(dfield, field, len); + + /* If the primary key contains a column prefix, then the + secondary index may contain a longer prefix of the same + column, or the full column, and we must adjust the length + accordingly. */ + + clust_col_prefix_len = + dict_index_get_nth_field(clust_index, i)->prefix_len; + + if (clust_col_prefix_len > 0) { + if (len != UNIV_SQL_NULL + && len > clust_col_prefix_len) { + + dfield_set_len(dfield, clust_col_prefix_len); + } + } } ut_ad(dtuple_check_typed(ref)); From e84eb55a0778ca62490c79136b9a09379b02773a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2004 12:07:59 +0100 Subject: [PATCH 19/44] Bug#5553 - Multi table UPDATE IGNORE fails on dup key We don't want the update to abort when IGNORE is specified mysql-test/r/update.result: Bug#5553 - UPDATE IGNORE fails on dup key New test mysql-test/t/update.test: Bug#5553 - UPDATE IGNORE fails on dup key New test BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted --- BitKeeper/etc/logging_ok | 1 + mysql-test/r/update.result | 37 +++++++++++++++++++++++++++++++++++++ mysql-test/t/update.test | 33 +++++++++++++++++++++++++++++++++ sql/sql_update.cc | 8 ++++++-- 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index d65810bb708..d427be619b8 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -9,6 +9,7 @@ acurtis@pcgem.rdg.cyberkinetica.com ahlentz@co3064164-a.rochd1.qld.optusnet.com.au akishkin@work.mysql.com antony@ltantony.dsl-verizon.net +antony@ltantony.rdg.cyberkinetica.homeunix.net arjen@bitbike.com arjen@co3064164-a.bitbike.com arjen@fred.bitbike.com diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result index 11aff8fe50a..c9405d71237 100644 --- a/mysql-test/r/update.result +++ b/mysql-test/r/update.result @@ -166,3 +166,40 @@ F1 F2 F3 cnt groupid 2 0 1 2 4 2 2 0 1 7 drop table t1; +CREATE TABLE t1 ( +`colA` int(10) unsigned NOT NULL auto_increment, +`colB` int(11) NOT NULL default '0', +PRIMARY KEY (`colA`) +); +INSERT INTO t1 VALUES (4433,5424); +CREATE TABLE t2 ( +`colC` int(10) unsigned NOT NULL default '0', +`colA` int(10) unsigned NOT NULL default '0', +`colD` int(10) unsigned NOT NULL default '0', +`colE` int(10) unsigned NOT NULL default '0', +`colF` int(10) unsigned NOT NULL default '0', +PRIMARY KEY (`colC`,`colA`,`colD`,`colE`) +); +INSERT INTO t2 VALUES (3,4433,10005,495,500); +INSERT INTO t2 VALUES (3,4433,10005,496,500); +INSERT INTO t2 VALUES (3,4433,10009,494,500); +INSERT INTO t2 VALUES (3,4433,10011,494,500); +INSERT INTO t2 VALUES (3,4433,10005,497,500); +INSERT INTO t2 VALUES (3,4433,10013,489,500); +INSERT INTO t2 VALUES (3,4433,10005,494,500); +INSERT INTO t2 VALUES (3,4433,10005,493,500); +INSERT INTO t2 VALUES (3,4433,10005,492,500); +UPDATE IGNORE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0 AND (colE + 1) < colF; +SELECT * FROM t2; +colC colA colD colE colF +3 4433 10005 495 500 +3 4433 10005 496 500 +3 4433 10009 495 0 +3 4433 10011 495 0 +3 4433 10005 498 0 +3 4433 10013 490 0 +3 4433 10005 494 500 +3 4433 10005 493 500 +3 4433 10005 492 500 +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index 2e739dd927d..1850564418c 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -122,3 +122,36 @@ insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6), delete from t1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3); select * from t1; drop table t1; + +# +# Bug#5553 - Multi table UPDATE IGNORE fails on duplicate keys +# + +CREATE TABLE t1 ( + `colA` int(10) unsigned NOT NULL auto_increment, + `colB` int(11) NOT NULL default '0', + PRIMARY KEY (`colA`) +); +INSERT INTO t1 VALUES (4433,5424); +CREATE TABLE t2 ( + `colC` int(10) unsigned NOT NULL default '0', + `colA` int(10) unsigned NOT NULL default '0', + `colD` int(10) unsigned NOT NULL default '0', + `colE` int(10) unsigned NOT NULL default '0', + `colF` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`colC`,`colA`,`colD`,`colE`) +); +INSERT INTO t2 VALUES (3,4433,10005,495,500); +INSERT INTO t2 VALUES (3,4433,10005,496,500); +INSERT INTO t2 VALUES (3,4433,10009,494,500); +INSERT INTO t2 VALUES (3,4433,10011,494,500); +INSERT INTO t2 VALUES (3,4433,10005,497,500); +INSERT INTO t2 VALUES (3,4433,10013,489,500); +INSERT INTO t2 VALUES (3,4433,10005,494,500); +INSERT INTO t2 VALUES (3,4433,10005,493,500); +INSERT INTO t2 VALUES (3,4433,10005,492,500); +UPDATE IGNORE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0 AND (colE + 1) < colF; +SELECT * FROM t2; +DROP TABLE t1; +DROP TABLE t2; + diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 02d2fe2c442..d51c81ee127 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -792,9 +792,13 @@ bool multi_update::send_data(List ¬_used_values) if ((error=table->file->update_row(table->record[1], table->record[0]))) { - table->file->print_error(error,MYF(0)); updated--; - DBUG_RETURN(1); + if (handle_duplicates != DUP_IGNORE || + error != HA_ERR_FOUND_DUPP_KEY) + { + table->file->print_error(error,MYF(0)); + DBUG_RETURN(1); + } } } } From cf51de6dc4d78eea73baba01db5502ba61817ca2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2004 17:16:02 +0300 Subject: [PATCH 20/44] InnoDB: Corrected typos in DBUG_ statements sql/ha_innodb.cc: Corrected typos in DBUG_ statements --- sql/ha_innodb.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index b9d898d5bd1..f149af85b3f 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -3049,7 +3049,7 @@ ha_innobase::index_last( { int error; - DBUG_ENTER("index_first"); + DBUG_ENTER("index_last"); statistic_increment(ha_read_last_count, &LOCK_status); error = index_read(buf, NULL, 0, HA_READ_BEFORE_KEY); @@ -4110,7 +4110,7 @@ ha_innobase::info( if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - return; + DBUG_VOID_RETURN; } /* We do not know if MySQL can call this function before calling From d7281b331a79d1e2e3f026bbf71660006ee6df0b Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Sep 2004 13:06:44 +0400 Subject: [PATCH 21/44] Fix for bug #5595: NULLIF() IS NULL returns false if NULLIF() returns NULL --- mysql-test/r/func_if.result | 3 +++ mysql-test/t/func_if.test | 4 ++++ sql/item_cmpfunc.cc | 9 +++++++++ sql/item_cmpfunc.h | 1 + 4 files changed, 17 insertions(+) diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result index aee54ede324..72226588de3 100644 --- a/mysql-test/r/func_if.result +++ b/mysql-test/r/func_if.result @@ -64,3 +64,6 @@ select if(1>2,a,avg(a)) from t1; if(1>2,a,avg(a)) 1.5000 drop table t1; +SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL; +NULLIF(5,5) IS NULL NULLIF(5,5) IS NOT NULL +1 0 diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index 5e605dbe97b..f78cb5ade55 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -47,3 +47,7 @@ insert t1 values (1),(2); select if(1>2,a,avg(a)) from t1; drop table t1; +# +# Bug #5595 NULLIF() IS NULL returns false if NULLIF() returns NULL +# +SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 013304d9df5..fbc1ad97e76 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -654,6 +654,15 @@ Item_func_nullif::val_str(String *str) return res; } + +bool +Item_func_nullif::is_null() +{ + if (!(this->*cmp_func)()) + return null_value=1; + return 0; +} + /* CASE expression Return the matching ITEM or NULL if all compares (including else) failed diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 236ebb8d28b..8f1aa525190 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -240,6 +240,7 @@ public: void fix_length_and_dec(); const char *func_name() const { return "nullif"; } table_map not_null_tables() const { return 0; } + bool is_null(); }; From a7919a11fcb3a52246158aba3193d0128baff344 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Sep 2004 20:33:39 +0200 Subject: [PATCH 22/44] bug#2831 - --extenral-locking does not fully work with --myisam-recover. Changed the semantics of open_count so that it is decremented at every unlock (if it was incremented due to data changes). So it indicates a crash, if it is non-zero after a lock. The table will then be repaired. myisam/mi_close.c: bug#2831 - --extenral-locking does not fully work with --myisam-recover. To avoid flushing the open_count at every unlock, we need to do so at close at least. myisam/mi_locking.c: bug#2831 - --extenral-locking does not fully work with --myisam-recover. open_count is now decremented at unlock (from a writelock) with mi_unlock_open_count(). After every new lock the state is read from the index file and the open_count checked. If not zero, another server must have crashed, so the table is marked as crashed. In certain situations the decremented open_count mut be flushed to the index file. I tried to keep these extra flushes as seldom as possible. sql/ha_myisam.cc: bug#2831 - --extenral-locking does not fully work with --myisam-recover. Added code to repair the table, if it is marked crashed after successful locking and the --myisam-recover option is set. sql/sql_table.cc: This does not really belong to the bugfix for #2831. But it was detected during fixing the external locking. --- myisam/mi_close.c | 3 +- myisam/mi_locking.c | 83 ++++++++++++++++++++++++++++++++++++++++++--- sql/ha_myisam.cc | 24 +++++++++++-- sql/sql_table.cc | 12 +++++-- 4 files changed, 111 insertions(+), 11 deletions(-) diff --git a/myisam/mi_close.c b/myisam/mi_close.c index dbaaebb1143..47308a5e9eb 100644 --- a/myisam/mi_close.c +++ b/myisam/mi_close.c @@ -70,7 +70,8 @@ int mi_close(register MI_INFO *info) error=my_errno; if (share->kfile >= 0) { - if (share->mode != O_RDONLY && mi_is_crashed(info)) + /* We must always flush the state with the current open_count. */ + if (share->mode != O_RDONLY) mi_state_info_write(share->kfile, &share->state, 1); if (my_close(share->kfile,MYF(0))) error = my_errno; diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c index f3bfa8deb90..8a140a8b6fb 100644 --- a/myisam/mi_locking.c +++ b/myisam/mi_locking.c @@ -26,6 +26,9 @@ #include #endif +static int mi_unlock_open_count(MI_INFO *info, my_bool write_info); + + /* lock table by F_UNLCK, F_RDLCK or F_WRLCK */ int mi_lock_database(MI_INFO *info, int lock_type) @@ -35,7 +38,12 @@ int mi_lock_database(MI_INFO *info, int lock_type) MYISAM_SHARE *share=info->s; uint flag; DBUG_ENTER("mi_lock_database"); - DBUG_PRINT("info",("lock_type: %d", lock_type)); + DBUG_PRINT("enter",("mi_lock_database: lock_type %d, old lock %d" + ", r_locks %u, w_locks %u", lock_type, + info->lock_type, share->r_locks, share->w_locks)); + DBUG_PRINT("enter",("mi_lock_database: gl._changed %d, open_count %u '%s'", + share->global_changed, share->state.open_count, + share->index_file_name)); if (share->options & HA_OPTION_READ_ONLY_DATA || info->lock_type == lock_type) @@ -54,7 +62,6 @@ int mi_lock_database(MI_INFO *info, int lock_type) { switch (lock_type) { case F_UNLCK: - DBUG_PRINT("info", ("old lock: %d", info->lock_type)); if (info->lock_type == F_RDLCK) count= --share->r_locks; else @@ -83,7 +90,8 @@ int mi_lock_database(MI_INFO *info, int lock_type) share->state.process= share->last_process=share->this_process; share->state.unique= info->last_unique= info->this_unique; share->state.update_count= info->last_loop= ++info->this_loop; - if (mi_state_info_write(share->kfile, &share->state, 1)) + if (mi_unlock_open_count(info, FALSE) || + mi_state_info_write(share->kfile, &share->state, 1)) error=my_errno; share->changed=0; if (myisam_flush) @@ -98,6 +106,19 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (error) mi_mark_crashed(info); } + else + { + /* + There are chances that _mi_mark_file_changed() has been called, + while share->changed remained FALSE. Consequently, we need to + clear the open_count even when share->changed is FALSE. Note, + that mi_unlock_open_count() will only clear the open_count when + it is set and only write the status to file, if it changes it + and we are running --with-external-locking. + */ + if (mi_unlock_open_count(info, ! my_disable_locking)) + error= my_errno; + } if (info->lock_type != F_EXTRA_LCK) { if (share->r_locks) @@ -122,10 +143,15 @@ int mi_lock_database(MI_INFO *info, int lock_type) case F_RDLCK: if (info->lock_type == F_WRLCK) { /* Change RW to READONLY */ + /* + mysqld does not turn write locks to read locks, + so we're never here in mysqld. + */ if (share->w_locks == 1) { flag=1; - if (my_lock(share->kfile,lock_type,0L,F_TO_EOF, + if (mi_unlock_open_count(info, ! my_disable_locking) || + my_lock(share->kfile,lock_type,0L,F_TO_EOF, MYF(MY_SEEK_NOT_DONE))) { error=my_errno; @@ -153,6 +179,14 @@ int mi_lock_database(MI_INFO *info, int lock_type) my_errno=error; break; } + if (share->state.open_count) + { + DBUG_PRINT("error",("RD: Table has not been correctly unlocked" + ": open_count %d '%s'", + share->state.open_count, + share->index_file_name)); + mi_mark_crashed(info); + } } VOID(_mi_test_if_changed(info)); share->r_locks++; @@ -198,6 +232,14 @@ int mi_lock_database(MI_INFO *info, int lock_type) my_errno=error; break; } + if (share->state.open_count) + { + DBUG_PRINT("error",("WR: Table has not been correctly unlocked" + ": open_count %d '%s'", + share->state.open_count, + share->index_file_name)); + mi_mark_crashed(info); + } } } } @@ -459,3 +501,36 @@ int _mi_decrement_open_count(MI_INFO *info) } return test(lock_error || write_error); } + +/* + Decrement open_count in preparation for unlock. + + SYNOPSIS + mi_unlock_open_count() + info Pointer to the MI_INFO structure. + write_info If info must be written when changed. + + RETURN + 0 OK +*/ + +static int mi_unlock_open_count(MI_INFO *info, my_bool write_info) +{ + int rc= 0; + MYISAM_SHARE *share=info->s; + + DBUG_ENTER("mi_unlock_open_count"); + DBUG_PRINT("enter",("mi_unlock_open_count: gl._changed %d open_count %d '%s'", + share->global_changed, share->state.open_count, + share->index_file_name)); + if (share->global_changed) + { + share->global_changed= 0; + if (share->state.open_count) + share->state.open_count--; + if (write_info) + rc= _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); + } + DBUG_RETURN(rc); +} + diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index d5bbf9b5a92..2b7b8f436b1 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -1000,9 +1000,27 @@ int ha_myisam::delete_table(const char *name) int ha_myisam::external_lock(THD *thd, int lock_type) { - return mi_lock_database(file, !table->tmp_table ? - lock_type : ((lock_type == F_UNLCK) ? - F_UNLCK : F_EXTRA_LCK)); + int rc; + + while ((! (rc= mi_lock_database(file, !table->tmp_table ? + lock_type : ((lock_type == F_UNLCK) ? + F_UNLCK : F_EXTRA_LCK)))) && + mi_is_crashed(file) && (myisam_recover_options != HA_RECOVER_NONE)) + { + /* + check_and_repair() implicitly write locks the table, unless a + LOCK TABLES is in effect. It should be safer to always write lock here. + The implicit lock by check_and_repair() will then be a no-op. + check_and_repair() does not restore the original lock, but unlocks the + table. So we have to get the requested lock type again. And then to + check, if the table has been crashed again meanwhile by another server. + If anything fails, we break. + */ + if (((lock_type != F_WRLCK) && (rc= mi_lock_database(file, F_WRLCK))) || + (rc= check_and_repair(thd))) + break; + } + return rc; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e2e186abb0d..0dd5c65bf79 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2208,7 +2208,12 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (!(copy= new Copy_field[to->fields])) DBUG_RETURN(-1); /* purecov: inspected */ - to->file->external_lock(thd,F_WRLCK); + if (to->file->external_lock(thd, F_WRLCK)) + { + /* We must always unlock, even when lock failed. */ + (void) to->file->external_lock(thd, F_UNLCK); + DBUG_RETURN(-1); + } to->file->extra(HA_EXTRA_WRITE_CACHE); from->file->info(HA_STATUS_VARIABLE); to->file->deactivate_non_unique_index(from->file->records); @@ -2308,11 +2313,12 @@ copy_data_between_tables(TABLE *from,TABLE *to, error=1; if (ha_commit(thd)) error=1; - if (to->file->external_lock(thd,F_UNLCK)) - error=1; err: free_io_cache(from); *copied= found_count; *deleted=delete_count; + /* we must always unlock the table on return. */ + if (to->file->external_lock(thd,F_UNLCK)) + error=1; DBUG_RETURN(error > 0 ? -1 : 0); } From 0e0a508d5df9ea2247ef95ec38797e71f735f0ca Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Sep 2004 14:48:41 +0400 Subject: [PATCH 23/44] Change www.mysql.com -> dev.mysql.com in a reference to how to resolve stack trace documentation. --- sql/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/stacktrace.c b/sql/stacktrace.c index 73a7ecdc7ba..fa9ab093f26 100644 --- a/sql/stacktrace.c +++ b/sql/stacktrace.c @@ -197,7 +197,7 @@ terribly wrong...\n"); fprintf(stderr, "Stack trace seems successful - bottom reached\n"); end: - fprintf(stderr, "Please read http://www.mysql.com/doc/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved\n\ + fprintf(stderr, "Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved\n\ stack trace is much more helpful in diagnosing the problem, so please do \n\ resolve it\n"); } From 946625d71d270797481e62f97e1447b57e47cac3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Sep 2004 16:15:01 +0500 Subject: [PATCH 24/44] A fix (Bug #5415: Table marked as crashed after DELETE queries). --- sql/sql_delete.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 555e63b9e32..92193e3abf2 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -282,6 +282,8 @@ multi_delete::initialize_tables(JOIN *join) walk=walk->next; /* Don't use KEYREAD optimization on this table */ tbl->no_keyread=1; + /* Don't use record cache */ + tbl->no_cache= 1; tbl->used_keys= 0; if (tbl->file->has_transactions()) log_delayed= transactional_tables= 1; From e4e919f99fd401f53e67dc36f6b9012a6793374e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Sep 2004 17:58:11 +0200 Subject: [PATCH 25/44] When coyright text is changed, autotools must be run after all other actions, as otherwise timestamps of "config.h.in" will cause re-run on compilation machine (fatal version problem!). Build-tools/mysql-copyright: 1) Ensure that autotools are run as last action, after copyright change, for proper timestamps. 2) Move the trimming of subtrees to an own function "trim_the_fat". 3) Align 4.0 and 4.1 versions. --- Build-tools/mysql-copyright | 140 ++++++++++++++++++++++++++++-------- 1 file changed, 112 insertions(+), 28 deletions(-) diff --git a/Build-tools/mysql-copyright b/Build-tools/mysql-copyright index a1869304ba7..251a6c78d23 100755 --- a/Build-tools/mysql-copyright +++ b/Build-tools/mysql-copyright @@ -1,9 +1,9 @@ -#!/usr/bin/perl -i +#!/usr/bin/perl -wi # Untar a MySQL distribution, change the copyright texts, # pack it up again to a given directory -$VER="1.3"; +$VER="1.4"; use Cwd; use File::Basename; @@ -79,7 +79,7 @@ sub main $newdistname .= $suffix if $win_flag; } # find out the extract path (should be same as distname!) - chomp($destdir = `tar ztf ../$distfile | head -1`); + chomp($destdir= `tar ztf ../$distfile | head -1`); # remove slash from the end $destdir= substr($destdir, 0, -1); @@ -104,37 +104,25 @@ sub main unlink("$destdir/COPYING", "$destdir/EXCEPTIONS-CLIENT"); copy("$WD/Docs/MySQLEULA.txt", "$destdir"); - # remove readline subdir and update configure accordingly - system("rm -rf $destdir/cmd-line-utils/readline"); - if ($win_flag) { - chdir("$destdir") or (print "$! Unable to change directory to $destdir!\n" && exit(0)); - } else { - chdir("$destdir"); - unlink ("configure") or die "Can't delete $destdir/configure: $!\n"; - open(CONFIGURE,"; - close(CONFIGURE); - $configure =~ s|cmd\-line\-utils/readline/Makefile dnl\n?||g; - open(CONFIGURE,">configure.in") or die "$! Unable to open configure.in to write to!\n"; - print CONFIGURE $configure; - close(CONFIGURE); - `aclocal && autoheader && aclocal && automake && autoconf`; - if (! -f "configure") { - print "\"./configure\" was not produced, exiting!\n"; - exit(0); - } - if (-d "autom4te.cache") { - print "Trying to delete autom4te.cache dir\n" if $opt_verbose; - system("rm -rf autom4te.cache") or print "Unable to delete autom4te.cache dir: $!\n"; - } + # remove subdirectories 'bdb', 'cmd-line-utils/readline' + # (latter does not apply to 4.0, but is in different place there!) + my @extra_fat= ('bdb', 'cmd-line-utils/readline'); + + foreach my $fat (@extra_fat) + { + &trim_the_fat($fat); } # fix file copyrights &fix_usage_copyright(); &add_copyright(); + # fix LICENSE tag in include/mysql_version.h + &fix_mysql_version(); + + # apply "autotools" - must be last to ensure proper timestamps + &run_autotools(); + # rename the directory with new distribution name chdir("$WD/$dir"); print "renaming $destdir $newdistname\n" if $opt_verbose; @@ -160,6 +148,101 @@ sub main exit(0); } +#### +#### This function will s/GPL/Commercial/ in include/mysql_version.h for the +#### LICENSE tag. +#### +sub fix_mysql_version +{ + my $cwd= getcwd(); + chdir("$destdir"); + my $header_file= (-f 'include/mysql_version.h.in')? 'include/mysql_version.h.in' : 'include/mysql_version.h'; + + open(MYSQL_VERSION,"<$header_file") or die "Unable to open $header_file for read: $!\n"; + undef $/; + my $mysql_version= ; + close(MYSQL_VERSION); + + $mysql_version=~ s/\#define LICENSE[\s\t]+GPL/#define LICENSE Commercial/; + + open(MYSQL_VERSION,">$header_file") or die "Unable to open $header_file for write: $!\n"; + print MYSQL_VERSION $mysql_version; + close(MYSQL_VERSION); + chdir("$cwd"); +} + +#### +#### This function will remove unwanted parts of a src tree for the mysqlcom +#### distributions. +#### +sub trim_the_fat +{ + my $the_fat= shift; + my $cwd= getcwd(); + + chdir("$destdir"); + if ( -d "${the_fat}" ) + { + system("rm -rf ${the_fat}"); + if (!$win_flag) + { + open(CONFIG_IN,"; + close(CONFIG_IN); + + # + # If $the_fat Makefile line closes the parenthesis, then + # replace that line with just the closing parenthesis. + # + if ($config_in=~ m|${the_fat}/Makefile\)\n?|) + { + $config_in=~ s|${the_fat}/Makefile(\)\n?)|$1|; + } + # + # Else just delete the line + # + else + { + $config_in=~ s|${the_fat}/Makefile dnl\n?||; + } + + open(CONFIG_IN,">configure.in") or die "Unable to open configure.in for write: $!\n"; + print CONFIG_IN $config_in; + close(CONFIG_IN); + } + } + chdir("$cwd"); +} + + +#### +#### This function will run the autotools on the reduced source tree. +#### +sub run_autotools +{ + my $cwd= getcwd(); + + if (!$win_flag) + { + chdir("$destdir"); + unlink ("configure") or die "Can't delete $destdir/configure: $!\n"; + + # File "configure.in" has already been modified by "trim_the_fat()" + + `aclocal && autoheader && aclocal && automake && autoconf`; + die "'./configure' was not produced!" unless (-f "configure"); + + if (-d "autom4te.cache") { + print "Trying to delete autom4te.cache dir\n" if $opt_verbose; + system("rm -rf autom4te.cache") or print "Unable to delete autom4te.cache dir: $!\n"; + } + + chdir("$cwd"); + } +} + + #### #### mysqld and MySQL client programs have a usage printed with --help. #### This usage includes a copyright, which needs to be modified @@ -191,6 +274,7 @@ sub add_copyright foreach my $file (@files) { next if ! -f $file; + next if -B $file; print "processing file $file in cwd $cwd\n" if $opt_verbose; `$WD/Build-tools/mysql-copyright-2 "$file"`; } From 9427b26e822690a903dfae38c93483e87a115d75 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Sep 2004 11:28:37 +0100 Subject: [PATCH 26/44] Bug#5655 - mysqldump fields-escaped-by behaviour Fix initialization client/mysqldump.c: Bug#5655 - mysqldump fields-escaped-by behaviour Fix for parameter --- client/mysqldump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 6dad8182b87..49822f0bee0 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -150,7 +150,7 @@ static struct my_option my_long_options[] = "Fields in the i.file are opt. enclosed by ...", (gptr*) &opt_enclosed, (gptr*) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0}, {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...", - (gptr*) &escaped, (gptr*) &escaped, 0, GET_STR, NO_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) &escaped, (gptr*) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"first-slave", 'x', "Locks all tables across all databases.", (gptr*) &opt_first_slave, (gptr*) &opt_first_slave, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, From 4063fd2c726a71ed0c9fd7052650f6f0feaaaac7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Sep 2004 16:29:15 +0400 Subject: [PATCH 27/44] Fix for BUG#4785: * myisampack leaves key_file_length value from original table * myisamchk uses this value when calculating key file pointer length --- include/myisam.h | 1 + myisam/mi_check.c | 2 +- myisam/mi_create.c | 13 +++++++++---- myisam/myisampack.c | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/myisam.h b/include/myisam.h index 87a40b50c73..cad48e2d331 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -96,6 +96,7 @@ typedef struct st_mi_create_info ha_rows reloc_rows; ulonglong auto_increment; ulonglong data_file_length; + ulonglong key_file_length; uint raid_type,raid_chunks; ulong raid_chunksize; uint old_options; diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 078f7787dc3..e78d831fde7 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -3520,7 +3520,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) create_info.raid_chunksize= share.base.raid_chunksize; create_info.language = (param->language ? param->language : share.state.header.language); - + create_info.key_file_length= status_info.key_file_length; /* We don't have to handle symlinks here because we are using HA_DONT_TOUCH_DATA */ if (mi_create(filename, diff --git a/myisam/mi_create.c b/myisam/mi_create.c index 328450c70db..99e9ca5ba5f 100644 --- a/myisam/mi_create.c +++ b/myisam/mi_create.c @@ -46,7 +46,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, ulong reclength, real_reclength,min_pack_length; char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr; ulong pack_reclength; - ulonglong tot_length,max_rows; + ulonglong tot_length,max_rows, tmp; enum en_fieldtype type; MYISAM_SHARE share; MI_KEYDEF *keydef,tmp_keydef; @@ -442,10 +442,15 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, share.state.auto_increment=ci->auto_increment; share.options=options; share.base.rec_reflength=pointer; + /* Get estimate for index file length (this may be wrong for FT keys) */ + tmp= (tot_length + max_key_block_length * keys * + MI_INDEX_BLOCK_MARGIN) / MI_MIN_KEY_BLOCK_LENGTH; + /* + use maximum of key_file_length we calculated and key_file_length value we + got from MYI file header (see also myisampack.c:save_state) + */ share.base.key_reflength= - mi_get_pointer_length((tot_length + max_key_block_length * keys * - MI_INDEX_BLOCK_MARGIN) / MI_MIN_KEY_BLOCK_LENGTH, - 3); + mi_get_pointer_length(max(ci->key_file_length,tmp),3); share.base.keys= share.state.header.keys = keys; share.state.header.uniques= uniques; mi_int2store(share.state.header.key_parts,key_segs); diff --git a/myisam/myisampack.c b/myisam/myisampack.c index 872fcb49faf..4b784641266 100644 --- a/myisam/myisampack.c +++ b/myisam/myisampack.c @@ -2041,7 +2041,11 @@ static int save_state(MI_INFO *isam_file,PACK_MRG_INFO *mrg,my_off_t new_length, share->state.split=(ha_rows) mrg->records; share->state.version=(ulong) time((time_t*) 0); share->state.key_map=0; - share->state.state.key_file_length=share->base.keystart; + /* + Don't save key_file_length here, keep key_file_length of original file + so "myisamchk -rq" can use this value (this is necessary because index + size cannot be easily calculated for fulltext keys) + */ for (key=0 ; key < share->base.keys ; key++) share->state.key_root[key]= HA_OFFSET_ERROR; for (key=0 ; key < share->state.header.max_block_size ; key++) From 0e6975f33ba434ccd884b8c3ebae36332c000a94 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 23 Sep 2004 14:43:31 +0200 Subject: [PATCH 28/44] Fix for BUG#5711 "replication SQL thread does not abort on SQL syntax error": in net_printf(), we fill net->last_* variables for the slave SQL thread to know the error. sql/net_pkg.cc: in net_printf(), store the error in net->last_*, so that slave SQL thread can be aware there was an error reported by net_printf() (which is what yacc uses for "you have an error in your syntax"). --- sql/net_pkg.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc index cc9147fe90a..df77d0347f2 100644 --- a/sql/net_pkg.cc +++ b/sql/net_pkg.cc @@ -132,6 +132,10 @@ net_printf(NET *net, uint errcode, ...) length=sizeof(net->last_error)-1; /* purecov: inspected */ va_end(args); + /* Replication slave relies on net->last_* to see if there was error */ + net->last_errno= errcode; + strmake(net->last_error, text_pos, sizeof(net->last_error)-1); + if (net->vio == 0) { if (thd && thd->bootstrap) From b2307545cb9412fc4896c487495889979efa7d7b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 23 Sep 2004 17:53:46 +0200 Subject: [PATCH 29/44] os0file.c: Added #ifdef around is_set in os_aio_print innobase/os/os0file.c: Added #ifdef around is_set in os_aio_print --- innobase/os/os0file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 70ef8f55b98..b09c48319c3 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -2965,9 +2965,11 @@ os_aio_print( srv_io_thread_op_info[i], srv_io_thread_function[i]); +#ifndef __WIN__ if (os_aio_segment_wait_events[i]->is_set) { fprintf(file, " ev set"); } +#endif fprintf(file, "\n"); } From ecd3172b00270cc53310e9eb7a009a2a44495a7e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Sep 2004 09:00:14 +0200 Subject: [PATCH 30/44] Bug #5539 SHOW DATABASES LIKE and symlinks sql_show.cc: Added wild card check to symdir block in mysql_find_files sql/sql_show.cc: Added wild card check to symdir block in mysql_find_files --- sql/sql_show.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6784cd64465..d82af1a6242 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -204,7 +204,8 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, if (end != buff && end[-1] == FN_LIBCHAR) end[-1]= 0; // Remove end FN_LIBCHAR if (!my_stat(buff, &status, MYF(0)) || - !MY_S_ISDIR(status.st_mode)) + !MY_S_ISDIR(status.st_mode) || + (wild && wild_compare(file->name, wild, 0))) continue; } else From c868213373782dc172a6d279d4d3d8ef45cdbc57 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Sep 2004 11:54:37 +0200 Subject: [PATCH 31/44] Fix for BUG#3248 "Doc says MyISAM warns if disk full but it does not": we force the message to the error log, and we make it more informative; we treat EDQUOT like ENOSPC. mysys/errors.c: more informative message mysys/my_fstream.c: Treat EDQUOT like ENOSPC. mysys/my_pread.c: Treat EDQUOT like ENOSPC. mysys/my_write.c: Treat EDQUOT like ENOSPC. mysys/mysys_priv.h: Define EDQUOT when it does not exist. Finally decided to put it here after discussion with Monty: as this constant is used only in 3 files only in mysys/, I don't make it visible everywhere (there currently is no file of choice for such defines; my_base.h does not contain any). Using a value which never happens avoids collisions. sql/mysqld.cc: If ME_NOREFRESH, we write message to error log, even if it has been saved for client (because if operation is hanging, the message does not get to client now; example is MyISAM waiting for free disk space). --- mysys/errors.c | 2 +- mysys/my_fstream.c | 14 ++++++++------ mysys/my_pread.c | 9 +++++---- mysys/my_write.c | 5 +++-- mysys/mysys_priv.h | 8 ++++++++ sql/mysqld.cc | 5 ++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/mysys/errors.c b/mysys/errors.c index 7d755718b16..e21609f6e94 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -41,7 +41,7 @@ const char * NEAR globerrs[GLOBERRS]= "Can't change dir to '%s' (Errcode: %d)", "Warning: '%s' had %d links", "%d files and %d streams is left open\n", - "Disk is full writing '%s'. Waiting for someone to free space...", + "Disk is full writing '%s' (Errcode: %d). Waiting for someone to free space... Retry in %d secs", "Can't create directory '%s' (Errcode: %d)", "Character set '%s' is not a compiled character set and is not specified in the '%s' file", "Out of resources when opening file '%s' (Errcode: %d)", diff --git a/mysys/my_fstream.c b/mysys/my_fstream.c index 94f3aaf3464..0ad789e98ac 100644 --- a/mysys/my_fstream.c +++ b/mysys/my_fstream.c @@ -114,13 +114,15 @@ uint my_fwrite(FILE *stream, const byte *Buffer, uint Count, myf MyFlags) if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ #endif - if (errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) + if ((errno == ENOSPC || errno == EDQUOT) && + (MyFlags & MY_WAIT_IF_FULL)) { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH)); - sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); - continue; + if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) + my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), + "[stream]",my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC); + VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); + VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); + continue; } #endif if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP))) diff --git a/mysys/my_pread.c b/mysys/my_pread.c index 661ef48ab3e..f76233fc4cc 100644 --- a/mysys/my_pread.c +++ b/mysys/my_pread.c @@ -115,11 +115,12 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ #endif - if (my_errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) + if ((my_errno == ENOSPC || my_errno == EDQUOT) && + (MyFlags & MY_WAIT_IF_FULL)) { if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), - my_filename(Filedes)); + my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC); VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); continue; } @@ -131,7 +132,7 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, { if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), + my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), my_filename(Filedes),my_errno); } DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ @@ -142,4 +143,4 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, if (MyFlags & (MY_NABP | MY_FNABP)) DBUG_RETURN(0); /* Want only errors */ DBUG_RETURN(writenbytes+written); /* purecov: inspected */ -} /* my_write */ +} /* my_pwrite */ diff --git a/mysys/my_write.c b/mysys/my_write.c index 61fd6097e28..da378d115f1 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -48,12 +48,13 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags) if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ #endif - if (my_errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL) && + if ((my_errno == ENOSPC || my_errno == EDQUOT) && + (MyFlags & MY_WAIT_IF_FULL) && (uint) writenbytes != (uint) -1) { if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), - my_filename(Filedes)); + my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC); VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); continue; } diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index f79431a0b0b..d7aee04ae20 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -29,3 +29,11 @@ extern pthread_mutex_t THR_LOCK_charset; #else #include #endif + +/* + EDQUOT is used only in 3 C files only in mysys/. If it does not exist on + system, we set it to some value which can never happen. +*/ +#ifndef EDQUOT +#define EDQUOT (-1) +#endif diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 06599cf0ea7..834cff0d869 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2080,8 +2080,7 @@ static void check_data_home(const char *path) /* ARGSUSED */ -extern "C" int my_message_sql(uint error, const char *str, - myf MyFlags __attribute__((unused))) +extern "C" int my_message_sql(uint error, const char *str, myf MyFlags) { NET *net; DBUG_ENTER("my_message_sql"); @@ -2094,7 +2093,7 @@ extern "C" int my_message_sql(uint error, const char *str, net->last_errno=error ? error : ER_UNKNOWN_ERROR; } } - else + if (!net || MyFlags & ME_NOREFRESH) sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */ DBUG_RETURN(0); } From 697cb7b106d74c047e616f9129129a9eea87ac95 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Sep 2004 18:39:25 +0200 Subject: [PATCH 32/44] BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Reworked the HANDLER functions and interface. Using a HASH to store information on open tables that survives FLUSH TABLE. HANDLER tables alias names must now be unique, though it is allowed in 4.0 to qualify them with the database name of the base table. mysql-test/r/flush_table.result: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Moved pure handler test results to handler.result. Added the new test results. mysql-test/r/handler.result: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Moved pure handler test results from flush_table.result to here. mysql-test/t/flush_table.test: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Moved pure handler tests to handler.test. Added new tests. mysql-test/t/handler.test: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Moved pure handler tests from flush_table.test to here. sql/mysql_priv.h: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Reworked the handler interface. sql/sql_base.cc: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Replaced mysql_ha_close_list() by the better named function mysql_ha_flush() with readable options. sql/sql_class.cc: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Added initialization for the handler tables hash. Changed the handler tables clean-up code. Unreleted to bug: Changed the order of THD initialization to avoid warning messages on Linux with gcc. sql/sql_class.h: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Added the handler tables HASH to THD. sql/sql_handler.cc: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. Completely reworked the handler functions. Added an introducing comment, describing the new functionality. sql/sql_table.cc: BUG#4286 - HANDLER tables are closed by FLUSH TABLE(S). BUG#4335 - one name can be handler open'ed many times. replaced mysql_ha_close() by the better named function mysql_ha_flush() with readable options. --- mysql-test/r/flush_table.result | 101 +++-- mysql-test/r/handler.result | 244 ++++++++++++ mysql-test/t/flush_table.test | 84 ++--- mysql-test/t/handler.test | 204 ++++++++++ sql/mysql_priv.h | 11 +- sql/sql_base.cc | 6 +- sql/sql_class.cc | 15 +- sql/sql_class.h | 1 + sql/sql_handler.cc | 644 +++++++++++++++++++++++--------- sql/sql_table.cc | 6 +- 10 files changed, 999 insertions(+), 317 deletions(-) diff --git a/mysql-test/r/flush_table.result b/mysql-test/r/flush_table.result index cfba428e2e8..ff69291193f 100644 --- a/mysql-test/r/flush_table.result +++ b/mysql-test/r/flush_table.result @@ -7,58 +7,6 @@ check table t1; Table Op Msg_type Msg_text test.t1 check status OK drop table t1; -drop database if exists test_test; -create database test_test; -use test_test; -create table t1(table_id char(20) primary key); -insert into t1 values ('test_test.t1'); -insert into t1 values (''); -handler t1 open; -handler t1 read first limit 9; -table_id -test_test.t1 - -create table t2(table_id char(20) primary key); -insert into t2 values ('test_test.t2'); -insert into t2 values (''); -handler t2 open; -handler t2 read first limit 9; -table_id -test_test.t2 - -use test; -drop table if exists t1; -create table t1(table_id char(20) primary key); -insert into t1 values ('test.t1'); -insert into t1 values (''); -handler t1 open; -handler t1 read first limit 9; -table_id -test.t1 - -use test; -handler test.t1 read first limit 9; -table_id -test.t1 - -handler test.t2 read first limit 9; -Unknown table 't2' in HANDLER -handler test_test.t1 read first limit 9; -table_id -test_test.t1 - -handler test_test.t2 read first limit 9; -table_id -test_test.t2 - -handler test_test.t1 close; -drop table test_test.t1; -handler test_test.t2 close; -drop table test_test.t2; -drop database test_test; -use test; -handler test.t1 close; -drop table test.t1; drop table if exists t1; drop table if exists t2; create table t1(table_id char(20) primary key); @@ -84,14 +32,23 @@ test.t2 flush tables; handler a1 read first limit 9; -Unknown table 'a1' in HANDLER +table_id +test.t1 + handler a2 read first limit 9; -Unknown table 'a2' in HANDLER +table_id +test.t1 + handler t2 read first limit 9; -Unknown table 't2' in HANDLER +table_id +test.t2 + handler t1 open as a1; +Not unique table/alias: 'a1' handler t1 open as a2; +Not unique table/alias: 'a2' handler t2 open; +Not unique table/alias: 't2' handler a1 read first limit 9; table_id test.t1 @@ -106,15 +63,43 @@ test.t2 flush table t1; handler a1 read first limit 9; -Unknown table 'a1' in HANDLER +table_id +test.t1 + handler a2 read first limit 9; -Unknown table 'a2' in HANDLER +table_id +test.t1 + handler t2 read first limit 9; table_id test.t2 flush table t2; handler t2 close; -Unknown table 't2' in HANDLER drop table t1; drop table t2; +create table t1(table_id char(20) primary key); +insert into t1 values ('Record-01'); +insert into t1 values ('Record-02'); +insert into t1 values ('Record-03'); +insert into t1 values ('Record-04'); +insert into t1 values ('Record-05'); +handler t1 open; +handler t1 read first limit 1; +table_id +Record-01 +handler t1 read next limit 1; +table_id +Record-02 +handler t1 read next limit 1; +table_id +Record-03 +flush table t1; +handler t1 read next limit 1; +table_id +Record-01 +handler t1 read next limit 1; +table_id +Record-02 +handler t1 close; +drop table t1; diff --git a/mysql-test/r/handler.result b/mysql-test/r/handler.result index 50d51cf14f4..5af153930d5 100644 --- a/mysql-test/r/handler.result +++ b/mysql-test/r/handler.result @@ -203,3 +203,247 @@ handler t1 read a=(1) where b=1; a b handler t1 close; drop table t1; +drop database if exists test_test; +create database test_test; +use test_test; +create table t1(table_id char(20) primary key); +insert into t1 values ('test_test.t1'); +insert into t1 values (''); +handler t1 open; +handler t1 read first limit 9; +table_id +test_test.t1 + +create table t2(table_id char(20) primary key); +insert into t2 values ('test_test.t2'); +insert into t2 values (''); +handler t2 open; +handler t2 read first limit 9; +table_id +test_test.t2 + +use test; +drop table if exists t1; +create table t1(table_id char(20) primary key); +insert into t1 values ('test.t1'); +insert into t1 values (''); +handler t1 open; +Not unique table/alias: 't1' +use test; +handler test.t1 read first limit 9; +Unknown table 'test.t1' in HANDLER +handler test_test.t1 read first limit 9; +table_id +test_test.t1 + +handler t1 read first limit 9; +table_id +test_test.t1 + +handler test_test.t2 read first limit 9; +table_id +test_test.t2 + +handler t2 read first limit 9; +table_id +test_test.t2 + +handler test_test.t1 close; +handler t1 close; +Unknown table 't1' in HANDLER +drop table test_test.t1; +handler test_test.t2 close; +handler t2 close; +Unknown table 't2' in HANDLER +drop table test_test.t2; +drop database test_test; +use test; +handler test.t1 close; +Unknown table 'test.t1' in HANDLER +handler t1 close; +Unknown table 't1' in HANDLER +drop table test.t1; +drop database if exists test_test; +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +create database test_test; +use test_test; +create table t1 (c1 char(20)); +insert into t1 values ('test_test.t1'); +create table t3 (c1 char(20)); +insert into t3 values ('test_test.t3'); +handler t1 open; +handler t1 read first limit 9; +c1 +test_test.t1 +handler t1 open h1; +handler h1 read first limit 9; +c1 +test_test.t1 +use test; +create table t1 (c1 char(20)); +create table t2 (c1 char(20)); +create table t3 (c1 char(20)); +insert into t1 values ('t1'); +insert into t2 values ('t2'); +insert into t3 values ('t3'); +handler t1 open; +Not unique table/alias: 't1' +handler t2 open t1; +Not unique table/alias: 't1' +handler t3 open t1; +Not unique table/alias: 't1' +handler t1 read first limit 9; +c1 +test_test.t1 +handler test.t1 close; +Unknown table 'test.t1' in HANDLER +handler test.t1 open h1; +Not unique table/alias: 'h1' +handler test_test.t1 open h1; +Not unique table/alias: 'h1' +handler test_test.t3 open h3; +handler test.t1 open h2; +handler t1 read first limit 9; +c1 +test_test.t1 +handler h1 read first limit 9; +c1 +test_test.t1 +handler h2 read first limit 9; +c1 +t1 +handler h3 read first limit 9; +c1 +test_test.t3 +handler test.h2 read first limit 9; +c1 +t1 +handler test.h1 close; +Unknown table 'test.h1' in HANDLER +handler test_test.t1 close; +handler test_test.h1 close; +handler h2 close; +handler t1 read first limit 9; +Unknown table 't1' in HANDLER +handler h1 read first limit 9; +Unknown table 'h1' in HANDLER +handler h2 read first limit 9; +Unknown table 'h2' in HANDLER +handler h3 read first limit 9; +c1 +test_test.t3 +handler test_test.h3 read first limit 9; +c1 +test_test.t3 +use test_test; +handler h3 read first limit 9; +c1 +test_test.t3 +handler test.h3 read first limit 9; +Unknown table 'test.h3' in HANDLER +handler test_test.h3 close; +use test; +drop table t3; +drop table t2; +drop table t1; +drop database test_test; +create table t1 (c1 char(20)); +insert into t1 values ("t1"); +handler t1 open as h1; +handler h1 read first limit 9; +c1 +t1 +create table t2 (c1 char(20)); +insert into t2 values ("t2"); +handler t2 open as h2; +handler h2 read first limit 9; +c1 +t2 +create table t3 (c1 char(20)); +insert into t3 values ("t3"); +handler t3 open as h3; +handler h3 read first limit 9; +c1 +t3 +create table t4 (c1 char(20)); +insert into t4 values ("t4"); +handler t4 open as h4; +handler h4 read first limit 9; +c1 +t4 +create table t5 (c1 char(20)); +insert into t5 values ("t5"); +handler t5 open as h5; +handler h5 read first limit 9; +c1 +t5 +alter table t1 engine=MyISAM; +handler h1 read first limit 9; +Unknown table 'h1' in HANDLER +handler h2 read first limit 9; +c1 +t2 +handler h3 read first limit 9; +c1 +t3 +handler h4 read first limit 9; +c1 +t4 +handler h5 read first limit 9; +c1 +t5 +alter table t5 engine=MyISAM; +handler h1 read first limit 9; +Unknown table 'h1' in HANDLER +handler h2 read first limit 9; +c1 +t2 +handler h3 read first limit 9; +c1 +t3 +handler h4 read first limit 9; +c1 +t4 +handler h5 read first limit 9; +Unknown table 'h5' in HANDLER +alter table t3 engine=MyISAM; +handler h1 read first limit 9; +Unknown table 'h1' in HANDLER +handler h2 read first limit 9; +c1 +t2 +handler h3 read first limit 9; +Unknown table 'h3' in HANDLER +handler h4 read first limit 9; +c1 +t4 +handler h5 read first limit 9; +Unknown table 'h5' in HANDLER +handler h2 close; +handler h4 close; +handler t1 open as h1_1; +handler t1 open as h1_2; +handler t1 open as h1_3; +handler h1_1 read first limit 9; +c1 +t1 +handler h1_2 read first limit 9; +c1 +t1 +handler h1_3 read first limit 9; +c1 +t1 +alter table t1 engine=MyISAM; +handler h1_1 read first limit 9; +Unknown table 'h1_1' in HANDLER +handler h1_2 read first limit 9; +Unknown table 'h1_2' in HANDLER +handler h1_3 read first limit 9; +Unknown table 'h1_3' in HANDLER +drop table t1; +drop table t2; +drop table t3; +drop table t4; +drop table t5; diff --git a/mysql-test/t/flush_table.test b/mysql-test/t/flush_table.test index ad81f266afc..58c12bad3fa 100644 --- a/mysql-test/t/flush_table.test +++ b/mysql-test/t/flush_table.test @@ -12,63 +12,10 @@ flush table t1; check table t1; drop table t1; -# -# Check if two database names beginning the same are seen as different. -# -# This database begins like the usual 'test' database. -# ---disable_warnings -drop database if exists test_test; ---enable_warnings -create database test_test; -use test_test; -create table t1(table_id char(20) primary key); -insert into t1 values ('test_test.t1'); -insert into t1 values (''); -handler t1 open; -handler t1 read first limit 9; -create table t2(table_id char(20) primary key); -insert into t2 values ('test_test.t2'); -insert into t2 values (''); -handler t2 open; -handler t2 read first limit 9; -# -# This is the usual 'test' database. -# -use test; ---disable_warnings -drop table if exists t1; ---enable_warnings -create table t1(table_id char(20) primary key); -insert into t1 values ('test.t1'); -insert into t1 values (''); -handler t1 open; -handler t1 read first limit 9; -# -# Check accesibility of all the tables. -# -use test; -handler test.t1 read first limit 9; ---error 1109; -handler test.t2 read first limit 9; -handler test_test.t1 read first limit 9; -handler test_test.t2 read first limit 9; -# -# Cleanup. -# -handler test_test.t1 close; -drop table test_test.t1; -handler test_test.t2 close; -drop table test_test.t2; -drop database test_test; -# -use test; -handler test.t1 close; -drop table test.t1; - # # In the following test FLUSH TABLES produces a deadlock -# (hang forever) if the fix for bug#3565 is missing. +# (hang forever) if the fix for BUG #3565 is missing. +# And it shows that handler tables are re-opened after flush (BUG #4286). # --disable_warnings drop table if exists t1; @@ -87,28 +34,43 @@ handler a1 read first limit 9; handler a2 read first limit 9; handler t2 read first limit 9; flush tables; ---error 1109; handler a1 read first limit 9; ---error 1109; handler a2 read first limit 9; ---error 1109; handler t2 read first limit 9; # +--error 1066 handler t1 open as a1; +--error 1066 handler t1 open as a2; +--error 1066 handler t2 open; handler a1 read first limit 9; handler a2 read first limit 9; handler t2 read first limit 9; flush table t1; ---error 1109; handler a1 read first limit 9; ---error 1109; handler a2 read first limit 9; handler t2 read first limit 9; flush table t2; ---error 1109; handler t2 close; drop table t1; drop table t2; +# +# The fix for BUG #4286 cannot restore the position after a flush. +# +create table t1(table_id char(20) primary key); +insert into t1 values ('Record-01'); +insert into t1 values ('Record-02'); +insert into t1 values ('Record-03'); +insert into t1 values ('Record-04'); +insert into t1 values ('Record-05'); +handler t1 open; +handler t1 read first limit 1; +handler t1 read next limit 1; +handler t1 read next limit 1; +flush table t1; +handler t1 read next limit 1; +handler t1 read next limit 1; +handler t1 close; +drop table t1; diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test index 1f7f32c930a..53fe8c0a059 100644 --- a/mysql-test/t/handler.test +++ b/mysql-test/t/handler.test @@ -135,3 +135,207 @@ handler t1 read a=(1) where b=1; handler t1 close; drop table t1; +# +# Check if two database names beginning the same are seen as different. +# +# This database begins like the usual 'test' database. +# +--disable_warnings +drop database if exists test_test; +--enable_warnings +create database test_test; +use test_test; +create table t1(table_id char(20) primary key); +insert into t1 values ('test_test.t1'); +insert into t1 values (''); +handler t1 open; +handler t1 read first limit 9; +create table t2(table_id char(20) primary key); +insert into t2 values ('test_test.t2'); +insert into t2 values (''); +handler t2 open; +handler t2 read first limit 9; +# +# This is the usual 'test' database. +# +use test; +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1(table_id char(20) primary key); +insert into t1 values ('test.t1'); +insert into t1 values (''); +--error 1066 +handler t1 open; +# +# Check accesibility of all the tables. +# +use test; +--error 1109; +handler test.t1 read first limit 9; +handler test_test.t1 read first limit 9; +handler t1 read first limit 9; +handler test_test.t2 read first limit 9; +handler t2 read first limit 9; +# +# Cleanup. +# + +handler test_test.t1 close; +--error 1109; +handler t1 close; +drop table test_test.t1; +handler test_test.t2 close; +--error 1109; +handler t2 close; +drop table test_test.t2; +drop database test_test; +# +use test; +--error 1109; +handler test.t1 close; +--error 1109; +handler t1 close; +drop table test.t1; + +# +# BUG#4335 +# +--disable_warnings +drop database if exists test_test; +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +--enable_warnings +create database test_test; +use test_test; +create table t1 (c1 char(20)); +insert into t1 values ('test_test.t1'); +create table t3 (c1 char(20)); +insert into t3 values ('test_test.t3'); +handler t1 open; +handler t1 read first limit 9; +handler t1 open h1; +handler h1 read first limit 9; +use test; +create table t1 (c1 char(20)); +create table t2 (c1 char(20)); +create table t3 (c1 char(20)); +insert into t1 values ('t1'); +insert into t2 values ('t2'); +insert into t3 values ('t3'); +--error 1066 +handler t1 open; +--error 1066 +handler t2 open t1; +--error 1066 +handler t3 open t1; +handler t1 read first limit 9; +--error 1109 +handler test.t1 close; +--error 1066 +handler test.t1 open h1; +--error 1066 +handler test_test.t1 open h1; +handler test_test.t3 open h3; +handler test.t1 open h2; +handler t1 read first limit 9; +handler h1 read first limit 9; +handler h2 read first limit 9; +handler h3 read first limit 9; +handler test.h2 read first limit 9; +--error 1109 +handler test.h1 close; +handler test_test.t1 close; +handler test_test.h1 close; +handler h2 close; +--error 1109 +handler t1 read first limit 9; +--error 1109 +handler h1 read first limit 9; +--error 1109 +handler h2 read first limit 9; +handler h3 read first limit 9; +handler test_test.h3 read first limit 9; +use test_test; +handler h3 read first limit 9; +--error 1109 +handler test.h3 read first limit 9; +handler test_test.h3 close; +use test; +drop table t3; +drop table t2; +drop table t1; +drop database test_test; + +# +# Test if fix for BUG#4286 correctly closes handler tables. +# +create table t1 (c1 char(20)); +insert into t1 values ("t1"); +handler t1 open as h1; +handler h1 read first limit 9; +create table t2 (c1 char(20)); +insert into t2 values ("t2"); +handler t2 open as h2; +handler h2 read first limit 9; +create table t3 (c1 char(20)); +insert into t3 values ("t3"); +handler t3 open as h3; +handler h3 read first limit 9; +create table t4 (c1 char(20)); +insert into t4 values ("t4"); +handler t4 open as h4; +handler h4 read first limit 9; +create table t5 (c1 char(20)); +insert into t5 values ("t5"); +handler t5 open as h5; +handler h5 read first limit 9; +# close first +alter table t1 engine=MyISAM; +--error 1109; +handler h1 read first limit 9; +handler h2 read first limit 9; +handler h3 read first limit 9; +handler h4 read first limit 9; +handler h5 read first limit 9; +# close last +alter table t5 engine=MyISAM; +--error 1109; +handler h1 read first limit 9; +handler h2 read first limit 9; +handler h3 read first limit 9; +handler h4 read first limit 9; +--error 1109; +handler h5 read first limit 9; +# close middle +alter table t3 engine=MyISAM; +--error 1109; +handler h1 read first limit 9; +handler h2 read first limit 9; +--error 1109; +handler h3 read first limit 9; +handler h4 read first limit 9; +--error 1109; +handler h5 read first limit 9; +handler h2 close; +handler h4 close; +# close all depending handler tables +handler t1 open as h1_1; +handler t1 open as h1_2; +handler t1 open as h1_3; +handler h1_1 read first limit 9; +handler h1_2 read first limit 9; +handler h1_3 read first limit 9; +alter table t1 engine=MyISAM; +--error 1109; +handler h1_1 read first limit 9; +--error 1109; +handler h1_2 read first limit 9; +--error 1109; +handler h1_3 read first limit 9; +drop table t1; +drop table t2; +drop table t3; +drop table t4; +drop table t5; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index acc07eb6188..8b41774e970 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -540,12 +540,15 @@ int mysql_find_files(THD *thd,List *files, const char *db, const char *path, const char *wild, bool dir); /* sql_handler.cc */ -int mysql_ha_open(THD *thd, TABLE_LIST *tables); -int mysql_ha_close(THD *thd, TABLE_LIST *tables, - bool dont_send_ok=0, bool dont_lock=0, bool no_alias=0); -int mysql_ha_close_list(THD *thd, TABLE_LIST *tables, bool flushed=0); +int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen= 0); +int mysql_ha_close(THD *thd, TABLE_LIST *tables); int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, List *,enum ha_rkey_function,Item *,ha_rows,ha_rows); +int mysql_ha_flush(THD *thd, TABLE_LIST *tables, int mode_flags); +/* mysql_ha_flush mode_flags bits */ +#define MYSQL_HA_CLOSE_FINAL 0x00 +#define MYSQL_HA_REOPEN_ON_USAGE 0x01 +#define MYSQL_HA_FLUSH_ALL 0x02 /* sql_base.cc */ void set_item_name(Item *item,char *pos,uint length); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8fd7273fd78..1ecd606f7d9 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -389,7 +389,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, thd->proc_info="Flushing tables"; close_old_data_files(thd,thd->open_tables,1,1); - mysql_ha_close_list(thd, tables); + mysql_ha_flush(thd, tables, MYSQL_HA_REOPEN_ON_USAGE | MYSQL_HA_FLUSH_ALL); bool found=1; /* Wait until all threads has closed all the tables we had locked */ DBUG_PRINT("info", ("Waiting for others threads to close their open tables")); @@ -859,7 +859,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, } /* close handler tables which are marked for flush */ - mysql_ha_close_list(thd, (TABLE_LIST*) NULL, /*flushed*/ 1); + mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; table && table->in_use ; @@ -1226,7 +1226,7 @@ bool wait_for_tables(THD *thd) { thd->some_tables_deleted=0; close_old_data_files(thd,thd->open_tables,0,dropping_tables != 0); - mysql_ha_close_list(thd, (TABLE_LIST*) NULL, /*flushed*/ 1); + mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); if (!table_is_used(thd->open_tables,1)) break; (void) pthread_cond_wait(&COND_refresh,&LOCK_open); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index eb6e74a58c4..c829778151b 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -78,9 +78,9 @@ extern "C" void free_user_var(user_var_entry *entry) ** Thread specific functions ****************************************************************************/ -THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), - insert_id_used(0),rand_used(0),in_lock_tables(0), - global_read_lock(0),bootstrap(0) +THD::THD():user_time(0),global_read_lock(0),fatal_error(0), + last_insert_id_used(0),insert_id_used(0),rand_used(0), + in_lock_tables(0),bootstrap(0) { host=user=priv_user=db=query=ip=0; host_or_ip= "connecting host"; @@ -90,6 +90,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), query_error=0; next_insert_id=last_insert_id=0; open_tables=temporary_tables=handler_tables=0; + hash_clear(&handler_tables_hash); current_tablenr=0; handler_items=0; tmp_table=0; @@ -215,11 +216,9 @@ void THD::cleanup(void) lock=locked_tables; locked_tables=0; close_thread_tables(this); } - if (handler_tables) - { - open_tables=handler_tables; handler_tables=0; - close_thread_tables(this); - } + mysql_ha_flush(this, (TABLE_LIST*) 0, + MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL); + hash_free(&handler_tables_hash); close_temporary_tables(this); hash_free(&user_vars); if (global_read_lock) diff --git a/sql/sql_class.h b/sql/sql_class.h index 30947041b7d..d84a5ba88ff 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -421,6 +421,7 @@ public: and are still in use by this thread */ TABLE *open_tables,*temporary_tables, *handler_tables; + HASH handler_tables_hash; // TODO: document the variables below MYSQL_LOCK *lock,*locked_tables; ULL *ull; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 272289b6176..f056651919f 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -17,10 +17,6 @@ /* HANDLER ... commands - direct access to ISAM */ -#include "mysql_priv.h" -#include "sql_select.h" -#include - /* TODO: HANDLER blabla OPEN [ AS foobar ] [ (column-list) ] @@ -38,34 +34,215 @@ all the sql_alloc'ed memory. It's harder to work around... */ +/* + There are two containers holding information about open handler tables. + The first is 'thd->handler_tables'. It is a linked list of TABLE objects. + It is used like 'thd->open_tables' in the table cache. The trick is to + exchange these two lists during open and lock of tables. Thus the normal + table cache code can be used. + The second container is a HASH. It holds objects of the type TABLE_LIST. + Despite its name, no lists of tables but only single structs are hashed + (the 'next' pointer is always NULL). The reason for theis second container + is, that we want handler tables to survive FLUSH TABLE commands. A table + affected by FLUSH TABLE must be closed so that other threads are not + blocked by handler tables still in use. Since we use the normal table cache + functions with 'thd->handler_tables', the closed tables are removed from + this list. Hence we need the original open information for the handler + table in the case that it is used again. This information is handed over + to mysql_ha_open() as a TABLE_LIST. So we store this information in the + second container, where it is not affected by FLUSH TABLE. The second + container is implemented as a hash for performance reasons. Consequently, + we use it not only for re-opening a handler table, but also for the + HANDLER ... READ commands. For this purpose, we store a pointer to the + TABLE structure (in the first container) in the TBALE_LIST object in the + second container. When the table is flushed, the pointer is cleared. +*/ + +#include "mysql_priv.h" +#include "sql_select.h" +#include + +#define HANDLER_TABLES_HASH_SIZE 120 + +static enum enum_ha_read_modes rkey_to_rnext[]= + { RNEXT_SAME, RNEXT, RPREV, RNEXT, RPREV, RNEXT, RPREV }; + #define HANDLER_TABLES_HACK(thd) { \ TABLE *tmp=thd->open_tables; \ thd->open_tables=thd->handler_tables; \ thd->handler_tables=tmp; } -static TABLE **find_table_ptr_by_name(THD *thd,const char *db, - const char *table_name, - bool is_alias, bool dont_lock, - bool *was_flushed); +static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, int mode_flags); -int mysql_ha_open(THD *thd, TABLE_LIST *tables) + +/* + Get hash key and hash key length. + + SYNOPSIS + mysql_ha_hash_get_key() + tables Pointer to the hash object. + key_len_p (out) Pointer to the result for key length. + first Unused. + + DESCRIPTION + The hash object is an TABLE_LIST struct. + The hash key is the alias name. + The hash key length is the alias name length plus one for the + terminateing NUL character. + + RETURN + Pointer to the TABLE_LIST struct. +*/ + +static char *mysql_ha_hash_get_key(TABLE_LIST *tables, uint *key_len_p, + my_bool first __attribute__((unused))) { - HANDLER_TABLES_HACK(thd); - int err=open_tables(thd,tables); - HANDLER_TABLES_HACK(thd); - if (err) - return -1; + *key_len_p= strlen(tables->alias) + 1 ; /* include '\0' in comparisons */ + return tables->alias; +} - // there can be only one table in *tables - if (!(tables->table->file->table_flags() & HA_CAN_SQL_HANDLER)) + +/* + Free an hash object. + + SYNOPSIS + mysql_ha_hash_free() + tables Pointer to the hash object. + + DESCRIPTION + The hash object is an TABLE_LIST struct. + + RETURN + Nothing +*/ + +static void mysql_ha_hash_free(TABLE_LIST *tables) +{ + my_free((char*) tables, MYF(0)); +} + + +/* + Open a HANDLER table. + + SYNOPSIS + mysql_ha_open() + thd Thread identifier. + tables A list of tables with the first entry to open. + reopen Re-open a previously opened handler table. + + DESCRIPTION + Though this function takes a list of tables, only the first list entry + will be opened. + 'reopen' is set when a handler table is to be re-opened. In this case, + 'tables' is the pointer to the hashed TABLE_LIST object which has been + saved on the original open. + 'reopen' is also used to suppress the sending of an 'ok' message or + error messages. + + RETURN + 0 ok + != 0 error +*/ + +int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) +{ + TABLE_LIST *hash_tables; + char *db; + char *name; + char *alias; + uint dblen; + uint namelen; + uint aliaslen; + int err; + DBUG_ENTER("mysql_ha_open"); + DBUG_PRINT("enter",("mysql_ha_open: '%s'.'%s' as '%s' reopen %d", + tables->db, tables->real_name, tables->alias, reopen)); + + if (! hash_inited(&thd->handler_tables_hash)) { - my_printf_error(ER_ILLEGAL_HA,ER(ER_ILLEGAL_HA),MYF(0), tables->alias); - mysql_ha_close(thd, tables,1); - return -1; + /* + HASH entries are of type TABLE_LIST. + */ + if (hash_init(&thd->handler_tables_hash, HANDLER_TABLES_HASH_SIZE, 0, 0, + (hash_get_key) mysql_ha_hash_get_key, + (hash_free_key) mysql_ha_hash_free, 0)) + goto err; + } + else if (! reopen) /* Otherwise we have 'tables' already. */ + { + if (hash_search(&thd->handler_tables_hash, (byte*) tables->alias, + strlen(tables->alias) + 1)) + { + DBUG_PRINT("info",("mysql_ha_open: duplicate '%s'", tables->alias)); + if (! reopen) + my_printf_error(ER_NONUNIQ_TABLE, ER(ER_NONUNIQ_TABLE), + MYF(0), tables->alias); + goto err; + } } - send_ok(&thd->net); - return 0; + /* + open_tables() will set 'tables->table' if successful. + It must be NULL for a real open when calling open_tables(). + */ + DBUG_ASSERT(! tables->table); + HANDLER_TABLES_HACK(thd); + err=open_tables(thd,tables); + HANDLER_TABLES_HACK(thd); + if (err) + goto err; + + /* There can be only one table in '*tables'. */ + if (! (tables->table->file->table_flags() & HA_CAN_SQL_HANDLER)) + { + if (! reopen) + my_printf_error(ER_ILLEGAL_HA,ER(ER_ILLEGAL_HA),MYF(0), tables->alias); + mysql_ha_close(thd, tables); + goto err; + } + + if (! reopen) + { + /* copy the TABLE_LIST struct */ + dblen= strlen(tables->db) + 1; + namelen= strlen(tables->real_name) + 1; + aliaslen= strlen(tables->alias) + 1; + if (!(my_multi_malloc(MYF(MY_WME), + &hash_tables, sizeof(*hash_tables), + &db, dblen, + &name, namelen, + &alias, aliaslen, + NullS))) + { + DBUG_PRINT("exit",("mysql_ha_open: malloc ERROR")); + goto err; + } + /* structure copy */ + *hash_tables= *tables; + hash_tables->db= db; + hash_tables->real_name= name; + hash_tables->alias= alias; + memcpy(hash_tables->db, tables->db, dblen); + memcpy(hash_tables->real_name, tables->real_name, namelen); + memcpy(hash_tables->alias, tables->alias, aliaslen); + + /* add to hash */ + if (hash_insert(&thd->handler_tables_hash, (byte*) hash_tables)) + { + mysql_ha_close(thd, tables); + goto err; + } + } + + if (! reopen) + send_ok(&thd->net); + DBUG_PRINT("exit",("mysql_ha_open: OK")); + DBUG_RETURN(0); + +err: + DBUG_PRINT("exit",("mysql_ha_open: ERROR")); + DBUG_RETURN(-1); } @@ -76,145 +253,185 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables) mysql_ha_close() thd Thread identifier. tables A list of tables with the first entry to close. - dont_send_ok Suppresses the commands' ok message and - error message and error return. - dont_lock Suppresses the normal locking of LOCK_open. DESCRIPTION Though this function takes a list of tables, only the first list entry will be closed. Broadcasts a COND_refresh condition. - If mysql_ha_close() is not called from the parser, 'dont_send_ok' - must be set. - If the caller did already lock LOCK_open, it must set 'dont_lock'. - - IMPLEMENTATION - find_table_ptr_by_name() closes the table, if a FLUSH TABLE is outstanding. - It returns a NULL pointer in this case, but flags the situation in - 'was_flushed'. In that case the normal ER_UNKNOWN_TABLE error messages - is suppressed. RETURN - 0 ok - -1 error + 0 ok + != 0 error */ -int mysql_ha_close(THD *thd, TABLE_LIST *tables, - bool dont_send_ok, bool dont_lock, bool no_alias) +int mysql_ha_close(THD *thd, TABLE_LIST *tables) { + TABLE_LIST *hash_tables; TABLE **table_ptr; - bool was_flushed; + bool was_flushed= FALSE; + bool not_opened; + DBUG_ENTER("mysql_ha_close"); + DBUG_PRINT("enter",("mysql_ha_close: '%s'.'%s' as '%s'", + tables->db, tables->real_name, tables->alias)); - table_ptr= find_table_ptr_by_name(thd, tables->db, tables->alias, - !no_alias, dont_lock, &was_flushed); - if (*table_ptr) + if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, + (byte*) tables->alias, + strlen(tables->alias) + 1))) { - if (!dont_lock) - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, table_ptr)) + /* + Though we could take the table pointer from hash_tables->table, + we must follow the thd->handler_tables chain anyway, as we need the + address of the 'next' pointer referencing this table + for close_thread_table(). + */ + for (table_ptr= &(thd->handler_tables); + *table_ptr && (*table_ptr != hash_tables->table); + table_ptr= &(*table_ptr)->next); + +#if MYSQL_VERSION_ID < 40100 + if (*tables->db && strcmp(hash_tables->db, tables->db)) { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); + DBUG_PRINT("info",("mysql_ha_close: wrong db")); + hash_tables= NULL; } - if (!dont_lock) - VOID(pthread_mutex_unlock(&LOCK_open)); - } - else if (!was_flushed && !dont_send_ok) - { - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - tables->alias, "HANDLER"); - return -1; - } - if (!dont_send_ok) - send_ok(&thd->net); - return 0; -} - - -/* - Close a list of HANDLER tables. - - SYNOPSIS - mysql_ha_close_list() - thd Thread identifier. - tables The list of tables to close. If NULL, - close all HANDLER tables. - flushed Close only tables which are marked flushed. - Used only if tables is NULL. - - DESCRIPTION - The list of HANDLER tables may be NULL, in which case all HANDLER - tables are closed. Broadcasts a COND_refresh condition, for - every table closed. If 'tables' is NULL and 'flushed' is set, - all HANDLER tables marked for flush are closed. - The caller must lock LOCK_open. - - IMPLEMENTATION - find_table_ptr_by_name() closes the table, if it is marked for flush. - It returns a NULL pointer in this case, but flags the situation in - 'was_flushed'. In that case the normal ER_UNKNOWN_TABLE error messages - is suppressed. - - RETURN - 0 ok -*/ - -int mysql_ha_close_list(THD *thd, TABLE_LIST *tables, bool flushed) -{ - TABLE_LIST *tl_item; - TABLE **table_ptr; - - if (tables) - { - for (tl_item= tables ; tl_item; tl_item= tl_item->next) + else +#endif { - mysql_ha_close(thd, tl_item, /*dont_send_ok*/ 1, - /*dont_lock*/ 1, /*no_alias*/ 1); - } - } - else - { - table_ptr= &(thd->handler_tables); - while (*table_ptr) - { - if (! flushed || ((*table_ptr)->version != refresh_version)) + if (*table_ptr) { + VOID(pthread_mutex_lock(&LOCK_open)); if (close_thread_table(thd, table_ptr)) { /* Tell threads waiting for refresh that something has happened */ VOID(pthread_cond_broadcast(&COND_refresh)); } - continue; + VOID(pthread_mutex_unlock(&LOCK_open)); } - table_ptr= &((*table_ptr)->next); + + hash_delete(&thd->handler_tables_hash, (byte*) hash_tables); } } - return 0; + + if (! hash_tables) + { +#if MYSQL_VERSION_ID < 40100 + char buff[MAX_DBKEY_LENGTH]; + if (*tables->db) + strxnmov(buff, sizeof(buff), tables->db, ".", tables->real_name, NullS); + else + strncpy(buff, tables->alias, sizeof(buff)); + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + buff, "HANDLER"); +#else + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + tables->alias, "HANDLER"); +#endif + DBUG_PRINT("exit",("mysql_ha_close: ERROR")); + DBUG_RETURN(-1); + } + + send_ok(&thd->net); + DBUG_PRINT("exit",("mysql_ha_close: OK")); + DBUG_RETURN(0); } -static enum enum_ha_read_modes rkey_to_rnext[]= - { RNEXT_SAME, RNEXT, RPREV, RNEXT, RPREV, RNEXT, RPREV }; +/* + Read from a HANDLER table. + SYNOPSIS + mysql_ha_read() + thd Thread identifier. + tables A list of tables with the first entry to read. + mode + keyname + key_expr + ha_rkey_mode + cond + select_limit + offset_limit + + RETURN + 0 ok + != 0 error +*/ + int mysql_ha_read(THD *thd, TABLE_LIST *tables, enum enum_ha_read_modes mode, char *keyname, List *key_expr, enum ha_rkey_function ha_rkey_mode, Item *cond, ha_rows select_limit,ha_rows offset_limit) { - int err, keyno=-1; - bool was_flushed; - TABLE *table= *find_table_ptr_by_name(thd, tables->db, tables->alias, - /*is_alias*/ 1, /*dont_lock*/ 0, - &was_flushed); + TABLE_LIST *hash_tables; + TABLE *table; + int err; + int keyno=-1; + uint num_rows; + bool was_flushed; + MYSQL_LOCK *lock; + DBUG_ENTER("mysql_ha_read"); + DBUG_PRINT("enter",("mysql_ha_read: '%s'.'%s' as '%s'", + tables->db, tables->real_name, tables->alias)); + + List list; + list.push_front(new Item_field(NULL,NULL,"*")); + List_iterator it(list); + it++; + + if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, + (byte*) tables->alias, + strlen(tables->alias) + 1))) + { + table= hash_tables->table; + DBUG_PRINT("info",("mysql_ha_read: found in hash '%s'.'%s' as '%s' tab %p", + hash_tables->db, hash_tables->real_name, + hash_tables->alias, table)); + if (!table) + { + /* + The handler table has been closed. Re-open it. + */ + if (mysql_ha_open(thd, hash_tables, 1)) + { + DBUG_PRINT("exit",("mysql_ha_read: reopen failed")); + goto err0; + } + + table= hash_tables->table; + DBUG_PRINT("info",("mysql_ha_read: re-opened '%s'.'%s' as '%s' tab %p", + hash_tables->db, hash_tables->real_name, + hash_tables->alias, table)); + } + +#if MYSQL_VERSION_ID < 40100 + if (*tables->db && strcmp(table->table_cache_key, tables->db)) + { + DBUG_PRINT("info",("mysql_ha_read: wrong db")); + table= NULL; + } +#endif + } + else + table= NULL; + if (!table) { - my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), - tables->alias,"HANDLER"); - return -1; +#if MYSQL_VERSION_ID < 40100 + char buff[MAX_DBKEY_LENGTH]; + if (*tables->db) + strxnmov(buff, sizeof(buff), tables->db, ".", tables->real_name, NullS); + else + strncpy(buff, tables->alias, sizeof(buff)); + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + buff, "HANDLER"); +#else + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + tables->alias, "HANDLER"); +#endif + goto err0; } tables->table=table; if (cond && cond->fix_fields(thd,tables)) - return -1; + goto err0; table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it @@ -224,24 +441,19 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, { my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), keyname,tables->alias); - return -1; + goto err0; } table->file->index_init(keyno); } - List list; - list.push_front(new Item_field(NULL,NULL,"*")); - List_iterator it(list); - uint num_rows; - it++; - - insert_fields(thd,tables,tables->db,tables->alias,&it); + if (insert_fields(thd,tables,tables->db,tables->alias,&it)) + goto err0; select_limit+=offset_limit; send_fields(thd,list,1); HANDLER_TABLES_HACK(thd); - MYSQL_LOCK *lock=mysql_lock_tables(thd,&tables->table,1); + lock= mysql_lock_tables(thd, &tables->table, 1); HANDLER_TABLES_HACK(thd); byte *key; @@ -363,83 +575,155 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ok: mysql_unlock_tables(thd,lock); send_eof(&thd->net); - return 0; + DBUG_PRINT("exit",("mysql_ha_read: OK")); + DBUG_RETURN(0); err: mysql_unlock_tables(thd,lock); err0: - return -1; + DBUG_PRINT("exit",("mysql_ha_read: ERROR")); + DBUG_RETURN(-1); } /* - Find a HANDLER table by name. + Flush (close) a list of HANDLER tables. SYNOPSIS - find_table_ptr_by_name() + mysql_ha_flush() thd Thread identifier. - db Database (schema) name. - table_name Table name ;-). - is_alias Table name may be an alias name. - dont_lock Suppresses the normal locking of LOCK_open. + tables The list of tables to close. If NULL, + close all HANDLER tables [marked as flushed]. + mode_flags MYSQL_HA_CLOSE_FINAL finally close the table. + MYSQL_HA_REOPEN_ON_USAGE mark for reopen. + MYSQL_HA_FLUSH_ALL flush all tables, not only + those marked for flush. DESCRIPTION - Find the table 'db'.'table_name' in the list of HANDLER tables of the - thread 'thd'. If the table has been marked by FLUSH TABLE(S), close it, - flag this situation in '*was_flushed' and broadcast a COND_refresh - condition. - An empty database (schema) name matches all database (schema) names. - If the caller did already lock LOCK_open, it must set 'dont_lock'. + The list of HANDLER tables may be NULL, in which case all HANDLER + tables are closed (if MYSQL_HA_FLUSH_ALL) is set. + If 'tables' is NULL and MYSQL_HA_FLUSH_ALL is not set, + all HANDLER tables marked for flush are closed. + Broadcasts a COND_refresh condition, for every table closed. + The caller must lock LOCK_open. - IMPLEMENTATION - Just in case that the table is twice in 'thd->handler_tables' (!?!), - the loop does not break when the table was flushed. If another table - by that name was found and not flushed, '*was_flushed' is cleared again, - since a pointer to an open HANDLER table is returned. + NOTE + Since mysql_ha_flush() is called when the base table has to be closed, + we compare real table names, not aliases. Hence, database names matter. RETURN - *was_flushed Table has been closed due to FLUSH TABLE. - NULL A HANDLER Table by that name does not exist (any more). - != NULL Pointer to the TABLE structure. + 0 ok */ -static TABLE **find_table_ptr_by_name(THD *thd, const char *db, - const char *table_name, - bool is_alias, bool dont_lock, - bool *was_flushed) +int mysql_ha_flush(THD *thd, TABLE_LIST *tables, int mode_flags) { - int dblen; - TABLE **table_ptr; + TABLE_LIST **tmp_tables_p; + TABLE_LIST *tmp_tables; + TABLE **table_ptr; + bool was_flushed; + DBUG_ENTER("mysql_ha_flush"); + DBUG_PRINT("enter",("mysql_ha_flush: tables %p mode_flags 0x%02x", + tables, mode_flags)); - DBUG_ASSERT(db); - dblen= *db ? strlen(db)+1 : 0; - table_ptr= &(thd->handler_tables); - *was_flushed= FALSE; - - for (TABLE *table=*table_ptr; table ; table=*table_ptr) + if (tables) { - if ((!dblen || !memcmp(table->table_cache_key, db, dblen)) && - !my_strcasecmp((is_alias ? table->table_name : table->real_name), - table_name)) + /* Close all tables in the list. */ + for (tmp_tables= tables ; tmp_tables; tmp_tables= tmp_tables->next) { - if (table->version != refresh_version) + DBUG_PRINT("info",("mysql_ha_flush: in tables list '%s'.'%s' as '%s'", + tmp_tables->db, tmp_tables->real_name, + tmp_tables->alias)); + /* Close all currently open handler tables with the same base table. */ + table_ptr= &(thd->handler_tables); + while (*table_ptr) { - if (!dont_lock) - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, table_ptr)) + if ((! *tmp_tables->db || + ! my_strcasecmp((*table_ptr)->table_cache_key, tmp_tables->db)) && + ! my_strcasecmp((*table_ptr)->real_name, tmp_tables->real_name)) { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); + DBUG_PRINT("info",("mysql_ha_flush: *table_ptr '%s'.'%s' as '%s'", + (*table_ptr)->table_cache_key, + (*table_ptr)->real_name, + (*table_ptr)->table_name)); + mysql_ha_flush_table(thd, table_ptr, mode_flags); + continue; } - if (!dont_lock) - VOID(pthread_mutex_unlock(&LOCK_open)); - *was_flushed= TRUE; + table_ptr= &(*table_ptr)->next; + } + /* end of handler_tables list */ + } + /* end of flush tables list */ + } + else + { + /* Close all currently open tables [which are marked for flush]. */ + table_ptr= &(thd->handler_tables); + while (*table_ptr) + { + if ((mode_flags & MYSQL_HA_FLUSH_ALL) || + ((*table_ptr)->version != refresh_version)) + { + mysql_ha_flush_table(thd, table_ptr, mode_flags); continue; } - *was_flushed= FALSE; - break; + table_ptr= &(*table_ptr)->next; } - table_ptr=&(table->next); } - return table_ptr; + + DBUG_PRINT("exit",("mysql_ha_flush: OK")); + DBUG_RETURN(0); +} + +/* + Flush (close) a table. + + SYNOPSIS + mysql_ha_flush_table() + thd Thread identifier. + table The table to close. + mode_flags MYSQL_HA_CLOSE_FINAL finally close the table. + MYSQL_HA_REOPEN_ON_USAGE mark for reopen. + + DESCRIPTION + Broadcasts a COND_refresh condition, for every table closed. + The caller must lock LOCK_open. + + RETURN + 0 ok +*/ + +static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, int mode_flags) +{ + TABLE_LIST *hash_tables; + TABLE *table= *table_ptr; + bool was_flushed; + DBUG_ENTER("mysql_ha_flush_table"); + DBUG_PRINT("info",("mysql_ha_flush_table: '%s'.'%s' as '%s' flags 0x%02x", + table->table_cache_key, table->real_name, + table->table_name, mode_flags)); + + if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, + (*table_ptr)->table_name, + strlen((*table_ptr)->table_name) + 1))) + { + if (! (mode_flags & MYSQL_HA_REOPEN_ON_USAGE)) + { + /* This is a final close. Remove from hash. */ + hash_delete(&thd->handler_tables_hash, (byte*) hash_tables); + } + else + { + /* Mark table as closed, ready for re-open. */ + hash_tables->table= NULL; + } + } + + if (close_thread_table(thd, table_ptr)) + { + /* Tell threads waiting for refresh that something has happened */ + VOID(pthread_cond_broadcast(&COND_refresh)); + } + + DBUG_PRINT("exit",("mysql_ha_flush_table: OK")); + DBUG_RETURN(0); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 96eebd98ac3..b218a224977 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -176,7 +176,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, for (table=tables ; table ; table=table->next) { char *db=table->db; - mysql_ha_close(thd, table, /*dont_send_ok*/ 1, /*dont_lock*/ 1); + mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL); if (!close_temporary_table(thd, db, table->real_name)) { tmp_table_deleted=1; @@ -1242,7 +1242,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, if (send_fields(thd, field_list, 1)) DBUG_RETURN(-1); - mysql_ha_close(thd, tables, /*dont_send_ok*/ 1, /*dont_lock*/ 1); + mysql_ha_flush(thd, tables, MYSQL_HA_CLOSE_FINAL); for (table = tables; table; table = table->next) { char table_name[NAME_LEN*2+2]; @@ -1503,7 +1503,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, } used_fields=create_info->used_fields; - mysql_ha_close(thd, table_list, /*dont_send_ok*/ 1, /*dont_lock*/ 1); + mysql_ha_flush(thd, table_list, MYSQL_HA_CLOSE_FINAL); if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ))) DBUG_RETURN(-1); From 550c4eb7952bf322f8360b736c0571b9ce7c4bd3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 25 Sep 2004 18:43:07 +0200 Subject: [PATCH 33/44] Bug #5539 SHOW DATABASES LIKE and symlinks sql_show.cc: Made change suggested by Serge. REmoved else in mysql_find_files so symlink files fall through to the wildcard check sql/sql_show.cc: Made change suggested by Serge. REmoved else in mysql_find_files so symlink files fall through to the wildcard check --- sql/sql_show.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d82af1a6242..2506033cda5 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -193,28 +193,23 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, { /* Return databases */ #ifdef USE_SYMDIR char *ext; + char buff[FN_REFLEN]; if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym")) { /* Only show the sym file if it points to a directory */ - char buff[FN_REFLEN], *end; - MY_STAT status; + char *end; *ext=0; /* Remove extension */ unpack_dirname(buff, file->name); end= strend(buff); if (end != buff && end[-1] == FN_LIBCHAR) end[-1]= 0; // Remove end FN_LIBCHAR - if (!my_stat(buff, &status, MYF(0)) || - !MY_S_ISDIR(status.st_mode) || - (wild && wild_compare(file->name, wild, 0))) - continue; - } - else + if (!my_stat(buff, file->mystat, MYF(0))) + continue; + } #endif - { if (file->name[0] == '.' || !MY_S_ISDIR(file->mystat->st_mode) || (wild && wild_compare(file->name,wild, 0))) continue; - } } else { From dc955863df5872ab4a70adbbf98d4f10d90a1f42 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Sep 2004 15:24:57 +0200 Subject: [PATCH 34/44] make --with-openssl work with parameters as expected, old options for include path and library settings still work for backwards compatibility (fix for BUG #5494) BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted --- BitKeeper/etc/logging_ok | 1 + acinclude.m4 | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index d427be619b8..8f9c0f60122 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -35,6 +35,7 @@ greg@mysql.com guilhem@mysql.com gweir@build.mysql.com gweir@work.mysql.com +hartmut@mysql.com heikki@donna.mysql.fi heikki@hundin.mysql.fi heikki@rescue. diff --git a/acinclude.m4 b/acinclude.m4 index a88957ea3df..6c567f00765 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -788,7 +788,7 @@ AC_DEFUN(MYSQL_FIND_OPENSSL, [ AC_DEFUN(MYSQL_CHECK_OPENSSL, [ AC_MSG_CHECKING(for OpenSSL) AC_ARG_WITH([openssl], - [ --with-openssl Include the OpenSSL support], + [ --with-openssl[=DIR] Include the OpenSSL support], [openssl="$withval"], [openssl=no]) @@ -806,8 +806,19 @@ AC_MSG_CHECKING(for OpenSSL) [openssl_libs="$withval"], [openssl_libs=""]) - if test "$openssl" = "yes" + if test "$openssl" != "no" then + if test "$openssl" != "yes" + then + if test -z "$openssl_includes" + then + openssl_includes="$openssl/include" + fi + if test -z "$openssl_libs" + then + openssl_libs="$openssl/lib" + fi + fi MYSQL_FIND_OPENSSL([$openssl_includes], [$openssl_libs]) #force VIO use vio_dir="vio" @@ -843,6 +854,14 @@ AC_MSG_CHECKING(for OpenSSL) NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs" else AC_MSG_RESULT(no) + if test ! -z "$openssl_includes" + then + AC_MSG_ERROR(Can't have --with-openssl-includes without --with-openssl); + fi + if test ! -z "$openssl_libs" + then + AC_MSG_ERROR(Can't have --with-openssl-libs without --with-openssl); + fi fi AC_SUBST(openssl_libs) AC_SUBST(openssl_includes) From 85d98034b4979b270154af305d1cb3c5f929fb0f Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Sep 2004 15:27:13 +0200 Subject: [PATCH 35/44] added --without-man option similar to --without-docs (part of BUG#5379) --- Makefile.am | 2 +- configure.in | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index fb0735b562c..1609b5a1da1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ AUTOMAKE_OPTIONS = foreign EXTRA_DIST = INSTALL-SOURCE README COPYING EXCEPTIONS-CLIENT SUBDIRS = . include @docs_dirs@ @readline_dir@ \ @thread_dirs@ pstack @sql_client_dirs@ \ - @sql_server_dirs@ scripts man tests \ + @sql_server_dirs@ scripts @man_dirs@ tests \ BUILD netware os2 @libmysqld_dirs@ \ @bench_dirs@ support-files @fs_dirs@ @tools_dirs@ diff --git a/configure.in b/configure.in index c3978ff32d1..37b0432b98d 100644 --- a/configure.in +++ b/configure.in @@ -2181,6 +2181,21 @@ else fi AC_SUBST(docs_dirs) +# Shall we build the man pages? +AC_ARG_WITH(man, + [ --without-man Skip building of the man pages.], + [with_man=$withval], + [with_man=yes] +) + +if test "$with_man" = "yes" +then + man_dirs="man" +else + man_dirs="" +fi +AC_SUBST(man_dirs) + # Shall we build the bench code? AC_ARG_WITH(bench, [ --without-bench Skip building of the benchmark suite.], From e6f924efe586cef418b6d77b950bdcd1ad97871b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Sep 2004 00:50:00 +0400 Subject: [PATCH 36/44] Fix for bug #4131 "TIMESTAMP columns missing minutes and seconds when using GROUP BY" Now we are setting Field_timestamp::field_length to 19 in open_table() if we are in new mode (and we are restoring it back when we are coming back to normal mode). This also should solve potential problems with some of LOAD DATA INFILE and SELECT * INTO in this mode. mysql-test/r/type_timestamp.result: Added test for bug #4131 'TIMESTAMP columns missing minutes and seconds when using GROUP BY' and other --new mode related behavior. mysql-test/t/type_timestamp.test: Added test for bug #4131 'TIMESTAMP columns missing minutes and seconds when using GROUP BY' and other --new mode related behavior. sql/field.cc: Added Field_timestamp::orig_field_length member for saving original field_length value, because this member can be modified if new_mode is in effect. Lot of Field_timestamp code simplified and Field_timestamp::make_field() is no longer needed because we are setting field_length to 19 if we are in --new mode now. sql/field.h: Added Field_timestamp::orig_field_length member for saving original field_length value, because this member can be modified if new_mode is in effect. Field_timestamp::make_field() is no longer needed because we are setting field_length to 19 if we are in --new mode now. sql/sql_base.cc: If --new mode is in effect all TIMESTAMP fields should pretend that they have length of 19. We are achieving this by setting Field_timestamp::field_length to 19 (or original value) in open_table(). We are using TABLE::timestamp_mode variable for avoiding of unnecessary looping over all fields of the table and setting field_length if table was used with same new_mode value before. Note: We do not introduce general framework for setting up Field objects for usage with current THD here because this fix is only needed in 4.0 and Monty said that we will also remove looping over all fields when updating table_name member at some point. This more general framework will also complicate nice optimization with avoiding of unneeded looping. sql/sql_parse.cc: Now when we are creating TIMESTAMP(19) fields by default in --new mode, otherwise we will have unaligned behavior between ALTER and CREATE. sql/table.h: Added TABLE::timestamp_mode field for saving information whenever we set field_length members of table's TIMESTAMP fields to 19 (to honor new_mode) or they have original values. --- mysql-test/r/type_timestamp.result | 60 +++++++++++++++++++++++++----- mysql-test/t/type_timestamp.test | 32 ++++++++++++++++ sql/field.cc | 24 +++--------- sql/field.h | 13 ++++++- sql/sql_base.cc | 25 +++++++++++++ sql/sql_parse.cc | 11 ++++++ sql/table.h | 8 ++++ 7 files changed, 144 insertions(+), 29 deletions(-) diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index 752a5045eb0..6253fa96ba8 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -122,40 +122,41 @@ t2 t4 t6 t8 t10 t12 t14 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 drop table t1; +set new=0; create table t1 (t1 timestamp default '2003-01-01 00:00:00', t2 timestamp default '2003-01-01 00:00:00'); set TIMESTAMP=1000000000; insert into t1 values(); select * from t1; t1 t2 -2001-09-09 04:46:40 2003-01-01 00:00:00 +20010909044640 20030101000000 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `t1` timestamp(14) NOT NULL, - `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00' + `t2` timestamp(14) NOT NULL default '20030101000000' ) TYPE=MyISAM show columns from t1; Field Type Null Key Default Extra t1 timestamp(14) YES NULL -t2 timestamp(14) YES 2003-01-01 00:00:00 +t2 timestamp(14) YES 20030101000000 show columns from t1 like 't2'; Field Type Null Key Default Extra -t2 timestamp(14) YES 2003-01-01 00:00:00 +t2 timestamp(14) YES 20030101000000 create table t2 (select * from t1); show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `t1` timestamp(14) NOT NULL, - `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00' + `t2` timestamp(14) NOT NULL default '20030101000000' ) TYPE=MyISAM alter table t1 add column t0 timestamp first; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `t0` timestamp(14) NOT NULL, - `t1` timestamp(14) NOT NULL default '2003-01-01 00:00:00', - `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00' + `t1` timestamp(14) NOT NULL default '20030101000000', + `t2` timestamp(14) NOT NULL default '20030101000000' ) TYPE=MyISAM drop table t1,t2; create table t1 (ts1 timestamp, ts2 timestamp); @@ -164,8 +165,8 @@ insert into t1 values (); insert into t1 values (DEFAULT, DEFAULT); select * from t1; ts1 ts2 -2001-09-09 04:46:40 0000-00-00 00:00:00 -2001-09-09 04:46:40 0000-00-00 00:00:00 +20010909044640 00000000000000 +20010909044640 00000000000000 drop table t1; create table t1 (ts timestamp(19)); show create table t1; @@ -179,3 +180,44 @@ select * from t1; ts 2001-09-09 04:46:40 drop table t1; +set new=1; +create table t1 (a char(2), t timestamp); +insert into t1 values ('a', '2004-01-01 00:00:00'), ('a', '2004-01-01 01:00:00'), +('b', '2004-02-01 00:00:00'); +select max(t) from t1 group by a; +max(t) +2004-01-01 01:00:00 +2004-02-01 00:00:00 +drop table t1; +create table t1 (ts1 timestamp); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `ts1` timestamp(19) NOT NULL +) TYPE=MyISAM +alter table t1 add ts2 timestamp; +set new=0; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `ts1` timestamp(19) NOT NULL, + `ts2` timestamp(19) NOT NULL default '0000-00-00 00:00:00' +) TYPE=MyISAM +drop table t1; +create table t1 (ts1 timestamp); +insert into t1 values ('2004-01-01 00:00:00'), ('2004-01-01 01:00:00'); +select * from t1; +ts1 +20040101000000 +20040101010000 +set new=1; +select * from t1; +ts1 +2004-01-01 00:00:00 +2004-01-01 01:00:00 +set new=0; +select * from t1; +ts1 +20040101000000 +20040101010000 +drop table t1; diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index 92bd20e846e..464ee63c137 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -71,6 +71,7 @@ select * from t1; set new=1; select * from t1; drop table t1; +set new=0; # # Bug #1885, bug #2539. @@ -116,3 +117,34 @@ set TIMESTAMP=1000000000; insert into t1 values (); select * from t1; drop table t1; + +# +# Test for bug #4131, TIMESTAMP columns missing minutes and seconds when +# using GROUP BY in @@new=1 mode. +# +set new=1; +create table t1 (a char(2), t timestamp); +insert into t1 values ('a', '2004-01-01 00:00:00'), ('a', '2004-01-01 01:00:00'), + ('b', '2004-02-01 00:00:00'); +select max(t) from t1 group by a; +drop table t1; + +# +# More --new mode tests +# Both columns created before and during alter should have same length. +# +create table t1 (ts1 timestamp); +show create table t1; +alter table t1 add ts2 timestamp; +set new=0; +show create table t1; +drop table t1; +# Selecting from table in --new mode should not affect further selects. +create table t1 (ts1 timestamp); +insert into t1 values ('2004-01-01 00:00:00'), ('2004-01-01 01:00:00'); +select * from t1; +set new=1; +select * from t1; +set new=0; +select * from t1; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 394d53238c2..69ee6606be4 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2467,8 +2467,7 @@ void Field_double::sql_type(String &res) const enum Item_result Field_timestamp::result_type() const { - return (!current_thd->variables.new_mode && - (field_length == 8 || field_length == 14) ? INT_RESULT : + return ((field_length == 8 || field_length == 14) ? INT_RESULT : STRING_RESULT); } @@ -2480,6 +2479,9 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg, :Field_num(ptr_arg, len_arg, (uchar*) 0,0, unireg_check_arg, field_name_arg, table_arg, 0, 1, 1) +#if MYSQL_VERSION_ID < 40100 + , orig_field_length(len_arg) +#endif { if (table && !table->timestamp_field) { @@ -2697,7 +2699,7 @@ String *Field_timestamp::val_str(String *val_buffer, time_t time_arg; struct tm *l_time; struct tm tm_tmp; - my_bool new_format= (current_thd->variables.new_mode) || field_length == 19, + my_bool new_format= field_length == 19, full_year=(field_length == 8 || field_length == 14 || new_format); int real_field_length= new_format ? 19 : field_length; @@ -2859,22 +2861,6 @@ void Field_timestamp::set_time() longstore(ptr,tmp); } -/* - This is an exact copy of Field_num except that 'length' is depending - on --new mode -*/ - -void Field_timestamp::make_field(Send_field *field) -{ - field->table_name=table_name; - field->col_name=field_name; - /* If --new, then we are using "YYYY-MM-DD HH:MM:SS" format */ - field->length= current_thd->variables.new_mode ? 19 : field_length; - field->type=type(); - field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags; - field->decimals=dec; -} - /**************************************************************************** ** time type diff --git a/sql/field.h b/sql/field.h index d25ce8d4774..c42f5f63f0c 100644 --- a/sql/field.h +++ b/sql/field.h @@ -546,6 +546,13 @@ public: class Field_timestamp :public Field_num { +#if MYSQL_VERSION_ID < 40100 + /* + We save the original field length here because field_length is + changed to a mock value in case when the 'new_mode' is in effect. + */ + uint32 orig_field_length; +#endif public: Field_timestamp(char *ptr_arg, uint32 len_arg, enum utype unireg_check_arg, const char *field_name_arg, @@ -587,7 +594,11 @@ public: void fill_and_store(char *from,uint len); bool get_date(TIME *ltime,bool fuzzydate); bool get_time(TIME *ltime); - void make_field(Send_field *field); + +#if MYSQL_VERSION_ID < 40100 + friend TABLE *open_table(THD *thd,const char *db,const char *table_name, + const char *alias,bool *refresh); +#endif }; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8fd7273fd78..c9d6ca87fdb 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -941,6 +941,31 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, for (uint i=0 ; i < table->fields ; i++) table->field[i]->table_name=table->table_name; } +#if MYSQL_VERSION_ID < 40100 + /* + If per-connection "new" variable (represented by variables.new_mode) + is set then we should pretend that the length of TIMESTAMP field is 19. + The cheapest (from perfomance viewpoint) way to achieve that is to set + field_length of all Field_timestamp objects in a table after opening + it (to 19 if new_mode is true or to original field length otherwise). + We save value of new_mode variable in TABLE::timestamp_mode to + not perform this setup if new_mode value is the same between sequential + table opens. + */ + my_bool new_mode= thd->variables.new_mode; + if (table->timestamp_mode != new_mode) + { + for (uint i=0 ; i < table->fields ; i++) + { + Field *field= table->field[i]; + + if (field->type() == FIELD_TYPE_TIMESTAMP) + field->field_length= new_mode ? 19 : + ((Field_timestamp *)(field))->orig_field_length; + } + table->timestamp_mode= new_mode; + } +#endif /* These variables are also set in reopen_table() */ table->tablenr=thd->current_tablenr++; table->used_fields=0; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 14fc748c288..4f1a0589db1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3229,7 +3229,18 @@ bool add_field_to_list(char *field_name, enum_field_types type, } break; case FIELD_TYPE_TIMESTAMP: +#if MYSQL_VERSION_ID < 40100 + /* + When in in --new mode, we should create TIMESTAMP(19) fields by default; + otherwise we will have problems with ALTER TABLE changing lengths of + existing TIMESTAMP fields to 19 and adding new fields with length 14. + */ + if (thd->variables.new_mode) + new_field->length= 19; + else if (!length) +#else if (!length) +#endif new_field->length= 14; // Full date YYYYMMDDHHMMSS else if (new_field->length != 19) { diff --git a/sql/table.h b/sql/table.h index f3b0e148cc0..84df7ba127e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -106,6 +106,14 @@ struct st_table { *found_next_number_field, /* Set on open */ *rowid_field; Field_timestamp *timestamp_field; +#if MYSQL_VERSION_ID < 40100 + /* + Indicates whenever we have to set field_length members of all TIMESTAMP + fields to 19 (to honour 'new_mode' variable) or to original + field_length values. + */ + my_bool timestamp_mode; +#endif my_string comment; /* Comment about table */ REGINFO reginfo; /* field connections */ MEM_ROOT mem_root; From 6882e87f15b6dfebdf8482f421a0d3e53ca1d11f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Sep 2004 19:05:33 +0200 Subject: [PATCH 37/44] Solve compile problem for 4.0.22 on hpita2. (Backport of a 4.1 change) sql/mysqld.cc: Replace 'sete_id(_)' calls by 'setre_id(-1,_)' calls, as the former have no prototypes on some platforms. (Backport of a 4.1 change) --- sql/mysqld.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 834cff0d869..89d71ecbfa2 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1114,14 +1114,14 @@ static void set_effective_user(struct passwd *user_info) { #if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) DBUG_ASSERT(user_info); - if (setegid(user_info->pw_gid) == -1) + if (setregid((gid_t)-1,user_info->pw_gid) == -1) { - sql_perror("setegid"); + sql_perror("setregid"); unireg_abort(1); } - if (seteuid(user_info->pw_uid) == -1) + if (setreuid((uid_t)-1,user_info->pw_uid) == -1) { - sql_perror("seteuid"); + sql_perror("setreuid"); unireg_abort(1); } #endif @@ -2510,9 +2510,9 @@ You should consider changing lower_case_table_names to 1 or 2", #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) if (locked_in_memory && !getuid()) { - if (seteuid(0) == -1) + if (setreuid((uid_t)-1,0) == -1) { // this should never happen - sql_perror("seteuid"); + sql_perror("setreuid"); unireg_abort(1); } if (mlockall(MCL_CURRENT)) From dc3f3ce69430ed1608c0134da7a7e95f527c3d7c Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Oct 2004 16:23:54 +0500 Subject: [PATCH 38/44] delete.result, delete.test: A fix (bug #5733: Table handler error with self-join multi-table DELETE). records.cc: A fix (bug #5733: Table handler error with self-join multi-table DELETE). sql/records.cc: ]A fix (bug #5733: Table handler error with self-join multi-table DELETE). mysql-test/t/delete.test: A fix (bug #5733: Table handler error with self-join multi-table DELETE). mysql-test/r/delete.result: A fix (bug #5733: Table handler error with self-join multi-table DELETE). --- mysql-test/r/delete.result | 11 +++++++++++ mysql-test/t/delete.test | 10 ++++++++++ sql/records.cc | 27 ++++++++++++++++++--------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index abc8245e69f..7353e687ae7 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -50,3 +50,14 @@ select count(*) from t1; count(*) 0 drop table t1; +create table t1 (a int not null auto_increment primary key, b char(32)); +insert into t1 (b) values ('apple'), ('apple'); +select * from t1; +a b +1 apple +2 apple +delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a; +select * from t1; +a b +1 apple +drop table t1; diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 904d959d148..07cb9155b3f 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -61,3 +61,13 @@ select count(*) from t1; drop table t1; +# +# Bug #5733: Table handler error with self-join multi-table DELETE +# + +create table t1 (a int not null auto_increment primary key, b char(32)); +insert into t1 (b) values ('apple'), ('apple'); +select * from t1; +delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a; +select * from t1; +drop table t1; diff --git a/sql/records.cc b/sql/records.cc index 415e75a467b..02ae2e06141 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -131,17 +131,26 @@ void end_read_record(READ_RECORD *info) static int rr_quick(READ_RECORD *info) { - int tmp=info->select->quick->get_next(); - if (tmp) + int tmp; + while ((tmp= info->select->quick->get_next())) { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else + if (info->thd->killed) { - if (info->print_error) - info->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; + my_error(ER_SERVER_SHUTDOWN, MYF(0)); + return 1; + } + if (tmp != HA_ERR_RECORD_DELETED) + { + if (tmp == HA_ERR_END_OF_FILE) + tmp= -1; + else + { + if (info->print_error) + info->file->print_error(tmp,MYF(0)); + if (tmp < 0) // Fix negative BDB errno + tmp=1; + } + break; } } return tmp; From a49f5cae9ad6f4de7f5c2d9f8bbdbca270376af6 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 3 Oct 2004 00:20:47 +0100 Subject: [PATCH 39/44] Bug#4118: multi-table UPDATE takes WRITE lock on read table Ensures that WRITE lock is not obtained on all tables referenced. mysql-test/r/lock_multi.result: Bug#4118 New test for multi-update locking mysql-test/r/multi_update.result: Bug#4118 Fix test mysql-test/t/lock_multi.test: Bug#4118 New test for multi-update locking mysql-test/t/multi_update.test: Bug#4118 Fix test sql/sql_parse.cc: Bug#4118 Split multi-update to its own case statement in sql_parse.cc sql/sql_update.cc: Bug#4118 Overview of locking checking: 1. Open and acquire READ lock 2. Check to see which tables need WRITE lock 3. Unlock tables and relock sql/sql_yacc.yy: Bug#4118 Split multi-update to its own case statement in sql_parse.cc --- mysql-test/r/lock_multi.result | 12 ++++ mysql-test/r/multi_update.result | 1 - mysql-test/t/lock_multi.test | 24 +++++++ mysql-test/t/multi_update.test | 2 - sql/sql_parse.cc | 31 +++++---- sql/sql_update.cc | 106 ++++++++++++++++++++++++++----- sql/sql_yacc.yy | 12 +++- 7 files changed, 155 insertions(+), 33 deletions(-) diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index b808fca0acf..b5672fe1791 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -17,6 +17,18 @@ unlock tables; n 1 drop table t1; +create table t1 (a int, b int); +create table t2 (c int, d int); +insert into t1 values(1,1); +insert into t1 values(2,2); +insert into t2 values(1,2); +lock table t1 read; + update t1,t2 set c=a where b=d; +select c from t2; +c +2 +drop table t1; +drop table t2; create table t1 (a int); create table t2 (a int); lock table t1 write, t2 write; diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index 12cb965f045..fc414f2f46b 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -151,7 +151,6 @@ Table 't2' was locked with a READ lock and can't be updated UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n; Table 't2' was locked with a READ lock and can't be updated UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n; -Table 't2' was locked with a READ lock and can't be updated unlock tables; LOCK TABLES t1 write, t2 write; UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index 0295fca29e7..e20f8163751 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -50,6 +50,30 @@ connection reader; reap; drop table t1; +# +# Test problem when using locks with multi-updates +# It should not block when multi-update is reading on a read-locked table +# + +connection locker; +create table t1 (a int, b int); +create table t2 (c int, d int); +insert into t1 values(1,1); +insert into t1 values(2,2); +insert into t2 values(1,2); +lock table t1 read; +connection writer; +--sleep 2 +send update t1,t2 set c=a where b=d; +connection reader; +--sleep 2 +select c from t2; +connection writer; +reap; +connection locker; +drop table t1; +drop table t2; + # # Test problem when using locks on many tables and droping a table that # is to-be-locked by another thread diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 39ea136bde1..3494126f890 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -151,8 +151,6 @@ LOCK TABLES t1 write, t2 read; DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n; --error 1099 UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n; -# The following should be fixed to not give an error ---error 1099 UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n; unlock tables; LOCK TABLES t1 write, t2 write; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e95c52f1e48..894fa355262 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1927,21 +1927,26 @@ mysql_execute_command(void) send_error(&thd->net,ER_WRONG_VALUE_COUNT); DBUG_VOID_RETURN; } - if (select_lex->table_list.elements == 1) + if (check_one_table_access(thd, UPDATE_ACL, tables, 0)) + goto error; /* purecov: inspected */ + + + res= mysql_update(thd,tables, + select_lex->item_list, + lex->value_list, + select_lex->where, + (ORDER *) select_lex->order_list.first, + select_lex->select_limit, + lex->duplicates); + break; + case SQLCOM_MULTI_UPDATE: + if (check_db_used(thd,tables)) + goto error; + if (select_lex->item_list.elements != lex->value_list.elements) { - if (check_one_table_access(thd, UPDATE_ACL, tables, 0)) - goto error; /* purecov: inspected */ - - - res= mysql_update(thd,tables, - select_lex->item_list, - lex->value_list, - select_lex->where, - (ORDER *) select_lex->order_list.first, - select_lex->select_limit, - lex->duplicates); + send_error(&thd->net,ER_WRONG_VALUE_COUNT); + DBUG_VOID_RETURN; } - else { const char *msg= 0; TABLE_LIST *table; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index d51c81ee127..a17742df03b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -401,25 +401,101 @@ int mysql_multi_update(THD *thd, int res; multi_update *result; TABLE_LIST *tl; + const bool locked= !(thd->locked_tables); DBUG_ENTER("mysql_multi_update"); - if ((res=open_and_lock_tables(thd,table_list))) - DBUG_RETURN(res); - - thd->select_limit=HA_POS_ERROR; - - /* - Ensure that we have update privilege for all tables and columns in the - SET part - */ - for (tl= table_list ; tl ; tl=tl->next) + for (;;) { - TABLE *table= tl->table; - table->grant.want_privilege= (UPDATE_ACL & ~table->grant.privilege); - } + table_map update_map= 0; + int tnr= 0; + + if ((res= open_tables(thd, table_list))) + DBUG_RETURN(res); - if (setup_fields(thd, table_list, *fields, 1, 0, 0)) - DBUG_RETURN(-1); + /* + Only need to call lock_tables if (thd->locked_tables == NULL) + */ + if (locked && ((res= lock_tables(thd, table_list)))) + DBUG_RETURN(res); + + thd->select_limit=HA_POS_ERROR; + + /* + Ensure that we have update privilege for all tables and columns in the + SET part + While we are here, initialize the table->map field. + */ + for (tl= table_list ; tl ; tl=tl->next) + { + TABLE *table= tl->table; + table->grant.want_privilege= (UPDATE_ACL & ~table->grant.privilege); + table->map= (table_map) 1 << (tnr++); + } + + if (!setup_fields(thd, table_list, *fields, 1, 0, 0)) + { + List_iterator_fast field_it(*fields); + Item_field *item; + + while ((item= (Item_field *) field_it++)) + update_map|= item->used_tables(); + + DBUG_PRINT("info",("update_map=0x%08x", update_map)); + } + else + DBUG_RETURN(-1); + + /* + Unlock the tables in preparation for relocking + */ + if (locked) + { + pthread_mutex_lock(&LOCK_open); + mysql_unlock_tables(thd, thd->lock); + thd->lock= 0; + pthread_mutex_unlock(&LOCK_open); + } + + /* + Set the table locking strategy according to the update map + */ + for (tl= table_list ; tl ; tl=tl->next) + { + TABLE *table= tl->table; + if (update_map & table->map) + { + DBUG_PRINT("info",("setting table `%s` for update", tl->alias)); + tl->lock_type= thd->lex.lock_option; + tl->updating= 1; + } + else + { + DBUG_PRINT("info",("setting table `%s` for read-only", tl->alias)); + tl->lock_type= TL_READ; + tl->updating= 0; + } + if (locked) + tl->table->reginfo.lock_type= tl->lock_type; + } + + /* + Relock the tables + */ + if (!(res=lock_tables(thd,table_list))) + break; + + if (!locked) + DBUG_RETURN(res); + + List_iterator_fast field_it(*fields); + Item_field *item; + + while ((item= (Item_field *) field_it++)) + /* item->cleanup(); XXX Use this instead in MySQL 4.1+ */ + item->field= item->result_field= 0; + + close_thread_tables(thd); + } /* Count tables and setup timestamp handling diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 6b073db2e36..7b72c73a915 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2751,10 +2751,18 @@ update: lex->select->order_list.next= (byte**) &lex->select->order_list.first; } opt_low_priority opt_ignore join_table_list - SET update_list where_clause opt_order_clause delete_limit_clause + SET update_list { - set_lock_for_tables($3); + if (Lex->select->table_list.elements > 1) + { + LEX *lex=Lex; + lex->sql_command= SQLCOM_MULTI_UPDATE; + lex->lock_option= $3; + } + else + set_lock_for_tables($3); } + where_clause opt_order_clause delete_limit_clause {} ; update_list: From a31b8f24e447a517dc90a8da51f4c4d743b0c00f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Oct 2004 16:24:37 +0300 Subject: [PATCH 40/44] InnoDB: make ALTER TABLE to work on table names containing '#' (Bug #5856) innobase/dict/dict0dict.c: dict_strip_comments(): do not look for comments within quotes (Bug #5856) innobase/row/row0mysql.c: row_drop_table_for_mysql(): Remove a memory leak --- innobase/dict/dict0dict.c | 22 ++++++++++++++++------ innobase/row/row0mysql.c | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index 61bf3fae137..4340934ab3d 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -2500,7 +2500,9 @@ dict_strip_comments( char* str; char* sptr; char* ptr; - + /* unclosed quote character (0 if none) */ + char quote = 0; + str = mem_alloc(strlen(sql_string) + 1); sptr = sql_string; @@ -2515,8 +2517,18 @@ scan_more: return(str); } - - if (*sptr == '#' + + if (*sptr == quote) { + /* Closing quote character: do not look for + starting quote or comments. */ + quote = 0; + } else if (quote) { + /* Within quotes: do not look for + starting quotes or comments. */ + } else if (*sptr == '"' || *sptr == '`') { + /* Starting quote: remember the quote character. */ + quote = *sptr; + } else if (*sptr == '#' || (0 == memcmp("-- ", sptr, 3))) { for (;;) { /* In Unix a newline is 0x0A while in Windows @@ -2531,9 +2543,7 @@ scan_more: sptr++; } - } - - if (*sptr == '/' && *(sptr + 1) == '*') { + } else if (!quote && *sptr == '/' && *(sptr + 1) == '*') { for (;;) { if (*sptr == '*' && *(sptr + 1) == '/') { diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index a23444df4ef..a884dc8d9ef 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -2051,6 +2051,7 @@ row_drop_table_for_mysql( memcpy(sql, str1, (sizeof str1) - 1); memcpy(sql + (sizeof str1) - 1, quoted_name, namelen); memcpy(sql + (sizeof str1) - 1 + namelen, str2, sizeof str2); + mem_free(quoted_name); /* Serialize data dictionary operations with dictionary mutex: no deadlocks can occur then in these operations */ From c0364263d9dcc9f122529804576f65640587acd4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Oct 2004 23:26:42 +0500 Subject: [PATCH 41/44] patch fixing after review on patch-fixing of Bug #5492 "set @@session.read_rnd_buffer_size=33554432" crashes server on query 1. added warning comments for uint3korr (need one more byte allocated) 2. unsigned long in uint3korr was replaced by unsigned int to avoid problems on 64-bits platforms 3. shorten warning comments in init_rr_cache in sql/records.cc include/config-win.h: 1. added warning comments for uint3korr (need one more byte allocated) 2. unsigned long in uint3korr was replaced by unsigned int to avoid problems on 64-bits platforms include/my_global.h: 1. added warning comments for uint3korr (need one more byte allocated) 2. unsigned long in uint3korr was replaced by unsigned int to avoid problems on 64-bits platforms sql/records.cc: shorten warning comments for my_malloc_lock in init_rr_cache --- include/config-win.h | 8 +++++++- include/my_global.h | 8 +++++++- sql/records.cc | 7 +------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/config-win.h b/include/config-win.h index bb6d663bd8d..152e85c8e68 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -218,7 +218,13 @@ inline double ulonglong2double(ulonglong value) ((uint32) (uchar) (A)[0]))) #define sint4korr(A) (*((long *) (A))) #define uint2korr(A) (*((uint16 *) (A))) -#define uint3korr(A) (long) (*((unsigned long *) (A)) & 0xFFFFFF) +/* + ATTENTION ! + + Please, note, uint3korr reads 4 bytes (not 3) ! + It means, that you have to provide enough allocated space ! +*/ +#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) #define uint4korr(A) (*((unsigned long *) (A))) #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ diff --git a/include/my_global.h b/include/my_global.h index f24fc05471e..6871dfbf6c6 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -898,7 +898,13 @@ typedef char bool; /* Ordinary boolean values 0 1 */ (((uint32) ((uchar) (A)[1])) << 8) +\ (((uint32) ((uchar) (A)[2])) << 16)) #else -#define uint3korr(A) (long) (*((unsigned long *) (A)) & 0xFFFFFF) +/* + ATTENTION ! + + Please, note, uint3korr reads 4 bytes (not 3) ! + It means, that you have to provide enough allocated space ! +*/ +#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) #endif #define uint4korr(A) (*((unsigned long *) (A))) #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ diff --git a/sql/records.cc b/sql/records.cc index a2c6eb0a040..7cbb1ab3205 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -249,12 +249,7 @@ static int init_rr_cache(READ_RECORD *info) rec_cache_size=info->cache_records*info->reclength; info->rec_cache_size=info->cache_records*info->ref_length; - /* - We are going to read the last three bytes of the buffer via uint3korr - This macro reads actually 4 bytes (for speed) - So, we have to allocate one more byte at the end of the buffer - to avoid memory assertion fault - */ + // We have to allocate one more byte to use uint3korr (see comments for it) if (info->cache_records <= 2 || !(info->cache=(byte*) my_malloc_lock(rec_cache_size+info->cache_records* info->struct_length+1, From 83b54807223200714ac1c6bc2ba2a73b02423d55 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2004 14:47:10 +0300 Subject: [PATCH 42/44] Fix for wrongly calculated Examined_rows in 4.0 UNION's. sql/sql_union.cc: Fixing a non-critical bug in 4.0 UNION's which results in erronously calculated number o fexamined rows. This value is displayed in the slow query log. This is a bug number #5879. --- sql/sql_union.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sql/sql_union.cc b/sql/sql_union.cc index f79ff7967db..f9c21079851 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -39,6 +39,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) TABLE_LIST *first_table=(TABLE_LIST *)lex->select_lex.table_list.first; TMP_TABLE_PARAM tmp_table_param; select_union *union_result; + ha_rows examined_rows= 0; DBUG_ENTER("mysql_union"); /* Fix tables 'to-be-unioned-from' list to point at opened tables */ @@ -202,6 +203,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) union_result); if (res) goto exit; + examined_rows+= thd->examined_row_count; /* Needed for the following test and for records_at_start in next loop */ table->file->info(HA_STATUS_VARIABLE); if (found_rows_for_union & sl->options) @@ -258,12 +260,15 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) if (describe) thd->select_limit= HA_POS_ERROR; // no limit - res=mysql_select(thd,&result_table_list, + res= mysql_select(thd,&result_table_list, item_list, NULL, (describe) ? 0 : order, (ORDER*) NULL, NULL, (ORDER*) NULL, thd->options, result); if (!res) - thd->limit_found_rows = (ulonglong)table->file->records + add_rows; + { + thd->limit_found_rows= (ulonglong)table->file->records + add_rows; + thd->examined_row_count+= examined_rows; + } } } From 1539b03934dfe7a317ab90fc70113838ca24c93f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2004 21:19:40 +0500 Subject: [PATCH 43/44] Fix for #5730 (Query cache crashes server) Recusive part leads to stack overflow sql/sql_cache.cc: Recursion removed from Query_cache::allocate_data_chain --- sql/sql_cache.cc | 75 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 5118421464b..60f0cfadc8e 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1843,7 +1843,6 @@ inline ulong Query_cache::get_min_append_result_data_size() /* Allocate one or more blocks to hold data */ - my_bool Query_cache::allocate_data_chain(Query_cache_block **result_block, ulong data_len, Query_cache_block *query_block, @@ -1851,55 +1850,55 @@ my_bool Query_cache::allocate_data_chain(Query_cache_block **result_block, { ulong all_headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) + ALIGN_SIZE(sizeof(Query_cache_result))); - ulong len= data_len + all_headers_len; - ulong align_len= ALIGN_SIZE(len); - DBUG_ENTER("Query_cache::allocate_data_chain"); - DBUG_PRINT("qcache", ("data_len %lu, all_headers_len %lu", - data_len, all_headers_len)); - ulong min_size = (first_block_arg ? get_min_first_result_data_size(): get_min_append_result_data_size()); - *result_block = allocate_block(max(min_size, align_len), - min_result_data_size == 0, - all_headers_len + min_result_data_size, - 1); - my_bool success = (*result_block != 0); - if (success) + Query_cache_block *prev_block= NULL; + Query_cache_block *new_block; + DBUG_ENTER("Query_cache::allocate_data_chain"); + DBUG_PRINT("qcache", ("data_len %lu, all_headers_len %lu", + data_len, all_headers_len)); + + do { - Query_cache_block *new_block= *result_block; + ulong len= data_len + all_headers_len; + ulong align_len= ALIGN_SIZE(len); + + if (!(new_block= allocate_block(max(min_size, align_len), + min_result_data_size == 0, + all_headers_len + min_result_data_size, + 1))) + { + DBUG_PRINT("warning", ("Can't allocate block for results")); + DBUG_RETURN(FALSE); + } + new_block->n_tables = 0; - new_block->used = 0; + new_block->used = min(len, new_block->length); new_block->type = Query_cache_block::RES_INCOMPLETE; new_block->next = new_block->prev = new_block; Query_cache_result *header = new_block->result(); header->parent(query_block); - if (new_block->length < len) - { - /* - We got less memory then we need (no big memory blocks) => - Continue to allocated more blocks until we got everything we need. - */ - Query_cache_block *next_block; - if ((success = allocate_data_chain(&next_block, - len - new_block->length, - query_block, first_block_arg))) - double_linked_list_join(new_block, next_block); - } - if (success) - { - new_block->used = min(len, new_block->length); - - DBUG_PRINT("qcache", ("Block len %lu used %lu", + DBUG_PRINT("qcache", ("Block len %lu used %lu", new_block->length, new_block->used)); - } + + if (prev_block) + double_linked_list_join(prev_block, new_block); else - DBUG_PRINT("warning", ("Can't allocate block for continue")); - } - else - DBUG_PRINT("warning", ("Can't allocate block for results")); - DBUG_RETURN(success); + *result_block= new_block; + if (new_block->length >= len) + break; + + /* + We got less memory then we need (no big memory blocks) => + Continue to allocated more blocks until we got everything we need. + */ + data_len= len - new_block->length; + prev_block= new_block; + } while(1); + + DBUG_RETURN(TRUE); } /***************************************************************************** From 0d76cb7ea4a20570342d51136a6da598fb553800 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Oct 2004 01:24:21 +0300 Subject: [PATCH 44/44] Reverted patch for new usage of open_count as it caused more problems than it solved Cleaned up patch for checking locks for multi-table updates myisam/mi_close.c: Reverted patch for new usage of open_counts myisam/mi_locking.c: Reverted patch for new usage of open_counts sql/ha_myisam.cc: Reverted patch for new usage of open_counts sql/handler.cc: Removed compiler warning sql/sql_acl.cc: Removed compiler warning sql/sql_table.cc: No need to unlock after failed call to external_lock() sql/sql_update.cc: Cleaned up (and made it more secure) patch for checking locks for multi-table updates --- myisam/mi_close.c | 9 +++- myisam/mi_locking.c | 117 +++++++++++++------------------------------- sql/ha_myisam.cc | 26 ++-------- sql/handler.cc | 2 +- sql/sql_acl.cc | 2 +- sql/sql_table.cc | 6 +-- sql/sql_update.cc | 112 +++++++++++++++++++++++++----------------- 7 files changed, 116 insertions(+), 158 deletions(-) diff --git a/myisam/mi_close.c b/myisam/mi_close.c index 47308a5e9eb..2712f0ca283 100644 --- a/myisam/mi_close.c +++ b/myisam/mi_close.c @@ -70,8 +70,13 @@ int mi_close(register MI_INFO *info) error=my_errno; if (share->kfile >= 0) { - /* We must always flush the state with the current open_count. */ - if (share->mode != O_RDONLY) + /* + If we are crashed, we can safely flush the current state as it will + not change the crashed state. + We can NOT write the state in other cases as other threads + may be using the file at this point + */ + if (share->mode != O_RDONLY && mi_is_crashed(info)) mi_state_info_write(share->kfile, &share->state, 1); if (my_close(share->kfile,MYF(0))) error = my_errno; diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c index 8a140a8b6fb..1efd203dc5f 100644 --- a/myisam/mi_locking.c +++ b/myisam/mi_locking.c @@ -19,16 +19,26 @@ reads info from a isam-table. Must be first request before doing any furter calls to any isamfunktion. Is used to allow many process use the same isamdatabase. - */ +*/ + +/* + state.open_count in the .MYI file is used the following way: + - For the first change of the file in this process it's incremented with + mi_mark_file_change(). (We have a write lock on the file in this case) + - In mi_close() it's decremented by _mi_decrement_open_count() if it + was incremented in the same process. + + This mean that if we are the only process using the file, the open_count + tells us if the MYISAM file wasn't properly closed. (This is true if + my_disable_locking is set). +*/ + #include "myisamdef.h" #ifdef __WIN__ #include #endif -static int mi_unlock_open_count(MI_INFO *info, my_bool write_info); - - /* lock table by F_UNLCK, F_RDLCK or F_WRLCK */ int mi_lock_database(MI_INFO *info, int lock_type) @@ -38,17 +48,17 @@ int mi_lock_database(MI_INFO *info, int lock_type) MYISAM_SHARE *share=info->s; uint flag; DBUG_ENTER("mi_lock_database"); - DBUG_PRINT("enter",("mi_lock_database: lock_type %d, old lock %d" - ", r_locks %u, w_locks %u", lock_type, - info->lock_type, share->r_locks, share->w_locks)); - DBUG_PRINT("enter",("mi_lock_database: gl._changed %d, open_count %u '%s'", + DBUG_PRINT("enter",("lock_type: %d old lock %d r_locks: %u w_locks: %u " + "global_changed: %d open_count: %u name: '%s'", + lock_type, info->lock_type, share->r_locks, + share->w_locks, share->global_changed, share->state.open_count, share->index_file_name)); if (share->options & HA_OPTION_READ_ONLY_DATA || info->lock_type == lock_type) DBUG_RETURN(0); - if (lock_type == F_EXTRA_LCK) + if (lock_type == F_EXTRA_LCK) /* Used by TMP tables */ { ++share->w_locks; ++share->tot_locks; @@ -90,8 +100,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) share->state.process= share->last_process=share->this_process; share->state.unique= info->last_unique= info->this_unique; share->state.update_count= info->last_loop= ++info->this_loop; - if (mi_unlock_open_count(info, FALSE) || - mi_state_info_write(share->kfile, &share->state, 1)) + if (mi_state_info_write(share->kfile, &share->state, 1)) error=my_errno; share->changed=0; if (myisam_flush) @@ -106,19 +115,6 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (error) mi_mark_crashed(info); } - else - { - /* - There are chances that _mi_mark_file_changed() has been called, - while share->changed remained FALSE. Consequently, we need to - clear the open_count even when share->changed is FALSE. Note, - that mi_unlock_open_count() will only clear the open_count when - it is set and only write the status to file, if it changes it - and we are running --with-external-locking. - */ - if (mi_unlock_open_count(info, ! my_disable_locking)) - error= my_errno; - } if (info->lock_type != F_EXTRA_LCK) { if (share->r_locks) @@ -142,16 +138,17 @@ int mi_lock_database(MI_INFO *info, int lock_type) break; case F_RDLCK: if (info->lock_type == F_WRLCK) - { /* Change RW to READONLY */ + { /* + Change RW to READONLY + mysqld does not turn write locks to read locks, so we're never here in mysqld. */ if (share->w_locks == 1) { flag=1; - if (mi_unlock_open_count(info, ! my_disable_locking) || - my_lock(share->kfile,lock_type,0L,F_TO_EOF, + if (my_lock(share->kfile,lock_type,0L,F_TO_EOF, MYF(MY_SEEK_NOT_DONE))) { error=my_errno; @@ -179,14 +176,6 @@ int mi_lock_database(MI_INFO *info, int lock_type) my_errno=error; break; } - if (share->state.open_count) - { - DBUG_PRINT("error",("RD: Table has not been correctly unlocked" - ": open_count %d '%s'", - share->state.open_count, - share->index_file_name)); - mi_mark_crashed(info); - } } VOID(_mi_test_if_changed(info)); share->r_locks++; @@ -232,14 +221,6 @@ int mi_lock_database(MI_INFO *info, int lock_type) my_errno=error; break; } - if (share->state.open_count) - { - DBUG_PRINT("error",("WR: Table has not been correctly unlocked" - ": open_count %d '%s'", - share->state.open_count, - share->index_file_name)); - mi_mark_crashed(info); - } } } } @@ -375,9 +356,10 @@ int _mi_readinfo(register MI_INFO *info, int lock_type, int check_keybuffer) } /* _mi_readinfo */ - /* Every isam-function that uppdates the isam-database must! end */ - /* with this request */ - /* ARGSUSED */ +/* + Every isam-function that uppdates the isam-database MUST end with this + request +*/ int _mi_writeinfo(register MI_INFO *info, uint operation) { @@ -450,6 +432,8 @@ int _mi_mark_file_changed(MI_INFO *info) { char buff[3]; register MYISAM_SHARE *share=info->s; + DBUG_ENTER("_mi_mark_file_changed"); + if (!(share->state.changed & STATE_CHANGED) || ! share->global_changed) { share->state.changed|=(STATE_CHANGED | STATE_NOT_ANALYZED | @@ -463,12 +447,12 @@ int _mi_mark_file_changed(MI_INFO *info) { mi_int2store(buff,share->state.open_count); buff[2]=1; /* Mark that it's changed */ - return (my_pwrite(share->kfile,buff,sizeof(buff), - sizeof(share->state.header), - MYF(MY_NABP))); + DBUG_RETURN(my_pwrite(share->kfile,buff,sizeof(buff), + sizeof(share->state.header), + MYF(MY_NABP))); } } - return 0; + DBUG_RETURN(0); } @@ -501,36 +485,3 @@ int _mi_decrement_open_count(MI_INFO *info) } return test(lock_error || write_error); } - -/* - Decrement open_count in preparation for unlock. - - SYNOPSIS - mi_unlock_open_count() - info Pointer to the MI_INFO structure. - write_info If info must be written when changed. - - RETURN - 0 OK -*/ - -static int mi_unlock_open_count(MI_INFO *info, my_bool write_info) -{ - int rc= 0; - MYISAM_SHARE *share=info->s; - - DBUG_ENTER("mi_unlock_open_count"); - DBUG_PRINT("enter",("mi_unlock_open_count: gl._changed %d open_count %d '%s'", - share->global_changed, share->state.open_count, - share->index_file_name)); - if (share->global_changed) - { - share->global_changed= 0; - if (share->state.open_count) - share->state.open_count--; - if (write_info) - rc= _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); - } - DBUG_RETURN(rc); -} - diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 2b7b8f436b1..3bfee7cdd79 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -998,32 +998,14 @@ int ha_myisam::delete_table(const char *name) return mi_delete_table(name); } + int ha_myisam::external_lock(THD *thd, int lock_type) { - int rc; - - while ((! (rc= mi_lock_database(file, !table->tmp_table ? - lock_type : ((lock_type == F_UNLCK) ? - F_UNLCK : F_EXTRA_LCK)))) && - mi_is_crashed(file) && (myisam_recover_options != HA_RECOVER_NONE)) - { - /* - check_and_repair() implicitly write locks the table, unless a - LOCK TABLES is in effect. It should be safer to always write lock here. - The implicit lock by check_and_repair() will then be a no-op. - check_and_repair() does not restore the original lock, but unlocks the - table. So we have to get the requested lock type again. And then to - check, if the table has been crashed again meanwhile by another server. - If anything fails, we break. - */ - if (((lock_type != F_WRLCK) && (rc= mi_lock_database(file, F_WRLCK))) || - (rc= check_and_repair(thd))) - break; - } - return rc; + return mi_lock_database(file, !table->tmp_table ? + lock_type : ((lock_type == F_UNLCK) ? + F_UNLCK : F_EXTRA_LCK)); } - THR_LOCK_DATA **ha_myisam::store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) diff --git a/sql/handler.cc b/sql/handler.cc index 9eb129fab45..65078a485c5 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -348,7 +348,7 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) if (trans == &thd->transaction.all && my_b_tell(&thd->transaction.trans_log)) { - if (error= wait_if_global_read_lock(thd, 0, 0)) + if ((error= wait_if_global_read_lock(thd, 0, 0))) { /* Note that ROLLBACK [TO SAVEPOINT] does not have this test; it's diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 58d0fe9a7fa..6e782f81ae5 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -469,7 +469,7 @@ static ulong get_sort(uint count,...) uint chars= 0; uint wild_pos= 0; /* first wildcard position */ - if (start= str) + if ((start= str)) { for (; *str ; str++) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0dd5c65bf79..6561af9c841 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2209,11 +2209,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, DBUG_RETURN(-1); /* purecov: inspected */ if (to->file->external_lock(thd, F_WRLCK)) - { - /* We must always unlock, even when lock failed. */ - (void) to->file->external_lock(thd, F_UNLCK); DBUG_RETURN(-1); - } to->file->extra(HA_EXTRA_WRITE_CACHE); from->file->info(HA_STATUS_VARIABLE); to->file->deactivate_non_unique_index(from->file->records); @@ -2313,11 +2309,11 @@ copy_data_between_tables(TABLE *from,TABLE *to, error=1; if (ha_commit(thd)) error=1; + err: free_io_cache(from); *copied= found_count; *deleted=delete_count; - /* we must always unlock the table on return. */ if (to->file->external_lock(thd,F_UNLCK)) error=1; DBUG_RETURN(error > 0 ? -1 : 0); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index a17742df03b..cdcc90e8651 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -386,6 +386,24 @@ err: Update multiple tables from join ***************************************************************************/ +/* + Get table map for list of Item_field +*/ + +static table_map get_table_map(List *items) +{ + List_iterator_fast item_it(*items); + Item_field *item; + table_map map= 0; + + while ((item= (Item_field *) item_it++)) + map|= item->used_tables(); + DBUG_PRINT("info",("table_map: 0x%08x", map)); + return map; +} + + + /* Setup multi-update handling and call SELECT to do the join */ @@ -401,59 +419,45 @@ int mysql_multi_update(THD *thd, int res; multi_update *result; TABLE_LIST *tl; - const bool locked= !(thd->locked_tables); + const bool using_lock_tables= thd->locked_tables != 0; DBUG_ENTER("mysql_multi_update"); + thd->select_limit= HA_POS_ERROR; + for (;;) { - table_map update_map= 0; - int tnr= 0; + table_map update_map; + int tnr; if ((res= open_tables(thd, table_list))) DBUG_RETURN(res); - /* - Only need to call lock_tables if (thd->locked_tables == NULL) - */ - if (locked && ((res= lock_tables(thd, table_list)))) + /* Only need to call lock_tables if we are not using LOCK TABLES */ + if (!using_lock_tables && ((res= lock_tables(thd, table_list)))) DBUG_RETURN(res); - thd->select_limit=HA_POS_ERROR; - /* Ensure that we have update privilege for all tables and columns in the SET part While we are here, initialize the table->map field. */ - for (tl= table_list ; tl ; tl=tl->next) + for (tl= table_list,tnr=0 ; tl ; tl=tl->next) { TABLE *table= tl->table; table->grant.want_privilege= (UPDATE_ACL & ~table->grant.privilege); table->map= (table_map) 1 << (tnr++); } - if (!setup_fields(thd, table_list, *fields, 1, 0, 0)) - { - List_iterator_fast field_it(*fields); - Item_field *item; - - while ((item= (Item_field *) field_it++)) - update_map|= item->used_tables(); - - DBUG_PRINT("info",("update_map=0x%08x", update_map)); - } - else + if (setup_fields(thd, table_list, *fields, 1, 0, 0)) DBUG_RETURN(-1); - /* - Unlock the tables in preparation for relocking - */ - if (locked) + update_map= get_table_map(fields); + + /* Unlock the tables in preparation for relocking */ + if (!using_lock_tables) { - pthread_mutex_lock(&LOCK_open); mysql_unlock_tables(thd, thd->lock); thd->lock= 0; - pthread_mutex_unlock(&LOCK_open); } /* @@ -474,26 +478,48 @@ int mysql_multi_update(THD *thd, tl->lock_type= TL_READ; tl->updating= 0; } - if (locked) + if (!using_lock_tables) tl->table->reginfo.lock_type= tl->lock_type; } + /* Relock the tables with the correct modes */ + res= lock_tables(thd,table_list); + if (using_lock_tables) + { + if (res) + DBUG_RETURN(res); + break; // Don't have to do setup_field() + } + /* - Relock the tables + We must setup fields again as the file may have been reopened + during lock_tables */ - if (!(res=lock_tables(thd,table_list))) + + { + List_iterator_fast field_it(*fields); + Item_field *item; + + while ((item= (Item_field *) field_it++)) +#if MYSQL_VERSION < 40100 + item->field= item->result_field= 0; +#else + item->cleanup(); +#endif + } + if (setup_fields(thd, table_list, *fields, 1, 0, 0)) + DBUG_RETURN(-1); + /* + If lock succeded and the table map didn't change since the above lock + we can continue. + */ + if (!res && update_map == get_table_map(fields)) break; - - if (!locked) - DBUG_RETURN(res); - - List_iterator_fast field_it(*fields); - Item_field *item; - - while ((item= (Item_field *) field_it++)) - /* item->cleanup(); XXX Use this instead in MySQL 4.1+ */ - item->field= item->result_field= 0; + /* + There was some very unexpected changes in the table definition between + open tables and lock tables. Close tables and try again. + */ close_thread_tables(thd); } @@ -548,7 +574,7 @@ int multi_update::prepare(List ¬_used_values) { TABLE_LIST *table_ref; SQL_LIST update; - table_map tables_to_update= 0; + table_map tables_to_update; Item_field *item; List_iterator_fast field_it(*fields); List_iterator_fast value_it(*values); @@ -559,8 +585,7 @@ int multi_update::prepare(List ¬_used_values) thd->cuted_fields=0L; thd->proc_info="updating main table"; - while ((item= (Item_field *) field_it++)) - tables_to_update|= item->used_tables(); + tables_to_update= get_table_map(fields); if (!tables_to_update) { @@ -624,7 +649,6 @@ int multi_update::prepare(List ¬_used_values) /* Split fields into fields_for_table[] and values_by_table[] */ - field_it.rewind(); while ((item= (Item_field *) field_it++)) { Item *value= value_it++;