diff options
author | unknown <monty@mysql.com> | 2004-07-07 11:29:39 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2004-07-07 11:29:39 +0300 |
commit | 11b8987313aab1eb8d9f829731fa0dcd83bf62f5 (patch) | |
tree | ca8974710746bb69b04a49bc64f938d0b1a8420a /sql | |
parent | c92670d80b3674fa025e373e0498eccbb407f873 (diff) | |
parent | 9890cd9a9eb37083d13370947fa50d64e21e54ff (diff) | |
download | mariadb-git-11b8987313aab1eb8d9f829731fa0dcd83bf62f5.tar.gz |
Merge with 4.1.3-beta
BitKeeper/etc/ignore:
auto-union
BitKeeper/etc/logging_ok:
auto-union
VC++Files/libmysqld/libmysqld.dsp:
Auto merged
VC++Files/sql/mysqld.dsp:
Auto merged
client/mysql.cc:
Auto merged
client/mysqlbinlog.cc:
Auto merged
client/mysqltest.c:
Auto merged
include/config-netware.h:
Auto merged
include/my_base.h:
Auto merged
include/my_global.h:
Auto merged
include/my_sys.h:
Auto merged
include/mysql_com.h:
Auto merged
include/sql_state.h:
Auto merged
innobase/include/row0mysql.h:
Auto merged
innobase/row/row0sel.c:
Auto merged
libmysql/libmysql.c:
Auto merged
libmysqld/lib_sql.cc:
Auto merged
myisam/mi_check.c:
Auto merged
mysql-test/r/bdb.result:
Auto merged
mysql-test/r/connect.result:
Auto merged
mysql-test/r/ctype_ucs.result:
Auto merged
mysql-test/r/derived.result:
Auto merged
mysql-test/r/func_group.result:
Auto merged
mysql-test/r/func_like.result:
Auto merged
mysql-test/r/func_sapdb.result:
Auto merged
mysql-test/r/func_time.result:
Auto merged
mysql-test/r/insert.result:
Auto merged
mysql-test/r/insert_select.result:
Auto merged
mysql-test/r/join_outer.result:
Auto merged
mysql-test/r/key.result:
Auto merged
mysql-test/r/multi_update.result:
Auto merged
mysql-test/r/mysqldump.result:
Auto merged
mysql-test/r/null.result:
Auto merged
mysql-test/r/null_key.result:
Auto merged
mysql-test/r/query_cache.result:
Auto merged
mysql-test/r/rpl_rotate_logs.result:
Auto merged
mysql-test/r/rpl_server_id1.result:
Auto merged
mysql-test/r/rpl_until.result:
Auto merged
mysql-test/r/select.result:
Auto merged
mysql-test/r/show_check.result:
Auto merged
mysql-test/r/subselect.result:
Auto merged
mysql-test/r/system_mysql_db.result:
Auto merged
mysql-test/r/union.result:
Auto merged
mysql-test/r/variables.result:
Auto merged
mysql-test/t/multi_update.test:
Auto merged
mysql-test/t/mysqlbinlog.test:
Auto merged
mysql-test/t/rpl000015.test:
Auto merged
mysql-test/t/subselect.test:
Auto merged
mysql-test/t/variables.test:
Auto merged
mysys/mf_iocache2.c:
Auto merged
mysys/my_bitmap.c:
Auto merged
mysys/my_pthread.c:
Auto merged
netware/Makefile.am:
Auto merged
netware/my_manage.c:
Auto merged
netware/mysql_test_run.c:
Auto merged
netware/BUILD/compile-linux-tools:
Auto merged
netware/BUILD/compile-netware-standard:
Auto merged
netware/BUILD/mwenv:
Auto merged
netware/BUILD/nwbootstrap:
Auto merged
scripts/make_binary_distribution.sh:
Auto merged
scripts/mysql_install_db.sh:
Auto merged
sql/ha_berkeley.cc:
Auto merged
sql/ha_berkeley.h:
Auto merged
sql/ha_heap.h:
Auto merged
sql/item.cc:
Auto merged
sql/item.h:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/item_create.cc:
Auto merged
sql/item_create.h:
Auto merged
sql/item_func.h:
Auto merged
sql/item_subselect.cc:
Auto merged
sql/item_sum.cc:
Auto merged
sql/item_sum.h:
Auto merged
sql/item_timefunc.h:
Auto merged
sql/lex.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/net_serv.cc:
Auto merged
sql/protocol.cc:
Auto merged
sql/protocol.h:
Auto merged
sql/records.cc:
Auto merged
sql/repl_failsafe.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/sql_acl.cc:
Auto merged
sql/sql_acl.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_derived.cc:
Auto merged
sql/sql_load.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_string.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/structs.h:
Auto merged
sql-common/client.c:
Auto merged
configure.in:
Merge with 4.1
include/mysqld_error.h:
New errors from 4.1
libmysqld/Makefile.am:
Merge with 4.1
myisam/myisamchk.c:
Merge with 4.1
myisam/myisamdef.h:
Merge with 4.1
myisam/sort.c:
Merge with 4.1
mysql-test/r/mysqlbinlog.result:
Merge with 4.1
mysql-test/r/range.result:
Merge with 4.1
mysql-test/r/rpl_flush_log_loop.result:
Merge with 4.1
mysql-test/r/rpl_replicate_do.result:
Merge with 4.1
mysql-test/r/rpl_temporary.result:
Merge with 4.1
mysql-test/r/rpl_user_variables.result:
Merge with 4.1
mysql-test/t/func_time.test:
Merge with 4.1
scripts/mysql_create_system_tables.sh:
Merge with 4.1
scripts/mysql_fix_privilege_tables.sql:
Merge with 4.1
sql/Makefile.am:
Merge with 4.1
sql/filesort.cc:
Merge with 4.1
sql/ha_innodb.cc:
Merge with 4.1
sql/ha_innodb.h:
Merge with 4.1
sql/ha_myisam.cc:
Merge with 4.1
sql/handler.cc:
Merge with 4.1
sql/handler.h:
Merge with 4.1
sql/item_func.cc:
Merge with 4.1
sql/item_timefunc.cc:
Merge with 4.1
sql/log.cc:
Merge with 4.1
sql/log_event.cc:
Merge with 4.1
sql/mysqld.cc:
Merge with 4.1
sql/opt_range.cc:
Merge with 4.1
sql/opt_range.h:
Merge with 4.1
sql/share/czech/errmsg.txt:
Merge with 4.1
Updated english error messages
sql/share/danish/errmsg.txt:
Merge with 4.1
sql/share/dutch/errmsg.txt:
Merge with 4.1
sql/share/english/errmsg.txt:
Merge with 4.1
sql/share/estonian/errmsg.txt:
Merge with 4.1
sql/share/french/errmsg.txt:
Merge with 4.1
sql/share/german/errmsg.txt:
Merge with 4.1
sql/share/greek/errmsg.txt:
Merge with 4.1
sql/share/hungarian/errmsg.txt:
Merge with 4.1
sql/share/italian/errmsg.txt:
Merge with 4.1
sql/share/japanese/errmsg.txt:
Merge with 4.1
sql/share/korean/errmsg.txt:
Merge with 4.1
sql/share/norwegian-ny/errmsg.txt:
Merge with 4.1
sql/share/norwegian/errmsg.txt:
Merge with 4.1
sql/share/polish/errmsg.txt:
Merge with 4.1
sql/share/portuguese/errmsg.txt:
Merge with 4.1
sql/share/romanian/errmsg.txt:
Merge with 4.1
sql/share/russian/errmsg.txt:
Merge with 4.1
sql/share/serbian/errmsg.txt:
Merge with 4.1
sql/share/slovak/errmsg.txt:
Merge with 4.1
sql/share/spanish/errmsg.txt:
Merge with 4.1
sql/share/swedish/errmsg.txt:
Merge with 4.1
sql/share/ukrainian/errmsg.txt:
Merge with 4.1
sql/slave.cc:
Merge with 4.1
sql/sql_class.cc:
Merge with 4.1
sql/sql_class.h:
Merge with 4.1
sql/sql_db.cc:
Merge with 4.1
sql/sql_insert.cc:
Merge with 4.1
sql/sql_lex.cc:
Merge with 4.1
sql/sql_lex.h:
Merge with 4.1
sql/sql_parse.cc:
Merge with 4.1 tree
Changed // comments to /* */
sql/sql_prepare.cc:
Merge with 4.1
sql/sql_select.cc:
Merge with 4.1
sql/sql_table.cc:
Merge with 4.1
sql/sql_yacc.yy:
Merge with 4.1
sql/table.h:
Merge with 4.1
tests/client_test.c:
Merge with 4.1
Diffstat (limited to 'sql')
107 files changed, 9603 insertions, 3660 deletions
diff --git a/sql/Makefile.am b/sql/Makefile.am index 828456c4510..a1eada6e3d2 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -27,6 +27,7 @@ WRAPLIBS= @WRAPLIBS@ SUBDIRS = share libexec_PROGRAMS = mysqld noinst_PROGRAMS = gen_lex_hash +bin_PROGRAMS = mysql_tzinfo_to_sql gen_lex_hash_LDFLAGS = @NOINST_LDFLAGS@ LDADD = @isam_libs@ \ ../myisam/libmyisam.a \ @@ -57,8 +58,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ lex.h lex_symbol.h sql_acl.h sql_crypt.h \ log_event.h sql_repl.h slave.h \ stacktrace.h sql_sort.h sql_cache.h set_var.h \ - spatial.h gstream.h client_settings.h \ - examples/ha_example.h \ + spatial.h gstream.h client_settings.h tzfile.h \ + tztime.h examples/ha_example.h examples/ha_archive.h \ sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \ parse_file.h mysqld_SOURCES = sql_lex.cc sql_handler.cc \ @@ -90,11 +91,14 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ client.c sql_client.cc mini_client_errors.c pack.c\ stacktrace.c repl_failsafe.h repl_failsafe.cc \ gstream.cc spatial.cc sql_help.cc protocol_cursor.cc \ - examples/ha_example.cc \ + tztime.cc my_time.c \ + examples/ha_example.cc examples/ha_archive.cc \ sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \ sp_cache.cc parse_file.cc gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS) +mysql_tzinfo_to_sql_SOURCES = mysql_tzinfo_to_sql.cc +mysql_tzinfo_to_sql_LDADD = $(LDADD) $(CXXLDFLAGS) DEFS = -DMYSQL_SERVER \ -DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \ @@ -106,17 +110,26 @@ BUILT_SOURCES = sql_yacc.cc sql_yacc.h EXTRA_DIST = udf_example.cc $(BUILT_SOURCES) AM_YFLAGS = -d -link_sources: +mysql_tzinfo_to_sql.cc: + rm -f mysql_tzinfo_to_sql.cc + @LN_CP_F@ tztime.cc mysql_tzinfo_to_sql.cc + +link_sources: mysql_tzinfo_to_sql.cc rm -f mini_client_errors.c @LN_CP_F@ ../libmysql/errmsg.c mini_client_errors.c rm -f pack.c @LN_CP_F@ ../sql-common/pack.c pack.c rm -f client.c @LN_CP_F@ ../sql-common/client.c client.c + rm -f my_time.c + @LN_CP_F@ ../sql-common/my_time.c my_time.c gen_lex_hash.o: gen_lex_hash.cc lex.h $(CXXCOMPILE) -c $(INCLUDES) $< +mysql_tzinfo_to_sql.o: $(mysql_tzinfo_to_sql_SOURCES) + $(CXXCOMPILE) -c $(INCLUDES) -DTZINFO2SQL $< + # Try to get better dependencies for the grammar. Othervise really bad # things like different grammars for different pars of MySQL can # happen if you are unlucky. diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc new file mode 100644 index 00000000000..e052a819ef8 --- /dev/null +++ b/sql/examples/ha_archive.cc @@ -0,0 +1,586 @@ +/* Copyright (C) 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 */ + +#ifdef __GNUC__ +#pragma implementation // gcc: Class implementation +#endif + +#include <mysql_priv.h> + +#ifdef HAVE_ARCHIVE_DB +#include "ha_archive.h" + +/* + First, if you want to understand storage engines you should look at + ha_example.cc and ha_example.h. + This example was written as a test case for a customer who needed + a storage engine without indexes that could compress data very well. + So, welcome to a completely compressed storage engine. This storage + engine only does inserts. No replace, deletes, or updates. All reads are + complete table scans. Compression is done through gzip (bzip compresses + better, but only marginally, if someone asks I could add support for + it too, but beaware that it costs a lot more in CPU time then gzip). + + We keep a file pointer open for each instance of ha_archive for each read + but for writes we keep one open file handle just for that. We flush it + only if we have a read occur. gzip handles compressing lots of records + at once much better then doing lots of little records between writes. + It is possible to not lock on writes but this would then mean we couldn't + handle bulk inserts as well (that is if someone was trying to read at + the same time since we would want to flush). + + No attempts at durability are made. You can corrupt your data. + + For performance as far as table scans go it is quite fast. I don't have + good numbers but locally it has out performed both Innodb and MyISAM. For + Innodb the question will be if the table can be fit into the buffer + pool. For MyISAM its a question of how much the file system caches the + MyISAM file. With enough free memory MyISAM is faster. Its only when the OS + doesn't have enough memory to cache entire table that archive turns out + to be any faster. For writes it is always a bit slower then MyISAM. It has no + internal limits though for row length. + + Examples between MyISAM (packed) and Archive. + + Table with 76695844 identical rows: + 29680807 a_archive.ARZ + 920350317 a.MYD + + + Table with 8991478 rows (all of Slashdot's comments): + 1922964506 comment_archive.ARZ + 2944970297 comment_text.MYD + + + TODO: + Add bzip optional support. + Allow users to set compression level. + Add truncate table command. + Implement versioning, should be easy. + Implement optimize so we can fix broken tables. + Allow for errors, find a way to mark bad rows. + See if during an optimize you can make the table smaller. + Talk to the gzip guys, come up with a writable format so that updates are doable + without switching to a block method. + Add optional feature so that rows can be flushed at interval (which will cause less + compression but may speed up ordered searches). + + -Brian +*/ + +/* Variables for archive share methods */ +pthread_mutex_t archive_mutex; +static HASH archive_open_tables; +static int archive_init= 0; + +/* The file extension */ +#define ARZ ".ARZ" + +/* + Used for hash table that tracks open tables. +*/ +static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length, + my_bool not_used __attribute__((unused))) +{ + *length=share->table_name_length; + return (byte*) share->table_name; +} + + +/* + Example of simple lock controls. + See ha_example.cc for a description. +*/ +static ARCHIVE_SHARE *get_share(const char *table_name, TABLE *table) +{ + ARCHIVE_SHARE *share; + uint length; + char *tmp_name; + + if (!archive_init) + { + /* Hijack a mutex for init'ing the storage engine */ + pthread_mutex_lock(&LOCK_mysql_create_db); + if (!archive_init) + { + archive_init++; + VOID(pthread_mutex_init(&archive_mutex,MY_MUTEX_INIT_FAST)); + (void) hash_init(&archive_open_tables,system_charset_info,32,0,0, + (hash_get_key) archive_get_key,0,0); + } + pthread_mutex_unlock(&LOCK_mysql_create_db); + } + pthread_mutex_lock(&archive_mutex); + length=(uint) strlen(table_name); + + if (!(share=(ARCHIVE_SHARE*) hash_search(&archive_open_tables, + (byte*) table_name, + length))) + { + if (!(share=(ARCHIVE_SHARE *) + my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), + &share, sizeof(*share), + &tmp_name, length+1, + NullS))) + { + pthread_mutex_unlock(&archive_mutex); + return NULL; + } + + share->use_count=0; + share->table_name_length=length; + share->table_name=tmp_name; + fn_format(share->data_file_name,table_name,"",ARZ,MY_REPLACE_EXT|MY_UNPACK_FILENAME); + strmov(share->table_name,table_name); + /* + It is expensive to open and close the data files and since you can't have + a gzip file that can be both read and written we keep a writer open + that is shared amoung all open tables. + */ + if ((share->archive_write= gzopen(share->data_file_name, "ab")) == NULL) + goto error; + if (my_hash_insert(&archive_open_tables, (byte*) share)) + goto error; + thr_lock_init(&share->lock); + if (pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST)) + goto error2; + } + share->use_count++; + pthread_mutex_unlock(&archive_mutex); + + return share; + +error2: + thr_lock_delete(&share->lock); + /* We close, but ignore errors since we already have errors */ + (void)gzclose(share->archive_write); +error: + pthread_mutex_unlock(&archive_mutex); + my_free((gptr) share, MYF(0)); + + return NULL; +} + + +/* + Free lock controls. + See ha_example.cc for a description. +*/ +static int free_share(ARCHIVE_SHARE *share) +{ + int rc= 0; + pthread_mutex_lock(&archive_mutex); + if (!--share->use_count) + { + hash_delete(&archive_open_tables, (byte*) share); + thr_lock_delete(&share->lock); + pthread_mutex_destroy(&share->mutex); + my_free((gptr) share, MYF(0)); + if (gzclose(share->archive_write) == Z_ERRNO) + rc= -1; + } + pthread_mutex_unlock(&archive_mutex); + + return rc; +} + + +/* + We just implement one additional file extension. +*/ +const char **ha_archive::bas_ext() const +{ static const char *ext[]= { ARZ, NullS }; return ext; } + + +/* + When opening a file we: + Create/get our shared structure. + Init out lock. + We open the file we will read from. + Set the size of ref_length. +*/ +int ha_archive::open(const char *name, int mode, uint test_if_locked) +{ + DBUG_ENTER("ha_archive::open"); + + if (!(share= get_share(name, table))) + DBUG_RETURN(1); + thr_lock_data_init(&share->lock,&lock,NULL); + + if ((archive= gzopen(share->data_file_name, "rb")) == NULL) + { + (void)free_share(share); //We void since we already have an error + DBUG_RETURN(-1); + } + + DBUG_RETURN(0); +} + + +/* + Closes the file. We first close this storage engines file handle to the + archive and then remove our reference count to the table (and possibly + free it as well). + */ +int ha_archive::close(void) +{ + DBUG_ENTER("ha_archive::close"); + int rc= 0; + if (gzclose(archive) == Z_ERRNO) + rc =-1; + rc |= free_share(share); + DBUG_RETURN(rc); +} + + +/* + We create our data file here. The format is pretty simple. The first bytes in + any file are the version number. Currently we do nothing with this, but in + the future this gives us the ability to figure out version if we change the + format at all. After the version we starting writing our rows. Unlike other + storage engines we do not "pack" our data. Since we are about to do a general + compression, packing would just be a waste of CPU time. If the table has blobs + they are written after the row in the order of creation. + So to read a row we: + Read the version + Read the record and copy it into buf + Loop through any blobs and read them + */ +int ha_archive::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) +{ + File create_file; + char name_buff[FN_REFLEN]; + size_t written; + DBUG_ENTER("ha_archive::create"); + + if ((create_file= my_create(fn_format(name_buff,name,"",ARZ,MY_REPLACE_EXT|MY_UNPACK_FILENAME),0, + O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) + DBUG_RETURN(-1); + if ((archive= gzdopen(create_file, "ab")) == NULL) + { + delete_table(name); + DBUG_RETURN(-1); + } + version= ARCHIVE_VERSION; + written= gzwrite(archive, &version, sizeof(version)); + if (written == 0 || written != sizeof(version)) + { + delete_table(name); + DBUG_RETURN(-1); + } + if (gzclose(archive)) + { + delete_table(name); + DBUG_RETURN(-1); + } + + DBUG_RETURN(0); +} + +/* + Look at ha_archive::open() for an explanation of the row format. + Here we just write out the row. +*/ +int ha_archive::write_row(byte * buf) +{ + char *pos; + z_off_t written; + DBUG_ENTER("ha_archive::write_row"); + + statistic_increment(ha_write_count,&LOCK_status); + if (table->timestamp_default_now) + update_timestamp(buf+table->timestamp_default_now-1); + written= gzwrite(share->archive_write, buf, table->reclength); + share->dirty= true; + if (written == 0 || written != table->reclength) + DBUG_RETURN(-1); + + for (Field_blob **field=table->blob_field ; *field ; field++) + { + char *ptr; + uint32 size= (*field)->get_length(); + + (*field)->get_ptr(&ptr); + written= gzwrite(share->archive_write, ptr, (unsigned)size); + if (written == 0 || written != size) + DBUG_RETURN(-1); + } + + DBUG_RETURN(0); +} + + +/* + All calls that need to scan the table start with this method. If we are told + that it is a table scan we rewind the file to the beginning, otherwise + we assume the position will be set. +*/ +int ha_archive::rnd_init(bool scan) +{ + DBUG_ENTER("ha_archive::rnd_init"); + int read; // gzread() returns int, and we use this to check the header + + /* We rewind the file so that we can read from the beginning if scan */ + if(scan) + { + records= 0; + if (gzrewind(archive)) + DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); + } + + /* + If dirty, we lock, and then reset/flush the data. + I found that just calling gzflush() doesn't always work. + */ + if (share->dirty == true) + { + pthread_mutex_lock(&share->mutex); + if (share->dirty == true) + { +/* I was having problems with OSX, but it worked for 10.3 so I am wrapping this with and ifdef */ +#ifdef BROKEN_GZFLUSH + gzclose(share->archive_write); + if ((share->archive_write= gzopen(share->data_file_name, "ab")) == NULL) + { + pthread_mutex_unlock(&share->mutex); + DBUG_RETURN(-1); + } +#else + gzflush(share->archive_write, Z_SYNC_FLUSH); +#endif + share->dirty= false; + } + pthread_mutex_unlock(&share->mutex); + } + + /* + At the moment we just check the size of version to make sure the header is + intact. + */ + if (scan) + { + read= gzread(archive, &version, sizeof(version)); + if (read == 0 || read != sizeof(version)) + DBUG_RETURN(-1); + } + + DBUG_RETURN(0); +} + + +/* + This is the method that is used to read a row. It assumes that the row is + positioned where you want it. +*/ +int ha_archive::get_row(byte *buf) +{ + int read; // Bytes read, gzread() returns int + char *last; + size_t total_blob_length= 0; + DBUG_ENTER("ha_archive::get_row"); + + read= gzread(archive, buf, table->reclength); + + /* If we read nothing we are at the end of the file */ + if (read == 0) + DBUG_RETURN(HA_ERR_END_OF_FILE); + + /* If the record is the wrong size, the file is probably damaged */ + if (read != table->reclength) + DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); + + /* Calculate blob length, we use this for our buffer */ + for (Field_blob **field=table->blob_field; *field ; field++) + total_blob_length += (*field)->get_length(); + + /* Adjust our row buffer if we need be */ + buffer.alloc(total_blob_length); + last= (char *)buffer.ptr(); + + /* Loop through our blobs and read them */ + for (Field_blob **field=table->blob_field; *field ; field++) + { + size_t size= (*field)->get_length(); + read= gzread(archive, last, size); + if (read == 0 || read != size) + DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); + (*field)->set_ptr(size, last); + last += size; + } + DBUG_RETURN(0); +} + +/* + Called during ORDER BY. Its position is either from being called sequentially + or by having had ha_archive::rnd_pos() called before it is called. +*/ +int ha_archive::rnd_next(byte *buf) +{ + DBUG_ENTER("ha_archive::rnd_next"); + int rc; + + statistic_increment(ha_read_rnd_next_count,&LOCK_status); + current_position= gztell(archive); + rc= get_row(buf); + if (!(HA_ERR_END_OF_FILE == rc)) + records++; + + DBUG_RETURN(rc); +} + + +/* + Thanks to the table flag HA_REC_NOT_IN_SEQ this will be called after + each call to ha_archive::rnd_next() if an ordering of the rows is + needed. +*/ +void ha_archive::position(const byte *record) +{ + DBUG_ENTER("ha_archive::position"); + ha_store_ptr(ref, ref_length, current_position); + DBUG_VOID_RETURN; +} + + +/* + This is called after a table scan for each row if the results of the scan need + to be ordered. It will take *pos and use it to move the cursor in the file so + that the next row that is called is the correctly ordered row. +*/ +int ha_archive::rnd_pos(byte * buf, byte *pos) +{ + DBUG_ENTER("ha_archive::rnd_pos"); + statistic_increment(ha_read_rnd_count,&LOCK_status); + current_position= ha_get_ptr(pos, ref_length); + z_off_t seek= gzseek(archive, current_position, SEEK_SET); + + DBUG_RETURN(get_row(buf)); +} + +/****************************************************************************** + + Everything below here is default, please look at ha_example.cc for + descriptions. + + ******************************************************************************/ + +int ha_archive::update_row(const byte * old_data, byte * new_data) +{ + + DBUG_ENTER("ha_archive::update_row"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::delete_row(const byte * buf) +{ + DBUG_ENTER("ha_archive::delete_row"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::index_read(byte * buf, const byte * key, + uint key_len __attribute__((unused)), + enum ha_rkey_function find_flag + __attribute__((unused))) +{ + DBUG_ENTER("ha_archive::index_read"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::index_read_idx(byte * buf, uint index, const byte * key, + uint key_len __attribute__((unused)), + enum ha_rkey_function find_flag + __attribute__((unused))) +{ + DBUG_ENTER("ha_archive::index_read_idx"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + + +int ha_archive::index_next(byte * buf) +{ + DBUG_ENTER("ha_archive::index_next"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::index_prev(byte * buf) +{ + DBUG_ENTER("ha_archive::index_prev"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::index_first(byte * buf) +{ + DBUG_ENTER("ha_archive::index_first"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int ha_archive::index_last(byte * buf) +{ + DBUG_ENTER("ha_archive::index_last"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + + +void ha_archive::info(uint flag) +{ + DBUG_ENTER("ha_archive::info"); + + /* This is a lie, but you don't want the optimizer to see zero or 1 */ + if (records < 2) + records= 2; + + DBUG_VOID_RETURN; +} + +int ha_archive::extra(enum ha_extra_function operation) +{ + DBUG_ENTER("ha_archive::extra"); + DBUG_RETURN(0); +} + +int ha_archive::reset(void) +{ + DBUG_ENTER("ha_archive::reset"); + DBUG_RETURN(0); +} + + +int ha_archive::external_lock(THD *thd, int lock_type) +{ + DBUG_ENTER("ha_archive::external_lock"); + DBUG_RETURN(0); +} + +THR_LOCK_DATA **ha_archive::store_lock(THD *thd, + THR_LOCK_DATA **to, + enum thr_lock_type lock_type) +{ + if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) + lock.type=lock_type; + *to++= &lock; + return to; +} + +ha_rows ha_archive::records_in_range(int inx, + const byte *start_key,uint start_key_len, + enum ha_rkey_function start_search_flag, + const byte *end_key,uint end_key_len, + enum ha_rkey_function end_search_flag) +{ + DBUG_ENTER("ha_archive::records_in_range "); + DBUG_RETURN(records); // HA_ERR_WRONG_COMMAND +} +#endif /* HAVE_ARCHIVE_DB */ diff --git a/sql/examples/ha_archive.h b/sql/examples/ha_archive.h new file mode 100644 index 00000000000..03e296d0eae --- /dev/null +++ b/sql/examples/ha_archive.h @@ -0,0 +1,120 @@ +/* Copyright (C) 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 */ + +#ifdef __GNUC__ +#pragma interface /* gcc class implementation */ +#endif + +#include <zlib.h> + +/* + Please read ha_archive.cc first. If you are looking for more general + answers on how storage engines work, look at ha_example.cc and + ha_example.h. +*/ + +typedef struct st_archive_share { + char *table_name; + char data_file_name[FN_REFLEN]; + uint table_name_length,use_count; + pthread_mutex_t mutex; + THR_LOCK lock; + gzFile archive_write; /* Archive file we are working with */ + bool dirty; /* Flag for if a flush should occur */ +} ARCHIVE_SHARE; + +/* + Version for file format. + 1 - Initial Version +*/ +#define ARCHIVE_VERSION 1 + +class ha_archive: public handler +{ + THR_LOCK_DATA lock; /* MySQL lock */ + ARCHIVE_SHARE *share; /* Shared lock info */ + gzFile archive; /* Archive file we are working with */ + z_off_t current_position; /* The position of the row we just read */ + byte byte_buffer[IO_SIZE]; /* Initial buffer for our string */ + String buffer; /* Buffer used for blob storage */ + unsigned int version; /* Used for recording version */ + +public: + ha_archive(TABLE *table): handler(table) + { + /* Set our original buffer from pre-allocated memory */ + buffer.set(byte_buffer, IO_SIZE, system_charset_info); + + /* The size of the offset value we will use for position() */ + ref_length = sizeof(z_off_t); + } + ~ha_archive() + { + } + const char *table_type() const { return "ARCHIVE"; } + const char *index_type(uint inx) { return "NONE"; } + const char **bas_ext() const; + ulong table_flags() const + { + return (HA_REC_NOT_IN_SEQ | HA_NOT_EXACT_COUNT | HA_NO_AUTO_INCREMENT | + HA_FILE_BASED); + } + ulong index_flags(uint idx, uint part) const + { + return 0; + } + /* + Have to put something here, there is no real limit as far as + archive is concerned. + */ + uint max_supported_record_length() const { return UINT_MAX; } + /* + Called in test_quick_select to determine if indexes should be used. + */ + virtual double scan_time() { return (double) (records) / 20.0+10; } + /* The next method will never be called */ + virtual double read_time(ha_rows rows) { return (double) rows / 20.0+1; } + int open(const char *name, int mode, uint test_if_locked); + int close(void); + int write_row(byte * buf); + int update_row(const byte * old_data, byte * new_data); + int delete_row(const byte * buf); + int index_read(byte * buf, const byte * key, + uint key_len, enum ha_rkey_function find_flag); + int index_read_idx(byte * buf, uint idx, const byte * key, + uint key_len, enum ha_rkey_function find_flag); + int index_next(byte * buf); + int index_prev(byte * buf); + int index_first(byte * buf); + int index_last(byte * buf); + int rnd_init(bool scan=1); + int rnd_next(byte *buf); + int rnd_pos(byte * buf, byte *pos); + int get_row(byte *buf); + void position(const byte *record); + void info(uint); + int extra(enum ha_extra_function operation); + int reset(void); + int external_lock(THD *thd, int lock_type); + ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len, + enum ha_rkey_function start_search_flag, + const byte *end_key,uint end_key_len, + enum ha_rkey_function end_search_flag); + int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); + + THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, + enum thr_lock_type lock_type); +}; diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc index 2d17caf1a83..097abd48e05 100644 --- a/sql/examples/ha_example.cc +++ b/sql/examples/ha_example.cc @@ -14,24 +14,24 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - ha_example is a stubbed storage engine. It does nothing at this point. It - will let you create/open/delete tables but that is all. You can enable it +/* + ha_example is a stubbed storage engine. It does nothing at this point. It + will let you create/open/delete tables but that is all. You can enable it in your buld by doing the following during your build process: ./configure --with-example-storage-engine - + Once this is done mysql will let you create tables with: CREATE TABLE A (...) ENGINE=EXAMPLE; The example is setup to use table locks. It implements an example "SHARE" - that is inserted into a hash by table name. You can use this to store + that is inserted into a hash by table name. You can use this to store information of state that any example handler object will be able to see if it is using the same table. - Please read the object definition in ha_example.h before reading the rest + Please read the object definition in ha_example.h before reading the rest if this file. - To get an idea of what occurs here is an example select that would do a + To get an idea of what occurs here is an example select that would do a scan of an entire table: ha_example::store_lock ha_example::external_lock @@ -50,13 +50,13 @@ ha_example::rnd_next ha_example::extra ENUM HA_EXTRA_NO_CACHE End cacheing of records (def) - ha_example::external_lock + ha_example::external_lock ha_example::extra ENUM HA_EXTRA_RESET Reset database to after open - In the above example has 9 row called before rnd_next signalled that it was - at the end of its data. In the above example the table was already opened - (or you would have seen a call to ha_example::open(). Calls to + In the above example has 9 row called before rnd_next signalled that it was + at the end of its data. In the above example the table was already opened + (or you would have seen a call to ha_example::open(). Calls to ha_example::extra() are hints as to what will be occuring to the request. Happy coding! @@ -92,7 +92,7 @@ static byte* example_get_key(EXAMPLE_SHARE *share,uint *length, /* Example of simple lock controls. The "share" it creates is structure we will pass to each example handler. Do you have to have one of these? Well, you have - pieces that are used for locking, and they are needed to function. + pieces that are used for locking, and they are needed to function. */ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) { @@ -130,7 +130,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), &share, sizeof(*share), &tmp_name, length+1, - NullS))) + NullS))) { pthread_mutex_unlock(&example_mutex); return NULL; @@ -161,7 +161,7 @@ error: } -/* +/* Free lock controls. We call this whenever we close a table. If the table had the last reference to the share then we free memory associated with it. */ @@ -182,7 +182,7 @@ static int free_share(EXAMPLE_SHARE *share) /* - If frm_error() is called then we will use this to to find out what file extentions + If frm_error() is called then we will use this to to find out what file extentions exist for the storage engine. This is also used by the default rename_table and delete_table method in handler.cc. */ @@ -190,10 +190,10 @@ const char **ha_example::bas_ext() const { static const char *ext[]= { NullS }; return ext; } -/* +/* Used for opening tables. The name will be the name of the file. A table is opened when it needs to be opened. For instance - when a request comes in for a select on the table (tables are not + when a request comes in for a select on the table (tables are not open and closed for each request, they are cached). Called from handler.cc by handler::ha_open(). The server opens all tables by @@ -212,12 +212,12 @@ int ha_example::open(const char *name, int mode, uint test_if_locked) /* - Closes a table. We call the free_share() function to free any resources + Closes a table. We call the free_share() function to free any resources that we have allocated in the "shared" structure. Called from sql_base.cc, sql_select.cc, and table.cc. In sql_select.cc it is only used to close up temporary tables or during - the process where a temporary table is converted over to being a + the process where a temporary table is converted over to being a myisam table. For sql_base.cc look at close_data_tables(). */ @@ -230,7 +230,7 @@ int ha_example::close(void) /* write_row() inserts a row. No extra() hint is given currently if a bulk load - is happeneding. buf() is a byte array of data. You can use the field + is happeneding. buf() is a byte array of data. You can use the field information to extract the data from the native byte array type. Example of this would be: for (Field **field=table->field ; *field ; field++) @@ -238,20 +238,20 @@ int ha_example::close(void) ... } - See ha_tina.cc for an example of extracting all of the data as strings. + See ha_tina.cc for an example of extracting all of the data as strings. ha_berekly.cc has an example of how to store it intact by "packing" it for ha_berkeley's own native storage type. See the note for update_row() on auto_increments and timestamps. This case also applied to write_row(). - Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, + Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc. */ int ha_example::write_row(byte * buf) { DBUG_ENTER("ha_example::write_row"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -274,7 +274,7 @@ int ha_example::update_row(const byte * old_data, byte * new_data) { DBUG_ENTER("ha_example::update_row"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -282,8 +282,8 @@ int ha_example::update_row(const byte * old_data, byte * new_data) This will delete a row. buf will contain a copy of the row to be deleted. The server will call this right after the current row has been called (from either a previous rnd_nexT() or index call). - If you keep a pointer to the last row or can access a primary key it will - make doing the deletion quite a bit easier. + If you keep a pointer to the last row or can access a primary key it will + make doing the deletion quite a bit easier. Keep in mind that the server does no guarentee consecutive deletions. ORDER BY clauses can be used. @@ -294,7 +294,7 @@ int ha_example::update_row(const byte * old_data, byte * new_data) int ha_example::delete_row(const byte * buf) { DBUG_ENTER("ha_example::delete_row"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -309,7 +309,7 @@ int ha_example::index_read(byte * buf, const byte * key, __attribute__((unused))) { DBUG_ENTER("ha_example::index_read"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -323,7 +323,7 @@ int ha_example::index_read_idx(byte * buf, uint index, const byte * key, __attribute__((unused))) { DBUG_ENTER("ha_example::index_read_idx"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -333,7 +333,7 @@ int ha_example::index_read_idx(byte * buf, uint index, const byte * key, int ha_example::index_next(byte * buf) { DBUG_ENTER("ha_example::index_next"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -343,40 +343,40 @@ int ha_example::index_next(byte * buf) int ha_example::index_prev(byte * buf) { DBUG_ENTER("ha_example::index_prev"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } /* index_first() asks for the first key in the index. - Called from opt_range.cc, opt_sum.cc, sql_handler.cc, + Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc. */ int ha_example::index_first(byte * buf) { DBUG_ENTER("ha_example::index_first"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } /* index_last() asks for the last key in the index. - Called from opt_range.cc, opt_sum.cc, sql_handler.cc, + Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc. */ int ha_example::index_last(byte * buf) { DBUG_ENTER("ha_example::index_last"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } -/* +/* rnd_init() is called when the system wants the storage engine to do a table - scan. - See the example in the introduction at the top of this file to see when + scan. + See the example in the introduction at the top of this file to see when rnd_init() is called. Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc, @@ -385,11 +385,16 @@ int ha_example::index_last(byte * buf) int ha_example::rnd_init(bool scan) { DBUG_ENTER("ha_example::rnd_init"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } +int ha_example::rnd_end() +{ + DBUG_ENTER("ha_example::rnd_end"); + DBUG_RETURN(0); +} -/* +/* This is called for each row of the table scan. When you run out of records you should return HA_ERR_END_OF_FILE. Fill buff up with the row information. The Field structure for the table is the key to getting data into buf @@ -415,8 +420,8 @@ int ha_example::rnd_next(byte *buf) the size needed to store current_position. ref is just a byte array that the server will maintain. If you are using offsets to mark rows, then current_position should be the offset. If it is a primary key like in - BDB, then it needs to be a primary key. - + BDB, then it needs to be a primary key. + Called from filesort.cc, sql_select.cc, sql_delete.cc and sql_update.cc. */ void ha_example::position(const byte *record) @@ -436,7 +441,7 @@ void ha_example::position(const byte *record) int ha_example::rnd_pos(byte * buf, byte *pos) { DBUG_ENTER("ha_example::rnd_pos"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } @@ -449,9 +454,9 @@ int ha_example::rnd_pos(byte * buf, byte *pos) if (records < 2) records = 2; The reason is that the server will optimize for cases of only a single - record. If in a table scan you don't know the number of records + record. If in a table scan you don't know the number of records it will probably be better to set records to two so you can return - as many records as you need. + as many records as you need. Along with records a few more variables you may wish to set are: records deleted @@ -518,9 +523,9 @@ int ha_example::reset(void) /* Used to delete all rows in a table. Both for cases of truncate and for cases where the optimizer realizes that all rows will be - removed as a result of a SQL statement. + removed as a result of a SQL statement. - Called from item_sum.cc by Item_func_group_concat::clear(), + Called from item_sum.cc by Item_func_group_concat::clear(), Item_sum_count_distinct::clear(), and Item_func_group_concat::clear(). Called from sql_delete.cc by mysql_delete(). Called from sql_select.cc by JOIN::reinit(). @@ -529,12 +534,12 @@ int ha_example::reset(void) int ha_example::delete_all_rows() { DBUG_ENTER("ha_example::delete_all_rows"); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } -/* - First you should go read the section "locking functions for mysql" in +/* + First you should go read the section "locking functions for mysql" in lock.cc to understand this. This create a lock on the table. If you are implementing a storage engine that can handle transacations look at ha_berkely.cc to see how you will @@ -564,7 +569,7 @@ int ha_example::external_lock(THD *thd, int lock_type) lock (if we don't want to use MySQL table locks at all) or add locks for many tables (like we do when we are using a MERGE handler). - Berkeley DB for example changes all WRITE locks to TL_WRITE_ALLOW_WRITE + Berkeley DB for example changes all WRITE locks to TL_WRITE_ALLOW_WRITE (which signals that we are doing WRITES, but we are still allowing other reader's and writer's. @@ -591,11 +596,15 @@ THR_LOCK_DATA **ha_example::store_lock(THD *thd, } /* - Used to delete a table. By the time delete_table() has been called all + Used to delete a table. By the time delete_table() has been called all opened references to this table will have been closed (and your globally - shared references released. The variable name will just be the name of + shared references released. The variable name will just be the name of the table. You will need to remove any files you have created at this point. + If you do not implement this, the default delete_table() is called from + handler.cc and it will delete all files with the file extentions returned + by bas_ext(). + Called from handler.cc by delete_table and ha_create_table(). Only used during create if the table_flag HA_DROP_BEFORE_CREATE was specified for the storage engine. @@ -610,15 +619,19 @@ int ha_example::delete_table(const char *name) /* Renames a table from one name to another from alter table call. + If you do not implement this, the default rename_table() is called from + handler.cc and it will delete all files with the file extentions returned + by bas_ext(). + Called from sql_table.cc by mysql_rename_table(). */ int ha_example::rename_table(const char * from, const char * to) { DBUG_ENTER("ha_example::rename_table "); - DBUG_RETURN(HA_ERR_NOT_IMPLEMENTED); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } -/* +/* Given a starting key, and an ending key estimate the number of rows that will exist between the two. end_key may be empty which in case determine if start_key matches any rows. @@ -636,14 +649,14 @@ ha_rows ha_example::records_in_range(uint inx, key_range *min_key, /* create() is called to create a database. The variable name will have the name of the table. When create() is called you do not need to worry about opening - the table. Also, the FRM file will have already been created so adjusting + the table. Also, the FRM file will have already been created so adjusting create_info will not do you any good. You can overwrite the frm file at this - point if you wish to change the table definition, but there are no methods + point if you wish to change the table definition, but there are no methods currently provided for doing that. Called from handle.cc by ha_create_table(). */ -int ha_example::create(const char *name, TABLE *table_arg, +int ha_example::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) { DBUG_ENTER("ha_example::create"); diff --git a/sql/examples/ha_example.h b/sql/examples/ha_example.h index 2228f04284a..dc8f265c16e 100644 --- a/sql/examples/ha_example.h +++ b/sql/examples/ha_example.h @@ -14,13 +14,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* +/* Please read ha_exmple.cc before reading this file. Please keep in mind that the example storage engine implements all methods that are required to be implemented. handler.h has a full list of methods that you can implement. */ +#ifdef __GNUC__ +#pragma interface /* gcc class implementation */ +#endif + /* EXAMPLE_SHARE is a structure that will be shared amoung all open handlers The example implements the minimum of what you will probably need. @@ -44,56 +48,68 @@ public: ha_example(TABLE *table): handler(table) { } - ~ha_example() + ~ha_example() { } /* The name that will be used for display purposes */ - const char *table_type() const { return "EXAMPLE"; } - /* The name of the index type that will be used for display */ - const char *index_type(uint inx) { return "NONE"; } + const char *table_type() const { return "EXAMPLE"; } + /* + The name of the index type that will be used for display + don't implement this method unless you really have indexes + */ + const char *index_type(uint inx) { return "HASH"; } const char **bas_ext() const; - /* - This is a list of flags that says what the storage engine + /* + This is a list of flags that says what the storage engine implements. The current table flags are documented in - table_flags. + handler.h */ ulong table_flags() const { return 0; } - /* - This is a list of flags that says how the storage engine + /* + This is a list of flags that says how the storage engine implements indexes. The current index flags are documented in - handler.h. If you do not implement indexes, just return zero + handler.h. If you do not implement indexes, just return zero here. */ - ulong index_flags(uint inx) const + ulong index_flags(uint inx, uint part) const { return 0; } - /* + /* unireg.cc will call the following to make sure that the storage engine can handle the data it is about to send. + + Return *real* limits of your storage engine here. MySQL will do + min(your_limits, MySQL_limits) automatically + + There is no need to implement ..._key_... methods if you don't suport + indexes. */ - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return 0; } - uint max_key_parts() const { return 0; } - uint max_key_length() const { return 0; } + uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; } + uint max_supported_keys() const { return 0; } + uint max_supported_key_parts() const { return 0; } + uint max_supported_key_length() const { return 0; } /* Called in test_quick_select to determine if indexes should be used. */ virtual double scan_time() { return (double) (records+deleted) / 20.0+10; } - /* + /* The next method will never be called if you do not implement indexes. */ virtual double read_time(ha_rows rows) { return (double) rows / 20.0+1; } - virtual bool fast_key_read() { return 1;} - /* + /* Everything below are methods that we implment in ha_example.cc. + + Most of these methods are not obligatory, skip them and + MySQL will treat them as not implemented */ - int open(const char *name, int mode, uint test_if_locked); - int close(void); + int open(const char *name, int mode, uint test_if_locked); // required + int close(void); // required + int write_row(byte * buf); int update_row(const byte * old_data, byte * new_data); int delete_row(const byte * buf); @@ -105,21 +121,32 @@ public: int index_prev(byte * buf); int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); - int rnd_next(byte *buf); - int rnd_pos(byte * buf, byte *pos); - void position(const byte *record); - void info(uint); + /* + unlike index_init(), rnd_init() can be called two times + without rnd_end() in between (it only makes sense if scan=1). + then the second call should prepare for the new table scan + (e.g if rnd_init allocates the cursor, second call should + position it to the start of the table, no need to deallocate + and allocate it again + */ + int rnd_init(bool scan); //required + int rnd_end(); + int rnd_next(byte *buf); //required + int rnd_pos(byte * buf, byte *pos); //required + void position(const byte *record); //required + void info(uint); //required + int extra(enum ha_extra_function operation); int reset(void); - int external_lock(THD *thd, int lock_type); + int external_lock(THD *thd, int lock_type); //required int delete_all_rows(void); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int delete_table(const char *from); int rename_table(const char * from, const char * to); - int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); + int create(const char *name, TABLE *form, + HA_CREATE_INFO *create_info); //required THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, - enum thr_lock_type lock_type); + enum thr_lock_type lock_type); //required }; diff --git a/sql/field.cc b/sql/field.cc index df9b4f84ae7..2d3729817b7 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -398,8 +398,8 @@ bool Field::get_date(TIME *ltime,uint fuzzydate) char buff[40]; String tmp(buff,sizeof(buff),&my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) <= - TIMESTAMP_DATETIME_ERROR) + str_to_datetime_with_warn(res->ptr(), res->length(), + ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR) return 1; return 0; } @@ -409,7 +409,7 @@ bool Field::get_time(TIME *ltime) char buff[40]; String tmp(buff,sizeof(buff),&my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_time(res->ptr(),res->length(),ltime)) + str_to_time_with_warn(res->ptr(), res->length(), ltime)) return 1; return 0; } @@ -433,7 +433,7 @@ void Field::store_time(TIME *ltime,timestamp_type type) bool Field::optimize_range(uint idx) { - return !test(table->file->index_flags(idx) & HA_WRONG_ASCII_ORDER); + return test(table->file->index_flags(idx) & HA_READ_RANGE); } /**************************************************************************** @@ -462,7 +462,7 @@ void Field_decimal::overflow(bool negative) uint len=field_length; char *to=ptr, filler= '9'; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); if (negative) { if (!unsigned_flag) @@ -546,7 +546,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) char *left_wall,*right_wall; char tmp_char; /* - To remember if current_thd->cuted_fields has already been incremented, + To remember if table->in_use->cuted_fields has already been incremented, to do that only once */ bool is_cuted_fields_incr=0; @@ -572,7 +572,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) from++; if (from == end) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); is_cuted_fields_incr=1; } else if (*from == '+' || *from == '-') // Found some sign ? @@ -642,13 +642,13 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) it makes the code easer to read. */ - if (current_thd->count_cuted_fields) + if (table->in_use->count_cuted_fields) { // Skip end spaces for (;from != end && my_isspace(&my_charset_bin, *from); from++) ; if (from != end) // If still something left, warn { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); is_cuted_fields_incr=1; } } @@ -794,7 +794,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) /* Write digits of the frac_% parts ; - Depending on current_thd->count_cutted_fields, we may also want + Depending on table->in_use->count_cutted_fields, we may also want to know if some non-zero tail of these parts will be truncated (for example, 0.002->0.00 will generate a warning, while 0.000->0.00 will not) @@ -812,7 +812,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) { if (pos == right_wall) { - if (current_thd->count_cuted_fields && !is_cuted_fields_incr) + if (table->in_use->count_cuted_fields && !is_cuted_fields_incr) break; // Go on below to see if we lose non zero digits return 0; } @@ -826,7 +826,8 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) if (tmp_char != '0') // Losing a non zero digit ? { if (!is_cuted_fields_incr) - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, 1); return 0; } continue; @@ -843,7 +844,7 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) if (tmp_char != '0') // Losing a non zero digit ? { if (!is_cuted_fields_incr) - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); return 0; } continue; @@ -1061,18 +1062,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; /* purecov: inspected */ - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp > 255) { tmp= 255; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1081,18 +1082,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < -128) { tmp= -128; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp >= 128) { tmp= 127; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1110,13 +1111,13 @@ int Field_tiny::store(double nr) if (nr < 0.0) { *ptr=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > 255.0) { *ptr=(char) 255; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1127,13 +1128,13 @@ int Field_tiny::store(double nr) if (nr < -128.0) { *ptr= (char) -128; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > 127.0) { *ptr=127; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1150,13 +1151,13 @@ int Field_tiny::store(longlong nr) if (nr < 0L) { *ptr=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > 255L) { *ptr= (char) 255; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1167,13 +1168,13 @@ int Field_tiny::store(longlong nr) if (nr < -128L) { *ptr= (char) -128; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > 127L) { *ptr=127; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1265,18 +1266,18 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp > (uint16) ~0) { tmp=(uint16) ~0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1285,18 +1286,18 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < INT_MIN16) { tmp= INT_MIN16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp > INT_MAX16) { tmp=INT_MAX16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1322,13 +1323,13 @@ int Field_short::store(double nr) if (nr < 0) { res=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (double) (uint16) ~0) { res=(int16) (uint16) ~0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1339,13 +1340,13 @@ int Field_short::store(double nr) if (nr < (double) INT_MIN16) { res=INT_MIN16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (double) INT_MAX16) { res=INT_MAX16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1371,13 +1372,13 @@ int Field_short::store(longlong nr) if (nr < 0L) { res=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (longlong) (uint16) ~0) { res=(int16) (uint16) ~0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1388,13 +1389,13 @@ int Field_short::store(longlong nr) if (nr < INT_MIN16) { res=INT_MIN16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > INT_MAX16) { res=INT_MAX16; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1540,18 +1541,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < 0) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp >= (long) (1L << 24)) { tmp=(long) (1L << 24)-1L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1560,18 +1561,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) if (tmp < INT_MIN24) { tmp= INT_MIN24; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (tmp > INT_MAX24) { tmp=INT_MAX24; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } - else if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) + else if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } } @@ -1590,14 +1591,14 @@ int Field_medium::store(double nr) if (nr < 0) { int3store(ptr,0); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr >= (double) (long) (1L << 24)) { uint32 tmp=(uint32) (1L << 24)-1L; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1609,14 +1610,14 @@ int Field_medium::store(double nr) { long tmp=(long) INT_MIN24; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (double) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1633,14 +1634,14 @@ int Field_medium::store(longlong nr) if (nr < 0L) { int3store(ptr,0); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr >= (longlong) (long) (1L << 24)) { long tmp=(long) (1L << 24)-1L;; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1652,14 +1653,14 @@ int Field_medium::store(longlong nr) { long tmp=(long) INT_MIN24; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (longlong) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1771,10 +1772,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) else tmp=my_strntol(cs,from,len,10,&end,&error); if (error || - (from+len != end && current_thd->count_cuted_fields && + (from+len != end && table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs))) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } #ifdef WORDS_BIGENDIAN @@ -1799,13 +1800,13 @@ int Field_long::store(double nr) if (nr < 0) { res=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (double) (ulong) ~0L) { res=(int32) (uint32) ~0L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1816,13 +1817,13 @@ int Field_long::store(double nr) if (nr < (double) INT_MIN32) { res=(int32) INT_MIN32; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (double) INT_MAX32) { res=(int32) INT_MAX32; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1844,18 +1845,26 @@ int Field_long::store(longlong nr) { int error= 0; int32 res; + + /* + This assert has nothing to do with this method per se, it was put here + only because it is one of the best places for catching places there its + condition is broken. + */ + DBUG_ASSERT(table->in_use == current_thd); + if (unsigned_flag) { if (nr < 0) { res=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr >= (LL(1) << 32)) { res=(int32) (uint32) ~0L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1866,13 +1875,13 @@ int Field_long::store(longlong nr) if (nr < (longlong) INT_MIN32) { res=(int32) INT_MIN32; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > (longlong) INT_MAX32) { res=(int32) INT_MAX32; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -1905,6 +1914,8 @@ double Field_long::val_real(void) longlong Field_long::val_int(void) { int32 j; + /* See the comment in Field_long::store(long long) */ + DBUG_ASSERT(table->in_use == current_thd); #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) j=sint4korr(ptr); @@ -2029,10 +2040,10 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) else tmp=my_strntoll(cs,from,len,10,&end,&error); if (error || - (from+len != end && current_thd->count_cuted_fields && + (from+len != end && table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs))) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } #ifdef WORDS_BIGENDIAN @@ -2057,13 +2068,13 @@ int Field_longlong::store(double nr) if (nr < 0) { res=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr >= (double) ~ (ulonglong) 0) { res= ~(longlong) 0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -2074,13 +2085,13 @@ int Field_longlong::store(double nr) if (nr <= (double) LONGLONG_MIN) { res=(longlong) LONGLONG_MIN; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr >= (double) LONGLONG_MAX) { res=(longlong) LONGLONG_MAX; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -2251,10 +2262,10 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) int error; char *end; double nr= my_strntod(cs,(char*) from,len,&end,&error); - if (error || ((uint) (end-from) != len && current_thd->count_cuted_fields)) + if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields)) { error= 1; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } Field_float::store(nr); return error; @@ -2270,13 +2281,13 @@ int Field_float::store(double nr) { j= 0; set_null(); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (unsigned_flag && nr < 0) { j= 0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -2300,13 +2311,13 @@ int Field_float::store(double nr) if (nr < -max_value) { j= (float)-max_value; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > max_value) { j= (float)max_value; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -2331,7 +2342,7 @@ int Field_float::store(longlong nr) float j= (float) nr; if (unsigned_flag && j < 0) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); j=0; error= 1; } @@ -2553,10 +2564,10 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) int error; char *end; double nr= my_strntod(cs,(char*) from, len, &end, &error); - if (error || ((uint) (end-from) != len && current_thd->count_cuted_fields)) + if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields)) { error= 1; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } Field_double::store(nr); return error; @@ -2571,13 +2582,13 @@ int Field_double::store(double nr) { nr= 0; set_null(); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (unsigned_flag && nr < 0) { nr= 0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else @@ -2597,13 +2608,13 @@ int Field_double::store(double nr) if (nr < -max_value) { nr= -max_value; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } else if (nr > max_value) { nr= max_value; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; } } @@ -2626,7 +2637,7 @@ int Field_double::store(longlong nr) int error= 0; if (unsigned_flag && j < 0) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); error= 1; j=0; } @@ -2900,7 +2911,39 @@ void Field_timestamp::set_timestamp_offsets() int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) { - long tmp=(long) str_to_timestamp(from,len); + TIME l_time; + my_time_t tmp= 0; + int error; + bool have_smth_to_conv; + bool in_dst_time_gap; + THD *thd= table->in_use; + + have_smth_to_conv= (str_to_datetime(from, len, &l_time, 0, &error) > + MYSQL_TIMESTAMP_ERROR); + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, + from, len, MYSQL_TIMESTAMP_DATETIME, 1); + + if (have_smth_to_conv) + { + if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap))) + { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + from, len, MYSQL_TIMESTAMP_DATETIME, !error); + + error= 1; + } + else if (in_dst_time_gap) + { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_INVALID_TIMESTAMP, + from, len, MYSQL_TIMESTAMP_DATETIME, !error); + error= 1; + } + } + #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -2909,7 +2952,7 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longstore(ptr,tmp); - return 0; + return error; } int Field_timestamp::store(double nr) @@ -2917,8 +2960,10 @@ int Field_timestamp::store(double nr) int error= 0; if (nr < 0 || nr > 99991231235959.0) { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATETIME); nr= 0; // Avoid overflow on buff - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } error|= Field_timestamp::store((longlong) rint(nr)); @@ -2926,96 +2971,37 @@ int Field_timestamp::store(double nr) } -/* - Convert a datetime of formats YYMMDD, YYYYMMDD or YYMMDDHHMSS to - YYYYMMDDHHMMSS. The high date '99991231235959' is checked before this - function. -*/ - -static longlong fix_datetime(longlong nr, TIME *time_res, - const char *field_name, bool *error) -{ - long part1,part2; - - *error= 0; - if (nr == LL(0) || nr >= LL(10000101000000)) - goto ok; - if (nr < 101) - goto err; - if (nr <= (YY_PART_YEAR-1)*10000L+1231L) - { - nr= (nr+20000000L)*1000000L; // YYMMDD, year: 2000-2069 - goto ok; - } - if (nr < (YY_PART_YEAR)*10000L+101L) - goto err; - if (nr <= 991231L) - { - nr= (nr+19000000L)*1000000L; // YYMMDD, year: 1970-1999 - goto ok; - } - if (nr < 10000101L) - goto err; - if (nr <= 99991231L) - { - nr= nr*1000000L; - goto ok; - } - if (nr < 101000000L) - goto err; - if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959)) - { - nr= nr+LL(20000000000000); // YYMMDDHHMMSS, 2000-2069 - goto ok; - } - if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000)) - goto err; - if (nr <= LL(991231235959)) - nr= nr+LL(19000000000000); // YYMMDDHHMMSS, 1970-1999 - - ok: - part1=(long) (nr/LL(1000000)); - part2=(long) (nr - (longlong) part1*LL(1000000)); - time_res->year= (int) (part1/10000L); part1%=10000L; - time_res->month= (int) part1 / 100; - time_res->day= (int) part1 % 100; - time_res->hour= (int) (part2/10000L); part2%=10000L; - time_res->minute=(int) part2 / 100; - time_res->second=(int) part2 % 100; - - if (time_res->year <= 9999 && time_res->month <= 12 && - time_res->day <= 31 && time_res->hour <= 23 && - time_res->minute <= 59 && time_res->second <= 59) - return nr; - - err: - THD *thd= current_thd; - if (thd->count_cuted_fields) - { - thd->cuted_fields++; - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_TRUNCATED, ER(ER_WARN_DATA_TRUNCATED), - field_name, thd->row_count); - } - *error= 1; - return LL(0); -} - - int Field_timestamp::store(longlong nr) { TIME l_time; - time_t timestamp= 0; - bool error; + my_time_t timestamp= 0; + int error; + bool in_dst_time_gap; + THD *thd= table->in_use; - if ((nr= fix_datetime(nr, &l_time, field_name, &error))) + if (number_to_TIME(nr, &l_time, 0, &error)) { - long not_used; - - if (!(timestamp= my_gmt_sec(&l_time, ¬_used))) - goto err; - } + if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap))) + { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATETIME, 1); + error= 1; + } + if (in_dst_time_gap) + { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_INVALID_TIMESTAMP, + nr, MYSQL_TIMESTAMP_DATETIME, !error); + error= 1; + } + } + else if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, + nr, MYSQL_TIMESTAMP_DATETIME, 1); + #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -3024,12 +3010,8 @@ int Field_timestamp::store(longlong nr) else #endif longstore(ptr,(uint32) timestamp); + return error; - -err: - longstore(ptr,(uint32) 0); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); - return 1; } @@ -3040,12 +3022,9 @@ double Field_timestamp::val_real(void) longlong Field_timestamp::val_int(void) { - int part_time; uint32 temp; - time_t time_arg; - struct tm *l_time; - longlong res; - struct tm tm_tmp; + TIME time_tmp; + THD *thd= table->in_use; #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -3056,32 +3035,21 @@ longlong Field_timestamp::val_int(void) if (temp == 0L) // No time return(0); /* purecov: inspected */ - time_arg=(time_t) temp; - localtime_r(&time_arg,&tm_tmp); - l_time=&tm_tmp; - - part_time= l_time->tm_year % 100; - res= ((longlong) (part_time+ ((part_time < YY_PART_YEAR) ? 2000 : 1900))* - LL(10000000000)); - part_time= l_time->tm_mon+1; - res+= (longlong) part_time * LL(100000000); - part_time=l_time->tm_mday; - res+= (longlong) ((long) part_time * 1000000L); - part_time=l_time->tm_hour; - res+= (longlong) (part_time * 10000L); - part_time=l_time->tm_min; - res+= (longlong) (part_time * 100); - part_time=l_time->tm_sec; - return res+part_time; + + thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp); + thd->time_zone_used= 1; + + return time_tmp.year * LL(10000000000) + time_tmp.month * LL(100000000) + + time_tmp.day * 1000000L + time_tmp.hour * 10000L + + time_tmp.minute * 100 + time_tmp.second; } String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) { uint32 temp, temp2; - time_t time_arg; - struct tm *l_time; - struct tm tm_tmp; + TIME time_tmp; + THD *thd= table->in_use; char *to; val_buffer->alloc(field_length+1); @@ -3101,11 +3069,11 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) return val_ptr; } val_buffer->set_charset(&my_charset_bin); // Safety - time_arg=(time_t) temp; - localtime_r(&time_arg,&tm_tmp); - l_time=&tm_tmp; + + thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp); + thd->time_zone_used= 1; - temp= l_time->tm_year % 100; + temp= time_tmp.year % 100; if (temp < YY_PART_YEAR) { *to++= '2'; @@ -3120,27 +3088,27 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); *to++= '-'; - temp=l_time->tm_mon+1; + temp=time_tmp.month; temp2=temp/10; temp=temp-temp2*10; *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); *to++= '-'; - temp=l_time->tm_mday; + temp=time_tmp.day; temp2=temp/10; temp=temp-temp2*10; *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); *to++= ' '; - temp=l_time->tm_hour; + temp=time_tmp.hour; temp2=temp/10; temp=temp-temp2*10; *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); *to++= ':'; - temp=l_time->tm_min; + temp=time_tmp.minute; temp2=temp/10; temp=temp-temp2*10; *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); *to++= ':'; - temp=l_time->tm_sec; + temp=time_tmp.second; temp2=temp/10; temp=temp-temp2*10; *to++= (char) ('0'+(char) (temp2)); *to++= (char) ('0'+(char) (temp)); @@ -3152,6 +3120,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate) { long temp; + THD *thd= table->in_use; #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) temp=uint4korr(ptr); @@ -3166,19 +3135,8 @@ bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate) } else { - struct tm tm_tmp; - time_t time_arg= (time_t) temp; - localtime_r(&time_arg,&tm_tmp); - struct tm *start= &tm_tmp; - ltime->year= start->tm_year+1900; - ltime->month= start->tm_mon+1; - ltime->day= start->tm_mday; - ltime->hour= start->tm_hour; - ltime->minute= start->tm_min; - ltime->second= start->tm_sec; - ltime->second_part= 0; - ltime->neg= 0; - ltime->time_type=TIMESTAMP_DATETIME; + thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp); + thd->time_zone_used= 1; } return 0; } @@ -3245,7 +3203,7 @@ void Field_timestamp::sql_type(String &res) const void Field_timestamp::set_time() { - long tmp= (long) current_thd->query_start(); + long tmp= (long) table->in_use->query_start(); #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -3267,25 +3225,35 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { TIME ltime; long tmp; - int error= 0; - if (str_to_time(from,len,<ime)) + int error; + + if (str_to_time(from, len, <ime, &error)) { tmp=0L; error= 1; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, + from, len, MYSQL_TIMESTAMP_TIME, 1); } else { + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, + from, len, MYSQL_TIMESTAMP_TIME, 1); + if (ltime.month) ltime.day=0; tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second); if (tmp > 8385959) { tmp=8385959; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + from, len, MYSQL_TIMESTAMP_TIME, !error); error= 1; } } + if (ltime.neg) tmp= -tmp; error |= Field_time::store((longlong) tmp); @@ -3300,13 +3268,15 @@ int Field_time::store(double nr) if (nr > 8385959.0) { tmp=8385959L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME); error= 1; } else if (nr < -8385959.0) { tmp= -8385959L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME); error= 1; } else @@ -3317,7 +3287,9 @@ int Field_time::store(double nr) if (tmp % 100 > 59 || tmp/100 % 100 > 59) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_TIME); error= 1; } } @@ -3333,13 +3305,17 @@ int Field_time::store(longlong nr) if (nr > (longlong) 8385959L) { tmp=8385959L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_TIME, 1); error= 1; } else if (nr < (longlong) -8385959L) { tmp= -8385959L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_TIME, 1); error= 1; } else @@ -3348,7 +3324,9 @@ int Field_time::store(longlong nr) if (tmp % 100 > 59 || tmp/100 % 100 > 59) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_TIME, 1); error= 1; } } @@ -3395,6 +3373,39 @@ String *Field_time::val_str(String *val_buffer, } +/* + Normally we would not consider 'time' as a vaild date, but we allow + get_date() here to be able to do things like + DATE_FORMAT(time, "%l.%i %p") +*/ + +bool Field_time::get_date(TIME *ltime, uint fuzzydate) +{ + long tmp; + if (!fuzzydate) + { + push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + ER(ER_WARN_DATA_OUT_OF_RANGE), field_name, + table->in_use->row_count); + return 1; + } + tmp=(long) sint3korr(ptr); + ltime->neg=0; + if (tmp < 0) + { + ltime->neg= 1; + tmp=-tmp; + } + ltime->hour=tmp/10000; + tmp-=ltime->hour*10000; + ltime->minute= tmp/100; + ltime->second= tmp % 100; + ltime->year= ltime->month= ltime->day= ltime->second_part= 0; + return 0; +} + + bool Field_time::get_time(TIME *ltime) { long tmp=(long) sint3korr(ptr); @@ -3410,7 +3421,7 @@ bool Field_time::get_time(TIME *ltime) ltime->minute= (int) tmp/100; ltime->second= (int) tmp % 100; ltime->second_part=0; - ltime->time_type= TIMESTAMP_TIME; + ltime->time_type= MYSQL_TIMESTAMP_TIME; return 0; } @@ -3460,11 +3471,11 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { *ptr=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); return 1; } - if (current_thd->count_cuted_fields && !test_if_int(from,len,end,cs)) - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + if (table->in_use->count_cuted_fields && !test_if_int(from,len,end,cs)) + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); if (nr != 0 || len != 4) { if (nr < YY_PART_YEAR) @@ -3493,7 +3504,7 @@ int Field_year::store(longlong nr) if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { *ptr=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); return 1; } if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000 @@ -3557,15 +3568,20 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) { TIME l_time; uint32 tmp; - int error= 0; - if (str_to_TIME(from,len,&l_time,1) <= TIMESTAMP_DATETIME_ERROR) + int error; + + if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR) { tmp=0; error= 1; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } else tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day); + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, + from, len, MYSQL_TIMESTAMP_DATE, 1); + #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -3587,7 +3603,9 @@ int Field_date::store(double nr) if (nr < 0.0 || nr > 99991231.0) { tmp=0L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATE); error= 1; } else @@ -3613,7 +3631,9 @@ int Field_date::store(longlong nr) if (nr < 0 || nr > LL(99991231)) { tmp=0L; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATE, 0); error= 1; } else @@ -3740,15 +3760,19 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) { TIME l_time; long tmp; - int error= 0; - if (str_to_TIME(from,len,&l_time,1) <= TIMESTAMP_DATETIME_ERROR) + int error; + if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR) { tmp=0L; error= 1; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); } else tmp= l_time.day + l_time.month*32 + l_time.year*16*32; + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, + from, len, MYSQL_TIMESTAMP_DATE, 1); + int3store(ptr,tmp); return error; } @@ -3758,7 +3782,8 @@ int Field_newdate::store(double nr) if (nr < 0.0 || nr > 99991231235959.0) { (void) Field_newdate::store((longlong) -1); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATE); return 1; } else @@ -3775,7 +3800,9 @@ int Field_newdate::store(longlong nr) if (nr < 0L || nr > 99991231L) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_DATE, 1); error= 1; } else @@ -3793,7 +3820,9 @@ int Field_newdate::store(longlong nr) if (month > 12 || day > 31) { tmp=0L; // Don't allow date to change - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, nr, + MYSQL_TIMESTAMP_DATE, 1); error= 1; } else @@ -3806,12 +3835,12 @@ int Field_newdate::store(longlong nr) void Field_newdate::store_time(TIME *ltime,timestamp_type type) { long tmp; - if (type == TIMESTAMP_DATE || type == TIMESTAMP_DATETIME) + if (type == MYSQL_TIMESTAMP_DATE || type == MYSQL_TIMESTAMP_DATETIME) tmp=ltime->year*16*32+ltime->month*32+ltime->day; else { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } int3store(ptr,tmp); } @@ -3870,7 +3899,7 @@ bool Field_newdate::get_date(TIME *ltime,uint fuzzydate) ltime->day= tmp & 31; ltime->month= (tmp >> 5) & 15; ltime->year= (tmp >> 9); - ltime->time_type=TIMESTAMP_DATE; + ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0; return (!fuzzydate && (!ltime->month || !ltime->day)) ? 1 : 0; } @@ -3910,12 +3939,18 @@ void Field_newdate::sql_type(String &res) const int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) { - longlong tmp=str_to_datetime(from,len,1); - if (tmp < 0) - { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); - tmp= 0; - } + TIME time_tmp; + int error; + ulonglong tmp= 0; + + if (str_to_datetime(from, len, &time_tmp, 1, &error) > MYSQL_TIMESTAMP_ERROR) + tmp= TIME_to_ulonglong_datetime(&time_tmp); + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + from, len, MYSQL_TIMESTAMP_DATETIME, 1); + #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -3924,7 +3959,7 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longlongstore(ptr,tmp); - return 0; + return error; } @@ -3933,8 +3968,10 @@ int Field_datetime::store(double nr) int error= 0; if (nr < 0.0 || nr > 99991231235959.0) { + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_OUT_OF_RANGE, + nr, MYSQL_TIMESTAMP_DATETIME); nr=0.0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); error= 1; } error |= Field_datetime::store((longlong) rint(nr)); @@ -3945,9 +3982,16 @@ int Field_datetime::store(double nr) int Field_datetime::store(longlong nr) { TIME not_used; - bool error; + int error; + longlong initial_nr= nr; - nr= fix_datetime(nr, ¬_used, field_name, &error); + nr= number_to_TIME(nr, ¬_used, 1, &error); + + if (error) + set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, initial_nr, + MYSQL_TIMESTAMP_DATETIME, 1); + #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -3963,13 +4007,13 @@ int Field_datetime::store(longlong nr) void Field_datetime::store_time(TIME *ltime,timestamp_type type) { longlong tmp; - if (type == TIMESTAMP_DATE || type == TIMESTAMP_DATETIME) + if (type == MYSQL_TIMESTAMP_DATE || type == MYSQL_TIMESTAMP_DATETIME) tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*LL(1000000)+ (ltime->hour*10000L+ltime->minute*100+ltime->second)); else { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -4062,7 +4106,7 @@ bool Field_datetime::get_date(TIME *ltime, uint fuzzydate) part1=(uint32) (tmp/LL(1000000)); part2=(uint32) (tmp - (ulonglong) part1*LL(1000000)); - ltime->time_type= TIMESTAMP_DATETIME; + ltime->time_type= MYSQL_TIMESTAMP_DATETIME; ltime->neg= 0; ltime->second_part= 0; ltime->second= (int) (part2%100); @@ -4146,7 +4190,10 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) char buff[80]; String tmpstr(buff,sizeof(buff), &my_charset_bin); uint copy_length; - + + /* See the comment for Field_long::store(long long) */ + DBUG_ASSERT(table->in_use == current_thd); + /* Convert character set if nesessary */ if (String::needs_conversion(length, cs, field_charset, ¬_used)) { @@ -4168,7 +4215,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) field_charset->cset->fill(field_charset,ptr+copy_length, field_length-copy_length,' '); - if ((copy_length < length) && current_thd->count_cuted_fields) + if ((copy_length < length) && table->in_use->count_cuted_fields) { // Check if we loosed some info const char *end=from+length; from+= copy_length; @@ -4176,7 +4223,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) MY_SEQ_SPACES); if (from != end) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error=1; } } @@ -4224,6 +4271,8 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)), String *val_ptr) { uint length= field_charset->cset->lengthsp(field_charset, ptr, field_length); + /* See the comment for Field_long::store(long long) */ + DBUG_ASSERT(table->in_use == current_thd); val_ptr->set((const char*) ptr, length, field_charset); return val_ptr; } @@ -4242,9 +4291,8 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr) (const uchar*) b_ptr, field_length); } - return field_charset->coll->strnncoll(field_charset, - (const uchar*) a_ptr, field_length, - (const uchar*) b_ptr, field_length); + return my_strnncoll(field_charset,(const uchar*) a_ptr, field_length, + (const uchar*) b_ptr, field_length); } void Field_string::sort_string(char *to,uint length) @@ -4352,7 +4400,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) if (length > field_length) { length=field_length; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error= 1; } memcpy(ptr+HA_KEY_BLOB_LENGTH,from,length); @@ -4636,6 +4684,42 @@ uint32 Field_blob::get_length(const char *pos) } +/* + Put a blob length field into a record buffer. + + SYNOPSIS + Field_blob::put_length() + pos Pointer into the record buffer. + length The length value to put. + + DESCRIPTION + Depending on the maximum length of a blob, its length field is + put into 1 to 4 bytes. This is a property of the blob object, + described by 'packlength'. + + RETURN + nothing +*/ + +void Field_blob::put_length(char *pos, uint32 length) +{ + switch (packlength) { + case 1: + *pos= (char) length; + break; + case 2: + int2store(pos, length); + break; + case 3: + int3store(pos, length); + break; + case 4: + int4store(pos, length); + break; + } +} + + int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) { if (!length) @@ -4670,7 +4754,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) min(length, copy_length), copy_length); if (copy_length < length) - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); Field_blob::store_length(copy_length); if (was_conversion || table->copy_blobs || copy_length <= MAX_FIELD_WIDTH) @@ -5010,6 +5094,50 @@ char *Field_blob::pack_key(char *to, const char *from, uint max_length) return to+length; } + +/* + Unpack a blob key into a record buffer. + + SYNOPSIS + Field_blob::unpack_key() + to Pointer into the record buffer. + from Pointer to the packed key. + max_length Key length limit from key description. + + DESCRIPTION + A blob key has a maximum size of 64K-1. + In its packed form, the length field is one or two bytes long, + depending on 'max_length'. + Depending on the maximum length of a blob, its length field is + put into 1 to 4 bytes. This is a property of the blob object, + described by 'packlength'. + Blobs are internally stored apart from the record buffer, which + contains a pointer to the blob buffer. + + RETURN + Pointer into 'from' past the last byte copied from packed key. +*/ + +const char *Field_blob::unpack_key(char *to, const char *from, uint max_length) +{ + /* get length of the blob key */ + uint32 length= *((uchar*) from++); + if (max_length > 255) + length+= (*((uchar*) from++)) << 8; + + /* put the length into the record buffer */ + put_length(to, length); + + /* put the address of the blob buffer or NULL */ + if (length) + memcpy_fixed(to + packlength, &from, sizeof(from)); + else + bzero(to + packlength, sizeof(from)); + + /* point to first byte of next field in 'from' */ + return from + length; +} + /* Create a packed key that will be used for storage from a MySQL key */ char *Field_blob::pack_key_from_key_image(char *to, const char *from, @@ -5229,11 +5357,11 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) if (err || end != from+length || tmp > typelib->count) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } } else - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } store_type((ulonglong) tmp); return err; @@ -5251,7 +5379,7 @@ int Field_enum::store(longlong nr) int error= 0; if ((uint) nr > typelib->count || nr == 0) { - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); nr=0; error=1; } @@ -5407,11 +5535,11 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) { tmp=0; - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); } } else if (got_warning) - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); store_type(tmp); return err; } @@ -5424,7 +5552,7 @@ int Field_set::store(longlong nr) (longlong) 1)) { nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1); - set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); error=1; } store_type((ulonglong) nr); @@ -5803,13 +5931,148 @@ create_field::create_field(Field *old_field,Field *orig_field) /* Warning handling */ -void Field::set_warning(const uint level, const uint code) + +/* + Produce warning or note about data saved into field + + SYNOPSYS + set_warning() + level - level of message (Note/Warning/Error) + code - error code of message to be produced + cuted_increment - whenever we should increase cut fields count or not + + NOTE + This function won't produce warning and increase cut fields counter + if count_cuted_fields == FIELD_CHECK_IGNORE for current thread. + + RETURN VALUE + true - if count_cuted_fields == FIELD_CHECK_IGNORE + false - otherwise +*/ +bool +Field::set_warning(const uint level, const uint code, int cuted_increment) { - THD *thd= current_thd; + THD *thd= table->in_use; if (thd->count_cuted_fields) { - thd->cuted_fields++; - push_warning_printf(thd, (MYSQL_ERROR::enum_warning_level) level, - code, ER(code), field_name, thd->row_count); + thd->cuted_fields+= cuted_increment; + push_warning_printf(thd, (MYSQL_ERROR::enum_warning_level) level, + code, ER(code), field_name, thd->row_count); + return 0; + } + return 1; +} + + +/* + Produce warning or note about datetime string data saved into field + + SYNOPSYS + set_warning() + level - level of message (Note/Warning/Error) + code - error code of message to be produced + str - string value which we tried to save + str_len - length of string which we tried to save + ts_type - type of datetime value (datetime/date/time) + cuted_increment - whenever we should increase cut fields count or not + + NOTE + This function will always produce some warning but won't increase cut + fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current + thread. +*/ +void +Field::set_datetime_warning(const uint level, const uint code, + const char *str, uint str_length, + timestamp_type ts_type, int cuted_increment) +{ + if (set_warning(level, code, cuted_increment)) + make_truncated_value_warning(table->in_use, str, str_length, ts_type); +} + + +/* + Produce warning or note about integer datetime value saved into field + + SYNOPSYS + set_warning() + level - level of message (Note/Warning/Error) + code - error code of message to be produced + nr - numeric value which we tried to save + ts_type - type of datetime value (datetime/date/time) + cuted_increment - whenever we should increase cut fields count or not + + NOTE + This function will always produce some warning but won't increase cut + fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current + thread. +*/ +void +Field::set_datetime_warning(const uint level, const uint code, + longlong nr, timestamp_type ts_type, + int cuted_increment) +{ + if (set_warning(level, code, cuted_increment)) + { + char str_nr[22]; + char *str_end= longlong10_to_str(nr, str_nr, -10); + make_truncated_value_warning(table->in_use, str_nr, str_end - str_nr, + ts_type); + } +} + + +/* + Produce warning or note about double datetime data saved into field + + SYNOPSYS + set_warning() + level - level of message (Note/Warning/Error) + code - error code of message to be produced + nr - double value which we tried to save + ts_type - type of datetime value (datetime/date/time) + + NOTE + This function will always produce some warning but won't increase cut + fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current + thread. +*/ +void +Field::set_datetime_warning(const uint level, const uint code, + double nr, timestamp_type ts_type) +{ + if (set_warning(level, code, 1)) + { + /* DBL_DIG is enough to print '-[digits].E+###' */ + char str_nr[DBL_DIG + 8]; + uint str_len= my_sprintf(str_nr, (str_nr, "%g", nr)); + make_truncated_value_warning(table->in_use, str_nr, str_len, ts_type); + } +} + +/* + maximum possible display length for blob + + SYNOPSIS + Field_blob::max_length() + + RETURN + length +*/ +uint32 Field_blob::max_length() +{ + switch (packlength) + { + case 1: + return 255; + case 2: + return 65535; + case 3: + return 16777215; + case 4: + return (uint32) 4294967295U; + default: + DBUG_ASSERT(0); // we should never go here + return 0; } } diff --git a/sql/field.h b/sql/field.h index 002a7228164..a2fe77e18a3 100644 --- a/sql/field.h +++ b/sql/field.h @@ -45,6 +45,10 @@ public: char *ptr; // Position to field in record uchar *null_ptr; // Byte where null_bit is + /* + Note that you can use table->in_use as replacement for current_thd member + only inside of val_*() and store() members (e.g. you can't use it in cons) + */ struct st_table *table; // Pointer for table struct st_table *orig_table; // Pointer to original table const char *table_name,*field_name; @@ -247,6 +251,10 @@ public: { return pack(to,from,max_length); } + virtual const char *unpack_key(char* to, const char *from, uint max_length) + { + return unpack(to,from); + } virtual uint packed_col_length(const char *to, uint length) { return length;} virtual uint max_packed_col_length(uint max_length) @@ -264,9 +272,20 @@ public: virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } virtual bool has_charset(void) const { return FALSE; } virtual void set_charset(CHARSET_INFO *charset) { } - void set_warning(const unsigned int level, const unsigned int code); + bool set_warning(const unsigned int level, const unsigned int code, + int cuted_increment); + void set_datetime_warning(const uint level, const uint code, + const char *str, uint str_len, + timestamp_type ts_type, int cuted_increment); + void set_datetime_warning(const uint level, const uint code, + longlong nr, timestamp_type ts_type, + int cuted_increment); + void set_datetime_warning(const uint level, const uint code, + double nr, timestamp_type ts_type); virtual field_cast_enum field_cast_type()= 0; bool field_cast_compatible(field_cast_enum type); + /* maximum possible display length */ + virtual uint32 max_length()= 0; friend bool reopen_table(THD *,struct st_table *,bool); friend int cre_myisam(my_string name, register TABLE *form, uint options, ulonglong auto_increment_value); @@ -336,6 +355,7 @@ public: CHARSET_INFO *charset(void) const { return field_charset; } void set_charset(CHARSET_INFO *charset) { field_charset=charset; } bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; } + uint32 max_length() { return field_length; } friend class create_field; }; @@ -366,6 +386,7 @@ public: void overflow(bool negative); bool zero_pack() const { return 0; } void sql_type(String &str) const; + uint32 max_length() { return field_length; } field_cast_enum field_cast_type() { return FIELD_CAST_DECIMAL; } }; @@ -397,6 +418,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return 1; } void sql_type(String &str) const; + uint32 max_length() { return 4; } field_cast_enum field_cast_type() { return FIELD_CAST_TINY; } }; @@ -433,6 +455,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return 2; } void sql_type(String &str) const; + uint32 max_length() { return 6; } field_cast_enum field_cast_type() { return FIELD_CAST_SHORT; } }; @@ -464,6 +487,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return 3; } void sql_type(String &str) const; + uint32 max_length() { return 8; } field_cast_enum field_cast_type() { return FIELD_CAST_MEDIUM; } }; @@ -500,6 +524,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return 4; } void sql_type(String &str) const; + uint32 max_length() { return 11; } field_cast_enum field_cast_type() { return FIELD_CAST_LONG; } }; @@ -539,6 +564,7 @@ public: uint32 pack_length() const { return 8; } void sql_type(String &str) const; bool store_for_compare() { return 1; } + uint32 max_length() { return 20; } field_cast_enum field_cast_type() { return FIELD_CAST_LONGLONG; } }; #endif @@ -573,6 +599,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return sizeof(float); } void sql_type(String &str) const; + uint32 max_length() { return 24; } field_cast_enum field_cast_type() { return FIELD_CAST_FLOAT; } }; @@ -607,6 +634,7 @@ public: void sort_string(char *buff,uint length); uint32 pack_length() const { return sizeof(double); } void sql_type(String &str) const; + uint32 max_length() { return 53; } field_cast_enum field_cast_type() { return FIELD_CAST_DOUBLE; } }; @@ -637,6 +665,7 @@ public: uint32 pack_length() const { return 0; } void sql_type(String &str) const; uint size_of() const { return sizeof(*this); } + uint32 max_length() { return 4; } field_cast_enum field_cast_type() { return FIELD_CAST_NULL; } }; @@ -800,6 +829,7 @@ public: double val_real(void); longlong val_int(void); String *val_str(String*,String *); + bool get_date(TIME *ltime, uint fuzzydate); bool send_binary(Protocol *protocol); bool get_time(TIME *ltime); int cmp(const char *,const char*); @@ -991,6 +1021,7 @@ public: inline uint32 get_length(uint row_offset=0) { return get_length(ptr+row_offset); } uint32 get_length(const char *ptr); + void put_length(char *pos, uint32 length); inline void get_ptr(char **str) { memcpy_fixed(str,ptr+packlength,sizeof(char*)); @@ -1023,6 +1054,7 @@ public: const char *unpack(char *to, const char *from); char *pack_key(char *to, const char *from, uint max_length); char *pack_key_from_key_image(char* to, const char *from, uint max_length); + const char *unpack_key(char* to, const char *from, uint max_length); int pack_cmp(const char *a, const char *b, uint key_length); int pack_cmp(const char *b, uint key_length); uint packed_col_length(const char *col_ptr, uint length); @@ -1034,6 +1066,7 @@ public: bool has_charset(void) const { return charset() == &my_charset_bin ? FALSE : TRUE; } field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; } + uint32 max_length(); }; #ifdef HAVE_SPATIAL diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 0974c552364..e98068ef974 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -121,7 +121,8 @@ set_field_to_null(Field *field) field->reset(); if (current_thd->count_cuted_fields == CHECK_FIELD_WARN) { - field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_DATA_TRUNCATED); + field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_DATA_TRUNCATED, 1); return 0; } if (!current_thd->no_errors) @@ -178,7 +179,8 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions) } if (current_thd->count_cuted_fields == CHECK_FIELD_WARN) { - field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_NULL_TO_NOTNULL); + field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_NULL_TO_NOTNULL, 1); return 0; } if (!current_thd->no_errors) @@ -229,7 +231,7 @@ static void do_copy_not_null(Copy_field *copy) if (*copy->from_null_ptr & copy->from_bit) { copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_TRUNCATED); + ER_WARN_DATA_TRUNCATED, 1); copy->to_field->reset(); } else @@ -329,7 +331,7 @@ static void do_cut_string(Copy_field *copy) if (!my_isspace(system_charset_info, *ptr)) // QQ: ucs incompatible { copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_TRUNCATED); + ER_WARN_DATA_TRUNCATED, 1); break; } } @@ -350,7 +352,7 @@ static void do_varstring(Copy_field *copy) length=copy->to_length-2; if (current_thd->count_cuted_fields) copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DATA_TRUNCATED); + ER_WARN_DATA_TRUNCATED, 1); } int2store(copy->to_ptr,length); memcpy(copy->to_ptr+2, copy->from_ptr,length); diff --git a/sql/filesort.cc b/sql/filesort.cc index 1a1547a9d67..fe2b3850197 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -341,7 +341,7 @@ static BUFFPEK *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count) { my_free((char*) tmp, MYF(0)); tmp=0; - } + } } DBUG_RETURN(tmp); } @@ -384,7 +384,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, if (sort_form->key_read) // QQ Can be removed after the reset file->extra(HA_EXTRA_KEYREAD); // QQ is removed next_pos=(byte*) 0; /* Find records in sequence */ - file->rnd_init(); + file->ha_rnd_init(1); file->extra_opt(HA_EXTRA_CACHE, current_thd->variables.read_buff_size); } @@ -439,7 +439,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, { DBUG_PRINT("info",("Sort killed by user")); (void) file->extra(HA_EXTRA_NO_CACHE); - file->rnd_end(); + file->ha_rnd_end(); DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */ } if (error == 0) @@ -469,7 +469,8 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, else { (void) file->extra(HA_EXTRA_NO_CACHE); /* End cacheing of records */ - file->rnd_end(); + if (!next_pos) + file->ha_rnd_end(); } DBUG_PRINT("test",("error: %d indexpos: %d",error,indexpos)); @@ -877,7 +878,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file, if (param->not_killable) { killed= ¬_killable; - not_killable=THD::NOT_KILLED; + not_killable= THD::NOT_KILLED; } error=0; diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 69a4635b7af..e25640280a3 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -442,7 +442,6 @@ berkeley_key_cmp(TABLE *table, KEY *key_info, const char *key, uint key_length) return 0; // Identical keys } - int ha_berkeley::open(const char *name, int mode, uint test_if_locked) { char name_buff[FN_REFLEN]; @@ -725,8 +724,8 @@ void ha_berkeley::unpack_key(char *record, DBT *key, uint index) } record[key_part->null_offset]&= ~key_part->null_bit; } - pos= (char*) key_part->field->unpack(record + key_part->field->offset(), - pos); + pos= (char*) key_part->field->unpack_key(record + key_part->field->offset(), + pos, key_part->length); } } @@ -843,8 +842,8 @@ int ha_berkeley::write_row(byte * record) else { DB_TXN *sub_trans = transaction; - /* Don't use sub transactions in temporary tables (in_use == 0) */ - ulong thd_options = table->in_use ? table->in_use->options : 0; + /* Don't use sub transactions in temporary tables */ + ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0; for (uint retry=0 ; retry < berkeley_trans_retry ; retry++) { key_map changed_keys(0); @@ -1067,7 +1066,7 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row) DBT prim_key, key, old_prim_key; int error; DB_TXN *sub_trans; - ulong thd_options = table->in_use ? table->in_use->options : 0; + ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0; bool primary_key_changed; DBUG_ENTER("update_row"); LINT_INIT(error); @@ -1260,7 +1259,7 @@ int ha_berkeley::delete_row(const byte * record) int error; DBT row, prim_key; key_map keys=table->keys_in_use; - ulong thd_options = table->in_use ? table->in_use->options : 0; + ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0; DBUG_ENTER("delete_row"); statistic_increment(ha_delete_count,&LOCK_status); @@ -1350,6 +1349,7 @@ int ha_berkeley::index_end() error=cursor->c_close(cursor); cursor=0; } + active_index=MAX_KEY; DBUG_RETURN(error); } @@ -1411,7 +1411,7 @@ int ha_berkeley::index_read_idx(byte * buf, uint keynr, const byte * key, statistic_increment(ha_read_key_count,&LOCK_status); DBUG_ENTER("index_read_idx"); current_row.flags=DB_DBT_REALLOC; - active_index= (uint) -1; + active_index=MAX_KEY; DBUG_RETURN(read_row(key_file[keynr]->get(key_file[keynr], transaction, pack_key(&last_key, keynr, key_buff, key, key_len), @@ -1482,7 +1482,7 @@ int ha_berkeley::index_read(byte * buf, const byte * key, bzero((char*) &row, sizeof(row)); error= read_row(cursor->c_get(cursor, &last_key, &row, DB_PREV), (char*) buf, active_index, &row, &last_key, 1); - } + } DBUG_RETURN(error); } @@ -1630,20 +1630,51 @@ int ha_berkeley::rnd_pos(byte * buf, byte *pos) statistic_increment(ha_read_rnd_count,&LOCK_status); DBUG_ENTER("ha_berkeley::rnd_pos"); - active_index= (uint) -1; // Don't delete via cursor + active_index= MAX_KEY; DBUG_RETURN(read_row(file->get(file, transaction, get_pos(&db_pos, pos), ¤t_row, 0), (char*) buf, primary_key, ¤t_row, (DBT*) 0, 0)); } +/* + Set a reference to the current record in (ref,ref_length). + + SYNOPSIS + ha_berkeley::position() + record The current record buffer + + DESCRIPTION + The BDB handler stores the primary key in (ref,ref_length). + There is either an explicit primary key, or an implicit (hidden) + primary key. + During open(), 'ref_length' is calculated as the maximum primary + key length. When an actual key is shorter than that, the rest of + the buffer must be cleared out. The row cannot be identified, if + garbage follows behind the end of the key. There is no length + field for the current key, so that the whole ref_length is used + for comparison. + + RETURN + nothing +*/ + void ha_berkeley::position(const byte *record) { DBT key; + DBUG_ENTER("ha_berkeley::position"); if (hidden_primary_key) + { + DBUG_ASSERT(ref_length == BDB_HIDDEN_PRIMARY_KEY_LENGTH); memcpy_fixed(ref, (char*) current_ident, BDB_HIDDEN_PRIMARY_KEY_LENGTH); + } else + { create_key(&key, primary_key, (char*) ref, record); + if (key.size < ref_length) + bzero(ref + key.size, ref_length - key.size); + } + DBUG_VOID_RETURN; } diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h index 1d7d29de979..3213a81fadf 100644 --- a/sql/ha_berkeley.h +++ b/sql/ha_berkeley.h @@ -87,24 +87,25 @@ class ha_berkeley: public handler public: ha_berkeley(TABLE *table): handler(table), alloc_ptr(0),rec_buff(0), file(0), - int_table_flags(HA_REC_NOT_IN_SEQ | - HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | HA_FAST_KEY_READ | - HA_NULL_KEY | HA_BLOB_KEY | HA_NOT_EXACT_COUNT | - HA_PRIMARY_KEY_IN_READ_INDEX | HA_DROP_BEFORE_CREATE | - HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX | - HA_KEY_READ_WRONG_STR | HA_FILE_BASED), - changed_rows(0),last_dup_key((uint) -1),version(0),using_ignore(0) - { - } + int_table_flags(HA_REC_NOT_IN_SEQ | HA_FAST_KEY_READ | + HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_NOT_EXACT_COUNT | + HA_PRIMARY_KEY_IN_READ_INDEX | HA_FILE_BASED | + HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX), + changed_rows(0),last_dup_key((uint) -1),version(0),using_ignore(0) {} ~ha_berkeley() {} const char *table_type() const { return "BerkeleyDB"; } + ulong index_flags(uint idx, uint part) const + { + ulong flags=HA_READ_NEXT | HA_READ_PREV; + if (part == (uint)~0 || + table->key_info[idx].key_part[part].field->key_type() != HA_KEYTYPE_TEXT) + flags|= HA_READ_ORDER | HA_KEYREAD_ONLY | HA_READ_RANGE; + return flags; + } const char *index_type(uint key_number) { return "BTREE"; } const char **bas_ext() const; ulong table_flags(void) const { return int_table_flags; } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return MAX_KEY-1; } - uint max_key_parts() const { return MAX_REF_PARTS; } - uint max_key_length() const { return MAX_KEY_LENGTH; } + uint max_supported_keys() const { return MAX_KEY-1; } uint extra_rec_buf_length() { return BDB_HIDDEN_PRIMARY_KEY_LENGTH; } ha_rows estimate_number_of_rows(); const key_map *keys_to_use_for_scanning() { return &key_map_full; } @@ -128,7 +129,7 @@ class ha_berkeley: public handler int index_prev(byte * buf); int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_end(); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index c375614ac95..cc828b6e6b2 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -111,6 +111,7 @@ int ha_heap::delete_row(const byte * buf) int ha_heap::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_key_count, &LOCK_status); int error = heap_rkey(file,buf,active_index, key, key_len, find_flag); table->status = error ? STATUS_NOT_FOUND : 0; @@ -119,6 +120,7 @@ int ha_heap::index_read(byte * buf, const byte * key, uint key_len, int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_key_count, &LOCK_status); int error= heap_rkey(file, buf, active_index, key, key_len, HA_READ_PREFIX_LAST); @@ -137,6 +139,7 @@ int ha_heap::index_read_idx(byte * buf, uint index, const byte * key, int ha_heap::index_next(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_next_count,&LOCK_status); int error=heap_rnext(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; @@ -145,6 +148,7 @@ int ha_heap::index_next(byte * buf) int ha_heap::index_prev(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_prev_count,&LOCK_status); int error=heap_rprev(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; @@ -153,6 +157,7 @@ int ha_heap::index_prev(byte * buf) int ha_heap::index_first(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_first_count,&LOCK_status); int error=heap_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -161,6 +166,7 @@ int ha_heap::index_first(byte * buf) int ha_heap::index_last(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_last_count,&LOCK_status); int error=heap_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; diff --git a/sql/ha_heap.h b/sql/ha_heap.h index ebca52265b0..9d0b9999300 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -40,21 +40,18 @@ class ha_heap: public handler const char **bas_ext() const; ulong table_flags() const { - return (HA_READ_RND_SAME | HA_FAST_KEY_READ | HA_KEYPOS_TO_RNDPOS | - HA_NO_BLOBS | HA_NULL_KEY | HA_REC_NOT_IN_SEQ); + return (HA_FAST_KEY_READ | HA_NO_BLOBS | HA_NULL_IN_KEY | + HA_REC_NOT_IN_SEQ | HA_READ_RND_SAME | + HA_CAN_INSERT_DELAYED); } - ulong index_flags(uint inx) const + ulong index_flags(uint inx, uint part) const { return ((table->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? - (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER) : - (HA_ONLY_WHOLE_INDEX | HA_WRONG_ASCII_ORDER | - HA_NOT_READ_PREFIX_LAST)); + HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE : + HA_ONLY_WHOLE_INDEX); } const key_map *keys_to_use_for_scanning() { return &btree_keys; } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return MAX_KEY; } - uint max_key_parts() const { return MAX_REF_PARTS; } - uint max_key_length() const { return HA_MAX_REC_LENGTH; } + uint max_supported_keys() const { return MAX_KEY; } double scan_time() { return (double) (records+deleted) / 20.0+10; } double read_time(uint index, uint ranges, ha_rows rows) { return (double) rows / 20.0+1; } @@ -75,7 +72,7 @@ class ha_heap: public handler int index_prev(byte * buf); int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index f870cbab1c3..9f14e22ce38 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -66,6 +66,7 @@ extern "C" { #include "../innobase/include/trx0roll.h" #include "../innobase/include/trx0trx.h" #include "../innobase/include/trx0sys.h" +#include "../innobase/include/mtr0mtr.h" #include "../innobase/include/row0ins.h" #include "../innobase/include/row0mysql.h" #include "../innobase/include/row0sel.h" @@ -103,7 +104,7 @@ are determined in innobase_init below: */ char* innobase_data_home_dir = NULL; char* innobase_data_file_path = NULL; char* innobase_log_group_home_dir = NULL; -char* innobase_log_arch_dir = NULL; +char* innobase_log_arch_dir = NULL;/* unused */ /* The following has a misleading name: starting from 4.0.5, this also affects Windows: */ char* innobase_unix_file_flush_method = NULL; @@ -112,7 +113,7 @@ char* innobase_unix_file_flush_method = NULL; values */ uint innobase_flush_log_at_trx_commit = 1; -my_bool innobase_log_archive = FALSE; +my_bool innobase_log_archive = FALSE;/* unused */ my_bool innobase_use_native_aio = FALSE; my_bool innobase_fast_shutdown = TRUE; my_bool innobase_file_per_table = FALSE; @@ -406,7 +407,7 @@ innobase_mysql_print_thd( May 14, 2004 probably no race any more, but better be safe */ } - + /* Use strmake to reduce the timeframe for a race, compared to fwrite() */ i= (uint) (strmake(buf, s, len) - buf); @@ -841,7 +842,8 @@ innobase_init(void) if (!innobase_log_group_home_dir) { innobase_log_group_home_dir = default_path; } - + +#ifdef UNIV_LOG_ARCHIVE /* Since innodb_log_arch_dir has no relevance under MySQL, starting from 4.0.6 we always set it the same as innodb_log_group_home_dir: */ @@ -849,6 +851,7 @@ innobase_init(void) innobase_log_arch_dir = innobase_log_group_home_dir; srv_arch_dir = innobase_log_arch_dir; +#endif /* UNIG_LOG_ARCHIVE */ ret = (bool) srv_parse_log_group_home_dirs(innobase_log_group_home_dir, @@ -870,7 +873,9 @@ innobase_init(void) srv_n_log_files = (ulint) innobase_log_files_in_group; srv_log_file_size = (ulint) innobase_log_file_size; +#ifdef UNIV_LOG_ARCHIVE srv_log_archive_on = (ulint) innobase_log_archive; +#endif /* UNIV_LOG_ARCHIVE */ srv_log_buffer_size = (ulint) innobase_log_buffer_size; srv_flush_log_at_trx_commit = (ulint) innobase_flush_log_at_trx_commit; @@ -1433,9 +1438,6 @@ ha_innobase::open( last_query_id = (ulong)-1; - active_index = 0; - active_index_before_scan = (uint)-1; /* undefined value */ - if (!(share=get_share(name))) { DBUG_RETURN(1); @@ -1579,15 +1581,6 @@ ha_innobase::open( DBUG_RETURN(0); } -/********************************************************************* -Does nothing. */ - -void -ha_innobase::initialize(void) -/*=========================*/ -{ -} - /********************************************************************** Closes a handle to an InnoDB table. */ @@ -1745,7 +1738,12 @@ innobase_mysql_cmp( } } - ret = my_strnncoll(charset, + /* Starting from 4.1.3, we use strnncollsp() in comparisons of + non-latin1_swedish_ci strings. NOTE that the collation order + changes then: 'b\0\0...' is ordered BEFORE 'b ...'. Users + having indexes on such data need to rebuild their tables! */ + + ret = charset->coll->strnncollsp(charset, a, a_length, b, b_length); if (ret < 0) { @@ -2655,7 +2653,7 @@ ha_innobase::index_end(void) { int error = 0; DBUG_ENTER("index_end"); - + active_index=MAX_KEY; DBUG_RETURN(error); } @@ -3126,8 +3124,6 @@ ha_innobase::rnd_init( /* Store the active index value so that we can restore the original value after a scan */ - active_index_before_scan = active_index; - if (prebuilt->clust_index_was_generated) { err = change_active_index(MAX_KEY); } else { @@ -3147,19 +3143,7 @@ ha_innobase::rnd_end(void) /*======================*/ /* out: 0 or error number */ { - /* Restore the old active_index back; MySQL may assume that a table - scan does not change active_index. We only restore the value if - MySQL has called rnd_init before: sometimes MySQL seems to call - rnd_end WITHOUT calling rnd_init. */ - - if (active_index_before_scan != (uint)-1) { - - change_active_index(active_index_before_scan); - - active_index_before_scan = (uint)-1; - } - - return(index_end()); + return(index_end()); } /********************************************************************* @@ -4331,9 +4315,8 @@ ha_innobase::analyze( } /************************************************************************** -This is currently mapped to ::analyze. A better option would be to map this -to "ALTER TABLE tablename TYPE=InnoDB", which seems to rebuild the table in -MySQL. */ +This is mapped to "ALTER TABLE tablename TYPE=InnoDB", which rebuilds +the table in MySQL. */ int ha_innobase::optimize( @@ -4341,7 +4324,7 @@ ha_innobase::optimize( THD* thd, /* in: connection thread handle */ HA_CHECK_OPT* check_opt) /* in: currently ignored */ { - return(ha_innobase::analyze(thd, check_opt)); + return(HA_ADMIN_TRY_ALTER); } /*********************************************************************** @@ -4664,7 +4647,22 @@ ha_innobase::start_stmt( prepared for an update of a row */ prebuilt->select_lock_type = LOCK_X; - } + } else { + 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: use LOCK_X as the + select_lock_type value (TODO: how could we know + whether it should be LOCK_S, LOCK_X, or LOCK_NONE?) */ + + 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; @@ -5044,7 +5042,7 @@ ha_innobase::store_lock( /*********************************************************************** This function initializes the auto-inc counter if it has not been initialized yet. This function does not change the value of the auto-inc -counter if it already has been initialized. In parameter ret returns +counter if it already has been initialized. In paramete ret returns the value of the auto-inc counter. */ int @@ -5170,6 +5168,39 @@ ha_innobase::get_auto_increment() return(nr); } +/*********************************************************************** +This function stores binlog offset and flushes logs */ + +void +innobase_store_binlog_offset_and_flush_log( +/*=============================*/ + char *binlog_name, /* in: binlog name */ + longlong offset /* in: binlog offset */ +) +{ + mtr_t mtr; + + assert(binlog_name != NULL); + + /* Start a mini-transaction */ + mtr_start_noninline(&mtr); + + /* Update the latest MySQL binlog name and offset info + in trx sys header */ + + trx_sys_update_mysql_binlog_offset( + binlog_name, + offset, + TRX_SYS_MYSQL_LOG_INFO, &mtr); + + /* Commits the mini-transaction */ + mtr_commit(&mtr); + + /* Syncronous flush of the log buffer to disk */ + log_buffer_flush_to_disk(); +} + + int ha_innobase::cmp_ref( const mysql_byte *ref1, @@ -5218,4 +5249,18 @@ ha_innobase::cmp_ref( return 0; } +char *ha_innobase::get_mysql_bin_log_name() +{ + return trx_sys_mysql_bin_log_name; +} + +ulonglong ha_innobase::get_mysql_bin_log_pos() +{ + /* + trx... is ib_longlong, which is a typedef for a 64-bit integer (__int64 or + longlong) so it's ok to cast it to ulonglong. + */ + return trx_sys_mysql_bin_log_pos; +} + #endif /* HAVE_INNOBASE_DB */ diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index a8f9750c3d4..0a86f4adf3c 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -61,20 +61,11 @@ class ha_innobase: public handler ulong start_of_scan; /* this is set to 1 when we are starting a table scan but have not yet fetched any row, else 0 */ - uint active_index_before_scan; - /* since a table scan in InnoDB is - always done through an index, a table - scan may change active_index; but - MySQL may assume that active_index - after a table scan is the same as - before; we store the value here so - that we can restore the value after - a scan */ uint last_match_mode;/* match mode of the latest search: ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX, or undefined */ longlong auto_inc_counter_for_this_stat; - ulong max_row_length(const byte *buf); + ulong max_supported_row_length(const byte *buf); uint store_key_val_for_row(uint keynr, char* buff, uint buff_len, const byte* record); @@ -87,13 +78,10 @@ class ha_innobase: public handler public: ha_innobase(TABLE *table): handler(table), int_table_flags(HA_REC_NOT_IN_SEQ | - HA_KEYPOS_TO_RNDPOS | - HA_LASTKEY_ORDER | - HA_NULL_KEY | HA_FAST_KEY_READ | - HA_BLOB_KEY | + HA_NULL_IN_KEY | HA_FAST_KEY_READ | + HA_CAN_INDEX_BLOBS | HA_CAN_SQL_HANDLER | HA_NOT_EXACT_COUNT | - HA_NO_WRITE_DELAYED | HA_PRIMARY_KEY_IN_READ_INDEX | HA_TABLE_SCAN_ON_INDEX), last_dup_key((uint) -1), @@ -106,14 +94,12 @@ class ha_innobase: public handler const char *index_type(uint key_number) { return "BTREE"; } const char** bas_ext() const; ulong table_flags() const { return int_table_flags; } - ulong index_flags(uint idx) const + ulong index_flags(uint idx, uint part) const { - return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | - HA_KEY_READ_ONLY); + return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE | + HA_KEYREAD_ONLY); } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return MAX_KEY; } - uint max_key_parts() const { return MAX_REF_PARTS; } + uint max_supported_keys() const { return MAX_KEY; } /* An InnoDB page must store >= 2 keys; a secondary key record must also contain the primary key value: @@ -121,15 +107,12 @@ class ha_innobase: public handler less than 1 / 4 of page size which is 16 kB; but currently MySQL does not work with keys whose size is > MAX_KEY_LENGTH */ - uint max_key_length() const { return((MAX_KEY_LENGTH <= 3500) ? - MAX_KEY_LENGTH : 3500);} - uint max_key_part_length() { return((MAX_KEY_LENGTH <= 3500) ? - MAX_KEY_LENGTH : 3500);} + uint max_supported_key_length() const { return 3500; } + uint max_supported_key_part_length() const { return 3500; } const key_map *keys_to_use_for_scanning() { return &key_map_full; } bool has_transactions() { return 1;} int open(const char *name, int mode, uint test_if_locked); - void initialize(void); int close(void); double scan_time(); double read_time(uint index, uint ranges, ha_rows rows); @@ -151,7 +134,7 @@ class ha_innobase: public handler int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_end(); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); @@ -183,6 +166,8 @@ class ha_innobase: public handler void init_table_handle_for_HANDLER(); longlong get_auto_increment(); uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; } + static char *get_mysql_bin_log_name(); + static ulonglong get_mysql_bin_log_pos(); bool primary_key_is_clustered() { return true; } int cmp_ref(const byte *ref1, const byte *ref2); }; @@ -241,3 +226,5 @@ int innodb_show_status(THD* thd); my_bool innobase_query_caching_of_table_permitted(THD* thd, char* full_name, uint full_name_len); void innobase_release_temporary_latches(void* innobase_tid); + +void innobase_store_binlog_offset_and_flush_log(char *binlog_name,longlong offset); diff --git a/sql/ha_isam.h b/sql/ha_isam.h index 8a887ababde..521946a17b5 100644 --- a/sql/ha_isam.h +++ b/sql/ha_isam.h @@ -32,19 +32,20 @@ class ha_isam: public handler public: ha_isam(TABLE *table) :handler(table), file(0), - int_table_flags(HA_READ_RND_SAME | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | - HA_KEY_READ_WRONG_STR | HA_DUPP_POS | - HA_NOT_DELETE_WITH_CACHE | HA_FILE_BASED) + int_table_flags(HA_READ_RND_SAME | + HA_DUPP_POS | HA_NOT_DELETE_WITH_CACHE | HA_FILE_BASED) {} ~ha_isam() {} + ulong index_flags(uint idx, uint part) const + { return HA_READ_NEXT; } // but no HA_READ_PREV here!!! const char *table_type() const { return "ISAM"; } const char *index_type(uint key_number) { return "BTREE"; } const char **bas_ext() const; ulong table_flags() const { return int_table_flags; } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return N_MAXKEY; } - uint max_key_parts() const { return N_MAXKEY_SEG; } - uint max_key_length() const { return N_MAX_KEY_LENGTH; } + uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; } + uint max_supported_keys() const { return N_MAXKEY; } + uint max_supported_key_parts() const { return N_MAXKEY_SEG; } + uint max_supported_key_length() const { return N_MAX_KEY_LENGTH; } uint min_record_length(uint options) const; bool low_byte_first() const { return 0; } @@ -62,11 +63,10 @@ class ha_isam: public handler int index_prev(byte * buf); int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); - my_off_t row_position() { return nisam_position(file); } void info(uint); int extra(enum ha_extra_function operation); int external_lock(THD *thd, int lock_type); diff --git a/sql/ha_isammrg.h b/sql/ha_isammrg.h index 289277a9dac..166a96cf9e4 100644 --- a/sql/ha_isammrg.h +++ b/sql/ha_isammrg.h @@ -32,14 +32,11 @@ class ha_isammrg: public handler ~ha_isammrg() {} const char *table_type() const { return "MRG_ISAM"; } const char **bas_ext() const; - ulong table_flags() const { return (HA_READ_RND_SAME | HA_KEYPOS_TO_RNDPOS | + ulong table_flags() const { return (HA_READ_RND_SAME | HA_REC_NOT_IN_SEQ | HA_FILE_BASED); } - ulong index_flags(uint idx) const { return HA_NOT_READ_PREFIX_LAST; } + ulong index_flags(uint idx, uint part) const { DBUG_ASSERT(0); return 0; } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return 0; } - uint max_key_parts() const { return 0; } - uint max_key_length() const { return 0; } + uint max_supported_keys() const { return 0; } bool low_byte_first() const { return 0; } uint min_record_length(uint options) const; @@ -56,11 +53,10 @@ class ha_isammrg: public handler int index_prev(byte * buf); int index_first(byte * buf); int index_last(byte * buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); - my_off_t row_position() { return mrg_position(file); } void info(uint); int extra(enum ha_extra_function operation); int external_lock(THD *thd, int lock_type); diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 0c43b1f263e..f7e966a9d16 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -60,13 +60,11 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, DBUG_PRINT(msg_type,("message: %s",msgbuf)); -#ifndef EMBEDDED_LIBRARY - if (thd->net.vio == 0) + if (!thd->vio_ok()) { sql_print_error(msgbuf); return; } -#endif if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR | T_AUTO_REPAIR)) @@ -1006,8 +1004,10 @@ bool ha_myisam::check_and_repair(THD *thd) { int error=0; int marked_crashed; + char *old_query; + uint old_query_length; HA_CHECK_OPT check_opt; - DBUG_ENTER("ha_myisam::auto_check_and_repair"); + DBUG_ENTER("ha_myisam::check_and_repair"); check_opt.init(); check_opt.flags= T_MEDIUM | T_AUTO_REPAIR; @@ -1015,7 +1015,15 @@ bool ha_myisam::check_and_repair(THD *thd) if (!file->state->del && (myisam_recover_options & HA_RECOVER_QUICK)) check_opt.flags|=T_QUICK; sql_print_error("Warning: Checking table: '%s'",table->path); - if ((marked_crashed=mi_is_crashed(file)) || check(thd, &check_opt)) + + old_query= thd->query; + old_query_length= thd->query_length; + pthread_mutex_lock(&LOCK_thread_count); + thd->query= table->real_name; + thd->query_length= strlen(table->real_name); + pthread_mutex_unlock(&LOCK_thread_count); + + if ((marked_crashed= mi_is_crashed(file)) || check(thd, &check_opt)) { sql_print_error("Warning: Recovering table: '%s'",table->path); check_opt.flags= @@ -1026,6 +1034,10 @@ bool ha_myisam::check_and_repair(THD *thd) if (repair(thd, &check_opt)) error=1; } + pthread_mutex_lock(&LOCK_thread_count); + thd->query= old_query; + thd->query_length= old_query_length; + pthread_mutex_unlock(&LOCK_thread_count); DBUG_RETURN(error); } @@ -1052,6 +1064,7 @@ int ha_myisam::delete_row(const byte * buf) int ha_myisam::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_key_count,&LOCK_status); int error=mi_rkey(file,buf,active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1069,6 +1082,7 @@ int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key, int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_key_count,&LOCK_status); int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1077,6 +1091,7 @@ int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len) int ha_myisam::index_next(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_next_count,&LOCK_status); int error=mi_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1085,6 +1100,7 @@ int ha_myisam::index_next(byte * buf) int ha_myisam::index_prev(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_prev_count,&LOCK_status); int error=mi_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1093,6 +1109,7 @@ int ha_myisam::index_prev(byte * buf) int ha_myisam::index_first(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_first_count,&LOCK_status); int error=mi_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1101,6 +1118,7 @@ int ha_myisam::index_first(byte * buf) int ha_myisam::index_last(byte * buf) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_last_count,&LOCK_status); int error=mi_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1111,6 +1129,7 @@ int ha_myisam::index_next_same(byte * buf, const byte *key __attribute__((unused)), uint length __attribute__((unused))) { + DBUG_ASSERT(inited==INDEX); statistic_increment(ha_read_next_count,&LOCK_status); int error=mi_rnext_same(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index 77887220903..ef3f00577dd 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -44,10 +44,10 @@ class ha_myisam: public handler public: ha_myisam(TABLE *table): handler(table), file(0), - int_table_flags(HA_READ_RND_SAME | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | - HA_NULL_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER | - HA_DUPP_POS | HA_BLOB_KEY | HA_AUTO_PART_KEY | - HA_FILE_BASED | HA_HAS_GEOMETRY), + int_table_flags(HA_NULL_IN_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER | + HA_DUPP_POS | HA_CAN_INDEX_BLOBS | HA_AUTO_PART_KEY | + HA_FILE_BASED | HA_CAN_GEOMETRY | HA_READ_RND_SAME | + HA_CAN_INSERT_DELAYED), can_enable_indexes(1) {} ~ha_myisam() {} @@ -55,17 +55,15 @@ class ha_myisam: public handler const char *index_type(uint key_number); const char **bas_ext() const; ulong table_flags() const { return int_table_flags; } - ulong index_flags(uint inx) const + ulong index_flags(uint inx, uint part) const { - ulong flags=(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER); - return (flags | ((table->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? - 0 : HA_KEY_READ_ONLY)); + return ((table->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? + 0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | + HA_READ_ORDER | HA_KEYREAD_ONLY); } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return MI_MAX_KEY; } - uint max_key_parts() const { return MAX_REF_PARTS; } - uint max_key_length() const { return MI_MAX_KEY_LENGTH; } - uint max_key_part_length() { return MI_MAX_KEY_LENGTH; } + uint max_supported_keys() const { return MI_MAX_KEY; } + uint max_supported_key_length() const { return MI_MAX_KEY_LENGTH; } + uint max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; } uint checksum() const; int open(const char *name, int mode, uint test_if_locked); @@ -94,12 +92,11 @@ class ha_myisam: public handler FT_INFO *ft_init_ext(uint flags, uint inx,const byte *key, uint keylen) { return ft_init_search(flags,file,inx,(byte*) key,keylen, table->record[0]); } int ft_read(byte *buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); int restart_rnd_next(byte *buf, byte *pos); void position(const byte *record); - my_off_t row_position() { return mi_position(file); } void info(uint); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); diff --git a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h index fd36c78202d..995cfe9ad4a 100644 --- a/sql/ha_myisammrg.h +++ b/sql/ha_myisammrg.h @@ -34,21 +34,20 @@ class ha_myisammrg: public handler const char **bas_ext() const; ulong table_flags() const { - return (HA_REC_NOT_IN_SEQ | HA_READ_RND_SAME | HA_AUTO_PART_KEY | - HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | - HA_NULL_KEY | HA_BLOB_KEY | HA_FILE_BASED); + return (HA_REC_NOT_IN_SEQ | HA_AUTO_PART_KEY | HA_READ_RND_SAME | + HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_FILE_BASED | + HA_CAN_INSERT_DELAYED); } - ulong index_flags(uint inx) const + ulong index_flags(uint inx, uint part) const { - ulong flags=(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER); - return (flags | ((table->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? - 0 : HA_KEY_READ_ONLY)); + return ((table->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? + 0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | + HA_READ_ORDER | HA_KEYREAD_ONLY); } - uint max_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_keys() const { return MI_MAX_KEY; } - uint max_key_parts() const { return MAX_REF_PARTS; } - uint max_key_length() const { return MAX_KEY_LENGTH; } - virtual double scan_time() + uint max_supported_keys() const { return MI_MAX_KEY; } + uint max_supported_key_length() const { return MI_MAX_KEY_LENGTH; } + uint max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; } + double scan_time() { return ulonglong2double(data_file_length) / IO_SIZE + file->tables; } int open(const char *name, int mode, uint test_if_locked); @@ -66,12 +65,11 @@ class ha_myisammrg: public handler int index_first(byte * buf); int index_last(byte * buf); int index_next_same(byte *buf, const byte *key, uint keylen); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); - my_off_t row_position() { return myrg_position(file); } void info(uint); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 21056ef4a8f..d499218a8c3 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -20,12 +20,6 @@ NDB Cluster */ -/* - TODO - After CREATE DATABASE gör discover pÃ¥ alla tabeller i den databasen - -*/ - #ifdef __GNUC__ #pragma implementation // gcc: Class implementation @@ -45,8 +39,13 @@ // Default value for parallelism static const int parallelism= 240; +// Default value for max number of transactions +// createable against NDB from this handler +static const int max_transactions = 256; + #define NDB_HIDDEN_PRIMARY_KEY_LENGTH 8 + #define ERR_PRINT(err) \ DBUG_PRINT("error", ("Error: %d message: %s", err.code, err.message)) @@ -64,6 +63,8 @@ typedef NdbDictionary::Dictionary NDBDICT; bool ndbcluster_inited= false; +static Ndb* g_ndb= NULL; + // Handler synchronization pthread_mutex_t ndbcluster_mutex; @@ -95,7 +96,22 @@ static const err_code_mapping err_map[]= { 630, HA_ERR_FOUND_DUPP_KEY }, { 893, HA_ERR_FOUND_DUPP_UNIQUE }, { 721, HA_ERR_TABLE_EXIST }, + { 4244, HA_ERR_TABLE_EXIST }, { 241, HA_ERR_OLD_METADATA }, + + { 266, HA_ERR_LOCK_WAIT_TIMEOUT }, + { 274, HA_ERR_LOCK_WAIT_TIMEOUT }, + { 296, HA_ERR_LOCK_WAIT_TIMEOUT }, + { 297, HA_ERR_LOCK_WAIT_TIMEOUT }, + { 237, HA_ERR_LOCK_WAIT_TIMEOUT }, + + { 623, HA_ERR_RECORD_FILE_FULL }, + { 624, HA_ERR_RECORD_FILE_FULL }, + { 625, HA_ERR_RECORD_FILE_FULL }, + { 826, HA_ERR_RECORD_FILE_FULL }, + { 827, HA_ERR_RECORD_FILE_FULL }, + { 832, HA_ERR_RECORD_FILE_FULL }, + { -1, -1 } }; @@ -144,6 +160,28 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans) /* + Override the default get_error_message in order to add the + error message of NDB + */ + +bool ha_ndbcluster::get_error_message(int error, + String *buf) +{ + DBUG_ENTER("ha_ndbcluster::get_error_message"); + DBUG_PRINT("enter", ("error: %d", error)); + + if (!m_ndb) + DBUG_RETURN(false); + + const NdbError err= m_ndb->getNdbError(error); + bool temporary= err.status==NdbError::TemporaryError; + buf->set(err.message, strlen(err.message), &my_charset_bin); + DBUG_PRINT("exit", ("message: %s, temporary: %d", buf->ptr(), temporary)); + DBUG_RETURN(temporary); +} + + +/* Instruct NDB to set the value of the hidden primary key */ @@ -297,7 +335,7 @@ int ha_ndbcluster::get_metadata(const char *path) const NDBTAB *tab; const void *data, *pack_data; const char **key_name; - uint ndb_columns, mysql_columns, length, pack_length, i; + uint ndb_columns, mysql_columns, length, pack_length; int error; DBUG_ENTER("get_metadata"); DBUG_PRINT("enter", ("m_tabname: %s, path: %s", m_tabname, path)); @@ -353,60 +391,111 @@ int ha_ndbcluster::get_metadata(const char *path) // All checks OK, lets use the table m_table= (void*)tab; - for (i= 0; i < MAX_KEY; i++) - m_indextype[i]= UNDEFINED_INDEX; + DBUG_RETURN(build_index_list()); +} +int ha_ndbcluster::build_index_list() +{ + char *name; + const char *index_name; + static const char* unique_suffix= "$unique"; + uint i, name_len; + DBUG_ENTER("build_index_list"); + // Save information about all known indexes - for (i= 0; i < table->keys; i++) - m_indextype[i] = get_index_type_from_table(i); - - DBUG_RETURN(0); + for (uint i= 0; i < table->keys; i++) + { + NDB_INDEX_TYPE idx_type= get_index_type_from_table(i); + m_indextype[i]= idx_type; + + if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX) + { + index_name= get_index_name(i); + name_len= strlen(index_name)+strlen(unique_suffix)+1; + // Create name for unique index by appending "$unique"; + if (!(name= my_malloc(name_len, MYF(MY_WME)))) + DBUG_RETURN(2); + strxnmov(name, name_len, index_name, unique_suffix, NullS); + m_unique_index_name[i]= name; + DBUG_PRINT("info", ("Created unique index name: %s for index %d", + name, i)); + } + } + DBUG_RETURN(0); } + + /* Decode the type of an index from information provided in table object */ -NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_table(uint index_no) const +NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_table(uint inx) const { - if (index_no == table->primary_key) - return PRIMARY_KEY_INDEX; + bool is_hash_index= (table->key_info[inx].algorithm == HA_KEY_ALG_HASH); + if (inx == table->primary_key) + return is_hash_index ? PRIMARY_KEY_INDEX : PRIMARY_KEY_ORDERED_INDEX; else - return ((table->key_info[index_no].flags & HA_NOSAME) ? - UNIQUE_INDEX : + return ((table->key_info[inx].flags & HA_NOSAME) ? + (is_hash_index ? UNIQUE_INDEX : UNIQUE_ORDERED_INDEX) : ORDERED_INDEX); } - + void ha_ndbcluster::release_metadata() { + uint i; + DBUG_ENTER("release_metadata"); DBUG_PRINT("enter", ("m_tabname: %s", m_tabname)); m_table= NULL; + // Release index list + for (i= 0; i < MAX_KEY; i++) + { + if (m_unique_index_name[i]) + my_free((char*)m_unique_index_name[i], MYF(0)); + m_unique_index_name[i]= NULL; + } + DBUG_VOID_RETURN; } +NdbCursorOperation::LockMode get_ndb_lock_type(enum thr_lock_type type) +{ + return (type == TL_WRITE_ALLOW_WRITE) ? + NdbCursorOperation::LM_Exclusive : NdbCursorOperation::LM_Read; +} + static const ulong index_type_flags[]= { /* UNDEFINED_INDEX */ 0, /* PRIMARY_KEY_INDEX */ - HA_ONLY_WHOLE_INDEX | - HA_WRONG_ASCII_ORDER | - HA_NOT_READ_PREFIX_LAST, + HA_ONLY_WHOLE_INDEX, + + /* PRIMARY_KEY_ORDERED_INDEX */ + /* + Enable HA_KEYREAD_ONLY when "sorted" indexes are supported, + thus ORDERD BY clauses can be optimized by reading directly + through the index. + */ + // HA_KEYREAD_ONLY | + HA_READ_NEXT | + HA_READ_RANGE, /* UNIQUE_INDEX */ - HA_ONLY_WHOLE_INDEX | - HA_WRONG_ASCII_ORDER | - HA_NOT_READ_PREFIX_LAST, + HA_ONLY_WHOLE_INDEX, + + /* UNIQUE_ORDERED_INDEX */ + HA_READ_NEXT | + HA_READ_RANGE, /* ORDERED_INDEX */ HA_READ_NEXT | - HA_READ_PREV | - HA_NOT_READ_AFTER_KEY + HA_READ_RANGE, }; static const int index_flags_size= sizeof(index_type_flags)/sizeof(ulong); @@ -416,6 +505,11 @@ inline const char* ha_ndbcluster::get_index_name(uint idx_no) const return table->keynames.type_names[idx_no]; } +inline const char* ha_ndbcluster::get_unique_index_name(uint idx_no) const +{ + return m_unique_index_name[idx_no]; +} + inline NDB_INDEX_TYPE ha_ndbcluster::get_index_type(uint idx_no) const { DBUG_ASSERT(idx_no < MAX_KEY); @@ -430,9 +524,10 @@ inline NDB_INDEX_TYPE ha_ndbcluster::get_index_type(uint idx_no) const flags depending on the type of the index. */ -inline ulong ha_ndbcluster::index_flags(uint idx_no) const +inline ulong ha_ndbcluster::index_flags(uint idx_no, uint part) const { DBUG_ENTER("index_flags"); + DBUG_PRINT("info", ("idx_no: %d", idx_no)); DBUG_ASSERT(get_index_type_from_table(idx_no) < index_flags_size); DBUG_RETURN(index_type_flags[get_index_type_from_table(idx_no)]); } @@ -457,6 +552,24 @@ int ha_ndbcluster::set_primary_key(NdbOperation *op, const byte *key) } +int ha_ndbcluster::set_primary_key_from_old_data(NdbOperation *op, const byte *old_data) +{ + KEY* key_info= table->key_info + table->primary_key; + KEY_PART_INFO* key_part= key_info->key_part; + KEY_PART_INFO* end= key_part+key_info->key_parts; + DBUG_ENTER("set_primary_key_from_old_data"); + + for (; key_part != end; key_part++) + { + Field* field= key_part->field; + if (set_ndb_key(op, field, + key_part->fieldnr-1, old_data+key_part->offset)) + ERR_RETURN(op->getNdbError()); + } + DBUG_RETURN(0); +} + + int ha_ndbcluster::set_primary_key(NdbOperation *op) { DBUG_ENTER("set_primary_key"); @@ -550,7 +663,6 @@ int ha_ndbcluster::unique_index_read(const byte *key, uint key_len, byte *buf) { NdbConnection *trans= m_active_trans; - const char *index_name; NdbIndexOperation *op; THD *thd= current_thd; byte *key_ptr; @@ -560,9 +672,10 @@ int ha_ndbcluster::unique_index_read(const byte *key, DBUG_ENTER("unique_index_read"); DBUG_PRINT("enter", ("key_len: %u, index: %u", key_len, active_index)); DBUG_DUMP("key", (char*)key, key_len); + DBUG_PRINT("enter", ("name: %s", get_unique_index_name(active_index))); - index_name= get_index_name(active_index); - if (!(op= trans->getNdbIndexOperation(index_name, m_tabname)) || + if (!(op= trans->getNdbIndexOperation(get_unique_index_name(active_index), + m_tabname)) || op->readTuple() != 0) ERR_RETURN(trans->getNdbError()); @@ -608,25 +721,64 @@ int ha_ndbcluster::unique_index_read(const byte *key, } /* - Get the next record of a started scan + Get the next record of a started scan. Try to fetch + it locally from NdbApi cached records if possible, + otherwise ask NDB for more. + + NOTE + If this is a update/delete make sure to not contact + NDB before any pending ops have been sent to NDB. + */ inline int ha_ndbcluster::next_result(byte *buf) { + int check; NdbConnection *trans= m_active_trans; NdbResultSet *cursor= m_active_cursor; DBUG_ENTER("next_result"); - - if (cursor->nextResult() == 0) - { - // One more record found - unpack_record(buf); - table->status= 0; - DBUG_RETURN(0); - } + + if (!cursor) + DBUG_RETURN(HA_ERR_END_OF_FILE); + + /* + If this an update or delete, call nextResult with false + to process any records already cached in NdbApi + */ + bool contact_ndb = m_lock.type != TL_WRITE_ALLOW_WRITE; + do { + DBUG_PRINT("info", ("Call nextResult, contact_ndb: %d", contact_ndb)); + check= cursor->nextResult(contact_ndb); + if (check == 0) + { + // One more record found + DBUG_PRINT("info", ("One more record found")); + unpack_record(buf); + table->status= 0; + DBUG_RETURN(0); + } + else if (check == 1 || check == 2) + { + // 1: No more records + // 2: No more cached records + + /* + Before fetching more rows and releasing lock(s), + all pending update or delete operations should + be sent to NDB + */ + DBUG_PRINT("info", ("ops_pending: %d", ops_pending)); + if (ops_pending && (trans->execute(NoCommit) != 0)) + DBUG_RETURN(ndb_err(trans)); + ops_pending= 0; + + contact_ndb= (check == 2); + } + } while (check == 2); + table->status= STATUS_NOT_FOUND; - if (ndb_err(trans)) - ERR_RETURN(trans->getNdbError()); + if (check == -1) + DBUG_RETURN(ndb_err(trans)); // No more records DBUG_PRINT("info", ("No more records")); @@ -635,155 +787,135 @@ inline int ha_ndbcluster::next_result(byte *buf) /* - Read record(s) from NDB using ordered index scan + Set bounds for a ordered index scan, use key_range */ -int ha_ndbcluster::ordered_index_scan(const byte *key, uint key_len, - byte *buf, - enum ha_rkey_function find_flag) -{ - uint no_fields= table->fields; - uint tot_len, i; - NdbConnection *trans= m_active_trans; - NdbResultSet *cursor= m_active_cursor; - NdbScanOperation *op; - const char *bound_str= NULL; - const char *index_name; - NdbOperation::BoundType bound_type = NdbOperation::BoundEQ; - bool can_be_handled_by_ndb= FALSE; +int ha_ndbcluster::set_bounds(NdbOperation *op, + const key_range *key, + int bound) +{ + uint i, tot_len; byte *key_ptr; - KEY *key_info; - THD* thd = current_thd; - DBUG_ENTER("ordered_index_scan"); - DBUG_PRINT("enter", ("index: %u", active_index)); - DBUG_PRINT("enter", ("Starting new ordered scan on %s", m_tabname)); - - index_name= get_index_name(active_index); - if (!(op= trans->getNdbScanOperation(index_name, m_tabname))) - ERR_RETURN(trans->getNdbError()); - if (!(cursor= op->readTuples(parallelism))) - ERR_RETURN(trans->getNdbError()); - m_active_cursor= cursor; - - switch (find_flag) { - case HA_READ_KEY_EXACT: /* Find first record else error */ - bound_str= "HA_READ_KEY_EXACT"; - bound_type= NdbOperation::BoundEQ; - can_be_handled_by_ndb= TRUE; - break; - case HA_READ_KEY_OR_NEXT: /* Record or next record */ - bound_str= "HA_READ_KEY_OR_NEXT"; - bound_type= NdbOperation::BoundLE; - can_be_handled_by_ndb= TRUE; - break; - case HA_READ_KEY_OR_PREV: /* Record or previous */ - bound_str= "HA_READ_KEY_OR_PREV"; - bound_type= NdbOperation::BoundGE; - can_be_handled_by_ndb= TRUE; - break; - case HA_READ_AFTER_KEY: /* Find next rec. after key-record */ - bound_str= "HA_READ_AFTER_KEY"; - bound_type= NdbOperation::BoundLT; - can_be_handled_by_ndb= TRUE; - break; - case HA_READ_BEFORE_KEY: /* Find next rec. before key-record */ - bound_str= "HA_READ_BEFORE_KEY"; - bound_type= NdbOperation::BoundGT; - can_be_handled_by_ndb= TRUE; - break; - case HA_READ_PREFIX: /* Key which as same prefix */ - bound_str= "HA_READ_PREFIX"; - break; - case HA_READ_PREFIX_LAST: /* Last key with the same prefix */ - bound_str= "HA_READ_PREFIX_LAST"; - break; - case HA_READ_PREFIX_LAST_OR_PREV: - /* Last or prev key with the same prefix */ - bound_str= "HA_READ_PREFIX_LAST_OR_PREV"; - break; - default: - bound_str= "UNKNOWN"; - break; - } - DBUG_PRINT("info", ("find_flag: %s, bound_type: %d," - "can_be_handled_by_ndb: %d", - bound_str, bound_type, can_be_handled_by_ndb)); - if (!can_be_handled_by_ndb) - DBUG_RETURN(1); - + KEY* key_info= table->key_info + active_index; + KEY_PART_INFO* key_part= key_info->key_part; + KEY_PART_INFO* end= key_part+key_info->key_parts; + + DBUG_ENTER("set_bounds"); + DBUG_PRINT("enter", ("bound: %d", bound)); + DBUG_PRINT("enter", ("key_parts: %d", key_info->key_parts)); + DBUG_PRINT("enter", ("key->length: %d", key->length)); + DBUG_PRINT("enter", ("key->flag: %d", key->flag)); + // Set bounds using key data tot_len= 0; - key_ptr= (byte *) key; - key_info= table->key_info + active_index; - for (i= 0; i < key_info->key_parts; i++) + key_ptr= (byte *) key->key; + for (; key_part != end; key_part++) { - Field* field= key_info->key_part[i].field; + Field* field= key_part->field; uint32 field_len= field->pack_length(); - DBUG_PRINT("info", ("Set index bound on %s", + tot_len+= field_len; + + const char* bounds[]= {"LE", "LT", "GE", "GT", "EQ"}; + DBUG_ASSERT(bound >= 0 && bound <= 4); + DBUG_PRINT("info", ("Set Bound%s on %s", + bounds[bound], field->field_name)); DBUG_DUMP("key", (char*)key_ptr, field_len); - + if (op->setBound(field->field_name, - bound_type, + bound, key_ptr, field_len) != 0) ERR_RETURN(op->getNdbError()); key_ptr+= field_len; - tot_len+= field_len; - if (tot_len >= key_len) + + if (tot_len >= key->length) + break; + + /* + Only one bound which is not EQ can be set + so if this bound was not EQ, bail out and make + a best effort attempt + */ + if (bound != NdbOperation::BoundEQ) break; } - - // Define attributes to read - for (i= 0; i < no_fields; i++) + + DBUG_RETURN(0); +} + + +/* + Start ordered index scan in NDB +*/ + +int ha_ndbcluster::ordered_index_scan(const key_range *start_key, + const key_range *end_key, + bool sorted, byte* buf) +{ + NdbConnection *trans= m_active_trans; + NdbResultSet *cursor; + NdbScanOperation *op; + const char *index_name; + + DBUG_ENTER("ordered_index_scan"); + DBUG_PRINT("enter", ("index: %u, sorted: %d", active_index, sorted)); + DBUG_PRINT("enter", ("Starting new ordered scan on %s", m_tabname)); + + index_name= get_index_name(active_index); + if (!(op= trans->getNdbScanOperation(index_name, m_tabname))) + ERR_RETURN(trans->getNdbError()); + if (!(cursor= op->readTuples(parallelism, get_ndb_lock_type(m_lock.type)))) + ERR_RETURN(trans->getNdbError()); + m_active_cursor= cursor; + + if (start_key && + set_bounds(op, start_key, + (start_key->flag == HA_READ_KEY_EXACT) ? + NdbOperation::BoundEQ : + (start_key->flag == HA_READ_AFTER_KEY) ? + NdbOperation::BoundLT : + NdbOperation::BoundLE)) + DBUG_RETURN(1); + + if (end_key) { - Field *field= table->field[i]; - if ((thd->query_id == field->query_id) || - (field->flags & PRI_KEY_FLAG)) - { - if (get_ndb_value(op, i, field->ptr)) - ERR_RETURN(op->getNdbError()); - } - else + if (start_key && start_key->flag == HA_READ_KEY_EXACT) { - m_value[i]= NULL; + DBUG_PRINT("info", ("start_key is HA_READ_KEY_EXACT ignoring end_key")); } + else if (set_bounds(op, end_key, + (end_key->flag == HA_READ_AFTER_KEY) ? + NdbOperation::BoundGE : + NdbOperation::BoundGT)) + DBUG_RETURN(1); } - - if (table->primary_key == MAX_KEY) - { - DBUG_PRINT("info", ("Getting hidden key")); - // Scanning table with no primary key - int hidden_no= no_fields; -#ifndef DBUG_OFF - const NDBTAB *tab= (NDBTAB *) m_table; - if (!tab->getColumn(hidden_no)) - DBUG_RETURN(1); -#endif - if (get_ndb_value(op, hidden_no, NULL)) - ERR_RETURN(op->getNdbError()); - } - - if (trans->execute(NoCommit) != 0) - DBUG_RETURN(ndb_err(trans)); - DBUG_PRINT("exit", ("Scan started successfully")); - DBUG_RETURN(next_result(buf)); + DBUG_RETURN(define_read_attrs(buf, op)); } -#if 0 /* - Read record(s) from NDB using full table scan with filter + Start a filtered scan in NDB. + + NOTE + This function is here as an example of how to start a + filtered scan. It should be possible to replace full_table_scan + with this function and make a best effort attempt + at filtering out the irrelevant data by converting the "items" + into interpreted instructions. + This would speed up table scans where there is a limiting WHERE clause + that doesn't match any index in the table. + */ int ha_ndbcluster::filtered_scan(const byte *key, uint key_len, byte *buf, enum ha_rkey_function find_flag) { - uint no_fields= table->fields; NdbConnection *trans= m_active_trans; - NdbResultSet *cursor= m_active_cursor; + NdbResultSet *cursor; + NdbScanOperation *op; DBUG_ENTER("filtered_scan"); DBUG_PRINT("enter", ("key_len: %u, index: %u", @@ -791,12 +923,10 @@ int ha_ndbcluster::filtered_scan(const byte *key, uint key_len, DBUG_DUMP("key", (char*)key, key_len); DBUG_PRINT("info", ("Starting a new filtered scan on %s", m_tabname)); - NdbScanOperation *op= trans->getNdbScanOperation(m_tabname); - if (!op) + + if (!(op= trans->getNdbScanOperation(m_tabname))) ERR_RETURN(trans->getNdbError()); - - cursor= op->readTuples(parallelism); - if (!cursor) + if (!(cursor= op->readTuples(parallelism, get_ndb_lock_type(m_lock.type)))) ERR_RETURN(trans->getNdbError()); m_active_cursor= cursor; @@ -845,66 +975,49 @@ int ha_ndbcluster::filtered_scan(const byte *key, uint key_len, sf.end(); } - // Define attributes to read - for (uint field_no= 0; field_no < no_fields; field_no++) - { - Field *field= table->field[field_no]; - - // Read attribute - DBUG_PRINT("get", ("%d: %s", field_no, field->field_name)); - if (get_ndb_value(op, field_no, field->ptr)) - ERR_RETURN(op->getNdbError()); - } - - if (table->primary_key == MAX_KEY) - { - DBUG_PRINT("info", ("Getting hidden key")); - // Scanning table with no primary key - int hidden_no= no_fields; -#ifndef DBUG_OFF - const NDBTAB *tab= (NDBTAB *) m_table; - if (!tab->getColumn(hidden_no)) - DBUG_RETURN(1); -#endif - if (get_ndb_value(op, hidden_no, NULL)) - ERR_RETURN(op->getNdbError()); - } - - if (trans->execute(NoCommit) != 0) - DBUG_RETURN(ndb_err(trans)); - DBUG_PRINT("exit", ("Scan started successfully")); - DBUG_RETURN(next_result(buf)); + DBUG_RETURN(define_read_attrs(buf, op)); } -#endif /* - Read records from NDB using full table scan + Start full table scan in NDB */ int ha_ndbcluster::full_table_scan(byte *buf) { uint i; - THD *thd= current_thd; - NdbConnection *trans= m_active_trans; NdbResultSet *cursor; NdbScanOperation *op; + NdbConnection *trans= m_active_trans; DBUG_ENTER("full_table_scan"); DBUG_PRINT("enter", ("Starting new scan on %s", m_tabname)); if (!(op=trans->getNdbScanOperation(m_tabname))) ERR_RETURN(trans->getNdbError()); - if (!(cursor= op->readTuples(parallelism))) + if (!(cursor= op->readTuples(parallelism, get_ndb_lock_type(m_lock.type)))) ERR_RETURN(trans->getNdbError()); m_active_cursor= cursor; - + DBUG_RETURN(define_read_attrs(buf, op)); +} + + +inline +int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op) +{ + uint i; + THD *thd= current_thd; + NdbConnection *trans= m_active_trans; + + DBUG_ENTER("define_read_attrs"); + // Define attributes to read for (i= 0; i < table->fields; i++) { Field *field= table->field[i]; if ((thd->query_id == field->query_id) || - (field->flags & PRI_KEY_FLAG)) + (field->flags & PRI_KEY_FLAG) || + retrieve_all_fields) { if (get_ndb_value(op, i, field->ptr)) ERR_RETURN(op->getNdbError()); @@ -991,8 +1104,17 @@ int ha_ndbcluster::write_row(byte *record) to NoCommit the transaction between each row. Find out how this is detected! */ - if (trans->execute(NoCommit) != 0) - DBUG_RETURN(ndb_err(trans)); + rows_inserted++; + if ((rows_inserted == rows_to_insert) || + ((rows_inserted % bulk_insert_rows) == 0)) + { + // Send rows to NDB + DBUG_PRINT("info", ("Sending inserts to NDB, "\ + "rows_inserted:%d, bulk_insert_rows: %d", + rows_inserted, bulk_insert_rows)); + if (trans->execute(NoCommit) != 0) + DBUG_RETURN(ndb_err(trans)); + } DBUG_RETURN(0); } @@ -1039,6 +1161,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) { THD *thd= current_thd; NdbConnection *trans= m_active_trans; + NdbResultSet* cursor= m_active_cursor; NdbOperation *op; uint i; DBUG_ENTER("update_row"); @@ -1047,49 +1170,66 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) if (table->timestamp_on_update_now) update_timestamp(new_data+table->timestamp_on_update_now-1); - if (!(op= trans->getNdbOperation(m_tabname)) || - op->updateTuple() != 0) - ERR_RETURN(trans->getNdbError()); - - if (table->primary_key == MAX_KEY) - { - // This table has no primary key, use "hidden" primary key - DBUG_PRINT("info", ("Using hidden key")); - - // Require that the PK for this record has previously been - // read into m_value - uint no_fields= table->fields; - NdbRecAttr* rec= m_value[no_fields]; - DBUG_ASSERT(rec); - DBUG_DUMP("key", (char*)rec->aRef(), NDB_HIDDEN_PRIMARY_KEY_LENGTH); - - if (set_hidden_key(op, no_fields, rec->aRef())) - ERR_RETURN(op->getNdbError()); - } - else + /* Check for update of primary key and return error */ + if ((table->primary_key != MAX_KEY) && + (key_cmp(table->primary_key, old_data, new_data))) + DBUG_RETURN(HA_ERR_UNSUPPORTED); + + if (cursor) { - /* Check for update of primary key and return error */ - if (key_cmp(table->primary_key, old_data, new_data)) - DBUG_RETURN(HA_ERR_UNSUPPORTED); - - int res; - if ((res= set_primary_key(op, old_data + table->null_bytes))) - DBUG_RETURN(res); + /* + We are scanning records and want to update the record + that was just found, call updateTuple on the cursor + to take over the lock to a new update operation + And thus setting the primary key of the record from + the active record in cursor + */ + DBUG_PRINT("info", ("Calling updateTuple on cursor")); + if (!(op= cursor->updateTuple())) + ERR_RETURN(trans->getNdbError()); + ops_pending++; + } + else + { + if (!(op= trans->getNdbOperation(m_tabname)) || + op->updateTuple() != 0) + ERR_RETURN(trans->getNdbError()); + + if (table->primary_key == MAX_KEY) + { + // This table has no primary key, use "hidden" primary key + DBUG_PRINT("info", ("Using hidden key")); + + // Require that the PK for this record has previously been + // read into m_value + uint no_fields= table->fields; + NdbRecAttr* rec= m_value[no_fields]; + DBUG_ASSERT(rec); + DBUG_DUMP("key", (char*)rec->aRef(), NDB_HIDDEN_PRIMARY_KEY_LENGTH); + + if (set_hidden_key(op, no_fields, rec->aRef())) + ERR_RETURN(op->getNdbError()); + } + else + { + int res; + if ((res= set_primary_key_from_old_data(op, old_data))) + DBUG_RETURN(res); + } } // Set non-key attribute(s) for (i= 0; i < table->fields; i++) { - Field *field= table->field[i]; if ((thd->query_id == field->query_id) && (!(field->flags & PRI_KEY_FLAG)) && set_ndb_value(op, field, i)) ERR_RETURN(op->getNdbError()); } - + // Execute update operation - if (trans->execute(NoCommit) != 0) + if (!cursor && trans->execute(NoCommit) != 0) DBUG_RETURN(ndb_err(trans)); DBUG_RETURN(0); @@ -1103,39 +1243,61 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) int ha_ndbcluster::delete_row(const byte *record) { NdbConnection *trans= m_active_trans; + NdbResultSet* cursor= m_active_cursor; NdbOperation *op; DBUG_ENTER("delete_row"); statistic_increment(ha_delete_count,&LOCK_status); - if (!(op=trans->getNdbOperation(m_tabname)) || - op->deleteTuple() != 0) - ERR_RETURN(trans->getNdbError()); - - if (table->primary_key == MAX_KEY) + if (cursor) { - // This table has no primary key, use "hidden" primary key - DBUG_PRINT("info", ("Using hidden key")); - uint no_fields= table->fields; - NdbRecAttr* rec= m_value[no_fields]; - DBUG_ASSERT(rec != NULL); + /* + We are scanning records and want to update the record + that was just found, call deleteTuple on the cursor + to take over the lock to a new update operation + And thus setting the primary key of the record from + the active record in cursor + */ + DBUG_PRINT("info", ("Calling deleteTuple on cursor")); + if (cursor->deleteTuple() != 0) + ERR_RETURN(trans->getNdbError()); + ops_pending++; - if (set_hidden_key(op, no_fields, rec->aRef())) - ERR_RETURN(op->getNdbError()); - } - else + // If deleting from cursor, NoCommit will be handled in next_result + DBUG_RETURN(0); + } + else { - int res; - if ((res= set_primary_key(op))) - return res; + + if (!(op=trans->getNdbOperation(m_tabname)) || + op->deleteTuple() != 0) + ERR_RETURN(trans->getNdbError()); + + if (table->primary_key == MAX_KEY) + { + // This table has no primary key, use "hidden" primary key + DBUG_PRINT("info", ("Using hidden key")); + uint no_fields= table->fields; + NdbRecAttr* rec= m_value[no_fields]; + DBUG_ASSERT(rec != NULL); + + if (set_hidden_key(op, no_fields, rec->aRef())) + ERR_RETURN(op->getNdbError()); + } + else + { + int res; + if ((res= set_primary_key(op))) + return res; + } } - + // Execute delete operation if (trans->execute(NoCommit) != 0) DBUG_RETURN(ndb_err(trans)); DBUG_RETURN(0); } - + /* Unpack a record read from NDB @@ -1223,6 +1385,7 @@ void ha_ndbcluster::print_results() switch (col->getType()) { case NdbDictionary::Column::Blob: + case NdbDictionary::Column::Clob: case NdbDictionary::Column::Undefined: fprintf(DBUG_FILE, "Unknown type: %d", col->getType()); break; @@ -1337,7 +1500,7 @@ int ha_ndbcluster::index_init(uint index) int ha_ndbcluster::index_end() { DBUG_ENTER("index_end"); - DBUG_RETURN(rnd_end()); + DBUG_RETURN(close_scan()); } @@ -1348,28 +1511,12 @@ int ha_ndbcluster::index_read(byte *buf, DBUG_ENTER("index_read"); DBUG_PRINT("enter", ("active_index: %u, key_len: %u, find_flag: %d", active_index, key_len, find_flag)); - - int error= 1; - statistic_increment(ha_read_key_count, &LOCK_status); - switch (get_index_type(active_index)){ - case PRIMARY_KEY_INDEX: - error= pk_read(key, key_len, buf); - break; - - case UNIQUE_INDEX: - error= unique_index_read(key, key_len, buf); - break; - - case ORDERED_INDEX: - error= ordered_index_scan(key, key_len, buf, find_flag); - break; - - default: - case UNDEFINED_INDEX: - break; - } - DBUG_RETURN(error); + key_range start_key; + start_key.key= key; + start_key.length= key_len; + start_key.flag= find_flag; + DBUG_RETURN(read_range_first(&start_key, NULL, false, true)); } @@ -1391,11 +1538,7 @@ int ha_ndbcluster::index_next(byte *buf) int error = 1; statistic_increment(ha_read_next_count,&LOCK_status); - if (get_index_type(active_index) == PRIMARY_KEY_INDEX) - error= HA_ERR_END_OF_FILE; - else - error = next_result(buf); - DBUG_RETURN(error); + DBUG_RETURN(next_result(buf)); } @@ -1423,6 +1566,62 @@ int ha_ndbcluster::index_last(byte *buf) } +int ha_ndbcluster::read_range_first(const key_range *start_key, + const key_range *end_key, + bool eq_range, bool sorted) +{ + KEY* key_info; + int error= 1; + byte* buf= table->record[0]; + DBUG_ENTER("ha_ndbcluster::read_range_first"); + DBUG_PRINT("info", ("eq_range: %d, sorted: %d", eq_range, sorted)); + + if (m_active_cursor) + close_scan(); + + switch (get_index_type(active_index)){ + case PRIMARY_KEY_ORDERED_INDEX: + case PRIMARY_KEY_INDEX: + key_info= table->key_info + active_index; + if (start_key && + start_key->length == key_info->key_length && + start_key->flag == HA_READ_KEY_EXACT) + { + error= pk_read(start_key->key, start_key->length, buf); + DBUG_RETURN(error == HA_ERR_KEY_NOT_FOUND ? HA_ERR_END_OF_FILE : error); + } + break; + case UNIQUE_ORDERED_INDEX: + case UNIQUE_INDEX: + key_info= table->key_info + active_index; + if (start_key && + start_key->length == key_info->key_length && + start_key->flag == HA_READ_KEY_EXACT) + { + error= unique_index_read(start_key->key, start_key->length, buf); + DBUG_RETURN(error == HA_ERR_KEY_NOT_FOUND ? HA_ERR_END_OF_FILE : error); + } + break; + default: + break; + } + + + // Start the ordered index scan and fetch the first row + error= ordered_index_scan(start_key, end_key, sorted, + buf); + + DBUG_RETURN(error); +} + + +int ha_ndbcluster::read_range_next() +{ + DBUG_ENTER("ha_ndbcluster::read_range_next"); + DBUG_RETURN(next_result(table->record[0])); +} + + int ha_ndbcluster::rnd_init(bool scan) { NdbResultSet *cursor= m_active_cursor; @@ -1435,19 +1634,23 @@ int ha_ndbcluster::rnd_init(bool scan) DBUG_RETURN(0); } +int ha_ndbcluster::close_scan() +{ + NdbResultSet *cursor= m_active_cursor; + DBUG_ENTER("close_scan"); + + if (!cursor) + DBUG_RETURN(1); + + cursor->close(); + m_active_cursor= NULL; + DBUG_RETURN(0); +} int ha_ndbcluster::rnd_end() { - NdbResultSet *cursor= m_active_cursor; DBUG_ENTER("rnd_end"); - - if (cursor) - { - DBUG_PRINT("info", ("Closing the cursor")); - cursor->close(); - m_active_cursor= NULL; - } - DBUG_RETURN(0); + DBUG_RETURN(close_scan()); } @@ -1455,12 +1658,10 @@ int ha_ndbcluster::rnd_next(byte *buf) { DBUG_ENTER("rnd_next"); statistic_increment(ha_read_rnd_next_count, &LOCK_status); - int error = 1; + if (!m_active_cursor) - error = full_table_scan(buf); - else - error = next_result(buf); - DBUG_RETURN(error); + DBUG_RETURN(full_table_scan(buf)); + DBUG_RETURN(next_result(buf)); } @@ -1654,6 +1855,7 @@ int ha_ndbcluster::extra(enum ha_extra_function operation) where field->query_id is the same as the current query id */ DBUG_PRINT("info", ("HA_EXTRA_RETRIEVE_ALL_COLS")); + retrieve_all_fields= TRUE; break; case HA_EXTRA_PREPARE_FOR_DELETE: DBUG_PRINT("info", ("HA_EXTRA_PREPARE_FOR_DELETE")); @@ -1679,6 +1881,53 @@ int ha_ndbcluster::extra(enum ha_extra_function operation) DBUG_RETURN(0); } +/* + Start of an insert, remember number of rows to be inserted, it will + be used in write_row and get_autoincrement to send an optimal number + of rows in each roundtrip to the server + + SYNOPSIS + rows number of rows to insert, 0 if unknown + +*/ + +void ha_ndbcluster::start_bulk_insert(ha_rows rows) +{ + int bytes, batch; + const NDBTAB *tab= (NDBTAB *) m_table; + + DBUG_ENTER("start_bulk_insert"); + DBUG_PRINT("enter", ("rows: %d", rows)); + + rows_inserted= 0; + rows_to_insert= rows; + + /* + Calculate how many rows that should be inserted + per roundtrip to NDB. This is done in order to minimize the + number of roundtrips as much as possible. However performance will + degrade if too many bytes are inserted, thus it's limited by this + calculation. + */ + const int bytesperbatch = 8192; + bytes= 12 + tab->getRowSizeInBytes() + 4 * tab->getNoOfColumns(); + batch= bytesperbatch/bytes; + batch= batch == 0 ? 1 : batch; + DBUG_PRINT("info", ("batch: %d, bytes: %d", batch, bytes)); + bulk_insert_rows= batch; + + DBUG_VOID_RETURN; +} + +/* + End of an insert + */ +int ha_ndbcluster::end_bulk_insert() +{ + DBUG_ENTER("end_bulk_insert"); + DBUG_RETURN(0); +} + int ha_ndbcluster::extra_opt(enum ha_extra_function operation, ulong cache_size) { @@ -1708,7 +1957,7 @@ const char **ha_ndbcluster::bas_ext() const double ha_ndbcluster::scan_time() { - return rows2double(records/3); + return rows2double(records*1000); } @@ -1740,6 +1989,8 @@ THR_LOCK_DATA **ha_ndbcluster::store_lock(THD *thd, m_lock.type=lock_type; } *to++= &m_lock; + + DBUG_PRINT("exit", ("lock_type: %d", lock_type)); DBUG_RETURN(to); } @@ -1788,6 +2039,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) if (lock_type != F_UNLCK) { + DBUG_PRINT("info", ("lock_type != F_UNLCK")); if (!thd->transaction.ndb_lock_count++) { PRINT_OPTION_FLAGS(thd); @@ -1853,10 +2105,14 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) (NdbConnection*)thd->transaction.all.ndb_tid: (NdbConnection*)thd->transaction.stmt.ndb_tid; DBUG_ASSERT(m_active_trans); - + + // Start of transaction + retrieve_all_fields= FALSE; + ops_pending= 0; } else { + DBUG_PRINT("info", ("lock_type == F_UNLCK")); if (!--thd->transaction.ndb_lock_count) { DBUG_PRINT("trans", ("Last external_lock")); @@ -1904,6 +2160,10 @@ int ha_ndbcluster::start_stmt(THD *thd) thd->transaction.stmt.ndb_tid= trans; } m_active_trans= trans; + + // Start of statement + retrieve_all_fields= FALSE; + ops_pending= 0; DBUG_RETURN(error); } @@ -2041,9 +2301,8 @@ int ha_ndbcluster::create(const char *name, NdbDictionary::Column::Type ndb_type; NDBCOL col; uint pack_length, length, i; - int res; const void *data, *pack_data; - const char **key_name= form->keynames.type_names; + const char **key_names= form->keynames.type_names; char name2[FN_HEADLEN]; DBUG_ENTER("create"); @@ -2086,13 +2345,11 @@ int ha_ndbcluster::create(const char *name, col.setPrimaryKey(field->flags & PRI_KEY_FLAG); if (field->flags & AUTO_INCREMENT_FLAG) { - DBUG_PRINT("info", ("Found auto_increment key")); col.setAutoIncrement(TRUE); - ulonglong value = info->auto_increment_value ? - info->auto_increment_value -1 : - (ulonglong) 0; - DBUG_PRINT("info", ("initial value=%ld", value)); -// col.setInitialAutIncValue(value); + ulonglong value= info->auto_increment_value ? + info->auto_increment_value -1 : (ulonglong) 0; + DBUG_PRINT("info", ("Autoincrement key, initial: %d", value)); + col.setAutoIncrementInitialValue(value); } else col.setAutoIncrement(false); @@ -2132,65 +2389,86 @@ int ha_ndbcluster::create(const char *name, DBUG_PRINT("info", ("Table %s/%s created successfully", m_dbname, m_tabname)); - // Fetch table from NDB, check that it exists - const NDBTAB *tab2= dict->getTable(m_tabname); - if (tab2 == NULL) - { - const NdbError err= dict->getNdbError(); - ERR_PRINT(err); - my_errno= ndb_to_mysql_error(&err); + if ((my_errno= build_index_list())) DBUG_RETURN(my_errno); - } // Create secondary indexes - for (i= 0; i < form->keys; i++) + KEY* key_info= form->key_info; + const char** key_name= key_names; + for (i= 0; i < form->keys; i++, key_info++, key_name++) { - DBUG_PRINT("info", ("Found index %u: %s", i, key_name[i])); - if (i == form->primary_key) - { - DBUG_PRINT("info", ("Skipping it, PK already created")); - continue; - } - - DBUG_PRINT("info", ("Creating index %u: %s", i, key_name[i])); - res= create_index(key_name[i], - form->key_info + i); - switch(res){ - case 0: - // OK + int error= 0; + DBUG_PRINT("info", ("Index %u: %s", i, *key_name)); + + switch (get_index_type_from_table(i)){ + + case PRIMARY_KEY_INDEX: + // Do nothing, already created + break; + case PRIMARY_KEY_ORDERED_INDEX: + error= create_ordered_index(*key_name, key_info); + break; + case UNIQUE_ORDERED_INDEX: + if (!(error= create_ordered_index(*key_name, key_info))) + error= create_unique_index(get_unique_index_name(i), key_info); + break; + case UNIQUE_INDEX: + error= create_unique_index(get_unique_index_name(i), key_info); + break; + case ORDERED_INDEX: + error= create_ordered_index(*key_name, key_info); break; default: + DBUG_ASSERT(false); + break; + } + + if (error) + { DBUG_PRINT("error", ("Failed to create index %u", i)); drop_table(); - my_errno= res; - goto err_end; + my_errno= error; + break; } } -err_end: DBUG_RETURN(my_errno); } +int ha_ndbcluster::create_ordered_index(const char *name, + KEY *key_info) +{ + DBUG_ENTER("create_ordered_index"); + DBUG_RETURN(create_index(name, key_info, false)); +} + +int ha_ndbcluster::create_unique_index(const char *name, + KEY *key_info) +{ + + DBUG_ENTER("create_unique_index"); + DBUG_RETURN(create_index(name, key_info, true)); +} + + /* Create an index in NDB Cluster */ int ha_ndbcluster::create_index(const char *name, - KEY *key_info){ + KEY *key_info, + bool unique) +{ NdbDictionary::Dictionary *dict= m_ndb->getDictionary(); KEY_PART_INFO *key_part= key_info->key_part; KEY_PART_INFO *end= key_part + key_info->key_parts; DBUG_ENTER("create_index"); DBUG_PRINT("enter", ("name: %s ", name)); - - // Check that an index with the same name do not already exist - if (dict->getIndex(name, m_tabname)) - ERR_RETURN(dict->getNdbError()); - + NdbDictionary::Index ndb_index(name); - if (key_info->flags & HA_NOSAME) + if (unique) ndb_index.setType(NdbDictionary::Index::UniqueHashIndex); else { @@ -2321,10 +2599,10 @@ int ndbcluster_drop_database(const char *path) longlong ha_ndbcluster::get_auto_increment() -{ - // NOTE If number of values to be inserted is known - // the autoincrement cache could be used here - Uint64 auto_value= m_ndb->getAutoIncrementValue(m_tabname); +{ + int cache_size = rows_to_insert ? rows_to_insert : 32; + Uint64 auto_value= + m_ndb->getAutoIncrementValue(m_tabname, cache_size); return (longlong)auto_value; } @@ -2340,16 +2618,18 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): m_ndb(NULL), m_table(NULL), m_table_flags(HA_REC_NOT_IN_SEQ | - HA_KEYPOS_TO_RNDPOS | HA_NOT_EXACT_COUNT | - HA_NO_WRITE_DELAYED | HA_NO_PREFIX_CHAR_KEYS | - HA_NO_BLOBS | - HA_DROP_BEFORE_CREATE | - HA_NOT_READ_AFTER_KEY), - m_use_write(false) + HA_NO_BLOBS), + m_use_write(false), + retrieve_all_fields(FALSE), + rows_to_insert(0), + rows_inserted(0), + bulk_insert_rows(1024), + ops_pending(0) { - + int i; + DBUG_ENTER("ha_ndbcluster"); m_tabname[0]= '\0'; @@ -2360,6 +2640,12 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): records= 100; block_size= 1024; + for (i= 0; i < MAX_KEY; i++) + { + m_indextype[i]= UNDEFINED_INDEX; + m_unique_index_name[i]= NULL; + } + DBUG_VOID_RETURN; } @@ -2445,7 +2731,7 @@ Ndb* ha_ndbcluster::seize_ndb() #else ndb= new Ndb(""); #endif - if (ndb->init(NDB_MAX_TRANSACTIONS) != 0) + if (ndb->init(max_transactions) != 0) { ERR_PRINT(ndb->getNdbError()); /* @@ -2500,11 +2786,6 @@ int ha_ndbcluster::check_ndb_connection() } m_ndb= (Ndb*)thd->transaction.ndb; m_ndb->setDatabaseName(m_dbname); - if (m_ndb->waitUntilReady() != 0) - { - DBUG_PRINT("error", ("Ndb was not ready")); - DBUG_RETURN(3); - } DBUG_RETURN(0); } @@ -2561,7 +2842,6 @@ int ndbcluster_discover(const char *dbname, const char *name, DBUG_RETURN(0); } -static Ndb* g_ndb= NULL; #ifdef USE_DISCOVER_ON_STARTUP /* @@ -2653,6 +2933,14 @@ bool ndbcluster_end() DBUG_RETURN(0); } +void ndbcluster_print_error(int error) +{ + DBUG_ENTER("ndbcluster_print_error"); + TABLE tab; + tab.table_name = NULL; + ha_ndbcluster error_handler(&tab); + error_handler.print_error(error, MYF(0)); +} /* Set m_tabname from full pathname to table file @@ -2751,32 +3039,27 @@ ha_rows ha_ndbcluster::records_in_range(uint inx, key_range *min_key, key_range *max_key) { - ha_rows records= 10; /* Good guess when you don't know anything */ KEY *key_info= table->key_info + inx; uint key_length= key_info->key_length; + NDB_INDEX_TYPE idx_type= get_index_type(inx); DBUG_ENTER("records_in_range"); DBUG_PRINT("enter", ("inx: %u", inx)); - DBUG_DUMP("start_key", min_key->key, min_key->length); - DBUG_DUMP("end_key", max_key->key, max_key->length); - DBUG_PRINT("enter", ("start_search_flag: %u end_search_flag: %u", - min_key->flag, max_key->flag)); - /* - Check that start_key_len is equal to - the length of the used index and - prevent partial scan/read of hash indexes by returning HA_POS_ERROR - */ - NDB_INDEX_TYPE idx_type= get_index_type(inx); - if ((idx_type == UNIQUE_INDEX || idx_type == PRIMARY_KEY_INDEX) && - min_key->length < key_length) - { - DBUG_PRINT("warning", ("Tried to use index which required" - "full key length: %d, HA_POS_ERROR", - key_length)); - records= HA_POS_ERROR; - } - DBUG_RETURN(records); + // Prevent partial read of hash indexes by returning HA_POS_ERROR + if ((idx_type == UNIQUE_INDEX || idx_type == PRIMARY_KEY_INDEX) && + ((min_key && min_key->length < key_length) || + (max_key && max_key->length < key_length))) + DBUG_RETURN(HA_POS_ERROR); + + // Read from hash index with full key + // This is a "const" table which returns only one record! + if ((idx_type != ORDERED_INDEX) && + ((min_key && min_key->length == key_length) || + (max_key && max_key->length == key_length))) + DBUG_RETURN(1); + + DBUG_RETURN(10); /* Good guess when you don't know anything */ } diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 029ebc11e46..39c1779a27a 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -37,8 +37,10 @@ class NdbResultSet; // Forward declaration typedef enum ndb_index_type { UNDEFINED_INDEX = 0, PRIMARY_KEY_INDEX = 1, - UNIQUE_INDEX = 2, - ORDERED_INDEX = 3 + PRIMARY_KEY_ORDERED_INDEX = 2, + UNIQUE_INDEX = 3, + UNIQUE_ORDERED_INDEX = 4, + ORDERED_INDEX = 5 } NDB_INDEX_TYPE; @@ -71,12 +73,17 @@ class ha_ndbcluster: public handler int index_prev(byte *buf); int index_first(byte *buf); int index_last(byte *buf); - int rnd_init(bool scan=1); + int rnd_init(bool scan); int rnd_end(); int rnd_next(byte *buf); int rnd_pos(byte *buf, byte *pos); void position(const byte *record); + int read_range_first(const key_range *start_key, + const key_range *end_key, + bool eq_range, bool sorted); + int read_range_next(); + bool get_error_message(int error, String *buf); void info(uint); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); @@ -86,11 +93,12 @@ class ha_ndbcluster: public handler const char * table_type() const { return("ndbcluster");} const char ** bas_ext() const; ulong table_flags(void) const { return m_table_flags; } - ulong index_flags(uint idx) const; - uint max_record_length() const { return NDB_MAX_TUPLE_SIZE; }; - uint max_keys() const { return MAX_KEY; } - uint max_key_parts() const { return NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY; }; - uint max_key_length() const { return NDB_MAX_KEY_SIZE;}; + ulong index_flags(uint idx, uint part) const; + uint max_supported_record_length() const { return NDB_MAX_TUPLE_SIZE; }; + uint max_supported_keys() const { return MAX_KEY; } + uint max_supported_key_parts() const + { return NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY; }; + uint max_supported_key_length() const { return NDB_MAX_KEY_SIZE;}; int rename_table(const char *from, const char *to); int delete_table(const char *name); @@ -112,6 +120,8 @@ class ha_ndbcluster: public handler const char* index_type(uint key_number) { switch (get_index_type(key_number)) { case ORDERED_INDEX: + case UNIQUE_ORDERED_INDEX: + case PRIMARY_KEY_ORDERED_INDEX: return "BTREE"; case UNIQUE_INDEX: case PRIMARY_KEY_INDEX: @@ -122,6 +132,8 @@ class ha_ndbcluster: public handler double scan_time(); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); + void start_bulk_insert(ha_rows rows); + int end_bulk_insert(); static Ndb* seize_ndb(); static void release_ndb(Ndb* ndb); @@ -130,11 +142,15 @@ class ha_ndbcluster: public handler private: int alter_table_name(const char *from, const char *to); int drop_table(); - int create_index(const char *name, KEY *key_info); + int create_index(const char *name, KEY *key_info, bool unique); + int create_ordered_index(const char *name, KEY *key_info); + int create_unique_index(const char *name, KEY *key_info); int initialize_autoincrement(const void* table); + int build_index_list(); int get_metadata(const char* path); void release_metadata(); const char* get_index_name(uint idx_no) const; + const char* get_unique_index_name(uint idx_no) const; NDB_INDEX_TYPE get_index_type(uint idx_no) const; NDB_INDEX_TYPE get_index_type_from_table(uint index_no) const; @@ -142,17 +158,16 @@ class ha_ndbcluster: public handler byte *buf); int unique_index_read(const byte *key, uint key_len, byte *buf); - int ordered_index_scan(const byte *key, uint key_len, - byte *buf, - enum ha_rkey_function find_flag); + int ordered_index_scan(const key_range *start_key, + const key_range *end_key, + bool sorted, byte* buf); int full_table_scan(byte * buf); int next_result(byte *buf); -#if 0 + int define_read_attrs(byte* buf, NdbOperation* op); int filtered_scan(const byte *key, uint key_len, byte *buf, enum ha_rkey_function find_flag); -#endif - + int close_scan(); void unpack_record(byte *buf); void set_dbname(const char *pathname); @@ -167,6 +182,9 @@ class ha_ndbcluster: public handler int get_ndb_value(NdbOperation*, uint fieldnr, byte *field_ptr); int set_primary_key(NdbOperation *op, const byte *key); int set_primary_key(NdbOperation *op); + int set_primary_key_from_old_data(NdbOperation *op, const byte *old_data); + int set_bounds(NdbOperation *ndb_op, const key_range *key, + int bound); int key_cmp(uint keynr, const byte * old_row, const byte * new_row); void print_results(); @@ -188,8 +206,14 @@ class ha_ndbcluster: public handler THR_LOCK_DATA m_lock; NDB_SHARE *m_share; NDB_INDEX_TYPE m_indextype[MAX_KEY]; + const char* m_unique_index_name[MAX_KEY]; NdbRecAttr *m_value[NDB_MAX_ATTRIBUTES_IN_TABLE]; bool m_use_write; + bool retrieve_all_fields; + ha_rows rows_to_insert; + ha_rows rows_inserted; + ha_rows bulk_insert_rows; + ha_rows ops_pending; }; bool ndbcluster_init(void); @@ -204,6 +228,7 @@ int ndbcluster_discover(const char* dbname, const char* name, const void** frmblob, uint* frmlen); int ndbcluster_drop_database(const char* path); +void ndbcluster_print_error(int error); diff --git a/sql/handler.cc b/sql/handler.cc index 079ff5ba687..017b9d9d4c8 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -35,10 +35,11 @@ #ifdef HAVE_EXAMPLE_DB #include "examples/ha_example.h" #endif +#ifdef HAVE_ARCHIVE_DB +#include "examples/ha_archive.h" +#endif #ifdef HAVE_INNOBASE_DB #include "ha_innodb.h" -#else -#define innobase_query_caching_of_table_permitted(X,Y,Z) 1 #endif #ifdef HAVE_NDBCLUSTER_DB #include "ha_ndbcluster.h" @@ -88,6 +89,8 @@ struct show_table_type_st sys_table_types[]= "Alias for NDBCLUSTER", DB_TYPE_NDBCLUSTER}, {"EXAMPLE",&have_example_db, "Example storage engine", DB_TYPE_EXAMPLE_DB}, + {"ARCHIVE",&have_archive_db, + "Archive storage engine", DB_TYPE_ARCHIVE_DB}, {NullS, NULL, NullS, DB_TYPE_UNKNOWN} }; @@ -189,6 +192,10 @@ handler *get_new_handler(TABLE *table, enum db_type db_type) case DB_TYPE_EXAMPLE_DB: return new ha_example(table); #endif +#ifdef HAVE_ARCHIVE_DB + case DB_TYPE_ARCHIVE_DB: + return new ha_archive(table); +#endif #ifdef HAVE_NDBCLUSTER_DB case DB_TYPE_NDBCLUSTER: return new ha_ndbcluster(table); @@ -210,6 +217,16 @@ handler *get_new_handler(TABLE *table, enum db_type db_type) } } +bool ha_caching_allowed(THD* thd, char* table_key, + uint key_length, uint8 cache_type) +{ +#ifdef HAVE_INNOBASE_DB + if (cache_type == HA_CACHE_TBL_ASKTRANSACT) + return innobase_query_caching_of_table_permitted(thd, table_key, key_length); +#endif + return 1; +} + int ha_init() { int error= 0; @@ -366,17 +383,25 @@ int ha_report_binlog_offset_and_commit(THD *thd, #ifdef HAVE_INNOBASE_DB THD_TRANS *trans; trans = &thd->transaction.all; - if (trans->innobase_tid) + if (trans->innodb_active_trans) { + /* + If we updated some InnoDB tables (innodb_active_trans is true), the + binlog coords will be reported into InnoDB during the InnoDB commit + (innobase_report_binlog_offset_and_commit). But if we updated only + non-InnoDB tables, we need an explicit call to report it. + */ if ((error=innobase_report_binlog_offset_and_commit(thd, - trans->innobase_tid, - log_file_name, - end_offset))) + trans->innobase_tid, + log_file_name, + end_offset))) { my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); error=1; } } + else if (opt_innodb_safe_binlog) // Don't report if not useful + innobase_store_binlog_offset_and_flush_log(log_file_name, end_offset); #endif return error; } @@ -469,7 +494,10 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) { if ((error=ndbcluster_commit(thd,trans->ndb_tid))) { - my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); + if (error == -1) + my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); + else + ndbcluster_print_error(error); error=1; } if (trans == &thd->transaction.all) @@ -535,7 +563,10 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) { if ((error=ndbcluster_rollback(thd, trans->ndb_tid))) { - my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); + if (error == -1) + my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); + else + ndbcluster_print_error(error); error=1; } trans->ndb_tid = 0; @@ -569,10 +600,11 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) if ((trans == &thd->transaction.all) && mysql_bin_log.is_open()) { /* - Update the binary log with a BEGIN/ROLLBACK block if we have cached some - queries and we updated some non-transactional table. Such cases should - be rare (updating a non-transactional table inside a transaction...). - Count disk writes to trans_log in any case. + Update the binary log with a BEGIN/ROLLBACK block if we have + cached some queries and we updated some non-transactional + table. Such cases should be rare (updating a + non-transactional table inside a transaction...). Count disk + writes to trans_log in any case. */ if (my_b_tell(&thd->transaction.trans_log)) { @@ -593,13 +625,12 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) reinit_io_cache(&thd->transaction.trans_log, WRITE_CACHE, (my_off_t) 0, 0, 1); thd->transaction.trans_log.end_of_file= max_binlog_cache_size; + if (operation_done) + thd->transaction.cleanup(); } thd->variables.tx_isolation=thd->session_tx_isolation; if (operation_done) - { statistic_increment(ha_rollback_count,&LOCK_status); - thd->transaction.cleanup(); - } } #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); @@ -617,12 +648,12 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) simply truncate the binlog cache, we lose the part of the binlog cache where the update is. If we want to not lose it, we need to write the SAVEPOINT command and the ROLLBACK TO SAVEPOINT command to the binlog cache. The latter - is easy: it's just write at the end of the binlog cache, but the former should - be *inserted* to the place where the user called SAVEPOINT. The solution is - that when the user calls SAVEPOINT, we write it to the binlog cache (so no - need to later insert it). As transactions are never intermixed in the binary log - (i.e. they are serialized), we won't have conflicts with savepoint names when - using mysqlbinlog or in the slave SQL thread. + is easy: it's just write at the end of the binlog cache, but the former + should be *inserted* to the place where the user called SAVEPOINT. The + solution is that when the user calls SAVEPOINT, we write it to the binlog + cache (so no need to later insert it). As transactions are never intermixed + in the binary log (i.e. they are serialized), we won't have conflicts with + savepoint names when using mysqlbinlog or in the slave SQL thread. Then when ROLLBACK TO SAVEPOINT is called, if we updated some non-transactional table, we don't truncate the binlog cache but instead write ROLLBACK TO SAVEPOINT to it; otherwise we truncate the binlog cache (which @@ -856,46 +887,6 @@ int handler::ha_open(const char *name, int mode, int test_if_locked) DBUG_RETURN(error); } -int handler::check(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::backup(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::restore(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::repair(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::optimize(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::analyze(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - -int handler::preload_keys(THD* thd, HA_CHECK_OPT* check_opt) -{ - return HA_ADMIN_NOT_IMPLEMENTED; -} - /* Read first row (only) from a table This is never called for InnoDB or BDB tables, as these table types @@ -913,35 +904,23 @@ int handler::read_first_row(byte * buf, uint primary_key) If there is very few deleted rows in the table, find the first row by scanning the table. */ - if (deleted < 10 || primary_key >= MAX_KEY || - !(index_flags(primary_key) & HA_READ_ORDER)) + if (deleted < 10 || primary_key >= MAX_KEY) { - (void) rnd_init(); + (void) ha_rnd_init(1); while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ; - (void) rnd_end(); + (void) ha_rnd_end(); } else { /* Find the first row through the primary key */ - (void) index_init(primary_key); + (void) ha_index_init(primary_key); error=index_first(buf); - (void) index_end(); + (void) ha_index_end(); } DBUG_RETURN(error); } -/* - The following function is only needed for tables that may be temporary tables - during joins -*/ - -int handler::restart_rnd_next(byte *buf, byte *pos) -{ - return HA_ERR_WRONG_COMMAND; -} - - /* Set a timestamp in record */ void handler::update_timestamp(byte *record) @@ -1121,7 +1100,21 @@ void handler::print_error(int error, myf errflag) break; default: { - my_error(ER_GET_ERRNO,errflag,error); + /* The error was "unknown" to this function. + Ask handler if it has got a message for this error */ + bool temporary= FALSE; + String str; + temporary= get_error_message(error, &str); + if (!str.is_empty()) + { + const char* engine= table_type(); + if (temporary) + my_error(ER_GET_TEMPORARY_ERRMSG,MYF(0),error,str.ptr(),engine); + else + my_error(ER_GET_ERRMSG,MYF(0),error,str.ptr(),engine); + } + else + my_error(ER_GET_ERRNO,errflag,error); DBUG_VOID_RETURN; } } @@ -1130,6 +1123,22 @@ void handler::print_error(int error, myf errflag) } +/* + Return an error message specific to this handler + + SYNOPSIS + error error code previously returned by handler + buf Pointer to String where to add error message + + Returns true if this is a temporary error + */ + +bool handler::get_error_message(int error, String* buf) +{ + return FALSE; +} + + /* Return key if error because of duplicated keys */ uint handler::get_dup_key(int error) @@ -1195,30 +1204,6 @@ int handler::index_next_same(byte *buf, const byte *key, uint keylen) } -/* - This is called to delete all rows in a table - If the handler don't support this, then this function will - return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one - by one. -*/ - -int handler::delete_all_rows() -{ - return (my_errno=HA_ERR_WRONG_COMMAND); -} - -bool handler::caching_allowed(THD* thd, char* table_key, - uint key_length, uint8 cache_type) -{ -#ifdef HAVE_INNOBASE_DB - if (cache_type == HA_CACHE_TBL_ASKTRANSACT) - return innobase_query_caching_of_table_permitted(thd, table_key, - key_length); - else -#endif - return 1; -} - /**************************************************************************** ** Some general functions that isn't in the handler class ****************************************************************************/ @@ -1241,8 +1226,6 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, if (update_create_info) { update_create_info_from_table(create_info, &table); - if (table.file->table_flags() & HA_DROP_BEFORE_CREATE) - table.file->delete_table(name); } if (lower_case_table_names == 2 && !(table.file->table_flags() & HA_FILE_BASED)) @@ -1499,3 +1482,15 @@ int handler::compare_key(key_range *range) cmp= key_compare_result_on_equal; return cmp; } + +int handler::index_read_idx(byte * buf, uint index, const byte * key, + uint key_len, enum ha_rkey_function find_flag) +{ + int error= ha_index_init(index); + if (!error) + error= index_read(buf, key, key_len, find_flag); + if (!error) + error= ha_index_end(); + return error; +} + diff --git a/sql/handler.h b/sql/handler.h index 8cc5921eacb..13874fa6bb0 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -43,53 +43,45 @@ #define HA_ADMIN_INTERNAL_ERROR -4 #define HA_ADMIN_INVALID -5 #define HA_ADMIN_REJECT -6 +#define HA_ADMIN_TRY_ALTER -7 /* Bits in table_flags() to show what database can do */ -#define HA_READ_RND_SAME 1 /* Read RND-record to KEY-record - (To update with RND-read) */ -#define HA_KEYPOS_TO_RNDPOS 2 /* ha_info gives pos to record */ -#define HA_TABLE_SCAN_ON_INDEX 4 /* No separate data/index file */ -#define HA_REC_NOT_IN_SEQ 8 /* ha_info don't return recnumber; +#define HA_READ_RND_SAME (1 << 0) /* can switch index during the scan + with ::rnd_same() - not used yet. + see mi_rsame/heap_rsame/myrg_rsame */ +#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */ +#define HA_REC_NOT_IN_SEQ (1 << 3) /* ha_info don't return recnumber; It returns a position to ha_r_rnd */ -#define HA_HAS_GEOMETRY (1 << 4) +#define HA_CAN_GEOMETRY (1 << 4) #define HA_FAST_KEY_READ (1 << 5) /* no need for a record cache in filesort */ -#define HA_KEY_READ_WRONG_STR (1 << 6) /* keyread returns converted strings */ -#define HA_NULL_KEY (1 << 7) /* One can have keys with NULL */ -#define HA_DUPP_POS (1 << 8) /* ha_position() gives dupp row */ +#define HA_NULL_IN_KEY (1 << 7) /* One can have keys with NULL */ +#define HA_DUPP_POS (1 << 8) /* ha_position() gives dup row */ #define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */ -#define HA_BLOB_KEY (1 << 10) /* key on blob */ -#define HA_AUTO_PART_KEY (1 << 11) -#define HA_REQUIRE_PRIMARY_KEY (1 << 12) +#define HA_CAN_INDEX_BLOBS (1 << 10) +#define HA_AUTO_PART_KEY (1 << 11) /* auto-increment in multi-part key */ +#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */ #define HA_NOT_EXACT_COUNT (1 << 13) -#define HA_NO_WRITE_DELAYED (1 << 14) +#define HA_CAN_INSERT_DELAYED (1 << 14) /* only handlers with table-level locks + need no special code to support + INSERT DELAYED */ #define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15) -#define HA_DROP_BEFORE_CREATE (1 << 16) -#define HA_NOT_READ_AFTER_KEY (1 << 17) #define HA_NOT_DELETE_WITH_CACHE (1 << 18) -#define HA_NO_TEMP_TABLES (1 << 19) #define HA_NO_PREFIX_CHAR_KEYS (1 << 20) #define HA_CAN_FULLTEXT (1 << 21) #define HA_CAN_SQL_HANDLER (1 << 22) #define HA_NO_AUTO_INCREMENT (1 << 23) #define HA_HAS_CHECKSUM (1 << 24) -/* - Next record gives next record according last record read (even - if database is updated after read). Not used at this point. -*/ -#define HA_LASTKEY_ORDER (1 << 25) -/* Table data are stored in separate files */ +/* Table data are stored in separate files (for lower_case_table_names) */ #define HA_FILE_BASED (1 << 26) /* bits in index_flags(index_number) for what you can do with index */ -#define HA_WRONG_ASCII_ORDER 1 /* Can't use sorting through key */ -#define HA_READ_NEXT 2 /* Read next record with same key */ -#define HA_READ_PREV 4 /* Read prev. record with same key */ -#define HA_READ_ORDER 8 /* Read through record-keys in order */ +#define HA_READ_NEXT 1 /* TODO really use this flag */ +#define HA_READ_PREV 2 /* supports ::index_prev */ +#define HA_READ_ORDER 4 /* index_next/prev follow sort order */ +#define HA_READ_RANGE 8 /* can find all records in a range */ #define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */ -#define HA_NOT_READ_PREFIX_LAST 32 /* No support for index_read_last() */ -#define HA_KEY_READ_ONLY 64 /* Support HA_EXTRA_KEYREAD */ - +#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */ /* operations for disable/enable indexes */ #define HA_KEY_SWITCH_NONUNIQ 0 @@ -108,9 +100,6 @@ #define HA_DDL_WITH_LOCK 2 /* Can create/drop with locked table */ #define HA_DDL_ONLINE 4 /* Can create/drop without lock */ -/* Return value for ddl methods */ -#define HA_DDL_NOT_IMPLEMENTED -1 - /* Parameters for open() (in register form->filestat) HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED @@ -158,7 +147,7 @@ enum db_type DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM, DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB, DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER, - DB_TYPE_EXAMPLE_DB, + DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_DEFAULT // Must be last }; @@ -239,6 +228,18 @@ class handler :public Sql_alloc protected: struct st_table *table; /* The table definition */ + virtual int index_init(uint idx) { active_index=idx; return 0; } + virtual int index_end() { active_index=MAX_KEY; return 0; } + /* + rnd_init() can be called two times without rnd_end() in between + (it only makes sense if scan=1). + then the second call should prepare for the new table scan (e.g + if rnd_init allocates the cursor, second call should position it + to the start of the table, no need to deallocate and allocate it again + */ + virtual int rnd_init(bool scan) =0; + virtual int rnd_end() { return 0; } + public: byte *ref; /* Pointer to current row */ byte *dupp_ref; /* Pointer to dupp row */ @@ -270,6 +271,7 @@ public: uint block_size; /* index block size */ uint raid_type,raid_chunks; FT_INFO *ft_handler; + enum {NONE=0, INDEX, RND} inited; bool auto_increment_column_changed; bool implicit_emptied; /* Can be !=0 only if HEAP */ @@ -279,15 +281,16 @@ public: delete_length(0), auto_increment_value(0), records(0), deleted(0), mean_rec_length(0), create_time(0), check_time(0), update_time(0), - key_used_on_scan(MAX_KEY), active_index(MAX_REF_PARTS), + key_used_on_scan(MAX_KEY), active_index(MAX_KEY), ref_length(sizeof(my_off_t)), block_size(0), - raid_type(0), ft_handler(0), implicit_emptied(0) + raid_type(0), ft_handler(0), inited(NONE), implicit_emptied(0) {} - virtual ~handler(void) {} + virtual ~handler(void) { /* TODO: DBUG_ASSERT(inited == NONE); */ } int ha_open(const char *name, int mode, int test_if_locked); void update_timestamp(byte *record); void update_auto_increment(); virtual void print_error(int error, myf errflag); + virtual bool get_error_message(int error, String *buf); uint get_dup_key(int error); void change_table_ptr(TABLE *table_arg) { table=table_arg; } virtual double scan_time() @@ -298,88 +301,140 @@ public: virtual bool has_transactions(){ return 0;} virtual uint extra_rec_buf_length() { return 0; } virtual ha_rows estimate_number_of_rows() { return records+EXTRA_RECORDS; } - virtual const char *index_type(uint key_number) { return "";} - virtual int index_init(uint idx) { active_index=idx; return 0;} - virtual int index_end() {return 0; } + virtual const char *index_type(uint key_number) { DBUG_ASSERT(0); return "";} + + int ha_index_init(uint idx) + { + DBUG_ASSERT(inited==NONE); + inited=INDEX; + return index_init(idx); + } + int ha_index_end() + { + DBUG_ASSERT(inited==INDEX); + inited=NONE; + return index_end(); + } + int ha_rnd_init(bool scan) + { + DBUG_ASSERT(inited==NONE || (inited==RND && scan)); + inited=RND; + return rnd_init(scan); + } + int ha_rnd_end() + { + DBUG_ASSERT(inited==RND); + inited=NONE; + return rnd_end(); + } + /* this is neseccary in many places, e.g. in HANDLER command */ + int ha_index_or_rnd_end() + { + return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0; + } uint get_index(void) const { return active_index; } virtual int open(const char *name, int mode, uint test_if_locked)=0; - virtual void initialize(void) {} virtual int close(void)=0; - virtual int write_row(byte * buf)=0; - virtual int update_row(const byte * old_data, byte * new_data)=0; - virtual int delete_row(const byte * buf)=0; + virtual int write_row(byte * buf) { return HA_ERR_WRONG_COMMAND; } + virtual int update_row(const byte * old_data, byte * new_data) + { return HA_ERR_WRONG_COMMAND; } + virtual int delete_row(const byte * buf) + { return HA_ERR_WRONG_COMMAND; } virtual int index_read(byte * buf, const byte * key, - uint key_len, enum ha_rkey_function find_flag)=0; + uint key_len, enum ha_rkey_function find_flag) + { return HA_ERR_WRONG_COMMAND; } virtual int index_read_idx(byte * buf, uint index, const byte * key, - uint key_len, enum ha_rkey_function find_flag)=0; - virtual int index_next(byte * buf)=0; - virtual int index_prev(byte * buf)=0; - virtual int index_first(byte * buf)=0; - virtual int index_last(byte * buf)=0; + uint key_len, enum ha_rkey_function find_flag); + virtual int index_next(byte * buf) + { return HA_ERR_WRONG_COMMAND; } + virtual int index_prev(byte * buf) + { return HA_ERR_WRONG_COMMAND; } + virtual int index_first(byte * buf) + { return HA_ERR_WRONG_COMMAND; } + virtual int index_last(byte * buf) + { return HA_ERR_WRONG_COMMAND; } virtual int index_next_same(byte *buf, const byte *key, uint keylen); virtual int index_read_last(byte * buf, const byte * key, uint key_len) - { - return (my_errno=HA_ERR_WRONG_COMMAND); - } + { return (my_errno=HA_ERR_WRONG_COMMAND); } virtual int read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range, bool sorted); virtual int read_range_next(); int compare_key(key_range *range); - virtual int ft_init() - { return -1; } + virtual int ft_init() { return HA_ERR_WRONG_COMMAND; } virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key, uint keylen) { return NULL; } - virtual int ft_read(byte *buf) { return -1; } - virtual int rnd_init(bool scan=1)=0; - virtual int rnd_end() { return 0; } + virtual int ft_read(byte *buf) { return HA_ERR_WRONG_COMMAND; } virtual int rnd_next(byte *buf)=0; virtual int rnd_pos(byte * buf, byte *pos)=0; virtual int read_first_row(byte *buf, uint primary_key); - virtual int restart_rnd_next(byte *buf, byte *pos); + /* + The following function is only needed for tables that may be temporary + tables during joins + */ + virtual int restart_rnd_next(byte *buf, byte *pos) + { return HA_ERR_WRONG_COMMAND; } + virtual int rnd_same(byte *buf, uint inx) + { return HA_ERR_WRONG_COMMAND; } virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key) { return (ha_rows) 10; } virtual void position(const byte *record)=0; - virtual my_off_t row_position() { return HA_OFFSET_ERROR; } virtual void info(uint)=0; - virtual int extra(enum ha_extra_function operation)=0; + virtual int extra(enum ha_extra_function operation) + { return 0; } virtual int extra_opt(enum ha_extra_function operation, ulong cache_size) - { - return extra(operation); - } + { return extra(operation); } virtual int reset() { return extra(HA_EXTRA_RESET); } virtual int external_lock(THD *thd, int lock_type)=0; virtual void unlock_row() {} virtual int start_stmt(THD *thd) {return 0;} - virtual int delete_all_rows(); + /* + This is called to delete all rows in a table + If the handler don't support this, then this function will + return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one + by one. + */ + virtual int delete_all_rows() + { return (my_errno=HA_ERR_WRONG_COMMAND); } virtual longlong get_auto_increment(); virtual void update_create_info(HA_CREATE_INFO *create_info) {} - virtual int check(THD* thd, HA_CHECK_OPT* check_opt ); - virtual int repair(THD* thd, HA_CHECK_OPT* check_opt); - virtual bool check_and_repair(THD *thd) {return 1;} - virtual int optimize(THD* thd,HA_CHECK_OPT* check_opt); - virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt); - virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt); - virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt); - virtual int backup(THD* thd, HA_CHECK_OPT* check_opt); + + /* admin commands - called from mysql_admin_table */ + virtual int check(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int backup(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } /* restore assumes .frm file must exist, and that generate_table() has been called; It will just copy the data file and run repair. */ - virtual int restore(THD* thd, HA_CHECK_OPT* check_opt); - virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; } + virtual int restore(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int repair(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt) + { return HA_ADMIN_NOT_IMPLEMENTED; } + /* end of the list of admin commands */ + + virtual bool check_and_repair(THD *thd) { return HA_ERR_WRONG_COMMAND; } + virtual int dump(THD* thd, int fd = -1) { return HA_ERR_WRONG_COMMAND; } virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int indexes_are_disabled(void) {return 0;} virtual void start_bulk_insert(ha_rows rows) {} virtual int end_bulk_insert() {return 0; } - virtual int discard_or_import_tablespace(my_bool discard) {return -1;} - // not implemented by default - virtual int net_read_dump(NET* net) - { return ER_DUMP_NOT_IMPLEMENTED; } + virtual int discard_or_import_tablespace(my_bool discard) + {return HA_ERR_WRONG_COMMAND;} + virtual int net_read_dump(NET* net) { return HA_ERR_WRONG_COMMAND; } virtual char *update_table_comment(const char * comment) { return (char*) comment;} virtual void append_create_info(String *packet) {} @@ -394,38 +449,47 @@ public: virtual const char *table_type() const =0; virtual const char **bas_ext() const =0; virtual ulong table_flags(void) const =0; - virtual ulong index_flags(uint idx) const - { - return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_KEY_READ_ONLY); - } + virtual ulong index_flags(uint idx, uint part=~0) const =0; virtual ulong index_ddl_flags(KEY *wanted_index) const - { - return (HA_DDL_SUPPORT); - } - virtual int add_index(TABLE *table, KEY *key_info, uint num_of_keys) - { - my_error(ER_NOT_SUPPORTED_YET, MYF(0), "online add index"); - return (HA_DDL_NOT_IMPLEMENTED); - } - virtual int drop_index(TABLE *table, uint *key_num, uint num_of_keys) - { - my_error(ER_NOT_SUPPORTED_YET, MYF(0), "online drop index"); - return (HA_DDL_NOT_IMPLEMENTED); - } - virtual uint max_record_length() const =0; - virtual uint max_keys() const =0; - virtual uint max_key_parts() const =0; - virtual uint max_key_length()const =0; - virtual uint max_key_part_length() { return 255; } + { return (HA_DDL_SUPPORT); } + virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) + { return (HA_ERR_WRONG_COMMAND); } + virtual int drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys) + { return (HA_ERR_WRONG_COMMAND); } + + uint max_record_length() const + { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); } + uint max_keys() const + { return min(MAX_KEY, max_supported_keys()); } + uint max_key_parts() const + { return min(MAX_REF_PARTS, max_supported_key_parts()); } + uint max_key_length() const + { return min(MAX_KEY_LENGTH, max_supported_key_length()); } + uint max_key_part_length() const + { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); } + + virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; } + virtual uint max_supported_keys() const { return 0; } + virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; } + virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; } + virtual uint max_supported_key_part_length() const { return 255; } virtual uint min_record_length(uint options) const { return 1; } + virtual bool low_byte_first() const { return 1; } virtual uint checksum() const { return 0; } virtual bool is_crashed() const { return 0; } virtual bool auto_repair() const { return 0; } + /* + default rename_table() and delete_table() rename/delete files with a + given name and extensions from bas_ext() + */ virtual int rename_table(const char *from, const char *to); virtual int delete_table(const char *name); + virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0; + + /* lock_count() can be more than one if the table is a MERGE */ virtual uint lock_count(void) const { return 1; } virtual THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, @@ -433,24 +497,18 @@ public: /* Type of table for caching query */ virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; } - /* - Is query with this table cachable (have sense only for ASKTRANSACT - tables) - */ - static bool caching_allowed(THD* thd, char* table_key, - uint key_length, uint8 cahe_type); - - /* - RETURN - true Primary key (if there is one) is clustered key covering all fields - false otherwise - */ - virtual bool primary_key_is_clustered() { return false; } - - virtual int cmp_ref(const byte *ref1, const byte *ref2) - { - return memcmp(ref1, ref2, ref_length); - } + + /* + RETURN + true Primary key (if there is one) is clustered key covering all fields + false otherwise + */ + virtual bool primary_key_is_clustered() { return FALSE; } + + virtual int cmp_ref(const byte *ref1, const byte *ref2) + { + return memcmp(ref1, ref2, ref_length); + } }; /* Some extern variables used with handlers */ @@ -465,8 +523,11 @@ extern TYPELIB tx_isolation_typelib; #define ha_commit(thd) (ha_commit_trans((thd), &((thd)->transaction.all))) #define ha_rollback(thd) (ha_rollback_trans((thd), &((thd)->transaction.all))) -#define ha_supports_generate(T) (T != DB_TYPE_INNODB) +#define ha_supports_generate(T) (T != DB_TYPE_INNODB && \ + T != DB_TYPE_BERKELEY_DB) +bool ha_caching_allowed(THD* thd, char* table_key, + uint key_length, uint8 cache_type); enum db_type ha_resolve_by_name(const char *name, uint namelen); const char *ha_get_storage_engine(enum db_type db_type); handler *get_new_handler(TABLE *table, enum db_type db_type); diff --git a/sql/item.cc b/sql/item.cc index 8dfe40abea8..8dfb8fb5587 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -230,8 +230,8 @@ bool Item::get_date(TIME *ltime,uint fuzzydate) char buff[40]; String tmp(buff,sizeof(buff), &my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) <= - TIMESTAMP_DATETIME_ERROR) + str_to_datetime_with_warn(res->ptr(), res->length(), + ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR) { bzero((char*) ltime,sizeof(*ltime)); return 1; @@ -249,7 +249,7 @@ bool Item::get_time(TIME *ltime) char buff[40]; String tmp(buff,sizeof(buff),&my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_time(res->ptr(),res->length(),ltime)) + str_to_time_with_warn(res->ptr(), res->length(), ltime)) { bzero((char*) ltime,sizeof(*ltime)); return 1; @@ -257,7 +257,7 @@ bool Item::get_time(TIME *ltime) return 0; } -CHARSET_INFO * Item::default_charset() const +CHARSET_INFO *Item::default_charset() { return current_thd->variables.collation_connection; } @@ -658,7 +658,9 @@ default_set_param_func(Item_param *param, Item_param::Item_param(unsigned pos_in_query_arg) : state(NO_VALUE), item_result_type(STRING_RESULT), - item_type(STRING_ITEM), + /* Don't pretend to be a literal unless value for this item is set. */ + item_type(PARAM_ITEM), + param_type(MYSQL_TYPE_STRING), pos_in_query(pos_in_query_arg), set_param_func(default_set_param_func) { @@ -766,6 +768,73 @@ bool Item_param::set_longdata(const char *str, ulong length) /* + Set parameter value from user variable value. + + SYNOPSIS + set_from_user_var + thd Current thread + entry User variable structure (NULL means use NULL value) + + RETURN + 0 OK + 1 Out of memort +*/ + +bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry) +{ + DBUG_ENTER("Item_param::set_from_user_var"); + if (entry && entry->value) + { + item_result_type= entry->type; + switch (entry->type) { + case REAL_RESULT: + set_double(*(double*)entry->value); + item_type= Item::REAL_ITEM; + item_result_type= REAL_RESULT; + break; + case INT_RESULT: + set_int(*(longlong*)entry->value, 21); + item_type= Item::INT_ITEM; + item_result_type= INT_RESULT; + break; + case STRING_RESULT: + { + CHARSET_INFO *fromcs= entry->collation.collation; + CHARSET_INFO *tocs= thd->variables.collation_connection; + uint32 dummy_offset; + + value.cs_info.character_set_client= fromcs; + /* + Setup source and destination character sets so that they + are different only if conversion is necessary: this will + make later checks easier. + */ + value.cs_info.final_character_set_of_str_value= + String::needs_conversion(0, fromcs, tocs, &dummy_offset) ? + tocs : fromcs; + /* + Exact value of max_length is not known unless data is converted to + charset of connection, so we have to set it later. + */ + item_type= Item::STRING_ITEM; + item_result_type= STRING_RESULT; + + if (set_str((const char *)entry->value, entry->length)) + DBUG_RETURN(1); + break; + } + default: + DBUG_ASSERT(0); + set_null(); + } + } + else + set_null(); + + DBUG_RETURN(0); +} + +/* Resets parameter after execution. SYNOPSIS @@ -783,21 +852,29 @@ void Item_param::reset() str_value.free(); else str_value.length(0); + str_value_ptr.length(0); /* - We must prevent all charset conversions unless data of str_value - has been written to the binary log. + We must prevent all charset conversions untill data has been written + to the binary log. */ str_value.set_charset(&my_charset_bin); state= NO_VALUE; maybe_null= 1; null_value= 0; + /* + Don't reset item_type to PARAM_ITEM: it's only needed to guard + us from item optimizations at prepare stage, when item doesn't yet + contain a literal of some kind. + In all other cases when this object is accessed its value is + set (this assumption is guarded by 'state' and + DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_* + methods). + */ } int Item_param::save_in_field(Field *field, bool no_conversions) { - DBUG_ASSERT(current_thd->command == COM_EXECUTE); - field->set_notnull(); switch (state) { @@ -837,6 +914,17 @@ bool Item_param::get_time(TIME *res) } +bool Item_param::get_date(TIME *res, uint fuzzydate) +{ + if (state == TIME_VALUE) + { + *res= value.time; + return 0; + } + return Item::get_date(res, fuzzydate); +} + + double Item_param::val() { switch (state) { @@ -896,7 +984,7 @@ String *Item_param::val_str(String* str) switch (state) { case STRING_VALUE: case LONG_DATA_VALUE: - return &str_value; + return &str_value_ptr; case REAL_VALUE: str->set(value.real, NOT_FIXED_DEC, &my_charset_bin); return str; @@ -1010,6 +1098,12 @@ bool Item_param::convert_str_value(THD *thd) } max_length= str_value.length(); decimals= 0; + /* + str_value_ptr is returned from val_str(). It must be not alloced + to prevent it's modification by val_str() invoker. + */ + str_value_ptr.set(str_value.ptr(), str_value.length(), + str_value.charset()); } return rc; } @@ -2368,6 +2462,7 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item) field_example= ((Item_field*) item)->field; else field_example= 0; + max_length= real_length(item); collation.set(item->collation); } @@ -2387,6 +2482,7 @@ static Item_result type_convertor[4][4]= bool Item_type_holder::join_types(THD *thd, Item *item) { + uint32 new_length= real_length(item); bool change_field= 0, skip_store_field= 0; Item_result new_type= type_convertor[item_type][item->result_type()]; @@ -2412,7 +2508,7 @@ bool Item_type_holder::join_types(THD *thd, Item *item) // size/type should be changed if (change_field || (new_type != item_type) || - (max_length < item->max_length) || + (max_length < new_length) || ((new_type == INT_RESULT) && (decimals < item->decimals)) || (!maybe_null && item->maybe_null) || @@ -2421,7 +2517,7 @@ bool Item_type_holder::join_types(THD *thd, Item *item) { // new field has some parameters worse then current skip_store_field|= (change_field && - (max_length > item->max_length) || + (max_length > new_length) || ((new_type == INT_RESULT) && (decimals > item->decimals)) || (maybe_null && !item->maybe_null) || @@ -2450,7 +2546,7 @@ bool Item_type_holder::join_types(THD *thd, Item *item) return 1; } - max_length= max(max_length, item->max_length); + max_length= max(max_length, new_length); decimals= max(decimals, item->decimals); maybe_null|= item->maybe_null; item_type= new_type; @@ -2459,6 +2555,26 @@ bool Item_type_holder::join_types(THD *thd, Item *item) return 0; } +uint32 Item_type_holder::real_length(Item *item) +{ + if (item->type() == Item::FIELD_ITEM) + { + return ((Item_field *)item)->max_disp_length(); + } + switch (item->result_type()) + { + case STRING_RESULT: + return item->max_length; + case REAL_RESULT: + return 53; + case INT_RESULT: + return 20; + case ROW_RESULT: + default: + DBUG_ASSERT(0); // we should never go there + return 0; + } +} double Item_type_holder::val() { diff --git a/sql/item.h b/sql/item.h index 69a6718a5a9..a169fc32a0b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -98,7 +98,8 @@ public: COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, - SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER}; + SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, + PARAM_ITEM}; enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; @@ -161,6 +162,31 @@ public: /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */ virtual double val()=0; virtual longlong val_int()=0; + /* + Return string representation of this item object. + + The argument to val_str() is an allocated buffer this or any + nested Item object can use to store return value of this method. + This buffer should only be used if the item itself doesn't have an + own String buffer. In case when the item maintains it's own string + buffer, it's preferrable to return it instead to minimize number of + mallocs/memcpys. + The caller of this method can modify returned string, but only in + case when it was allocated on heap, (is_alloced() is true). This + allows the caller to efficiently use a buffer allocated by a child + without having to allocate a buffer of it's own. The buffer, given + to val_str() as agrument, belongs to the caller and is later used + by the caller at it's own choosing. + A few implications from the above: + - unless you return a string object which only points to your buffer + but doesn't manages it you should be ready that it will be + modified. + - even for not allocated strings (is_alloced() == false) the caller + can change charset (see Item_func_{typecast/binary}. XXX: is this + a bug? + - still you should try to minimize data copying and return internal + object whenever possible. + */ virtual String *val_str(String*)=0; virtual Field *get_tmp_table_field() { return 0; } virtual Field *tmp_table_field(TABLE *t_arg) { return 0; } @@ -221,7 +247,7 @@ public: virtual Item *real_item() { return this; } virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } - CHARSET_INFO *default_charset() const; + static CHARSET_INFO *default_charset(); virtual CHARSET_INFO *compare_collation() { return NULL; } virtual bool walk(Item_processor processor, byte *arg) @@ -409,17 +435,11 @@ class Item_field :public Item_ident void set_field(Field *field); public: Field *field,*result_field; -#ifndef DBUG_OFF - bool double_fix; -#endif Item_field(const char *db_par,const char *table_name_par, const char *field_name_par) :Item_ident(db_par,table_name_par,field_name_par), field(0), result_field(0) -#ifndef DBUG_OFF - ,double_fix(0) -#endif { collation.set(DERIVATION_IMPLICIT); } // Constructor need to process subselect with temporary tables (see Item) Item_field(THD *thd, Item_field *item); @@ -459,6 +479,7 @@ public: bool is_null() { return field->is_null(); } Item *get_tmp_table_item(THD *thd); void cleanup(); + inline uint32 max_disp_length() { return field->max_length(); } friend class Item_default_value; friend class Item_insert_value; friend class st_select_lex_unit; @@ -492,19 +513,33 @@ public: void print(String *str) { str->append("NULL", 4); } }; + +/* Item represents one placeholder ('?') of prepared statement */ + class Item_param :public Item { -public: +public: enum enum_item_param_state { NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE } state; + /* + A buffer for string and long data values. Historically all allocated + values returned from val_str() were treated as eligible to + modification. I. e. in some cases Item_func_concat can append it's + second argument to return value of the first one. Because of that we + can't return the original buffer holding string data from val_str(), + and have to have one buffer for data and another just pointing to + the data. This is the latter one and it's returned from val_str(). + Can not be declared inside the union as it's not a POD type. + */ + String str_value_ptr; union { - longlong integer; - double real; + longlong integer; + double real; /* Character sets conversion info for string values. Character sets of client and connection defined at bind time are used @@ -517,7 +552,7 @@ public: /* This points at character set of connection if conversion to it is required (i. e. if placeholder typecode is not BLOB). - Otherwise it's equal to character_set_client (to simplify + Otherwise it's equal to character_set_client (to simplify check in convert_str_value()). */ CHARSET_INFO *final_character_set_of_str_value; @@ -528,22 +563,33 @@ public: /* Cached values for virtual methods to save us one switch. */ enum Item_result item_result_type; enum Type item_type; - /* + + /* + Used when this item is used in a temporary table. + This is NOT placeholder metadata sent to client, as this value + is assigned after sending metadata (in setup_one_conversion_function). + For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both + in result set and placeholders metadata, no matter what type you will + supply for this placeholder in mysql_stmt_execute. + */ + enum enum_field_types param_type; + /* Offset of placeholder inside statement text. Used to create no-placeholders version of this statement for the binary log. - */ + */ uint pos_in_query; Item_param(uint pos_in_query_arg); enum Item_result result_type () const { return item_result_type; } enum Type type() const { return item_type; } - enum_field_types field_type() const { return MYSQL_TYPE_STRING; } + enum_field_types field_type() const { return param_type; } double val(); longlong val_int(); String *val_str(String*); bool get_time(TIME *tm); + bool get_date(TIME *tm, uint fuzzydate); int save_in_field(Field *field, bool no_conversions); void set_null(); @@ -552,6 +598,7 @@ public: bool set_str(const char *str, ulong length); bool set_longdata(const char *str, ulong length); void set_time(TIME *tm, timestamp_type type, uint32 max_length_arg); + bool set_from_user_var(THD *thd, const user_var_entry *entry); void reset(); /* Assign placeholder value from bind data. @@ -564,16 +611,18 @@ public: const String *query_val_str(String *str) const; bool convert_str_value(THD *thd); - + Item *new_item() { return new Item_param(pos_in_query); } - /* - If value for parameter was not set we treat it as non-const - so noone will use parameters value in fix_fields still + /* + If value for parameter was not set we treat it as non-const + so noone will use parameters value in fix_fields still parameter is constant during execution. */ virtual table_map used_tables() const { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; } void print(String *str) { str->append('?'); } + /* parameter never equal to other parameter of other item */ + bool eq(const Item *item, bool binary_cmp) const { return 0; } }; class Item_int :public Item_num @@ -871,7 +920,10 @@ public: void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); } enum Item_result result_type () const { return (*ref)->result_type(); } enum_field_types field_type() const { return (*ref)->field_type(); } - table_map used_tables() const { return (*ref)->used_tables(); } + table_map used_tables() const + { + return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); + } void set_result_field(Field *field) { result_field= field; } bool is_result_field() { return 1; } void save_in_result_field(bool no_conversions) @@ -1250,6 +1302,7 @@ public: String *val_str(String*); bool join_types(THD *thd, Item *); Field *example() { return field_example; } + static uint32 real_length(Item *item); void cleanup() { DBUG_ENTER("Item_type_holder::cleanup"); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 446d72ac143..91257c31fb9 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -922,8 +922,8 @@ Item_func_if::fix_length_and_dec() decimals=max(args[1]->decimals,args[2]->decimals); enum Item_result arg1_type=args[1]->result_type(); enum Item_result arg2_type=args[2]->result_type(); - bool null1=args[1]->null_value; - bool null2=args[2]->null_value; + bool null1=args[1]->const_item() && args[1]->null_value; + bool null2=args[2]->const_item() && args[2]->null_value; if (null1) { @@ -2151,49 +2151,62 @@ Item_func::optimize_type Item_func_like::select_optimize() const bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref) { DBUG_ASSERT(fixed == 0); - if (Item_bool_func2::fix_fields(thd, tlist, ref)) + if (Item_bool_func2::fix_fields(thd, tlist, ref) || + escape_item->fix_fields(thd, tlist, &escape_item)) return 1; - /* - We could also do boyer-more for non-const items, but as we would have to - recompute the tables for each row it's not worth it. - */ - if (args[1]->const_item() && !use_strnxfrm(collation.collation) && - !(specialflag & SPECIAL_NO_NEW_FUNC)) + if (!escape_item->const_during_execution()) { - String* res2 = args[1]->val_str(&tmp_value2); - if (!res2) - return 0; // Null argument - - const size_t len = res2->length(); - const char* first = res2->ptr(); - const char* last = first + len - 1; + my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE"); + return 1; + } + + if (escape_item->const_item()) + { + /* If we are on execution stage */ + String *escape_str= escape_item->val_str(&tmp_value1); + escape= escape_str ? *(escape_str->ptr()) : '\\'; + /* - len must be > 2 ('%pattern%') - heuristic: only do TurboBM for pattern_len > 2 + We could also do boyer-more for non-const items, but as we would have to + recompute the tables for each row it's not worth it. */ - - if (len > MIN_TURBOBM_PATTERN_LEN + 2 && - *first == wild_many && - *last == wild_many) - { - const char* tmp = first + 1; - for (; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ; - canDoTurboBM = (tmp == last) && !use_mb(args[0]->collation.collation); - } - - if (canDoTurboBM) + if (args[1]->const_item() && !use_strnxfrm(collation.collation) && + !(specialflag & SPECIAL_NO_NEW_FUNC)) { - pattern = first + 1; - pattern_len = len - 2; - DBUG_PRINT("info", ("Initializing pattern: '%s'", first)); - int *suff = (int*) thd->alloc(sizeof(int)*((pattern_len + 1)*2+ - alphabet_size)); - bmGs = suff + pattern_len + 1; - bmBc = bmGs + pattern_len + 1; - turboBM_compute_good_suffix_shifts(suff); - turboBM_compute_bad_character_shifts(); - DBUG_PRINT("info",("done")); + String* res2 = args[1]->val_str(&tmp_value2); + if (!res2) + return 0; // Null argument + + const size_t len = res2->length(); + const char* first = res2->ptr(); + const char* last = first + len - 1; + /* + len must be > 2 ('%pattern%') + heuristic: only do TurboBM for pattern_len > 2 + */ + + if (len > MIN_TURBOBM_PATTERN_LEN + 2 && + *first == wild_many && + *last == wild_many) + { + const char* tmp = first + 1; + for (; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ; + canDoTurboBM = (tmp == last) && !use_mb(args[0]->collation.collation); + } + if (canDoTurboBM) + { + pattern = first + 1; + pattern_len = len - 2; + DBUG_PRINT("info", ("Initializing pattern: '%s'", first)); + int *suff = (int*) thd->alloc(sizeof(int)*((pattern_len + 1)*2+ + alphabet_size)); + bmGs = suff + pattern_len + 1; + bmBc = bmGs + pattern_len + 1; + turboBM_compute_good_suffix_shifts(suff); + turboBM_compute_bad_character_shifts(); + DBUG_PRINT("info",("done")); + } } } return 0; @@ -2298,15 +2311,19 @@ longlong Item_func_regex::val_int() } -Item_func_regex::~Item_func_regex() +void Item_func_regex::cleanup() { + DBUG_ENTER("Item_func_regex::cleanup"); + Item_bool_func::cleanup(); if (regex_compiled) { regfree(&preg); regex_compiled=0; } + DBUG_VOID_RETURN; } + #endif /* USE_REGEX */ diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 2288a99c55f..23ac82e79e6 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -875,12 +875,14 @@ class Item_func_like :public Item_bool_func2 bool turboBM_matches(const char* text, int text_len) const; enum { alphabet_size = 256 }; + Item *escape_item; + public: char escape; - Item_func_like(Item *a,Item *b, char* escape_arg) + Item_func_like(Item *a,Item *b, Item *escape_arg) :Item_bool_func2(a,b), canDoTurboBM(false), pattern(0), pattern_len(0), - bmGs(0), bmBc(0), escape(*escape_arg) {} + bmGs(0), bmBc(0), escape_item(escape_arg) {} longlong val_int(); enum Functype functype() const { return LIKE_FUNC; } optimize_type select_optimize() const; @@ -903,7 +905,7 @@ class Item_func_regex :public Item_bool_func public: Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b), regex_compiled(0),regex_is_const(0) {} - ~Item_func_regex(); + void cleanup(); longlong val_int(); bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref); const char *func_name() const { return "regexp"; } diff --git a/sql/item_create.cc b/sql/item_create.cc index e314bfc3e2c..e2c85af49bc 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -85,6 +85,11 @@ Item *create_func_conv(Item* a, Item *b, Item *c) return new Item_func_conv(a,b,c); } +Item *create_func_convert_tz(Item* a, Item *b, Item *c) +{ + return new Item_func_convert_tz(a,b,c); +} + Item *create_func_cos(Item* a) { return new Item_func_cos(a); @@ -145,7 +150,7 @@ Item *create_func_found_rows(void) { THD *thd=current_thd; thd->lex->safe_to_cache_query= 0; - return new Item_int(NullS,(longlong) thd->found_rows(),21); + return new Item_func_found_rows(); } Item *create_func_from_days(Item* a) @@ -364,7 +369,7 @@ Item *create_func_space(Item *a) CHARSET_INFO *cs= current_thd->variables.collation_connection; Item *sp; - if (cs->state & MY_CS_NONTEXT) + if (cs->mbminlen > 1) { sp= new Item_string("",0,cs); if (sp) diff --git a/sql/item_create.h b/sql/item_create.h index d48aed5284a..18c5b3239f3 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -31,6 +31,7 @@ Item *create_func_char_length(Item* a); Item *create_func_cast(Item *a, Cast_target cast_type, int len, CHARSET_INFO *cs); Item *create_func_connection_id(void); Item *create_func_conv(Item* a, Item *b, Item *c); +Item *create_func_convert_tz(Item* a, Item *b, Item *c); Item *create_func_cos(Item* a); Item *create_func_cot(Item* a); Item *create_func_crc32(Item* a); diff --git a/sql/item_func.cc b/sql/item_func.cc index ac7025a391a..c2c93586af8 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2593,27 +2593,39 @@ longlong Item_func_get_user_var::val_int() /* + Get variable by name and, if necessary, put the record of variable + use into the binary log. + + SYNOPSIS + get_var_with_binlog() + thd Current thread + name Variable name + out_entry [out] variable structure or NULL. The pointer is set + regardless of whether function succeeded or not. + When a user variable is invoked from an update query (INSERT, UPDATE etc), stores this variable and its value in thd->user_var_events, so that it can be written to the binlog (will be written just before the query is written, see log.cc). + + RETURN + 0 OK + 1 Failed to put appropiate record into binary log + */ -void Item_func_get_user_var::fix_length_and_dec() +int get_var_with_binlog(THD *thd, LEX_STRING &name, + user_var_entry **out_entry) { - THD *thd=current_thd; BINLOG_USER_VAR_EVENT *user_var_event; - maybe_null=1; - decimals=NOT_FIXED_DEC; - max_length=MAX_BLOB_WIDTH; - - if (!(var_entry= get_variable(&thd->user_vars, name, 0))) - null_value= 1; - else - collation.set(var_entry->collation); + user_var_entry *var_entry; + var_entry= get_variable(&thd->user_vars, name, 0); if (!(opt_bin_log && is_update_query(thd->lex->sql_command))) - return; + { + *out_entry= var_entry; + return 0; + } if (!var_entry) { @@ -2640,13 +2652,16 @@ void Item_func_get_user_var::fix_length_and_dec() if (!(var_entry= get_variable(&thd->user_vars, name, 0))) goto err; } - /* - If this variable was already stored in user_var_events by this query - (because it's used in more than one place in the query), don't store - it. - */ else if (var_entry->used_query_id == thd->query_id) - return; + { + /* + If this variable was already stored in user_var_events by this query + (because it's used in more than one place in the query), don't store + it. + */ + *out_entry= var_entry; + return 0; + } uint size; /* @@ -2681,11 +2696,34 @@ void Item_func_get_user_var::fix_length_and_dec() var_entry->used_query_id= thd->query_id; if (insert_dynamic(&thd->user_var_events, (gptr) &user_var_event)) goto err; - - return; + + *out_entry= var_entry; + return 0; err: - thd->fatal_error(); + *out_entry= var_entry; + return 1; +} + + +void Item_func_get_user_var::fix_length_and_dec() +{ + THD *thd=current_thd; + int error; + maybe_null=1; + decimals=NOT_FIXED_DEC; + max_length=MAX_BLOB_WIDTH; + + error= get_var_with_binlog(thd, name, &var_entry); + + if (var_entry) + collation.set(var_entry->collation); + else + null_value= 1; + + if (error) + thd->fatal_error(); + return; } @@ -3168,7 +3206,6 @@ longlong Item_func_is_free_lock::val_int() { DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); - THD *thd=current_thd; User_level_lock *ull; null_value=0; @@ -3191,7 +3228,6 @@ longlong Item_func_is_used_lock::val_int() { DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); - THD *thd=current_thd; User_level_lock *ull; null_value=1; @@ -3339,3 +3375,12 @@ Item_func_sp::fix_length_and_dec() } DBUG_VOID_RETURN; } + + +longlong Item_func_found_rows::val_int() +{ + DBUG_ASSERT(fixed == 1); + THD *thd= current_thd; + + return thd->found_rows(); +} diff --git a/sql/item_func.h b/sql/item_func.h index 1d945af35b2..8636bcd6507 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1151,3 +1151,13 @@ public: void fix_length_and_dec(); }; + + +class Item_func_found_rows :public Item_int_func +{ +public: + Item_func_found_rows() :Item_int_func() {} + longlong val_int(); + const char *func_name() const { return "found_rows"; } + void fix_length_and_dec() { decimals= 0; maybe_null=0; } +}; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 676d8c1386a..b0c685c1c46 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -950,17 +950,10 @@ String *Item_func_left::val_str(String *str) return 0; if (length <= 0) return &my_empty_string; - length= res->charpos(length); - if (res->length() > (ulong) length) - { // Safe even if const arg - if (!res->alloced_length()) - { // Don't change const str - str_value= *res; // Not malloced string - res= &str_value; - } - res->length((uint) length); - } - return res; + if (res->length() <= (uint) length) + return res; + str_value.set(*res, 0, res->charpos(length)); + return &str_value; } @@ -1461,6 +1454,7 @@ void Item_func_encode::fix_length_and_dec() { max_length=args[0]->max_length; maybe_null=args[0]->maybe_null; + collation.set(&my_charset_bin); } String *Item_func_encode::val_str(String *str) @@ -1476,6 +1470,7 @@ String *Item_func_encode::val_str(String *str) res=copy_if_not_alloced(str,res,res->length()); sql_crypt.init(); sql_crypt.encode((char*) res->ptr(),res->length()); + res->set_charset(&my_charset_bin); return res; } @@ -2097,10 +2092,8 @@ String *Item_func_lpad::val_str(String *str) count-= pad_char_length; } if (count > 0) - { - pad->length(pad->charpos(count)); - str->append(*pad); - } + str->append(pad->ptr(), pad->charpos(count), collation.collation); + str->append(*res); null_value= 0; return str; @@ -2285,8 +2278,8 @@ String *Item_func_hex::val_str(String *str) from++, to+=2) { uint tmp=(uint) (uchar) *from; - to[0]=_dig_vec[tmp >> 4]; - to[1]=_dig_vec[tmp & 15]; + to[0]=_dig_vec_upper[tmp >> 4]; + to[1]=_dig_vec_upper[tmp & 15]; } return &tmp_value; } @@ -2746,9 +2739,6 @@ static uint nanoseq; static ulonglong uuid_time=0; static char clock_seq_and_node_str[]="-0000-000000000000"; -/* we cannot use _dig_vec[] as letters should be lowercase */ -static const char hex[] = "0123456789abcdef"; - /* number of 100-nanosecond intervals between 1582-10-15 00:00:00.00 and 1970-01-01 00:00:00.00 */ #define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * 1000 * 10 ) @@ -2761,7 +2751,7 @@ static void tohex(char *to, uint from, uint len) to+= len; while (len--) { - *--to= hex[from & 15]; + *--to= _dig_vec_lower[from & 15]; from >>= 4; } } @@ -2798,8 +2788,8 @@ String *Item_func_uuid::val_str(String *str) s=clock_seq_and_node_str+sizeof(clock_seq_and_node_str)-1; for (i=sizeof(mac)-1 ; i>=0 ; i--) { - *--s=hex[mac[i] & 15]; - *--s=hex[mac[i] >> 4]; + *--s=_dig_vec_lower[mac[i] & 15]; + *--s=_dig_vec_lower[mac[i] >> 4]; } randominit(&uuid_rand, tmp + (ulong)start_time, tmp + bytes_sent); set_clock_seq_str(); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 48d38c0d602..91a31502780 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -74,6 +74,11 @@ void Item_subselect::init(st_select_lex *select_lex, else engine= new subselect_single_select_engine(select_lex, result, this); } + { + SELECT_LEX *upper= unit->outer_select(); + if (upper->parsing_place == SELECT_LEX_NODE::IN_HAVING) + upper->subquery_in_having= 1; + } DBUG_VOID_RETURN; } @@ -657,7 +662,6 @@ Item_in_subselect::single_value_transformer(JOIN *join, !(select_lex->next_select())) { Item *item; - subs_type type= substype(); if (func->l_op()) { /* @@ -1183,7 +1187,7 @@ int subselect_single_select_engine::exec() join->thd->where= save_where; executed= 1; join->thd->lex->current_select= save_select; - DBUG_RETURN(join->error?join->error:1); + DBUG_RETURN(join->error ? join->error : 1); } if (item->engine_changed) { @@ -1235,6 +1239,8 @@ int subselect_uniquesubquery_engine::exec() } else { + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], tab->ref.key_buff, tab->ref.key_length,HA_READ_KEY_EXACT); @@ -1256,7 +1262,7 @@ int subselect_uniquesubquery_engine::exec() subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine() { /* Tell handler we don't need the index anymore */ - tab->table->file->index_end(); + tab->table->file->ha_index_end(); } @@ -1283,6 +1289,8 @@ int subselect_indexsubquery_engine::exec() } else { + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); error= table->file->index_read(table->record[0], tab->ref.key_buff, tab->ref.key_length,HA_READ_KEY_EXACT); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3275440e522..50864132932 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -477,6 +477,16 @@ longlong Item_sum_count::val_int() return (longlong) count; } + +void Item_sum_count::cleanup() +{ + DBUG_ENTER("Item_sum_count::cleanup"); + Item_sum_int::cleanup(); + used_table_cache= ~(table_map) 0; + DBUG_VOID_RETURN; +} + + /* Avgerage */ @@ -691,6 +701,15 @@ Item_sum_hybrid::val_str(String *str) } +void Item_sum_hybrid::cleanup() +{ + DBUG_ENTER("Item_sum_hybrid::cleanup"); + Item_sum::cleanup(); + used_table_cache= ~(table_map) 0; + DBUG_VOID_RETURN; +} + + Item *Item_sum_min::copy_or_same(THD* thd) { return new (&thd->mem_root) Item_sum_min(thd, this); @@ -1777,6 +1796,9 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), String tmp((char *)&buff,sizeof(buff),default_charset_info), tmp2; char *record= (char*) item->table->record[0]; + if (item->result.length()) + item->result.append(*item->separator); + tmp.length(0); for (uint i= 0; i < item->arg_count_field; i++) @@ -1806,14 +1828,6 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), item->result.append(*res); } } - if (item->tree_mode) // Last item of tree - { - item->show_elements++; - if (item->show_elements < item->tree->elements_in_tree) - item->result.append(*item->separator); - } - else - item->result.append(*item->separator); /* stop if length of result more than group_concat_max_len */ if (item->result.length() > item->group_concat_max_len) @@ -1844,7 +1858,7 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct, tree_mode(0), distinct(is_distinct), warning_for_row(0), separator(is_separator), tree(&tree_base), table(0), order(0), tables_list(0), - show_elements(0), arg_count_order(0), arg_count_field(0), + arg_count_order(0), arg_count_field(0), count_cut_values(0) { Item *item_select; @@ -1910,7 +1924,6 @@ Item_func_group_concat::Item_func_group_concat(THD *thd, order(item->order), tables_list(item->tables_list), group_concat_max_len(item->group_concat_max_len), - show_elements(item->show_elements), arg_count_order(item->arg_count_order), arg_count_field(item->arg_count_field), field_list_offset(item->field_list_offset), @@ -2218,15 +2231,9 @@ String* Item_func_group_concat::val_str(String* str) return 0; if (tree_mode) { - show_elements= 0; tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this, left_root_right); } - else - { - if (!warning_for_row) - result.length(result.length()-separator->length()); - } if (count_cut_values && !warning_available) { warning_available= TRUE; diff --git a/sql/item_sum.h b/sql/item_sum.h index ce46e92e6cf..2dde6f73425 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -207,6 +207,7 @@ class Item_sum_count :public Item_sum_int void make_const(longlong count_arg) { count=count_arg; used_table_cache=0; } longlong val_int(); void reset_field(); + void cleanup(); void update_field(); const char *func_name() const { return "count"; } Item *copy_or_same(THD* thd); @@ -463,6 +464,7 @@ class Item_sum_hybrid :public Item_sum void min_max_update_str_field(); void min_max_update_real_field(); void min_max_update_int_field(); + void cleanup(); }; @@ -729,7 +731,6 @@ class Item_func_group_concat : public Item_sum ORDER **order; TABLE_LIST *tables_list; ulong group_concat_max_len; - uint show_elements; uint arg_count_order; uint arg_count_field; uint field_list_offset; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 39f67ba24f8..3baf55abc0c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -425,21 +425,21 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, str->append(month_names[l_time->month-1],3); break; case 'W': - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; weekday= calc_weekday(calc_daynr(l_time->year,l_time->month, l_time->day),0); str->append(day_names[weekday]); break; case 'a': - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; weekday=calc_weekday(calc_daynr(l_time->year,l_time->month, l_time->day),0); str->append(day_names[weekday],3); break; case 'D': - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; length= int10_to_str(l_time->day, intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 1, '0'); @@ -507,7 +507,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, str->append_with_prefill(intbuff, length, 2, '0'); break; case 'j': - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; length= int10_to_str(calc_daynr(l_time->year,l_time->month, l_time->day) - @@ -555,7 +555,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, case 'u': { uint year; - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; length= int10_to_str(calc_week(l_time, (*ptr) == 'U' ? @@ -569,7 +569,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, case 'V': { uint year; - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; length= int10_to_str(calc_week(l_time, ((*ptr) == 'V' ? @@ -584,7 +584,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, case 'X': { uint year; - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; (void) calc_week(l_time, ((*ptr) == 'X' ? @@ -596,7 +596,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, } break; case 'w': - if (type == TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME) return 1; weekday=calc_weekday(calc_daynr(l_time->year,l_time->month, l_time->day),1); @@ -894,6 +894,9 @@ longlong Item_func_year::val_int() longlong Item_func_unix_timestamp::val_int() { + TIME ltime; + bool not_used; + DBUG_ASSERT(fixed == 1); if (arg_count == 0) return (longlong) current_thd->query_start(); @@ -903,12 +906,19 @@ longlong Item_func_unix_timestamp::val_int() if (field->type() == FIELD_TYPE_TIMESTAMP) return ((Field_timestamp*) field)->get_timestamp(); } - String *str=args[0]->val_str(&value); - if ((null_value=args[0]->null_value)) + + if (get_arg0_date(<ime, 0)) { - return 0; /* purecov: inspected */ + /* + We have to set null_value again because get_arg0_date will also set it + to true if we have wrong datetime parameter (and we should return 0 in + this case). + */ + null_value= args[0]->null_value; + return 0; } - return (longlong) str_to_timestamp(str->ptr(),str->length()); + + return (longlong) TIME_to_timestamp(current_thd, <ime, ¬_used); } @@ -1103,7 +1113,7 @@ int Item_date::save_in_field(Field *field, bool no_conversions) if (get_date(<ime, TIME_FUZZY_DATE)) return set_field_to_null(field); field->set_notnull(); - field->store_time(<ime, TIMESTAMP_DATE); + field->store_time(<ime, MYSQL_TIMESTAMP_DATE); return 0; } @@ -1125,31 +1135,22 @@ bool Item_func_from_days::get_date(TIME *ltime, uint fuzzy_date) return 1; bzero(ltime, sizeof(TIME)); get_date_from_daynr((long) value, <ime->year, <ime->month, <ime->day); - ltime->time_type= TIMESTAMP_DATE; + ltime->time_type= MYSQL_TIMESTAMP_DATE; return 0; } void Item_func_curdate::fix_length_and_dec() { - struct tm start; - collation.set(&my_charset_bin); decimals=0; max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; - store_now_in_tm(current_thd->query_start(),&start); + store_now_in_TIME(<ime); - /* For getdate */ - ltime.year= start.tm_year+1900; - ltime.month= start.tm_mon+1; - ltime.day= start.tm_mday; - ltime.hour= 0; - ltime.minute= 0; - ltime.second= 0; - ltime.second_part=0; - ltime.neg=0; - ltime.time_type=TIMESTAMP_DATE; + /* We don't need to set second_part and neg because they already 0 */ + ltime.hour= ltime.minute= ltime.second= 0; + ltime.time_type= MYSQL_TIMESTAMP_DATE; value= (longlong) TIME_to_ulonglong_date(<ime); } @@ -1165,31 +1166,39 @@ String *Item_func_curdate::val_str(String *str) return str; } -bool Item_func_curdate::get_date(TIME *res, - uint fuzzy_date __attribute__((unused))) +/* + Converts current time in my_time_t to TIME represenatation for local + time zone. Defines time zone (local) used for whole CURDATE function. +*/ +void Item_func_curdate_local::store_now_in_TIME(TIME *now_time) { - *res=ltime; - return 0; + THD *thd= current_thd; + thd->variables.time_zone->gmt_sec_to_TIME(now_time, + (my_time_t)thd->query_start()); + thd->time_zone_used= 1; } /* - Converts time in time_t to struct tm represenatation for local timezone. - Defines timezone (local) used for whole CURDATE function + Converts current time in my_time_t to TIME represenatation for UTC + time zone. Defines time zone (UTC) used for whole UTC_DATE function. */ -void Item_func_curdate_local::store_now_in_tm(time_t now, struct tm *now_tm) +void Item_func_curdate_utc::store_now_in_TIME(TIME *now_time) { - localtime_r(&now,now_tm); + my_tz_UTC->gmt_sec_to_TIME(now_time, + (my_time_t)(current_thd->query_start())); + /* + We are not flagging this query as using time zone, since it uses fixed + UTC-SYSTEM time-zone. + */ } -/* - Converts time in time_t to struct tm represenatation for UTC - Defines timezone (UTC) used for whole UTC_DATE function -*/ -void Item_func_curdate_utc::store_now_in_tm(time_t now, struct tm *now_tm) +bool Item_func_curdate::get_date(TIME *res, + uint fuzzy_date __attribute__((unused))) { - gmtime_r(&now,now_tm); + *res=ltime; + return 0; } @@ -1203,17 +1212,12 @@ String *Item_func_curtime::val_str(String *str) void Item_func_curtime::fix_length_and_dec() { - struct tm start; - String tmp((char*) buff,sizeof(buff), &my_charset_bin); TIME ltime; + String tmp((char*) buff,sizeof(buff), &my_charset_bin); - decimals=0; - store_now_in_tm(current_thd->query_start(),&start); - ltime.hour= start.tm_hour; - ltime.minute= start.tm_min; - ltime.second= start.tm_sec; - ltime.second_part= 0; - ltime.neg= 0; + decimals=0; + collation.set(&my_charset_bin); + store_now_in_TIME(<ime); value= TIME_to_ulonglong_time(<ime); make_time((DATE_TIME_FORMAT *) 0, <ime, &tmp); max_length= buff_length= tmp.length(); @@ -1221,22 +1225,30 @@ void Item_func_curtime::fix_length_and_dec() /* - Converts time in time_t to struct tm represenatation for local timezone. - Defines timezone (local) used for whole CURTIME function + Converts current time in my_time_t to TIME represenatation for local + time zone. Defines time zone (local) used for whole CURTIME function. */ -void Item_func_curtime_local::store_now_in_tm(time_t now, struct tm *now_tm) +void Item_func_curtime_local::store_now_in_TIME(TIME *now_time) { - localtime_r(&now,now_tm); + THD *thd= current_thd; + thd->variables.time_zone->gmt_sec_to_TIME(now_time, + (my_time_t)thd->query_start()); + thd->time_zone_used= 1; } /* - Converts time in time_t to struct tm represenatation for UTC. - Defines timezone (UTC) used for whole UTC_TIME function + Converts current time in my_time_t to TIME represenatation for UTC + time zone. Defines time zone (UTC) used for whole UTC_TIME function. */ -void Item_func_curtime_utc::store_now_in_tm(time_t now, struct tm *now_tm) +void Item_func_curtime_utc::store_now_in_TIME(TIME *now_time) { - gmtime_r(&now,now_tm); + my_tz_UTC->gmt_sec_to_TIME(now_time, + (my_time_t)(current_thd->query_start())); + /* + We are not flagging this query as using time zone, since it uses fixed + UTC-SYSTEM time-zone. + */ } @@ -1250,18 +1262,12 @@ String *Item_func_now::val_str(String *str) void Item_func_now::fix_length_and_dec() { - struct tm start; String tmp((char*) buff,sizeof(buff),&my_charset_bin); decimals=0; collation.set(&my_charset_bin); - store_now_in_tm(current_thd->query_start(),&start); - - /* For getdate */ - localtime_to_TIME(<ime, &start); - ltime.time_type= TIMESTAMP_DATETIME; - + store_now_in_TIME(<ime); value= (longlong) TIME_to_ulonglong_datetime(<ime); make_datetime((DATE_TIME_FORMAT *) 0, <ime, &tmp); @@ -1269,39 +1275,47 @@ void Item_func_now::fix_length_and_dec() } -bool Item_func_now::get_date(TIME *res, - uint fuzzy_date __attribute__((unused))) +/* + Converts current time in my_time_t to TIME represenatation for local + time zone. Defines time zone (local) used for whole NOW function. +*/ +void Item_func_now_local::store_now_in_TIME(TIME *now_time) { - *res=ltime; - return 0; + THD *thd= current_thd; + thd->variables.time_zone->gmt_sec_to_TIME(now_time, + (my_time_t)thd->query_start()); + thd->time_zone_used= 1; } -int Item_func_now::save_in_field(Field *to, bool no_conversions) +/* + Converts current time in my_time_t to TIME represenatation for UTC + time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function. +*/ +void Item_func_now_utc::store_now_in_TIME(TIME *now_time) { - to->set_notnull(); - to->store_time(<ime,TIMESTAMP_DATETIME); - return 0; + my_tz_UTC->gmt_sec_to_TIME(now_time, + (my_time_t)(current_thd->query_start())); + /* + We are not flagging this query as using time zone, since it uses fixed + UTC-SYSTEM time-zone. + */ } -/* - Converts time in time_t to struct tm represenatation for local timezone. - Defines timezone (local) used for whole CURRENT_TIMESTAMP function -*/ -void Item_func_now_local::store_now_in_tm(time_t now, struct tm *now_tm) +bool Item_func_now::get_date(TIME *res, + uint fuzzy_date __attribute__((unused))) { - localtime_r(&now,now_tm); + *res=ltime; + return 0; } -/* - Converts time in time_t to struct tm represenatation for UTC. - Defines timezone (UTC) used for whole UTC_TIMESTAMP function -*/ -void Item_func_now_utc::store_now_in_tm(time_t now, struct tm *now_tm) +int Item_func_now::save_in_field(Field *to, bool no_conversions) { - gmtime_r(&now,now_tm); + to->set_notnull(); + to->store_time(<ime, MYSQL_TIMESTAMP_DATETIME); + return 0; } @@ -1461,7 +1475,7 @@ String *Item_func_date_format::val_str(String *str) { String *res; if (!(res=args[0]->val_str(str)) || - (str_to_time(res->ptr(),res->length(),&l_time))) + (str_to_time_with_warn(res->ptr(), res->length(), &l_time))) goto null_date; l_time.year=l_time.month=l_time.day=0; @@ -1486,7 +1500,9 @@ String *Item_func_date_format::val_str(String *str) /* Create the result string */ if (!make_date_time(&date_time_format, &l_time, - is_time_format ? TIMESTAMP_TIME : TIMESTAMP_DATE, str)) + is_time_format ? MYSQL_TIMESTAMP_TIME : + MYSQL_TIMESTAMP_DATE, + str)) return str; null_date: @@ -1495,24 +1511,31 @@ null_date: } +void Item_func_from_unixtime::fix_length_and_dec() +{ + thd= current_thd; + collation.set(&my_charset_bin); + decimals=0; + max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; + thd->time_zone_used= 1; +} + + String *Item_func_from_unixtime::val_str(String *str) { - struct tm tm_tmp; - time_t tmp; - TIME ltime; + TIME time_tmp; + my_time_t tmp; DBUG_ASSERT(fixed == 1); tmp= (time_t) args[0]->val_int(); if ((null_value=args[0]->null_value)) goto null_date; - - localtime_r(&tmp,&tm_tmp); - - localtime_to_TIME(<ime, &tm_tmp); - + + thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp); + if (str->alloc(20*MY_CHARSET_BIN_MB_MAXLEN)) goto null_date; - make_datetime((DATE_TIME_FORMAT *) 0, <ime, str); + make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str); return str; null_date: @@ -1523,28 +1546,109 @@ null_date: longlong Item_func_from_unixtime::val_int() { - TIME ltime; - struct tm tm_tmp; - time_t tmp; + TIME time_tmp; + my_time_t tmp; + DBUG_ASSERT(fixed == 1); tmp= (time_t) (ulong) args[0]->val_int(); if ((null_value=args[0]->null_value)) return 0; - localtime_r(&tmp,&tm_tmp); - localtime_to_TIME(<ime, &tm_tmp); - return (longlong) TIME_to_ulonglong_datetime(<ime); + + current_thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp); + + return (longlong) TIME_to_ulonglong_datetime(&time_tmp); } bool Item_func_from_unixtime::get_date(TIME *ltime, uint fuzzy_date __attribute__((unused))) { - time_t tmp=(time_t) (ulong) args[0]->val_int(); + my_time_t tmp=(my_time_t) args[0]->val_int(); if ((null_value=args[0]->null_value)) return 1; - struct tm tm_tmp; - localtime_r(&tmp,&tm_tmp); - localtime_to_TIME(ltime, &tm_tmp); + + current_thd->variables.time_zone->gmt_sec_to_TIME(ltime, tmp); + + return 0; +} + + +void Item_func_convert_tz::fix_length_and_dec() +{ + String str; + + thd= current_thd; + collation.set(&my_charset_bin); + decimals= 0; + max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; + + if (args[1]->const_item()) + from_tz= my_tz_find(thd, args[1]->val_str(&str)); + + if (args[2]->const_item()) + to_tz= my_tz_find(thd, args[2]->val_str(&str)); +} + + +String *Item_func_convert_tz::val_str(String *str) +{ + TIME time_tmp; + + if (get_date(&time_tmp, 0)) + return 0; + + if (str->alloc(20*MY_CHARSET_BIN_MB_MAXLEN)) + { + null_value= 1; + return 0; + } + + make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str); + return str; +} + + +longlong Item_func_convert_tz::val_int() +{ + TIME time_tmp; + + if (get_date(&time_tmp, 0)) + return 0; + + return (longlong)TIME_to_ulonglong_datetime(&time_tmp); +} + + +bool Item_func_convert_tz::get_date(TIME *ltime, + uint fuzzy_date __attribute__((unused))) +{ + my_time_t my_time_tmp; + bool not_used; + String str; + + if (!args[1]->const_item()) + from_tz= my_tz_find(thd, args[1]->val_str(&str)); + + if (!args[2]->const_item()) + to_tz= my_tz_find(thd, args[2]->val_str(&str)); + + if (from_tz==0 || to_tz==0 || get_arg0_date(ltime, 0)) + { + null_value= 1; + return 1; + } + + /* Check if we in range where we treat datetime values as non-UTC */ + if (ltime->year < TIMESTAMP_MAX_YEAR && ltime->year > TIMESTAMP_MIN_YEAR || + ltime->year==TIMESTAMP_MAX_YEAR && ltime->month==1 && ltime->day==1 || + ltime->year==TIMESTAMP_MIN_YEAR && ltime->month==12 && ltime->day==31) + { + my_time_tmp= from_tz->TIME_to_gmt_sec(ltime, ¬_used); + if (my_time_tmp >= TIMESTAMP_MIN_VALUE && my_time_tmp <= TIMESTAMP_MAX_VALUE) + to_tz->gmt_sec_to_TIME(ltime, my_time_tmp); + } + + null_value= 0; return 0; } @@ -1617,7 +1721,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) case INTERVAL_DAY_HOUR: { longlong sec, days, daynr, microseconds, extra_sec; - ltime->time_type=TIMESTAMP_DATETIME; // Return full date + ltime->time_type= MYSQL_TIMESTAMP_DATETIME; // Return full date microseconds= ltime->second_part + sign*interval.second_part; extra_sec= microseconds/1000000L; microseconds= microseconds%1000000L; @@ -1704,7 +1808,7 @@ String *Item_date_add_interval::val_str(String *str) if (Item_date_add_interval::get_date(<ime,0)) return 0; - if (ltime.time_type == TIMESTAMP_DATE) + if (ltime.time_type == MYSQL_TIMESTAMP_DATE) format= DATE_ONLY; else if (ltime.second_part) format= DATE_TIME_MICROSECOND; @@ -1727,7 +1831,7 @@ longlong Item_date_add_interval::val_int() if (Item_date_add_interval::get_date(<ime,0)) return (longlong) 0; date = (ltime.year*100L + ltime.month)*100L + ltime.day; - return ltime.time_type == TIMESTAMP_DATE ? date : + return ltime.time_type == MYSQL_TIMESTAMP_DATE ? date : ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second; } @@ -1808,7 +1912,7 @@ longlong Item_extract::val_int() else { String *res= args[0]->val_str(&value); - if (!res || str_to_time(res->ptr(),res->length(),<ime)) + if (!res || str_to_time_with_warn(res->ptr(), res->length(), <ime)) { null_value=1; return 0; @@ -1986,7 +2090,7 @@ String *Item_datetime_typecast::val_str(String *str) bool Item_time_typecast::get_time(TIME *ltime) { bool res= get_arg0_time(ltime); - ltime->time_type= TIMESTAMP_TIME; + ltime->time_type= MYSQL_TIMESTAMP_TIME; return res; } @@ -2009,7 +2113,7 @@ String *Item_time_typecast::val_str(String *str) bool Item_date_typecast::get_date(TIME *ltime, uint fuzzy_date) { bool res= get_arg0_date(ltime,1); - ltime->time_type= TIMESTAMP_DATE; + ltime->time_type= MYSQL_TIMESTAMP_DATE; return res; } @@ -2115,17 +2219,17 @@ String *Item_func_add_time::val_str(String *str) { if (get_arg0_date(&l_time1,1) || args[1]->get_time(&l_time2) || - l_time1.time_type == TIMESTAMP_TIME || - l_time2.time_type != TIMESTAMP_TIME) + l_time1.time_type == MYSQL_TIMESTAMP_TIME || + l_time2.time_type != MYSQL_TIMESTAMP_TIME) goto null_date; } else // ADDTIME function { if (args[0]->get_time(&l_time1) || args[1]->get_time(&l_time2) || - l_time2.time_type == TIMESTAMP_DATETIME) + l_time2.time_type == MYSQL_TIMESTAMP_DATETIME) goto null_date; - is_time= (l_time1.time_type == TIMESTAMP_TIME); + is_time= (l_time1.time_type == MYSQL_TIMESTAMP_TIME); if (is_time && (l_time2.neg == l_time1.neg && l_time1.neg)) l_time3.neg= 1; } @@ -2248,11 +2352,11 @@ bool calc_time_diff(TIME *l_time1,TIME *l_time2, int l_sign, long microseconds= *microseconds_out; /* - We suppose that if first argument is TIMESTAMP_TIME + We suppose that if first argument is MYSQL_TIMESTAMP_TIME the second argument should be TIMESTAMP_TIME also. We should check it before calc_time_diff call. */ - if (l_time1->time_type == TIMESTAMP_TIME) // Time value + if (l_time1->time_type == MYSQL_TIMESTAMP_TIME) // Time value days= l_time1->day - l_sign*l_time2->day; else // DateTime value days= (calc_daynr((uint) l_time1->year, @@ -2317,7 +2421,7 @@ String *Item_func_timediff::val_str(String *str) &seconds, µseconds); /* - For TIMESTAMP_TIME only: + For MYSQL_TIMESTAMP_TIME only: If both argumets are negative values and diff between them is negative we need to swap sign as result should be positive. */ @@ -2591,13 +2695,13 @@ void Item_func_get_format::print(String *str) str->append('('); switch (type) { - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: str->append("DATE, "); break; - case TIMESTAMP_DATETIME: + case MYSQL_TIMESTAMP_DATETIME: str->append("DATETIME, "); break; - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: str->append("TIME, "); break; default: @@ -2680,25 +2784,25 @@ void Item_func_str_to_date::fix_length_and_dec() decimals=0; cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; - cached_timestamp_type= TIMESTAMP_NONE; + cached_timestamp_type= MYSQL_TIMESTAMP_NONE; if ((const_item= args[1]->const_item())) { format= args[1]->val_str(&format_str); cached_format_type= check_result_type(format->ptr(), format->length()); switch (cached_format_type) { case DATE_ONLY: - cached_timestamp_type= TIMESTAMP_DATE; + cached_timestamp_type= MYSQL_TIMESTAMP_DATE; cached_field_type= MYSQL_TYPE_DATE; max_length= MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; break; case TIME_ONLY: case TIME_MICROSECOND: - cached_timestamp_type= TIMESTAMP_TIME; + cached_timestamp_type= MYSQL_TIMESTAMP_TIME; cached_field_type= MYSQL_TYPE_TIME; max_length= MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; break; default: - cached_timestamp_type= TIMESTAMP_DATETIME; + cached_timestamp_type= MYSQL_TIMESTAMP_DATETIME; cached_field_type= MYSQL_TYPE_DATETIME; break; } @@ -2724,7 +2828,7 @@ bool Item_func_str_to_date::get_date(TIME *ltime, uint fuzzy_date) if (extract_date_time(&date_time_format, val->ptr(), val->length(), ltime, cached_timestamp_type)) goto null_date; - if (cached_timestamp_type == TIMESTAMP_TIME && ltime->day) + if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day) { /* Day part for time type can be nonzero value and so @@ -2765,6 +2869,6 @@ bool Item_func_last_day::get_date(TIME *ltime, uint fuzzy_date) ltime->day= days_in_month[month_idx]; if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366) ltime->day= 29; - ltime->time_type= TIMESTAMP_DATE; + ltime->time_type= MYSQL_TIMESTAMP_DATE; return 0; } diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 263969cd26b..fe72ac6193b 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -348,6 +348,7 @@ public: Item_date_func() :Item_str_func() {} Item_date_func(Item *a) :Item_str_func(a) {} Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {} + Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {} enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } Field *tmp_table_field(TABLE *t_arg) { @@ -356,7 +357,7 @@ public: }; -/* Abstract CURTIME function. Children should define what timezone is used */ +/* Abstract CURTIME function. Children should define what time zone is used */ class Item_func_curtime :public Item_func { @@ -378,10 +379,10 @@ public: } /* Abstract method that defines which time zone is used for conversion. - Converts time from time_t representation to broken down representation - in struct tm using gmtime_r or localtime_r functions. + Converts time current time in my_time_t representation to broken-down + TIME representation using UTC-SYSTEM or per-thread time zone. */ - virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; + virtual void store_now_in_TIME(TIME *now_time)=0; }; @@ -391,7 +392,7 @@ public: Item_func_curtime_local() :Item_func_curtime() {} Item_func_curtime_local(Item *a) :Item_func_curtime(a) {} const char *func_name() const { return "curtime"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + virtual void store_now_in_TIME(TIME *now_time); }; @@ -401,7 +402,7 @@ public: Item_func_curtime_utc() :Item_func_curtime() {} Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {} const char *func_name() const { return "utc_time"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + virtual void store_now_in_TIME(TIME *now_time); }; @@ -413,12 +414,11 @@ class Item_func_curdate :public Item_date TIME ltime; public: Item_func_curdate() :Item_date() {} - void set_result_from_tm(struct tm *now); longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; } String *val_str(String *str); void fix_length_and_dec(); bool get_date(TIME *res, uint fuzzy_date); - virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; + virtual void store_now_in_TIME(TIME *now_time)=0; }; @@ -427,7 +427,7 @@ class Item_func_curdate_local :public Item_func_curdate public: Item_func_curdate_local() :Item_func_curdate() {} const char *func_name() const { return "curdate"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + void store_now_in_TIME(TIME *now_time); }; @@ -436,7 +436,7 @@ class Item_func_curdate_utc :public Item_func_curdate public: Item_func_curdate_utc() :Item_func_curdate() {} const char *func_name() const { return "utc_date"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + void store_now_in_TIME(TIME *now_time); }; @@ -458,7 +458,7 @@ public: String *val_str(String *str); void fix_length_and_dec(); bool get_date(TIME *res, uint fuzzy_date); - virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; + virtual void store_now_in_TIME(TIME *now_time)=0; }; @@ -468,7 +468,7 @@ public: Item_func_now_local() :Item_func_now() {} Item_func_now_local(Item *a) :Item_func_now(a) {} const char *func_name() const { return "now"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + virtual void store_now_in_TIME(TIME *now_time); virtual enum Functype functype() const { return NOW_FUNC; } }; @@ -479,7 +479,7 @@ public: Item_func_now_utc() :Item_func_now() {} Item_func_now_utc(Item *a) :Item_func_now(a) {} const char *func_name() const { return "utc_timestamp"; } - void store_now_in_tm(time_t now, struct tm *now_tm); + virtual void store_now_in_TIME(TIME *now_time); }; @@ -509,6 +509,7 @@ public: class Item_func_from_unixtime :public Item_date_func { + THD *thd; public: Item_func_from_unixtime(Item *a) :Item_date_func(a) {} double val() @@ -519,12 +520,29 @@ class Item_func_from_unixtime :public Item_date_func longlong val_int(); String *val_str(String *str); const char *func_name() const { return "from_unixtime"; } - void fix_length_and_dec() - { - collation.set(&my_charset_bin); - decimals=0; - max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; - } + void fix_length_and_dec(); + bool get_date(TIME *res, uint fuzzy_date); +}; + + +/* + We need Time_zone class declaration for storing pointers in + Item_func_convert_tz. +*/ +class Time_zone; + +class Item_func_convert_tz :public Item_date_func +{ + THD *thd; + Time_zone *from_tz, *to_tz; + public: + Item_func_convert_tz(Item *a, Item *b, Item *c): + Item_date_func(a, b, c) {} + longlong val_int(); + double val() { return (double) val_int(); } + String *val_str(String *str); + const char *func_name() const { return "convert_tz"; } + void fix_length_and_dec(); bool get_date(TIME *res, uint fuzzy_date); }; diff --git a/sql/lex.h b/sql/lex.h index b72ba53ec7e..24a6431adf5 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -139,6 +139,7 @@ static SYMBOL symbols[] = { { "DAY_MICROSECOND", SYM(DAY_MICROSECOND_SYM)}, { "DAY_MINUTE", SYM(DAY_MINUTE_SYM)}, { "DAY_SECOND", SYM(DAY_SECOND_SYM)}, + { "DEALLOCATE", SYM(DEALLOCATE_SYM)}, { "DEC", SYM(DECIMAL_SYM)}, { "DECIMAL", SYM(DECIMAL_SYM)}, { "DECLARE", SYM(DECLARE_SYM)}, @@ -224,7 +225,7 @@ static SYMBOL symbols[] = { { "IGNORE", SYM(IGNORE_SYM)}, { "IMPORT", SYM(IMPORT)}, { "IN", SYM(IN_SYM)}, - { "INDEX", SYM(INDEX)}, + { "INDEX", SYM(INDEX_SYM)}, { "INDEXES", SYM(INDEXES)}, { "INFILE", SYM(INFILE)}, { "INNER", SYM(INNER_SYM)}, @@ -332,6 +333,7 @@ static SYMBOL symbols[] = { { "OFFSET", SYM(OFFSET_SYM)}, { "OLD_PASSWORD", SYM(OLD_PASSWORD)}, { "ON", SYM(ON)}, + { "ONE_SHOT", SYM(ONE_SHOT_SYM)}, { "OPEN", SYM(OPEN_SYM)}, { "OPTIMIZE", SYM(OPTIMIZE)}, { "OPTION", SYM(OPTION)}, @@ -347,6 +349,7 @@ static SYMBOL symbols[] = { { "POINT", SYM(POINT_SYM)}, { "POLYGON", SYM(POLYGON)}, { "PRECISION", SYM(PRECISION)}, + { "PREPARE", SYM(PREPARE_SYM)}, { "PREV", SYM(PREV_SYM)}, { "PRIMARY", SYM(PRIMARY_SYM)}, { "PRIVILEGES", SYM(PRIVILEGES)}, @@ -543,6 +546,7 @@ static SYMBOL sql_functions[] = { { "CONNECTION_ID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)}, { "CONTAINS", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_contains)}, { "CONV", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)}, + { "CONVERT_TZ", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_convert_tz)}, { "COUNT", SYM(COUNT_SYM)}, { "COS", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)}, { "COT", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)}, diff --git a/sql/log.cc b/sql/log.cc index a673e72e26c..225aaae0549 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -25,12 +25,14 @@ #include "mysql_priv.h" #include "sql_acl.h" #include "sql_repl.h" +#include "ha_innodb.h" // necessary to cut the binlog when crash recovery #include <my_dir.h> #include <stdarg.h> #include <m_ctype.h> // For test_if_number MYSQL_LOG mysql_log, mysql_slow_log, mysql_bin_log; +ulong sync_binlog_counter= 0; static bool test_if_number(const char *str, long *res, bool allow_wildcards); @@ -299,6 +301,7 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, if ((index_file_nr= my_open(index_file_name, O_RDWR | O_CREAT | O_BINARY , MYF(MY_WME))) < 0 || + my_sync(index_file_nr, MYF(MY_WME)) || init_io_cache(&index_file, index_file_nr, IO_SIZE, WRITE_CACHE, my_seek(index_file_nr,0L,MY_SEEK_END,MYF(0)), @@ -359,16 +362,21 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, goto err; bytes_written+= description_event_for_queue->get_event_len(); } - if (flush_io_cache(&log_file)) + if (flush_io_cache(&log_file) || + my_sync(log_file.file, MYF(MY_WME))) goto err; if (write_file_name_to_index_file) { - /* As this is a new log file, we write the file name to the index file */ + /* + As this is a new log file, we write the file name to the index + file. As every time we write to the index file, we sync it. + */ if (my_b_write(&index_file, (byte*) log_file_name, strlen(log_file_name)) || my_b_write(&index_file, (byte*) "\n", 1) || - flush_io_cache(&index_file)) + flush_io_cache(&index_file) || + my_sync(index_file.file, MYF(MY_WME))) goto err; } break; @@ -449,7 +457,8 @@ static bool copy_up_file_and_fill(IO_CACHE *index_file, my_off_t offset) goto err; } /* The following will either truncate the file or fill the end with \n' */ - if (my_chsize(file, offset - init_offset, '\n', MYF(MY_WME))) + if (my_chsize(file, offset - init_offset, '\n', MYF(MY_WME)) || + my_sync(file, MYF(MY_WME))) goto err; /* Reset data in old index cache */ @@ -1048,6 +1057,8 @@ void MYSQL_LOG::new_file(bool need_lock) open(old_name, save_log_type, new_name_ptr, index_file_name, io_cache_type, no_auto_events, max_size, 1); + if (this == &mysql_bin_log) + report_pos_in_innodb(); my_free(old_name,MYF(0)); end: @@ -1218,6 +1229,17 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command, } +inline bool sync_binlog(IO_CACHE *cache) +{ + if (sync_binlog_period == ++sync_binlog_counter && sync_binlog_period) + { + sync_binlog_counter= 0; + return my_sync(cache->file, MYF(MY_WME)); + } + return 0; +} + + /* Write an event to the binary log */ @@ -1285,6 +1307,54 @@ bool MYSQL_LOG::write(Log_event* event_info) if (thd) { +#if MYSQL_VERSION_ID < 50000 + /* + To make replication of charsets working in 4.1 we are writing values + of charset related variables before every statement in the binlog, + if values of those variables differ from global server-wide defaults. + We are using SET ONE_SHOT command so that the charset vars get reset + to default after the first non-SET statement. + In the next 5.0 this won't be needed as we will use the new binlog + format to store charset info. + */ + if ((thd->variables.character_set_client->number != + global_system_variables.collation_server->number) || + (thd->variables.character_set_client->number != + thd->variables.collation_connection->number) || + (thd->variables.collation_server->number != + thd->variables.collation_connection->number)) + { + char buf[200]; + int written= my_snprintf(buf, sizeof(buf)-1, + "SET ONE_SHOT CHARACTER_SET_CLIENT=%u,\ +COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", + (uint) thd->variables.character_set_client->number, + (uint) thd->variables.collation_connection->number, + (uint) thd->variables.collation_database->number, + (uint) thd->variables.collation_server->number); + Query_log_event e(thd, buf, written, 0); + e.set_log_pos(this); + if (e.write(file)) + goto err; + } + /* + We use the same ONE_SHOT trick for making replication of time zones + working in 4.1. Again in 5.0 we have better means for doing this. + */ + if (thd->time_zone_used && + thd->variables.time_zone != global_system_variables.time_zone) + { + char buf[MAX_TIME_ZONE_NAME_LENGTH + 26]; + char *buf_end= strxmov(buf, "SET ONE_SHOT TIME_ZONE='", + thd->variables.time_zone->get_name()->ptr(), + "'", NullS); + Query_log_event e(thd, buf, buf_end - buf, 0); + e.set_log_pos(this); + if (e.write(file)) + goto err; + } +#endif + if (thd->last_insert_id_used) { Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT, @@ -1398,9 +1468,9 @@ bool MYSQL_LOG::write(Log_event* event_info) if (file == &log_file) // we are writing to the real log (disk) { - if (flush_io_cache(file)) + if (flush_io_cache(file) || sync_binlog(file)) goto err; - + if (opt_using_transactions && !my_b_tell(&thd->transaction.trans_log)) { /* @@ -1413,6 +1483,30 @@ bool MYSQL_LOG::write(Log_event* event_info) if (event_info->get_type_code() == QUERY_EVENT || event_info->get_type_code() == EXEC_LOAD_EVENT) { +#ifndef DBUG_OFF + if (unlikely(opt_crash_binlog_innodb)) + { + /* + This option is for use in rpl_crash_binlog_innodb.test. + 1st we want to verify that Binlog_dump thread cannot send the + event now (because of LOCK_log): we here tell the Binlog_dump + thread to wake up, sleep for the slave to have time to possibly + receive data from the master (it should not), and then crash. + 2nd we want to verify that at crash recovery the rolled back + event is cut from the binlog. + */ + if (!(--opt_crash_binlog_innodb)) + { + signal_update(); + sleep(2); + fprintf(stderr,"This is a normal crash because of" + " --crash-binlog-innodb\n"); + assert(0); + } + DBUG_PRINT("info",("opt_crash_binlog_innodb: %d", + opt_crash_binlog_innodb)); + } +#endif error = ha_report_binlog_offset_and_commit(thd, log_file_name, file->pos_in_file); called_handler_commit=1; @@ -1558,7 +1652,8 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) commit_or_rollback ? 6 : 8, TRUE); qinfo.set_log_pos(this); - if (qinfo.write(&log_file) || flush_io_cache(&log_file)) + if (qinfo.write(&log_file) || flush_io_cache(&log_file) || + sync_binlog(&log_file)) goto err; } if (cache->error) // Error on read @@ -1567,6 +1662,22 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) write_error=1; // Don't give more errors goto err; } +#ifndef DBUG_OFF + if (unlikely(opt_crash_binlog_innodb)) + { + /* see the previous MYSQL_LOG::write() method for a comment */ + if (!(--opt_crash_binlog_innodb)) + { + signal_update(); + sleep(2); + fprintf(stderr, "This is a normal crash because of" + " --crash-binlog-innodb\n"); + assert(0); + } + DBUG_PRINT("info",("opt_crash_binlog_innodb: %d", + opt_crash_binlog_innodb)); + } +#endif if ((ha_report_binlog_offset_and_commit(thd, log_file_name, log_file.pos_in_file))) goto err; @@ -1979,4 +2090,138 @@ bool flush_error_log() } +/* + If the server has InnoDB on, and InnoDB has published the position of the + last committed transaction (which happens only if a crash recovery occured at + this startup) then truncate the previous binary log at the position given by + InnoDB. If binlog is shorter than the position, print a message to the error + log. + + SYNOPSIS + cut_spurious_tail() + + RETURN VALUES + 1 Error + 0 Ok +*/ + +bool MYSQL_LOG::cut_spurious_tail() +{ + int error= 0; + char llbuf1[22], llbuf2[22]; + ulonglong actual_size; + + DBUG_ENTER("cut_spurious_tail"); +#ifdef HAVE_INNOBASE_DB + if (have_innodb != SHOW_OPTION_YES) + DBUG_RETURN(0); + /* + This is the place where we use information from InnoDB to cut the + binlog. + */ + char *name= ha_innobase::get_mysql_bin_log_name(); + ulonglong pos= ha_innobase::get_mysql_bin_log_pos(); + if (name[0] == 0 || pos == ULONGLONG_MAX) + { + DBUG_PRINT("info", ("InnoDB has not set binlog info")); + DBUG_RETURN(0); + } + /* The binlog given by InnoDB normally is never an active binlog */ + if (is_open() && is_active(name)) + { + sql_print_error("Warning: after InnoDB crash recovery, InnoDB says that " + "the binary log of the previous run has the same name " + "'%s' as the current one; this is likely to be abnormal.", + name); + DBUG_RETURN(1); + } + sql_print_error("After InnoDB crash recovery, checking if the binary log " + "'%s' contains rolled back transactions which must be " + "removed from it...", name); + /* If we have a too long binlog, cut. If too short, print error */ + int fd= my_open(name, O_EXCL | O_APPEND | O_BINARY | O_WRONLY, MYF(MY_WME)); + if (fd < 0) + { + int save_errno= my_errno; + sql_print_error("Could not open the binary log '%s' for truncation.", + name); + if (save_errno != ENOENT) + sql_print_error("The binary log '%s' should not be used for " + "replication.", name); + DBUG_RETURN(1); + } + + if (pos > (actual_size= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME)))) + { + /* + Note that when we have MyISAM rollback this error message should be + reconsidered. + */ + sql_print_error("The binary log '%s' is shorter than its expected size " + "(actual: %s, expected: %s) so it misses at least one " + "committed transaction; so it should not be used for " + "replication or point-in-time recovery. You would need " + "to restart slaves from a fresh master's data " + "snapshot ", + name, llstr(actual_size, llbuf1), + llstr(pos, llbuf2)); + error= 1; + goto err; + } + if (pos < actual_size) + { + sql_print_error("The binary log '%s' is bigger than its expected size " + "(actual: %s, expected: %s) so it contains a rolled back " + "transaction; now truncating that.", name, + llstr(actual_size, llbuf1), llstr(pos, llbuf2)); + /* + As on some OS, my_chsize() can only pad with 0s instead of really + truncating. Then mysqlbinlog (and Binlog_dump thread) will error on + these zeroes. This is annoying, but not more (you just need to manually + switch replication to the next binlog). Fortunately, in my_chsize.c, it + says that all modern machines support real ftruncate(). + + */ + if ((error= my_chsize(fd, pos, 0, MYF(MY_WME)))) + goto err; + } +err: + if (my_close(fd, MYF(MY_WME))) + error= 1; +#endif + DBUG_RETURN(error); +} + + +/* + If the server has InnoDB on, store the binlog name and position into + InnoDB. This function is used every time we create a new binlog. + SYNOPSIS + report_pos_in_innodb() + + NOTES + This cannot simply be done in MYSQL_LOG::open(), because when we create + the first binlog at startup, we have not called ha_init() yet so we cannot + write into InnoDB yet. + + RETURN VALUES + 1 Error + 0 Ok +*/ + +void MYSQL_LOG::report_pos_in_innodb() +{ + DBUG_ENTER("report_pos_in_innodb"); +#ifdef HAVE_INNOBASE_DB + if (is_open() && have_innodb == SHOW_OPTION_YES) + { + DBUG_PRINT("info", ("Reporting binlog info into InnoDB - " + "name: '%s' position: %d", + log_file_name, my_b_tell(&log_file))); + innobase_store_binlog_offset_and_flush_log(log_file_name, + my_b_tell(&log_file)); + } +#endif + DBUG_VOID_RETURN; +} diff --git a/sql/log_event.cc b/sql/log_event.cc index b8d80883451..3b69e1c3176 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -203,6 +203,29 @@ static inline int read_str(char * &buf, char *buf_end, char * &str, } /* + Transforms a string into "" or its expression in 0x... form. +*/ +static char *str_to_hex(char *to, char *from, uint len) +{ + char *p= to; + if (len) + { + p= strmov(p, "0x"); + for (uint i= 0; i < len; i++, p+= 2) + { + /* val[i] is char. Casting to uchar helps greatly if val[i] < 0 */ + uint tmp= (uint) (uchar) from[i]; + p[0]= _dig_vec_upper[tmp >> 4]; + p[1]= _dig_vec_upper[tmp & 15]; + } + *p= 0; + } + else + p= strmov(p, "\"\""); + return p; // pointer to end 0 of 'to' +} + +/* Prints a "session_var=value" string. Used by mysqlbinlog to print some SET commands just before it prints a query. */ @@ -607,6 +630,7 @@ end: #else #define UNLOCK_MUTEX #define LOCK_MUTEX +#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) #endif /* @@ -2910,7 +2934,7 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli) void User_var_log_event::pack_info(Protocol* protocol) { char *buf= 0; - uint val_offset= 2 + name_len; + uint val_offset= 4 + name_len; uint event_len= val_offset; if (is_null) @@ -2934,16 +2958,21 @@ void User_var_log_event::pack_info(Protocol* protocol) event_len= longlong10_to_str(uint8korr(val), buf + val_offset,-10)-buf; break; case STRING_RESULT: - /* - This is correct as pack_info is used for SHOW BINLOG command - only. But be carefull this is may be incorrect in other cases as - string may contain \ and '. - */ - event_len= val_offset + 2 + val_len; - buf= my_malloc(event_len, MYF(MY_WME)); - buf[val_offset]= '\''; - memcpy(buf + val_offset + 1, val, val_len); - buf[val_offset + val_len + 1]= '\''; + /* 15 is for 'COLLATE' and other chars */ + buf= my_malloc(event_len+val_len*2+1+2*MY_CS_NAME_SIZE+15, MYF(MY_WME)); + CHARSET_INFO *cs; + if (!(cs= get_charset(charset_number, MYF(0)))) + { + strmov(buf+val_offset, "???"); + event_len+= 3; + } + else + { + char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NullS); + p= str_to_hex(p, val, val_len); + p= strxmov(p, " COLLATE ", cs->name, NullS); + event_len= p-buf; + } break; case ROW_RESULT: default: @@ -2952,8 +2981,10 @@ void User_var_log_event::pack_info(Protocol* protocol) } } buf[0]= '@'; - buf[1+name_len]= '='; - memcpy(buf+1, name, name_len); + buf[1]= '`'; + buf[2+name_len]= '`'; + buf[3+name_len]= '='; + memcpy(buf+2, name, name_len); protocol->store(buf, event_len, &my_charset_bin); my_free(buf, MYF(MY_ALLOW_ZERO_PTR)); } @@ -3046,8 +3077,9 @@ void User_var_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* las fprintf(file, "\tUser_var\n"); } - fprintf(file, "SET @"); + fprintf(file, "SET @`"); my_fwrite(file, (byte*) name, (uint) (name_len), MYF(MY_NABP | MY_WME)); + fprintf(file, "`"); if (is_null) { @@ -3067,7 +3099,42 @@ void User_var_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* las fprintf(file, ":=%s;\n", int_buf); break; case STRING_RESULT: - fprintf(file, ":='%s';\n", val); + { + /* + Let's express the string in hex. That's the most robust way. If we + print it in character form instead, we need to escape it with + character_set_client which we don't know (we will know it in 5.0, but + in 4.1 we don't know it easily when we are printing + User_var_log_event). Explanation why we would need to bother with + character_set_client (quoting Bar): + > Note, the parser doesn't switch to another unescaping mode after + > it has met a character set introducer. + > For example, if an SJIS client says something like: + > SET @a= _ucs2 \0a\0b' + > the string constant is still unescaped according to SJIS, not + > according to UCS2. + */ + char *p, *q; + if (!(p= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits per byte + break; // no error, as we are 'void' + str_to_hex(p, val, val_len); + /* + For proper behaviour when mysqlbinlog|mysql, we need to explicitely + specify the variable's collation. It will however cause problems when + people want to mysqlbinlog|mysql into another server not supporting the + character set. But there's not much to do about this and it's unlikely. + */ + CHARSET_INFO *cs; + if (!(cs= get_charset(charset_number, MYF(0)))) + /* + Generate an unusable command (=> syntax error) is probably the best + thing we can do here. + */ + fprintf(file, ":=???;\n"); + else + fprintf(file, ":=_%s %s COLLATE %s;\n", cs->csname, p, cs->name); + my_afree(p); + } break; case ROW_RESULT: default: @@ -3088,7 +3155,9 @@ void User_var_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* las int User_var_log_event::exec_event(struct st_relay_log_info* rli) { Item *it= 0; - CHARSET_INFO *charset= get_charset(charset_number, MYF(0)); + CHARSET_INFO *charset; + if (!(charset= get_charset(charset_number, MYF(MY_WME)))) + return 1; LEX_STRING user_var_name; user_var_name.str= name; user_var_name.length= name_len; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index c8b57d9fb55..792b1a1189f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -24,10 +24,10 @@ #ifndef MYSQL_CLIENT #include <my_global.h> -#include <assert.h> #include <mysql_version.h> #include <mysql_embed.h> #include <my_sys.h> +#include <my_time.h> #include <m_string.h> #include <hash.h> #include <signal.h> @@ -388,7 +388,9 @@ inline THD *_current_thd(void) #include "field.h" /* Field definitions */ #include "protocol.h" #include "sql_udf.h" +class user_var_entry; #include "item.h" +#include "tztime.h" typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); /* sql_parse.cc */ void free_items(Item *item); @@ -418,6 +420,7 @@ struct Query_cache_query_flags uint character_set_results_num; uint collation_connection_num; ha_rows limit; + Time_zone *time_zone; }; #define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags) #include "sql_cache.h" @@ -570,7 +573,8 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name, List<Key> &keys, uint order_num, ORDER *order, enum enum_duplicates handle_duplicates, - ALTER_INFO *alter_info); + ALTER_INFO *alter_info, bool do_send_ok=1); +int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok); int mysql_create_like_table(THD *thd, TABLE_LIST *table, HA_CREATE_INFO *create_info, Table_ident *src_table); @@ -679,8 +683,10 @@ int mysqld_show_column_types(THD *thd); int mysqld_help (THD *thd, const char *text); /* sql_prepare.cc */ -void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length); +int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, + LEX_STRING *name=NULL); void mysql_stmt_execute(THD *thd, char *packet, uint packet_length); +void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name); void mysql_stmt_free(THD *thd, char *packet); void mysql_stmt_reset(THD *thd, char *packet); void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length); @@ -698,8 +704,9 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show); /* 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); -int mysql_ha_closeall(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_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows); @@ -862,7 +869,7 @@ extern Le_creator le_creator; extern uchar *days_in_month; extern char language[LIBLEN],reg_ext[FN_EXTLEN]; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; -extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file; +extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char log_error_file[FN_REFLEN]; extern double last_query_cost; extern double log_10[32]; @@ -899,8 +906,8 @@ extern ulong max_binlog_size, max_relay_log_size; extern ulong rpl_recovery_rank, thread_cache_size; extern ulong com_stat[(uint) SQLCOM_END], com_other, back_log; extern ulong specialflag, current_pid; -extern ulong expire_logs_days; -extern my_bool relay_log_purge; +extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter; +extern my_bool relay_log_purge, opt_innodb_safe_binlog; extern uint test_flags,select_errors,ha_open_options; extern uint protocol_version, mysqld_port, dropping_tables; extern uint delay_key_write_options, lower_case_table_names; @@ -918,8 +925,10 @@ extern my_bool opt_slave_compressed_protocol, use_temp_pool; extern my_bool opt_readonly, lower_case_file_system; extern my_bool opt_enable_named_pipe, opt_sync_frm; extern my_bool opt_secure_auth; +extern uint opt_crash_binlog_innodb; extern char *shared_memory_base_name, *mysqld_unix_port; extern bool opt_enable_shared_memory; +extern char *default_tz_name; extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; extern FILE *bootstrap_file; @@ -960,9 +969,11 @@ extern struct my_option my_long_options[]; /* optional things, have_* variables */ -extern SHOW_COMP_OPTION have_isam, have_innodb, have_berkeley_db, have_example_db; +extern SHOW_COMP_OPTION have_isam, have_innodb, have_berkeley_db; +extern SHOW_COMP_OPTION have_example_db, have_archive_db; extern SHOW_COMP_OPTION have_raid, have_openssl, have_symlink; extern SHOW_COMP_OPTION have_query_cache, have_berkeley_db, have_innodb; +extern SHOW_COMP_OPTION have_geometry, have_rtree_keys; extern SHOW_COMP_OPTION have_crypt; extern SHOW_COMP_OPTION have_compress; @@ -1028,12 +1039,13 @@ uint calc_days_in_year(uint year); void get_date_from_daynr(long daynr,uint *year, uint *month, uint *day); void init_time(void); -long my_gmt_sec(TIME *, long *current_timezone); -time_t str_to_timestamp(const char *str,uint length); -bool str_to_time(const char *str,uint length,TIME *l_time); -longlong str_to_datetime(const char *str,uint length, uint fuzzy_date); -timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time, - uint flags); +my_time_t my_system_gmt_sec(const TIME *, long *current_timezone, bool *not_exist); +my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *not_exist); +bool str_to_time_with_warn(const char *str,uint length,TIME *l_time); +timestamp_type str_to_datetime_with_warn(const char *str, uint length, + TIME *l_time, uint flags); +longlong number_to_TIME(longlong nr, TIME *time_res, bool fuzzy_date, + int *was_cut); void localtime_to_TIME(TIME *to, struct tm *from); void calc_time_from_sec(TIME *to, long seconds, long microseconds); @@ -1112,6 +1124,9 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, LEX_STRING component); Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name, uint length, const char *item_name); +/* item_func.cc */ +int get_var_with_binlog(THD *thd, LEX_STRING &name, + user_var_entry **out_entry); /* log.cc */ bool flush_error_log(void); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e4302a4a9ad..564a8090b23 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -50,10 +50,6 @@ #define ONE_THREAD #endif -#define SHUTDOWN_THD -#define MAIN_THD -#define SIGNAL_THD - #ifdef HAVE_purify #define IF_PURIFY(A,B) (A) #else @@ -276,11 +272,13 @@ my_bool opt_secure_auth= 0; my_bool opt_short_log_format= 0; my_bool opt_log_queries_not_using_indexes= 0; my_bool lower_case_file_system= 0; +my_bool opt_innodb_safe_binlog= 0; volatile bool mqh_used = 0; uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options; uint delay_key_write_options, protocol_version; uint lower_case_table_names; +uint opt_crash_binlog_innodb; uint volatile thread_count, thread_running, kill_cached_threads, wake_thread; ulong back_log, connect_timeout, concurrency; @@ -309,7 +307,7 @@ ulong binlog_cache_use= 0, binlog_cache_disk_use= 0; ulong max_connections,max_used_connections, max_connect_errors, max_user_connections = 0; ulong thread_id=1L,current_pid; -ulong slow_launch_threads = 0; +ulong slow_launch_threads = 0, sync_binlog_period; ulong expire_logs_days = 0; ulong rpl_recovery_rank=0; ulong my_bind_addr; /* the address we bind to */ @@ -317,23 +315,15 @@ volatile ulong cached_thread_count= 0; double last_query_cost= -1; /* -1 denotes that no query was compiled yet */ double log_10[32]; /* 10 potences */ -ulonglong log_10_int[20]= -{ - 1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL, - ULL(100000000), ULL(1000000000), ULL(10000000000), ULL(100000000000), - ULL(1000000000000), ULL(10000000000000), ULL(100000000000000), - ULL(1000000000000000), ULL(10000000000000000), ULL(100000000000000000), - ULL(1000000000000000000), ULL(10000000000000000000) -}; - time_t start_time; -char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], time_zone[30]; +char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30]; +char *default_tz_name; char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN]; char* log_error_file_ptr= log_error_file; char mysql_real_data_home[FN_REFLEN], language[LIBLEN],reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN], - max_sort_char,*mysqld_user,*mysqld_chroot, *opt_init_file, + *mysqld_user,*mysqld_chroot, *opt_init_file, *opt_init_connect, *opt_init_slave, def_ft_boolean_syntax[sizeof(ft_boolean_syntax)]; @@ -379,9 +369,10 @@ KEY_CACHE *sql_key_cache; CHARSET_INFO *system_charset_info, *files_charset_info ; CHARSET_INFO *national_charset_info, *table_alias_charset; -SHOW_COMP_OPTION have_berkeley_db, have_innodb, have_isam, - have_ndbcluster, have_example_db; +SHOW_COMP_OPTION have_berkeley_db, have_innodb, have_isam, have_ndbcluster, + have_example_db, have_archive_db; SHOW_COMP_OPTION have_raid, have_openssl, have_symlink, have_query_cache; +SHOW_COMP_OPTION have_geometry, have_rtree_keys; SHOW_COMP_OPTION have_crypt, have_compress; /* Thread specific variables */ @@ -665,7 +656,7 @@ static void close_connections(void) break; } #ifndef __bsdi__ // Bug in BSDI kernel - if (tmp->net.vio) + if (tmp->vio_ok()) { sql_print_error(ER(ER_FORCING_CLOSE),my_progname, tmp->thread_id,tmp->user ? tmp->user : ""); @@ -831,7 +822,6 @@ static void __cdecl kill_server(int sig_ptr) #if defined(USE_ONE_SIGNAL_HAND) || (defined(__NETWARE__) && defined(SIGNALS_DONT_BREAK_READ)) extern "C" pthread_handler_decl(kill_server_thread,arg __attribute__((unused))) { - SHUTDOWN_THD; my_thread_init(); // Initialize new thread kill_server(0); my_thread_end(); // Normally never reached @@ -914,6 +904,7 @@ void clean_up(bool print_message) if (use_slave_mask) bitmap_free(&slave_error_mask); #endif + my_tz_free(); #ifndef NO_EMBEDDED_ACCESS_CHECKS acl_free(1); grant_free(); @@ -1259,6 +1250,12 @@ static void server_init(void) { DBUG_PRINT("general",("UNIX Socket is %s",mysqld_unix_port)); + if (strlen(mysqld_unix_port) > (sizeof(UNIXaddr.sun_path) - 1)) + { + sql_print_error("The socket file path is too long (> %d): %s", + sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port); + unireg_abort(1); + } if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { sql_perror("Can't start server : UNIX Socket "); /* purecov: inspected */ @@ -1507,7 +1504,7 @@ void mysql_cb_init() } -/ *To get the name of the NetWare volume having MySQL data folder */ +/* To get the name of the NetWare volume having MySQL data folder */ static void getvolumename() { @@ -1578,6 +1575,7 @@ static void registerwithneb() /* Callback for NSS Volume Deactivation event */ + ulong neb_event_callback(struct EventBlock *eblock) { EventChangeVolStateEnter_s *voldata; @@ -1606,7 +1604,7 @@ ulong neb_event_callback(struct EventBlock *eblock) #define ADMIN_VOL_PATH "_ADMIN:/Volumes/" -staticvoid getvolumeID(BYTE *volumeName) +static void getvolumeID(BYTE *volumeName) { char path[zMAX_FULL_NAME]; Key_t rootKey= 0, fileKey= 0; @@ -1614,7 +1612,7 @@ staticvoid getvolumeID(BYTE *volumeName) zInfo_s info; STATUS status; - /* Get the root key */ + /* Get the root key */ if ((status= zRootKey(0, &rootKey)) != zOK) { consoleprintf("\nGetNSSVolumeProperties - Failed to get root key, status: %d\n.", (int) status); @@ -1718,7 +1716,6 @@ static void init_signals(void) signal(SIGALRM, SIG_IGN); signal(SIGBREAK,SIG_IGN); signal_thread = pthread_self(); - SIGNAL_THD; } static void start_signal_handler(void) @@ -2122,7 +2119,6 @@ int uname(struct utsname *a) extern "C" pthread_handler_decl(handle_shutdown,arg) { MSG msg; - SHUTDOWN_THD; my_thread_init(); /* this call should create the message queue for this thread */ @@ -2151,7 +2147,6 @@ int STDCALL handle_kill(ulong ctrl_type) #ifdef OS2 extern "C" pthread_handler_decl(handle_shutdown,arg) { - SHUTDOWN_THD; my_thread_init(); // wait semaphore @@ -2276,9 +2271,17 @@ static int init_common_variables(const char *conf_file_name, int argc, { struct tm tm_tmp; localtime_r(&start_time,&tm_tmp); - strmov(time_zone,tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]); + strmov(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]); } #endif + /* + We set SYSTEM time zone as reasonable default and + also for failure of my_tz_init() and bootstrap mode. + If user explicitly set time zone with --default-time-zone + option we will change this value in my_tz_init(). + */ + global_system_variables.time_zone= my_tz_SYSTEM; + /* Init mutexes for the global MYSQL_LOG objects. @@ -2584,6 +2587,41 @@ server."); } } + if (opt_innodb_safe_binlog) + { + if (have_innodb != SHOW_OPTION_YES) + sql_print_error("Warning: --innodb-safe-binlog is meaningful only if " + "the InnoDB storage engine is enabled in the server."); +#ifdef HAVE_INNOBASE_DB + if (innobase_flush_log_at_trx_commit != 1) + { + sql_print_error("Warning: --innodb-safe-binlog is meaningful only if " + "innodb_flush_log_at_trx_commit is 1; now setting it " + "to 1."); + innobase_flush_log_at_trx_commit= 1; + } + if (innobase_unix_file_flush_method) + { + /* + This option has so many values that it's hard to know which value is + good (especially "littlesync", and on Windows... see + srv/srv0start.c). + */ + sql_print_error("Warning: --innodb-safe-binlog requires that " + "the innodb_flush_method actually synchronizes the " + "InnoDB log to disk; it is your responsibility " + "to verify that the method you chose does it."); + } + if (sync_binlog_period != 1) + { + sql_print_error("Warning: --innodb-safe-binlog is meaningful only if " + "the global sync_binlog variable is 1; now setting it " + "to 1."); + sync_binlog_period= 1; + } +#endif + } + if (ha_init()) { sql_print_error("Can't init databases"); @@ -2592,6 +2630,18 @@ server."); if (opt_myisam_log) (void) mi_log(1); + /* + Now that InnoDB is initialized, we can know the last good binlog position + and cut the binlog if needed. This function does nothing if there was no + crash recovery by InnoDB. + */ + if (opt_innodb_safe_binlog) + { + /* not fatal if fails (but print errors) */ + mysql_bin_log.cut_spurious_tail(); + } + mysql_bin_log.report_pos_in_innodb(); + /* call ha_init_key_cache() on all key caches to init them */ process_key_caches(&ha_init_key_cache); /* We must set dflt_key_cache in case we are using ISAM tables */ @@ -2862,7 +2912,8 @@ we force server id to 2, but this MySQL server will not act as a slave."); */ error_handler_hook = my_message_sql; start_signal_handler(); // Creates pidfile - if (acl_init((THD *)0, opt_noacl)) + if (acl_init((THD *)0, opt_noacl) || + my_tz_init((THD *)0, default_tz_name, opt_bootstrap)) { abort_loop=1; select_thread_in_use=0; @@ -3069,7 +3120,7 @@ int main(int argc, char **argv) need to have an unique named hEventShudown through the application PID e.g.: MySQLShutdown1890; MySQLShutdown2342 */ - int2str((int) GetCurrentProcessId(),strmov(shutdown_event_name, + int10_to_str((int) GetCurrentProcessId(),strmov(shutdown_event_name, "MySQLShutdown"), 10); /* Must be initialized early for comparison of service name */ @@ -3713,7 +3764,7 @@ pthread_handler_decl(handle_connections_shared_memory,arg) HANDLE event_server_read= 0; THD *thd= 0; - p= int2str(connect_number, connect_number_char, 10); + p= int10_to_str(connect_number, connect_number_char, 10); /* The name of event and file-mapping events create agree next rule: shared_memory_base_name+unique_part+number_of_connection @@ -3890,8 +3941,8 @@ enum options_mysqld OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT, OPT_INNODB_FLUSH_METHOD, OPT_INNODB_FAST_SHUTDOWN, - OPT_INNODB_FILE_PER_TABLE, - OPT_SAFE_SHOW_DB, + OPT_INNODB_FILE_PER_TABLE, OPT_CRASH_BINLOG_INNODB, + OPT_SAFE_SHOW_DB, OPT_INNODB_SAFE_BINLOG, OPT_INNODB, OPT_ISAM, OPT_NDBCLUSTER, OPT_SKIP_SAFEMALLOC, OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS, @@ -3961,7 +4012,7 @@ enum options_mysqld OPT_RANGE_ALLOC_BLOCK_SIZE, OPT_QUERY_ALLOC_BLOCK_SIZE, OPT_QUERY_PREALLOC_SIZE, OPT_TRANS_ALLOC_BLOCK_SIZE, OPT_TRANS_PREALLOC_SIZE, - OPT_SYNC_FRM, OPT_BDB_NOSYNC, + OPT_SYNC_FRM, OPT_SYNC_BINLOG, OPT_BDB_NOSYNC, OPT_ENABLE_SHARED_MEMORY, OPT_SHARED_MEMORY_BASE_NAME, OPT_OLD_PASSWORDS, @@ -3975,6 +4026,7 @@ enum options_mysqld OPT_TIME_FORMAT, OPT_DATETIME_FORMAT, OPT_LOG_QUERIES_NOT_USING_INDEXES, + OPT_DEFAULT_TIME_ZONE, OPT_OPTIMIZER_SEARCH_DEPTH, OPT_OPTIMIZER_PRUNE_LEVEL }; @@ -4038,6 +4090,12 @@ Disable with --skip-bdb (will save memory).", REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"bootstrap", OPT_BOOTSTRAP, "Used by mysql installation scripts.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"character_set_server", 'C', "Set the default character set.", + (gptr*) &default_character_set_name, (gptr*) &default_character_set_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + {"collation_server", OPT_DEFAULT_COLLATION, "Set the default collation.", + (gptr*) &default_collation_name, (gptr*) &default_collation_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"console", OPT_CONSOLE, "Write error output on screen; Don't remove the console window on windows.", (gptr*) &opt_console, (gptr*) &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -4071,10 +4129,10 @@ Disable with --skip-bdb (will save memory).", (gptr*) &des_key_file, (gptr*) &des_key_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif /* HAVE_OPENSSL */ - {"default-character-set", 'C', "Set the default character set.", + {"default-character-set", 'C', "Set the default character set (Deprecated option, use character_set_server instead).", (gptr*) &default_character_set_name, (gptr*) &default_character_set_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, - {"default-collation", OPT_DEFAULT_COLLATION, "Set the default collation.", + {"default-collation", OPT_DEFAULT_COLLATION, "Set the default collation (Deprecated option, use character_set_server instead).", (gptr*) &default_collation_name, (gptr*) &default_collation_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"default-storage-engine", OPT_STORAGE_ENGINE, @@ -4083,6 +4141,9 @@ Disable with --skip-bdb (will save memory).", {"default-table-type", OPT_STORAGE_ENGINE, "(deprecated) Use default-storage-engine.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"default-time-zone", OPT_DEFAULT_TIME_ZONE, "Set the default time zone.", + (gptr*) &default_tz_name, (gptr*) &default_tz_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"delay-key-write", OPT_DELAY_KEY_WRITE, "Type of DELAY_KEY_WRITE.", 0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"delay-key-write-for-all-tables", OPT_DELAY_KEY_WRITE_ALL, @@ -4529,11 +4590,11 @@ log and this option does nothing anymore.", NO_ARG, 0, 0, 0, 0, 0, 0}, {"log-warnings", 'W', "Log some not critical warnings to the log file.", (gptr*) &global_system_variables.log_warnings, - (gptr*) &max_system_variables.log_warnings, 0, GET_BOOL, NO_ARG, 1, 0, 0, + (gptr*) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG, 1, 0, 0, 0, 0, 0}, {"warnings", 'W', "Deprecated ; Use --log-warnings instead.", (gptr*) &global_system_variables.log_warnings, - (gptr*) &max_system_variables.log_warnings, 0, GET_BOOL, NO_ARG, 1, 0, 0, + (gptr*) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG, 1, 0, 0, 0, 0, 0}, { "back_log", OPT_BACK_LOG, "The number of outstanding connection requests MySQL can have. This comes into play when the main MySQL thread gets very many connection requests in a very short time.", @@ -4565,6 +4626,12 @@ log and this option does nothing anymore.", "The number of seconds the mysqld server is waiting for a connect packet before responding with 'Bad handshake'.", (gptr*) &connect_timeout, (gptr*) &connect_timeout, 0, GET_ULONG, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 }, +#ifdef HAVE_REPLICATION + {"crash_binlog_innodb", OPT_CRASH_BINLOG_INNODB, + "Used only for testing, to crash when writing Nth event to binlog.", + (gptr*) &opt_crash_binlog_innodb, (gptr*) &opt_crash_binlog_innodb, + 0, GET_UINT, REQUIRED_ARG, 0, 0, ~(uint)0, 0, 1, 0}, +#endif {"delayed_insert_timeout", OPT_DELAYED_INSERT_TIMEOUT, "How long a INSERT DELAYED thread should wait for INSERT statements before terminating.", (gptr*) &delayed_insert_timeout, (gptr*) &delayed_insert_timeout, 0, @@ -4644,6 +4711,26 @@ log and this option does nothing anymore.", "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back.", (gptr*) &innobase_lock_wait_timeout, (gptr*) &innobase_lock_wait_timeout, 0, GET_LONG, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0}, +#ifdef HAVE_REPLICATION + /* + Disabled for the 4.1.3 release. Disabling just this paragraph of code is + enough, as then user can't set it to 1 so it will always be ignored in the + rest of code. + */ +#if MYSQL_VERSION_ID >= 40103 + /* + innodb_safe_binlog is not a variable, just an option. Does not make + sense to make it a variable, as it is only used at startup (and so the + value would be lost at next startup, so setting it on the fly would have no + effect). + */ + {"innodb_safe_binlog", OPT_INNODB_SAFE_BINLOG, + "After a crash recovery by InnoDB, truncate the binary log after the last " + "not-rolled-back statement/transaction.", + (gptr*) &opt_innodb_safe_binlog, (gptr*) &opt_innodb_safe_binlog, + 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0}, +#endif +#endif {"innodb_thread_concurrency", OPT_INNODB_THREAD_CONCURRENCY, "Helps in performance tuning in heavily concurrent environments.", (gptr*) &innobase_thread_concurrency, (gptr*) &innobase_thread_concurrency, @@ -4950,6 +5037,12 @@ The minimum value for this variable is 4096.", (gptr*) &max_system_variables.sortbuff_size, 0, GET_ULONG, REQUIRED_ARG, MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, ~0L, MALLOC_OVERHEAD, 1, 0}, + {"sync-binlog", OPT_SYNC_BINLOG, + "Sync the binlog to disk after every #th event. \ +#=0 (the default) does no sync. Syncing slows MySQL down", + (gptr*) &sync_binlog_period, + (gptr*) &sync_binlog_period, 0, GET_ULONG, REQUIRED_ARG, 0, 0, ~0L, 0, 1, + 0}, {"table_cache", OPT_TABLE_CACHE, "The number of open tables for all threads.", (gptr*) &table_cache_size, (gptr*) &table_cache_size, 0, GET_ULONG, REQUIRED_ARG, 64, 1, 512*1024L, @@ -4999,18 +5092,18 @@ The minimum value for this variable is 4096.", 0, GET_ULONG, REQUIRED_ARG, 0, 0, 7L, 0, 1, 0}, { "date-format", OPT_DATE_FORMAT, "The DATE format (For future).", - (gptr*) &opt_date_time_formats[TIMESTAMP_DATE], - (gptr*) &opt_date_time_formats[TIMESTAMP_DATE], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE], 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { "datetime-format", OPT_DATETIME_FORMAT, "The DATETIME/TIMESTAMP format (for future).", - (gptr*) &opt_date_time_formats[TIMESTAMP_DATETIME], - (gptr*) &opt_date_time_formats[TIMESTAMP_DATETIME], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_DATETIME], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_DATETIME], 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { "time-format", OPT_TIME_FORMAT, "The TIME format (for future).", - (gptr*) &opt_date_time_formats[TIMESTAMP_TIME], - (gptr*) &opt_date_time_formats[TIMESTAMP_TIME], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_TIME], + (gptr*) &opt_date_time_formats[MYSQL_TIMESTAMP_TIME], 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -5107,6 +5200,12 @@ struct show_var_st status_vars[]= { {"Com_unlock_tables", (char*) (com_stat+(uint) SQLCOM_UNLOCK_TABLES),SHOW_LONG}, {"Com_update", (char*) (com_stat+(uint) SQLCOM_UPDATE),SHOW_LONG}, {"Com_update_multi", (char*) (com_stat+(uint) SQLCOM_UPDATE_MULTI),SHOW_LONG}, + {"Com_prepare_sql", (char*) (com_stat+(uint) SQLCOM_PREPARE), + SHOW_LONG}, + {"Com_execute_sql", (char*) (com_stat+(uint) SQLCOM_EXECUTE), + SHOW_LONG}, + {"Com_dealloc_sql", (char*) (com_stat+(uint) + SQLCOM_DEALLOCATE_PREPARE), SHOW_LONG}, {"Connections", (char*) &thread_id, SHOW_LONG_CONST}, {"Created_tmp_disk_tables", (char*) &created_tmp_disk_tables,SHOW_LONG}, {"Created_tmp_files", (char*) &my_tmp_file_created, SHOW_LONG}, @@ -5322,7 +5421,6 @@ static void mysql_init_variables(void) specialflag= opened_tables= created_tmp_tables= created_tmp_disk_tables= 0; binlog_cache_use= binlog_cache_disk_use= 0; max_used_connections= slow_launch_threads = 0; - max_sort_char= 0; mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0; errmesg= 0; mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS; @@ -5429,6 +5527,11 @@ static void mysql_init_variables(void) #else have_example_db= SHOW_OPTION_NO; #endif +#ifdef HAVE_ARCHIVE_DB + have_archive_db= SHOW_OPTION_YES; +#else + have_archive_db= SHOW_OPTION_NO; +#endif #ifdef HAVE_NDBCLUSTER_DB have_ndbcluster=SHOW_OPTION_DISABLED; #else @@ -5454,6 +5557,16 @@ static void mysql_init_variables(void) #else have_query_cache=SHOW_OPTION_NO; #endif +#ifdef HAVE_SPATIAL + have_geometry=SHOW_OPTION_YES; +#else + have_geometry=SHOW_OPTION_NO; +#endif +#ifdef HAVE_RTREE_KEYS + have_rtree_keys=SHOW_OPTION_YES; +#else + have_rtree_keys=SHOW_OPTION_NO; +#endif #ifdef HAVE_CRYPT have_crypt=SHOW_OPTION_YES; #else @@ -5525,7 +5638,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), mysql_data_home= mysql_real_data_home; break; case 'u': - if (!mysqld_user) + if (!mysqld_user || !strcmp(mysqld_user, argument)) mysqld_user= argument; else fprintf(stderr, "Warning: Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user); @@ -5555,6 +5668,14 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'V': print_version(); exit(0); + case 'W': + if (!argument) + global_system_variables.log_warnings++; + else if (argument == disabled_my_option) + global_system_variables.log_warnings= 0L; + else + global_system_variables.log_warnings= atoi(argument); + break; case 'T': test_flags= argument ? (uint) atoi(argument) : 0; test_flags&= ~TEST_NO_THREADS; @@ -6089,11 +6210,11 @@ static void get_options(int argc,char **argv) if (opt_log_queries_not_using_indexes) opt_specialflag|= SPECIAL_LOG_QUERIES_NOT_USING_INDEXES; - if (init_global_datetime_format(TIMESTAMP_DATE, + if (init_global_datetime_format(MYSQL_TIMESTAMP_DATE, &global_system_variables.date_format) || - init_global_datetime_format(TIMESTAMP_TIME, + init_global_datetime_format(MYSQL_TIMESTAMP_TIME, &global_system_variables.time_format) || - init_global_datetime_format(TIMESTAMP_DATETIME, + init_global_datetime_format(MYSQL_TIMESTAMP_DATETIME, &global_system_variables.datetime_format)) exit(1); } @@ -6316,7 +6437,7 @@ static void create_pid_file() O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) { char buff[21], *end; - end= int2str((long) getpid(), buff, 10); + end= int10_to_str((long) getpid(), buff, 10); *end++= '\n'; (void) my_write(file, (byte*) buff, (uint) (end-buff),MYF(MY_WME)); (void) my_close(file, MYF(0)); diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 5e5d4b14c89..36a10370508 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -285,7 +285,9 @@ my_net_write(NET *net,const char *packet,ulong len) buff[3]= (uchar) net->pkt_nr++; if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE)) return 1; +#ifndef DEBUG_DATA_PACKETS DBUG_DUMP("packet_header",(char*) buff,NET_HEADER_SIZE); +#endif return test(net_write_buff(net,packet,len)); } @@ -395,6 +397,9 @@ net_write_buff(NET *net,const char *packet,ulong len) else left_length= (ulong) (net->buff_end - net->write_pos); +#ifdef DEBUG_DATA_PACKETS + DBUG_DUMP("data", packet, len); +#endif if (len > left_length) { if (net->write_pos != net->buff) @@ -777,6 +782,8 @@ my_real_read(NET *net, ulong *complen) if (i == 0) { /* First parts is packet length */ ulong helping; + DBUG_DUMP("packet_header",(char*) net->buff+net->where_b, + NET_HEADER_SIZE); if (net->buff[net->where_b + 3] != (uchar) net->pkt_nr) { if (net->buff[net->where_b] != (uchar) 255) @@ -785,7 +792,6 @@ my_real_read(NET *net, ulong *complen) ("Packets out of order (Found: %d, expected %u)", (int) net->buff[net->where_b + 3], net->pkt_nr)); - DBUG_DUMP("packet_header",(char*) net->buff+net->where_b, 4); #ifdef EXTRA_DEBUG fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", (int) net->buff[net->where_b + 3], @@ -842,6 +848,10 @@ end: vio_blocking(net->vio, net_blocking, &old_mode); } net->reading_or_writing=0; +#ifdef DEBUG_DATA_PACKETS + if (len != packet_error) + DBUG_DUMP("data",(char*) net->buff+net->where_b, len); +#endif return(len); } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index f14f331008d..08eae68c855 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -729,7 +729,7 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr, int QUICK_RANGE_SELECT::init() { DBUG_ENTER("QUICK_RANGE_SELECT::init"); - DBUG_RETURN(error= file->index_init(index)); + DBUG_RETURN(error= file->ha_index_init(index)); } QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() @@ -737,7 +737,8 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() DBUG_ENTER("QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT"); if (!dont_free) { - file->index_end(); + if (file->inited) + file->ha_index_end(); file->extra(HA_EXTRA_NO_KEYREAD); delete_dynamic(&ranges); /* ranges are allocated in alloc */ if (free_file) @@ -1514,7 +1515,6 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, table_map prev_tables, ha_rows limit, bool force_quick_range) { - uint basflag; uint idx; double scan_time; DBUG_ENTER("test_quick_select"); @@ -1529,14 +1529,13 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, if (!cond || (specialflag & SPECIAL_SAFE_MODE) && ! force_quick_range || !limit) DBUG_RETURN(0); /* purecov: inspected */ - if (!((basflag= head->file->table_flags()) & HA_KEYPOS_TO_RNDPOS) && - keys_to_use.is_set_all() || keys_to_use.is_clear_all()) - DBUG_RETURN(0); /* Not smart database */ + if (keys_to_use.is_clear_all()) + DBUG_RETURN(0); records=head->file->records; if (!records) records++; /* purecov: inspected */ scan_time=(double) records / TIME_FOR_COMPARE+1; - read_time=(double) head->file->scan_time()+ scan_time + 1.0; + read_time=(double) head->file->scan_time()+ scan_time + 1.1; if (head->force_index) scan_time= read_time= DBL_MAX; if (limit < records) @@ -1557,7 +1556,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, /* set up parameter that is passed to all functions */ param.thd= thd; - param.baseflag=basflag; + param.baseflag=head->file->table_flags(); param.prev_tables=prev_tables | const_tables; param.read_tables=read_tables; param.current_table= head->map; @@ -2971,7 +2970,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, } if (found_records != HA_POS_ERROR && found_records > 2 && read_index_only && - (param->table->file->index_flags(keynr) & HA_KEY_READ_ONLY) && + (param->table->file->index_flags(keynr) & HA_KEYREAD_ONLY) && !(pk_is_clustered && keynr == param->table->primary_key)) { /* We can resolve this by only reading through this key. */ @@ -2988,6 +2987,8 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, found_records)+ (double) found_records / TIME_FOR_COMPARE); } + DBUG_PRINT("info",("read_time: %g found_read_time: %g", + read_time, found_read_time)); if (read_time > found_read_time && found_records != HA_POS_ERROR /*|| read_time == DBL_MAX*/ ) { @@ -3991,7 +3992,7 @@ key_or(SEL_ARG *key1,SEL_ARG *key2) { swap_variables(SEL_ARG *,key1,key2); } - else if (!(key1=key1->clone_tree())) + if (key1->use_count > 0 || !(key1=key1->clone_tree())) return 0; // OOM } @@ -4060,10 +4061,10 @@ key_or(SEL_ARG *key1,SEL_ARG *key2) SEL_ARG *next=key2->next; // Keys are not overlapping if (key2_shared) { - SEL_ARG *tmp= new SEL_ARG(*key2); // Must make copy - if (!tmp) + SEL_ARG *cpy= new SEL_ARG(*key2); // Must make copy + if (!cpy) return 0; // OOM - key1=key1->insert(tmp); + key1=key1->insert(cpy); key2->increment_use_count(key1->use_count+1); } else @@ -4299,8 +4300,17 @@ SEL_ARG::find_range(SEL_ARG *key) /* -** Remove a element from the tree -** This also frees all sub trees that is used by the element + Remove a element from the tree + + SYNOPSIS + tree_delete() + key Key that is to be deleted from tree (this) + + NOTE + This also frees all sub trees that is used by the element + + RETURN + root of new tree (with key deleted) */ SEL_ARG * @@ -4308,7 +4318,10 @@ SEL_ARG::tree_delete(SEL_ARG *key) { enum leaf_color remove_color; SEL_ARG *root,*nod,**par,*fix_par; - root=this; this->parent= 0; + DBUG_ENTER("tree_delete"); + + root=this; + this->parent= 0; /* Unlink from list */ if (key->prev) @@ -4355,7 +4368,7 @@ SEL_ARG::tree_delete(SEL_ARG *key) } if (root == &null_element) - return 0; // Maybe root later + DBUG_RETURN(0); // Maybe root later if (remove_color == BLACK) root=rb_delete_fixup(root,nod,fix_par); test_rb_tree(root,root->parent); @@ -4363,7 +4376,7 @@ SEL_ARG::tree_delete(SEL_ARG *key) root->use_count=this->use_count; // Fix root counters root->elements=this->elements-1; root->maybe_flag=this->maybe_flag; - return root; + DBUG_RETURN(root); } @@ -5223,7 +5236,6 @@ bool QUICK_ROR_UNION_SELECT::check_if_keys_used(List<Item> *fields) QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, TABLE_REF *ref) { - table->file->index_end(); // Remove old cursor QUICK_RANGE_SELECT *quick=new QUICK_RANGE_SELECT(thd, table, ref->key, 1); KEY *key_info = &table->key_info[ref->key]; KEY_PART *key_part; @@ -5719,22 +5731,13 @@ QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q, uint used_key_parts) : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges) { - bool not_read_after_key = file->table_flags() & HA_NOT_READ_AFTER_KEY; QUICK_RANGE *r; QUICK_RANGE **pr= (QUICK_RANGE**)ranges.buffer; QUICK_RANGE **last_range= pr + ranges.elements; - for (; pr!=last_range; ++pr) - { - r= *pr; - rev_ranges.push_front(r); - if (not_read_after_key && range_reads_after_key(r)) - { - error = HA_ERR_UNSUPPORTED; - dont_free=1; // Don't free memory from 'q' - return; - } - } + for (; pr!=last_range; pr++) + rev_ranges.push_front(*pr); + /* Remove EQ_RANGE flag for keys that are not using the full key */ for (r = rev_it++; r; r = rev_it++) { @@ -5803,29 +5806,10 @@ int QUICK_SELECT_DESC::get_next() else { DBUG_ASSERT(range->flag & NEAR_MAX || range_reads_after_key(range)); -#ifndef NOT_IMPLEMENTED_YET result=file->index_read(record, (byte*) range->max_key, range->max_length, ((range->flag & NEAR_MAX) ? HA_READ_BEFORE_KEY : HA_READ_PREFIX_LAST_OR_PREV)); -#else - /* - Heikki changed Sept 11, 2002: since InnoDB does not store the cursor - position if READ_KEY_EXACT is used to a primary key with all - key columns specified, we must use below HA_READ_KEY_OR_NEXT, - so that InnoDB stores the cursor position and is able to move - the cursor one step backward after the search. - */ - /* - Note: even if max_key is only a prefix, HA_READ_AFTER_KEY will - do the right thing - go past all keys which match the prefix - */ - result=file->index_read(record, (byte*) range->max_key, - range->max_length, - ((range->flag & NEAR_MAX) ? - HA_READ_KEY_OR_NEXT : HA_READ_AFTER_KEY)); - result = file->index_prev(record); -#endif } if (result) { diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 8c1cd9ce1cb..75b00b97ce7 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -46,9 +46,9 @@ #include "mysql_priv.h" #include "sql_select.h" -static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, - Field* field, COND *cond, - uint *range_fl, uint *key_prefix_length); +static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, Field* field, + COND *cond, uint *range_fl, + uint *key_prefix_length); static int reckey_in_range(bool max_fl, TABLE_REF *ref, Field* field, COND *cond, uint range_fl, uint prefix_len); static int maxmin_in_range(bool max_fl, Field* field, COND *cond); @@ -166,11 +166,6 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) Item_field *item_field= ((Item_field*) expr); TABLE *table= item_field->field->table; - if ((table->file->table_flags() & HA_NOT_READ_AFTER_KEY)) - { - const_result=0; - break; - } /* Look for a partial key that can be used for optimization. If we succeed, ref.key_length will contain the length of @@ -186,7 +181,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) const_result= 0; break; } - error= table->file->index_init((uint) ref.key); + error= table->file->ha_index_init((uint) ref.key); if (!ref.key_length) error= table->file->index_first(table->record[0]); @@ -206,7 +201,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) table->key_read= 0; table->file->extra(HA_EXTRA_NO_KEYREAD); } - table->file->index_end(); + table->file->ha_index_end(); if (error) { if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE) @@ -260,12 +255,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) const_result= 0; break; } - if ((table->file->table_flags() & HA_NOT_READ_AFTER_KEY)) - { - const_result= 0; - break; - } - error= table->file->index_init((uint) ref.key); + error= table->file->ha_index_init((uint) ref.key); if (!ref.key_length) error= table->file->index_last(table->record[0]); @@ -285,7 +275,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) table->key_read=0; table->file->extra(HA_EXTRA_NO_KEYREAD); } - table->file->index_end(); + table->file->ha_index_end(); if (error) { if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE) @@ -648,7 +638,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, keyinfo != keyinfo_end; keyinfo++,idx++) { - if (table->file->index_flags(idx) & HA_WRONG_ASCII_ORDER) + if (!(table->file->index_flags(idx) & HA_READ_ORDER)) break; KEY_PART_INFO *part,*part_end; diff --git a/sql/password.c b/sql/password.c index 9f4910d8c60..0ac91346a55 100644 --- a/sql/password.c +++ b/sql/password.c @@ -218,6 +218,8 @@ check_scramble_323(const char *scrambled, const char *message, to=buff; for (pos=scrambled ; *pos ; pos++) *to++=(char) (floor(my_rnd(&rand_st)*31)+64); + if (pos-scrambled != SCRAMBLE_LENGTH_323) + return 1; extra=(char) (floor(my_rnd(&rand_st)*31)); to=buff; while (*scrambled) @@ -321,8 +323,8 @@ octet2hex(char *to, const uint8 *str, uint len) const uint8 *str_end= str + len; for (; str != str_end; ++str) { - *to++= _dig_vec[(*str & 0xF0) >> 4]; - *to++= _dig_vec[*str & 0x0F]; + *to++= _dig_vec_upper[(*str & 0xF0) >> 4]; + *to++= _dig_vec_upper[*str & 0x0F]; } *to= '\0'; } diff --git a/sql/protocol.cc b/sql/protocol.cc index b2334b0f356..065fcd3d4af 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -27,6 +27,8 @@ #include "sp_rcontext.h" #include <stdarg.h> +static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024; + #ifndef EMBEDDED_LIBRARY bool Protocol::net_store_data(const char *from, uint length) #else @@ -700,7 +702,7 @@ bool Protocol_simple::store_null() #endif char buff[1]; buff[0]= (char)251; - return packet->append(buff, sizeof(buff), PACKET_BUFFET_EXTRA_ALLOC); + return packet->append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC); } #endif @@ -1003,7 +1005,7 @@ bool Protocol_prep::store_tiny(longlong from) char buff[1]; field_pos++; buff[0]= (uchar) from; - return packet->append(buff, sizeof(buff), PACKET_BUFFET_EXTRA_ALLOC); + return packet->append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC); } @@ -1015,7 +1017,7 @@ bool Protocol_prep::store_short(longlong from) field_types[field_pos] == MYSQL_TYPE_YEAR); #endif field_pos++; - char *to= packet->prep_append(2, PACKET_BUFFET_EXTRA_ALLOC); + char *to= packet->prep_append(2, PACKET_BUFFER_EXTRA_ALLOC); if (!to) return 1; int2store(to, (int) from); @@ -1031,7 +1033,7 @@ bool Protocol_prep::store_long(longlong from) field_types[field_pos] == MYSQL_TYPE_LONG); #endif field_pos++; - char *to= packet->prep_append(4, PACKET_BUFFET_EXTRA_ALLOC); + char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC); if (!to) return 1; int4store(to, from); @@ -1046,7 +1048,7 @@ bool Protocol_prep::store_longlong(longlong from, bool unsigned_flag) field_types[field_pos] == MYSQL_TYPE_LONGLONG); #endif field_pos++; - char *to= packet->prep_append(8, PACKET_BUFFET_EXTRA_ALLOC); + char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC); if (!to) return 1; int8store(to, from); @@ -1061,7 +1063,7 @@ bool Protocol_prep::store(float from, uint32 decimals, String *buffer) field_types[field_pos] == MYSQL_TYPE_FLOAT); #endif field_pos++; - char *to= packet->prep_append(4, PACKET_BUFFET_EXTRA_ALLOC); + char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC); if (!to) return 1; float4store(to, from); @@ -1076,7 +1078,7 @@ bool Protocol_prep::store(double from, uint32 decimals, String *buffer) field_types[field_pos] == MYSQL_TYPE_DOUBLE); #endif field_pos++; - char *to= packet->prep_append(8, PACKET_BUFFET_EXTRA_ALLOC); + char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC); if (!to) return 1; float8store(to, from); @@ -1125,7 +1127,7 @@ bool Protocol_prep::store(TIME *tm) else length=0; buff[0]=(char) length; // Length is stored first - return packet->append(buff, length+1, PACKET_BUFFET_EXTRA_ALLOC); + return packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC); } bool Protocol_prep::store_date(TIME *tm) @@ -1142,7 +1144,7 @@ bool Protocol_prep::store_time(TIME *tm) DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_TIME); #endif - char buff[15],*pos; + char buff[13], *pos; uint length; field_pos++; pos= buff+1; @@ -1153,11 +1155,11 @@ bool Protocol_prep::store_time(TIME *tm) pos[7]= (uchar) tm->second; int4store(pos+8, tm->second_part); if (tm->second_part) - length=11; + length=12; else if (tm->hour || tm->minute || tm->second || tm->day) length=8; else length=0; buff[0]=(char) length; // Length is stored first - return packet->append(buff, length+1, PACKET_BUFFET_EXTRA_ALLOC); + return packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC); } diff --git a/sql/protocol.h b/sql/protocol.h index 25efecab712..079c06ae155 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -18,7 +18,6 @@ #pragma interface /* gcc class implementation */ #endif -#define PACKET_BUFFET_EXTRA_ALLOC 1024 class i_string; class THD; @@ -36,8 +35,10 @@ protected: enum enum_field_types *field_types; #endif uint field_count; +#ifndef EMBEDDED_LIBRARY bool net_store_data(const char *from, uint length); -#ifdef EMBEDDED_LIBRARY +#else + virtual bool net_store_data(const char *from, uint length); char **next_field; MYSQL_FIELD *next_mysql_field; MEM_ROOT *alloc; diff --git a/sql/records.cc b/sql/records.cc index 264f7fe1241..37fbc7570ed 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -70,7 +70,8 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table, info->io_cache=tempfile; reinit_io_cache(info->io_cache,READ_CACHE,0L,0,0); info->ref_pos=table->file->ref; - table->file->rnd_init(0); + if (!table->file->inited) + table->file->ha_rnd_init(0); /* table->sort.addon_field is checked because if we use addon fields, @@ -105,7 +106,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table, else if (table->sort.record_pointers) { DBUG_PRINT("info",("using record_pointers")); - table->file->rnd_init(0); + table->file->ha_rnd_init(0); info->cache_pos=table->sort.record_pointers; info->cache_end=info->cache_pos+ table->sort.found_records*info->ref_length; @@ -116,7 +117,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table, { DBUG_PRINT("info",("using rr_sequential")); info->read_record=rr_sequential; - table->file->rnd_init(); + table->file->ha_rnd_init(1); /* We can use record cache if we don't update dynamic length tables */ if (!table->no_cache && (use_record_cache > 0 || @@ -142,7 +143,8 @@ void end_read_record(READ_RECORD *info) { filesort_free_buffers(info->table); (void) info->file->extra(HA_EXTRA_NO_CACHE); - (void) info->file->rnd_end(); + if (info->read_record != rr_quick) // otherwise quick_range does it + (void) info->file->ha_index_or_rnd_end(); info->table=0; } } diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 2a5381ae478..4feb24f06b2 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -63,6 +63,11 @@ static Slave_log_event* find_slave_event(IO_CACHE* log, static int init_failsafe_rpl_thread(THD* thd) { DBUG_ENTER("init_failsafe_rpl_thread"); + /* + thd->bootstrap is to report errors barely to stderr; if this code is + enable again one day, one should check if bootstrap is still needed (maybe + this thread has no other error reporting method). + */ thd->system_thread = thd->bootstrap = 1; thd->host_or_ip= ""; thd->client_capabilities = 0; diff --git a/sql/set_var.cc b/sql/set_var.cc index 811c700d527..614d615e37b 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -183,7 +183,7 @@ sys_var_key_cache_long sys_key_cache_age_threshold("key_cache_age_threshold", param_age_threshold)); sys_var_bool_ptr sys_local_infile("local_infile", &opt_local_infile); -sys_var_thd_bool sys_log_warnings("log_warnings", &SV::log_warnings); +sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings); sys_var_thd_ulong sys_long_query_time("long_query_time", &SV::long_query_time); sys_var_thd_bool sys_low_priority_updates("low_priority_updates", @@ -330,6 +330,10 @@ sys_var_thd_table_type sys_table_type("table_type", &SV::table_type); sys_var_thd_storage_engine sys_storage_engine("storage_engine", &SV::table_type); +#ifdef HAVE_REPLICATION +sys_var_sync_binlog_period sys_sync_binlog_period("sync_binlog", &sync_binlog_period); +#endif +sys_var_bool_ptr sys_sync_frm("sync_frm", &opt_sync_frm); sys_var_long_ptr sys_table_cache_size("table_cache", &table_cache_size); sys_var_long_ptr sys_thread_cache_size("thread_cache_size", @@ -352,13 +356,13 @@ sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_p sys_var_thd_date_time_format sys_time_format("time_format", &SV::time_format, - TIMESTAMP_TIME); + MYSQL_TIMESTAMP_TIME); sys_var_thd_date_time_format sys_date_format("date_format", &SV::date_format, - TIMESTAMP_DATE); + MYSQL_TIMESTAMP_DATE); sys_var_thd_date_time_format sys_datetime_format("datetime_format", &SV::datetime_format, - TIMESTAMP_DATETIME); + MYSQL_TIMESTAMP_DATETIME); /* Variables that are bits in THD */ @@ -442,6 +446,7 @@ static sys_var_thd_ulong sys_default_week_format("default_week_format", sys_var_thd_ulong sys_group_concat_max_len("group_concat_max_len", &SV::group_concat_max_len); +sys_var_thd_time_zone sys_time_zone("time_zone"); /* Read only variables */ @@ -580,11 +585,16 @@ sys_var *sys_variables[]= &sys_sql_mode, &sys_sql_warnings, &sys_storage_engine, +#ifdef HAVE_REPLICATION + &sys_sync_binlog_period, +#endif + &sys_sync_frm, &sys_table_cache_size, &sys_table_type, &sys_thread_cache_size, &sys_time_format, &sys_timestamp, + &sys_time_zone, &sys_tmp_table_size, &sys_trans_alloc_block_size, &sys_trans_prealloc_size, @@ -645,15 +655,18 @@ struct show_var_st init_vars[]= { {"ft_query_expansion_limit",(char*) &ft_query_expansion_limit, SHOW_LONG}, {"ft_stopword_file", (char*) &ft_stopword_file, SHOW_CHAR_PTR}, {sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len, SHOW_SYS}, + {"have_archive", (char*) &have_archive_db, SHOW_HAVE}, {"have_bdb", (char*) &have_berkeley_db, SHOW_HAVE}, {"have_compress", (char*) &have_compress, SHOW_HAVE}, {"have_crypt", (char*) &have_crypt, SHOW_HAVE}, {"have_innodb", (char*) &have_innodb, SHOW_HAVE}, {"have_isam", (char*) &have_isam, SHOW_HAVE}, + {"have_geometry", (char*) &have_geometry, SHOW_HAVE}, {"have_ndbcluster", (char*) &have_ndbcluster, SHOW_HAVE}, {"have_openssl", (char*) &have_openssl, SHOW_HAVE}, {"have_query_cache", (char*) &have_query_cache, SHOW_HAVE}, {"have_raid", (char*) &have_raid, SHOW_HAVE}, + {"have_rtree_keys", (char*) &have_rtree_keys, SHOW_HAVE}, {"have_symlink", (char*) &have_symlink, SHOW_HAVE}, {"init_connect", (char*) &sys_init_connect, SHOW_SYS}, {"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR}, @@ -796,6 +809,10 @@ struct show_var_st init_vars[]= { {sys_sort_buffer.name, (char*) &sys_sort_buffer, SHOW_SYS}, {sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS}, {sys_storage_engine.name, (char*) &sys_storage_engine, SHOW_SYS}, +#ifdef HAVE_REPLICATION + {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period, SHOW_SYS}, +#endif + {sys_sync_frm.name, (char*) &sys_sync_frm, SHOW_SYS}, {"table_cache", (char*) &table_cache_size, SHOW_LONG}, {sys_table_type.name, (char*) &sys_table_type, SHOW_SYS}, {sys_thread_cache_size.name,(char*) &sys_thread_cache_size, SHOW_SYS}, @@ -805,8 +822,9 @@ struct show_var_st init_vars[]= { {"thread_stack", (char*) &thread_stack, SHOW_LONG}, {sys_time_format.name, (char*) &sys_time_format, SHOW_SYS}, #ifdef HAVE_TZNAME - {"timezone", time_zone, SHOW_CHAR}, + {"system_time_zone", system_time_zone, SHOW_CHAR}, #endif + {"time_zone", (char*) &sys_time_zone, SHOW_SYS}, {sys_tmp_table_size.name, (char*) &sys_tmp_table_size, SHOW_SYS}, {"tmpdir", (char*) &opt_mysql_tmpdir, SHOW_CHAR_PTR}, {sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size, @@ -1719,19 +1737,31 @@ CHARSET_INFO *get_old_charset_by_name(const char *name) bool sys_var_collation::check(THD *thd, set_var *var) { CHARSET_INFO *tmp; - char buff[80]; - String str(buff,sizeof(buff), system_charset_info), *res; - if (!(res=var->value->val_str(&str))) + if (var->value->result_type() == STRING_RESULT) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); - return 1; + char buff[80]; + String str(buff,sizeof(buff), system_charset_info), *res; + if (!(res=var->value->val_str(&str))) + { + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); + return 1; + } + if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) + { + my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr()); + return 1; + } } - - if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) + else // INT_RESULT { - my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr()); - return 1; + if (!(tmp=get_charset(var->value->val_int(),MYF(0)))) + { + char buf[20]; + int10_to_str(var->value->val_int(), buf, -10); + my_error(ER_UNKNOWN_COLLATION, MYF(0), buf); + return 1; + } } var->save_result.charset= tmp; // Save for update return 0; @@ -1741,23 +1771,36 @@ bool sys_var_collation::check(THD *thd, set_var *var) bool sys_var_character_set::check(THD *thd, set_var *var) { CHARSET_INFO *tmp; - char buff[80]; - String str(buff,sizeof(buff), system_charset_info), *res; - if (!(res=var->value->val_str(&str))) - { - if (!nullable) + if (var->value->result_type() == STRING_RESULT) + { + char buff[80]; + String str(buff,sizeof(buff), system_charset_info), *res; + if (!(res=var->value->val_str(&str))) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); + if (!nullable) + { + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); + return 1; + } + tmp= NULL; + } + else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && + !(tmp=get_old_charset_by_name(res->c_ptr()))) + { + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); return 1; } - tmp= NULL; } - else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && - !(tmp=get_old_charset_by_name(res->c_ptr()))) + else // INT_RESULT { - my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); - return 1; + if (!(tmp=get_charset(var->value->val_int(),MYF(0)))) + { + char buf[20]; + int10_to_str(var->value->val_int(), buf, -10); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf); + return 1; + } } var->save_result.charset= tmp; // Save for update return 0; @@ -1870,6 +1913,20 @@ void sys_var_character_set_server::set_default(THD *thd, enum_var_type type) } } +#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000) +bool sys_var_character_set_server::check(THD *thd, set_var *var) +{ + if ((var->type == OPT_GLOBAL) && + (mysql_bin_log.is_open() || + active_mi->slave_running || active_mi->rli.slave_running)) + { + my_printf_error(0, "Binary logging and replication forbid changing \ +the global server character set or collation", MYF(0)); + return 1; + } + return sys_var_character_set::check(thd,var); +} +#endif CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd, enum_var_type type) @@ -1963,6 +2020,20 @@ void sys_var_collation_database::set_default(THD *thd, enum_var_type type) } } +#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000) +bool sys_var_collation_server::check(THD *thd, set_var *var) +{ + if ((var->type == OPT_GLOBAL) && + (mysql_bin_log.is_open() || + active_mi->slave_running || active_mi->rli.slave_running)) + { + my_printf_error(0, "Binary logging and replication forbid changing \ +the global server character set or collation", MYF(0)); + return 1; + } + return sys_var_collation::check(thd,var); +} +#endif bool sys_var_collation_server::update(THD *thd, set_var *var) { @@ -2264,6 +2335,22 @@ bool sys_var_slave_skip_counter::update(THD *thd, set_var *var) pthread_mutex_unlock(&LOCK_active_mi); return 0; } + + +bool sys_var_sync_binlog_period::update(THD *thd, set_var *var) +{ + pthread_mutex_t *lock_log= mysql_bin_log.get_log_lock(); + sync_binlog_period= var->save_result.ulong_value; + /* + Must reset the counter otherwise it may already be beyond the new period + and so the new period will not be taken into account. Need mutex otherwise + might be cancelled by a simultanate ++ in MYSQL_LOG::write(). + */ + pthread_mutex_lock(lock_log); + sync_binlog_counter= 0; + pthread_mutex_unlock(lock_log); + return 0; +} #endif /* HAVE_REPLICATION */ bool sys_var_rand_seed1::update(THD *thd, set_var *var) @@ -2279,6 +2366,77 @@ bool sys_var_rand_seed2::update(THD *thd, set_var *var) } +bool sys_var_thd_time_zone::check(THD *thd, set_var *var) +{ + char buff[MAX_TIME_ZONE_NAME_LENGTH]; + String str(buff, sizeof(buff), &my_charset_latin1); + String *res= var->value->val_str(&str); + +#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000) + if ((var->type == OPT_GLOBAL) && + (mysql_bin_log.is_open() || + active_mi->slave_running || active_mi->rli.slave_running)) + { + my_printf_error(0, "Binary logging and replication forbid changing " + "of the global server time zone", MYF(0)); + return 1; + } +#endif + + if (!(var->save_result.time_zone= my_tz_find(thd, res))) + { + my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL"); + return 1; + } + return 0; +} + + +bool sys_var_thd_time_zone::update(THD *thd, set_var *var) +{ + /* We are using Time_zone object found during check() phase */ + *get_tz_ptr(thd,var->type)= var->save_result.time_zone; + return 0; +} + + +byte *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type, + LEX_STRING *base) +{ + /* + We can use ptr() instead of c_ptr() here because String contaning + time zone name is guaranteed to be zero ended. + */ + return (byte *)((*get_tz_ptr(thd,type))->get_name()->ptr()); +} + + +Time_zone** sys_var_thd_time_zone::get_tz_ptr(THD *thd, + enum_var_type type) +{ + if (type == OPT_GLOBAL) + return &global_system_variables.time_zone; + else + return &thd->variables.time_zone; +} + + +void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type) +{ + if (type == OPT_GLOBAL) + { + if (default_tz_name) + { + String str(default_tz_name, &my_charset_latin1); + global_system_variables.time_zone= my_tz_find(thd, &str); + } + else + global_system_variables.time_zone= my_tz_SYSTEM; + } + else + thd->variables.time_zone= global_system_variables.time_zone; +} + /* Functions to update thd->options bits */ @@ -2559,6 +2717,36 @@ int sql_set_variables(THD *thd, List<set_var_base> *var_list) } +/* + Say if all variables set by a SET support the ONE_SHOT keyword (currently, + only character set and collation do; later timezones will). + + SYNOPSIS + + not_all_support_one_shot + set_var List of variables to update + + NOTES + It has a "not_" because it makes faster tests (no need to "!") + + RETURN VALUE + 0 all variables of the list support ONE_SHOT + 1 at least one does not support ONE_SHOT +*/ + +bool not_all_support_one_shot(List<set_var_base> *var_list) +{ + List_iterator_fast<set_var_base> it(*var_list); + set_var_base *var; + while ((var= it++)) + { + if (var->no_support_one_shot()) + return 1; + } + return 0; +} + + /***************************************************************************** Functions to handle SET mysql_internal_variable=const_expr *****************************************************************************/ diff --git a/sql/set_var.h b/sql/set_var.h index 699f320bbd9..a51e44285d6 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -49,10 +49,20 @@ public: const char *name; sys_after_update_func after_update; - sys_var(const char *name_arg) :name(name_arg),after_update(0) - {} +#if MYSQL_VERSION_ID < 50000 + bool no_support_one_shot; +#endif + sys_var(const char *name_arg) + :name(name_arg), after_update(0) +#if MYSQL_VERSION_ID < 50000 + , no_support_one_shot(1) +#endif + {} sys_var(const char *name_arg,sys_after_update_func func) - :name(name_arg),after_update(func) + :name(name_arg), after_update(func) +#if MYSQL_VERSION_ID < 50000 + , no_support_one_shot(1) +#endif {} virtual ~sys_var() {} virtual bool check(THD *thd, set_var *var); @@ -452,7 +462,7 @@ public: }; -#ifndef EMBEDDED_LIBRARY +#ifdef HAVE_REPLICATION class sys_var_slave_skip_counter :public sys_var { public: @@ -465,6 +475,14 @@ public: type() or value_ptr() */ }; + +class sys_var_sync_binlog_period :public sys_var_long_ptr +{ +public: + sys_var_sync_binlog_period(const char *name_arg, ulong *value_ptr) + :sys_var_long_ptr(name_arg,value_ptr) {} + bool update(THD *thd, set_var *var); +}; #endif class sys_var_rand_seed1 :public sys_var @@ -487,12 +505,17 @@ public: class sys_var_collation :public sys_var_thd { public: - sys_var_collation(const char *name_arg) :sys_var_thd(name_arg) {} + sys_var_collation(const char *name_arg) :sys_var_thd(name_arg) + { +#if MYSQL_VERSION_ID < 50000 + no_support_one_shot= 0; +#endif + } bool check(THD *thd, set_var *var); SHOW_TYPE type() { return SHOW_CHAR; } bool check_update_type(Item_result type) { - return type != STRING_RESULT; /* Only accept strings */ + return ((type != STRING_RESULT) && (type != INT_RESULT)); } bool check_default(enum_var_type type) { return 0; } virtual void set_default(THD *thd, enum_var_type type)= 0; @@ -502,13 +525,23 @@ class sys_var_character_set :public sys_var_thd { public: bool nullable; - sys_var_character_set(const char *name_arg) :sys_var_thd(name_arg) - { nullable= 0; } + sys_var_character_set(const char *name_arg) : + sys_var_thd(name_arg) + { + nullable= 0; +#if MYSQL_VERSION_ID < 50000 + /* + In fact only almost all variables derived from sys_var_character_set + support ONE_SHOT; character_set_results doesn't. But that's good enough. + */ + no_support_one_shot= 0; +#endif + } bool check(THD *thd, set_var *var); SHOW_TYPE type() { return SHOW_CHAR; } bool check_update_type(Item_result type) { - return type != STRING_RESULT; /* Only accept strings */ + return ((type != STRING_RESULT) && (type != INT_RESULT)); } bool check_default(enum_var_type type) { return 0; } bool update(THD *thd, set_var *var); @@ -541,6 +574,9 @@ class sys_var_character_set_server :public sys_var_character_set public: sys_var_character_set_server(const char *name_arg) : sys_var_character_set(name_arg) {} +#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000) + bool check(THD *thd, set_var *var); +#endif void set_default(THD *thd, enum_var_type type); CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type); }; @@ -576,6 +612,9 @@ class sys_var_collation_server :public sys_var_collation { public: sys_var_collation_server(const char *name_arg) :sys_var_collation(name_arg) {} +#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000) + bool check(THD *thd, set_var *var); +#endif bool update(THD *thd, set_var *var); void set_default(THD *thd, enum_var_type type); byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); @@ -630,7 +669,7 @@ public: class sys_var_thd_date_time_format :public sys_var_thd { DATE_TIME_FORMAT *SV::*offset; - enum timestamp_type date_time_type; + timestamp_type date_time_type; public: sys_var_thd_date_time_format(const char *name_arg, DATE_TIME_FORMAT *SV::*offset_arg, @@ -677,6 +716,29 @@ public: SHOW_TYPE type() { return show_type; } }; +class sys_var_thd_time_zone :public sys_var_thd +{ +public: + sys_var_thd_time_zone(const char *name_arg): + sys_var_thd(name_arg) + { +#if MYSQL_VERSION_ID < 50000 + no_support_one_shot= 0; +#endif + } + bool check(THD *thd, set_var *var); + SHOW_TYPE type() { return SHOW_CHAR; } + bool check_update_type(Item_result type) + { + return type != STRING_RESULT; /* Only accept strings */ + } + bool check_default(enum_var_type type) { return 0; } + bool update(THD *thd, set_var *var); + byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); + virtual void set_default(THD *thd, enum_var_type type); + Time_zone **get_tz_ptr(THD *thd, enum_var_type type); +}; + /**************************************************************************** Classes for parsing of the SET command ****************************************************************************/ @@ -689,7 +751,10 @@ public: virtual int check(THD *thd)=0; /* To check privileges etc. */ virtual int update(THD *thd)=0; /* To set the value */ /* light check for PS */ - virtual int light_check(THD *thd) { return check(thd); } + virtual int light_check(THD *thd) { return check(thd); } +#if MYSQL_VERSION_ID < 50000 + virtual bool no_support_one_shot() { return 1; } +#endif }; @@ -707,6 +772,7 @@ public: ulong ulong_value; ulonglong ulonglong_value; DATE_TIME_FORMAT *date_time_format; + Time_zone *time_zone; } save_result; LEX_STRING base; /* for structs */ @@ -731,6 +797,9 @@ public: int check(THD *thd); int update(THD *thd); int light_check(THD *thd); +#if MYSQL_VERSION_ID < 50000 + bool no_support_one_shot() { return var->no_support_one_shot; } +#endif }; @@ -833,6 +902,7 @@ void set_var_init(); void set_var_free(); sys_var *find_sys_var(const char *str, uint length=0); int sql_set_variables(THD *thd, List<set_var_base> *var_list); +bool not_all_support_one_shot(List<set_var_base> *var_list); void fix_delay_key_write(THD *thd, enum_var_type type); ulong fix_sql_mode(ulong sql_mode); extern sys_var_str sys_charset_system; diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index f35eb975b7a..75cbf12f60c 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -174,7 +174,7 @@ character-set=latin2 "Zji-B¹tìn timeout pøi ètení komunikaèního packetu", "Zji-B¹tìna chyba pøi zápisu komunikaèního packetu", "Zji-B¹tìn timeout pøi zápisu komunikaèního packetu", -"V-Býsledný øetìzec je del¹í ne¾ max_allowed_packet", +"V-Býsledný øetìzec je del¹í ne¾ 'max_allowed_packet'", "Typ pou-B¾ité tabulky nepodporuje BLOB/TEXT sloupce", "Typ pou-B¾ité tabulky nepodporuje AUTO_INCREMENT sloupce", "INSERT DELAYED nen-Bí mo¾no s tabulkou '%-.64s' pou¾ít, proto¾e je zamèená pomocí LOCK TABLES", @@ -209,74 +209,74 @@ character-set=latin2 "Tabulka '%-.64s' je ozna-Bèena jako poru¹ená a mìla by být opravena", "Tabulka '%-.64s' je ozna-Bèena jako poru¹ená a poslední (automatická?) oprava se nezdaøila", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", -"Cannot add a child row: a foreign key constraint fails", -"Cannot delete a parent row: a foreign key constraint fails", +"Cannot add or update a child row: a foreign key constraint fails", +"Cannot delete or update a parent row: a foreign key constraint fails", "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -284,30 +284,34 @@ character-set=latin2 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you will get problems if you get an unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", -"Query cache failed to set size %lu, new query cache size is %lu", +"Query cache failed to set size %lu; new query cache size is %lu", "Column '%-.64s' cannot be part of FULLTEXT index", "Unknown key cache '%-.100s'", -"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", +"MySQL is started in --skip-name-resolve mode; you must restart it without this switch for this grant to work", "Unknown table engine '%s'", -"'%s' is deprecated, use '%s' instead", +"'%s' is deprecated; use '%s' instead", "The target table %-.100s of the %s is not updatable", -"The '%s' feature was disabled; you need MySQL built with '%s' to have it working", +"The '%s' feature is disabled; you need MySQL built with '%s' to have it working", "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" -"Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Truncated incorrect %-.32s value: '%-.128s'" +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index 105c138c440..b4b42b41969 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -126,7 +126,7 @@ character-set=latin1 "For mange felter", "For store poster. Max post størrelse, uden BLOB's, er %d. Du må lave nogle felter til BLOB's", "Thread stack brugt: Brugt: %ld af en %ld stak. Brug 'mysqld -O thread_stack=#' for at allokere en større stak om nødvendigt", -"Krydsreferencer fundet i OUTER JOIN. Check dine ON conditions", +"Krydsreferencer fundet i OUTER JOIN; check dine ON conditions", "Kolonne '%-.32s' bruges som UNIQUE eller INDEX men er ikke defineret som NOT NULL", "Kan ikke læse funktionen '%-.64s'", "Kan ikke starte funktionen '%-.64s'; %-.80s", @@ -168,7 +168,7 @@ character-set=latin1 "Timeout-fejl ved læsning af kommunukations-pakker (communication packets)", "Fik fejlmeddelelse ved skrivning af kommunukations-pakker (communication packets)", "Timeout-fejl ved skrivning af kommunukations-pakker (communication packets)", -"Strengen med resultater er større end max_allowed_packet", +"Strengen med resultater er større end 'max_allowed_packet'", "Denne tabeltype understøtter ikke brug af BLOB og TEXT kolonner", "Denne tabeltype understøtter ikke brug af AUTO_INCREMENT kolonner", "INSERT DELAYED kan ikke bruges med tabellen '%-.64s', fordi tabellen er låst med LOCK TABLES", @@ -208,7 +208,7 @@ character-set=latin1 "Denne handling kræver en kørende slave. Konfigurer en slave og brug kommandoen START SLAVE", "Denne server er ikke konfigureret som slave. Ret in config-filen eller brug kommandoen CHANGE MASTER TO", "Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Kunne ikke danne en slave-tråd. Check systemressourcerne", +"Kunne ikke danne en slave-tråd; check systemressourcerne", "Brugeren %-.64s har allerede mere end 'max_user_connections' aktive forbindelser", "Du må kun bruge konstantudtryk med SET", "Lock wait timeout overskredet", @@ -216,10 +216,10 @@ character-set=latin1 "Update lås kan ikke opnås under en READ UNCOMMITTED transaktion", "DROP DATABASE er ikke tilladt mens en tråd holder på globalt read lock", "CREATE DATABASE er ikke tilladt mens en tråd holder på globalt read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -227,26 +227,26 @@ character-set=latin1 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", -+ "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Variable '%-.64s' is a %s variable", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", "Unknown prepared statement handler (%ld) given to %s", @@ -254,23 +254,23 @@ character-set=latin1 "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -278,13 +278,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support, they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -299,9 +299,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Modtog fejl %d '%-.100s' fra %s", +"Modtog temporary fejl %d '%-.100s' fra %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 93dbeab1a5c..af0c3a1bc0b 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -176,7 +176,7 @@ character-set=latin1 "Timeout bij het lezen van communicatiepakketten", "Fout bij het schrijven van communicatiepakketten", "Timeout bij het schrijven van communicatiepakketten", -"Resultaat string is langer dan max_allowed_packet", +"Resultaat string is langer dan 'max_allowed_packet'", "Het gebruikte tabel type ondersteunt geen BLOB/TEXT kolommen", "Het gebruikte tabel type ondersteunt geen AUTO_INCREMENT kolommen", "INSERT DELAYED kan niet worden gebruikt bij table '%-.64s', vanwege een 'lock met LOCK TABLES", @@ -253,32 +253,32 @@ character-set=latin1 "Kreeg fatale fout %d: '%-.128s' van master tijdens lezen van data uit binaire log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -286,13 +286,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -307,9 +307,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 3f8e5483fef..7706257a55d 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -24,8 +24,8 @@ character-set=latin1 "Can't read dir of '%-.64s' (errno: %d)", "Can't change dir to '%-.64s' (errno: %d)", "Record has changed since last read in table '%-.64s'", -"Disk full (%s). Waiting for someone to free some space...", -"Can't write, duplicate key in table '%-.64s'", +"Disk full (%s); waiting for someone to free some space...", +"Can't write; duplicate key in table '%-.64s'", "Error on close of '%-.64s' (errno: %d)", "Error reading file '%-.64s' (errno: %d)", "Error on rename of '%-.64s' to '%-.64s' (errno: %d)", @@ -37,25 +37,25 @@ character-set=latin1 "Table storage engine for '%-.64s' doesn't have this option", "Can't find record in '%-.64s'", "Incorrect information in file: '%-.64s'", -"Incorrect key file for table: '%-.64s'; try to repair it", +"Incorrect key file for table '%-.64s'; try to repair it", "Old key file for table '%-.64s'; repair it!", "Table '%-.64s' is read only", -"Out of memory. Restart daemon and try again (needed %d bytes)", -"Out of sort memory. Increase daemon sort buffer size", -"Unexpected eof found when reading file '%-.64s' (errno: %d)", +"Out of memory; restart server and try again (needed %d bytes)", +"Out of sort memory; increase server sort buffer size", +"Unexpected EOF found when reading file '%-.64s' (errno: %d)", "Too many connections", -"Out of memory; Check if mysqld or some other process uses all available memory. If not you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space", +"Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space", "Can't get hostname for your address", "Bad handshake", -"Access denied for user: '%-.32s'@'%-.64s' to database '%-.64s'", -"Access denied for user: '%-.32s'@'%-.64s' (Using password: %s)", -"No Database Selected", +"Access denied for user '%-.32s'@'%-.64s' to database '%-.64s'", +"Access denied for user '%-.32s'@'%-.64s' (using password: %s)", +"No database selected", "Unknown command", "Column '%-.64s' cannot be null", "Unknown database '%-.64s'", "Table '%-.64s' already exists", "Unknown table '%-.64s'", -"Column: '%-.64s' in %-.64s is ambiguous", +"Column '%-.64s' in %-.64s is ambiguous", "Server shutdown in progress", "Unknown column '%-.64s' in '%-.64s'", "'%-.64s' isn't in GROUP BY", @@ -73,28 +73,28 @@ character-set=latin1 "Invalid default value for '%-.64s'", "Multiple primary key defined", "Too many keys specified; max %d keys allowed", -"Too many key parts specified. Max %d parts allowed", +"Too many key parts specified; max %d parts allowed", "Specified key was too long; max key length is %d bytes", "Key column '%-.64s' doesn't exist in table", "BLOB column '%-.64s' can't be used in key specification with the used table type", -"Too big column length for column '%-.64s' (max = %d). Use BLOB instead", -"Incorrect table definition; There can only be one auto column and it must be defined as a key", +"Column length too big for column '%-.64s' (max = %d); use BLOB instead", +"Incorrect table definition; there can be only one auto column and it must be defined as a key", "%s: ready for connections.\nVersion: '%s' socket: '%s' port: %d\n", "%s: Normal shutdown\n", "%s: Got signal %d. Aborting!\n", -"%s: Shutdown Complete\n", +"%s: Shutdown complete\n", "%s: Forcing close of thread %ld user: '%-.32s'\n", "Can't create IP socket", -"Table '%-.64s' has no index like the one used in CREATE INDEX. Recreate the table", -"Field separator argument is not what is expected. Check the manual", -"You can't use fixed rowlength with BLOBs. Please use 'fields terminated by'", +"Table '%-.64s' has no index like the one used in CREATE INDEX; recreate the table", +"Field separator argument is not what is expected; check the manual", +"You can't use fixed rowlength with BLOBs; please use 'fields terminated by'", "The file '%-.64s' must be in the database directory or be readable by all", "File '%-.80s' already exists", "Records: %ld Deleted: %ld Skipped: %ld Warnings: %ld", "Records: %ld Duplicates: %ld", -"Incorrect sub part key. The used key part isn't a string, the used length is longer than the key part or the storage engine doesn't support unique sub keys", -"You can't delete all columns with ALTER TABLE. Use DROP TABLE instead", -"Can't DROP '%-.64s'. Check that column/key exists", +"Incorrect sub part key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique sub keys", +"You can't delete all columns with ALTER TABLE; use DROP TABLE instead", +"Can't DROP '%-.64s'; check that column/key exists", "Records: %ld Duplicates: %ld Warnings: %ld", "You can't specify target table '%-.64s' for update in FROM clause", "Unknown thread id: %lu", @@ -107,7 +107,7 @@ character-set=latin1 "BLOB/TEXT column '%-.64s' can't have a default value", "Incorrect database name '%-.100s'", "Incorrect table name '%-.100s'", -"The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok", +"The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay", "Unknown error", "Unknown procedure '%-.64s'", "Incorrect parameter count to procedure '%-.64s'", @@ -119,44 +119,44 @@ character-set=latin1 "A table must have at least 1 column", "The table '%-.64s' is full", "Unknown character set: '%-.64s'", -"Too many tables. MySQL can only use %d tables in a join", +"Too many tables; MySQL can only use %d tables in a join", "Too many columns", -"Too big row size. The maximum row size for the used table type, not counting BLOBs, is %ld. You have to change some fields to TEXT or BLOBs", +"Row size too large. The maximum row size for the used table type, not counting BLOBs, is %ld. You have to change some columns to TEXT or BLOBs", "Thread stack overrun: Used: %ld of a %ld stack. Use 'mysqld -O thread_stack=#' to specify a bigger stack if needed", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "Column '%-.64s' is used with UNIQUE or INDEX but is not defined as NOT NULL", "Can't load function '%-.64s'", "Can't initialize function '%-.64s'; %-.80s", "No paths allowed for shared library", -"Function '%-.64s' already exist", +"Function '%-.64s' already exists", "Can't open shared library '%-.64s' (errno: %d %-.64s)", "Can't find function '%-.64s' in library'", "Function '%-.64s' is not defined", -"Host '%-.64s' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'", +"Host '%-.64s' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'", "Host '%-.64s' is not allowed to connect to this MySQL server", -"You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords", +"You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords", "You must have privileges to update tables in the mysql database to be able to change passwords for others", "Can't find any matching row in the user table", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory, you can consult the manual for a possible OS-dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s'", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privileges can be used", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used", "The host or user argument to GRANT is too long", "Table '%-.64s.%-.64s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", "The used command is not allowed with this MySQL version", -"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use", +"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use", "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.32s' (%-.64s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -165,7 +165,7 @@ character-set=latin1 "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s' because it is locked with LOCK TABLES", @@ -174,7 +174,7 @@ character-set=latin1 "All tables in the MERGE table are not identically defined", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB/TEXT column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -200,23 +200,23 @@ character-set=latin1 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded; Try restarting transaction", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add or update a child row: a foreign key constraint fails", @@ -224,50 +224,50 @@ character-set=latin1 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", "ZLIB: Not enough memory", "ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", "ZLIB: Input data corrupted", -"%d line(s) was(were) cut by group_concat()", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -275,30 +275,34 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL. Otherwise you will get problems if you get an unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you will get problems if you get an unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", -"Query cache failed to set size %lu, new query cache size is %lu", +"Query cache failed to set size %lu; new query cache size is %lu", "Column '%-.64s' cannot be part of FULLTEXT index", "Unknown key cache '%-.100s'", -"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", +"MySQL is started in --skip-name-resolve mode; you must restart it without this switch for this grant to work", "Unknown table engine '%s'", -"'%s' is deprecated, use '%s' instead", +"'%s' is deprecated; use '%s' instead", "The target table %-.100s of the %s is not updatable", -"The '%s' feature was disabled; you need MySQL built with '%s' to have it working", +"The '%s' feature is disabled; you need MySQL built with '%s' to have it working", "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" -"Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Truncated incorrect %-.32s value: '%-.128s'" +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index 706ea858121..ace966b693a 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -206,11 +206,11 @@ character-set=latin7 "Tabel '%-.64s' on märgitud vigaseks ja viimane (automaatne?) parandus ebaõnnestus", "Hoiatus: mõnesid transaktsioone mittetoetavaid tabeleid ei suudetud tagasi kerida", "Mitme lausendiga transaktsioon nõudis rohkem ruumi kui lubatud 'max_binlog_cache_size' muutujaga. Suurenda muutuja väärtust ja proovi uuesti", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "Kasutajal %-.64s on juba rohkem ühendusi kui lubatud 'max_user_connections' muutujaga", "Ainult konstantsed suurused on lubatud SET klauslis", "Kontrollaeg ületatud luku järel ootamisel; Proovi transaktsiooni otsast alata", @@ -235,44 +235,44 @@ character-set=latin7 "Transaktsioone toetavate ning mittetoetavate tabelite kooskasutamine ei ole lubatud", "Määrangut '%s' on lauses kasutatud topelt", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -280,13 +280,13 @@ character-set=latin7 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -301,9 +301,13 @@ character-set=latin7 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 7a7c4bbcbe0..63568b9ebd7 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -165,7 +165,7 @@ character-set=latin1 "Timeout en lecture des paquets reçus", "Erreur d'écriture des paquets envoyés", "Timeout d'écriture des paquets envoyés", -"La chaîne résultat est plus grande que max_allowed_packet", +"La chaîne résultat est plus grande que 'max_allowed_packet'", "Ce type de table ne supporte pas les colonnes BLOB/TEXT", "Ce type de table ne supporte pas les colonnes AUTO_INCREMENT", "INSERT DELAYED ne peut être utilisé avec la table '%-.64s', car elle est verrouée avec LOCK TABLES", @@ -224,50 +224,50 @@ character-set=latin1 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -275,13 +275,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -296,9 +296,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index dee216f3bfd..d2588b10092 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -177,7 +177,7 @@ character-set=latin1 "Zeitüberschreitung beim Lesen eines Kommunikationspakets", "Fehler beim Schreiben eines Kommunikationspakets", "Zeitüberschreitung beim Schreiben eines Kommunikationspakets", -"Ergebnis ist länger als max_allowed_packet", +"Ergebnis ist länger als 'max_allowed_packet'", "Der verwendete Tabellentyp unterstützt keine BLOB- und TEXT-Spalten", "Der verwendete Tabellentyp unterstützt keine AUTO_INCREMENT-Spalten", "INSERT DELAYED kann nicht auf Tabelle '%-.64s' angewendet werden, da diese mit LOCK TABLES gesperrt ist", @@ -258,7 +258,7 @@ character-set=latin1 "Schlüssel- und Tabellenverweis passen nicht zusammen", "Operand solle %d Spalte(n) enthalten", "Unterabfrage lieferte mehr als einen Datensatz zurück", -"Unbekannter Prepared-Statement-Handler (%ld) für %s angegeben", +"Unbekannter Prepared-Statement-Handler (%.*s) für %s angegeben", "Die Hilfe-Datenbank ist beschädigt oder existiert nicht", "Zyklischer Verweis in Unterabfragen", "Spalte '%s' wird von %s nach %s umgewandelt", @@ -272,10 +272,10 @@ character-set=latin1 "Slave läuft bereits", "Slave wurde bereits angehalten", "Unkomprimierte Daten sind zu groß. Die maximale Größe beträgt %d", -"Z_MEM_ERROR: Für zlib steht nicht genug Speicher zur Verfügung", -"Z_BUF_ERROR: Im Ausgabepuffer ist nicht genug Platz für zlib vorhanden (wahrscheinlich wurde die Länge der unkomprimierten Daten beschädigt)", -"Z_DATA_ERROR: Eingabedaten für zlib beschädigt", -"%d Zeile(n) durch group_concat() abgeschnitten", +"ZLIB: Steht nicht genug Speicher zur Verfügung", +"ZLIB: Im Ausgabepuffer ist nicht genug Platz vorhanden (wahrscheinlich wurde die Länge der unkomprimierten Daten beschädigt)", +"ZLIB: Eingabedaten beschädigt", +"%d Zeile(n) durch GROUP_CONCAT() abgeschnitten", "Anzahl der Datensätze in Zeile %ld geringer als Anzahl der Spalten", "Anzahl der Datensätze in Zeile %ld größer als Anzahl der Spalten", "Daten abgeschnitten, NULL für NOT NULL-Spalte '%s' in Zeile %ld angegeben", @@ -308,9 +308,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index d5ba8d93cd1..2d099e149f6 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -138,16 +138,16 @@ character-set=greek "ÐñÝðåé íá Ý÷åôå äéêáßùìá äéüñèùóçò ðéíÜêùí (update) óôç âÜóç äåäïìÝíùí mysql ãéá íá ìðïñåßôå íá áëëÜîåôå ôá passwords Üëëùí ÷ñçóôþí", "Äåí åßíáé äõíáôÞ ç áíåýñåóç ôçò áíôßóôïé÷çò åããñáöÞò óôïí ðßíáêá ôùí ÷ñçóôþí", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory, you can consult the manual for a possible OS-dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s'", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privileges can be used.", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%-.64s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -156,7 +156,7 @@ character-set=greek "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-32s' (%-.64s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -165,7 +165,7 @@ character-set=greek "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -174,7 +174,7 @@ character-set=greek "All tables in the MERGE table are not identically defined", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -200,23 +200,23 @@ character-set=greek "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -224,50 +224,50 @@ character-set=greek "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -275,13 +275,13 @@ character-set=greek "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -296,9 +296,13 @@ character-set=greek "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index 235d09e760c..ac9539b35cf 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -109,7 +109,7 @@ character-set=latin2 "A(z) '%-.64s' blob objektumnak nem lehet alapertelmezett erteke", "Hibas adatbazisnev: '%-.100s'", "Hibas tablanev: '%-.100s'", -"A SELECT tul sok rekordot fog megvizsgalni es nagyon sokaig fog tartani. Ellenorizze a WHERE-t es hasznalja a SET SQL_BIG_SELECTS=1 beallitast, ha a SELECT ok", +"A SELECT tul sok rekordot fog megvizsgalni es nagyon sokaig fog tartani. Ellenorizze a WHERE-t es hasznalja a SET SQL_BIG_SELECTS=1 beallitast, ha a SELECT okay", "Ismeretlen hiba", "Ismeretlen eljaras: '%-.64s'", "Rossz parameter a(z) '%-.64s'eljaras szamitasanal", @@ -167,7 +167,7 @@ character-set=latin2 "Idotullepes a kommunikacios adatcsomagok olvasasa soran", "Hiba a kommunikacios csomagok irasa soran", "Idotullepes a kommunikacios csomagok irasa soran", -"Ez eredmeny sztring nagyobb, mint a lehetseges maximum: max_allowed_packet", +"Ez eredmeny sztring nagyobb, mint a lehetseges maximum: 'max_allowed_packet'", "A hasznalt tabla tipus nem tamogatja a BLOB/TEXT mezoket", "A hasznalt tabla tipus nem tamogatja az AUTO_INCREMENT tipusu mezoket", "Az INSERT DELAYED nem hasznalhato a '%-.64s' tablahoz, mert a tabla zarolt (LOCK TABLES)", @@ -202,23 +202,23 @@ character-set=latin2 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -226,50 +226,50 @@ character-set=latin2 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -277,13 +277,13 @@ character-set=latin2 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -298,9 +298,13 @@ character-set=latin2 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index b5eaabe9824..33ea2cb2a9d 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -165,7 +165,7 @@ character-set=latin1 "Rilevato un timeout ricevendo i pacchetti di comunicazione", "Rilevato un errore inviando i pacchetti di comunicazione", "Rilevato un timeout inviando i pacchetti di comunicazione", -"La stringa di risposta e` piu` lunga di max_allowed_packet", +"La stringa di risposta e` piu` lunga di 'max_allowed_packet'", "Il tipo di tabella usata non supporta colonne di tipo BLOB/TEXT", "Il tipo di tabella usata non supporta colonne di tipo AUTO_INCREMENT", "L'inserimento ritardato (INSERT DELAYED) non puo` essere usato con la tabella '%-.64s', perche` soggetta a lock da 'LOCK TABLES'", @@ -242,32 +242,32 @@ character-set=latin1 "Errore fatale %d: '%-.128s' dal master leggendo i dati dal log binario", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -275,13 +275,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -296,9 +296,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index a4cb4cd513d..6bb82cc9749 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -50,7 +50,7 @@ character-set=ujis "¤½¤Î address ¤Î hostname ¤¬°ú¤±¤Þ¤»¤ó.", "Bad handshake", "¥æ¡¼¥¶¡¼ '%-.32s'@'%-.64s' ¤Î '%-.64s' ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤Î¥¢¥¯¥»¥¹¤òµñÈݤ·¤Þ¤¹", -"¥æ¡¼¥¶¡¼ '%-.32s'@'%-.64s' ¤òµñÈݤ·¤Þ¤¹.(Using password: %s)", +"¥æ¡¼¥¶¡¼ '%-.32s'@'%-.64s' ¤òµñÈݤ·¤Þ¤¹.uUsing password: %s)", "¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤Þ¤»¤ó.", "¤½¤Î¥³¥Þ¥ó¥É¤Ï²¿¡©", "Column '%-.64s' ¤Ï null ¤Ë¤Ï¤Ç¤¤Ê¤¤¤Î¤Ç¤¹", @@ -75,12 +75,12 @@ character-set=ujis "Invalid default value for '%-.64s'", "Ê£¿ô¤Î primary key ¤¬ÄêµÁ¤µ¤ì¤Þ¤·¤¿", "key ¤Î»ØÄ꤬¿¤¹¤®¤Þ¤¹. key ¤ÏºÇÂç %d ¤Þ¤Ç¤Ç¤¹", -"Too many key parts specified. Max %d parts allowed", +"Too many key parts specified; max %d parts allowed", "key ¤¬Ä¹¤¹¤®¤Þ¤¹. key ¤ÎŤµ¤ÏºÇÂç %d ¤Ç¤¹", "Key column '%-.64s' ¤¬¥Æ¡¼¥Ö¥ë¤Ë¤¢¤ê¤Þ¤»¤ó.", "BLOB column '%-.64s' can't be used in key specification with the used table type", "column '%-.64s' ¤Ï,³ÎÊݤ¹¤ë column ¤ÎÂ礤µ¤¬Â¿¤¹¤®¤Þ¤¹. (ºÇÂç %d ¤Þ¤Ç). BLOB ¤ò¤«¤ï¤ê¤Ë»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤.", -"¥Æ¡¼¥Ö¥ë¤ÎÄêµÁ¤¬°ã¤¤¤Þ¤¹; There can only be one auto column and it must be defined as a key", +"¥Æ¡¼¥Ö¥ë¤ÎÄêµÁ¤¬°ã¤¤¤Þ¤¹; there can be only one auto column and it must be defined as a key", "%s: ½àÈ÷´°Î»\n", "%s: Normal shutdown\n", "%s: Got signal %d. ÃæÃÇ!\n", @@ -88,15 +88,15 @@ character-set=ujis "%s: ¥¹¥ì¥Ã¥É %ld ¶¯À©½ªÎ» user: '%-.64s'\n", "IP socket ¤¬ºî¤ì¤Þ¤»¤ó", "Table '%-.64s' ¤Ï¤½¤Î¤è¤¦¤Ê index ¤ò»ý¤Ã¤Æ¤¤¤Þ¤»¤ó(CREATE INDEX ¼Â¹Ô»þ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó). ¥Æ¡¼¥Ö¥ë¤òºî¤êľ¤·¤Æ¤¯¤À¤µ¤¤", -"Field separator argument is not what is expected. Check the manual", -"You can't use fixed rowlength with BLOBs. Please use 'fields terminated by'.", +"Field separator argument is not what is expected; check the manual", +"You can't use fixed rowlength with BLOBs; please use 'fields terminated by'.", "¥Õ¥¡¥¤¥ë '%-.64s' ¤Ï databse ¤Î directory ¤Ë¤¢¤ë¤«Á´¤Æ¤Î¥æ¡¼¥¶¡¼¤¬Æɤá¤ë¤è¤¦¤Ëµö²Ä¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó.", "File '%-.64s' ¤Ï´û¤Ë¸ºß¤·¤Þ¤¹", "¥ì¥³¡¼¥É¿ô: %ld ºï½ü: %ld Skipped: %ld Warnings: %ld", "¥ì¥³¡¼¥É¿ô: %ld ½ÅÊ£: %ld", -"Incorrect sub part key. The used key part isn't a string or the used length is longer than the key part", +"Incorrect sub part key; the used key part isn't a string or the used length is longer than the key part", "ALTER TABLE ¤ÇÁ´¤Æ¤Î column ¤Ïºï½ü¤Ç¤¤Þ¤»¤ó. DROP TABLE ¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤", -"'%-.64s' ¤òÇË´þ¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿. Check that column/key exists", +"'%-.64s' ¤òÇË´þ¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿; check that column/key exists", "¥ì¥³¡¼¥É¿ô: %ld ½ÅÊ£¿ô: %ld Warnings: %ld", "You can't specify target table '%-.64s' for update in FROM clause", "thread id: %lu ¤Ï¤¢¤ê¤Þ¤»¤ó", @@ -109,7 +109,7 @@ character-set=ujis "BLOB column '%-.64s' can't have a default value", "»ØÄꤷ¤¿ database ̾ '%-.100s' ¤¬´Ö°ã¤Ã¤Æ¤¤¤Þ¤¹", "»ØÄꤷ¤¿ table ̾ '%-.100s' ¤Ï¤Þ¤Á¤¬¤Ã¤Æ¤¤¤Þ¤¹", -"The SELECT would examine more rows than MAX_JOIN_SIZE. Check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is ok", +"The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay", "Unknown error", "Unknown procedure '%-.64s'", "Incorrect parameter count to procedure '%-.64s'", @@ -121,11 +121,11 @@ character-set=ujis "¥Æ¡¼¥Ö¥ë¤ÏºÇÄã 1 ¸Ä¤Î column ¤¬É¬ÍפǤ¹", "table '%-.64s' ¤Ï¤¤¤Ã¤Ñ¤¤¤Ç¤¹", "character set '%-.64s' ¤Ï¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤»¤ó", -"¥Æ¡¼¥Ö¥ë¤¬Â¿¤¹¤®¤Þ¤¹. MySQL can only use %d tables in a join", +"¥Æ¡¼¥Ö¥ë¤¬Â¿¤¹¤®¤Þ¤¹; MySQL can only use %d tables in a join", "column ¤¬Â¿¤¹¤®¤Þ¤¹", "row size ¤¬Â礤¹¤®¤Þ¤¹. BLOB ¤ò´Þ¤Þ¤Ê¤¤¾ì¹ç¤Î row size ¤ÎºÇÂç¤Ï %d ¤Ç¤¹. ¤¤¤¯¤Ä¤«¤Î field ¤ò BLOB ¤ËÊѤ¨¤Æ¤¯¤À¤µ¤¤.", "Thread stack overrun: Used: %ld of a %ld stack. ¥¹¥¿¥Ã¥¯Îΰè¤ò¿¤¯¤È¤ê¤¿¤¤¾ì¹ç¡¢'mysqld -O thread_stack=#' ¤È»ØÄꤷ¤Æ¤¯¤À¤µ¤¤", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "Column '%-.64s' ¤¬ UNIQUE ¤« INDEX ¤Ç»ÈÍѤµ¤ì¤Þ¤·¤¿. ¤³¤Î¥«¥é¥à¤Ï NOT NULL ¤ÈÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó.", "function '%-.64s' ¤ò ¥í¡¼¥É¤Ç¤¤Þ¤»¤ó", "function '%-.64s' ¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó; %-.80s", @@ -145,11 +145,11 @@ character-set=ujis "Can't reopen table: '%-.64s'", "NULL ÃͤλÈÍÑÊýË¡¤¬ÉÔŬÀڤǤ¹", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "¥æ¡¼¥¶¡¼ '%-.32s' (¥Û¥¹¥È '%-.64s' ¤Î¥æ¡¼¥¶¡¼) ¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó", "¥³¥Þ¥ó¥É %-.16s ¤Ï ¥æ¡¼¥¶¡¼ '%-.32s'@'%-.64s' ,¥Æ¡¼¥Ö¥ë '%-.64s' ¤ËÂФ·¤Æµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó", "¥³¥Þ¥ó¥É %-.16s ¤Ï ¥æ¡¼¥¶¡¼ '%-.32s'@'%-.64s'\n ¥«¥é¥à '%-.64s' ¥Æ¡¼¥Ö¥ë '%-.64s' ¤ËÂФ·¤Æµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó", -"Illegal GRANT/REVOKE command. Please consult the manual which privleges can be used.", +"Illegal GRANT/REVOKE command; please consult the manual to see which privleges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -158,7 +158,7 @@ character-set=ujis "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.64s' (%s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -167,7 +167,7 @@ character-set=ujis "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -176,7 +176,7 @@ character-set=ujis "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -202,23 +202,23 @@ character-set=ujis "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -226,50 +226,50 @@ character-set=ujis "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -277,13 +277,13 @@ character-set=ujis "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -299,8 +299,12 @@ character-set=ujis "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" "Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got NDB error %d '%-.100s'", +"Got temporary NDB error %d '%-.100s'", +"Unknown or incorrect time zone: '%-.64s'", ++ "Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 091e19e8b71..884ce735815 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -48,7 +48,7 @@ character-set=euckr "´ç½ÅÀÇ ÄÄÇ»ÅÍÀÇ È£½ºÆ®À̸§À» ¾òÀ» ¼ö ¾øÀ¾´Ï´Ù.", "Bad handshake", "'%-.32s'@'%-.64s' »ç¿ëÀÚ´Â '%-.64s' µ¥ÀÌŸº£À̽º¿¡ Á¢±ÙÀÌ °ÅºÎ µÇ¾ú½À´Ï´Ù.", -"'%-.32s'@'%-.64s' »ç¿ëÀÚ´Â Á¢±ÙÀÌ °ÅºÎ µÇ¾ú½À´Ï´Ù. (Using password: %s)", +"'%-.32s'@'%-.64s' »ç¿ëÀÚ´Â Á¢±ÙÀÌ °ÅºÎ µÇ¾ú½À´Ï´Ù. (using password: %s)", "¼±ÅÃµÈ µ¥ÀÌŸº£À̽º°¡ ¾ø½À´Ï´Ù.", "¸í·É¾î°¡ ¹ºÁö ¸ð¸£°Ú¾î¿ä...", "Ä®·³ '%-.64s'´Â ³Î(Null)ÀÌ µÇ¸é ¾ÈµË´Ï´Ù. ", @@ -123,7 +123,7 @@ character-set=euckr "Ä®·³ÀÌ ³Ê¹« ¸¹½À´Ï´Ù.", "³Ê¹« Å« row »çÀÌÁîÀÔ´Ï´Ù. BLOB¸¦ °è»êÇÏÁö ¾Ê°í ÃÖ´ë row »çÀÌÁî´Â %dÀÔ´Ï´Ù. ¾ó¸¶°£ÀÇ ÇʵåµéÀ» BLOB·Î ¹Ù²Ù¼Å¾ß °Ú±º¿ä..", "¾²·¹µå ½ºÅÃÀÌ ³ÑÃƽÀ´Ï´Ù. »ç¿ë: %ld°³ ½ºÅÃ: %ld°³. ¸¸¾à ÇÊ¿ä½Ã ´õÅ« ½ºÅÃÀ» ¿øÇÒ¶§¿¡´Â 'mysqld -O thread_stack=#' ¸¦ Á¤ÀÇÇϼ¼¿ä", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "'%-.64s' Ä®·³ÀÌ UNIQUE³ª INDEX¸¦ »ç¿ëÇÏ¿´Áö¸¸ NOT NULLÀÌ Á¤ÀǵÇÁö ¾Ê¾Ò±º¿ä...", "'%-.64s' ÇÔ¼ö¸¦ ·ÎµåÇÏÁö ¸øÇß½À´Ï´Ù.", "'%-.64s' ÇÔ¼ö¸¦ ÃʱâÈ ÇÏÁö ¸øÇß½À´Ï´Ù.; %-.80s", @@ -143,7 +143,7 @@ character-set=euckr "Å×À̺íÀ» ´Ù½Ã ¿¼ö ¾ø±º¿ä: '%-.64s", "NULL °ªÀ» À߸ø »ç¿ëÇϼ̱º¿ä...", "regexp¿¡¼ '%-.64s'°¡ ³µ½À´Ï´Ù.", -"Mixing of GROUP Ä®·³s (MIN(),MAX(),COUNT()...) with no GROUP Ä®·³s is illegal if there is no GROUP BY clause", +"Mixing of GROUP Ä®·³s (MIN(),MAX(),COUNT(),...) with no GROUP Ä®·³s is illegal if there is no GROUP BY clause", "»ç¿ëÀÚ '%-.32s' (È£½ºÆ® '%-.64s')¸¦ À§ÇÏ¿© Á¤ÀÇµÈ ±×·± ½ÂÀÎÀº ¾ø½À´Ï´Ù.", "'%-.16s' ¸í·ÉÀº ´ÙÀ½ »ç¿ëÀÚ¿¡°Ô °ÅºÎµÇ¾ú½À´Ï´Ù. : '%-.32s'@'%-.64s' for Å×À̺í '%-.64s'", "'%-.16s' ¸í·ÉÀº ´ÙÀ½ »ç¿ëÀÚ¿¡°Ô °ÅºÎµÇ¾ú½À´Ï´Ù. : '%-.32s'@'%-.64s' for Ä®·³ '%-.64s' in Å×À̺í '%-.64s'", @@ -165,7 +165,7 @@ character-set=euckr "Åë½Å ÆÐŶÀ» Àд Áß timeoutÀÌ ¹ß»ýÇÏ¿´½À´Ï´Ù.", "Åë½Å ÆÐŶÀ» ±â·ÏÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.", "Åë½Å ÆÐÆÂÀ» ±â·ÏÇÏ´Â Áß timeoutÀÌ ¹ß»ýÇÏ¿´½À´Ï´Ù.", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -174,7 +174,7 @@ character-set=euckr "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -200,23 +200,23 @@ character-set=euckr "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -224,50 +224,50 @@ character-set=euckr "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -275,13 +275,13 @@ character-set=euckr "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -296,9 +296,13 @@ character-set=euckr "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index f42eeb93a94..27ebe984c7e 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -121,35 +121,35 @@ character-set=latin1 "A table must have at least 1 column", "The table '%-.64s' is full", "Unknown character set: '%-.64s'", -"Too many tables. MySQL can only use %d tables in a join", -"Too many fields", -"Too big row size. The maximum row size, not counting blobs, is %d. You have to change some fields to blobs", +"Too many tables; MySQL can only use %d tables in a join", +"Too many columns", +"Row size too large. The maximum row size for the used table type, not counting BLOBs, is %ld. You have to change some columns to TEXT or BLOBs", "Thread stack overrun: Used: %ld of a %ld stack. Use 'mysqld -O thread_stack=#' to specify a bigger stack if needed", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "Column '%-.32s' is used with UNIQUE or INDEX but is not defined as NOT NULL", "Can't load function '%-.64s'", "Can't initialize function '%-.64s'; %-.80s", "No paths allowed for shared library", -"Function '%-.64s' already exist", +"Function '%-.64s' already exists", "Can't open shared library '%-.64s' (errno: %d %s)", "Can't find function '%-.64s' in library'", "Function '%-.64s' is not defined", -"Host '%-.64s' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'", +"Host '%-.64s' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'", "Host '%-.64s' is not allowed to connect to this MySQL server", -"You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords", +"You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords", "You must have privileges to update tables in the mysql database to be able to change passwords for others", "Can't find any matching row in the user table", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory you can consult the manual for any possible OS dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory you can consult the manual for any possible OS dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privleges can be used.", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privleges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -158,7 +158,7 @@ character-set=latin1 "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.64s' (%s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -167,7 +167,7 @@ character-set=latin1 "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -176,7 +176,7 @@ character-set=latin1 "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -202,23 +202,23 @@ character-set=latin1 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -226,50 +226,50 @@ character-set=latin1 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -277,13 +277,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -298,9 +298,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Mottok feil %d '%-.100s' fra %s", +"Mottok temporary feil %d '%-.100s' fra %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index 71e14b3df5b..764032da9da 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -121,35 +121,35 @@ character-set=latin1 "A table must have at least 1 column", "The table '%-.64s' is full", "Unknown character set: '%-.64s'", -"Too many tables. MySQL can only use %d tables in a join", -"Too many fields", -"Too big row size. The maximum row size, not counting blobs, is %d. You have to change some fields to blobs", +"Too many tables; MySQL can only use %d tables in a join", +"Too many columns", +"Row size too large. The maximum row size for the used table type, not counting BLOBs, is %ld. You have to change some columns to TEXT or BLOBs", "Thread stack overrun: Used: %ld of a %ld stack. Use 'mysqld -O thread_stack=#' to specify a bigger stack if needed", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "Column '%-.32s' is used with UNIQUE or INDEX but is not defined as NOT NULL", "Can't load function '%-.64s'", "Can't initialize function '%-.64s'; %-.80s", "No paths allowed for shared library", -"Function '%-.64s' already exist", +"Function '%-.64s' already exists", "Can't open shared library '%-.64s' (errno: %d %s)", "Can't find function '%-.64s' in library'", "Function '%-.64s' is not defined", -"Host '%-.64s' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'", +"Host '%-.64s' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'", "Host '%-.64s' is not allowed to connect to this MySQL server", -"You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords", +"You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords", "You must have privileges to update tables in the mysql database to be able to change passwords for others", "Can't find any matching row in the user table", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory you can consult the manual for any possible OS dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory you can consult the manual for any possible OS dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privleges can be used.", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privleges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -158,7 +158,7 @@ character-set=latin1 "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.64s' (%s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -167,7 +167,7 @@ character-set=latin1 "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -176,7 +176,7 @@ character-set=latin1 "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -202,23 +202,23 @@ character-set=latin1 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -226,50 +226,50 @@ character-set=latin1 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -277,13 +277,13 @@ character-set=latin1 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -298,9 +298,13 @@ character-set=latin1 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Mottok feil %d '%-.100s' fa %s", +"Mottok temporary feil %d '%-.100s' fra %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index 51e23c18dfd..68464d0b8f1 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -51,8 +51,8 @@ character-set=latin2 "Zbyt ma³o miejsca/pamiêci dla w?tku", "Nie mo¿na otrzymaæ nazwy hosta dla twojego adresu", "Z³y uchwyt(handshake)", -"Access denied for user: '%-.32s'@'%-.64s' to database '%-.64s'", -"Access denied for user: '%-.32s'@'%-.64s' (Using password: %s)", +"Access denied for user '%-.32s'@'%-.64s' to database '%-.64s'", +"Access denied for user '%-.32s'@'%-.64s' (using password: %s)", "Nie wybrano ¿adnej bazy danych", "Nieznana komenda", "Kolumna '%-.64s' nie mo¿e byæ null", @@ -114,8 +114,8 @@ character-set=latin2 "Operacja SELECT bêdzie dotyczy³a zbyt wielu rekordów i prawdopodobnie zajmie bardzo du¿o czasu. Sprawd¥ warunek WHERE i u¿yj SQL_OPTION BIG_SELECTS=1 je?li operacja SELECT jest poprawna", "Unknown error", "Unkown procedure %s", -"Wrong parameter count to procedure %s", -"Wrong parameters to procedure %s", +"Incorrect parameter count to procedure %s", +"Incorrect parameters to procedure %s", "Unknown table '%-.64s' in %s", "Field '%-.64s' specified twice", "Invalid use of group function", @@ -123,35 +123,35 @@ character-set=latin2 "A table must have at least 1 column", "The table '%-.64s' is full", "Unknown character set: '%-.64s'", -"Too many tables. MySQL can only use %d tables in a join", -"Too many fields", -"Too big row size. The maximum row size, not counting blobs, is %d. You have to change some fields to blobs", +"Too many tables; MySQL can only use %d tables in a join", +"Too many columns", +"Row size too large. The maximum row size for the used table type, not counting BLOBs, is %ld. You have to change some columns to TEXT or BLOBs", "Thread stack overrun: Used: %ld of a %ld stack. Use 'mysqld -O thread_stack=#' to specify a bigger stack if needed", -"Cross dependency found in OUTER JOIN. Examine your ON conditions", +"Cross dependency found in OUTER JOIN; examine your ON conditions", "Column '%-.32s' is used with UNIQUE or INDEX but is not defined as NOT NULL", "Can't load function '%-.64s'", "Can't initialize function '%-.64s'; %-.80s", "No paths allowed for shared library", -"Function '%-.64s' already exist", +"Function '%-.64s' already exists", "Can't open shared library '%-.64s' (errno: %d %s)", "Can't find function '%-.64s' in library'", "Function '%-.64s' is not defined", -"Host '%-.64s' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'", +"Host '%-.64s' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'", "Host '%-.64s' is not allowed to connect to this MySQL server", -"You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords", +"You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords", "You must have privileges to update tables in the mysql database to be able to change passwords for others", "Can't find any matching row in the user table", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory you can consult the manual for any possible OS dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory you can consult the manual for any possible OS dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privleges can be used.", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privleges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -160,7 +160,7 @@ character-set=latin2 "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.64s' (%s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -169,7 +169,7 @@ character-set=latin2 "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -178,7 +178,7 @@ character-set=latin2 "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -204,23 +204,23 @@ character-set=latin2 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -228,50 +228,50 @@ character-set=latin2 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -279,13 +279,13 @@ character-set=latin2 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -300,9 +300,13 @@ character-set=latin2 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 7a969a6541b..7561f12cb7c 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -78,7 +78,7 @@ character-set=latin1 "Chave especificada longa demais. O comprimento de chave máximo permitido é %d", "Coluna chave '%-.64s' não existe na tabela", "Coluna BLOB '%-.64s' não pode ser utilizada na especificação de chave para o tipo de tabela usado", -"Comprimento da coluna '%-.64s' grande demais (max = %d). Use BLOB em seu lugar", +"Comprimento da coluna '%-.64s' grande demais (max = %d); use BLOB em seu lugar", "Definição incorreta de tabela. Somente é permitido um único campo auto-incrementado e ele tem que ser definido como chave", "%s: Pronto para conexões\n", "%s: 'Shutdown' normal\n", @@ -94,7 +94,7 @@ character-set=latin1 "Registros: %ld - Deletados: %ld - Ignorados: %ld - Avisos: %ld", "Registros: %ld - Duplicados: %ld", "Sub parte da chave incorreta. A parte da chave usada não é uma 'string' ou o comprimento usado é maior que parte da chave ou o manipulador de tabelas não suporta sub chaves únicas", -"Você não pode deletar todas as colunas com ALTER TABLE. Use DROP TABLE em seu lugar", +"Você não pode deletar todas as colunas com ALTER TABLE; use DROP TABLE em seu lugar", "Não se pode fazer DROP '%-.64s'. Confira se esta coluna/chave existe", "Registros: %ld - Duplicados: %ld - Avisos: %ld", "You can't specify target table '%-.64s' for update in FROM clause", @@ -123,8 +123,8 @@ character-set=latin1 "Tabelas demais. O MySQL pode usar somente %d tabelas em uma junção (JOIN)", "Colunas demais", "Tamanho de linha grande demais. O máximo tamanho de linha, não contando BLOBs, é %d. Você tem que mudar alguns campos para BLOBs", -"Estouro da pilha do 'thread'. Usados %ld de uma pilha de %ld . Use 'mysqld -O thread_stack=#' para especificar uma pilha maior, se necessário", -"Dependência cruzada encontrada em junção externa (OUTER JOIN). Examine as condições utilizadas nas cláusulas 'ON'", +"Estouro da pilha do 'thread'. Usados %ld de uma pilha de %ld. Use 'mysqld -O thread_stack=#' para especificar uma pilha maior, se necessário", +"Dependência cruzada encontrada em junção externa (OUTER JOIN); examine as condições utilizadas nas cláusulas 'ON'", "Coluna '%-.64s' é usada com única (UNIQUE) ou índice (INDEX), mas não está definida como não-nula (NOT NULL)", "Não pode carregar a função '%-.64s'", "Não pode inicializar a função '%-.64s' - '%-.80s'", @@ -247,24 +247,24 @@ character-set=latin1 "Referência da chave e referência da tabela não coincidem", "Operand should contain %d column(s)", "Subconsulta retorna mais que 1 registro", -"Desconhecido manipulador de declaração preparado (%ld) determinado para %s", +"Desconhecido manipulador de declaração preparado (%.*s) determinado para %s", "Banco de dado de ajuda corrupto ou não existente", "Referência cíclica em subconsultas", "Convertendo coluna '%s' de %s para %s", "Referência '%-.64s' não suportada (%s)", "Cada tabela derivada deve ter seu próprio alias", "Select %u foi reduzido durante otimização", -"Tabela '%-.64s' de um dos SELECT's não pode ser usada em %-.32s", +"Tabela '%-.64s' de um dos SELECTs não pode ser usada em %-.32s", "Cliente não suporta o protocolo de autenticação exigido pelo servidor; considere a atualização do cliente MySQL", "Todas as partes de uma SPATIAL KEY devem ser NOT NULL", "COLLATION '%s' não é válida para CHARACTER SET '%s'", "O slave já está rodando", "O slave já está parado", "Tamanho muito grande dos dados des comprimidos. O máximo tamanho é %d. (provavelmente, o comprimento dos dados descomprimidos está corrupto)", -"Z_MEM_ERROR: Não suficiente memória disponível para zlib", -"Z_BUF_ERROR: Não suficiente espaço no buffer emissor para zlib (provavelmente, o comprimento dos dados descomprimidos está corrupto)", -"Z_DATA_ERROR: Dados de entrada está corrupto para zlib", -"%d linha(s) foi(foram) cortada(s) por group_concat()", +"ZLIB: Não suficiente memória disponível", +"ZLIB: Não suficiente espaço no buffer emissor (provavelmente, o comprimento dos dados descomprimidos está corrupto)", +"ZLIB: Dados de entrada está corrupto", +"%d linha(s) foram cortada(s) por GROUP_CONCAT()", "Conta de registro é menor que a conta de coluna na linha %ld", "Conta de registro é maior que a conta de coluna na linha %ld", "Dado truncado, NULL fornecido para NOT NULL coluna '%s' na linha %ld", @@ -300,6 +300,10 @@ character-set=latin1 "Incorreta definição de tabela; Pode ter somente uma coluna TIMESTAMP com CURRENT_TIMESTAMP em DEFAULT ou ON UPDATE cláusula" "Inválida cláusula ON UPDATE para campo '%-.64s'", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index c53c9b11d0d..03dd45fb6c2 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -111,7 +111,7 @@ character-set=latin2 "Coloana BLOB '%-.64s' nu poate avea o valoare default", "Numele bazei de date este incorect '%-.100s'", "Numele tabelei este incorect '%-.100s'", -"SELECT-ul ar examina prea multe cimpuri si probabil ar lua prea mult timp. Verifica clauza WHERE si foloseste SET SQL_BIG_SELECTS=1 daca SELECT-ul e ok", +"SELECT-ul ar examina prea multe cimpuri si probabil ar lua prea mult timp; verifica clauza WHERE si foloseste SET SQL_BIG_SELECTS=1 daca SELECT-ul e okay", "Eroare unknown", "Procedura unknown '%-.64s'", "Procedura '%-.64s' are un numar incorect de parametri", @@ -169,7 +169,7 @@ character-set=latin2 "Timeout obtinut citind pachetele de comunicatie (communication packets)", "Eroare in scrierea pachetelor de comunicatie (communication packets)", "Timeout obtinut scriind pachetele de comunicatie (communication packets)", -"Sirul rezultat este mai lung decit max_allowed_packet", +"Sirul rezultat este mai lung decit 'max_allowed_packet'", "Tipul de tabela folosit nu suporta coloane de tip BLOB/TEXT", "Tipul de tabela folosit nu suporta coloane de tip AUTO_INCREMENT", "INSERT DELAYED nu poate fi folosit cu tabela '%-.64s', deoarece este locked folosing LOCK TABLES", @@ -192,7 +192,7 @@ character-set=latin2 "Got error %d during FLUSH_LOGS", "Got error %d during CHECKPOINT", "Aborted connection %ld to db: '%-.64s' user: '%-.32s' host: `%-.64s' (%-.64s)", -"The handler for the table does not support binary table dump","Binlog closed while trying to FLUSH MASTER", +"The handler for the table does not support binary table dump", "Binlog closed while trying to FLUSH MASTER", "Failed rebuilding the index of dumped table '%-.64s'", "Error from master: '%-.64s'", @@ -204,23 +204,23 @@ character-set=latin2 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", -"This operation cannot be performed with a running slave, run STOP SLAVE first", -"This operation requires a running slave, configure slave and do START SLAVE", -"The server is not configured as slave, fix in config file or with CHANGE MASTER TO", -"Could not initialize master info structure, more error messages can be found in the MySQL error log", -"Could not create slave thread, check system resources", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", +"This operation cannot be performed with a running slave; run STOP SLAVE first", +"This operation requires a running slave; configure slave and do START SLAVE", +"The server is not configured as slave; fix in config file or with CHANGE MASTER TO", +"Could not initialize master info structure; more error messages can be found in the MySQL error log", +"Could not create slave thread; check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -228,50 +228,50 @@ character-set=latin2 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -279,13 +279,13 @@ character-set=latin2 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -300,9 +300,13 @@ character-set=latin2 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 30a024ef86a..3b0286ea3f8 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -244,32 +244,32 @@ character-set=koi8r "ðÏÌÕÞÅÎÁ ÎÅÉÓÐÒÁ×ÉÍÁÑ ÏÛÉÂËÁ %d: '%-.128s' ÏÔ ÇÏÌÏ×ÎÏÇÏ ÓÅÒ×ÅÒÁ × ÐÒÏÃÅÓÓÅ ×ÙÂÏÒËÉ ÄÁÎÎÙÈ ÉÚ Ä×ÏÉÞÎÏÇÏ ÖÕÒÎÁÌÁ", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "ïÐÅÒÁÎÄ ÄÏÌÖÅÎ ÓÏÄÅÒÖÁÔØ %d ËÏÌÏÎÏË", "ðÏÄÚÁÐÒÏÓ ×ÏÚ×ÒÁÝÁÅÔ ÂÏÌÅÅ ÏÄÎÏÊ ÚÁÐÉÓÉ", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "ãÉËÌÉÞÅÓËÁÑ ÓÓÙÌËÁ ÎÁ ÐÏÄÚÁÐÒÏÓ", "ðÒÅÏÂÒÁÚÏ×ÁÎÉÅ ÐÏÌÑ '%s' ÉÚ %s × %s", "óÓÙÌËÁ '%-.64s' ÎÅ ÐÏÄÄÅÒÖÉ×ÁÅÔÓÑ (%s)", -"Every derived table must have it's own alias", +"Every derived table must have its own alias", "Select %u ÂÙÌ ÕÐÒÁÚÄÎÅÎ × ÐÒÏÃÅÓÓÅ ÏÐÔÉÍÉÚÁÃÉÉ", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -277,13 +277,13 @@ character-set=koi8r "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "óÅÒ×ÅÒ ÚÁÐÕÝÅÎ × ÒÅÖÉÍÅ --secure-auth (ÂÅÚÏÐÁÓÎÏÊ Á×ÔÏÒÉÚÁÃÉÉ), ÎÏ ÄÌÑ ÐÏÌØÚÏ×ÁÔÅÌÑ '%s'@'%s' ÐÁÒÏÌØ ÓÏÈÒÁÎ£Î × ÓÔÁÒÏÍ ÆÏÒÍÁÔÅ; ÎÅÏÂÈÏÄÉÍÏ ÏÂÎÏ×ÉÔØ ÆÏÒÍÁÔ ÐÁÒÏÌÑ", "ðÏÌÅ ÉÌÉ ÓÓÙÌËÁ '%-.64s%s%-.64s%s%-.64s' ÉÚ SELECTÁ #%d ÂÙÌÁ ÎÁÊÄÅÎÁ × SELECTÅ #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -298,9 +298,13 @@ character-set=koi8r "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index 18633e0b7be..a64d9056701 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -236,8 +236,20 @@ character-set=cp1250 "Mešanje tabela koje podržavaju transakcije i onih koje ne podržavaju transakcije je iskljuèeno", "Opcija '%s' je upotrebljena dva puta u istom iskazu", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Access denied; you need the %-.128s privilege for this operation", +"Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", +"Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", +"Variable '%-.64s' doesn't have a default value", +"Variable '%-.64s' can't be set to the value of '%-.64s'", +"Incorrect argument type to variable '%-.64s'", +"Variable '%-.64s' can only be set, not read", +"Incorrect usage/placement of '%s'", +"This version of MySQL doesn't yet support '%s'", +"Got fatal error %d: '%-.128s' from master when reading data from binary log", +"Slave SQL thread ignored the query because of replicate-*-table rules", +"Variable '%-.64s' is a %s variable", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", "Unknown prepared statement handler (%ld) given to %s", @@ -245,23 +257,23 @@ character-set=cp1250 "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", "Row %ld was truncated; it contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -269,13 +281,13 @@ character-set=cp1250 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -290,9 +302,13 @@ character-set=cp1250 "The MySQL server is running with the %s option so it cannot execute this statement" "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index 5cd9b4f0e26..ebd64f34f88 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -100,8 +100,8 @@ character-set=latin2 "Súbor '%-.64s' u¾ existuje", "Záznamov: %ld Zmazaných: %ld Preskoèených: %ld Varovania: %ld", "Záznamov: %ld Opakovaných: %ld", -"Wrong sub part key. The used key part isn't a string or the used length is longer than the key part", -"One nemô¾em zmaza» all fields with ALTER TABLE. Use DROP TABLE instead", +"Incorrect sub part key; the used key part isn't a string or the used length is longer than the key part", +"One nemô¾em zmaza» all fields with ALTER TABLE; use DROP TABLE instead", "Nemô¾em zru¹i» (DROP) '%-.64s'. Skontrolujte, èi neexistujú záznamy/kµúèe", "Záznamov: %ld Opakovaných: %ld Varovania: %ld", "You can't specify target table '%-.64s' for update in FROM clause", @@ -140,22 +140,22 @@ character-set=latin2 "Nemô¾em otvori» zdieµanú kni¾nicu '%-.64s' (chybový kód: %d %s)", "Nemô¾em nájs» funkciu '%-.64s' v kni¾nici'", "Funkcia '%-.64s' nie je definovaná", -"Host '%-.64s' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'", +"Host '%-.64s' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'", "Host '%-.64s' is not allowed to connect to this MySQL server", -"You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords", +"You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords", "You must have privileges to update tables in the mysql database to be able to change passwords for others", "Can't find any matching row in the user table", "Rows matched: %ld Changed: %ld Warnings: %ld", -"Can't create a new thread (errno %d). If you are not out of available memory, you can consult the manual for a possible OS-dependent bug", +"Can't create a new thread (errno %d); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug", "Column count doesn't match value count at row %ld", "Can't reopen table: '%-.64s", "Invalid use of NULL value", "Got error '%-.64s' from regexp", -"Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause", +"Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause", "There is no such grant defined for user '%-.32s' on host '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for table '%-.64s'", -"%-.16s command denied to user: '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", -"Illegal GRANT/REVOKE command. Please consult the manual which privleges can be used.", +"%-.16s command denied to user '%-.32s'@'%-.64s' for table '%-.64s'", +"%-.16s command denied to user '%-.32s'@'%-.64s' for column '%-.64s' in table '%-.64s'", +"Illegal GRANT/REVOKE command; please consult the manual to see which privleges can be used.", "The host or user argument to GRANT is too long", "Table '%-.64s.%s' doesn't exist", "There is no such grant defined for user '%-.32s' on host '%-.64s' on table '%-.64s'", @@ -164,7 +164,7 @@ character-set=latin2 "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", "Aborted connection %ld to db: '%-.64s' user: '%-.64s' (%s)", -"Got a packet bigger than 'max_allowed_packet'", +"Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", "Got packets out of order", @@ -173,7 +173,7 @@ character-set=latin2 "Got timeout reading communication packets", "Got an error writing communication packets", "Got timeout writing communication packets", -"Result string is longer than max_allowed_packet", +"Result string is longer than 'max_allowed_packet' bytes", "The used table type doesn't support BLOB/TEXT columns", "The used table type doesn't support AUTO_INCREMENT columns", "INSERT DELAYED can't be used with table '%-.64s', because it is locked with LOCK TABLES", @@ -182,7 +182,7 @@ character-set=latin2 "All tables in the MERGE table are not defined identically", "Can't write, because of unique constraint, to table '%-.64s'", "BLOB column '%-.64s' used in key specification without a key length", -"All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead", +"All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead", "Result consisted of more than one row", "This table type requires a primary key", "This version of MySQL is not compiled with RAID support", @@ -208,7 +208,7 @@ character-set=latin2 "Table '%-.64s' is marked as crashed and should be repaired", "Table '%-.64s' is marked as crashed and last (automatic?) repair failed", "Some non-transactional changed tables couldn't be rolled back", -"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage. Increase this mysqld variable and try again", +"Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again", "This operation cannot be performed with a running slave, run STOP SLAVE first", "This operation requires a running slave, configure slave and do START SLAVE", "The server is not configured as slave, fix in config file or with CHANGE MASTER TO", @@ -216,15 +216,15 @@ character-set=latin2 "Could not create slave thread, check system resources", "User %-.64s has already more than 'max_user_connections' active connections", "You may only use constant expressions with SET", -"Lock wait timeout exceeded", +"Lock wait timeout exceeded; try restarting transaction", "The total number of locks exceeds the lock table size", "Update locks cannot be acquired during a READ UNCOMMITTED transaction", "DROP DATABASE not allowed while thread is holding global read lock", "CREATE DATABASE not allowed while thread is holding global read lock", -"Wrong arguments to %s", +"Incorrect arguments to %s", "'%-.32s'@'%-.64s' is not allowed to create new users", "Incorrect table definition; all MERGE tables must be in the same database", -"Deadlock found when trying to get lock; Try restarting transaction", +"Deadlock found when trying to get lock; try restarting transaction", "The used table type doesn't support FULLTEXT indexes", "Cannot add foreign key constraint", "Cannot add a child row: a foreign key constraint fails", @@ -232,50 +232,50 @@ character-set=latin2 "Error connecting to master: %-.128s", "Error running query on master: %-.128s", "Error when executing command %s: %-.128s", -"Wrong usage of %s and %s", +"Incorrect usage of %s and %s", "The used SELECT statements have a different number of columns", "Can't execute the query because you have a conflicting read lock", "Mixing of transactional and non-transactional tables is disabled", "Option '%s' used twice in statement", "User '%-.64s' has exceeded the '%s' resource (current value: %ld)", -"Access denied. You need the %-.128s privilege for this operation", +"Access denied; you need the %-.128s privilege for this operation", "Variable '%-.64s' is a SESSION variable and can't be used with SET GLOBAL", "Variable '%-.64s' is a GLOBAL variable and should be set with SET GLOBAL", "Variable '%-.64s' doesn't have a default value", "Variable '%-.64s' can't be set to the value of '%-.64s'", -"Wrong argument type to variable '%-.64s'", +"Incorrect argument type to variable '%-.64s'", "Variable '%-.64s' can only be set, not read", -"Wrong usage/placement of '%s'", +"Incorrect usage/placement of '%s'", "This version of MySQL doesn't yet support '%s'", "Got fatal error %d: '%-.128s' from master when reading data from binary log", "Slave SQL thread ignored the query because of replicate-*-table rules", "Variable '%-.64s' is a %s variable", -"Wrong foreign key definition for '%-.64s': %s", -"Key reference and table reference doesn't match", +"Incorrect foreign key definition for '%-.64s': %s", +"Key reference and table reference don't match", "Operand should contain %d column(s)", "Subquery returns more than 1 row", -"Unknown prepared statement handler (%ld) given to %s", +"Unknown prepared statement handler (%.*s) given to %s", "Help database is corrupt or does not exist", "Cyclic reference on subqueries", "Converting column '%s' from %s to %s", "Reference '%-.64s' not supported (%s)", -"Every derived table must have it's own alias", -"Select %u was reduced during optimisation", -"Table '%-.64s' from one of SELECT's can not be used in %-.32s", +"Every derived table must have its own alias", +"Select %u was reduced during optimization", +"Table '%-.64s' from one of the SELECTs cannot be used in %-.32s", "Client does not support authentication protocol requested by server; consider upgrading MySQL client", -"All parts of a SPATIAL KEY must be NOT NULL", +"All parts of a SPATIAL index must be NOT NULL", "COLLATION '%s' is not valid for CHARACTER SET '%s'", "Slave is already running", "Slave has already been stopped", -"Too big size of uncompressed data. The maximum size is %d. (probably, length of uncompressed data was corrupted)", -"Z_MEM_ERROR: Not enough memory available for zlib", -"Z_BUF_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)", -"Z_DATA_ERROR: Input data was corrupted for zlib", -"%d line(s) was(were) cut by group_concat()", +"Uncompressed data size too large; the maximum size is %d (probably, length of uncompressed data was corrupted)", +"ZLIB: Not enough memory", +"ZLIB: Not enough room in the output buffer (probably, length of uncompressed data was corrupted)", +"ZLIB: Input data corrupted", +"%d line(s) were cut by GROUP_CONCAT()", "Row %ld doesn't contain data for all columns", -"Row %ld was truncated; It contained more data than there were input columns", -"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld", -"Data truncated, out of range for column '%s' at row %ld", +"Row %ld was truncated; it contained more data than there were input columns", +"Data truncated; NULL supplied to NOT NULL column '%s' at row %ld", +"Data truncated; out of range for column '%s' at row %ld", "Data truncated for column '%s' at row %ld", "Using storage engine %s for table '%s'", "Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'", @@ -283,13 +283,13 @@ character-set=latin2 "Can't revoke all privileges, grant for one or more of the requested users", "Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'", "Illegal mix of collations for operation '%s'", -"Variable '%-.64s' is not a variable component (Can't be used as XXXX.variable_name)", +"Variable '%-.64s' is not a variable component (can't be used as XXXX.variable_name)", "Unknown collation: '%-.64s'", -"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later when MySQL slave with SSL will be started", +"SSL parameters in CHANGE MASTER are ignored because this MySQL slave was compiled without SSL support; they can be used later if MySQL slave with SSL is started", "Server is running in --secure-auth mode, but '%s'@'%s' has a password in the old format; please change the password to the new format", "Field or reference '%-.64s%s%-.64s%s%-.64s' of SELECT #%d was resolved in SELECT #%d", -"Wrong parameter or combination of parameters for START SLAVE UNTIL", -"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL, otherwise you are not safe in case of unexpected slave's mysqld restart", +"Incorrect parameter or combination of parameters for START SLAVE UNTIL", +"It is recommended to run with --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you are not safe in case of unexpected slave's mysqld restart", "SQL thread is not to be started so UNTIL options are ignored", "Incorrect index name '%-.100s'", "Incorrect catalog name '%-.100s'", @@ -304,9 +304,13 @@ character-set=latin2 "The MySQL server is running with the %s option so it cannot execute this statement", "Column '%-.100s' has duplicated value '%-.64s' in %s" "Truncated wrong %-.32s value: '%-.128s'" -"Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" -"Invalid ON UPDATE clause for '%-.64s' field", +"Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause" +"Invalid ON UPDATE clause for '%-.64s' column", "This command is not supported in the prepared statement protocol yet", +"Got error %d '%-.100s' from %s", +"Got temporary error %d '%-.100s' from %s", +"Unknown or incorrect time zone: '%-.64s'", +"Invalid TIMESTAMP value in column '%s' at row %ld", "Can't create a %s from within another stored routine" "%s %s already exists" "%s %s does not exist" diff --git a/sql/slave.cc b/sql/slave.cc index d652ad0e664..5bc2599211e 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -72,6 +72,7 @@ static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed, static int request_table_dump(MYSQL* mysql, const char* db, const char* table); static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, const char* table_name, bool overwrite); +static int get_master_version_and_clock(MYSQL* mysql, MASTER_INFO* mi); /* Find out which replications threads are running @@ -1374,31 +1375,90 @@ static int get_master_version_and_clock(MYSQL* mysql, MASTER_INFO* mi) return 1; } - MYSQL_RES *master_clock_res; - MYSQL_ROW master_clock_row; - time_t slave_clock; + /* + Compare the master and slave's clock. Do not die if master's clock is + unavailable (very old master not supporting UNIX_TIMESTAMP()?). + */ + MYSQL_RES *master_res= 0; + MYSQL_ROW master_row; + + if (!mysql_real_query(mysql, "SELECT UNIX_TIMESTAMP()", 23) && + (master_res= mysql_store_result(mysql)) && + (master_row= mysql_fetch_row(master_res))) + { + mi->clock_diff_with_master= + (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10)); + } + else + { + mi->clock_diff_with_master= 0; /* The "most sensible" value */ + sql_print_error("Warning: \"SELECT UNIX_TIMESTAMP()\" failed on master, \ +do not trust column Seconds_Behind_Master of SHOW SLAVE STATUS"); + } + if (master_res) + mysql_free_result(master_res); + + /* + Check that the master's server id and ours are different. Because if they + are equal (which can result from a simple copy of master's datadir to slave, + thus copying some my.cnf), replication will work but all events will be + skipped. + Do not die if SHOW VARIABLES LIKE 'SERVER_ID' fails on master (very old + master?). + Note: we could have put a @@SERVER_ID in the previous SELECT + UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters. + */ + if (!mysql_real_query(mysql, "SHOW VARIABLES LIKE 'SERVER_ID'", 31) && + (master_res= mysql_store_result(mysql))) + { + if ((master_row= mysql_fetch_row(master_res)) && + (::server_id == strtoul(master_row[1], 0, 10)) && + !replicate_same_server_id) + errmsg= "The slave I/O thread stops because master and slave have equal \ +MySQL server ids; these ids must be different for replication to work (or \ +the --replicate-same-server-id option must be used on slave but this does \ +not always make sense; please check the manual before using it)."; + mysql_free_result(master_res); + } - if (mysql_real_query(mysql, "SELECT UNIX_TIMESTAMP()", 23)) - errmsg= "\"SELECT UNIX_TIMESTAMP()\" failed on master"; - else if (!(master_clock_res= mysql_store_result(mysql))) + /* + Check that the master's global character_set_server and ours are the same. + Not fatal if query fails (old master?). + */ + if (!mysql_real_query(mysql, "SELECT @@GLOBAL.COLLATION_SERVER", 32) && + (master_res= mysql_store_result(mysql))) { - errmsg= "Could not read the result of \"SELECT UNIX_TIMESTAMP()\" on \ -master"; + if ((master_row= mysql_fetch_row(master_res)) && + strcmp(master_row[0], global_system_variables.collation_server->name)) + errmsg= "The slave I/O thread stops because master and slave have \ +different values for the COLLATION_SERVER global variable. The values must \ +be equal for replication to work"; + mysql_free_result(master_res); } - else + + /* + Perform analogous check for time zone. Theoretically we also should + perform check here to verify that SYSTEM time zones are the same on + slave and master, but we can't rely on value of @@system_time_zone + variable (it is time zone abbreviation) since it determined at start + time and so could differ for slave and master even if they are really + in the same system time zone. So we are omiting this check and just + relying on documentation. Also according to Monty there are many users + who are using replication between servers in various time zones. Hence + such check will broke everything for them. (And now everything will + work for them because by default both their master and slave will have + 'SYSTEM' time zone). + */ + if (!mysql_real_query(mysql, "SELECT @@GLOBAL.TIME_ZONE", 25) && + (master_res= mysql_store_result(mysql))) { - if (!(master_clock_row= mysql_fetch_row(master_clock_res))) - errmsg= "Could not read a row from the result of \"SELECT \ -UNIX_TIMESTAMP()\" on master"; - else - { - slave_clock= time((time_t*) 0); - mi->clock_diff_with_master= (long) (slave_clock - - strtoul(master_clock_row[0], 0, 10)); - DBUG_PRINT("info",("slave_clock=%lu, master_clock=%s", - slave_clock, master_clock_row[0])); - } - mysql_free_result(master_clock_res); + if ((master_row= mysql_fetch_row(master_res)) && + strcmp(master_row[0], + global_system_variables.time_zone->get_name()->ptr())) + errmsg= "The slave I/O thread stops because master and slave have \ +different values for the TIME_ZONE global variable. The values must \ +be equal for replication to work"; + mysql_free_result(master_res); } if (errmsg) @@ -1406,6 +1466,7 @@ UNIX_TIMESTAMP()\" on master"; sql_print_error(errmsg); return 1; } + return 0; } @@ -1573,7 +1634,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, thd->net.no_send_ok = 0; // Clear up garbage after create_table_from_dump if (!called_connected) mysql_close(mysql); - if (errmsg && thd->net.vio) + if (errmsg && thd->vio_ok()) send_error(thd, error, errmsg); DBUG_RETURN(test(error)); // Return 1 on error } @@ -2681,7 +2742,6 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type) DBUG_ENTER("init_slave_thread"); thd->system_thread = (thd_type == SLAVE_THD_SQL) ? SYSTEM_THREAD_SLAVE_SQL : SYSTEM_THREAD_SLAVE_IO; - thd->bootstrap= 1; thd->host_or_ip= ""; thd->client_capabilities = 0; my_net_init(&thd->net, 0); @@ -3781,7 +3841,6 @@ err: static int process_io_rotate(MASTER_INFO *mi, Rotate_log_event *rev) { - int return_val= 1; DBUG_ENTER("process_io_rotate"); safe_mutex_assert_owner(&mi->data_lock); diff --git a/sql/spatial.cc b/sql/spatial.cc index ab415d9af10..0668dd2faab 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -15,6 +15,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mysql_priv.h" + +#ifdef HAVE_SPATIAL + #define MAX_DIGITS_IN_DOUBLE 16 /***************************** Gis_class_info *******************************/ @@ -395,7 +398,7 @@ bool Gis_line_string::init_from_wkt(Gis_read_stream *trs, String *wkb) if (trs->skip_char(',')) // Didn't find ',' break; } - if (n_points < 2) + if (n_points < 1) { trs->set_error_msg("Too few points in LINESTRING"); return 1; @@ -484,6 +487,11 @@ int Gis_line_string::is_closed(int *closed) const if (no_data(data, 4)) return 1; n_points= uint4korr(data); + if (n_points == 1) + { + *closed=1; + return 0; + } data+= 4; if (no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) return 1; @@ -1652,3 +1660,4 @@ const Geometry::Class_info *Gis_geometry_collection::get_class_info() const return &geometrycollection_class; } +#endif /*HAVE_SPATIAL*/ diff --git a/sql/spatial.h b/sql/spatial.h index cc1cc70f1bc..45db1ca8d00 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -17,6 +17,8 @@ #ifndef _spatial_h #define _spatial_h +#ifdef HAVE_SPATIAL + const uint SRID_SIZE= 4; const uint SIZEOF_STORED_DOUBLE= 8; const uint POINT_DATA_SIZE= SIZEOF_STORED_DOUBLE*2; @@ -459,4 +461,5 @@ struct Geometry_buffer void *arr[(geometry_buffer_size - 1)/sizeof(void *) + 1]; }; +#endif /*HAVE_SPATAIAL*/ #endif diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index c1740a80fa5..36926d4526d 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -629,10 +629,10 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, if (passwd_len == acl_user_tmp->salt_len) { if (acl_user_tmp->salt_len == 0 || - acl_user_tmp->salt_len == SCRAMBLE_LENGTH && - check_scramble(passwd, thd->scramble, acl_user_tmp->salt) == 0 || + (acl_user_tmp->salt_len == SCRAMBLE_LENGTH ? + check_scramble(passwd, thd->scramble, acl_user_tmp->salt) : check_scramble_323(passwd, thd->scramble, - (ulong *) acl_user_tmp->salt) == 0) + (ulong *) acl_user_tmp->salt)) == 0) { acl_user= acl_user_tmp; res= 0; @@ -1021,7 +1021,7 @@ static void acl_insert_db(const char *user, const char *host, const char *db, */ ulong acl_get(const char *host, const char *ip, - const char *user, const char *db, my_bool db_is_pattern) + const char *user, const char *db, my_bool db_is_pattern) { ulong host_access,db_access; uint i,key_length; @@ -1507,8 +1507,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, table->field[0]->store(combo.host.str,combo.host.length, &my_charset_latin1); table->field[1]->store(combo.user.str,combo.user.length, &my_charset_latin1); - table->file->index_init(0); - if (table->file->index_read(table->record[0], + if (table->file->index_read_idx(table->record[0], 0, (byte*) table->field[0]->ptr,0, HA_READ_KEY_EXACT)) { @@ -1519,7 +1518,6 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, else my_error(ER_NO_PERMISSION_TO_CREATE_USER, MYF(0), thd->user, thd->host_or_ip); - error= -1; goto end; } old_row_exists = 0; @@ -1656,7 +1654,6 @@ end: &thd->lex->mqh, rights); } - table->file->index_end(); DBUG_RETURN(error); } @@ -1692,8 +1689,7 @@ static int replace_db_table(TABLE *table, const char *db, table->field[0]->store(combo.host.str,combo.host.length, &my_charset_latin1); table->field[1]->store(db,(uint) strlen(db), &my_charset_latin1); table->field[2]->store(combo.user.str,combo.user.length, &my_charset_latin1); - table->file->index_init(0); - if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr,0, + if (table->file->index_read_idx(table->record[0],0,(byte*) table->field[0]->ptr,0, HA_READ_KEY_EXACT)) { if (what == 'N') @@ -1747,13 +1743,11 @@ static int replace_db_table(TABLE *table, const char *db, acl_update_db(combo.user.str,combo.host.str,db,rights); else acl_insert_db(combo.user.str,combo.host.str,db,rights); - table->file->index_end(); DBUG_RETURN(0); /* This could only happen if the grant tables got corrupted */ table_error: table->file->print_error(error,MYF(0)); /* purecov: deadcode */ - table->file->index_end(); abort: DBUG_RETURN(-1); @@ -1875,8 +1869,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs) col_privs->field[3]->pack_length()); key_copy(key,col_privs,0,key_len); col_privs->field[4]->store("",0, &my_charset_latin1); - col_privs->file->index_init(0); - if (col_privs->file->index_read(col_privs->record[0], + if (col_privs->file->index_read_idx(col_privs->record[0],0, (byte*) col_privs->field[0]->ptr, key_len, HA_READ_KEY_EXACT)) { @@ -1991,7 +1984,7 @@ static int replace_column_table(GRANT_TABLE *g_t, List_iterator <LEX_COLUMN> iter(columns); class LEX_COLUMN *xx; - table->file->index_init(0); + table->file->ha_index_init(0); while ((xx=iter++)) { ulong privileges = xx->rights; @@ -2061,7 +2054,6 @@ static int replace_column_table(GRANT_TABLE *g_t, my_hash_insert(&g_t->hash_columns,(byte*) grant_column); } } - table->file->index_end(); /* If revoke of privileges on the table level, remove all such privileges @@ -2070,7 +2062,6 @@ static int replace_column_table(GRANT_TABLE *g_t, if (revoke_grant) { - table->file->index_init(0); if (table->file->index_read(table->record[0], (byte*) table->field[0]->ptr, key_length, HA_READ_KEY_EXACT)) goto end; @@ -2126,7 +2117,7 @@ static int replace_column_table(GRANT_TABLE *g_t, } end: - table->file->index_end(); + table->file->ha_index_end(); DBUG_RETURN(result); } @@ -2639,15 +2630,13 @@ my_bool grant_init(THD *org_thd) goto end; t_table = tables[0].table; c_table = tables[1].table; - t_table->file->index_init(0); + t_table->file->ha_index_init(0); if (t_table->file->index_first(t_table->record[0])) { - t_table->file->index_end(); return_val= 0; goto end_unlock; } grant_option= TRUE; - t_table->file->index_end(); /* Will be restored by org_thd->store_globals() */ my_pthread_setspecific_ptr(THR_MALLOC,&memex); @@ -2667,7 +2656,7 @@ my_bool grant_init(THD *org_thd) { sql_print_error("Warning: 'tables_priv' entry '%s %s@%s' " "ignored in --skip-name-resolve mode.", - mem_check->tname, mem_check->user, + mem_check->tname, mem_check->user, mem_check->host, mem_check->host); continue; } @@ -2684,6 +2673,7 @@ my_bool grant_init(THD *org_thd) return_val=0; // Return ok end_unlock: + t_table->file->ha_index_end(); mysql_unlock_tables(thd, lock); thd->version--; // Force close to free memory @@ -2909,7 +2899,7 @@ bool check_grant_all_columns(THD *thd, ulong want_access, TABLE *table) if (table->grant.version != grant_version) { table->grant.grant_table= - table_hash_search(thd->host,thd->ip,thd->db, + table_hash_search(thd->host, thd->ip, table->table_cache_key, thd->priv_user, table->real_name,0); /* purecov: inspected */ table->grant.version=grant_version; /* purecov: inspected */ @@ -3022,7 +3012,7 @@ ulong get_column_grant(THD *thd, TABLE_LIST *table, Field *field) if (table->grant.version != grant_version) { table->grant.grant_table= - table_hash_search(thd->host,thd->ip,thd->db, + table_hash_search(thd->host, thd->ip, table->db, thd->priv_user, table->real_name,0); /* purecov: inspected */ table->grant.version=grant_version; /* purecov: inspected */ @@ -3627,12 +3617,10 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list) record[0]))) { tables[0].table->file->print_error(error, MYF(0)); - tables[0].table->file->index_end(); DBUG_RETURN(-1); } delete_dynamic_element(&acl_users, acl_userd); } - tables[0].table->file->index_end(); } VOID(pthread_mutex_unlock(&acl_cache->lock)); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6af822e3ec2..22f93bb05ba 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -300,6 +300,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); bool found=1; /* Wait until all threads has closed all the tables we had locked */ DBUG_PRINT("info", @@ -850,6 +851,9 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, DBUG_RETURN(0); } + /* close handler tables which are marked for flush */ + mysql_ha_close_list(thd, (TABLE_LIST*) NULL, /*flushed*/ 1); + for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; table && table->in_use ; table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) @@ -1220,6 +1224,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); if (!table_is_used(thd->open_tables,1)) break; (void) pthread_cond_wait(&COND_refresh,&LOCK_open); @@ -1760,6 +1765,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, } tmp_table->reginfo.lock_type=TL_WRITE; // Simulate locked + tmp_table->in_use= thd; tmp_table->tmp_table = (tmp_table->file->has_transactions() ? TRANSACTIONAL_TMP_TABLE : TMP_TABLE); tmp_table->table_cache_key=(char*) (tmp_table+1); @@ -2184,8 +2190,19 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, !((Item_field*) item)->field) { uint elem= fields.elements; - if (insert_fields(thd,tables,((Item_field*) item)->db_name, - ((Item_field*) item)->table_name, &it)) + Item_subselect *subsel= thd->lex->current_select->master_unit()->item; + if (subsel && + subsel->substype() == Item_subselect::EXISTS_SUBS) + { + /* + It is EXISTS(SELECT * ...) and we can replace * by any constant. + + Item_int do not need fix_fields() because it is basic constant. + */ + it.replace(new Item_int("Not_used", (longlong) 1, 21)); + } + else if (insert_fields(thd,tables,((Item_field*) item)->db_name, + ((Item_field*) item)->table_name, &it)) { if (arena) thd->restore_backup_item_arena(arena, &backup); diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h index 0274cd700da..5c51f3ecb67 100644 --- a/sql/sql_bitmap.h +++ b/sql/sql_bitmap.h @@ -64,15 +64,15 @@ public: char *s=buf; int i; for (i=sizeof(buffer)-1; i>=0 ; i--) { - if ((*s=_dig_vec[buffer[i] >> 4]) != '0') + if ((*s=_dig_vec_upper[buffer[i] >> 4]) != '0') break; - if ((*s=_dig_vec[buffer[i] & 15]) != '0') + if ((*s=_dig_vec_upper[buffer[i] & 15]) != '0') break; } for (s++, i-- ; i>=0 ; i--) { - *s++=_dig_vec[buffer[i] >> 4]; - *s++=_dig_vec[buffer[i] & 15]; + *s++=_dig_vec_upper[buffer[i] >> 4]; + *s++=_dig_vec_upper[buffer[i] & 15]; } *s=0; return buf; @@ -91,7 +91,16 @@ template <> class Bitmap<64> ulonglong map; public: Bitmap<64>() { } +#if defined(__NETWARE__) + /* + Metwork compiler gives error on Bitmap<64> + Changed to Bitmap, since in this case also it will proper construct + this class + */ + explicit Bitmap(uint prefix_to_set) { set_prefix(prefix_to_set); } +#else explicit Bitmap<64>(uint prefix_to_set) { set_prefix(prefix_to_set); } +#endif void init() { } void init(uint prefix_to_set) { set_prefix(prefix_to_set); } uint length() const { return 64; } diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 50bcca4b57e..68b4bc601fe 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -786,6 +786,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) flags.collation_connection_num= thd->variables.collation_connection->number; flags.limit= thd->variables.select_limit; + flags.time_zone= thd->variables.time_zone; STRUCT_LOCK(&structure_guard_mutex); if (query_cache_size == 0) @@ -977,6 +978,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) UINT_MAX); flags.collation_connection_num= thd->variables.collation_connection->number; flags.limit= thd->variables.select_limit; + flags.time_zone= thd->variables.time_zone; memcpy((void *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)), &flags, QUERY_CACHE_FLAGS_SIZE); query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql, @@ -1047,9 +1049,9 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) goto err_unlock; // Parse query } #endif /*!NO_EMBEDDED_ACCESS_CHECKS*/ - if (check_tables && !handler::caching_allowed(thd, table->db(), - table->key_length(), - table->type())) + if (check_tables && !ha_caching_allowed(thd, table->db(), + table->key_length(), + table->type())) { DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s", table_list.db, table_list.alias)); @@ -2690,9 +2692,9 @@ my_bool Query_cache::ask_handler_allowance(THD *thd, for (; tables_used; tables_used= tables_used->next) { TABLE *table= tables_used->table; - if (!handler::caching_allowed(thd, table->table_cache_key, - table->key_length, - table->file->table_cache_type())) + if (!ha_caching_allowed(thd, table->table_cache_key, + table->key_length, + table->file->table_cache_type())) { DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s", tables_used->db, tables_used->alias)); @@ -3236,9 +3238,10 @@ void Query_cache::queries_dump() Query_cache_query_flags flags; memcpy(&flags, str+len, QUERY_CACHE_FLAGS_SIZE); str[len]= 0; // make zero ending DB name - DBUG_PRINT("qcache", ("F:%u C:%u L:%lu (%u) '%s' '%s'", + DBUG_PRINT("qcache", ("F:%u C:%u L:%lu T:'%s' (%u) '%s' '%s'", flags.client_long_flag, - flags.character_set_client_num, (ulong)flags.limit, + flags.character_set_client_num, + (ulong)flags.limit, flags.time_zone->get_name(), len, str, strend(str)+1)); DBUG_PRINT("qcache", ("-b- 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx", (ulong) block, (ulong) block->next, (ulong) block->prev, diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7a4f3dff845..07c894dc8c1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -81,7 +81,6 @@ extern "C" void free_user_var(user_var_entry *entry) my_free((char*) entry,MYF(0)); } - bool key_part_spec::operator==(const key_part_spec& other) const { return length == other.length && !strcmp(field_name, other.field_name); @@ -161,8 +160,9 @@ bool foreign_key_prefix(Key *a, Key *b) THD::THD():user_time(0), current_arena(0), is_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), spcont(NULL) + insert_id_used(0), rand_used(0), time_zone_used(0), + in_lock_tables(0), global_read_lock(0), bootstrap(0), + spcont(NULL) { host= user= priv_user= db= ip= 0; catalog= (char*)"std"; // the only catalog we have for now @@ -186,6 +186,7 @@ THD::THD():user_time(0), current_arena(0), is_fatal_error(0), current_linfo = 0; slave_thread = 0; variables.pseudo_thread_id= 0; + one_shot_set= 0; file_id = 0; warn_id= 0; db_charset= global_system_variables.collation_database; @@ -762,7 +763,7 @@ bool select_send::send_data(List<Item> &items) } } thd->sent_row_count++; - if (!thd->net.vio) + if (!thd->vio_ok()) DBUG_RETURN(0); if (!thd->net.report_error) DBUG_RETURN(protocol->write()); @@ -1352,7 +1353,9 @@ Statement::Statement(THD *thd) lex(&main_lex), query(0), query_length(0) -{} +{ + name.str= NULL; +} /* This constructor is called when statement is a subobject of THD: @@ -1431,17 +1434,52 @@ static void delete_statement_as_hash_key(void *key) delete (Statement *) key; } +static byte *get_stmt_name_hash_key(Statement *entry, uint *length, + my_bool not_used __attribute__((unused))) +{ + *length=(uint) entry->name.length; + return (byte*) entry->name.str; +} + C_MODE_END Statement_map::Statement_map() : last_found_statement(0) { - enum { START_HASH_SIZE = 16 }; - hash_init(&st_hash, default_charset_info, START_HASH_SIZE, 0, 0, + enum + { + START_STMT_HASH_SIZE = 16, + START_NAME_HASH_SIZE = 16 + }; + hash_init(&st_hash, default_charset_info, START_STMT_HASH_SIZE, 0, 0, get_statement_id_as_hash_key, delete_statement_as_hash_key, MYF(0)); + hash_init(&names_hash, &my_charset_bin, START_NAME_HASH_SIZE, 0, 0, + (hash_get_key) get_stmt_name_hash_key, + NULL,MYF(0)); } +int Statement_map::insert(Statement *statement) +{ + int rc= my_hash_insert(&st_hash, (byte *) statement); + if (rc == 0) + last_found_statement= statement; + if (statement->name.str) + { + /* + If there is a statement with the same name, remove it. It is ok to + remove old and fail to insert new one at the same time. + */ + Statement *old_stmt; + if ((old_stmt= find_by_name(&statement->name))) + erase(old_stmt); + if ((rc= my_hash_insert(&names_hash, (byte*)statement))) + hash_delete(&st_hash, (byte*)statement); + } + return rc; +} + + bool select_dumpvar::send_data(List<Item> &items) { List_iterator_fast<Item_func_set_user_var> li(vars); diff --git a/sql/sql_class.h b/sql/sql_class.h index 1e9b1d04351..08f73309a85 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -192,6 +192,8 @@ public: int purge_first_log(struct st_relay_log_info* rli, bool included); bool reset_logs(THD* thd); void close(uint exiting); + bool cut_spurious_tail(); + void report_pos_in_innodb(); // iterating through the log index file int find_log_pos(LOG_INFO* linfo, const char* log_name, @@ -408,6 +410,7 @@ struct system_variables ulong query_prealloc_size; ulong trans_alloc_block_size; ulong trans_prealloc_size; + ulong log_warnings; ulong group_concat_max_len; /* In slave thread we need to know in behalf of which @@ -415,7 +418,6 @@ struct system_variables */ ulong pseudo_thread_id; - my_bool log_warnings; my_bool low_priority_updates; my_bool new_mode; my_bool query_cache_wlock_invalidate; @@ -430,6 +432,8 @@ struct system_variables CHARSET_INFO *collation_database; CHARSET_INFO *collation_connection; + Time_zone *time_zone; + /* DATE, DATETIME and TIME formats */ DATE_TIME_FORMAT *date_format; DATE_TIME_FORMAT *datetime_format; @@ -528,6 +532,7 @@ public: */ bool allow_sum_func; + LEX_STRING name; /* name for named prepared statements */ LEX *lex; // parse tree descriptor /* Points to the query associated with this statement. It's const, but @@ -563,8 +568,14 @@ public: /* - Used to seek all existing statements in the connection - Deletes all statements in destructor. + Container for all statements created/used in a connection. + Statements in Statement_map have unique Statement::id (guaranteed by id + assignment in Statement::Statement) + Non-empty statement names are unique too: attempt to insert a new statement + with duplicate name causes older statement to be deleted + + Statements are auto-deleted when they are removed from the map and when the + map is deleted. */ class Statement_map @@ -572,34 +583,47 @@ class Statement_map public: Statement_map(); - int insert(Statement *statement) + int insert(Statement *statement); + + Statement *find_by_name(LEX_STRING *name) { - int rc= my_hash_insert(&st_hash, (byte *) statement); - if (rc == 0) - last_found_statement= statement; - return rc; + Statement *stmt; + stmt= (Statement*)hash_search(&names_hash, (byte*)name->str, + name->length); + return stmt; } Statement *find(ulong id) { if (last_found_statement == 0 || id != last_found_statement->id) - last_found_statement= (Statement *) hash_search(&st_hash, (byte *) &id, - sizeof(id)); + { + Statement *stmt; + stmt= (Statement *) hash_search(&st_hash, (byte *) &id, sizeof(id)); + if (stmt && stmt->name.str) + return NULL; + last_found_statement= stmt; + } return last_found_statement; } void erase(Statement *statement) { if (statement == last_found_statement) last_found_statement= 0; + if (statement->name.str) + { + hash_delete(&names_hash, (byte *) statement); + } hash_delete(&st_hash, (byte *) statement); } ~Statement_map() { hash_free(&st_hash); + hash_free(&names_hash); } private: HASH st_hash; + HASH names_hash; Statement *last_found_statement; }; @@ -845,11 +869,12 @@ public: /* scramble - random string sent to client on handshake */ char scramble[SCRAMBLE_LENGTH+1]; - bool slave_thread; + bool slave_thread, one_shot_set; bool locked, some_tables_deleted; bool last_cuted_field; bool no_errors, password, is_fatal_error; bool query_start_used,last_insert_id_used,insert_id_used,rand_used; + bool time_zone_used; bool in_lock_tables,global_read_lock; bool query_error, bootstrap, cleanup_done; @@ -992,8 +1017,10 @@ public: net.last_errno= 0; net.report_error= 0; } + inline bool vio_ok() const { return net.vio != 0; } #else void clear_error(); + inline bool vio_ok() const { return true; } #endif inline void fatal_error() { diff --git a/sql/sql_db.cc b/sql/sql_db.cc index e2c337e5064..fcb6134ce41 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -357,15 +357,25 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) { error= -1; my_error(ER_DB_DROP_EXISTS,MYF(0),db); + goto exit; } else - { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS), db); - if (!silent) - send_ok(thd,0); + } + else + { + pthread_mutex_lock(&LOCK_open); + remove_db_from_cache(db); + pthread_mutex_unlock(&LOCK_open); + + error= -1; + if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0)) >= 0) + { + ha_drop_database(path); + query_cache_invalidate1(db); + error = 0; } - goto exit; } if (lower_case_table_names) { @@ -374,41 +384,30 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) my_casedn_str(files_charset_info, tmp_db); db= tmp_db; } - - pthread_mutex_lock(&LOCK_open); - remove_db_from_cache(db); - pthread_mutex_unlock(&LOCK_open); - - error = -1; - if ((deleted=mysql_rm_known_files(thd, dirp, db, path,0)) >= 0 && thd) + if (!silent && deleted>=0 && thd) { - ha_drop_database(path); - query_cache_invalidate1(db); - if (!silent) + const char *query; + ulong query_length; + if (!thd->query) { - const char *query; - ulong query_length; - if (!thd->query) - { - /* The client used the old obsolete mysql_drop_db() call */ - query= path; - query_length = (uint) (strxmov(path,"drop database `", db, "`", - NullS)- path); - } - else - { - query=thd->query; - query_length=thd->query_length; - } - if (mysql_bin_log.is_open()) - { - Query_log_event qinfo(thd, query, query_length, 0); - thd->clear_error(); - mysql_bin_log.write(&qinfo); - } - send_ok(thd,(ulong) deleted); + /* The client used the old obsolete mysql_drop_db() call */ + query= path; + query_length= (uint) (strxmov(path, "drop database `", db, "`", + NullS) - path); + } + else + { + query =thd->query; + query_length= thd->query_length; + } + mysql_update_log.write(thd, query, query_length); + if (mysql_bin_log.is_open()) + { + Query_log_event qinfo(thd, query, query_length, 0); + thd->clear_error(); + mysql_bin_log.write(&qinfo); } - error = 0; + send_ok(thd, (ulong) deleted); } exit: diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 440d404056b..9e425f86579 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -205,15 +205,24 @@ cleanup: query_cache_invalidate3(thd, table_list, 1); } + delete select; transactional_table= table->file->has_transactions(); log_delayed= (transactional_table || table->tmp_table); - if (deleted && (error <= 0 || !transactional_table)) + /* + We write to the binary log even if we deleted no row, because maybe the + user is using this command to ensure that a table is clean on master *and + on slave*. Think of the case of a user having played separately with the + master's table and slave's table and wanting to take a fresh identical + start now. + error < 0 means "really no error". error <= 0 means "maybe some error". + */ + if ((deleted || (error < 0)) && (error <= 0 || !transactional_table)) { if (mysql_bin_log.is_open()) { if (error <= 0) thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, + Query_log_event qinfo(thd, thd->query, thd->query_length, log_delayed); if (mysql_bin_log.write(&qinfo) && transactional_table) error=1; @@ -232,7 +241,6 @@ cleanup: mysql_unlock_tables(thd, thd->lock); thd->lock=0; } - delete select; free_underlaid_joins(thd, &thd->lex->select_lex); if (error >= 0 || thd->net.report_error) send_error(thd,thd->killed_errno()); @@ -560,6 +568,8 @@ bool multi_delete::send_eof() rows and we succeeded, or also in an error case when there was a non-transaction-safe table involved, since modifications in it cannot be rolled back. + Note that if we deleted nothing we don't write to the binlog (TODO: + fix this). */ if (deleted && (error <= 0 || normal_tables)) { diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 46794f45f3c..48bc6f4c5a2 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -117,7 +117,6 @@ static int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, select_union *derived_result; bool is_union= first_select->next_select() && first_select->next_select()->linkage == UNION_TYPE; - bool is_subsel= first_select->first_inner_unit() ? 1: 0; SELECT_LEX *save_current_select= lex->current_select; DBUG_ENTER("mysql_derived"); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index fcc56cbf9c9..56c1b0a1b51 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -43,7 +43,9 @@ thd->handler_tables=tmp; } static TABLE **find_table_ptr_by_name(THD *thd,const char *db, - const char *table_name, bool is_alias); + const char *table_name, + bool is_alias, bool dont_lock, + bool *was_flushed); int mysql_ha_open(THD *thd, TABLE_LIST *tables) { @@ -66,24 +68,61 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables) return 0; } -int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok) + +/* + Close a HANDLER table. + + SYNOPSIS + 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 +*/ + +int mysql_ha_close(THD *thd, TABLE_LIST *tables, + bool dont_send_ok, bool dont_lock, bool no_alias) { - TABLE **ptr=find_table_ptr_by_name(thd, tables->db, tables->alias, 1); + TABLE **table_ptr; + bool was_flushed; - if (*ptr) + table_ptr= find_table_ptr_by_name(thd, tables->db, tables->alias, + !no_alias, dont_lock, &was_flushed); + if (*table_ptr) { - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, ptr)) + (*table_ptr)->file->ha_index_or_rnd_end(); + if (!dont_lock) + 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)); } - VOID(pthread_mutex_unlock(&LOCK_open)); + if (!dont_lock) + VOID(pthread_mutex_unlock(&LOCK_open)); } - else + else if (!was_flushed && !dont_send_ok) { - my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), - tables->alias, "HANDLER"); + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + tables->alias, "HANDLER"); return -1; } if (!dont_send_ok) @@ -91,13 +130,65 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok) return 0; } -int mysql_ha_closeall(THD *thd, TABLE_LIST *tables) + +/* + 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 **ptr=find_table_ptr_by_name(thd, tables->db, tables->real_name, 0); - if (*ptr && close_thread_table(thd, ptr)) + TABLE_LIST *tl_item; + TABLE **table_ptr; + + if (tables) { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); + for (tl_item= tables ; tl_item; tl_item= tl_item->next) + { + 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)) + { + (*table_ptr)->file->ha_index_or_rnd_end(); + if (close_thread_table(thd, table_ptr)) + { + /* Tell threads waiting for refresh that something has happened */ + VOID(pthread_cond_broadcast(&COND_refresh)); + } + continue; + } + table_ptr= &((*table_ptr)->next); + } } return 0; } @@ -112,7 +203,10 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ha_rows select_limit,ha_rows offset_limit) { int err, keyno=-1; - TABLE *table=*find_table_ptr_by_name(thd, tables->db, tables->alias, 1); + bool was_flushed; + TABLE *table= *find_table_ptr_by_name(thd, tables->db, tables->alias, + /*is_alias*/ 1, /*dont_lock*/ 0, + &was_flushed); if (!table) { my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), @@ -136,7 +230,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, keyname,tables->alias); return -1; } - table->file->index_init(keyno); + table->file->ha_index_or_rnd_end(); + table->file->ha_index_init(keyno); } List<Item> list; @@ -148,8 +243,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, uint num_rows; byte *key; uint key_len; - LINT_INIT(key); - LINT_INIT(key_len); + LINT_INIT(key); + LINT_INIT(key_len); it++; // Skip first NULL field @@ -180,7 +275,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, err=table->file->index_first(table->record[0]); else { - if (!(err=table->file->rnd_init(1))) + table->file->ha_index_or_rnd_end(); + if (!(err=table->file->ha_rnd_init(1))) err=table->file->rnd_next(table->record[0]); } mode=RNEXT; @@ -291,17 +387,51 @@ err0: } +/* + Find a HANDLER table by name. + + SYNOPSIS + find_table_ptr_by_name() + 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. + + 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'. + + 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. + + 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. +*/ + static TABLE **find_table_ptr_by_name(THD *thd, const char *db, - const char *table_name, bool is_alias) + const char *table_name, + bool is_alias, bool dont_lock, + bool *was_flushed) { int dblen; - TABLE **ptr; + TABLE **table_ptr; DBUG_ASSERT(db); dblen= strlen(db); - ptr= &(thd->handler_tables); + table_ptr= &(thd->handler_tables); + *was_flushed= FALSE; - for (TABLE *table= *ptr; table ; table= *ptr) + for (TABLE *table= *table_ptr; table ; table= *table_ptr) { if ((db == any_db || !memcmp(table->table_cache_key, db, dblen)) && !my_strcasecmp(system_charset_info, @@ -310,18 +440,22 @@ static TABLE **find_table_ptr_by_name(THD *thd, const char *db, { if (table->version != refresh_version) { - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, ptr)) + if (!dont_lock) + 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)); } - VOID(pthread_mutex_unlock(&LOCK_open)); + if (!dont_lock) + VOID(pthread_mutex_unlock(&LOCK_open)); + *was_flushed= TRUE; continue; } + *was_flushed= FALSE; break; } - ptr= &(table->next); + table_ptr= &(table->next); } - return ptr; + return table_ptr; } diff --git a/sql/sql_help.cc b/sql/sql_help.cc index 44293b8214f..eabe66d33bf 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -22,8 +22,6 @@ struct st_find_field Field *field; }; -static void free_select(SQL_SELECT *sel); - /* Used fields */ static struct st_find_field init_used_fields[]= @@ -48,9 +46,9 @@ static struct st_find_field init_used_fields[]= enum enum_used_fields { help_topic_help_topic_id= 0, - help_topic_name, + help_topic_name, help_topic_help_category_id, - help_topic_description, + help_topic_description, help_topic_example, help_category_help_category_id, @@ -60,13 +58,13 @@ enum enum_used_fields help_keyword_help_keyword_id, help_keyword_name, - help_relation_help_topic_id, + help_relation_help_topic_id, help_relation_help_keyword_id }; /* - Fill st_find_field structure with pointers to fields + Fill st_find_field structure with pointers to fields SYNOPSIS init_fields() @@ -90,7 +88,7 @@ static bool init_fields(THD *thd, TABLE_LIST *tables, /* We have to use 'new' here as field will be re_linked on free */ Item_field *field= new Item_field("mysql", find_fields->table_name, find_fields->field_name); - if (!(find_fields->field= find_field_in_tables(thd, field, tables, + if (!(find_fields->field= find_field_in_tables(thd, field, tables, ¬_used, TRUE))) DBUG_RETURN(1); } @@ -119,12 +117,12 @@ static bool init_fields(THD *thd, TABLE_LIST *tables, NOTE Field 'names' is set only if more than one topic is found. - Fields 'name', 'description', 'example' are set only if + Fields 'name', 'description', 'example' are set only if found exactly one topic. */ void memorize_variant_topic(THD *thd, TABLE *topics, int count, - struct st_find_field *find_fields, + struct st_find_field *find_fields, List<String> *names, String *name, String *description, String *example) { @@ -136,7 +134,7 @@ void memorize_variant_topic(THD *thd, TABLE *topics, int count, get_field(mem_root,find_fields[help_topic_description].field, description); get_field(mem_root,find_fields[help_topic_example].field, example); } - else + else { if (count == 1) names->push_back(name); @@ -168,7 +166,7 @@ void memorize_variant_topic(THD *thd, TABLE *topics, int count, NOTE Field 'names' is set only if more than one topic was found. - Fields 'name', 'description', 'example' are set only if + Fields 'name', 'description', 'example' are set only if exactly one topic was found. */ @@ -179,12 +177,12 @@ int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_fields, { DBUG_ENTER("search_topics"); int count= 0; - + READ_RECORD read_record_info; init_read_record(&read_record_info, thd, topics, select,1,0); while (!read_record_info.read_record(&read_record_info)) { - if (!select->cond->val_int()) // Dosn't match like + if (!select->cond->val_int()) // Doesn't match like continue; memorize_variant_topic(thd,topics,count,find_fields, names,name,description,example); @@ -219,7 +217,7 @@ int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields, { DBUG_ENTER("search_keyword"); int count= 0; - + READ_RECORD read_record_info; init_read_record(&read_record_info, thd, keywords, select,1,0); while (!read_record_info.read_record(&read_record_info) && count<2) @@ -256,13 +254,13 @@ int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields, description description of found topic (out) example example for found topic (out) - NOTE + NOTE Field 'names' is set only if more than one topic was found. - Fields 'name', 'description', 'example' are set only if + Fields 'name', 'description', 'example' are set only if exactly one topic was found. */ -int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, +int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, struct st_find_field *find_fields, int16 key_id, List<String> *names, String *name, String *description, String *example) @@ -273,7 +271,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, Field *rtopic_id, *rkey_id; DBUG_ENTER("get_topics_for_keyword"); - + if ((iindex_topic= find_type((char*) primary_key_name, &topics->keynames, 1+2)-1)<0 || (iindex_relations= find_type((char*) primary_key_name, @@ -284,18 +282,18 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, } rtopic_id= find_fields[help_relation_help_topic_id].field; rkey_id= find_fields[help_relation_help_keyword_id].field; - - topics->file->index_init(iindex_topic); - relations->file->index_init(iindex_relations); - + + topics->file->ha_index_init(iindex_topic); + relations->file->ha_index_init(iindex_relations); + rkey_id->store((longlong) key_id); rkey_id->get_key_image(buff, rkey_id->pack_length(), rkey_id->charset(), Field::itRAW); int key_res= relations->file->index_read(relations->record[0], (byte *)buff, rkey_id->pack_length(), HA_READ_KEY_EXACT); - - for ( ; + + for ( ; !key_res && key_id == (int16) rkey_id->val_int() ; key_res= relations->file->index_next(relations->record[0])) { @@ -305,7 +303,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, field->store((longlong) topic_id); field->get_key_image(topic_id_buff, field->pack_length(), field->charset(), Field::itRAW); - + if (!topics->file->index_read(topics->record[0], (byte *)topic_id_buff, field->pack_length(), HA_READ_KEY_EXACT)) { @@ -314,50 +312,12 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, count++; } } + topics->file->ha_index_end(); + relations->file->ha_index_end(); DBUG_RETURN(count); } /* - Look for topics with keyword by mask - - SYNOPSIS - search_topics_by_keyword() - thd Thread handler - keywords Table of keywords - topics Table of topics - relations Table of m:m relation "topic/keyword" - find_fields Filled array of info for fields - select Function to test for if matching help keyword. - Normally 'help_keyword.name like 'bit%' - - RETURN VALUES - # number of topics found - - names array of name of found topics (out) - - name name of found topic (out) - description description of found topic (out) - example example for found topic (out) - - NOTE - Field 'names' is set only if more than one topic was found. - Fields 'name', 'description', 'example' are set only if - exactly one topic was found. -*/ - -int search_topics_by_keyword(THD *thd, - TABLE *keywords, TABLE *topics, TABLE *relations, - struct st_find_field *find_fields, - SQL_SELECT *select, List<String> *names, - String *name, String *description, String *example) -{ - int key_id; - return search_keyword(thd,keywords,find_fields,select,&key_id)!=1 - ? 0 : get_topics_for_keyword(thd,topics,relations,find_fields,key_id, - names,name,description,example); -} - -/* Look for categories by mask SYNOPSIS @@ -382,10 +342,10 @@ int search_categories(THD *thd, TABLE *categories, Field *pfname= find_fields[help_category_name].field; Field *pcat_id= find_fields[help_category_help_category_id].field; int count= 0; - READ_RECORD read_record_info; + READ_RECORD read_record_info; DBUG_ENTER("search_categories"); - + init_read_record(&read_record_info, thd, categories, select,1,0); while (!read_record_info.read_record(&read_record_info)) { @@ -398,7 +358,7 @@ int search_categories(THD *thd, TABLE *categories, names->push_back(lname); } end_read_record(&read_record_info); - + DBUG_RETURN(count); } @@ -423,7 +383,7 @@ void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname, init_read_record(&read_record_info, thd, items, select,1,0); while (!read_record_info.read_record(&read_record_info)) { - if (!select->cond->val_int()) + if (!select->cond->val_int()) continue; String *name= new (&thd->mem_root) String(); get_field(&thd->mem_root,pfname,name); @@ -436,7 +396,7 @@ void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname, /* Send to client answer for help request - + SYNOPSIS send_answer_1() protocol - protocol for sending @@ -466,10 +426,10 @@ int send_answer_1(Protocol *protocol, String *s1, String *s2, String *s3) field_list.push_back(new Item_empty_string("name",64)); field_list.push_back(new Item_empty_string("description",1000)); field_list.push_back(new Item_empty_string("example",1000)); - + if (protocol->send_fields(&field_list,1)) DBUG_RETURN(1); - + protocol->prepare_for_resend(); protocol->store(s1); protocol->store(s2); @@ -539,7 +499,7 @@ extern "C" int string_ptr_cmp(const void* ptr1, const void* ptr2) SYNOPSIS send_variant_2_list() protocol Protocol for sending - names List of names + names List of names cat Value of the column <is_it_category> source_name name of category for all items.. @@ -548,8 +508,8 @@ extern "C" int string_ptr_cmp(const void* ptr1, const void* ptr2) 0 Data was successefully send */ -int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol, - List<String> *names, +int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol, + List<String> *names, const char *cat, String *source_name) { DBUG_ENTER("send_variant_2_list"); @@ -589,17 +549,22 @@ int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol, table goal table error code of error (out) - + RETURN VALUES - # created SQL_SELECT + # created SQL_SELECT */ -SQL_SELECT *prepare_simple_select(THD *thd, Item *cond, TABLE_LIST *tables, +SQL_SELECT *prepare_simple_select(THD *thd, Item *cond, TABLE_LIST *tables, TABLE *table, int *error) { cond->fix_fields(thd, tables, &cond); // can never fail SQL_SELECT *res= make_select(table,0,0,cond,error); - return (*error || (res && res->check_quick(thd, 0, HA_POS_ERROR))) ? 0 : res; + if (*error || (res && res->check_quick(thd, 0, HA_POS_ERROR))) + { + delete res; + res=0; + } + return res; } /* @@ -615,9 +580,9 @@ SQL_SELECT *prepare_simple_select(THD *thd, Item *cond, TABLE_LIST *tables, pfname field "name" in table error code of error (out) - + RETURN VALUES - # created SQL_SELECT + # created SQL_SELECT */ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, @@ -626,7 +591,7 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, { Item *cond= new Item_func_like(new Item_field(pfname), new Item_string(mask,mlen,pfname->charset()), - (char*) "\\"); + new Item_string("\\",1,&my_charset_latin1)); if (thd->is_fatal_error) return 0; // OOM return prepare_simple_select(thd,cond,tables,table,error); @@ -649,12 +614,10 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, int mysqld_help(THD *thd, const char *mask) { Protocol *protocol= thd->protocol; - SQL_SELECT *select_topics_by_name= 0, *select_keyword_by_name= 0, - *select_cat_by_name= 0, *select_topics_by_cat= 0, *select_cat_by_cat= 0, - *select_root_cats= 0; + SQL_SELECT *select; st_find_field used_fields[array_elements(init_used_fields)]; DBUG_ENTER("mysqld_help"); - + TABLE_LIST tables[4]; bzero((gptr)tables,sizeof(tables)); tables[0].alias= tables[0].real_name= (char*) "help_topic"; @@ -670,13 +633,13 @@ int mysqld_help(THD *thd, const char *mask) tables[3].lock_type= TL_READ; tables[3].next= 0; tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql"; - + List<String> topics_list, categories_list, subcategories_list; String name, description, example; int res, count_topics, count_categories, error; uint mlen= strlen(mask); MEM_ROOT *mem_root= &thd->mem_root; - + if (open_and_lock_tables(thd, tables)) { res= -1; @@ -684,7 +647,7 @@ int mysqld_help(THD *thd, const char *mask) } /* Init tables and fields to be usable from items */ setup_tables(tables); - memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields)); + memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields)); if (init_fields(thd, tables, used_fields, array_elements(used_fields))) { res= -1; @@ -693,39 +656,55 @@ int mysqld_help(THD *thd, const char *mask) size_t i; for (i=0; i<sizeof(tables)/sizeof(TABLE_LIST); i++) tables[i].table->file->init_table_handle_for_HANDLER(); - - if (!(select_topics_by_name= + + if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[0].table, - used_fields[help_topic_name].field,&error)) || - !(select_cat_by_name= - prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, - used_fields[help_category_name].field,&error))|| - !(select_keyword_by_name= - prepare_select_for_name(thd,mask,mlen,tables,tables[3].table, - used_fields[help_keyword_name].field,&error))) + used_fields[help_topic_name].field,&error))) { res= -1; goto end; } res= 1; - count_topics= search_topics(thd,tables[0].table,used_fields, - select_topics_by_name,&topics_list, + count_topics= search_topics(thd,tables[0].table,used_fields, + select,&topics_list, &name, &description, &example); + delete select; if (count_topics == 0) - count_topics= search_topics_by_keyword(thd,tables[3].table,tables[0].table, - tables[2].table,used_fields, - select_keyword_by_name,&topics_list, - &name,&description,&example); - + { + int key_id; + if (!(select= + prepare_select_for_name(thd,mask,mlen,tables,tables[3].table, + used_fields[help_keyword_name].field,&error))) + { + res= -1; + goto end; + } + count_topics=search_keyword(thd,tables[3].table,used_fields,select,&key_id); + delete select; + count_topics= (count_topics != 1) ? 0 : + get_topics_for_keyword(thd,tables[0].table,tables[2].table, + used_fields,key_id,&topics_list,&name, + &description,&example); + } + if (count_topics == 0) { int16 category_id; Field *cat_cat_id= used_fields[help_category_parent_category_id].field; + if (!(select= + prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, + used_fields[help_category_name].field,&error))) + { + res= -1; + goto end; + } + count_categories= search_categories(thd, tables[1].table, used_fields, - select_cat_by_name, + select, &categories_list,&category_id); + delete select; if (!count_categories) { if (send_header_2(protocol,FALSE)) @@ -746,22 +725,26 @@ int mysqld_help(THD *thd, const char *mask) Item *cond_cat_by_cat= new Item_func_equal(new Item_field(cat_cat_id), new Item_int((int32)category_id)); - if (!(select_topics_by_cat= prepare_simple_select(thd,cond_topic_by_cat, - tables,tables[0].table, - &error)) || - !(select_cat_by_cat= - prepare_simple_select(thd,cond_cat_by_cat,tables, - tables[1].table,&error))) + if (!(select= prepare_simple_select(thd,cond_topic_by_cat, + tables,tables[0].table,&error))) { res= -1; goto end; } get_all_items_for_category(thd,tables[0].table, used_fields[help_topic_name].field, - select_topics_by_cat,&topics_list); + select,&topics_list); + delete select; + if (!(select= prepare_simple_select(thd,cond_cat_by_cat,tables, + tables[1].table,&error))) + { + res= -1; + goto end; + } get_all_items_for_category(thd,tables[1].table, used_fields[help_category_name].field, - select_cat_by_cat,&subcategories_list); + select,&subcategories_list); + delete select; String *cat= categories_list.head(); if (send_header_2(protocol, true) || send_variant_2_list(mem_root,protocol,&topics_list, "N",cat) || @@ -780,30 +763,25 @@ int mysqld_help(THD *thd, const char *mask) if (send_header_2(protocol, FALSE) || send_variant_2_list(mem_root,protocol, &topics_list, "N", 0)) goto end; - search_categories(thd, tables[1].table, used_fields, - select_cat_by_name,&categories_list, 0); + if (!(select= + prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, + used_fields[help_category_name].field,&error))) + { + res= -1; + goto end; + } + search_categories(thd, tables[1].table, used_fields, + select,&categories_list, 0); + delete select; /* Then send categories */ if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0)) goto end; } res= 0; - + send_eof(thd); end: - free_select(select_topics_by_name); - free_select(select_keyword_by_name); - free_select(select_cat_by_name); - free_select(select_topics_by_cat); - free_select(select_cat_by_cat); - free_select(select_root_cats); - DBUG_RETURN(res); } - -static void free_select(SQL_SELECT *sel) -{ - if (sel) - delete sel->quick; -} diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 19fb439c5cb..3acebf5cadc 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -183,7 +183,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, else #endif /* EMBEDDED_LIBRARY */ res= open_and_lock_tables(thd, table_list); - if (res) + if (res || thd->is_fatal_error) DBUG_RETURN(-1); table= table_list->table; @@ -943,6 +943,10 @@ TABLE *delayed_insert::get_local_table(THD* client_thd) /* _rowid is not used with delayed insert */ copy->rowid_field=0; + + /* Adjust in_use for pointing to client thread */ + copy->in_use= client_thd; + return copy; /* Got fatal error */ @@ -1109,7 +1113,7 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) thd->fatal_error(); // Abort waiting inserts goto end; } - if (di->table->file->has_transactions()) + if (!(di->table->file->table_flags() & HA_CAN_INSERT_DELAYED)) { thd->fatal_error(); my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.real_name); @@ -1215,8 +1219,10 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) di->status=0; if (!di->stacked_inserts && !di->tables_in_use && thd->lock) { - /* No one is doing a insert delayed; - Unlock it so that other threads can use it */ + /* + No one is doing a insert delayed + Unlock table so that other threads can use it + */ MYSQL_LOCK *lock=thd->lock; thd->lock=0; pthread_mutex_unlock(&di->mutex); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 2c970e4c7ca..1ffe3d12139 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -44,13 +44,6 @@ pthread_key(LEX*,THR_LEX); #define TOCK_NAME_LENGTH 24 /* - Map to default keyword characters. This is used to test if an identifer - is 'simple', in which case we don't have to do any character set conversions - on it -*/ -uchar *bin_ident_map= my_charset_bin.ident_map; - -/* The following data is based on the latin1 character set, and is only used when comparing keywords */ @@ -556,13 +549,9 @@ int yylex(void *arg, void *yythd) else #endif { - result_state= bin_ident_map[c] ? IDENT : IDENT_QUOTED; - while (ident_map[c=yyGet()]) - { - /* If not simple character, mark that we must convert it */ - if (!bin_ident_map[c]) - result_state= IDENT_QUOTED; - } + for (result_state= c; ident_map[c= yyGet()]; result_state|= c); + /* If there were non-ASCII characters, mark that we must convert */ + result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; } length= (uint) (lex->ptr - lex->tok_start)-1; if (lex->ignore_space) @@ -664,12 +653,11 @@ int yylex(void *arg, void *yythd) } else #endif - while (ident_map[c = yyGet()]) - { - /* If not simple character, mark that we must convert it */ - if (!bin_ident_map[c]) - result_state= IDENT_QUOTED; - } + { + for (result_state=0; ident_map[c= yyGet()]; result_state|= c); + /* If there were non-ASCII characters, mark that we must convert */ + result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; + } if (c == '.' && ident_map[yyPeek()]) lex->next_state=MY_LEX_IDENT_SEP;// Next is '.' @@ -943,13 +931,11 @@ int yylex(void *arg, void *yythd) We should now be able to handle: [(global | local | session) .]variable_name */ - result_state= IDENT; - while (ident_map[c=yyGet()]) - { - /* If not simple character, mark that we must convert it */ - if (!bin_ident_map[c]) - result_state= IDENT_QUOTED; - } + + for (result_state= 0; ident_map[c= yyGet()]; result_state|= c); + /* If there were non-ASCII characters, mark that we must convert */ + result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; + if (c == '.') lex->next_state=MY_LEX_IDENT_SEP; length= (uint) (lex->ptr - lex->tok_start)-1; @@ -1017,7 +1003,7 @@ void st_select_lex::init_query() ref_pointer_array= 0; select_n_having_items= 0; prep_where= 0; - explicit_limit= 0; + subquery_in_having= explicit_limit= 0; first_execution= 1; first_cond_optimization= 1; } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 02b3da55921..387685194f3 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -84,6 +84,7 @@ enum enum_sql_command { SQLCOM_SHOW_CREATE_PROC, SQLCOM_SHOW_CREATE_FUNC, SQLCOM_SHOW_STATUS_PROC, SQLCOM_SHOW_STATUS_FUNC, + SQLCOM_PREPARE, SQLCOM_EXECUTE, SQLCOM_DEALLOCATE_PREPARE, /* This should be the last !!! */ SQLCOM_END }; @@ -186,8 +187,8 @@ enum tablespace_op_type e||+-------------------------+ || V| neighbor | V| unit1.1<+==================>unit1.2 unit2.1 - fake1.1 fake2.1 - select1.1.1 select 1.1.2 select1.2.1 select2.1.1 select2.1.2 + fake1.1 + select1.1.1 select 1.1.2 select1.2.1 select2.1.1 |^ || V| @@ -453,6 +454,11 @@ public: bool having_fix_field; /* explicit LIMIT clause was used */ bool explicit_limit; + /* + there are subquery in HAVING clause => we can't close tables before + query processing end even if we use temporary table + */ + bool subquery_in_having; bool first_execution; /* first execution in SP or PS */ bool first_cond_optimization; @@ -648,11 +654,22 @@ typedef struct st_lex uint fk_delete_opt, fk_update_opt, fk_match_option; uint slave_thd_opt; uint8 describe; - bool drop_if_exists, drop_temporary, local_file; + bool drop_if_exists, drop_temporary, local_file, one_shot_set; bool in_comment, ignore_space, verbose, no_write_to_binlog; bool derived_tables; bool safe_to_cache_query; ALTER_INFO alter_info; + /* Prepared statements SQL syntax:*/ + LEX_STRING prepared_stmt_name; /* Statement name (in all queries) */ + /* + Prepared statement query text or name of variable that holds the + prepared statement (in PREPARE ... queries) + */ + LEX_STRING prepared_stmt_code; + /* If true, prepared_stmt_code is a name of variable that holds the query */ + bool prepared_stmt_code_is_varref; + /* Names of user variables holding parameters (in EXECUTE) */ + List<LEX_STRING> prepared_stmt_params; sp_head *sphead; sp_name *spname; bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */ diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 3313ff913dc..c7a64ea8699 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -527,7 +527,7 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, ((Field_timestamp*) field)->set_time(); else if (field != table->next_number_field) field->set_warning((uint) MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_NULL_TO_NOTNULL); + ER_WARN_NULL_TO_NOTNULL, 1); } continue; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 52cbe95d24d..6870721a085 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -295,9 +295,10 @@ int check_user(THD *thd, enum enum_server_command command, thd->user, thd->host_or_ip); DBUG_RETURN(-1); } + /* We have to read very specific packet size */ if (send_old_password_request(thd) || - my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) // We have to read very - { // specific packet size + my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) + { inc_host_errors(&thd->remote.sin_addr); DBUG_RETURN(ER_HANDSHAKE_ERROR); } @@ -626,8 +627,9 @@ static void reset_mqh(THD *thd, LEX_USER *lu, bool get_them= 0) uc->conn_per_hour=0; } } - else // for FLUSH PRIVILEGES and FLUSH USER_RESOURCES + else { + /* for FLUSH PRIVILEGES and FLUSH USER_RESOURCES */ for (uint idx=0;idx < hash_user_connections.records; idx++) { USER_CONN *uc=(struct user_conn *) hash_element(&hash_user_connections, @@ -951,7 +953,7 @@ pthread_handler_decl(handle_one_connection,arg) pthread_detach_this_thread(); #if !defined( __WIN__) && !defined(OS2) // Win32 calls this in pthread_create - // The following calls needs to be done before we call DBUG_ macros + /* The following calls needs to be done before we call DBUG_ macros */ if (!(test_flags & TEST_NO_THREADS) & my_thread_init()) { close_connection(thd, ER_OUT_OF_RESOURCES, 1); @@ -970,7 +972,7 @@ pthread_handler_decl(handle_one_connection,arg) */ DBUG_PRINT("info", ("handle_one_connection called by thread %d\n", thd->thread_id)); - // now that we've called my_thread_init(), it is safe to call DBUG_* + /* now that we've called my_thread_init(), it is safe to call DBUG_* */ #if defined(__WIN__) init_signals(); // IRENA; testing ? @@ -1032,7 +1034,7 @@ pthread_handler_decl(handle_one_connection,arg) decrease_user_connections(thd->user_connect); if (net->error && net->vio != 0 && net->report_error) { - if (!thd->killed && thd->variables.log_warnings) + if (!thd->killed && thd->variables.log_warnings > 1) sql_print_error(ER(ER_NEW_ABORTING_CONNECTION), thd->thread_id,(thd->db ? thd->db : "unconnected"), thd->user ? thd->user : "unauthenticated", @@ -1206,7 +1208,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd) } net_flush(&thd->net); if ((error= table->file->dump(thd,fd))) - my_error(ER_GET_ERRNO, MYF(0)); + my_error(ER_GET_ERRNO, MYF(0), error); err: close_thread_tables(thd); @@ -1244,7 +1246,7 @@ bool do_command(THD *thd) packet=0; old_timeout=net->read_timeout; - // Wait max for 8 hours + /* Wait max for 8 hours */ net->read_timeout=(uint) thd->variables.net_wait_timeout; thd->clear_error(); // Clear error message @@ -1326,6 +1328,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (command != COM_STATISTICS && command != COM_PING) query_id++; thread_running++; + /* TODO: set thd->lex->sql_command to SQLCOM_END here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->server_status&= @@ -1442,7 +1445,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_EXECUTE: { - thd->free_list= NULL; mysql_stmt_execute(thd, packet, packet_length); break; } @@ -1497,6 +1499,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->query_length= length; thd->query= packet; thd->query_id= query_id++; + /* TODO: set thd->lex->sql_command to SQLCOM_END here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); #ifndef EMBEDDED_LIBRARY mysql_parse(thd, packet, length); @@ -1544,7 +1547,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, packet, (uint) (pend-packet), thd->charset()); table_list.alias= table_list.real_name= conv_name.str; packet= pend+1; - // command not cachable => no gap for data base name + /* command not cachable => no gap for data base name */ if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1))) break; mysql_log.write(thd,command,"%s %s",table_list.real_name,fields); @@ -1591,7 +1594,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { statistic_increment(com_stat[SQLCOM_DROP_DB],&LOCK_status); char *db=thd->strdup(packet), *alias; - // null test to handle EOM + /* null test to handle EOM */ if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL"); @@ -1605,7 +1608,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } mysql_log.write(thd,command,db); - mysql_rm_db(thd,alias,0,0); + mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : db), 0, 0); break; } #ifndef EMBEDDED_LIBRARY @@ -1629,7 +1632,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->server_id = slave_server_id; mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags); unregister_slave(thd,1,1); - // fake COM_QUIT -- if we get here, the thread needs to terminate + /* fake COM_QUIT -- if we get here, the thread needs to terminate */ error = TRUE; net->error = 0; break; @@ -1650,10 +1653,28 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } #ifndef EMBEDDED_LIBRARY case COM_SHUTDOWN: + { statistic_increment(com_other,&LOCK_status); if (check_global_access(thd,SHUTDOWN_ACL)) break; /* purecov: inspected */ - DBUG_PRINT("quit",("Got shutdown command")); + /* + If the client is < 4.1.3, it is going to send us no argument; then + packet_length is 1, packet[0] is the end 0 of the packet. Note that + SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in + packet[0]. + */ + enum enum_shutdown_level level= + (enum enum_shutdown_level) (uchar) packet[0]; + DBUG_PRINT("quit",("Got shutdown command for level %u", level)); + if (level == SHUTDOWN_DEFAULT) + level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable + else if (level != SHUTDOWN_WAIT_ALL_BUFFERS) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level"); + send_error(thd); + break; + } + DBUG_PRINT("quit",("Got shutdown command for level %u", level)); mysql_log.write(thd,command,NullS); send_eof(thd); #ifdef __WIN__ @@ -1667,6 +1688,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, kill_mysql(); error=TRUE; break; + } #endif case COM_STATISTICS: { @@ -1988,7 +2010,98 @@ mysql_execute_command(THD *thd) } break; } - + case SQLCOM_PREPARE: + { + char *query_str; + uint query_len; + if (lex->prepared_stmt_code_is_varref) + { + /* This is PREPARE stmt FROM @var. */ + String str; + CHARSET_INFO *to_cs= thd->variables.collation_connection; + bool need_conversion; + user_var_entry *entry; + uint32 unused; + /* + Convert @var contents to string in connection character set. Although + it is known that int/real/NULL value cannot be a valid query we still + convert it for error messages to uniform. + */ + if ((entry= + (user_var_entry*)hash_search(&thd->user_vars, + (byte*)lex->prepared_stmt_code.str, + lex->prepared_stmt_code.length)) + && entry->value) + { + String *pstr; + my_bool is_var_null; + pstr= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC); + DBUG_ASSERT(!is_var_null); + if (!pstr) + send_error(thd, ER_OUT_OF_RESOURCES); + DBUG_ASSERT(pstr == &str); + } + else + str.set("NULL", 4, &my_charset_latin1); + need_conversion= + String::needs_conversion(str.length(), str.charset(), to_cs, &unused); + + query_len= need_conversion? (str.length() * to_cs->mbmaxlen) : + str.length(); + if (!(query_str= alloc_root(&thd->mem_root, query_len+1))) + send_error(thd, ER_OUT_OF_RESOURCES); + + if (need_conversion) + query_len= copy_and_convert(query_str, query_len, to_cs, str.ptr(), + str.length(), str.charset()); + else + memcpy(query_str, str.ptr(), str.length()); + query_str[query_len]= 0; + } + else + { + query_str= lex->prepared_stmt_code.str; + query_len= lex->prepared_stmt_code.length; + DBUG_PRINT("info", ("PREPARE: %.*s FROM '%.*s' \n", + lex->prepared_stmt_name.length, + lex->prepared_stmt_name.str, + query_len, query_str)); + } + thd->command= COM_PREPARE; + if (!mysql_stmt_prepare(thd, query_str, query_len + 1, + &lex->prepared_stmt_name)) + send_ok(thd, 0L, 0L, "Statement prepared"); + break; + } + case SQLCOM_EXECUTE: + { + DBUG_PRINT("info", ("EXECUTE: %.*s\n", + lex->prepared_stmt_name.length, + lex->prepared_stmt_name.str)); + mysql_sql_stmt_execute(thd, &lex->prepared_stmt_name); + lex->prepared_stmt_params.empty(); + break; + } + case SQLCOM_DEALLOCATE_PREPARE: + { + Statement* stmt; + DBUG_PRINT("info", ("DEALLOCATE PREPARE: %.*s\n", + lex->prepared_stmt_name.length, + lex->prepared_stmt_name.str)); + if ((stmt= thd->stmt_map.find_by_name(&lex->prepared_stmt_name))) + { + thd->stmt_map.erase(stmt); + send_ok(thd); + } + else + { + res= -1; + my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), + lex->prepared_stmt_name.length, lex->prepared_stmt_name.str, + "DEALLOCATE PREPARE"); + } + break; + } case SQLCOM_DO: if (tables && ((res= check_table_access(thd, SELECT_ACL, tables,0)) || (res= open_and_lock_tables(thd,tables)))) @@ -2012,7 +2125,7 @@ mysql_execute_command(THD *thd) { if (check_global_access(thd, SUPER_ACL)) goto error; - // PURGE MASTER LOGS TO 'file' + /* PURGE MASTER LOGS TO 'file' */ res = purge_master_logs(thd, lex->to_log); break; } @@ -2020,7 +2133,7 @@ mysql_execute_command(THD *thd) { if (check_global_access(thd, SUPER_ACL)) goto error; - // PURGE MASTER LOGS BEFORE 'data' + /* PURGE MASTER LOGS BEFORE 'data' */ res = purge_master_logs_before_date(thd, lex->purge_time); break; } @@ -2251,14 +2364,23 @@ mysql_execute_command(THD *thd) lex->create_list, lex->key_list, select_lex->item_list,lex->duplicates))) + { + /* + CREATE from SELECT give its SELECT_LEX for SELECT, + and item_list belong to SELECT + */ + select_lex->resolve_mode= SELECT_LEX::SELECT_MODE; res=handle_select(thd, lex, result); - //reset for PS + select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE; + } + /* reset for PS */ lex->create_list.empty(); lex->key_list.empty(); } } - else // regular create + else { + /* regular create */ if (lex->name) res= mysql_create_like_table(thd, create_table, &lex->create_info, (Table_ident *)lex->name); @@ -2273,15 +2395,15 @@ mysql_execute_command(THD *thd) send_ok(thd); } - // put tables back for PS rexecuting + /* put tables back for PS rexecuting */ tables= lex->link_first_table_back(tables, create_table, create_table_local); break; create_error: - res= 1; //error reported + res= 1; //error reported unsent_create_error: - // put tables back for PS rexecuting + /* put tables back for PS rexecuting */ tables= lex->link_first_table_back(tables, create_table, create_table_local); break; @@ -2508,29 +2630,13 @@ unsent_create_error: case SQLCOM_OPTIMIZE: { - HA_CREATE_INFO create_info; if (check_db_used(thd,tables) || check_table_access(thd,SELECT_ACL | INSERT_ACL, tables,0)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - if (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) - { - /* Use ALTER TABLE */ - lex->create_list.empty(); - lex->key_list.empty(); - lex->col_list.empty(); - lex->alter_info.reset(); - bzero((char*) &create_info,sizeof(create_info)); - create_info.db_type=DB_TYPE_DEFAULT; - create_info.row_type=ROW_TYPE_DEFAULT; - create_info.default_table_charset=default_charset_info; - res= mysql_alter_table(thd, NullS, NullS, &create_info, - tables, lex->create_list, - lex->key_list, 0, (ORDER *) 0, - DUP_ERROR, &lex->alter_info); - } - else - res = mysql_optimize_table(thd, tables, &lex->check_opt); + res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ? + mysql_recreate_table(thd, tables, 1) : + mysql_optimize_table(thd, tables, &lex->check_opt); /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { @@ -2611,7 +2717,11 @@ unsent_create_error: lex->duplicates))) /* Skip first table, which is the table we are inserting in */ lex->select_lex.table_list.first= (byte*) first_local_table->next; - lex->select_lex.resolve_mode= SELECT_LEX::NOMATTER_MODE; + /* + insert/replace from SELECT give its SELECT_LEX for SELECT, + and item_list belong to SELECT + */ + lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; res=handle_select(thd,lex,result); /* revert changes for SP */ lex->select_lex.table_list.first= (byte*) first_local_table; @@ -2813,7 +2923,7 @@ unsent_create_error: char *db=select_lex->db ? select_lex->db : thd->db; if (!db) { - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ goto error; /* purecov: inspected */ } remove_escape(db); // Fix escaped '_' @@ -2833,7 +2943,7 @@ unsent_create_error: goto error; } /* grant is checked in mysqld_show_tables */ - if (select_lex->options & SELECT_DESCRIBE) + if (lex->describe) res= mysqld_extend_show_tables(thd,db, (lex->wild ? lex->wild->ptr() : NullS)); else @@ -2920,14 +3030,31 @@ unsent_create_error: } case SQLCOM_SET_OPTION: + { + List<set_var_base> *lex_var_list= &lex->var_list; if (tables && ((res= check_table_access(thd, SELECT_ACL, tables,0)) || (res= open_and_lock_tables(thd,tables)))) break; - if (!(res= sql_set_variables(thd, &lex->var_list))) + if (lex->one_shot_set && not_all_support_one_shot(lex_var_list)) + { + my_printf_error(0, "The SET ONE_SHOT syntax is reserved for \ +purposes internal to the MySQL server", MYF(0)); + res= -1; + break; + } + if (!(res= sql_set_variables(thd, lex_var_list))) + { + /* + If the previous command was a SET ONE_SHOT, we don't want to forget + about the ONE_SHOT property of that SET. So we use a |= instead of = . + */ + thd->one_shot_set|= lex->one_shot_set; send_ok(thd); + } if (thd->net.report_error) res= -1; break; + } case SQLCOM_UNLOCK_TABLES: unlock_locked_tables(thd); @@ -3023,7 +3150,8 @@ unsent_create_error: send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); goto error; } - res=mysql_rm_db(thd,alias,lex->drop_if_exists,0); + res=mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : lex->name), + lex->drop_if_exists, 0); break; } case SQLCOM_ALTER_DB: @@ -3076,7 +3204,7 @@ unsent_create_error: res=mysqld_show_create_db(thd,lex->name,&lex->create_info); break; } - case SQLCOM_CREATE_FUNCTION: // UDF function + case SQLCOM_CREATE_FUNCTION: // UDF function { sp_head *sph; if (check_access(thd,INSERT_ACL,"mysql",0,1,0)) @@ -3153,7 +3281,7 @@ unsent_create_error: { if (check_access(thd, UPDATE_ACL, "mysql",0,1,0)) goto error; - break; // We are allowed to do changes + break; // We are allowed to do changes } } } @@ -3370,7 +3498,7 @@ unsent_create_error: { if (!lex->sphead) { - res= -1; // Shouldn't happen + res= -1; // Shouldn't happen break; } uint namelen; @@ -3442,7 +3570,7 @@ unsent_create_error: uint smrx; LINT_INIT(smrx); - // In case the arguments are subselects... + /* In case the arguments are subselects... */ if (tables && ((res= check_table_access(thd, SELECT_ACL, tables, 0)) || (res= open_and_lock_tables(thd, tables)))) { @@ -3451,8 +3579,10 @@ unsent_create_error: fix_tables_pointers(lex->all_selects_list); #ifndef EMBEDDED_LIBRARY - // When executing substatements, they're assumed to send_error when - // it happens, but not to send_ok. + /* + When executing substatements, they're assumed to send_error when + it happens, but not to send_ok. + */ my_bool nsok= thd->net.no_send_ok; thd->net.no_send_ok= TRUE; #endif @@ -3636,7 +3766,31 @@ unsent_create_error: send_ok(thd); break; } - thd->proc_info="query end"; // QQ + thd->proc_info="query end"; + if (thd->one_shot_set) + { + /* + If this is a SET, do nothing. This is to allow mysqlbinlog to print + many SET commands (in this case we want the charset temp setting to + live until the real query). This is also needed so that SET + CHARACTER_SET_CLIENT... does not cancel itself immediately. + */ + if (lex->sql_command != SQLCOM_SET_OPTION) + { + thd->variables.character_set_client= + global_system_variables.character_set_client; + thd->variables.collation_connection= + global_system_variables.collation_connection; + thd->variables.collation_database= + global_system_variables.collation_database; + thd->variables.collation_server= + global_system_variables.collation_server; + thd->update_charset(); + thd->variables.time_zone= + global_system_variables.time_zone; + thd->one_shot_set= 0; + } + } /* The return value for ROW_COUNT() is "implementation dependent" if @@ -3658,14 +3812,16 @@ unsent_create_error: thd->row_count_func= -1; } - // We end up here if res == 0 and send_ok() has been done, - // or res != 0 and no send_error() has yet been done. + /* + We end up here if res == 0 and send_ok() has been done, + or res != 0 and no send_error() has yet been done. + */ if (res < 0) send_error(thd,thd->killed_errno()); DBUG_RETURN(res); error: - // We end up here if send_error() has already been done. + /* We end up here if send_error() has already been done. */ DBUG_RETURN(-1); } @@ -3686,7 +3842,6 @@ error: */ int check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables) - { if (check_access(thd, privilege, tables->db, &tables->grant.privilege,0,0)) return 1; @@ -3785,7 +3940,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, thd->priv_user, db, test(want_access & GRANT_ACL)); else db_access=thd->db_access; - // Remove SHOW attribute and access rights we already have + /* Remove SHOW attribute and access rights we already have */ want_access &= ~(thd->master_access | EXTRA_ACL); db_access= ((*save_priv=(db_access | thd->master_access)) & want_access); @@ -3953,10 +4108,10 @@ bool check_stack_overrun(THD *thd,char *buf __attribute__((unused))) #define MY_YACC_INIT 1000 // Start with big alloc #define MY_YACC_MAX 32000 // Because of 'short' -bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, int *yystacksize) +bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize) { LEX *lex=current_lex; - int old_info=0; + ulong old_info=0; if ((uint) *yystacksize >= MY_YACC_MAX) return 1; if (!lex->yacc_yyvs) @@ -4021,7 +4176,7 @@ mysql_init_query(THD *thd, bool lexonly) thd->total_warn_count=0; // Warnings for this query thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0; thd->sent_row_count= thd->examined_row_count= 0; - thd->is_fatal_error= thd->rand_used= 0; + thd->is_fatal_error= thd->rand_used= thd->time_zone_used= 0; thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS | SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED); @@ -4072,7 +4227,7 @@ mysql_new_select(LEX *lex, bool move_down) unit->link_prev= 0; unit->return_to= lex->current_select; select_lex->include_down(unit); - // TODO: assign resolve_mode for fake subquery after merging with new tree + /* TODO: assign resolve_mode for fake subquery after merging with new tree */ } else { @@ -4379,7 +4534,12 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, break; case FIELD_TYPE_DECIMAL: if (!length) - new_field->length= 10; // Default length for DECIMAL + { + if ((new_field->length= new_field->decimals)) + new_field->length++; + else + new_field->length= 10; // Default length for DECIMAL + } if (new_field->length < MAX_FIELD_WIDTH) // Skip wrong argument { new_field->length+=sign_len; @@ -5066,7 +5226,7 @@ void add_join_on(TABLE_LIST *b,Item *expr) b->on_expr=expr; else { - // This only happens if you have both a right and left join + /* This only happens if you have both a right and left join */ b->on_expr=new Item_cond_and(b->on_expr,expr); } b->on_expr->top_level_item(); @@ -5168,7 +5328,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, if (options & REFRESH_QUERY_CACHE_FREE) { query_cache.pack(); // FLUSH QUERY CACHE - options &= ~REFRESH_QUERY_CACHE; //don't flush all cache, just free memory + options &= ~REFRESH_QUERY_CACHE; // Don't flush cache, just free memory } if (options & (REFRESH_TABLES | REFRESH_QUERY_CACHE)) { diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index a8a2f5e8515..d4f69e5dd4f 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -92,16 +92,22 @@ public: bool get_longdata_error; #ifndef EMBEDDED_LIBRARY bool (*set_params)(Prepared_statement *st, uchar *data, uchar *data_end, - uchar *read_pos); + uchar *read_pos, String *expanded_query); #else - bool (*set_params_data)(Prepared_statement *st); + bool (*set_params_data)(Prepared_statement *st, String *expanded_query); #endif + bool (*set_params_from_vars)(Prepared_statement *stmt, + List<LEX_STRING>& varnames, + String *expanded_query); public: Prepared_statement(THD *thd_arg); virtual ~Prepared_statement(); + void setup_set_params(); virtual Statement::Type type() const; }; +static void execute_stmt(THD *thd, Prepared_statement *stmt, + String *expanded_query, bool set_context); /****************************************************************************** Implementation @@ -130,7 +136,8 @@ find_prepared_statement(THD *thd, ulong id, const char *where, if (stmt == 0 || stmt->type() != Statement::PREPARED_STATEMENT) { - my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), id, where); + char llbuf[22]; + my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 22, llstr(id, llbuf), where); if (se == SEND_ERROR) send_error(thd); return 0; @@ -211,7 +218,13 @@ static ulong get_param_length(uchar **packet, ulong len) if (len < 5) return 0; (*packet)+=9; // Must be 254 when here - /* TODO: why uint4korr here? (should be uint8korr) */ + /* + In our client-server protocol all numbers bigger than 2^24 + stored as 8 bytes with uint8korr. Here we always know that + parameter length is less than 2^4 so don't look at the second + 4 bytes. But still we need to obey the protocol hence 9 in the + assignment above. + */ return (ulong) uint4korr(pos+1); } #else @@ -327,20 +340,19 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) { uchar *to= *pos; TIME tm; - - /* TODO: why length is compared with 8 here? */ - tm.second_part= (length > 8 ) ? (ulong) sint4korr(to+7): 0; + tm.neg= (bool) to[0]; + day= (uint) sint4korr(to+1); /* Note, that though ranges of hour, minute and second are not checked here we rely on them being < 256: otherwise we'll get buffer overflow in make_{date,time} functions, which are called when time value is converted to string. */ - day= (uint) sint4korr(to+1); tm.hour= (uint) to[5] + day * 24; tm.minute= (uint) to[6]; tm.second= (uint) to[7]; + tm.second_part= (length > 8) ? (ulong) sint4korr(to+8) : 0; if (tm.hour > 838) { /* TODO: add warning 'Data truncated' here */ @@ -349,9 +361,8 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) tm.second= 59; } tm.day= tm.year= tm.month= 0; - tm.neg= (bool)to[0]; - param->set_time(&tm, TIMESTAMP_TIME, + param->set_time(&tm, MYSQL_TIMESTAMP_TIME, MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } *pos+= length; @@ -360,14 +371,16 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) static void set_param_datetime(Item_param *param, uchar **pos, ulong len) { uint length; - + if ((length= get_param_length(pos, len)) >= 4) { uchar *to= *pos; TIME tm; - - tm.second_part= (length > 7 ) ? (ulong) sint4korr(to+7): 0; - + + tm.neg= 0; + tm.year= (uint) sint2korr(to); + tm.month= (uint) to[2]; + tm.day= (uint) to[3]; /* Note, that though ranges of hour, minute and second are not checked here we rely on them being < 256: otherwise @@ -381,13 +394,10 @@ static void set_param_datetime(Item_param *param, uchar **pos, ulong len) } else tm.hour= tm.minute= tm.second= 0; - - tm.year= (uint) sint2korr(to); - tm.month= (uint) to[2]; - tm.day= (uint) to[3]; - tm.neg= 0; - param->set_time(&tm, TIMESTAMP_DATETIME, + tm.second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; + + param->set_time(&tm, MYSQL_TIMESTAMP_DATETIME, MAX_DATETIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } *pos+= length; @@ -414,7 +424,7 @@ static void set_param_date(Item_param *param, uchar **pos, ulong len) tm.second_part= 0; tm.neg= 0; - param->set_time(&tm, TIMESTAMP_DATE, + param->set_time(&tm, MYSQL_TIMESTAMP_DATE, MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } *pos+= length; @@ -423,58 +433,25 @@ static void set_param_date(Item_param *param, uchar **pos, ulong len) #else/*!EMBEDDED_LIBRARY*/ void set_param_time(Item_param *param, uchar **pos, ulong len) { - TIME tm; MYSQL_TIME *to= (MYSQL_TIME*)*pos; - - tm.second_part= to->second_part; - - tm.day= to->day; - tm.hour= to->hour; - tm.minute= to->minute; - tm.second= to->second; - - tm.year= tm.month= 0; - tm.neg= to->neg; - param->set_time(&tm, TIMESTAMP_TIME, + param->set_time(to, MYSQL_TIMESTAMP_TIME, MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } void set_param_datetime(Item_param *param, uchar **pos, ulong len) { - TIME tm; MYSQL_TIME *to= (MYSQL_TIME*)*pos; - tm.second_part= to->second_part; - - tm.day= to->day; - tm.hour= to->hour; - tm.minute= to->minute; - tm.second= to->second; - tm.year= to->year; - tm.month= to->month; - tm.neg= 0; - - param->set_time(&tm, TIMESTAMP_DATETIME, + param->set_time(to, MYSQL_TIMESTAMP_DATETIME, MAX_DATETIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } void set_param_date(Item_param *param, uchar **pos, ulong len) { - TIME tm; MYSQL_TIME *to= (MYSQL_TIME*)*pos; - - tm.second_part= to->second_part; - tm.day= to->day; - tm.year= to->year; - tm.month= to->month; - tm.neg= 0; - tm.hour= tm.minute= tm.second= 0; - tm.second_part= 0; - tm.neg= 0; - - param->set_time(&tm, TIMESTAMP_DATE, + param->set_time(to, MYSQL_TIMESTAMP_DATE, MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } #endif /*!EMBEDDED_LIBRARY*/ @@ -580,6 +557,7 @@ static void setup_one_conversion_function(THD *thd, Item_param *param, param->item_result_type= STRING_RESULT; } } + param->param_type= (enum enum_field_types) param_type; } #ifndef EMBEDDED_LIBRARY @@ -589,19 +567,20 @@ static void setup_one_conversion_function(THD *thd, Item_param *param, */ static bool insert_params_withlog(Prepared_statement *stmt, uchar *null_array, - uchar *read_pos, uchar *data_end) + uchar *read_pos, uchar *data_end, + String *query) { THD *thd= stmt->thd; Item_param **begin= stmt->param_array; Item_param **end= begin + stmt->param_count; uint32 length= 0; - String str, query; + String str; const String *res; DBUG_ENTER("insert_params_withlog"); - if (query.copy(stmt->query, stmt->query_length, default_charset_info)) + if (query->copy(stmt->query, stmt->query_length, default_charset_info)) DBUG_RETURN(1); for (Item_param **it= begin; it < end; ++it) @@ -622,20 +601,18 @@ static bool insert_params_withlog(Prepared_statement *stmt, uchar *null_array, if (param->convert_str_value(thd)) DBUG_RETURN(1); /* out of memory */ - if (query.replace(param->pos_in_query+length, 1, *res)) + if (query->replace(param->pos_in_query+length, 1, *res)) DBUG_RETURN(1); length+= res->length()-1; } - if (alloc_query(thd, (char *)query.ptr(), query.length()+1)) - DBUG_RETURN(1); - DBUG_RETURN(0); } static bool insert_params(Prepared_statement *stmt, uchar *null_array, - uchar *read_pos, uchar *data_end) + uchar *read_pos, uchar *data_end, + String *expanded_query) { Item_param **begin= stmt->param_array; Item_param **end= begin + stmt->param_count; @@ -700,7 +677,7 @@ static bool setup_conversion_functions(Prepared_statement *stmt, #else -static bool emb_insert_params(Prepared_statement *stmt) +static bool emb_insert_params(Prepared_statement *stmt, String *expanded_query) { THD *thd= stmt->thd; Item_param **it= stmt->param_array; @@ -733,20 +710,20 @@ static bool emb_insert_params(Prepared_statement *stmt) } -static bool emb_insert_params_withlog(Prepared_statement *stmt) +static bool emb_insert_params_withlog(Prepared_statement *stmt, String *query) { THD *thd= stmt->thd; Item_param **it= stmt->param_array; Item_param **end= it + stmt->param_count; MYSQL_BIND *client_param= thd->client_params; - String str, query; + String str; const String *res; uint32 length= 0; DBUG_ENTER("emb_insert_params_withlog"); - if (query.copy(stmt->query, stmt->query_length, default_charset_info)) + if (query->copy(stmt->query, stmt->query_length, default_charset_info)) DBUG_RETURN(1); for (; it < end; ++it, ++client_param) @@ -765,18 +742,16 @@ static bool emb_insert_params_withlog(Prepared_statement *stmt) *client_param->length : client_param->buffer_length); } - res= param->query_val_str(&str); - if (param->convert_str_value(thd)) - DBUG_RETURN(1); /* out of memory */ } - if (query.replace(param->pos_in_query+length, 1, *res)) + res= param->query_val_str(&str); + if (param->convert_str_value(thd)) + DBUG_RETURN(1); /* out of memory */ + + if (query->replace(param->pos_in_query+length, 1, *res)) DBUG_RETURN(1); + length+= res->length()-1; } - - if (alloc_query(thd, (char *) query.ptr(), query.length()+1)) - DBUG_RETURN(1); - DBUG_RETURN(0); } @@ -784,6 +759,105 @@ static bool emb_insert_params_withlog(Prepared_statement *stmt) /* + Set prepared statement parameters from user variables. + SYNOPSIS + insert_params_from_vars() + stmt Statement + varnames List of variables. Caller must ensure that number of variables + in the list is equal to number of statement parameters + query Ignored +*/ + +static bool insert_params_from_vars(Prepared_statement *stmt, + List<LEX_STRING>& varnames, + String *query __attribute__((unused))) +{ + Item_param **begin= stmt->param_array; + Item_param **end= begin + stmt->param_count; + user_var_entry *entry; + LEX_STRING *varname; + List_iterator<LEX_STRING> var_it(varnames); + DBUG_ENTER("insert_params_from_vars"); + + for (Item_param **it= begin; it < end; ++it) + { + Item_param *param= *it; + varname= var_it++; + entry= (user_var_entry*)hash_search(&stmt->thd->user_vars, + (byte*) varname->str, + varname->length); + if (param->set_from_user_var(stmt->thd, entry) || + param->convert_str_value(stmt->thd)) + DBUG_RETURN(1); + } + DBUG_RETURN(0); +} + + +/* + Do the same as insert_params_from_vars but also construct query text for + binary log. + SYNOPSIS + insert_params_from_vars() + stmt Statement + varnames List of variables. Caller must ensure that number of variables + in the list is equal to number of statement parameters + query The query with parameter markers replaced with their values +*/ + +static bool insert_params_from_vars_with_log(Prepared_statement *stmt, + List<LEX_STRING>& varnames, + String *query) +{ + Item_param **begin= stmt->param_array; + Item_param **end= begin + stmt->param_count; + user_var_entry *entry; + LEX_STRING *varname; + DBUG_ENTER("insert_params_from_vars"); + + List_iterator<LEX_STRING> var_it(varnames); + String str; + uint32 length= 0; + if (query->copy(stmt->query, stmt->query_length, default_charset_info)) + DBUG_RETURN(1); + + for (Item_param **it= begin; it < end; ++it) + { + Item_param *param= *it; + varname= var_it++; + if (get_var_with_binlog(stmt->thd, *varname, &entry)) + DBUG_RETURN(1); + DBUG_ASSERT(entry); + + if (param->set_from_user_var(stmt->thd, entry)) + DBUG_RETURN(1); + /* Insert @'escaped-varname' instead of parameter in the query */ + char *buf, *ptr; + str.length(0); + if (str.reserve(entry->name.length*2+3)) + DBUG_RETURN(1); + + buf= str.c_ptr_quick(); + ptr= buf; + *ptr++= '@'; + *ptr++= '\''; + ptr+= + escape_string_for_mysql(&my_charset_utf8_general_ci, + ptr, entry->name.str, entry->name.length); + *ptr++= '\''; + str.length(ptr - buf); + + if (param->convert_str_value(stmt->thd)) + DBUG_RETURN(1); /* out of memory */ + + if (query->replace(param->pos_in_query+length, 1, str)) + DBUG_RETURN(1); + length+= str.length()-1; + } + DBUG_RETURN(0); +} + +/* Validate INSERT statement: SYNOPSIS @@ -979,7 +1053,7 @@ static int mysql_test_delete(Prepared_statement *stmt, */ static int mysql_test_select(Prepared_statement *stmt, - TABLE_LIST *tables) + TABLE_LIST *tables, bool text_protocol) { THD *thd= stmt->thd; LEX *lex= stmt->lex; @@ -1009,30 +1083,32 @@ static int mysql_test_select(Prepared_statement *stmt, goto err; } + thd->used_tables= 0; // Updated by setup_fields + + // JOIN::prepare calls + if (unit->prepare(thd, 0, 0)) + { + send_error(thd); + goto err_prep; + } if (lex->describe) { - if (send_prep_stmt(stmt, 0)) - goto err; + if (!text_protocol && send_prep_stmt(stmt, 0)) + goto err_prep; + unit->cleanup(); } else { - thd->used_tables= 0; // Updated by setup_fields - - // JOIN::prepare calls - if (unit->prepare(thd, 0, 0)) + if (!text_protocol) { - send_error(thd); - goto err_prep; - } - - if (send_prep_stmt(stmt, lex->select_lex.item_list.elements) || + if (send_prep_stmt(stmt, lex->select_lex.item_list.elements) || thd->protocol_simple.send_fields(&lex->select_lex.item_list, 0) #ifndef EMBEDDED_LIBRARY - || net_flush(&thd->net) + || net_flush(&thd->net) #endif - ) - goto err_prep; - + ) + goto err_prep; + } unit->cleanup(); } thd->free_temporary_memory_pool_for_ps_preparing(); @@ -1199,6 +1275,7 @@ static int mysql_test_create_table(Prepared_statement *stmt, DBUG_ENTER("mysql_test_create_table"); THD *thd= stmt->thd; LEX *lex= stmt->lex; + SELECT_LEX *select_lex= &lex->select_lex; int res= 0; /* Skip first table, which is the table we are creating */ @@ -1207,8 +1284,12 @@ static int mysql_test_create_table(Prepared_statement *stmt, &create_table_local); if (!(res= create_table_precheck(thd, tables, create_table)) && - lex->select_lex.item_list.elements) + select_lex->item_list.elements) + { + select_lex->resolve_mode= SELECT_LEX::SELECT_MODE; res= select_like_statement_test(stmt, tables); + select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE; + } /* put tables back for PS rexecuting */ tables= lex->link_first_table_back(tables, create_table, @@ -1292,7 +1373,11 @@ static int mysql_test_insert_select(Prepared_statement *stmt, (TABLE_LIST *)lex->select_lex.table_list.first; /* Skip first table, which is the table we are inserting in */ lex->select_lex.table_list.first= (byte*) first_local_table->next; - lex->select_lex.resolve_mode= SELECT_LEX::NOMATTER_MODE; + /* + insert/replace from SELECT give its SELECT_LEX for SELECT, + and item_list belong to SELECT + */ + lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; res= select_like_statement_test(stmt, tables); /* revert changes*/ lex->select_lex.table_list.first= (byte*) first_local_table; @@ -1310,7 +1395,7 @@ static int mysql_test_insert_select(Prepared_statement *stmt, 0 success 1 error, sent to client */ -static int send_prepare_results(Prepared_statement *stmt) +static int send_prepare_results(Prepared_statement *stmt, bool text_protocol) { THD *thd= stmt->thd; LEX *lex= stmt->lex; @@ -1347,7 +1432,7 @@ static int send_prepare_results(Prepared_statement *stmt) break; case SQLCOM_SELECT: - if ((res= mysql_test_select(stmt, tables))) + if ((res= mysql_test_select(stmt, tables, text_protocol))) goto error; /* Statement and field info has already been sent */ DBUG_RETURN(0); @@ -1405,7 +1490,7 @@ static int send_prepare_results(Prepared_statement *stmt) goto error; } if (res == 0) - DBUG_RETURN(send_prep_stmt(stmt, 0)); + DBUG_RETURN(text_protocol? 0 : send_prep_stmt(stmt, 0)); error: if (res < 0) send_error(thd,thd->killed_errno()); @@ -1446,20 +1531,36 @@ static bool init_param_array(Prepared_statement *stmt) /* - Parse the query and send the total number of parameters - and resultset metadata information back to client (if any), - without executing the query i.e. without any log/disk - writes. This will allow the queries to be re-executed - without re-parsing during execute. - - If parameter markers are found in the query, then store - the information using Item_param along with maintaining a - list in lex->param_array, so that a fast and direct - retrieval can be made without going through all field - items. + Given a query string with parameter markers, create a Prepared Statement + from it and send PS info back to the client. + + SYNOPSIS + mysql_stmt_prepare() + packet query to be prepared + packet_length query string length, including ignored trailing NULL or + quote char. + name NULL or statement name. For unnamed statements binary PS + protocol is used, for named statements text protocol is + used. + RETURN + 0 OK, statement prepared successfully + other Error + + NOTES + This function parses the query and sends the total number of parameters + and resultset metadata information back to client (if any), without + executing the query i.e. without any log/disk writes. This allows the + queries to be re-executed without re-parsing during execute. + + If parameter markers are found in the query, then store the information + using Item_param along with maintaining a list in lex->param_array, so + that a fast and direct retrieval can be made without going through all + field items. + */ -void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) +int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, + LEX_STRING *name) { LEX *lex; Prepared_statement *stmt= new Prepared_statement(thd); @@ -1471,14 +1572,26 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) if (stmt == 0) { send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_VOID_RETURN; + DBUG_RETURN(1); + } + + if (name) + { + stmt->name.length= name->length; + if (!(stmt->name.str= memdup_root(&stmt->mem_root, (char*)name->str, + name->length))) + { + delete stmt; + send_error(thd, ER_OUT_OF_RESOURCES); + DBUG_RETURN(1); + } } if (thd->stmt_map.insert(stmt)) { delete stmt; send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_VOID_RETURN; + DBUG_RETURN(1); } thd->stmt_backup.set_statement(thd); @@ -1495,7 +1608,7 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_VOID_RETURN; + DBUG_RETURN(1); } mysql_log.write(thd, COM_PREPARE, "%s", packet); @@ -1507,7 +1620,7 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) error= yyparse((void *)thd) || thd->is_fatal_error || init_param_array(stmt) || - send_prepare_results(stmt); + send_prepare_results(stmt, test(name)); /* restore to WAIT_PRIOR: QUERY_PRIOR is set inside alloc_query */ if (!(specialflag & SPECIAL_NO_PRIOR)) @@ -1530,9 +1643,14 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) { /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); + stmt= NULL; /* error is sent inside yyparse/send_prepare_results */ } - DBUG_VOID_RETURN; + else + stmt->setup_set_params(); + + DBUG_RETURN(!stmt); + } /* Reinit statement before execution */ @@ -1545,6 +1663,9 @@ void reset_stmt_for_execute(THD *thd, LEX *lex) { if (!sl->first_execution) { + /* remove option which was put by mysql_explain_union() */ + sl->options&= ~SELECT_DESCRIBE; + /* Copy WHERE clause pointers to avoid damaging they by optimisation */ @@ -1609,13 +1730,21 @@ static void reset_stmt_params(Prepared_statement *stmt) Executes previously prepared query. If there is any parameters, then replace markers with the data supplied from client, and then execute the query. - SYNOPSYS + SYNOPSIS mysql_stmt_execute() + thd Current thread + packet Query string + packet_length Query string length, including terminator character. */ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) { ulong stmt_id= uint4korr(packet); + /* + Query text for binary log, or empty string if the query is not put into + binary log. + */ + String expanded_query; #ifndef EMBEDDED_LIBRARY uchar *packet_end= (uchar *) packet + packet_length - 1; #endif @@ -1623,7 +1752,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) DBUG_ENTER("mysql_stmt_execute"); packet+= 9; /* stmt_id + 5 bytes of flags */ - + if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute", SEND_ERROR))) DBUG_VOID_RETURN; @@ -1637,15 +1766,13 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) DBUG_VOID_RETURN; } - thd->stmt_backup.set_statement(thd); - thd->set_statement(stmt); - reset_stmt_for_execute(thd, stmt->lex); #ifndef EMBEDDED_LIBRARY if (stmt->param_count) { uchar *null_array= (uchar *) packet; if (setup_conversion_functions(stmt, (uchar **) &packet, packet_end) || - stmt->set_params(stmt, null_array, (uchar *) packet, packet_end)) + stmt->set_params(stmt, null_array, (uchar *) packet, packet_end, + &expanded_query)) goto set_params_data_err; } #else @@ -1654,55 +1781,126 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) we set params, and also we don't need to parse packet. So we do it in one function. */ - if (stmt->param_count && stmt->set_params_data(stmt)) + if (stmt->param_count && stmt->set_params_data(stmt, &expanded_query)) goto set_params_data_err; #endif - - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),QUERY_PRIOR); - - /* - TODO: - Also, have checks on basic executions such as mysql_insert(), - mysql_delete(), mysql_update() and mysql_select() to not to - have re-check on setup_* and other things .. - */ thd->current_arena= stmt; thd->protocol= &thd->protocol_prep; // Switch to binary protocol - mysql_execute_command(thd); - thd->lex->unit.cleanup(); + execute_stmt(thd, stmt, &expanded_query, true); thd->protocol= &thd->protocol_simple; // Use normal protocol thd->current_arena= 0; + DBUG_VOID_RETURN; - if (!(specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(), WAIT_PRIOR); - - cleanup_items(stmt->free_list); +set_params_data_err: reset_stmt_params(stmt); - close_thread_tables(thd); // to close derived tables - thd->set_statement(&thd->stmt_backup); + my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute"); + send_error(thd); + DBUG_VOID_RETURN; +} + + +/* + Execute prepared statement using parameter values from + lex->prepared_stmt_params and send result to the client using text protocol. +*/ + +void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name) +{ + Prepared_statement *stmt; /* - Free Items that were created during this execution of the PS by query - optimizer. + Query text for binary log, or empty string if the query is not put into + binary log. */ - free_items(thd->free_list); + String expanded_query; + DBUG_ENTER("mysql_sql_stmt_execute"); + + if (!(stmt= (Prepared_statement*)thd->stmt_map.find_by_name(stmt_name))) + { + my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_name->length, + stmt_name->str, "EXECUTE"); + send_error(thd); + DBUG_VOID_RETURN; + } + + if (stmt->param_count != thd->lex->prepared_stmt_params.elements) + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); + send_error(thd); + DBUG_VOID_RETURN; + } + + thd->free_list= NULL; + thd->stmt_backup.set_statement(thd); + thd->set_statement(stmt); + if (stmt->set_params_from_vars(stmt, + thd->stmt_backup.lex->prepared_stmt_params, + &expanded_query)) + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); + send_error(thd); + } + execute_stmt(thd, stmt, &expanded_query, false); DBUG_VOID_RETURN; +} -set_params_data_err: + +/* + Execute prepared statement. + SYNOPSIS + execute_stmt() + thd Current thread + stmt Statement to execute + expanded_query If binary log is enabled, query string with parameter + placeholders replaced with actual values. Otherwise empty + string. + NOTES + Caller must set parameter values and thd::protocol. + thd->free_list is assumed to be garbage. +*/ + +static void execute_stmt(THD *thd, Prepared_statement *stmt, + String *expanded_query, bool set_context) +{ + DBUG_ENTER("execute_stmt"); + if (set_context) + { + thd->free_list= NULL; + thd->stmt_backup.set_statement(thd); + thd->set_statement(stmt); + } + reset_stmt_for_execute(stmt); + + if (expanded_query->length() && + alloc_query(thd, (char *)expanded_query->ptr(), + expanded_query->length()+1)) + { + my_error(ER_OUTOFMEMORY, 0, expanded_query->length()); + DBUG_VOID_RETURN; + } + + if (!(specialflag & SPECIAL_NO_PRIOR)) + my_pthread_setprio(pthread_self(),QUERY_PRIOR); + mysql_execute_command(thd); + thd->lex->unit.cleanup(); + if (!(specialflag & SPECIAL_NO_PRIOR)) + my_pthread_setprio(pthread_self(), WAIT_PRIOR); + + /* Free Items that were created during this execution of the PS. */ + free_items(thd->free_list); + cleanup_items(stmt->free_list); reset_stmt_params(stmt); + close_thread_tables(thd); // to close derived tables thd->set_statement(&thd->stmt_backup); - my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute"); - send_error(thd); DBUG_VOID_RETURN; } /* - Reset a prepared statement in case there was a recoverable error. + Reset a prepared statement in case there was a recoverable error. SYNOPSIS mysql_stmt_reset() - thd Thread handle - packet Packet with stmt id + thd Thread handle + packet Packet with stmt id DESCRIPTION This function resets statement to the state it was right after prepare. @@ -1842,8 +2040,14 @@ Prepared_statement::Prepared_statement(THD *thd_arg) get_longdata_error(0) { *last_error= '\0'; - if (mysql_bin_log.is_open()) +} + +void Prepared_statement::setup_set_params() +{ + /* Setup binary logging */ + if (mysql_bin_log.is_open() && is_update_query(lex->sql_command)) { + set_params_from_vars= insert_params_from_vars_with_log; #ifndef EMBEDDED_LIBRARY set_params= insert_params_withlog; #else @@ -1851,14 +2055,16 @@ Prepared_statement::Prepared_statement(THD *thd_arg) #endif } else + { + set_params_from_vars= insert_params_from_vars; #ifndef EMBEDDED_LIBRARY set_params= insert_params; #else set_params_data= emb_insert_params; #endif + } } - Prepared_statement::~Prepared_statement() { free_items(free_list); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e28ee52c00f..05676f9058a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -148,14 +148,15 @@ static int remove_duplicates(JOIN *join,TABLE *entry,List<Item> &fields, Item *having); static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field, ulong offset,Item *having); -static int remove_dup_with_hash_index(THD *thd, TABLE *table, +static int remove_dup_with_hash_index(THD *thd,TABLE *table, uint field_count, Field **first_field, ulong key_length,Item *having); static int join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count); static ulong used_blob_length(CACHE_FIELD **ptr); static bool store_record_in_cache(JOIN_CACHE *cache); -static void reset_cache(JOIN_CACHE *cache); +static void reset_cache_read(JOIN_CACHE *cache); +static void reset_cache_write(JOIN_CACHE *cache); static void read_cached_record(JOIN_TAB *tab); static bool cmp_buffer_with_ref(JOIN_TAB *tab); static bool setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields, @@ -643,7 +644,6 @@ JOIN::optimize() { zero_result_cause= "no matching row in const table"; DBUG_PRINT("error",("Error: %s", zero_result_cause)); - select_options= 0; //TODO why option in return_zero_rows was droped error= 0; DBUG_RETURN(0); } @@ -657,22 +657,8 @@ JOIN::optimize() } if (const_tables && !thd->locked_tables && !(select_options & SELECT_NO_UNLOCK)) - { - TABLE **curr_table, **end; - for (curr_table= table, end=curr_table + const_tables ; - curr_table != end; - curr_table++) - { - /* BDB tables require that we call index_end() before doing an unlock */ - if ((*curr_table)->key_read) - { - (*curr_table)->key_read=0; - (*curr_table)->file->extra(HA_EXTRA_NO_KEYREAD); - } - (*curr_table)->file->index_end(); - } mysql_unlock_some_tables(thd, table, const_tables); - } + if (!conds && outer_join) { /* Handle the case where we have an OUTER JOIN without a WHERE */ @@ -977,7 +963,7 @@ JOIN::optimize() If having is not handled here, it will be checked before the row is sent to the client. */ - if (having && + if (tmp_having && (sort_and_group || (exec_tmp_table1->distinct && !group_list))) having= tmp_having; @@ -1127,12 +1113,14 @@ JOIN::exec() DBUG_ENTER("JOIN::exec"); error= 0; - thd->limit_found_rows= thd->examined_row_count= 0; if (procedure) { if (procedure->change_columns(fields_list) || result->prepare(fields_list, unit)) + { + thd->limit_found_rows= thd->examined_row_count= 0; DBUG_VOID_RETURN; + } } if (!tables_list) @@ -1158,8 +1146,10 @@ JOIN::exec() else error=(int) result->send_eof(); } + thd->limit_found_rows= thd->examined_row_count= 0; DBUG_VOID_RETURN; } + thd->limit_found_rows= thd->examined_row_count= 0; if (zero_result_cause) { @@ -1578,6 +1568,7 @@ JOIN::cleanup() } } tmp_join->tmp_join= 0; + tmp_table_param.copy_field=0; DBUG_RETURN(tmp_join->cleanup()); } @@ -2332,12 +2323,13 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, case Item_func::OPTIMIZE_NONE: break; case Item_func::OPTIMIZE_KEY: - // BETWEEN or IN + // BETWEEN, IN, NOT if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM && !(cond_func->used_tables() & OUTER_REF_TABLE_BIT)) add_key_field(key_fields,*and_level,cond_func, - ((Item_field*) (cond_func->key_item()->real_item()))-> - field, 0, + ((Item_field*)(cond_func->key_item()->real_item()))->field, + cond_func->argument_count() == 2 && + cond_func->functype() == Item_func::IN_FUNC, cond_func->arguments()+1, cond_func->argument_count()-1, usable_tables); break; @@ -4848,7 +4840,6 @@ make_join_readinfo(JOIN *join, uint options) } delete tab->quick; tab->quick=0; - table->file->index_init(tab->ref.key); tab->read_first_record= join_read_key; tab->read_record.read_record= join_no_more_records; if (table->used_keys.is_set(tab->ref.key) && @@ -4868,7 +4859,6 @@ make_join_readinfo(JOIN *join, uint options) } delete tab->quick; tab->quick=0; - table->file->index_init(tab->ref.key); if (table->used_keys.is_set(tab->ref.key) && !table->no_keyread) { @@ -4888,7 +4878,6 @@ make_join_readinfo(JOIN *join, uint options) break; case JT_FT: table->status=STATUS_NO_RECORD; - table->file->index_init(tab->ref.key); tab->read_first_record= join_ft_read_first; tab->read_record.read_record= join_ft_read_next; break; @@ -4958,7 +4947,6 @@ make_join_readinfo(JOIN *join, uint options) !(tab->select && tab->select->quick)) { // Only read index tree tab->index=find_shortest_key(table, & table->used_keys); - tab->table->file->index_init(tab->index); tab->read_first_record= join_read_first; tab->type=JT_NEXT; // Read with index_first / index_next } @@ -5032,9 +5020,7 @@ void JOIN_TAB::cleanup() table->key_read= 0; table->file->extra(HA_EXTRA_NO_KEYREAD); } - /* Don't free index if we are using read_record */ - if (!read_record.table) - table->file->index_end(); + table->file->ha_index_or_rnd_end(); /* We need to reset this for next select (Tested in part_of_refkey) @@ -5060,7 +5046,9 @@ void JOIN::join_free(bool full) { JOIN_TAB *tab,*end; - DBUG_ENTER("join_free"); + DBUG_ENTER("JOIN::join_free"); + + full= full || !select_lex->uncacheable; if (table) { @@ -5073,36 +5061,49 @@ JOIN::join_free(bool full) free_io_cache(table[const_tables]); filesort_free_buffers(table[const_tables]); } - if (!full && select_lex->uncacheable) + + for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit(); unit; + unit= unit->next_unit()) { - for (tab= join_tab, end= tab+tables; tab != end; tab++) - { - if (tab->table) - { - /* Don't free index if we are using read_record */ - if (!tab->read_record.table) - tab->table->file->index_end(); - } - } + JOIN *join; + for (SELECT_LEX *sl= unit->first_select_in_union(); sl; + sl= sl->next_select()) + if ((join= sl->join)) + join->join_free(full); } - else + + if (full) { for (tab= join_tab, end= tab+tables; tab != end; tab++) tab->cleanup(); table= 0; } + else + { + for (tab= join_tab, end= tab+tables; tab != end; tab++) + { + if (tab->table) + tab->table->file->ha_index_or_rnd_end(); + } + } } + /* We are not using tables anymore Unlock all tables. We may be in an INSERT .... SELECT statement. */ - if ((full || !select_lex->uncacheable) && - lock && thd->lock && - !(select_options & SELECT_NO_UNLOCK)) + if (full && lock && thd->lock && !(select_options & SELECT_NO_UNLOCK) && + !select_lex->subquery_in_having) { - mysql_unlock_read_tables(thd, lock);// Don't free join->lock - lock=0; + // TODO: unlock tables even if the join isn't top level select in the tree + if (select_lex == (thd->lex->unit.fake_select_lex ? + thd->lex->unit.fake_select_lex : &thd->lex->select_lex)) + { + mysql_unlock_read_tables(thd, lock); // Don't free join->lock + lock=0; + } } + if (full) { group_fields.delete_elements(); @@ -5324,6 +5325,8 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables, DBUG_RETURN(0); } + join->join_free(0); + if (send_row) { for (TABLE_LIST *table=tables; table ; table=table->next) @@ -5341,12 +5344,6 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables, item->no_rows_in_result(); result->send_data(fields); } - if (tables) // Not from do_select() - { - /* Close open cursors */ - for (TABLE_LIST *table=tables; table ; table=table->next) - table->table->file->index_end(); - } result->send_eof(); // Should be safe } /* Update results for FOUND_ROWS */ @@ -6419,6 +6416,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, table->db_low_byte_first=1; // True for HEAP and MyISAM table->temp_pool_slot = temp_pool_slot; table->copy_blobs= 1; + table->in_use= thd; table->keys_for_keyread.init(); table->keys_in_use.init(); table->read_only_keys.init(); @@ -6581,6 +6579,10 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, recinfo->length=null_pack_length; recinfo++; bfill(null_flags,null_pack_length,255); // Set null fields + + table->null_flags= (uchar*) table->record[0]; + table->null_fields= null_count+ hidden_null_count; + table->null_bytes= null_pack_length; } null_count= (blob_count == 0) ? 1 : 0; hidden_field_count=param->hidden_field_count; @@ -6644,7 +6646,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, param->copy_field_end=copy; param->recinfo=recinfo; - store_record(table,default_values); // Make empty default record + store_record(table,default_values); // Make empty default record if (thd->variables.tmp_table_size == ~(ulong) 0) // No limit table->max_rows= ~(ha_rows) 0; @@ -6996,8 +6998,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, goto err1; if (table->file->indexes_are_disabled()) new_table.file->disable_indexes(HA_KEY_SWITCH_ALL); - table->file->index_end(); - table->file->rnd_init(); + table->file->ha_index_or_rnd_end(); + table->file->ha_rnd_init(1); if (table->no_rows) { new_table.file->extra(HA_EXTRA_NO_ROWS); @@ -7019,7 +7021,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, } /* remove heap table and change to use myisam table */ - (void) table->file->rnd_end(); + (void) table->file->ha_rnd_end(); (void) table->file->close(); (void) table->file->delete_table(table->real_name); delete table->file; @@ -7033,7 +7035,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, err: DBUG_PRINT("error",("Got error: %d",write_err)); table->file->print_error(error,MYF(0)); // Give table is full error - (void) table->file->rnd_end(); + (void) table->file->ha_rnd_end(); (void) new_table.file->close(); err1: new_table.file->delete_table(new_table.real_name); @@ -7082,7 +7084,8 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) { DBUG_PRINT("info",("Using end_update")); end_select=end_update; - table->file->index_init(0); + if (!table->file->inited) + table->file->ha_index_init(0); } else { @@ -7160,9 +7163,9 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) my_errno= tmp; error= -1; } - if ((tmp=table->file->index_end())) + if ((tmp=table->file->ha_index_or_rnd_end())) { - DBUG_PRINT("error",("index_end() failed")); + DBUG_PRINT("error",("ha_index_or_rnd_end() failed")); my_errno= tmp; error= -1; } @@ -7541,8 +7544,7 @@ flush_cached_records(JOIN *join,JOIN_TAB *join_tab,bool skip_last) /* read through all records */ if ((error=join_init_read_record(join_tab))) { - reset_cache(&join_tab->cache); - join_tab->cache.records=0; join_tab->cache.ptr_record= (uint) ~0; + reset_cache_write(&join_tab->cache); return -error; /* No records or error */ } @@ -7565,21 +7567,23 @@ flush_cached_records(JOIN *join,JOIN_TAB *join_tab,bool skip_last) !join_tab->cache.select->skip_record())) { uint i; - reset_cache(&join_tab->cache); + reset_cache_read(&join_tab->cache); for (i=(join_tab->cache.records- (skip_last ? 1 : 0)) ; i-- > 0 ;) { read_cached_record(join_tab); if (!select || !select->skip_record()) if ((error=(join_tab->next_select)(join,join_tab+1,0)) < 0) + { + reset_cache_write(&join_tab->cache); return error; /* purecov: inspected */ + } } } } while (!(error=info->read_record(info))); if (skip_last) read_cached_record(join_tab); // Restore current record - reset_cache(&join_tab->cache); - join_tab->cache.records=0; join_tab->cache.ptr_record= (uint) ~0; + reset_cache_write(&join_tab->cache); if (error > 0) // Fatal error return -1; /* purecov: inspected */ for (JOIN_TAB *tmp2=join->join_tab; tmp2 != join_tab ; tmp2++) @@ -7650,7 +7654,8 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos) else { if (!table->key_read && table->used_keys.is_set(tab->ref.key) && - !table->no_keyread) + !table->no_keyread && + (int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY) { table->key_read=1; table->file->extra(HA_EXTRA_KEYREAD); @@ -7663,6 +7668,11 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos) if (!table->outer_join || error > 0) DBUG_RETURN(error); } + if (table->key_read) + { + table->key_read=0; + table->file->extra(HA_EXTRA_NO_KEYREAD); + } } if (tab->on_expr && !table->null_row) { @@ -7741,6 +7751,8 @@ join_read_key(JOIN_TAB *tab) int error; TABLE *table= tab->table; + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); if (cmp_buffer_with_ref(tab) || (table->status & (STATUS_GARBAGE | STATUS_NO_PARENT | STATUS_NULL_ROW))) { @@ -7766,6 +7778,8 @@ join_read_always_key(JOIN_TAB *tab) int error; TABLE *table= tab->table; + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); if (cp_buffer_from_ref(&tab->ref)) return -1; if ((error=table->file->index_read(table->record[0], @@ -7791,6 +7805,8 @@ join_read_last_key(JOIN_TAB *tab) int error; TABLE *table= tab->table; + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); if (cp_buffer_from_ref(&tab->ref)) return -1; if ((error=table->file->index_read_last(table->record[0], @@ -7899,6 +7915,8 @@ join_read_first(JOIN_TAB *tab) tab->read_record.file=table->file; tab->read_record.index=tab->index; tab->read_record.record=table->record[0]; + if (!table->file->inited) + table->file->ha_index_init(tab->index); if ((error=tab->table->file->index_first(tab->table->record[0]))) { if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE) @@ -7936,6 +7954,8 @@ join_read_last(JOIN_TAB *tab) tab->read_record.file=table->file; tab->read_record.index=tab->index; tab->read_record.record=table->record[0]; + if (!table->file->inited) + table->file->ha_index_init(tab->index); if ((error= tab->table->file->index_last(tab->table->record[0]))) return report_error(table, error); return 0; @@ -7958,6 +7978,8 @@ join_ft_read_first(JOIN_TAB *tab) int error; TABLE *table= tab->table; + if (!table->file->inited) + table->file->ha_index_init(tab->ref.key); #if NOT_USED_YET if (cp_buffer_from_ref(&tab->ref)) // as ft-key doesn't use store_key's return -1; // see also FT_SELECT::init() @@ -8048,7 +8070,8 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), if ((join->tables == 1) && !join->tmp_table && !join->sort_and_group && !join->send_group_parts && !join->having && !jt->select_cond && !(jt->select && jt->select->quick) && - !(jt->table->file->table_flags() & HA_NOT_EXACT_COUNT)) + !(jt->table->file->table_flags() & HA_NOT_EXACT_COUNT) && + (jt->ref.key < 0)) { /* Join over all rows in table; Return number of found rows */ TABLE *table=jt->table; @@ -8274,7 +8297,6 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), if (item->maybe_null) group->buff[-1]=item->null_value ? 1 : 0; } - // table->file->index_init(0); if (!table->file->index_read(table->record[1], join->tmp_table_param.group_buff,0, HA_READ_KEY_EXACT)) @@ -8305,7 +8327,7 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), error, 0)) DBUG_RETURN(-1); // Not a table_is_full error /* Change method to update rows */ - table->file->index_init(0); + table->file->ha_index_init(0); join->join_tab[join->tables-1].next_select=end_unique_update; } join->send_records++; @@ -8814,10 +8836,10 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, if (tab->ref.key >= 0) { tab->ref.key= new_ref_key; - table->file->index_init(new_ref_key); } else { + select->quick->file->ha_index_end(); /* We have verified above that select->quick is not index_merge quick select. @@ -8844,7 +8866,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, if (!select->quick->reverse_sorted()) { int quick_type= select->quick->get_type(); - if (table->file->index_flags(ref_key) & HA_NOT_READ_PREFIX_LAST || + if (!(table->file->index_flags(ref_key) & HA_READ_PREV) || quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE || quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT || quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION) @@ -8870,7 +8892,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, Use a traversal function that starts by reading the last row with key part (A) and then traverse the index backwards. */ - if (table->file->index_flags(ref_key) & HA_NOT_READ_PREFIX_LAST) + if (!(table->file->index_flags(ref_key) & HA_READ_PREV)) DBUG_RETURN(0); // Use filesort tab->read_first_record= join_read_last_key; tab->read_record.read_record= join_read_prev_same; @@ -8924,7 +8946,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, tab->index=nr; tab->read_first_record= (flag > 0 ? join_read_first: join_read_last); - table->file->index_init(nr); tab->type=JT_NEXT; // Read with index_first(), index_next() if (table->used_keys.is_set(nr)) { @@ -9190,7 +9211,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, org_record=(char*) (record=table->record[0])+offset; new_record=(char*) table->record[1]+offset; - file->rnd_init(); + file->ha_rnd_init(1); error=file->rnd_next(record); for (;;) { @@ -9302,7 +9323,7 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, (*field_length++)= (*ptr)->pack_length(); } - file->rnd_init(); + file->ha_rnd_init(1); key_pos=key_buffer; for (;;) { @@ -9348,14 +9369,14 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, my_free((char*) key_buffer,MYF(0)); hash_free(&hash); file->extra(HA_EXTRA_NO_CACHE); - (void) file->rnd_end(); + (void) file->ha_rnd_end(); DBUG_RETURN(0); err: my_free((char*) key_buffer,MYF(0)); hash_free(&hash); file->extra(HA_EXTRA_NO_CACHE); - (void) file->rnd_end(); + (void) file->ha_rnd_end(); if (error) file->print_error(error,MYF(0)); DBUG_RETURN(1); @@ -9482,7 +9503,6 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) } } - cache->records=0; cache->ptr_record= (uint) ~0; cache->length=length+blobs*sizeof(char*); cache->blobs=blobs; *blob_ptr=0; /* End sequentel */ @@ -9490,7 +9510,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) if (!(cache->buff=(uchar*) my_malloc(size,MYF(0)))) DBUG_RETURN(1); /* Don't use cache */ /* purecov: inspected */ cache->end=cache->buff+size; - reset_cache(cache); + reset_cache_write(cache); DBUG_RETURN(0); } @@ -9574,13 +9594,21 @@ store_record_in_cache(JOIN_CACHE *cache) static void -reset_cache(JOIN_CACHE *cache) +reset_cache_read(JOIN_CACHE *cache) { cache->record_nr=0; cache->pos=cache->buff; } +static void reset_cache_write(JOIN_CACHE *cache) +{ + reset_cache_read(cache); + cache->records= 0; + cache->ptr_record= (uint) ~0; +} + + static void read_cached_record(JOIN_TAB *tab) { @@ -10029,10 +10057,11 @@ calc_group_buffer(JOIN *join,ORDER *group) join->tmp_table_param.group_null_parts=null_parts; } + /* - alloc group fields or take prepared (chached) + allocate group fields or take prepared (cached) - SYNOPSYS + SYNOPSIS make_group_fields() main_join - join of current select curr_join - current join (join of current select or temporary copy of it) @@ -10045,22 +10074,21 @@ calc_group_buffer(JOIN *join,ORDER *group) static bool make_group_fields(JOIN *main_join, JOIN *curr_join) { - if (main_join->group_fields_cache.elements) - { - curr_join->group_fields= main_join->group_fields_cache; - curr_join->sort_and_group= 1; - } - else - { - if (alloc_group_fields(curr_join, curr_join->group_list)) - { - return (1); - } - main_join->group_fields_cache= curr_join->group_fields; - } - return (0); + if (main_join->group_fields_cache.elements) + { + curr_join->group_fields= main_join->group_fields_cache; + curr_join->sort_and_group= 1; + } + else + { + if (alloc_group_fields(curr_join, curr_join->group_list)) + return (1); + main_join->group_fields_cache= curr_join->group_fields; + } + return (0); } + /* Get a list of buffers for saveing last group Groups are saved in reverse order for easyer check loop @@ -10101,7 +10129,6 @@ test_if_group_changed(List<Item_buff> &list) } - /* Setup copy_fields to save fields at start of new group diff --git a/sql/sql_show.cc b/sql/sql_show.cc index e481a961288..3e99704e80c 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -473,6 +473,8 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) field_list.push_back(item=new Item_empty_string("Name",NAME_LEN)); field_list.push_back(item=new Item_empty_string("Engine",10)); item->maybe_null=1; + field_list.push_back(item=new Item_int("Version", (longlong) 0, 21)); + item->maybe_null=1; field_list.push_back(item=new Item_empty_string("Row_format",10)); item->maybe_null=1; field_list.push_back(item=new Item_int("Rows",(longlong) 1,21)); @@ -529,11 +531,11 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) } else { - struct tm tm_tmp; const char *str; handler *file=table->file; file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK); protocol->store(file->table_type(), system_charset_info); + protocol->store((ulonglong) table->frm_version); str= ((table->db_options_in_use & HA_OPTION_COMPRESS_RECORD) ? "Compressed" : (table->db_options_in_use & HA_OPTION_PACK_RECORD) ? @@ -562,24 +564,21 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) protocol->store_null(); else { - localtime_r(&file->create_time,&tm_tmp); - localtime_to_TIME(&time, &tm_tmp); + thd->variables.time_zone->gmt_sec_to_TIME(&time, file->create_time); protocol->store(&time); } if (!file->update_time) protocol->store_null(); else { - localtime_r(&file->update_time,&tm_tmp); - localtime_to_TIME(&time, &tm_tmp); + thd->variables.time_zone->gmt_sec_to_TIME(&time, file->update_time); protocol->store(&time); } if (!file->check_time) protocol->store_null(); else { - localtime_r(&file->check_time,&tm_tmp); - localtime_to_TIME(&time, &tm_tmp); + thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time); protocol->store(&time); } str= (table->table_charset ? table->table_charset->name : "default"); @@ -1251,7 +1250,7 @@ store_create_info(THD *thd, TABLE *table, String *packet) packet->append(' '); // check for surprises from the previous call to Field::sql_type() if (type.ptr() != tmp) - type.set(tmp, sizeof(tmp),&my_charset_bin); + type.set(tmp, sizeof(tmp), system_charset_info); field->sql_type(type); packet->append(type.ptr(), type.length(), system_charset_info); @@ -1540,13 +1539,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) while ((tmp=it++)) { struct st_my_thread_var *mysys_var; -#ifndef EMBEDDED_LIBRARY - if ((tmp->net.vio || tmp->system_thread) && + if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp->user && !strcmp(tmp->user,user)))) -#else - if (tmp->system_thread && - (!user || (tmp->user && !strcmp(tmp->user,user)))) -#endif { thread_info *thd_info=new thread_info; diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 4d85438b03f..ba9431f27c4 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -24,7 +24,6 @@ #include <my_sys.h> #include <m_string.h> #include <m_ctype.h> -#include <assert.h> #ifdef HAVE_FCONVERT #include <floatingpoint.h> #endif @@ -371,7 +370,7 @@ bool String::copy(const char *str, uint32 arg_length, bool String::set_ascii(const char *str, uint32 arg_length) { - if (!(str_charset->state & MY_CS_NONTEXT)) + if (str_charset->mbminlen == 1) { set(str, arg_length, str_charset); return 0; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d05b5a6cbc7..48bd9e572b0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -191,7 +191,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_closeall(thd, table); + mysql_ha_close(thd, table, /*dont_send_ok*/ 1, /*dont_lock*/ 1); if (!close_temporary_table(thd, db, table->real_name)) { tmp_table_deleted=1; @@ -254,12 +254,23 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } } thd->tmp_table_used= tmp_table_deleted; - if (some_tables_deleted || tmp_table_deleted) + error= 0; + if (wrong_tables.length()) + { + if (!foreign_key_error) + my_error(ER_BAD_TABLE_ERROR,MYF(0), wrong_tables.c_ptr()); + else + my_error(ER_ROW_IS_REFERENCED, MYF(0)); + error= 1; + } + + if (some_tables_deleted || tmp_table_deleted || !error) { query_cache_invalidate3(thd, tables, 0); if (!dont_log_query && mysql_bin_log.is_open()) { - thd->clear_error(); + if (!error) + thd->clear_error(); Query_log_event qinfo(thd, thd->query, thd->query_length, tmp_table_deleted && !some_tables_deleted); mysql_bin_log.write(&qinfo); @@ -267,15 +278,6 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } unlock_table_names(thd, tables); - error= 0; - if (wrong_tables.length()) - { - if (!foreign_key_error) - my_error(ER_BAD_TABLE_ERROR,MYF(0),wrong_tables.c_ptr()); - else - my_error(ER_ROW_IS_REFERENCED,MYF(0)); - error= 1; - } DBUG_RETURN(error); } @@ -525,7 +527,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, break; case FIELD_TYPE_GEOMETRY: #ifdef HAVE_SPATIAL - if (!(file->table_flags() & HA_HAS_GEOMETRY)) + if (!(file->table_flags() & HA_CAN_GEOMETRY)) { my_printf_error(ER_CHECK_NOT_IMPLEMENTED, ER(ER_CHECK_NOT_IMPLEMENTED), MYF(0), "GEOMETRY"); @@ -663,7 +665,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, continue; } (*key_count)++; - tmp=max(file->max_key_parts(),MAX_REF_PARTS); + tmp=file->max_key_parts(); if (key->columns.elements > tmp) { my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp); @@ -715,7 +717,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, DBUG_RETURN(-1); } } - tmp=min(file->max_keys(), MAX_KEY); + tmp=file->max_keys(); if (*key_count > tmp) { my_error(ER_TOO_MANY_KEYS,MYF(0),tmp); @@ -852,7 +854,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, sql_field->sql_type != FIELD_TYPE_VAR_STRING && !f_is_blob(sql_field->pack_flag)) || sql_field->charset == &my_charset_bin || - sql_field->charset->state & MY_CS_NONTEXT || // ucs2 doesn't work yet + sql_field->charset->mbminlen > 1 || // ucs2 doesn't work yet (ft_key_charset && sql_field->charset != ft_key_charset)) { my_printf_error(ER_BAD_FT_COLUMN,ER(ER_BAD_FT_COLUMN),MYF(0), @@ -875,7 +877,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (f_is_blob(sql_field->pack_flag)) { - if (!(file->table_flags() & HA_BLOB_KEY)) + if (!(file->table_flags() & HA_CAN_INDEX_BLOBS)) { my_printf_error(ER_BLOB_USED_AS_KEY,ER(ER_BLOB_USED_AS_KEY),MYF(0), column->field_name); @@ -912,7 +914,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } else key_info->flags|= HA_NULL_PART_KEY; - if (!(file->table_flags() & HA_NULL_KEY)) + if (!(file->table_flags() & HA_NULL_IN_KEY)) { my_printf_error(ER_NULL_COLUMN_IN_INDEX,ER(ER_NULL_COLUMN_IN_INDEX), MYF(0),column->field_name); @@ -1044,7 +1046,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (!(key_info->flags & HA_NULL_PART_KEY)) unique_key=1; key_info->key_length=(uint16) key_length; - uint max_key_length= min(file->max_key_length(), MAX_KEY_LENGTH); + uint max_key_length= file->max_key_length(); if (key_length > max_key_length && key->type != Key::FULLTEXT) { my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length); @@ -1136,12 +1138,21 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, alias= table_case_name(create_info, table_name); file=get_new_handler((TABLE*) 0, create_info->db_type); +#ifdef NOT_USED + /* + if there is a technical reason for a handler not to have support + for temp. tables this code can be re-enabled. + Otherwise, if a handler author has a wish to prohibit usage of + temporary tables for his handler he should implement a check in + ::create() method + */ if ((create_info->options & HA_LEX_CREATE_TMP_TABLE) && (file->table_flags() & HA_NO_TEMP_TABLES)) { my_error(ER_ILLEGAL_HA,MYF(0),table_name); DBUG_RETURN(-1); } +#endif if (mysql_prepare_table(thd, create_info, fields, keys, tmp_table, db_options, file, @@ -1707,7 +1718,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, if (protocol->send_fields(&field_list, 1)) DBUG_RETURN(-1); - mysql_ha_closeall(thd, tables); + mysql_ha_close(thd, tables, /*dont_send_ok*/ 1, /*dont_lock*/ 1); for (table = tables; table; table = table->next) { char table_name[NAME_LEN*2+2]; @@ -1793,6 +1804,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store(table_name, system_charset_info); protocol->store(operator_name, system_charset_info); +send_result_message: + + DBUG_PRINT("info", ("result_code: %d", result_code)); switch (result_code) { case HA_ADMIN_NOT_IMPLEMENTED: { @@ -1836,6 +1850,29 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store("Invalid argument",16, system_charset_info); break; + case HA_ADMIN_TRY_ALTER: + { + /* + This is currently used only by InnoDB. ha_innobase::optimize() answers + "try with alter", so here we close the table, do an ALTER TABLE, + reopen the table and do ha_innobase::analyze() on it. + */ + close_thread_tables(thd); + TABLE_LIST *save_next= table->next; + table->next= 0; + result_code= mysql_recreate_table(thd, table, 0); + close_thread_tables(thd); + if (!result_code) // recreation went ok + { + if ((table->table= open_ltable(thd, table, lock_type)) && + ((result_code= table->table->file->analyze(thd, check_opt)) > 0)) + result_code= 0; // analyze went ok + } + result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK; + table->next= save_next; + goto send_result_message; + } + default: // Probably HA_ADMIN_INTERNAL_ERROR protocol->store("error", 5, system_charset_info); protocol->store("Unknown - internal error during operation", 41 @@ -2207,7 +2244,7 @@ int mysql_discard_or_import_tablespace(THD *thd, thd->tablespace_op=TRUE; /* we set this flag so that ha_innobase::open and ::external_lock() do not complain when we lock the table */ - mysql_ha_closeall(thd, table_list); + mysql_ha_close(thd, table_list, /*dont_send_ok*/ 1, /*dont_lock*/ 1); if (!(table=open_ltable(thd,table_list,TL_WRITE))) { @@ -2463,7 +2500,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, List<create_field> &fields, List<Key> &keys, uint order_num, ORDER *order, enum enum_duplicates handle_duplicates, - ALTER_INFO *alter_info) + ALTER_INFO *alter_info, bool do_send_ok) { TABLE *table,*new_table; int error; @@ -2485,7 +2522,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, new_db= db; used_fields=create_info->used_fields; - mysql_ha_closeall(thd, table_list); + mysql_ha_close(thd, table_list, /*dont_send_ok*/ 1, /*dont_lock*/ 1); /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */ if (alter_info->tablespace_op != NO_TABLESPACE_OP) @@ -2540,7 +2577,10 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, } } else - new_alias= new_name= table_name; + { + new_alias= (lower_case_table_names == 2) ? alias : table_name; + new_name= table_name; + } old_db_type=table->db_type; if (create_info->db_type == DB_TYPE_DEFAULT) @@ -2619,7 +2659,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); } - send_ok(thd); + if (do_send_ok) + send_ok(thd); } else { @@ -3180,7 +3221,8 @@ end_temporary: my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO), (ulong) (copied + deleted), (ulong) deleted, (ulong) thd->cuted_fields); - send_ok(thd,copied+deleted,0L,tmp_name); + if (do_send_ok) + send_ok(thd,copied+deleted,0L,tmp_name); thd->some_tables_deleted=0; DBUG_RETURN(0); @@ -3261,7 +3303,11 @@ copy_data_between_tables(TABLE *from,TABLE *to, error= 1; goto err; } - + + /* Handler must be told explicitly to retrieve all columns, because + this function does not set field->query_id in the columns to the + current query id */ + from->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS); init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1,1); if (handle_duplicates == DUP_IGNORE || handle_duplicates == DUP_REPLACE) @@ -3326,6 +3372,40 @@ copy_data_between_tables(TABLE *from,TABLE *to, } +/* + Recreates tables by calling mysql_alter_table(). + + SYNOPSIS + mysql_recreate_table() + thd Thread handler + tables Tables to recreate + do_send_ok If we should send_ok() or leave it to caller + + RETURN + Like mysql_alter_table(). +*/ +int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, + bool do_send_ok) +{ + DBUG_ENTER("mysql_recreate_table"); + LEX *lex= thd->lex; + HA_CREATE_INFO create_info; + lex->create_list.empty(); + lex->key_list.empty(); + lex->col_list.empty(); + lex->alter_info.reset(); + lex->alter_info.is_simple= 0; // Force full recreate + bzero((char*) &create_info,sizeof(create_info)); + create_info.db_type=DB_TYPE_DEFAULT; + create_info.row_type=ROW_TYPE_DEFAULT; + create_info.default_table_charset=default_charset_info; + DBUG_RETURN(mysql_alter_table(thd, NullS, NullS, &create_info, + table_list, lex->create_list, + lex->key_list, 0, (ORDER *) 0, + DUP_ERROR, &lex->alter_info, do_send_ok)); +} + + int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) { TABLE_LIST *table; @@ -3380,7 +3460,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) current query id */ t->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS); - if (t->file->rnd_init(1)) + if (t->file->ha_rnd_init(1)) protocol->store_null(); else { @@ -3408,6 +3488,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) crc+= row_crc; } protocol->store((ulonglong)crc); + t->file->ha_rnd_end(); } } thd->clear_error(); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 0953e63765a..e0281c813f1 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -328,6 +328,7 @@ int mysql_update(THD *thd, error= 1; // Aborted end_read_record(&info); free_io_cache(table); // If ORDER BY + delete select; thd->proc_info="end"; VOID(table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY)); @@ -342,7 +343,7 @@ int mysql_update(THD *thd, transactional_table= table->file->has_transactions(); log_delayed= (transactional_table || table->tmp_table); - if (updated && (error <= 0 || !transactional_table)) + if ((updated || (error < 0)) && (error <= 0 || !transactional_table)) { if (mysql_bin_log.is_open()) { @@ -368,7 +369,6 @@ int mysql_update(THD *thd, thd->lock=0; } - delete select; free_underlaid_joins(thd, &thd->lex->select_lex); if (error >= 0) send_error(thd,thd->killed_errno()); /* purecov: inspected */ @@ -980,25 +980,24 @@ int multi_update::do_updates(bool from_send_error) TABLE_LIST *cur_table; int local_error; ha_rows org_updated; - TABLE *table; + TABLE *table, *tmp_table; DBUG_ENTER("do_updates"); - - do_update= 0; // Don't retry this function + + do_update= 0; // Don't retry this function if (!found) DBUG_RETURN(0); for (cur_table= update_tables; cur_table ; cur_table= cur_table->next) { byte *ref_pos; - TABLE *tmp_table; - + table = cur_table->table; if (table == table_to_update) continue; // Already updated org_updated= updated; tmp_table= tmp_tables[cur_table->shared]; tmp_table->file->extra(HA_EXTRA_CACHE); // Change to read cache - (void) table->file->rnd_init(0); + (void) table->file->ha_rnd_init(0); table->file->extra(HA_EXTRA_NO_CACHE); /* @@ -1014,7 +1013,7 @@ int multi_update::do_updates(bool from_send_error) } copy_field_end=copy_field_ptr; - if ((local_error = tmp_table->file->rnd_init(1))) + if ((local_error = tmp_table->file->ha_rnd_init(1))) goto err; ref_pos= (byte*) tmp_table->field[0]->ptr; @@ -1065,7 +1064,8 @@ int multi_update::do_updates(bool from_send_error) else trans_safe= 0; // Can't do safe rollback } - (void) table->file->rnd_end(); + (void) table->file->ha_rnd_end(); + (void) tmp_table->file->ha_rnd_end(); } DBUG_RETURN(0); @@ -1073,6 +1073,9 @@ err: if (!from_send_error) table->file->print_error(local_error,MYF(0)); + (void) table->file->ha_rnd_end(); + (void) tmp_table->file->ha_rnd_end(); + if (updated != org_updated) { if (table->tmp_table != NO_TMP_TABLE) @@ -1108,7 +1111,9 @@ bool multi_update::send_eof() /* Write the SQL statement to the binlog if we updated rows and we succeeded or if we updated some non - transacational tables + transacational tables. + Note that if we updated nothing we don't write to the binlog (TODO: + fix this). */ if (updated && (local_error <= 0 || !trans_safe)) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index bad4a2c7190..cf17d38566d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -44,7 +44,7 @@ int yylex(void *yylval, void *yythd); -#define yyoverflow(A,B,C,D,E,F) if (my_yyoverflow((B),(D),(int*) (F))) { yyerror((char*) (A)); return 2; } +#define yyoverflow(A,B,C,D,E,F) {ulong val= *(F); if(my_yyoverflow((B), (D), &val)) { yyerror((char*) (A)); return 2; } else { *(F)= (YYSIZE_T)val; }} #define WARN_DEPRECATED(A,B) \ push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, \ @@ -98,7 +98,7 @@ inline Item *or_or_concat(THD *thd, Item* A, Item* B) } %{ -bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); +bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %} %pure_parser /* We have threads */ @@ -274,7 +274,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token IDENT_QUOTED %token IGNORE_SYM %token IMPORT -%token INDEX +%token INDEX_SYM %token INDEXES %token INFILE %token INNER_SYM @@ -340,6 +340,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token NUM %token OFFSET_SYM %token ON +%token ONE_SHOT_SYM %token OPEN_SYM %token OPTION %token OPTIONALLY @@ -465,6 +466,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token MEDIUMTEXT %token NUMERIC_SYM %token PRECISION +%token PREPARE_SYM +%token DEALLOCATE_SYM %token QUICK %token REAL %token SIGNED_SYM @@ -643,11 +646,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); opt_table_alias %type <table> - table_ident table_ident_ref references + table_ident table_ident_nodb references %type <simple_string> remember_name remember_end opt_ident opt_db text_or_password - opt_escape opt_constraint constraint + opt_constraint constraint %type <string> text_string opt_gconcat_separator @@ -675,7 +678,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); using_list expr_or_default set_expr_or_default interval_expr param_marker singlerow_subselect singlerow_subselect_init exists_subselect exists_subselect_init geometry_function - signed_literal now_or_signed_literal + signed_literal now_or_signed_literal opt_escape sp_opt_default simple_ident_nospvar simple_ident_q @@ -770,6 +773,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); precision subselect_start opt_and charset subselect_end select_var_list select_var_list_init help opt_len opt_extended_describe + prepare prepare_src execute deallocate statement sp_suid sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic sp_a_chistic END_OF_INPUT @@ -821,10 +825,12 @@ statement: | checksum | commit | create + | deallocate | delete | describe | do | drop + | execute | flush | grant | handler @@ -836,6 +842,7 @@ statement: | optimize | keycache | preload + | prepare | purge | rename | repair @@ -856,6 +863,92 @@ statement: | use ; +deallocate: + deallocate_or_drop PREPARE_SYM ident + { + THD *thd=YYTHD; + LEX *lex= thd->lex; + if (thd->command == COM_PREPARE) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + lex->sql_command= SQLCOM_DEALLOCATE_PREPARE; + lex->prepared_stmt_name= $3; + }; + +deallocate_or_drop: + DEALLOCATE_SYM | + DROP + ; + + +prepare: + PREPARE_SYM ident FROM prepare_src + { + THD *thd=YYTHD; + LEX *lex= thd->lex; + if (thd->command == COM_PREPARE) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + lex->sql_command= SQLCOM_PREPARE; + lex->prepared_stmt_name= $2; + }; + +prepare_src: + TEXT_STRING_sys + { + THD *thd=YYTHD; + LEX *lex= thd->lex; + lex->prepared_stmt_code= $1; + lex->prepared_stmt_code_is_varref= false; + } + | '@' ident_or_text + { + THD *thd=YYTHD; + LEX *lex= thd->lex; + lex->prepared_stmt_code= $2; + lex->prepared_stmt_code_is_varref= true; + }; + +execute: + EXECUTE_SYM ident + { + THD *thd=YYTHD; + LEX *lex= thd->lex; + if (thd->command == COM_PREPARE) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + lex->sql_command= SQLCOM_EXECUTE; + lex->prepared_stmt_name= $2; + } + execute_using + {} + ; + +execute_using: + /* nothing */ + | USING execute_var_list + ; + +execute_var_list: + execute_var_list ',' execute_var_ident + | execute_var_ident + ; + +execute_var_ident: '@' ident_or_text + { + LEX *lex=Lex; + LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING)); + if (!lexstr || lex->prepared_stmt_params.push_back(lexstr)) + YYABORT; + } + ; + /* help */ help: @@ -996,7 +1089,7 @@ create: } create2 { Lex->current_select= &Lex->select_lex; } - | CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident + | CREATE opt_unique_or_fulltext INDEX_SYM ident key_alg ON table_ident { LEX *lex=Lex; lex->sql_command= SQLCOM_CREATE_INDEX; @@ -2186,7 +2279,7 @@ create_table_option: | INSERT_METHOD opt_equal merge_insert_types { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;} | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.data_file_name= $4.str; } - | INDEX DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; }; + | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; }; storage_engines: ident_or_text @@ -2379,7 +2472,6 @@ type: $$=FIELD_TYPE_GEOMETRY; #else net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), sym_group_geom.name, sym_group_geom.needed_define); YYABORT; @@ -2697,7 +2789,6 @@ key_type: $$= Key::SPATIAL; #else net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif @@ -2709,7 +2800,7 @@ constraint_key_type: key_or_index: KEY_SYM {} - | INDEX {}; + | INDEX_SYM {}; opt_key_or_index: /* empty */ {} @@ -2718,7 +2809,7 @@ opt_key_or_index: keys_or_index: KEYS {} - | INDEX {} + | INDEX_SYM {} | INDEXES {}; opt_unique_or_fulltext: @@ -2731,7 +2822,6 @@ opt_unique_or_fulltext: $$= Key::SPATIAL; #else net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif @@ -2794,7 +2884,7 @@ alter: lex->create_info.db_type= DB_TYPE_DEFAULT; lex->create_info.default_table_charset= thd->variables.collation_database; lex->create_info.row_type= ROW_TYPE_NOT_USED; - lex->alter_info.clear(); + lex->alter_info.reset(); lex->alter_info.is_simple= 1; lex->alter_info.flags= 0; } @@ -3228,7 +3318,7 @@ table_to_table: }; keycache: - CACHE_SYM INDEX keycache_list IN_SYM key_cache_name + CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name { LEX *lex=Lex; lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE; @@ -3259,7 +3349,7 @@ key_cache_name: ; preload: - LOAD INDEX INTO CACHE_SYM + LOAD INDEX_SYM INTO CACHE_SYM { LEX *lex=Lex; lex->sql_command=SQLCOM_PRELOAD_KEYS; @@ -3773,7 +3863,6 @@ simple_expr: if (!$1.symbol->create_func) { net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), $1.symbol->group->name, $1.symbol->group->needed_define); YYABORT; @@ -3785,7 +3874,6 @@ simple_expr: if (!$1.symbol->create_func) { net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), $1.symbol->group->name, $1.symbol->group->needed_define); YYABORT; @@ -3797,7 +3885,6 @@ simple_expr: if (!$1.symbol->create_func) { net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), $1.symbol->group->name, $1.symbol->group->needed_define); YYABORT; @@ -3809,7 +3896,6 @@ simple_expr: if (!$1.symbol->create_func) { net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), $1.symbol->group->name, $1.symbol->group->needed_define); YYABORT; @@ -3908,7 +3994,6 @@ simple_expr: $$= $1; #else net_printf(Lex->thd, ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif @@ -4678,9 +4763,9 @@ interval_time_st: | YEAR_SYM { $$=INTERVAL_YEAR; }; date_time_type: - DATE_SYM {$$=TIMESTAMP_DATE;} - | TIME_SYM {$$=TIMESTAMP_TIME;} - | DATETIME {$$=TIMESTAMP_DATETIME;}; + DATE_SYM {$$=MYSQL_TIMESTAMP_DATE;} + | TIME_SYM {$$=MYSQL_TIMESTAMP_TIME;} + | DATETIME {$$=MYSQL_TIMESTAMP_DATETIME;}; table_alias: /* empty */ @@ -4724,8 +4809,12 @@ having_clause: ; opt_escape: - ESCAPE_SYM TEXT_STRING_literal { $$= $2.str; } - | /* empty */ { $$= (char*) "\\"; }; + ESCAPE_SYM simple_expr { $$= $2; } + | /* empty */ + { + $$= new Item_string("\\", 1, &my_charset_latin1); + } + ; /* @@ -5024,7 +5113,7 @@ drop: lex->drop_temporary= $2; lex->drop_if_exists= $4; } - | DROP INDEX ident ON table_ident {} + | DROP INDEX_SYM ident ON table_ident {} { LEX *lex=Lex; lex->sql_command= SQLCOM_DROP_INDEX; @@ -5399,13 +5488,12 @@ show_param: LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLES; lex->select_lex.db= $2; - lex->select_lex.options= 0; } | TABLE_SYM STATUS_SYM opt_db wild { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLES; - lex->select_lex.options|= SELECT_DESCRIBE; + lex->describe= DESCRIBE_EXTENDED; lex->select_lex.db= $3; } | OPEN_SYM TABLES opt_db wild @@ -5413,7 +5501,6 @@ show_param: LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_OPEN_TABLES; lex->select_lex.db= $3; - lex->select_lex.options= 0; } | ENGINE_SYM storage_engines { Lex->create_info.db_type= $2; } @@ -6096,7 +6183,7 @@ simple_ident_q: field_ident: ident { $$=$1;} - | ident '.' ident { $$=$3;} /* Skipp schema name in create*/ + | ident '.' ident { $$=$3;} /* Skip schema name in create*/ | '.' ident { $$=$2;} /* For Delphi */; table_ident: @@ -6105,9 +6192,8 @@ table_ident: | '.' ident { $$=new Table_ident($2);} /* For Delphi */ ; -table_ident_ref: +table_ident_nodb: ident { LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); } - | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);} ; IDENT_sys: @@ -6239,6 +6325,7 @@ keyword: | DATETIME {} | DATE_SYM {} | DAY_SYM {} + | DEALLOCATE_SYM {} | DEFINER_SYM {} | DELAY_KEY_WRITE_SYM {} | DES_KEY_FILE {} @@ -6334,12 +6421,14 @@ keyword: | NVARCHAR_SYM {} | OFFSET_SYM {} | OLD_PASSWORD {} + | ONE_SHOT_SYM {} | OPEN_SYM {} | PACK_KEYS_SYM {} | PARTIAL {} | PASSWORD {} | POINT_SYM {} | POLYGON {} + | PREPARE_SYM {} | PREV_SYM {} | PROCESS {} | PROCESSLIST_SYM {} @@ -6426,6 +6515,7 @@ set: lex->sql_command= SQLCOM_SET_OPTION; lex->option_type=OPT_SESSION; lex->var_list.empty(); + lex->one_shot_set= 0; } option_value_list {} @@ -6444,6 +6534,7 @@ option_type: | GLOBAL_SYM { Lex->option_type= OPT_GLOBAL; } | LOCAL_SYM { Lex->option_type= OPT_SESSION; } | SESSION_SYM { Lex->option_type= OPT_SESSION; } + | ONE_SHOT_SYM { Lex->option_type= OPT_SESSION; Lex->one_shot_set= 1; } ; opt_var_type: @@ -6687,14 +6778,14 @@ handler: if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0)) YYABORT; } - | HANDLER_SYM table_ident_ref CLOSE_SYM + | HANDLER_SYM table_ident_nodb CLOSE_SYM { LEX *lex= Lex; lex->sql_command = SQLCOM_HA_CLOSE; if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0)) YYABORT; } - | HANDLER_SYM table_ident_ref READ_SYM + | HANDLER_SYM table_ident_nodb READ_SYM { LEX *lex=Lex; lex->sql_command = SQLCOM_HA_READ; @@ -6804,7 +6895,7 @@ grant_privilege: | REFERENCES { Lex->which_columns = REFERENCES_ACL;} opt_column_list {} | DELETE_SYM { Lex->grant |= DELETE_ACL;} | USAGE {} - | INDEX { Lex->grant |= INDEX_ACL;} + | INDEX_SYM { Lex->grant |= INDEX_ACL;} | ALTER { Lex->grant |= ALTER_ACL;} | CREATE { Lex->grant |= CREATE_ACL;} | DROP { Lex->grant |= DROP_ACL;} diff --git a/sql/structs.h b/sql/structs.h index 2fcba9b3692..9f13ef54ce0 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -130,23 +130,14 @@ typedef struct st_read_record { /* Parameter to read_record */ } READ_RECORD; -enum timestamp_type -{ - TIMESTAMP_NONE= -2, TIMESTAMP_DATETIME_ERROR= -1, - TIMESTAMP_DATE= 0, TIMESTAMP_DATETIME= 1, TIMESTAMP_TIME= 2 -}; - -/* Parameters to str_to_TIME */ -#define TIME_FUZZY_DATE 1 -#define TIME_DATETIME_ONLY 2 - - -typedef struct st_time { - uint year,month,day,hour,minute,second; - ulong second_part; - bool neg; - timestamp_type time_type; -} TIME; +/* + Originally MySQL used TIME structure inside server only, but since + 4.1 it's exported to user in the new client API. Define aliases for + new names to keep existing code simple. +*/ + +typedef struct st_mysql_time TIME; +typedef enum enum_mysql_timestamp_type timestamp_type; typedef struct { diff --git a/sql/table.cc b/sql/table.cc index 73f036aed87..5024015c382 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -126,6 +126,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, goto err_not_open; /* purecov: inspected */ *fn_ext(index_file)='\0'; // Remove .frm extension + outparam->frm_version= head[2]; outparam->db_type=ha_checktype((enum db_type) (uint) *(head+3)); outparam->db_create_options=db_create_options=uint2korr(head+30); outparam->db_options_in_use=outparam->db_create_options; @@ -494,15 +495,13 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, for (uint key=0 ; key < outparam->keys ; key++,keyinfo++) { uint usable_parts=0; - ulong index_flags; keyinfo->name=(char*) outparam->keynames.type_names[key]; /* Fix fulltext keys for old .frm files */ if (outparam->key_info[key].flags & HA_FULLTEXT) outparam->key_info[key].algorithm= HA_KEY_ALG_FULLTEXT; /* This has to be done after the above fulltext correction */ - index_flags=outparam->file->index_flags(key); - if (!(index_flags & HA_KEY_READ_ONLY)) + if (!(outparam->file->index_flags(key) & HA_KEYREAD_ONLY)) { outparam->read_only_keys.set_bit(key); outparam->keys_for_keyread.clear_bit(key); @@ -577,15 +576,9 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, if (field->key_length() == key_part->length && !(field->flags & BLOB_FLAG)) { - if ((index_flags & HA_KEY_READ_ONLY) && - (field->key_type() != HA_KEYTYPE_TEXT || - (!((ha_option & HA_KEY_READ_WRONG_STR) || - (field->flags & BINARY_FLAG)) && - !(keyinfo->flags & HA_FULLTEXT)))) + if (outparam->file->index_flags(key, i) & HA_KEYREAD_ONLY) field->part_of_key.set_bit(key); - if ((field->key_type() != HA_KEYTYPE_TEXT || - !(keyinfo->flags & HA_FULLTEXT)) && - !(index_flags & HA_WRONG_ASCII_ORDER)) + if (outparam->file->index_flags(key, i) & HA_READ_ORDER) field->part_of_sortkey.set_bit(key); } if (!(key_part->key_part_flag & HA_REVERSE_SORT) && @@ -1134,7 +1127,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo, char fill[IO_SIZE]; #if SIZEOF_OFF_T > 4 - /* Fix this in MySQL 4.0; The current limit is 4G rows (QQ) */ + /* Fix this when we have new .frm files; Current limit is 4G rows (QQ) */ if (create_info->max_rows > ~(ulong) 0) create_info->max_rows= ~(ulong) 0; if (create_info->min_rows > ~(ulong) 0) diff --git a/sql/table.h b/sql/table.h index c59b5a03bc4..eaad8bedf90 100644 --- a/sql/table.h +++ b/sql/table.h @@ -157,7 +157,8 @@ struct st_table { uint quick_key_parts[MAX_KEY]; key_part_map const_key_parts[MAX_KEY]; ulong query_id; - uint temp_pool_slot; /* Used by intern temp tables */ + uchar frm_version; + uint temp_pool_slot; /* Used by intern temp tables */ struct st_table_list *pos_in_table_list;/* Element referring to this table */ /* number of select if it is derived table */ uint derived_select_number; diff --git a/sql/time.cc b/sql/time.cc index 6d15fa184a1..132612e53c5 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -23,16 +23,26 @@ static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */ uchar *days_in_month= (uchar*) "\037\034\037\036\037\036\037\037\036\037\036\037"; - /* Init some variabels needed when using my_local_time */ - /* Currently only my_time_zone is inited */ +/* + Offset of system time zone from UTC in seconds used to speed up + work of my_system_gmt_sec() function. +*/ static long my_time_zone=0; + +/* + Prepare offset of system time zone from UTC for my_system_gmt_sec() func. + + SYNOPSIS + init_time() +*/ void init_time(void) { time_t seconds; struct tm *l_time,tm_tmp;; TIME my_time; + bool not_used; seconds= (time_t) time((time_t*) 0); localtime_r(&seconds,&tm_tmp); @@ -44,33 +54,40 @@ void init_time(void) my_time.hour= (uint) l_time->tm_hour; my_time.minute= (uint) l_time->tm_min; my_time.second= (uint) l_time->tm_sec; - my_gmt_sec(&my_time, &my_time_zone); /* Init my_time_zone */ + my_system_gmt_sec(&my_time, &my_time_zone, ¬_used); /* Init my_time_zone */ } + /* - Convert current time to sec. since 1970.01.01 - This code handles also day light saving time. - The idea is to cache the time zone (including daylight saving time) - for the next call to make things faster. + Convert time in TIME representation in system time zone to its + my_time_t form (number of seconds in UTC since begginning of Unix Epoch). -*/ + SYNOPSIS + my_system_gmt_sec() + t - time value to be converted + my_timezone - pointer to long where offset of system time zone + from UTC will be stored for caching + in_dst_time_gap - set to true if time falls into spring time-gap -long my_gmt_sec(TIME *t, long *my_timezone) + NOTES + The idea is to cache the time zone offset from UTC (including daylight + saving time) for the next call to make things faster. But currently we + just calculate this offset during startup (by calling init_time() + function) and use it all the time. + Time value provided should be legal time value (e.g. '2003-01-01 25:00:00' + is not allowed). + + RETURN VALUE + Time in UTC seconds since Unix Epoch representation. +*/ +my_time_t +my_system_gmt_sec(const TIME *t, long *my_timezone, bool *in_dst_time_gap) { uint loop; time_t tmp; struct tm *l_time,tm_tmp; long diff, current_timezone; - if (t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) - return 0; - - if (t->hour >= 24) - { /* Fix for time-loop */ - t->day+=t->hour/24; - t->hour%=24; - } - /* Calculate the gmt time based on current time and timezone The -1 on the end is to ensure that if have a date that exists twice @@ -125,14 +142,13 @@ long my_gmt_sec(TIME *t, long *my_timezone) tmp+=3600 - t->minute*60 - t->second; // Move to next hour else if (diff == -3600) tmp-=t->minute*60 + t->second; // Move to previous hour + + *in_dst_time_gap= 1; } *my_timezone= current_timezone; - if (tmp < TIMESTAMP_MIN_VALUE || tmp > TIMESTAMP_MAX_VALUE) - tmp= 0; - - return (long) tmp; -} /* my_gmt_sec */ + return (my_time_t) tmp; +} /* my_system_gmt_sec */ /* Some functions to calculate dates */ @@ -164,6 +180,7 @@ long calc_daynr(uint year,uint month,uint day) } /* calc_daynr */ +#ifndef TESTTIME /* Calc weekday from daynr */ /* Returns 0 for monday, 1 for tuesday .... */ @@ -328,545 +345,167 @@ ulong convert_month_to_period(ulong month) } -/* Position for YYYY-DD-MM HH-MM-DD.FFFFFF AM in default format */ - -static uchar internal_format_positions[]= -{0, 1, 2, 3, 4, 5, 6, (uchar) 255}; - -static char time_separator=':'; - /* - Convert a timestamp string to a TIME value. + Convert a timestamp string to a TIME value and produce a warning + if string was truncated during conversion. - SYNOPSIS - str_to_TIME() - str String to parse - length Length of string - l_time Date is stored here - flags Bitmap of following items - TIME_FUZZY_DATE Set if we should allow partial dates - TIME_DATETIME_ONLY Set if we only allow full datetimes. - - DESCRIPTION - At least the following formats are recogniced (based on number of digits) - YYMMDD, YYYYMMDD, YYMMDDHHMMSS, YYYYMMDDHHMMSS - YY-MM-DD, YYYY-MM-DD, YY-MM-DD HH.MM.SS - YYYYMMDDTHHMMSS where T is a the character T (ISO8601) - Also dates where all parts are zero are allowed - - The second part may have an optional .###### fraction part. - - NOTES - This function should work with a format position vector as long as the - following things holds: - - All date are kept together and all time parts are kept together - - Date and time parts must be separated by blank - - Second fractions must come after second part and be separated - by a '.'. (The second fractions are optional) - - AM/PM must come after second fractions (or after seconds if no fractions) - - Year must always been specified. - - If time is before date, then we will use datetime format only if - the argument consist of two parts, separated by space. - Otherwise we will assume the argument is a date. - - The hour part must be specified in hour-minute-second order. - - RETURN VALUES - TIMESTAMP_NONE String wasn't a timestamp, like - [DD [HH:[MM:[SS]]]].fraction. - l_time is not changed. - TIMESTAMP_DATE DATE string (YY MM and DD parts ok) - TIMESTAMP_DATETIME Full timestamp - TIMESTAMP_DATETIME_ERROR Timestamp with wrong values. - All elements in l_time is set to 0 + NOTE + See description of str_to_datetime() for more information. */ - -#define MAX_DATE_PARTS 8 - timestamp_type -str_to_TIME(const char *str, uint length, TIME *l_time, uint flags) +str_to_datetime_with_warn(const char *str, uint length, TIME *l_time, + uint flags) { - uint field_length, year_length, digits, i, number_of_fields; - uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS]; - uint add_hours= 0, start_loop; - ulong not_zero_date, allow_space; - bool is_internal_format; - const char *pos, *last_field_pos; - const char *str_begin= str; - const char *end=str+length; - const uchar *format_position; - bool found_delimitier= 0, found_space= 0; - uint frac_pos, frac_len; - DBUG_ENTER("str_to_TIME"); - DBUG_PRINT("ENTER",("str: %.*s",length,str)); - - LINT_INIT(field_length); - LINT_INIT(year_length); - LINT_INIT(last_field_pos); - - // Skip space at start - for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++) - ; - if (str == end || ! my_isdigit(&my_charset_latin1, *str)) - DBUG_RETURN(TIMESTAMP_NONE); - - is_internal_format= 0; - /* This has to be changed if want to activate different timestamp formats */ - format_position= internal_format_positions; - - /* - Calculate number of digits in first part. - If length= 8 or >= 14 then year is of format YYYY. - (YYYY-MM-DD, YYYYMMDD, YYYYYMMDDHHMMSS) - */ - for (pos=str; pos != end && my_isdigit(&my_charset_latin1,*pos) ; pos++) - ; - - digits= (uint) (pos-str); - start_loop= 0; // Start of scan loop - date_len[format_position[0]]= 0; // Length of year field - if (pos == end) - { - /* Found date in internal format (only numbers like YYYYMMDD) */ - year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; - field_length=year_length-1; - is_internal_format= 1; - format_position= internal_format_positions; - } - else - { - if (format_position[0] >= 3) // If year is after HHMMDD - { - /* - If year is not in first part then we have to determinate if we got - a date field or a datetime field. - We do this by checking if there is two numbers separated by - space in the input. - */ - while (pos < end && !my_isspace(&my_charset_latin1, *pos)) - pos++; - while (pos < end && !my_isdigit(&my_charset_latin1, *pos)) - pos++; - if (pos == end) - { - if (flags & TIME_DATETIME_ONLY) - DBUG_RETURN(TIMESTAMP_NONE); // Can't be a full datetime - /* Date field. Set hour, minutes and seconds to 0 */ - date[0]= date[1]= date[2]= date[3]= date[4]= 0; - start_loop= 5; // Start with first date part - } - } - } - - /* - Only allow space in the first "part" of the datetime field and: - - after days, part seconds - - before and after AM/PM (handled by code later) - - 2003-03-03 20:00:20 AM - 20:00:20.000000 AM 03-03-2000 - */ - i= max((uint) format_position[0], (uint) format_position[1]); - set_if_bigger(i, (uint) format_position[2]); - allow_space= ((1 << i) | (1 << format_position[6])); - allow_space&= (1 | 2 | 4 | 8); - - not_zero_date= 0; - for (i = start_loop; - i < MAX_DATE_PARTS-1 && str != end && - my_isdigit(&my_charset_latin1,*str); - i++) - { - const char *start= str; - ulong tmp_value= (uint) (uchar) (*str++ - '0'); - while (str != end && my_isdigit(&my_charset_latin1,str[0]) && - (!is_internal_format || field_length--)) - { - tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0'); - str++; - } - date_len[i]= (uint) (str - start); - if (tmp_value > 999999) // Impossible date part - DBUG_RETURN(TIMESTAMP_NONE); - date[i]=tmp_value; - not_zero_date|= tmp_value; - - /* Length-1 of next field */ - field_length= format_position[i+1] == 0 ? 3 : 1; - - if ((last_field_pos= str) == end) - { - i++; // Register last found part - break; - } - /* Allow a 'T' after day to allow CCYYMMDDT type of fields */ - if (i == format_position[2] && *str == 'T') - { - str++; // ISO8601: CCYYMMDDThhmmss - continue; - } - if (i == format_position[5]) // Seconds - { - if (*str == '.') // Followed by part seconds - { - str++; - field_length= 5; // 5 digits after first (=6) - } - continue; - - /* No part seconds */ - date[++i]= 0; - } - while (str != end && - (my_ispunct(&my_charset_latin1,*str) || - my_isspace(&my_charset_latin1,*str))) - { - if (my_isspace(&my_charset_latin1,*str)) - { - if (!(allow_space & (1 << i))) - DBUG_RETURN(TIMESTAMP_NONE); - found_space= 1; - } - str++; - found_delimitier= 1; // Should be a 'normal' date - } - /* Check if next position is AM/PM */ - if (i == format_position[6]) // Seconds, time for AM/PM - { - i++; // Skip AM/PM part - if (format_position[7] != 255) // If using AM/PM - { - if (str+2 <= end && (str[1] == 'M' || str[1] == 'm')) - { - if (str[0] == 'p' || str[0] == 'P') - add_hours= 12; - else if (str[0] != 'a' || str[0] != 'A') - continue; // Not AM/PM - str+= 2; // Skip AM/PM - /* Skip space after AM/PM */ - while (str != end && my_isspace(&my_charset_latin1,*str)) - str++; - } - } - } - last_field_pos= str; - } - if (found_delimitier && !found_space && (flags & TIME_DATETIME_ONLY)) - DBUG_RETURN(TIMESTAMP_NONE); // Can't be a datetime - - str= last_field_pos; - - number_of_fields= i - start_loop; - while (i < MAX_DATE_PARTS) - { - date_len[i]= 0; - date[i++]= 0; - } + int was_cut; + timestamp_type ts_type= str_to_datetime(str, length, l_time, flags, &was_cut); + if (was_cut) + make_truncated_value_warning(current_thd, str, length, ts_type); + return ts_type; +} - if (!is_internal_format) - { - year_length= date_len[(uint) format_position[0]]; - if (!year_length) // Year must be specified - DBUG_RETURN(TIMESTAMP_NONE); - - l_time->year= date[(uint) format_position[0]]; - l_time->month= date[(uint) format_position[1]]; - l_time->day= date[(uint) format_position[2]]; - l_time->hour= date[(uint) format_position[3]]; - l_time->minute= date[(uint) format_position[4]]; - l_time->second= date[(uint) format_position[5]]; - - frac_pos= (uint) format_position[6]; - frac_len= date_len[frac_pos]; - if (frac_len < 6) - date[frac_pos]*= (uint) log_10_int[6 - frac_len]; - l_time->second_part= date[frac_pos]; - - if (format_position[7] != (uchar) 255) - { - if (l_time->hour > 12) - goto err; - l_time->hour= l_time->hour%12 + add_hours; - } - } - else - { - l_time->year= date[0]; - l_time->month= date[1]; - l_time->day= date[2]; - l_time->hour= date[3]; - l_time->minute= date[4]; - l_time->second= date[5]; - if (date_len[6] < 6) - date[6]*= (uint) log_10_int[6 - date_len[6]]; - l_time->second_part=date[6]; - } - l_time->neg= 0; - if (year_length == 2 && i >= format_position[1] && i >=format_position[2] && - (l_time->month || l_time->day)) - l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900); +/* + Convert a datetime from broken-down TIME representation to corresponding + TIMESTAMP value. - if (number_of_fields < 3 || l_time->month > 12 || - l_time->day > 31 || l_time->hour > 23 || - l_time->minute > 59 || l_time->second > 59 || - (!(flags & TIME_FUZZY_DATE) && (l_time->month == 0 || l_time->day == 0))) - { - /* Only give warning for a zero date if there is some garbage after */ - if (!not_zero_date) // If zero date - { - for (; str != end ; str++) - { - if (!my_isspace(&my_charset_latin1, *str)) - { - not_zero_date= 1; // Give warning - break; - } - } - } - if (not_zero_date) - current_thd->cuted_fields++; - goto err; - } + SYNOPSIS + TIME_to_timestamp() + thd - current thread + t - datetime in broken-down representation, + in_dst_time_gap - pointer to bool which is set to true if t represents + value which doesn't exists (falls into the spring + time-gap) or to false otherwise. + + RETURN + Number seconds in UTC since start of Unix Epoch corresponding to t. + 0 - t contains datetime value which is out of TIMESTAMP range. + +*/ +my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *in_dst_time_gap) +{ + my_time_t timestamp; - l_time->time_type= (number_of_fields <= 3 ? - TIMESTAMP_DATE : TIMESTAMP_DATETIME); + *in_dst_time_gap= 0; - for (; str != end ; str++) + if (t->year < TIMESTAMP_MAX_YEAR && t->year > TIMESTAMP_MIN_YEAR || + t->year == TIMESTAMP_MAX_YEAR && t->month == 1 && t->day == 1 || + t->year == TIMESTAMP_MIN_YEAR && t->month == 12 && t->day == 31) { - if (!my_isspace(&my_charset_latin1,*str)) - { - make_truncated_value_warning(current_thd, str_begin, length, - l_time->time_type); - break; - } + thd->time_zone_used= 1; + timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap); + if (timestamp >= TIMESTAMP_MIN_VALUE && timestamp <= TIMESTAMP_MAX_VALUE) + return timestamp; } - DBUG_RETURN(l_time->time_type= - (number_of_fields <= 3 ? TIMESTAMP_DATE : TIMESTAMP_DATETIME)); - -err: - bzero((char*) l_time, sizeof(*l_time)); - DBUG_RETURN(TIMESTAMP_DATETIME_ERROR); -} - - -time_t str_to_timestamp(const char *str,uint length) -{ - TIME l_time; - long not_used; - time_t timestamp= 0; - - if (str_to_TIME(str,length,&l_time,0) > TIMESTAMP_DATETIME_ERROR && - !(timestamp= my_gmt_sec(&l_time, ¬_used))) - current_thd->cuted_fields++; - return timestamp; + /* If we are here we have range error. */ + return(0); } /* - Convert a string to datetime. - - SYNOPSIS - str_to_datetime() - str String to parse (see str_to_TIME() synopsis) - length Length of str - fuzzy_date Flags (see str_to_TIME() synopsis) + Convert a time string to a TIME struct and produce a warning + if string was cut during conversion. - RETURN - -1 if error - datetime value otherwise + NOTE + See str_to_time() for more info. */ - -longlong str_to_datetime(const char *str,uint length, uint fuzzy_date) +bool +str_to_time_with_warn(const char *str, uint length, TIME *l_time) { - TIME l_time; - if (str_to_TIME(str,length,&l_time,fuzzy_date) <= TIMESTAMP_DATETIME_ERROR) - return -1; - return (longlong) (l_time.year*LL(10000000000) + - l_time.month*LL(100000000)+ - l_time.day*LL(1000000)+ - l_time.hour*LL(10000)+ - (longlong) (l_time.minute*100+l_time.second)); + int was_cut; + bool ret_val= str_to_time(str, length, l_time, &was_cut); + if (was_cut) + make_truncated_value_warning(current_thd, str, length, MYSQL_TIMESTAMP_TIME); + return ret_val; } /* - Convert a time string to a TIME struct. + Convert datetime value specified as number to broken-down TIME + representation and form value of DATETIME type as side-effect. SYNOPSIS - str_to_time() - str A string in full TIMESTAMP format or - [-] DAYS [H]H:MM:SS, [H]H:MM:SS, [M]M:SS, [H]HMMSS, - [M]MSS or [S]S - There may be an optional [.second_part] after seconds - length Length of str - l_time Store result here - - NOTES - Because of the extra days argument, this function can only - work with times where the time arguments are in the above order. - - RETURN - 0 ok - 1 error + number_to_TIME() + nr - datetime value as number + time_res - pointer for structure for broken-down representation + fuzzy_date - indicates whenever we allow fuzzy dates + was_cut - set ot 1 if there was some kind of error during + conversion or to 0 if everything was OK. + + DESCRIPTION + Convert a datetime value of formats YYMMDD, YYYYMMDD, YYMMDDHHMSS, + YYYYMMDDHHMMSS to broken-down TIME representation. Return value in + YYYYMMDDHHMMSS format as side-effect. + + This function also checks if datetime value fits in DATETIME range. + + RETURN VALUE + Datetime value in YYYYMMDDHHMMSS format. + If input value is not valid datetime value then 0 is returned. */ -bool str_to_time(const char *str,uint length,TIME *l_time) +longlong number_to_TIME(longlong nr, TIME *time_res, bool fuzzy_date, + int *was_cut) { - long date[5],value; - const char *end=str+length, *end_of_days; - const char *str_begin= str; - bool found_days,found_hours; - uint state; - - l_time->neg=0; - for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++) - length--; - if (str != end && *str == '-') - { - l_time->neg=1; - str++; - length--; - } - if (str == end) - return 1; + long part1,part2; - /* Check first if this is a full TIMESTAMP */ - if (length >= 12) - { // Probably full timestamp - enum timestamp_type res= str_to_TIME(str,length,l_time, - (TIME_FUZZY_DATE | - TIME_DATETIME_ONLY)); - if ((int) res >= (int) TIMESTAMP_DATETIME_ERROR) - return res == TIMESTAMP_DATETIME_ERROR; - } - - /* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */ - for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++) - value=value*10L + (long) (*str - '0'); - - /* Skipp all space after 'days' */ - end_of_days= str; - for (; str != end && my_isspace(&my_charset_latin1, str[0]) ; str++) - ; - - LINT_INIT(state); - found_days=found_hours=0; - if ((uint) (end-str) > 1 && str != end_of_days && - my_isdigit(&my_charset_latin1, *str)) - { // Found days part - date[0]= value; - state= 1; // Assume next is hours - found_days= 1; - } - else if ((end-str) > 1 && *str == time_separator && - my_isdigit(&my_charset_latin1, str[1])) - { - date[0]=0; // Assume we found hours - date[1]=value; - state=2; - found_hours=1; - str++; // skip ':' - } - else - { - /* String given as one number; assume HHMMSS format */ - date[0]= 0; - date[1]= value/10000; - date[2]= value/100 % 100; - date[3]= value % 100; - state=4; - goto fractional; - } - - /* Read hours, minutes and seconds */ - for (;;) - { - for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++) - value=value*10L + (long) (*str - '0'); - date[state++]=value; - if (state == 4 || (end-str) < 2 || *str != time_separator || - !my_isdigit(&my_charset_latin1,str[1])) - break; - str++; // Skip time_separator (':') - } - - if (state != 4) - { // Not HH:MM:SS - /* Fix the date to assume that seconds was given */ - if (!found_hours && !found_days) - { - bmove_upp((char*) (date+4), (char*) (date+state), - sizeof(long)*(state-1)); - bzero((char*) date, sizeof(long)*(4-state)); - } - else - bzero((char*) (date+state), sizeof(long)*(4-state)); - } - -fractional: - /* Get fractional second part */ - if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_latin1,str[1])) + *was_cut= 0; + + if (nr == LL(0) || nr >= LL(10000101000000)) + goto ok; + if (nr < 101) + goto err; + if (nr <= (YY_PART_YEAR-1)*10000L+1231L) { - uint field_length=5; - str++; value=(uint) (uchar) (*str - '0'); - while (++str != end && - my_isdigit(&my_charset_latin1,str[0]) && - field_length--) - value=value*10 + (uint) (uchar) (*str - '0'); - if (field_length) - value*= (long) log_10_int[field_length]; - date[4]=value; + nr= (nr+20000000L)*1000000L; // YYMMDD, year: 2000-2069 + goto ok; } - else - date[4]=0; - - if (internal_format_positions[7] != 255) + if (nr < (YY_PART_YEAR)*10000L+101L) + goto err; + if (nr <= 991231L) { - /* Read a possible AM/PM */ - while (str != end && my_isspace(&my_charset_latin1, *str)) - str++; - if (str+2 <= end && (str[1] == 'M' || str[1] == 'm')) - { - if (str[0] == 'p' || str[0] == 'P') - { - str+= 2; - date[1]= date[1]%12 + 12; - } - else if (str[0] == 'a' || str[0] == 'A') - str+=2; - } + nr= (nr+19000000L)*1000000L; // YYMMDD, year: 1970-1999 + goto ok; } - - /* Some simple checks */ - if (date[2] >= 60 || date[3] >= 60) + if (nr < 10000101L) + goto err; + if (nr <= 99991231L) { - current_thd->cuted_fields++; - return 1; + nr= nr*1000000L; + goto ok; } - l_time->year= 0; // For protocol::store_time - l_time->month= 0; - l_time->day= date[0]; - l_time->hour= date[1]; - l_time->minute= date[2]; - l_time->second= date[3]; - l_time->second_part= date[4]; - l_time->time_type= TIMESTAMP_TIME; - - /* Check if there is garbage at end of the TIME specification */ - if (str != end) + if (nr < 101000000L) + goto err; + if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959)) { - do - { - if (!my_isspace(&my_charset_latin1,*str)) - { - make_truncated_value_warning(current_thd, str_begin, length, - TIMESTAMP_TIME); - break; - } - } while (++str != end); + nr= nr+LL(20000000000000); // YYMMDDHHMMSS, 2000-2069 + goto ok; } - return 0; + if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000)) + goto err; + if (nr <= LL(991231235959)) + nr= nr+LL(19000000000000); // YYMMDDHHMMSS, 1970-1999 + + ok: + part1=(long) (nr/LL(1000000)); + part2=(long) (nr - (longlong) part1*LL(1000000)); + time_res->year= (int) (part1/10000L); part1%=10000L; + time_res->month= (int) part1 / 100; + time_res->day= (int) part1 % 100; + time_res->hour= (int) (part2/10000L); part2%=10000L; + time_res->minute=(int) part2 / 100; + time_res->second=(int) part2 % 100; + + if (time_res->year <= 9999 && time_res->month <= 12 && + time_res->day <= 31 && time_res->hour <= 23 && + time_res->minute <= 59 && time_res->second <= 59 && + (fuzzy_date || (time_res->month != 0 && time_res->day != 0) || nr==0)) + return nr; + + err: + + *was_cut= 1; + return LL(0); } @@ -1042,10 +681,10 @@ bool parse_date_time_format(timestamp_type format_type, The last test is to ensure that %p is used if and only if it's needed. */ - if ((format_type == TIMESTAMP_DATETIME && + if ((format_type == MYSQL_TIMESTAMP_DATETIME && !test_all_bits(part_map, (1 | 2 | 4 | 8 | 16 | 32))) || - (format_type == TIMESTAMP_DATE && part_map != (1 | 2 | 4)) || - (format_type == TIMESTAMP_TIME && + (format_type == MYSQL_TIMESTAMP_DATE && part_map != (1 | 2 | 4)) || + (format_type == MYSQL_TIMESTAMP_TIME && !test_all_bits(part_map, 8 | 16 | 32)) || !allow_separator || // %option should be last (need_p && dt_pos[6] +1 != dt_pos[7]) || @@ -1088,10 +727,10 @@ bool parse_date_time_format(timestamp_type format_type, format_str= 0; switch (format_type) { - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: format_str= known_date_time_formats[INTERNAL_FORMAT].date_format; /* fall through */ - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: if (!format_str) format_str=known_date_time_formats[INTERNAL_FORMAT].time_format; @@ -1106,7 +745,7 @@ bool parse_date_time_format(timestamp_type format_type, return 0; if (separator_map == (1 | 2)) { - if (format_type == TIMESTAMP_TIME) + if (format_type == MYSQL_TIMESTAMP_TIME) { if (*(format+2) != *(format+5)) break; // Error @@ -1116,7 +755,7 @@ bool parse_date_time_format(timestamp_type format_type, return 0; } break; - case TIMESTAMP_DATETIME: + case MYSQL_TIMESTAMP_DATETIME: /* If there is no separators, allow the internal format as we can read this. If separators are used, they must be between each part. @@ -1235,11 +874,11 @@ const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format, timestamp_type type) { switch (type) { - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: return format->date_format; - case TIMESTAMP_DATETIME: + case MYSQL_TIMESTAMP_DATETIME: return format->datetime_format; - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: return format->time_format; default: DBUG_ASSERT(0); // Impossible @@ -1307,6 +946,7 @@ void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)), str->set_charset(&my_charset_bin); } + void make_truncated_value_warning(THD *thd, const char *str_val, uint str_length, timestamp_type time_type) { @@ -1320,22 +960,20 @@ void make_truncated_value_warning(THD *thd, const char *str_val, str.append('\0'); switch (time_type) { - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: type_str= "date"; break; - case TIMESTAMP_DATETIME: - type_str= "datetime"; - break; - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: type_str= "time"; break; + case MYSQL_TIMESTAMP_DATETIME: // FALLTHROUGH default: - type_str= "string"; + type_str= "datetime"; break; } sprintf(warn_buff, ER(ER_TRUNCATED_WRONG_VALUE), type_str, str.ptr()); - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, warn_buff); } @@ -1398,14 +1036,14 @@ ulonglong TIME_to_ulonglong_time(const TIME *time) ulonglong TIME_to_ulonglong(const TIME *time) { switch (time->time_type) { - case TIMESTAMP_DATETIME: + case MYSQL_TIMESTAMP_DATETIME: return TIME_to_ulonglong_datetime(time); - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: return TIME_to_ulonglong_date(time); - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: return TIME_to_ulonglong_time(time); - case TIMESTAMP_NONE: - case TIMESTAMP_DATETIME_ERROR: + case MYSQL_TIMESTAMP_NONE: + case MYSQL_TIMESTAMP_ERROR: return ULL(0); default: DBUG_ASSERT(0); @@ -1428,17 +1066,17 @@ ulonglong TIME_to_ulonglong(const TIME *time) void TIME_to_string(const TIME *time, String *str) { switch (time->time_type) { - case TIMESTAMP_DATETIME: + case MYSQL_TIMESTAMP_DATETIME: make_datetime((DATE_TIME_FORMAT*) 0, time, str); break; - case TIMESTAMP_DATE: + case MYSQL_TIMESTAMP_DATE: make_date((DATE_TIME_FORMAT*) 0, time, str); break; - case TIMESTAMP_TIME: + case MYSQL_TIMESTAMP_TIME: make_time((DATE_TIME_FORMAT*) 0, time, str); break; - case TIMESTAMP_NONE: - case TIMESTAMP_DATETIME_ERROR: + case MYSQL_TIMESTAMP_NONE: + case MYSQL_TIMESTAMP_ERROR: str->length(0); str->set_charset(&my_charset_bin); break; @@ -1446,3 +1084,5 @@ void TIME_to_string(const TIME *time, String *str) DBUG_ASSERT(0); } } + +#endif diff --git a/sql/tzfile.h b/sql/tzfile.h new file mode 100644 index 00000000000..623cddc1f12 --- /dev/null +++ b/sql/tzfile.h @@ -0,0 +1,137 @@ +/* Copyright (C) 2004 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 */ + +/* + This file is based on public domain code from ftp://elsie.ncih.nist.gov/ + Initial source code is in the public domain, so clarified as of + 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). +*/ + +/* + Information about time zone files. +*/ + +#ifndef TZDIR +#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ +#endif /* !defined TZDIR */ + +/* + Each file begins with. . . +*/ + +#define TZ_MAGIC "TZif" + +struct tzhead { + char tzh_magic[4]; /* TZ_MAGIC */ + char tzh_reserved[16]; /* reserved for future use */ + char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ + char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ + char tzh_leapcnt[4]; /* coded number of leap seconds */ + char tzh_timecnt[4]; /* coded number of transition times */ + char tzh_typecnt[4]; /* coded number of local time types */ + char tzh_charcnt[4]; /* coded number of abbr. chars */ +}; + +/* + . . .followed by. . . + + tzh_timecnt (char [4])s coded transition times a la time(2) + tzh_timecnt (unsigned char)s types of local time starting at above + tzh_typecnt repetitions of + one (char [4]) coded UTC offset in seconds + one (unsigned char) used to set tm_isdst + one (unsigned char) that's an abbreviation list index + tzh_charcnt (char)s '\0'-terminated zone abbreviations + tzh_leapcnt repetitions of + one (char [4]) coded leap second transition times + one (char [4]) total correction after above + tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition + time is standard time, if FALSE, + transition time is wall clock time + if absent, transition times are + assumed to be wall clock time + tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition + time is UTC, if FALSE, + transition time is local time + if absent, transition times are + assumed to be local time +*/ + +/* + In the current implementation, we refuse to deal with files that + exceed any of the limits below. +*/ + +#ifndef TZ_MAX_TIMES +/* + The TZ_MAX_TIMES value below is enough to handle a bit more than a + year's worth of solar time (corrected daily to the nearest second) or + 138 years of Pacific Presidential Election time + (where there are three time zone transitions every fourth year). +*/ +#define TZ_MAX_TIMES 370 +#endif /* !defined TZ_MAX_TIMES */ + +#ifndef TZ_MAX_TYPES +#ifdef SOLAR +#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ +#else +/* + Must be at least 14 for Europe/Riga as of Jan 12 1995, + as noted by Earl Chew <earl@hpato.aus.hp.com>. +*/ +#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ +#endif /* defined SOLAR */ +#endif /* !defined TZ_MAX_TYPES */ + +#ifndef TZ_MAX_CHARS +#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ + /* (limited by what unsigned chars can hold) */ +#endif /* !defined TZ_MAX_CHARS */ + +#ifndef TZ_MAX_LEAPS +#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ +#endif /* !defined TZ_MAX_LEAPS */ + +#ifndef TZ_MAX_REV_RANGES +#ifdef SOLAR +/* Solar (Asia/RiyadhXX) zones need significantly bigger TZ_MAX_REV_RANGES */ +#define TZ_MAX_REV_RANGES (TZ_MAX_TIMES*2+TZ_MAX_LEAPS*2+2) +#else +#define TZ_MAX_REV_RANGES (TZ_MAX_TIMES+TZ_MAX_LEAPS+2) +#endif +#endif + +#define SECS_PER_MIN 60 +#define MINS_PER_HOUR 60 +#define HOURS_PER_DAY 24 +#define DAYS_PER_WEEK 7 +#define DAYS_PER_NYEAR 365 +#define DAYS_PER_LYEAR 366 +#define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR) +#define SECS_PER_DAY ((long) SECS_PER_HOUR * HOURS_PER_DAY) +#define MONS_PER_YEAR 12 + +#define TM_YEAR_BASE 1900 + +#define EPOCH_YEAR 1970 + +/* + Accurate only for the past couple of centuries, + that will probably do. +*/ + +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) diff --git a/sql/tztime.cc b/sql/tztime.cc new file mode 100644 index 00000000000..aab0d36b61e --- /dev/null +++ b/sql/tztime.cc @@ -0,0 +1,2581 @@ +/* Copyright (C) 2004 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 */ + +/* + Most of the following code and structures were derived from + public domain code from ftp://elsie.nci.nih.gov/pub + (We will refer to this code as to elsie-code further.) +*/ + +#ifdef __GNUC__ +#pragma implementation // gcc: Class implementation +#endif + +/* + We should not include mysql_priv.h in mysql_tzinfo_to_sql utility since + it creates unsolved link dependencies on some platforms. +*/ +#if !defined(TZINFO2SQL) && !defined(TESTTIME) +#include "mysql_priv.h" +#else +#include <my_global.h> +#include "tztime.h" +#include <my_sys.h> +#endif + +#include "tzfile.h" +#include <m_string.h> +#include <my_dir.h> + +/* + Now we don't use abbreviations in server but we will do this in future. +*/ +#if defined(TZINFO2SQL) || defined(TESTTIME) +#define ABBR_ARE_USED +#else +#if !defined(DBUG_OFF) +/* Let use abbreviations for debug purposes */ +#undef ABBR_ARE_USED +#define ABBR_ARE_USED +#endif /* !defined(DBUG_OFF) */ +#endif /* defined(TZINFO2SQL) || defined(TESTTIME) */ + +/* Structure describing local time type (e.g. Moscow summer time (MSD)) */ +typedef struct ttinfo +{ + long tt_gmtoff; // Offset from UTC in seconds + uint tt_isdst; // Is daylight saving time or not. Used to set tm_isdst +#ifdef ABBR_ARE_USED + uint tt_abbrind; // Index of start of abbreviation for this time type. +#endif + /* + We don't use tt_ttisstd and tt_ttisgmt members of original elsie-code + struct since we don't support POSIX-style TZ descriptions in variables. + */ +} TRAN_TYPE_INFO; + +/* Structure describing leap-second corrections. */ +typedef struct lsinfo +{ + my_time_t ls_trans; // Transition time + long ls_corr; // Correction to apply +} LS_INFO; + +/* + Structure with information describing ranges of my_time_t shifted to local + time (my_time_t + offset). Used for local TIME -> my_time_t conversion. + See comments for TIME_to_gmt_sec() for more info. +*/ +typedef struct revtinfo +{ + long rt_offset; // Offset of local time from UTC in seconds + uint rt_type; // Type of period 0 - Normal period. 1 - Spring time-gap +} REVT_INFO; + +#ifdef TZNAME_MAX +#define MY_TZNAME_MAX TZNAME_MAX +#endif +#ifndef TZNAME_MAX +#define MY_TZNAME_MAX 255 +#endif + +/* + Structure which fully describes time zone which is + described in our db or in zoneinfo files. +*/ +typedef struct st_time_zone_info +{ + uint leapcnt; // Number of leap-second corrections + uint timecnt; // Number of transitions between time types + uint typecnt; // Number of local time types + uint charcnt; // Number of characters used for abbreviations + uint revcnt; // Number of transition descr. for TIME->my_time_t conversion + /* The following are dynamical arrays are allocated in MEM_ROOT */ + my_time_t *ats; // Times of transitions between time types + unsigned char *types; // Local time types for transitions + TRAN_TYPE_INFO *ttis; // Local time types descriptions +#ifdef ABBR_ARE_USED + /* Storage for local time types abbreviations. They are stored as ASCIIZ */ + char *chars; +#endif + /* + Leap seconds corrections descriptions, this array is shared by + all time zones who use leap seconds. + */ + LS_INFO *lsis; + /* + Starting points and descriptions of shifted my_time_t (my_time_t + offset) + ranges on which shifted my_time_t -> my_time_t mapping is linear or undefined. + Used for tm -> my_time_t conversion. + */ + my_time_t *revts; + REVT_INFO *revtis; + /* + Time type which is used for times smaller than first transition or if + there are no transitions at all. + */ + TRAN_TYPE_INFO *fallback_tti; + +} TIME_ZONE_INFO; + + +static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage); + + +#if defined(TZINFO2SQL) || defined(TESTTIME) + +/* + Load time zone description from zoneinfo (TZinfo) file. + + SYNOPSIS + tz_load() + name - path to zoneinfo file + sp - TIME_ZONE_INFO structure to fill + + RETURN VALUES + 0 - Ok + 1 - Error +*/ +static my_bool +tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage) +{ + char *p; + int read_from_file; + uint i; + FILE *file; + + if (!(file= my_fopen(name, O_RDONLY|O_BINARY, MYF(MY_WME)))) + return 1; + { + union + { + struct tzhead tzhead; + char buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES + + TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES + +#ifdef ABBR_ARE_USED + max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) + +#endif + sizeof(LS_INFO) * TZ_MAX_LEAPS]; + } u; + uint ttisstdcnt; + uint ttisgmtcnt; + char *tzinfo_buf; + + read_from_file= my_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME)); + + if (my_fclose(file, MYF(MY_WME)) != 0) + return 1; + + if (read_from_file < (int)sizeof(struct tzhead)) + return 1; + + ttisstdcnt= int4net(u.tzhead.tzh_ttisgmtcnt); + ttisgmtcnt= int4net(u.tzhead.tzh_ttisstdcnt); + sp->leapcnt= int4net(u.tzhead.tzh_leapcnt); + sp->timecnt= int4net(u.tzhead.tzh_timecnt); + sp->typecnt= int4net(u.tzhead.tzh_typecnt); + sp->charcnt= int4net(u.tzhead.tzh_charcnt); + p= u.tzhead.tzh_charcnt + sizeof u.tzhead.tzh_charcnt; + if (sp->leapcnt > TZ_MAX_LEAPS || + sp->typecnt == 0 || sp->typecnt > TZ_MAX_TYPES || + sp->timecnt > TZ_MAX_TIMES || + sp->charcnt > TZ_MAX_CHARS || + (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) || + (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0)) + return 1; + if ((uint)(read_from_file - (p - u.buf)) < + sp->timecnt * 4 + /* ats */ + sp->timecnt + /* types */ + sp->typecnt * (4 + 2) + /* ttinfos */ + sp->charcnt + /* chars */ + sp->leapcnt * (4 + 4) + /* lsinfos */ + ttisstdcnt + /* ttisstds */ + ttisgmtcnt) /* ttisgmts */ + return 1; + + if (!(tzinfo_buf= (char *)alloc_root(storage, + ALIGN_SIZE(sp->timecnt * + sizeof(my_time_t)) + + ALIGN_SIZE(sp->timecnt) + + ALIGN_SIZE(sp->typecnt * + sizeof(TRAN_TYPE_INFO)) + +#ifdef ABBR_ARE_USED + ALIGN_SIZE(sp->charcnt) + +#endif + sp->leapcnt * sizeof(LS_INFO)))) + return 1; + + sp->ats= (my_time_t *)tzinfo_buf; + tzinfo_buf+= ALIGN_SIZE(sp->timecnt * sizeof(my_time_t)); + sp->types= (unsigned char *)tzinfo_buf; + tzinfo_buf+= ALIGN_SIZE(sp->timecnt); + sp->ttis= (TRAN_TYPE_INFO *)tzinfo_buf; + tzinfo_buf+= ALIGN_SIZE(sp->typecnt * sizeof(TRAN_TYPE_INFO)); +#ifdef ABBR_ARE_USED + sp->chars= tzinfo_buf; + tzinfo_buf+= ALIGN_SIZE(sp->charcnt); +#endif + sp->lsis= (LS_INFO *)tzinfo_buf; + + for (i= 0; i < sp->timecnt; i++, p+= 4) + sp->ats[i]= int4net(p); + + for (i= 0; i < sp->timecnt; i++) + { + sp->types[i]= (unsigned char) *p++; + if (sp->types[i] >= sp->typecnt) + return 1; + } + for (i= 0; i < sp->typecnt; i++) + { + TRAN_TYPE_INFO * ttisp; + + ttisp= &sp->ttis[i]; + ttisp->tt_gmtoff= int4net(p); + p+= 4; + ttisp->tt_isdst= (unsigned char) *p++; + if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) + return 1; + ttisp->tt_abbrind= (unsigned char) *p++; + if (ttisp->tt_abbrind > sp->charcnt) + return 1; + } + for (i= 0; i < sp->charcnt; i++) + sp->chars[i]= *p++; + sp->chars[i]= '\0'; /* ensure '\0' at end */ + for (i= 0; i < sp->leapcnt; i++) + { + LS_INFO *lsisp; + + lsisp= &sp->lsis[i]; + lsisp->ls_trans= int4net(p); + p+= 4; + lsisp->ls_corr= int4net(p); + p+= 4; + } + /* + Since we don't support POSIX style TZ definitions in variables we + don't read further like glibc or elsie code. + */ + } + + return prepare_tz_info(sp, storage); +} +#endif /* defined(TZINFO2SQL) || defined(TESTTIME) */ + + +/* + Finish preparation of time zone description for use in TIME_to_gmt_sec() + and gmt_sec_to_TIME() functions. + + SYNOPSIS + prepare_tz_info() + sp - pointer to time zone description + storage - pointer to MEM_ROOT where arrays for map allocated + + DESCRIPTION + First task of this function is to find fallback time type which will + be used if there are no transitions or we have moment in time before + any transitions. + Second task is to build "shifted my_time_t" -> my_time_t map used in + TIME -> my_time_t conversion. + Note: See description of TIME_to_gmt_sec() function first. + In order to perform TIME -> my_time_t conversion we need to build table + which defines "shifted by tz offset and leap seconds my_time_t" -> + my_time_t function wich is almost the same (except ranges of ambiguity) + as reverse function to piecewise linear function used for my_time_t -> + "shifted my_time_t" conversion and which is also specified as table in + zoneinfo file or in our db (It is specified as start of time type ranges + and time type offsets). So basic idea is very simple - let us iterate + through my_time_t space from one point of discontinuity of my_time_t -> + "shifted my_time_t" function to another and build our approximation of + reverse function. (Actually we iterate through ranges on which + my_time_t -> "shifted my_time_t" is linear function). + + RETURN VALUES + 0 Ok + 1 Error +*/ +static my_bool +prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage) +{ + my_time_t cur_t= MY_TIME_T_MIN; + my_time_t cur_l, end_t, end_l; + my_time_t cur_max_seen_l= MY_TIME_T_MIN; + long cur_offset, cur_corr, cur_off_and_corr; + uint next_trans_idx, next_leap_idx; + uint i; + /* + Temporary arrays where we will store tables. Needed because + we don't know table sizes ahead. (Well we can estimate their + upper bound but this will take extra space.) + */ + my_time_t revts[TZ_MAX_REV_RANGES]; + REVT_INFO revtis[TZ_MAX_REV_RANGES]; + + LINT_INIT(end_l); + + /* + Let us setup fallback time type which will be used if we have not any + transitions or if we have moment of time before first transition. + We will find first non-DST local time type and use it (or use first + local time type if all of them are DST types). + */ + for (i= 0; i < sp->typecnt && sp->ttis[i].tt_isdst; i++) + /* no-op */ ; + if (i == sp->typecnt) + i= 0; + sp->fallback_tti= &(sp->ttis[i]); + + + /* + Let us build shifted my_time_t -> my_time_t map. + */ + sp->revcnt= 0; + + /* Let us find initial offset */ + if (sp->timecnt == 0 || cur_t < sp->ats[0]) + { + /* + If we have not any transitions or t is before first transition we are using + already found fallback time type which index is already in i. + */ + next_trans_idx= 0; + } + else + { + /* cur_t == sp->ats[0] so we found transition */ + i= sp->types[0]; + next_trans_idx= 1; + } + + cur_offset= sp->ttis[i].tt_gmtoff; + + + /* let us find leap correction... unprobable, but... */ + for (next_leap_idx= 0; next_leap_idx < sp->leapcnt && + cur_t >= sp->lsis[next_leap_idx].ls_trans; + ++next_leap_idx) + continue; + + if (next_leap_idx > 0) + cur_corr= sp->lsis[next_leap_idx - 1].ls_corr; + else + cur_corr= 0; + + /* Iterate trough t space */ + while (sp->revcnt < TZ_MAX_REV_RANGES - 1) + { + cur_off_and_corr= cur_offset - cur_corr; + + /* + We assuming that cur_t could be only overflowed downwards, + we also assume that end_t won't be overflowed in this case. + */ + if (cur_off_and_corr < 0 && + cur_t < MY_TIME_T_MIN - cur_off_and_corr) + cur_t= MY_TIME_T_MIN - cur_off_and_corr; + + cur_l= cur_t + cur_off_and_corr; + + /* + Let us choose end_t as point before next time type change or leap + second correction. + */ + end_t= min((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1: + MY_TIME_T_MAX, + (next_leap_idx < sp->leapcnt) ? + sp->lsis[next_leap_idx].ls_trans - 1: MY_TIME_T_MAX); + /* + again assuming that end_t can be overlowed only in positive side + we also assume that end_t won't be overflowed in this case. + */ + if (cur_off_and_corr > 0 && + end_t > MY_TIME_T_MAX - cur_off_and_corr) + end_t= MY_TIME_T_MAX - cur_off_and_corr; + + end_l= end_t + cur_off_and_corr; + + + if (end_l > cur_max_seen_l) + { + /* We want special handling in the case of first range */ + if (cur_max_seen_l == MY_TIME_T_MIN) + { + revts[sp->revcnt]= cur_l; + revtis[sp->revcnt].rt_offset= cur_off_and_corr; + revtis[sp->revcnt].rt_type= 0; + sp->revcnt++; + cur_max_seen_l= end_l; + } + else + { + if (cur_l > cur_max_seen_l + 1) + { + /* We have a spring time-gap and we are not at the first range */ + revts[sp->revcnt]= cur_max_seen_l + 1; + revtis[sp->revcnt].rt_offset= revtis[sp->revcnt-1].rt_offset; + revtis[sp->revcnt].rt_type= 1; + sp->revcnt++; + if (sp->revcnt == TZ_MAX_TIMES + TZ_MAX_LEAPS + 1) + break; /* That was too much */ + cur_max_seen_l= cur_l - 1; + } + + /* Assume here end_l > cur_max_seen_l (because end_l>=cur_l) */ + + revts[sp->revcnt]= cur_max_seen_l + 1; + revtis[sp->revcnt].rt_offset= cur_off_and_corr; + revtis[sp->revcnt].rt_type= 0; + sp->revcnt++; + cur_max_seen_l= end_l; + } + } + + if (end_t == MY_TIME_T_MAX || + (cur_off_and_corr > 0) && + (end_t >= MY_TIME_T_MAX - cur_off_and_corr)) + /* end of t space */ + break; + + cur_t= end_t + 1; + + /* + Let us find new offset and correction. Because of our choice of end_t + cur_t can only be point where new time type starts or/and leap + correction is performed. + */ + if (sp->timecnt != 0 && cur_t >= sp->ats[0]) /* else reuse old offset */ + if (next_trans_idx < sp->timecnt && + cur_t == sp->ats[next_trans_idx]) + { + /* We are at offset point */ + cur_offset= sp->ttis[sp->types[next_trans_idx]].tt_gmtoff; + ++next_trans_idx; + } + + if (next_leap_idx < sp->leapcnt && + cur_t == sp->lsis[next_leap_idx].ls_trans) + { + /* we are at leap point */ + cur_corr= sp->lsis[next_leap_idx].ls_corr; + ++next_leap_idx; + } + } + + /* check if we have had enough space */ + if (sp->revcnt == TZ_MAX_REV_RANGES - 1) + return 1; + + /* set maximum end_l as finisher */ + revts[sp->revcnt]= end_l; + + /* Allocate arrays of proper size in sp and copy result there */ + if (!(sp->revts= (my_time_t *)alloc_root(storage, + sizeof(my_time_t) * (sp->revcnt + 1))) || + !(sp->revtis= (REVT_INFO *)alloc_root(storage, + sizeof(REVT_INFO) * sp->revcnt))) + return 1; + + memcpy(sp->revts, revts, sizeof(my_time_t) * (sp->revcnt + 1)); + memcpy(sp->revtis, revtis, sizeof(REVT_INFO) * sp->revcnt); + + return 0; +} + + +#if !defined(TZINFO2SQL) + +static const uint mon_lengths[2][MONS_PER_YEAR]= +{ + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +static const uint mon_starts[2][MONS_PER_YEAR]= +{ + { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, + { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } +}; + +static const uint year_lengths[2]= +{ + DAYS_PER_NYEAR, DAYS_PER_LYEAR +}; + +#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) + + +/* + Converts time from my_time_t representation (seconds in UTC since Epoch) + to broken down representation using given local time zone offset. + + SYNOPSIS + sec_to_TIME() + tmp - pointer to structure for broken down representation + t - my_time_t value to be converted + offset - local time zone offset + + DESCRIPTION + Convert my_time_t with offset to TIME struct. Differs from timesub + (from elsie code) because doesn't contain any leap correction and + TM_GMTOFF and is_dst setting and contains some MySQL specific + initialization. Funny but with removing of these we almost have + glibc's offtime function. +*/ +static void +sec_to_TIME(TIME * tmp, my_time_t t, long offset) +{ + long days; + long rem; + int y; + int yleap; + const uint *ip; + + days= t / SECS_PER_DAY; + rem= t % SECS_PER_DAY; + + /* + We do this as separate step after dividing t, because this + allows us handle times near my_time_t bounds without overflows. + */ + rem+= offset; + while (rem < 0) + { + rem+= SECS_PER_DAY; + days--; + } + while (rem >= SECS_PER_DAY) + { + rem -= SECS_PER_DAY; + days++; + } + tmp->hour= (uint)(rem / SECS_PER_HOUR); + rem= rem % SECS_PER_HOUR; + tmp->minute= (uint)(rem / SECS_PER_MIN); + /* + A positive leap second requires a special + representation. This uses "... ??:59:60" et seq. + */ + tmp->second= (uint)(rem % SECS_PER_MIN); + + y= EPOCH_YEAR; + while (days < 0 || days >= (long)year_lengths[yleap= isleap(y)]) + { + int newy; + + newy= y + days / DAYS_PER_NYEAR; + if (days < 0) + newy--; + days-= (newy - y) * DAYS_PER_NYEAR + + LEAPS_THRU_END_OF(newy - 1) - + LEAPS_THRU_END_OF(y - 1); + y= newy; + } + tmp->year= y; + + ip= mon_lengths[yleap]; + for (tmp->month= 0; days >= (long) ip[tmp->month]; tmp->month++) + days= days - (long) ip[tmp->month]; + tmp->month++; + tmp->day= (uint)(days + 1); + + /* filling MySQL specific TIME members */ + tmp->neg= 0; tmp->second_part= 0; + tmp->time_type= MYSQL_TIMESTAMP_DATETIME; +} + + +/* + Find time range wich contains given my_time_t value + + SYNOPSIS + find_time_range() + t - my_time_t value for which we looking for range + range_boundaries - sorted array of range starts. + higher_bound - number of ranges + + DESCRIPTION + Performs binary search for range which contains given my_time_t value. + It has sense if number of ranges is greater than zero and my_time_t value + is greater or equal than beginning of first range. It also assumes that + t belongs to some range specified or end of last is MY_TIME_T_MAX. + + With this localtime_r on real data may takes less time than with linear + search (I've seen 30% speed up). + + RETURN VALUE + Index of range to which t belongs +*/ +static uint +find_time_range(my_time_t t, const my_time_t *range_boundaries, + uint higher_bound) +{ + uint i, lower_bound= 0; + + /* + Function will work without this assertion but result would be meaningless. + */ + DBUG_ASSERT(higher_bound > 0 && t >= range_boundaries[0]); + + /* + Do binary search for minimal interval which contain t. We preserve: + range_boundaries[lower_bound] <= t < range_boundaries[higher_bound] + invariant and decrease this higher_bound - lower_bound gap twice + times on each step. + */ + + while (higher_bound - lower_bound > 1) + { + i= (lower_bound + higher_bound) >> 1; + if (range_boundaries[i] <= t) + lower_bound= i; + else + higher_bound= i; + } + return lower_bound; +} + +/* + Find local time transition for given my_time_t. + + SYNOPSIS + find_transition_type() + t - my_time_t value to be converted + sp - pointer to struct with time zone description + + RETURN VALUE + Pointer to structure in time zone description describing + local time type for given my_time_t. +*/ +static +const TRAN_TYPE_INFO * +find_transition_type(my_time_t t, const TIME_ZONE_INFO *sp) +{ + if (unlikely(sp->timecnt == 0 || t < sp->ats[0])) + { + /* + If we have not any transitions or t is before first transition let + us use fallback time type. + */ + return sp->fallback_tti; + } + + /* + Do binary search for minimal interval between transitions which + contain t. With this localtime_r on real data may takes less + time than with linear search (I've seen 30% speed up). + */ + return &(sp->ttis[sp->types[find_time_range(t, sp->ats, sp->timecnt)]]); +} + + +/* + Converts time in my_time_t representation (seconds in UTC since Epoch) to + broken down TIME representation in local time zone. + + SYNOPSIS + gmt_sec_to_TIME() + tmp - pointer to structure for broken down represenatation + sec_in_utc - my_time_t value to be converted + sp - pointer to struct with time zone description + + TODO + We can improve this function by creating joined array of transitions and + leap corrections. This will require adding extra field to TRAN_TYPE_INFO + for storing number of "extra" seconds to minute occured due to correction + (60th and 61st second, look how we calculate them as "hit" in this + function). + Under realistic assumptions about frequency of transitions the same array + can be used fot TIME -> my_time_t conversion. For this we need to + implement tweaked binary search which will take into account that some + TIME has two matching my_time_t ranges and some of them have none. +*/ +static void +gmt_sec_to_TIME(TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp) +{ + const TRAN_TYPE_INFO *ttisp; + const LS_INFO *lp; + long corr= 0; + int hit= 0; + int i; + + /* + Find proper transition (and its local time type) for our sec_in_utc value. + Funny but again by separating this step in function we receive code + which very close to glibc's code. No wonder since they obviously use + the same base and all steps are sensible. + */ + ttisp= find_transition_type(sec_in_utc, sp); + + /* + Let us find leap correction for our sec_in_utc value and number of extra + secs to add to this minute. + This loop is rarely used because most users will use time zones without + leap seconds, and even in case when we have such time zone there won't + be many iterations (we have about 22 corrections at this moment (2004)). + */ + for ( i= sp->leapcnt; i-- > 0; ) + { + lp= &sp->lsis[i]; + if (sec_in_utc >= lp->ls_trans) + { + if (sec_in_utc == lp->ls_trans) + { + hit= ((i == 0 && lp->ls_corr > 0) || + lp->ls_corr > sp->lsis[i - 1].ls_corr); + if (hit) + { + while (i > 0 && + sp->lsis[i].ls_trans == sp->lsis[i - 1].ls_trans + 1 && + sp->lsis[i].ls_corr == sp->lsis[i - 1].ls_corr + 1) + { + hit++; + i--; + } + } + } + corr= lp->ls_corr; + break; + } + } + + sec_to_TIME(tmp, sec_in_utc, ttisp->tt_gmtoff - corr); + + tmp->second+= hit; +} + + +/* + Converts local time in broken down representation to local + time zone analog of my_time_t represenation. + + SYNOPSIS + sec_since_epoch() + year, mon, mday, hour, min, sec - broken down representation. + + DESCRIPTION + Converts time in broken down representation to my_time_t representation + ignoring time zone. Note that we cannot convert back some valid _local_ + times near ends of my_time_t range because of my_time_t overflow. But we + ignore this fact now since MySQL will never pass such argument. + + RETURN VALUE + Seconds since epoch time representation. +*/ +static my_time_t +sec_since_epoch(int year, int mon, int mday, int hour, int min ,int sec) +{ +#ifndef WE_WANT_TO_HANDLE_UNORMALIZED_DATES + /* + It turns out that only whenever month is normalized or unnormalized + plays role. + */ + DBUG_ASSERT(mon > 0 && mon < 13); + long days= year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR + + LEAPS_THRU_END_OF(year - 1) - + LEAPS_THRU_END_OF(EPOCH_YEAR - 1); + days+= mon_starts[isleap(year)][mon - 1]; +#else + long norm_month= (mon - 1) % MONS_PER_YEAR; + long a_year= year + (mon - 1)/MONS_PER_YEAR - (int)(norm_month < 0); + long days= a_year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR + + LEAPS_THRU_END_OF(a_year - 1) - + LEAPS_THRU_END_OF(EPOCH_YEAR - 1); + days+= mon_starts[isleap(a_year)] + [norm_month + (norm_month < 0 ? MONS_PER_YEAR : 0)]; +#endif + days+= mday - 1; + + return ((days * HOURS_PER_DAY + hour) * MINS_PER_HOUR + min) * + SECS_PER_MIN + sec; +} + + +/* + Converts local time in broken down TIME representation to my_time_t + representation. + + SYNOPSIS + TIME_to_gmt_sec() + t - pointer to structure for broken down represenatation + sp - pointer to struct with time zone description + in_dst_time_gap - pointer to bool which is set to true if datetime + value passed doesn't really exist (i.e. falls into + spring time-gap) and is not touched otherwise. + + DESCRIPTION + This is mktime analog for MySQL. It is essentially different + from mktime (or hypotetical my_mktime) because: + - It has no idea about tm_isdst member so if it + has two answers it will give the smaller one + - If we are in spring time gap then it will return + beginning of the gap + - It can give wrong results near the ends of my_time_t due to + overflows, but we are safe since in MySQL we will never + call this function for such dates (its restriction for year + between 1970 and 2038 gives us several days of reserve). + - By default it doesn't support un-normalized input. But if + sec_since_epoch() function supports un-normalized dates + then this function should handle un-normalized input right, + altough it won't normalize structure TIME. + + Traditional approach to problem of conversion from broken down + representation to time_t is iterative. Both elsie's and glibc + implementation try to guess what time_t value should correspond to + this broken-down value. They perform localtime_r function on their + guessed value and then calculate the difference and try to improve + their guess. Elsie's code guesses time_t value in bit by bit manner, + Glibc's code tries to add difference between broken-down value + corresponding to guess and target broken-down value to current guess. + It also uses caching of last found correction... So Glibc's approach + is essentially faster but introduces some undetermenism (in case if + is_dst member of broken-down representation (tm struct) is not known + and we have two possible answers). + + We use completely different approach. It is better since it is both + faster than iterative implementations and fully determenistic. If you + look at my_time_t to TIME conversion then you'll find that it consist + of two steps: + The first is calculating shifted my_time_t value and the second - TIME + calculation from shifted my_time_t value (well it is a bit simplified + picture). The part in which we are interested in is my_time_t -> shifted + my_time_t conversion. It is piecewise linear function which is defined + by combination of transition times as break points and times offset + as changing function parameter. The possible inverse function for this + converison would be ambiguos but with MySQL's restrictions we can use + some function which is the same as inverse function on unambigiuos + ranges and coincides with one of branches of inverse function in + other ranges. Thus we just need to build table which will determine + this shifted my_time_t -> my_time_t conversion similar to existing + (my_time_t -> shifted my_time_t table). We do this in + prepare_tz_info function. + + TODO + If we can even more improve this function. For doing this we will need to + build joined map of transitions and leap corrections for gmt_sec_to_TIME() + function (similar to revts/revtis). Under realistic assumptions about + frequency of transitions we can use the same array for TIME_to_gmt_sec(). + We need to implement special version of binary search for this. Such step + will be beneficial to CPU cache since we will decrease data-set used for + conversion twice. + + RETURN VALUE + Seconds in UTC since Epoch. + 0 in case of error. +*/ +static my_time_t +TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, bool *in_dst_time_gap) +{ + my_time_t local_t; + uint saved_seconds; + uint i; + + DBUG_ENTER("TIME_to_gmt_sec"); + + /* We need this for correct leap seconds handling */ + if (t->second < SECS_PER_MIN) + saved_seconds= 0; + else + saved_seconds= t->second; + + /* + NOTE If we want to convert full my_time_t range without MySQL + restrictions we should catch overflow here somehow. + */ + + local_t= sec_since_epoch(t->year, t->month, t->day, + t->hour, t->minute, + saved_seconds ? 0 : t->second); + + /* We have at least one range */ + DBUG_ASSERT(sp->revcnt >= 1); + + if (local_t < sp->revts[0] || local_t > sp->revts[sp->revcnt]) + { + /* + This means that source time can't be represented as my_time_t due to + limited my_time_t range. + */ + DBUG_RETURN(0); + } + + /* binary search for our range */ + i= find_time_range(local_t, sp->revts, sp->revcnt); + + if (sp->revtis[i].rt_type) + { + /* + Oops! We are in spring time gap. + May be we should return error here? + Now we are returning my_time_t value corresponding to the + beginning of the gap. + */ + *in_dst_time_gap= 1; + DBUG_RETURN(sp->revts[i] - sp->revtis[i].rt_offset + saved_seconds); + } + else + DBUG_RETURN(local_t - sp->revtis[i].rt_offset + saved_seconds); +} + + +/* + End of elsie derived code. +*/ +#endif /* !defined(TZINFO2SQL) */ + + +#if !defined(TESTTIME) && !defined(TZINFO2SQL) + +/* + String with names of SYSTEM time zone. +*/ +static const String tz_SYSTEM_name("SYSTEM", 6, &my_charset_latin1); + + +/* + Instance of this class represents local time zone used on this system + (specified by TZ environment variable or via any other system mechanism). + It uses system functions (localtime_r, my_system_gmt_sec) for conversion + and is always available. Because of this it is used by default - if there + were no explicit time zone specified. On the other hand because of this + conversion methods provided by this class is significantly slower and + possibly less multi-threaded-friendly than corresponding Time_zone_db + methods so the latter should be preffered there it is possible. +*/ +class Time_zone_system : public Time_zone +{ +public: + virtual my_time_t TIME_to_gmt_sec(const TIME *t, + bool *in_dst_time_gap) const; + virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; + virtual const String * get_name() const; +}; + + +/* + Converts local time in system time zone in TIME representation + to its my_time_t representation. + + SYNOPSIS + TIME_to_gmt_sec() + t - pointer to TIME structure with local time in + broken-down representation. + in_dst_time_gap - pointer to bool which is set to true if datetime + value passed doesn't really exist (i.e. falls into + spring time-gap) and is not touched otherwise. + + DESCRIPTION + This method uses system function (localtime_r()) for conversion + local time in system time zone in TIME structure to its my_time_t + representation. Unlike the same function for Time_zone_db class + it it won't handle unnormalized input properly. Still it will + return lowest possible my_time_t in case of ambiguity or if we + provide time corresponding to the time-gap. + + You should call init_time() function before using this function. + + RETURN VALUE + Corresponding my_time_t value or 0 in case of error +*/ +my_time_t +Time_zone_system::TIME_to_gmt_sec(const TIME *t, bool *in_dst_time_gap) const +{ + long not_used; + return my_system_gmt_sec(t, ¬_used, in_dst_time_gap); +} + + +/* + Converts time from UTC seconds since Epoch (my_time_t) representation + to system local time zone broken-down representation. + + SYNOPSIS + gmt_sec_to_TIME() + tmp - pointer to TIME structure to fill-in + t - my_time_t value to be converted + + NOTE + We assume that value passed to this function will fit into time_t range + supported by localtime_r. This conversion is putting restriction on + TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least + for interaction with client then we can extend TIMESTAMP range down to + the 1902 easily. +*/ +void +Time_zone_system::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const +{ + struct tm tmp_tm; + time_t tmp_t= (time_t)t; + + localtime_r(&tmp_t, &tmp_tm); + localtime_to_TIME(tmp, &tmp_tm); + tmp->time_type= MYSQL_TIMESTAMP_DATETIME; +} + + +/* + Get name of time zone + + SYNOPSIS + get_name() + + RETURN VALUE + Name of time zone as String +*/ +const String * +Time_zone_system::get_name() const +{ + return &tz_SYSTEM_name; +} + + +/* + Instance of this class represents UTC time zone. It uses system gmtime_r + function for conversions and is always available. It is used only for + my_time_t -> TIME conversions in various UTC_... functions, it is not + intended for TIME -> my_time_t conversions and shouldn't be exposed to user. +*/ +class Time_zone_utc : public Time_zone +{ +public: + virtual my_time_t TIME_to_gmt_sec(const TIME *t, + bool *in_dst_time_gap) const; + virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; + virtual const String * get_name() const; +}; + + +/* + Convert UTC time from TIME representation to its my_time_t representation. + + SYNOPSIS + TIME_to_gmt_sec() + t - pointer to TIME structure with local time + in broken-down representation. + in_dst_time_gap - pointer to bool which is set to true if datetime + value passed doesn't really exist (i.e. falls into + spring time-gap) and is not touched otherwise. + + DESCRIPTION + Since Time_zone_utc is used only internally for my_time_t -> TIME + conversions, this function of Time_zone interface is not implemented for + this class and should not be called. + + RETURN VALUE + 0 +*/ +my_time_t +Time_zone_utc::TIME_to_gmt_sec(const TIME *t, bool *in_dst_time_gap) const +{ + /* Should be never called */ + DBUG_ASSERT(0); + return 0; +} + + +/* + Converts time from UTC seconds since Epoch (my_time_t) representation + to broken-down representation (also in UTC). + + SYNOPSIS + gmt_sec_to_TIME() + tmp - pointer to TIME structure to fill-in + t - my_time_t value to be converted + + NOTE + See note for apropriate Time_zone_system method. +*/ +void +Time_zone_utc::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const +{ + struct tm tmp_tm; + time_t tmp_t= (time_t)t; + gmtime_r(&tmp_t, &tmp_tm); + localtime_to_TIME(tmp, &tmp_tm); + tmp->time_type= MYSQL_TIMESTAMP_DATETIME; +} + + +/* + Get name of time zone + + SYNOPSIS + get_name() + + DESCRIPTION + Since Time_zone_utc is used only internally by SQL's UTC_* functions it + is not accessible directly, and hence this function of Time_zone + interface is not implemented for this class and should not be called. + + RETURN VALUE + 0 +*/ +const String * +Time_zone_utc::get_name() const +{ + /* Should be never called */ + DBUG_ASSERT(0); + return 0; +} + + +/* + Instance of this class represents some time zone which is + described in mysql.time_zone family of tables. +*/ +class Time_zone_db : public Time_zone +{ +public: + Time_zone_db(TIME_ZONE_INFO *tz_info_arg, const String * tz_name_arg); + virtual my_time_t TIME_to_gmt_sec(const TIME *t, + bool *in_dst_time_gap) const; + virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; + virtual const String * get_name() const; +private: + TIME_ZONE_INFO *tz_info; + const String *tz_name; +}; + + +/* + Initializes object representing time zone described by mysql.time_zone + tables. + + SYNOPSIS + Time_zone_db() + tz_info_arg - pointer to TIME_ZONE_INFO structure which is filled + according to db or other time zone description + (for example by my_tz_init()). + Several Time_zone_db instances can share one + TIME_ZONE_INFO structure. + tz_name_arg - name of time zone. +*/ +Time_zone_db::Time_zone_db(TIME_ZONE_INFO *tz_info_arg, + const String *tz_name_arg): + tz_info(tz_info_arg), tz_name(tz_name_arg) +{ +} + + +/* + Converts local time in time zone described from TIME + representation to its my_time_t representation. + + SYNOPSIS + TIME_to_gmt_sec() + t - pointer to TIME structure with local time + in broken-down representation. + in_dst_time_gap - pointer to bool which is set to true if datetime + value passed doesn't really exist (i.e. falls into + spring time-gap) and is not touched otherwise. + + DESCRIPTION + Please see ::TIME_to_gmt_sec for function description and + parameter restrictions. + + RETURN VALUE + Corresponding my_time_t value or 0 in case of error +*/ +my_time_t +Time_zone_db::TIME_to_gmt_sec(const TIME *t, bool *in_dst_time_gap) const +{ + return ::TIME_to_gmt_sec(t, tz_info, in_dst_time_gap); +} + + +/* + Converts time from UTC seconds since Epoch (my_time_t) representation + to local time zone described in broken-down representation. + + SYNOPSIS + gmt_sec_to_TIME() + tmp - pointer to TIME structure to fill-in + t - my_time_t value to be converted +*/ +void +Time_zone_db::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const +{ + ::gmt_sec_to_TIME(tmp, t, tz_info); +} + + +/* + Get name of time zone + + SYNOPSIS + get_name() + + RETURN VALUE + Name of time zone as ASCIIZ-string +*/ +const String * +Time_zone_db::get_name() const +{ + return tz_name; +} + + +/* + Instance of this class represents time zone which + was specified as offset from UTC. +*/ +class Time_zone_offset : public Time_zone +{ +public: + Time_zone_offset(long tz_offset_arg); + virtual my_time_t TIME_to_gmt_sec(const TIME *t, + bool *in_dst_time_gap) const; + virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; + virtual const String * get_name() const; + /* + This have to be public because we want to be able to access it from + my_offset_tzs_get_key() function + */ + long offset; +private: + /* Extra reserve because of snprintf */ + char name_buff[7+16]; + String name; +}; + + +/* + Initializes object representing time zone described by its offset from UTC. + + SYNOPSIS + Time_zone_offset() + tz_offset_arg - offset from UTC in seconds. + Positive for direction to east. +*/ +Time_zone_offset::Time_zone_offset(long tz_offset_arg): + offset(tz_offset_arg) +{ + uint hours= abs((int)(offset / SECS_PER_HOUR)); + uint minutes= abs((int)(offset % SECS_PER_HOUR / SECS_PER_MIN)); + ulong length= my_snprintf(name_buff, sizeof(name_buff), "%s%02d:%02d", + (offset>=0) ? "+" : "-", hours, minutes); + name.set(name_buff, length, &my_charset_latin1); +} + + +/* + Converts local time in time zone described as offset from UTC + from TIME representation to its my_time_t representation. + + SYNOPSIS + TIME_to_gmt_sec() + t - pointer to TIME structure with local time + in broken-down representation. + in_dst_time_gap - pointer to bool which should be set to true if + datetime value passed doesn't really exist + (i.e. falls into spring time-gap) and is not + touched otherwise. + It is not really used in this class. + + RETURN VALUE + Corresponding my_time_t value or 0 in case of error +*/ +my_time_t +Time_zone_offset::TIME_to_gmt_sec(const TIME *t, bool *in_dst_time_gap) const +{ + return sec_since_epoch(t->year, t->month, t->day, + t->hour, t->minute, t->second) - + offset; +} + + +/* + Converts time from UTC seconds since Epoch (my_time_t) representation + to local time zone described as offset from UTC and in broken-down + representation. + + SYNOPSIS + gmt_sec_to_TIME() + tmp - pointer to TIME structure to fill-in + t - my_time_t value to be converted +*/ +void +Time_zone_offset::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const +{ + sec_to_TIME(tmp, t, offset); +} + + +/* + Get name of time zone + + SYNOPSIS + get_name() + + RETURN VALUE + Name of time zone as pointer to String object +*/ +const String * +Time_zone_offset::get_name() const +{ + return &name; +} + + +static Time_zone_utc tz_UTC; +static Time_zone_system tz_SYSTEM; + +Time_zone *my_tz_UTC= &tz_UTC; +Time_zone *my_tz_SYSTEM= &tz_SYSTEM; + +static HASH tz_names; +static HASH offset_tzs; +static MEM_ROOT tz_storage; + +/* + These mutex protects offset_tzs and tz_storage. + These protection needed only when we are trying to set + time zone which is specified as offset, and searching for existing + time zone in offset_tzs or creating if it didn't existed before in + tz_storage. So contention is low. +*/ +static pthread_mutex_t tz_LOCK; +static bool tz_inited= 0; + +/* + This two static variables are inteded for holding info about leap seconds + shared by all time zones. +*/ +static uint tz_leapcnt= 0; +static LS_INFO *tz_lsis= 0; + + +typedef struct st_tz_names_entry: public Sql_alloc +{ + String name; + Time_zone *tz; +} TZ_NAMES_ENTRY; + + +/* + We are going to call both of these functions from C code so + they should obey C calling conventions. +*/ + +extern "C" byte* my_tz_names_get_key(TZ_NAMES_ENTRY *entry, uint *length, + my_bool not_used __attribute__((unused))) +{ + *length= entry->name.length(); + return (byte*) entry->name.ptr(); +} + +extern "C" byte* my_offset_tzs_get_key(Time_zone_offset *entry, uint *length, + my_bool not_used __attribute__((unused))) +{ + *length= sizeof(long); + return (byte*) &entry->offset; +} + + +/* + Initialize time zone support infrastructure. + + SYNOPSIS + my_tz_init() + thd - current thread object + default_tzname - default time zone or 0 if none. + bootstrap - indicates whenever we are in bootstrap mode + + DESCRIPTION + This function will init memory structures needed for time zone support, + it will register mandatory SYSTEM time zone in them. It will try to open + mysql.time_zone_leap_seconds table and and load information which further + will be shared among all time zones loaded. It will also try to load + information about default time zone. If system tables with time zone + descriptions don't exist it won't fail (unless default_tzname is time zone + from tables). If bootstrap parameter is true then this routine assumes that + we are in bootstrap mode and won't load time zone descriptions unless someone + specifies default time zone which is supposedly stored in those tables. + It'll also set default time zone if it is specified. + + RETURN VALUES + 0 - ok + 1 - Error +*/ +my_bool +my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) +{ + THD *thd; + TABLE_LIST tables; + TABLE *table; + TABLE *lock_ptr; + MYSQL_LOCK *lock; + TZ_NAMES_ENTRY *tmp_tzname; + my_bool return_val= 1; + int res; + uint not_used; + DBUG_ENTER("my_tz_init"); + + /* + To be able to run this from boot, we allocate a temporary THD + */ + if (!(thd= new THD)) + DBUG_RETURN(1); + thd->store_globals(); + + /* Init all memory structures that require explicit destruction */ + if (hash_init(&tz_names, &my_charset_latin1, 20, + 0, 0, (hash_get_key)my_tz_names_get_key, 0, 0)) + { + sql_print_error("Fatal error: OOM while initializing time zones"); + goto end; + } + if (hash_init(&offset_tzs, &my_charset_latin1, 26, 0, 0, + (hash_get_key)my_offset_tzs_get_key, 0, 0)) + { + sql_print_error("Fatal error: OOM while initializing time zones"); + hash_free(&tz_names); + goto end; + } + init_alloc_root(&tz_storage, 32 * 1024, 0); + VOID(pthread_mutex_init(&tz_LOCK, MY_MUTEX_INIT_FAST)); + tz_inited= 1; + + /* Add 'SYSTEM' time zone to tz_names hash */ + if (!(tmp_tzname= new (&tz_storage) TZ_NAMES_ENTRY())) + { + sql_print_error("Fatal error: OOM while initializing time zones"); + goto end_with_cleanup; + } + tmp_tzname->name.set("SYSTEM", 6, &my_charset_latin1); + tmp_tzname->tz= my_tz_SYSTEM; + if (my_hash_insert(&tz_names, (const byte *)tmp_tzname)) + { + sql_print_error("Fatal error: OOM while initializing time zones"); + goto end_with_cleanup; + } + + if (bootstrap) + { + /* If we are in bootstrap mode we should not load time zone tables */ + return_val= 0; + goto end_with_setting_default_tz; + } + + /* + After this point all memory structures are inited and we even can live + without time zone description tables. Now try to load information about + leap seconds shared by all time zones. + */ + + thd->db= my_strdup("mysql",MYF(0)); + thd->db_length= 5; // Safety + bzero((char*) &tables,sizeof(tables)); + tables.alias= tables.real_name= (char*)"time_zone_leap_second"; + tables.lock_type= TL_READ; + tables.db= thd->db; + + if (open_tables(thd, &tables, ¬_used)) + { + sql_print_error("Warning: Can't open time zone table: %s " + "trying to live without them", thd->net.last_error); + /* We will try emulate that everything is ok */ + return_val= 0; + goto end_with_setting_default_tz; + } + + lock_ptr= tables.table; + if (!(lock= mysql_lock_tables(thd, &lock_ptr, 1))) + { + sql_print_error("Fatal error: Can't lock time zone table: %s", + thd->net.last_error); + goto end_with_close; + } + + + /* + Now we are going to load leap seconds descriptions that are shared + between all time zones that use them. We are using index for getting + records in proper order. Since we share the same MEM_ROOT between + all time zones we just allocate enough memory for it first. + */ + if (!(tz_lsis= (LS_INFO*) alloc_root(&tz_storage, + sizeof(LS_INFO) * TZ_MAX_LEAPS))) + { + sql_print_error("Fatal error: Out of memory while loading " + "mysql.time_zone_leap_second table"); + goto end_with_unlock; + } + + table= tables.table; + table->file->ha_index_init(0); + tz_leapcnt= 0; + + res= table->file->index_first(table->record[0]); + + while (!res) + { + if (tz_leapcnt + 1 > TZ_MAX_LEAPS) + { + sql_print_error("Fatal error: While loading mysql.time_zone_leap_second" + " table: too much leaps"); + table->file->ha_index_end(); + goto end_with_unlock; + } + + tz_lsis[tz_leapcnt].ls_trans= (my_time_t)table->field[0]->val_int(); + tz_lsis[tz_leapcnt].ls_corr= (long)table->field[1]->val_int(); + + tz_leapcnt++; + + DBUG_PRINT("info", + ("time_zone_leap_second table: tz_leapcnt=%u tt_time=%lld offset=%ld", + tz_leapcnt, (longlong)tz_lsis[tz_leapcnt-1].ls_trans, + tz_lsis[tz_leapcnt-1].ls_corr)); + + res= table->file->index_next(table->record[0]); + } + + table->file->ha_index_end(); + + if (res != HA_ERR_END_OF_FILE) + { + sql_print_error("Fatal error: Error while loading " + "mysql.time_zone_leap_second table"); + goto end_with_unlock; + } + + /* + Loading of info about leap seconds succeeded + */ + + return_val= 0; + + +end_with_unlock: + mysql_unlock_tables(thd, lock); + +end_with_close: + close_thread_tables(thd); + thd->version--; /* Force close to free memory */ + +end_with_setting_default_tz: + /* If not an error and have default time zone try to load it */ + if (!return_val && default_tzname) + { + String tzname(default_tzname, &my_charset_latin1); + if (!(global_system_variables.time_zone= my_tz_find(thd, &tzname))) + { + sql_print_error("Fatal error: Illegal or unknown default time zone '%s'", + default_tzname); + return_val= 1; + } + } + +end_with_cleanup: + + /* if there were error free time zone describing structs */ + if (return_val) + my_tz_free(); +end: + delete thd; + if (org_thd) + org_thd->store_globals(); /* purecov: inspected */ + else + { + /* Remember that we don't have a THD */ + my_pthread_setspecific_ptr(THR_THD, 0); + my_pthread_setspecific_ptr(THR_MALLOC, 0); + } + DBUG_RETURN(return_val); +} + + +/* + Free resources used by time zone support infrastructure. + + SYNOPSIS + my_tz_free() +*/ + +void my_tz_free() +{ + if (tz_inited) + { + tz_inited= 0; + VOID(pthread_mutex_destroy(&tz_LOCK)); + hash_free(&offset_tzs); + hash_free(&tz_names); + free_root(&tz_storage, MYF(0)); + } +} + + +/* + Load time zone description from system tables. + + SYNOPSIS + tz_load_from_db() + thd - current thread object + tz_name - name of time zone that should be loaded. + + DESCRIPTION + This function will try to open system tables describing time zones + and to load information about time zone specified. It will also update + information in hash used for time zones lookup. + + RETURN VALUES + Returns pointer to newly created Time_zone object or 0 in case of error. + +*/ +static Time_zone* +tz_load_from_db(THD *thd, const String *tz_name) +{ + TABLE_LIST tables[4]; + TABLE *table= 0; + TABLE *lock_ptr[4]; + MYSQL_LOCK *lock; + char system_db_name[]= "mysql"; + char *db_save; + uint db_length_save; + TIME_ZONE_INFO *tz_info; + TZ_NAMES_ENTRY *tmp_tzname; + Time_zone *return_val= 0; + int res; + uint tzid, ttid; + my_time_t ttime; + char buff[MAX_FIELD_WIDTH]; + String abbr(buff, sizeof(buff), &my_charset_latin1); + char *alloc_buff, *tz_name_buff; + /* + Temporary arrays that are used for loading of data for filling + TIME_ZONE_INFO structure + */ + my_time_t ats[TZ_MAX_TIMES]; + unsigned char types[TZ_MAX_TIMES]; + TRAN_TYPE_INFO ttis[TZ_MAX_TYPES]; +#ifdef ABBR_ARE_USED + char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))]; +#endif + uint not_used; + + DBUG_ENTER("tz_load_from_db"); + + + /* Prepare tz_info for loading also let us make copy of time zone name */ + if (!(alloc_buff= alloc_root(&tz_storage, sizeof(TIME_ZONE_INFO) + + tz_name->length() + 1))) + { + sql_print_error("Error: Out of memory while loading time zone " + "description"); + return 0; + } + tz_info= (TIME_ZONE_INFO *)alloc_buff; + bzero(tz_info, sizeof(TIME_ZONE_INFO)); + tz_name_buff= alloc_buff + sizeof(TIME_ZONE_INFO); + /* + By writing zero to the end we guarantee that we can call ptr() + instead of c_ptr() for time zone name. + */ + strmake(tz_name_buff, tz_name->ptr(), tz_name->length()); + + /* + Open and lock time zone description tables + */ + db_save= thd->db; + db_length_save= thd->db_length; + thd->db= system_db_name; + thd->db_length= 5; + + bzero((char*) &tables,sizeof(tables)); + tables[0].alias= tables[0].real_name= (char*)"time_zone_name"; + tables[1].alias= tables[1].real_name= (char*)"time_zone"; + tables[2].alias= tables[2].real_name= (char*)"time_zone_transition"; + tables[3].alias= tables[3].real_name= (char*)"time_zone_transition_type"; + tables[0].next= tables+1; + tables[1].next= tables+2; + tables[2].next= tables+3; + tables[0].lock_type= tables[1].lock_type= tables[2].lock_type= + tables[3].lock_type= TL_READ; + tables[0].db= tables[1].db= tables[2].db= tables[3].db= thd->db; + if (open_tables(thd, tables, ¬_used)) + { + sql_print_error("Error: Can't open time zone tables: %s", + thd->net.last_error); + goto end; + } + + lock_ptr[0]= tables[0].table; + lock_ptr[1]= tables[1].table; + lock_ptr[2]= tables[2].table; + lock_ptr[3]= tables[3].table; + if (!(lock= mysql_lock_tables(thd, lock_ptr, 4))) + { + sql_print_error("Error: Can't lock time zone tables: %s", + thd->net.last_error); + goto end_with_close; + } + + /* + Let us find out time zone id by its name (there is only one index + and it is specifically for this purpose). + */ + table= tables[0].table; + + table->field[0]->store(tz_name->ptr(), tz_name->length(), &my_charset_latin1); + table->file->ha_index_init(0); + + if (table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, + 0, HA_READ_KEY_EXACT)) + { + sql_print_error("Error: Can't find description of time zone."); + goto end_with_unlock; + } + + tzid= (uint)table->field[1]->val_int(); + + table->file->ha_index_end(); + + /* + Now we need to lookup record in mysql.time_zone table in order to + understand whenever this timezone uses leap seconds (again we are + using the only index in this table). + */ + table= tables[1].table; + table->field[0]->store((longlong)tzid); + table->file->ha_index_init(0); + + if (table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, + 0, HA_READ_KEY_EXACT)) + { + sql_print_error("Error: Can't find description of time zone."); + goto end_with_unlock; + } + + /* If Uses_leap_seconds == 'Y' */ + if (table->field[1]->val_int() == 1) + { + tz_info->leapcnt= tz_leapcnt; + tz_info->lsis= tz_lsis; + } + + table->file->ha_index_end(); + + /* + Now we will iterate through records for out time zone in + mysql.time_zone_transition_type table. Because we want records + only for our time zone guess what are we doing? + Right - using special index. + */ + table= tables[3].table; + table->field[0]->store((longlong)tzid); + table->file->ha_index_init(0); + + // FIXME Is there any better approach than explicitly specifying 4 ??? + res= table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, + 4, HA_READ_KEY_EXACT); + while (!res) + { + ttid= (uint)table->field[1]->val_int(); + + if (ttid > TZ_MAX_TYPES) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition_type table: too big " + "transition type id"); + goto end_with_unlock; + } + + ttis[ttid].tt_gmtoff= (long)table->field[2]->val_int(); + ttis[ttid].tt_isdst= (table->field[3]->val_int() > 0); + +#ifdef ABBR_ARE_USED + // FIXME should we do something with duplicates here ? + table->field[4]->val_str(&abbr, &abbr); + if (tz_info->charcnt + abbr.length() + 1 > sizeof(chars)) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition_type table: not enough " + "room for abbreviations"); + goto end_with_unlock; + } + ttis[ttid].tt_abbrind= tz_info->charcnt; + memcpy(chars + tz_info->charcnt, abbr.ptr(), abbr.length()); + tz_info->charcnt+= abbr.length(); + chars[tz_info->charcnt]= 0; + tz_info->charcnt++; + + DBUG_PRINT("info", + ("time_zone_transition_type table: tz_id=%u tt_id=%u tt_gmtoff=%ld " + "abbr='%s' tt_isdst=%u", tzid, ttid, ttis[ttid].tt_gmtoff, + chars + ttis[ttid].tt_abbrind, ttis[ttid].tt_isdst)); +#else + DBUG_PRINT("info", + ("time_zone_transition_type table: tz_id=%u tt_id=%u tt_gmtoff=%ld " + "tt_isdst=%u", tzid, ttid, ttis[ttid].tt_gmtoff, ttis[ttid].tt_isdst)); +#endif + + /* ttid is increasing because we are reading using index */ + DBUG_ASSERT(ttid >= tz_info->typecnt); + + tz_info->typecnt= ttid + 1; + + res= table->file->index_next_same(table->record[0], + (byte*)table->field[0]->ptr, 4); + } + + if (res != HA_ERR_END_OF_FILE) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition_type table"); + goto end_with_unlock; + } + + table->file->ha_index_end(); + + + /* + At last we are doing the same thing for records in + mysql.time_zone_transition table. Here we additionaly need records + in ascending order by index scan also satisfies us. + */ + table= tables[2].table; + table->field[0]->store((longlong)tzid); + table->file->ha_index_init(0); + + // FIXME Is there any better approach than explicitly specifying 4 ??? + res= table->file->index_read(table->record[0], (byte*)table->field[0]->ptr, + 4, HA_READ_KEY_EXACT); + while (!res) + { + ttime= (my_time_t)table->field[1]->val_int(); + ttid= (uint)table->field[2]->val_int(); + + if (tz_info->timecnt + 1 > TZ_MAX_TIMES) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition table: " + "too much transitions"); + goto end_with_unlock; + } + if (ttid + 1 > tz_info->typecnt) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition table: " + "bad transition type id"); + goto end_with_unlock; + } + + ats[tz_info->timecnt]= ttime; + types[tz_info->timecnt]= ttid; + tz_info->timecnt++; + + DBUG_PRINT("info", + ("time_zone_transition table: tz_id=%u tt_time=%lld tt_id=%u", + tzid, (longlong)ttime, ttid)); + + res= table->file->index_next_same(table->record[0], + (byte*)table->field[0]->ptr, 4); + } + + /* + We have to allow HA_ERR_KEY_NOT_FOUND because some time zones + for example UTC have no transitons. + */ + if (res != HA_ERR_END_OF_FILE && res != HA_ERR_KEY_NOT_FOUND) + { + sql_print_error("Error while loading time zone description from " + "mysql.time_zone_transition table"); + goto end_with_unlock; + } + + table->file->ha_index_end(); + table= 0; + + /* + Now we will allocate memory and init TIME_ZONE_INFO structure. + */ + if (!(alloc_buff= alloc_root(&tz_storage, + ALIGN_SIZE(sizeof(my_time_t) * + tz_info->timecnt) + + ALIGN_SIZE(tz_info->timecnt) + +#ifdef ABBR_ARE_USED + ALIGN_SIZE(tz_info->charcnt) + +#endif + sizeof(TRAN_TYPE_INFO) * tz_info->typecnt))) + { + sql_print_error("Error: Out of memory while loading time zone " + "description"); + goto end_with_unlock; + } + + + tz_info->ats= (my_time_t *)alloc_buff; + memcpy(tz_info->ats, ats, tz_info->timecnt * sizeof(my_time_t)); + alloc_buff+= ALIGN_SIZE(sizeof(my_time_t) * tz_info->timecnt); + tz_info->types= (unsigned char *)alloc_buff; + memcpy(tz_info->types, types, tz_info->timecnt); + alloc_buff+= ALIGN_SIZE(tz_info->timecnt); +#ifdef ABBR_ARE_USED + tz_info->chars= alloc_buff; + memcpy(tz_info->chars, chars, tz_info->charcnt); + alloc_buff+= ALIGN_SIZE(tz_info->charcnt); +#endif + tz_info->ttis= (TRAN_TYPE_INFO *)alloc_buff; + memcpy(tz_info->ttis, ttis, tz_info->typecnt * sizeof(TRAN_TYPE_INFO)); + + /* + Let us check how correct our time zone description and build + reversed map. We don't check for tz->timecnt < 1 since it ok for GMT. + */ + if (tz_info->typecnt < 1) + { + sql_print_error("Error: loading time zone without transition types"); + goto end_with_unlock; + } + if (prepare_tz_info(tz_info, &tz_storage)) + { + sql_print_error("Error: Unable to build mktime map for time zone"); + goto end_with_unlock; + } + + + if (!(tmp_tzname= new (&tz_storage) TZ_NAMES_ENTRY()) || + !(tmp_tzname->tz= new (&tz_storage) Time_zone_db(tz_info, + &(tmp_tzname->name))) || + (tmp_tzname->name.set(tz_name_buff, tz_name->length(), + &my_charset_latin1), + my_hash_insert(&tz_names, (const byte *)tmp_tzname))) + { + sql_print_error("Error: Out of memory while loading time zone"); + goto end_with_unlock; + } + + /* + Loading of time zone succeeded + */ + return_val= tmp_tzname->tz; + +end_with_unlock: + + if (table) + table->file->ha_index_end(); + + mysql_unlock_tables(thd, lock); + +end_with_close: + close_thread_tables(thd); + +end: + thd->db= db_save; + thd->db_length= db_length_save; + DBUG_RETURN(return_val); +} + + +/* + Parse string that specifies time zone as offset from UTC. + + SYNOPSIS + str_to_offset() + str - pointer to string which contains offset + length - length of string + offset - out parameter for storing found offset in seconds. + + DESCRIPTION + This function parses string which contains time zone offset + in form similar to '+10:00' and converts found value to + seconds from UTC form (east is positive). + + RETURN VALUE + 0 - Ok + 1 - String doesn't contain valid time zone offset +*/ +my_bool +str_to_offset(const char *str, uint length, long *offset) +{ + const char *end= str + length; + my_bool negative; + ulong number_tmp; + long offset_tmp; + + if (length < 4) + return 1; + + if (*str == '+') + negative= 0; + else if (*str == '-') + negative= 1; + else + return 1; + str++; + + number_tmp= 0; + + while (str < end && my_isdigit(&my_charset_latin1, *str)) + { + number_tmp= number_tmp*10 + *str - '0'; + str++; + } + + if (str + 1 >= end || *str != ':') + return 1; + str++; + + offset_tmp = number_tmp * MINS_PER_HOUR; number_tmp= 0; + + while (str < end && my_isdigit(&my_charset_latin1, *str)) + { + number_tmp= number_tmp * 10 + *str - '0'; + str++; + } + + if (str != end) + return 1; + + offset_tmp= (offset_tmp + number_tmp) * SECS_PER_MIN; + + if (negative) + offset_tmp= -offset_tmp; + + /* + Check if offset is in range prescribed by standard + (from -12:59 to 13:00). + */ + + if (number_tmp > 59 || offset_tmp < -13 * SECS_PER_HOUR + 1 || + offset_tmp > 13 * SECS_PER_HOUR) + return 1; + + *offset= offset_tmp; + + return 0; +} + + +/* + Get Time_zone object for specified time zone. + + SYNOPSIS + my_tz_find() + thd - current thread + name - time zone specification + + DESCRIPTION + This function checks if name is one of time zones described in db, + predefined SYSTEM time zone or valid time zone specification as + offset from UTC (In last case it will create proper Time_zone_offset + object if there were not any.). If name is ok it returns corresponding + Time_zone object. + + Clients of this function are not responsible for releasing resources + occupied by returned Time_zone object so they can just forget pointers + to Time_zone object if they are not needed longer. + + Other important property of this function: if some Time_zone found once + it will be for sure found later, so this function can also be used for + checking if proper Time_zone object exists (and if there will be error + it will be reported during first call). + + If name pointer is 0 then this function returns 0 (this allows to pass 0 + values as parameter without additional external check and this property + is used by @@time_zone variable handling code). + + It will perform lookup in system tables (mysql.time_zone*) if needed. + + RETURN VALUE + Pointer to corresponding Time_zone object. 0 - in case of bad time zone + specification or other error. + +*/ +Time_zone * +my_tz_find(THD *thd, const String * name) +{ + TZ_NAMES_ENTRY *tmp_tzname; + Time_zone *result_tz= 0; + long offset; + + DBUG_ENTER("my_tz_find"); + DBUG_PRINT("enter", ("time zone name='%s'", + name ? ((String *)name)->c_ptr() : "NULL")); + + if (!name) + DBUG_RETURN(0); + + VOID(pthread_mutex_lock(&tz_LOCK)); + + if (!str_to_offset(name->ptr(), name->length(), &offset)) + { + + if (!(result_tz= (Time_zone_offset *)hash_search(&offset_tzs, + (const byte *)&offset, + sizeof(long)))) + { + DBUG_PRINT("info", ("Creating new Time_zone_offset object")); + + if (!(result_tz= new (&tz_storage) Time_zone_offset(offset)) || + my_hash_insert(&offset_tzs, (const byte *) result_tz)) + { + sql_print_error("Fatal error: Out of memory " + "while setting new time zone"); + result_tz= 0; + } + } + } else { + if ((tmp_tzname= (TZ_NAMES_ENTRY *)hash_search(&tz_names, + (const byte *)name->ptr(), + name->length()))) + result_tz= tmp_tzname->tz; + else + result_tz= tz_load_from_db(thd, name); + } + + VOID(pthread_mutex_unlock(&tz_LOCK)); + + DBUG_RETURN(result_tz); +} + +#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */ + + +#ifdef TZINFO2SQL +/* + This code belongs to mysql_tzinfo_to_sql converter command line utility. + This utility should be used by db admin for populating mysql.time_zone + tables. +*/ + + +/* + Print info about time zone described by TIME_ZONE_INFO struct as + SQL statements populating mysql.time_zone* tables. + + SYNOPSIS + print_tz_as_sql() + tz_name - name of time zone + sp - structure describing time zone +*/ +void +print_tz_as_sql(const char* tz_name, const TIME_ZONE_INFO *sp) +{ + uint i; + + /* Here we assume that all time zones have same leap correction tables */ + printf("INSERT INTO time_zone (Use_leap_seconds) VALUES ('%s');\n", + sp->leapcnt ? "Y" : "N"); + printf("SET @time_zone_id= LAST_INSERT_ID();\n"); + printf("INSERT INTO time_zone_name (Name, Time_zone_id) VALUES \ +('%s', @time_zone_id);\n", tz_name); + + if (sp->timecnt) + { + printf("INSERT INTO time_zone_transition \ +(Time_zone_id, Transition_time, Transition_type_id) VALUES\n"); + for (i= 0; i < sp->timecnt; i++) + printf("%s(@time_zone_id, %ld, %u)\n", (i == 0 ? " " : ","), sp->ats[i], + (uint)sp->types[i]); + printf(";\n"); + } + + printf("INSERT INTO time_zone_transition_type \ +(Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES\n"); + + for (i= 0; i < sp->typecnt; i++) + printf("%s(@time_zone_id, %u, %ld, %d, '%s')\n", (i == 0 ? " " : ","), i, + sp->ttis[i].tt_gmtoff, sp->ttis[i].tt_isdst, + sp->chars + sp->ttis[i].tt_abbrind); + printf(";\n"); +} + + +/* + Print info about leap seconds in time zone as SQL statements + populating mysql.time_zone_leap_second table. + + SYNOPSIS + print_tz_leaps_as_sql() + sp - structure describing time zone +*/ +void +print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) +{ + uint i; + + /* + We are assuming that there are only one list of leap seconds + For all timezones. + */ + printf("TRUNCATE TABLE time_zone_leap_second;\n"); + + if (sp->leapcnt) + { + printf("INSERT INTO time_zone_leap_second \ +(Transition_time, Correction) VALUES\n"); + for (i= 0; i < sp->leapcnt; i++) + printf("%s(%ld, %ld)\n", (i == 0 ? " " : ","), + sp->lsis[i].ls_trans, sp->lsis[i].ls_corr); + printf(";\n"); + } + + printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n"); +} + + +/* + Some variables used as temporary or as parameters + in recursive scan_tz_dir() code. +*/ +TIME_ZONE_INFO tz_info; +MEM_ROOT tz_storage; +char fullname[FN_REFLEN + 1]; +char *root_name_end; + + +/* + Recursively scan zoneinfo directory and print all found time zone + descriptions as SQL. + + SYNOPSIS + scan_tz_dir() + name_end - pointer to end of path to directory to be searched. + + DESCRIPTION + This auxiliary recursive function also uses several global + variables as in parameters and for storing temporary values. + + fullname - path to directory that should be scanned. + root_name_end - pointer to place in fullname where part with + path to initial directory ends. + current_tz_id - last used time zone id + + RETURN VALUE + 0 - Ok, 1 - Fatal error + +*/ +my_bool +scan_tz_dir(char * name_end) +{ + MY_DIR *cur_dir; + char *name_end_tmp; + uint i; + + if (!(cur_dir= my_dir(fullname, MYF(MY_WANT_STAT)))) + return 1; + + name_end= strmake(name_end, "/", FN_REFLEN - (name_end - fullname)); + + for (i= 0; i < cur_dir->number_off_files; i++) + { + if (cur_dir->dir_entry[i].name[0] != '.') + { + name_end_tmp= strmake(name_end, cur_dir->dir_entry[i].name, + FN_REFLEN - (name_end - fullname)); + + if (MY_S_ISDIR(cur_dir->dir_entry[i].mystat->st_mode)) + { + if (scan_tz_dir(name_end_tmp)) + { + my_dirend(cur_dir); + return 1; + } + } + else if (MY_S_ISREG(cur_dir->dir_entry[i].mystat->st_mode)) + { + init_alloc_root(&tz_storage, 32768, 0); + if (!tz_load(fullname, &tz_info, &tz_storage)) + print_tz_as_sql(root_name_end + 1, &tz_info); + else + fprintf(stderr, + "Warning: Unable to load '%s' as time zone. Skipping it.\n", + fullname); + free_root(&tz_storage, MYF(0)); + } + else + fprintf(stderr, "Warning: '%s' is not regular file or directory\n", + fullname); + } + } + + my_dirend(cur_dir); + + return 0; +} + + +int +main(int argc, char **argv) +{ + MY_INIT(argv[0]); + + if (argc != 2 && argc != 3) + { + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " %s timezonedir\n", argv[0]); + fprintf(stderr, " %s timezonefile timezonename\n", argv[0]); + fprintf(stderr, " %s --leap timezonefile\n", argv[0]); + return 1; + } + + if (argc == 2) + { + root_name_end= strmake(fullname, argv[1], FN_REFLEN); + + printf("TRUNCATE TABLE time_zone;\n"); + printf("TRUNCATE TABLE time_zone_name;\n"); + printf("TRUNCATE TABLE time_zone_transition;\n"); + printf("TRUNCATE TABLE time_zone_transition_type;\n"); + + if (scan_tz_dir(root_name_end)) + { + fprintf(stderr, "There were fatal errors during processing " + "of zoneinfo directory\n"); + return 1; + } + + printf("ALTER TABLE time_zone_transition " + "ORDER BY Time_zone_id, Transition_time;\n"); + printf("ALTER TABLE time_zone_transition_type " + "ORDER BY Time_zone_id, Transition_type_id;\n"); + } + else + { + init_alloc_root(&tz_storage, 32768, 0); + + if (strcmp(argv[1], "--leap") == 0) + { + if (tz_load(argv[2], &tz_info, &tz_storage)) + { + fprintf(stderr, "Problems with zoneinfo file '%s'\n", argv[2]); + return 1; + } + print_tz_leaps_as_sql(&tz_info); + } + else + { + if (tz_load(argv[1], &tz_info, &tz_storage)) + { + fprintf(stderr, "Problems with zoneinfo file '%s'\n", argv[2]); + return 1; + } + print_tz_as_sql(argv[2], &tz_info); + } + + free_root(&tz_storage, MYF(0)); + } + + return 0; +} + +#endif /* defined(TZINFO2SQL) */ + + +#ifdef TESTTIME + +/* + Some simple brute-force test wich allowed to catch a pair of bugs. + Also can provide interesting facts about system's time zone support + implementation. +*/ + +#ifndef CHAR_BIT +#define CHAR_BIT 8 +#endif + +#ifndef TYPE_BIT +#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) +#endif + +#ifndef TYPE_SIGNED +#define TYPE_SIGNED(type) (((type) -1) < 0) +#endif + +my_bool +is_equal_TIME_tm(const TIME* time_arg, const struct tm * tm_arg) +{ + return (time_arg->year == (uint)tm_arg->tm_year+TM_YEAR_BASE) && + (time_arg->month == (uint)tm_arg->tm_mon+1) && + (time_arg->day == (uint)tm_arg->tm_mday) && + (time_arg->hour == (uint)tm_arg->tm_hour) && + (time_arg->minute == (uint)tm_arg->tm_min) && + (time_arg->second == (uint)tm_arg->tm_sec) && + time_arg->second_part == 0; +} + + +int +main(int argc, char **argv) +{ + my_bool localtime_negative; + TIME_ZONE_INFO tz_info; + struct tm tmp; + TIME time_tmp; + time_t t, t1, t2; + char fullname[FN_REFLEN+1]; + char *str_end; + long not_used; + bool not_used_2; + MEM_ROOT tz_storage; + + MY_INIT(argv[0]); + + init_alloc_root(&tz_storage, 32768, 0); + + /* let us set some well known timezone */ + setenv("TZ", "MET", 1); + tzset(); + + /* Some initial time zone related system info */ + printf("time_t: %s %u bit\n", TYPE_SIGNED(time_t) ? "signed" : "unsigned", + (uint)TYPE_BIT(time_t)); + if (TYPE_SIGNED(time_t)) + { + t= -100; + localtime_negative= test(localtime_r(&t, &tmp) != 0); + printf("localtime_r %s negative params \ + (time_t=%d is %d-%d-%d %d:%d:%d)\n", + (localtime_negative ? "supports" : "doesn't support"), (int)t, + TM_YEAR_BASE + tmp.tm_year, tmp.tm_mon + 1, tmp.tm_mday, + tmp.tm_hour, tmp.tm_min, tmp.tm_sec); + + printf("mktime %s negative results (%d)\n", + (t == mktime(&tmp) ? "doesn't support" : "supports"), + (int)mktime(&tmp)); + } + + tmp.tm_year= 103; tmp.tm_mon= 2; tmp.tm_mday= 30; + tmp.tm_hour= 2; tmp.tm_min= 30; tmp.tm_sec= 0; tmp.tm_isdst= -1; + t= mktime(&tmp); + printf("mktime returns %s for spring time gap (%d)\n", + (t != (time_t)-1 ? "something" : "error"), (int)t); + + tmp.tm_year= 103; tmp.tm_mon= 8; tmp.tm_mday= 1; + tmp.tm_hour= 0; tmp.tm_min= 0; tmp.tm_sec= 0; tmp.tm_isdst= 0; + t= mktime(&tmp); + printf("mktime returns %s for non existing date (%d)\n", + (t != (time_t)-1 ? "something" : "error"), (int)t); + + tmp.tm_year= 103; tmp.tm_mon= 8; tmp.tm_mday= 1; + tmp.tm_hour= 25; tmp.tm_min=0; tmp.tm_sec=0; tmp.tm_isdst=1; + t= mktime(&tmp); + printf("mktime %s unnormalized input (%d)\n", + (t != (time_t)-1 ? "handles" : "doesn't handle"), (int)t); + + tmp.tm_year= 103; tmp.tm_mon= 9; tmp.tm_mday= 26; + tmp.tm_hour= 0; tmp.tm_min= 30; tmp.tm_sec= 0; tmp.tm_isdst= 1; + mktime(&tmp); + tmp.tm_hour= 2; tmp.tm_isdst= -1; + t= mktime(&tmp); + tmp.tm_hour= 4; tmp.tm_isdst= 0; + mktime(&tmp); + tmp.tm_hour= 2; tmp.tm_isdst= -1; + t1= mktime(&tmp); + printf("mktime is %s (%d %d)\n", + (t == t1 ? "determenistic" : "is non-determenistic"), + (int)t, (int)t1); + + /* Let us load time zone description */ + str_end= strmake(fullname, TZDIR, FN_REFLEN); + strmake(str_end, "/MET", FN_REFLEN - (str_end - fullname)); + + if (tz_load(fullname, &tz_info, &tz_storage)) + { + printf("Unable to load time zone info from '%s'\n", fullname); + free_root(&tz_storage, MYF(0)); + return 1; + } + + printf("Testing our implementation\n"); + + if (TYPE_SIGNED(time_t) && localtime_negative) + { + for (t= -40000; t < 20000; t++) + { + localtime_r(&t, &tmp); + gmt_sec_to_TIME(&time_tmp, (my_time_t)t, &tz_info); + if (!is_equal_TIME_tm(&time_tmp, &tmp)) + { + printf("Problem with negative time_t = %d\n", (int)t); + free_root(&tz_storage, MYF(0)); + return 1; + } + } + printf("gmt_sec_to_TIME = localtime for time_t in [-40000,20000) range\n"); + } + + for (t= 1000000000; t < 1100000000; t+= 13) + { + localtime_r(&t,&tmp); + gmt_sec_to_TIME(&time_tmp, (my_time_t)t, &tz_info); + + if (!is_equal_TIME_tm(&time_tmp, &tmp)) + { + printf("Problem with time_t = %d\n", (int)t); + free_root(&tz_storage, MYF(0)); + return 1; + } + } + printf("gmt_sec_to_TIME = localtime for time_t in [1000000000,1100000000) range\n"); + + init_time(); + + /* + Be careful here! my_system_gmt_sec doesn't fully handle unnormalized + dates. + */ + for (time_tmp.year= 1980; time_tmp.year < 2010; time_tmp.year++) + for (time_tmp.month= 1; time_tmp.month < 13; time_tmp.month++) + for (time_tmp.day= 1; + time_tmp.day < mon_lengths[isleap(time_tmp.year)][time_tmp.month-1]; + time_tmp.day++) + for (time_tmp.hour= 0; time_tmp.hour < 24; time_tmp.hour++) + for (time_tmp.minute= 0; time_tmp.minute < 60; time_tmp.minute+= 5) + for (time_tmp.second=0; time_tmp.second<60; time_tmp.second+=25) + { + t= (time_t)my_system_gmt_sec(&time_tmp, ¬_used, ¬_used_2); + t1= (time_t)TIME_to_gmt_sec(&time_tmp, &tz_info, ¬_used_2); + if (t != t1) + { + /* + We need special handling during autumn since my_system_gmt_sec + prefers greater time_t values (in MET) for ambiguity. + And BTW that is a bug which should be fixed !!! + */ + tmp.tm_year= time_tmp.year - TM_YEAR_BASE; + tmp.tm_mon= time_tmp.month - 1; + tmp.tm_mday= time_tmp.day; + tmp.tm_hour= time_tmp.hour; + tmp.tm_min= time_tmp.minute; + tmp.tm_sec= time_tmp.second; + tmp.tm_isdst= 1; + + t2= mktime(&tmp); + + if (t1 == t2) + continue; + + printf("Problem: %u/%u/%u %u:%u:%u with times t=%d, t1=%d\n", + time_tmp.year, time_tmp.month, time_tmp.day, + time_tmp.hour, time_tmp.minute, time_tmp.second, + (int)t,(int)t1); + + free_root(&tz_storage, MYF(0)); + return 1; + } + } + + printf("TIME_to_gmt_sec = my_system_gmt_sec for test range\n"); + + free_root(&tz_storage, MYF(0)); + return 0; +} + +#endif /* defined(TESTTIME) */ diff --git a/sql/tztime.h b/sql/tztime.h new file mode 100644 index 00000000000..334b14f4fc4 --- /dev/null +++ b/sql/tztime.h @@ -0,0 +1,79 @@ +/* Copyright (C) 2004 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 */ + + +#ifdef __GNUC__ +#pragma interface /* gcc class interface */ +#endif + +/* + Portable time_t replacement. + Should be signed and hold seconds for 1902-2038 range. +*/ +typedef long my_time_t; +#define MY_TIME_T_MAX LONG_MAX +#define MY_TIME_T_MIN LONG_MIN + +#if !defined(TESTTIME) && !defined(TZINFO2SQL) +/* + This class represents abstract time zone and provides + basic interface for TIME <-> my_time_t conversion. + Actual time zones which are specified by DB, or via offset + or use system functions are its descendants. +*/ +class Time_zone: public Sql_alloc +{ +public: + /* + Converts local time in broken down TIME representation to + my_time_t (UTC seconds since Epoch) represenation. + Returns 0 in case of error. Sets in_dst_time_gap to true if date provided + falls into spring time-gap (or lefts it untouched otherwise). + */ + virtual my_time_t TIME_to_gmt_sec(const TIME *t, + bool *in_dst_time_gap) const = 0; + /* + Converts time in my_time_t representation to local time in + broken down TIME representation. + */ + virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const = 0; + /* + Because of constness of String returned by get_name() time zone name + have to be already zeroended to be able to use String::ptr() instead + of c_ptr(). + */ + virtual const String * get_name() const = 0; + + /* + We need this only for surpressing warnings, objects of this type are + allocated on MEM_ROOT and should not require destruction. + */ + virtual ~Time_zone() {}; +}; + +extern Time_zone * my_tz_UTC; +extern Time_zone * my_tz_SYSTEM; +extern Time_zone * my_tz_find(THD *thd, const String *name); +extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap); +extern void my_tz_free(); + +/* + Maximum length of time zone name that we support + (Time zone name is char(64) in db) +*/ +#define MAX_TIME_ZONE_NAME_LENGTH 72 + +#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */ diff --git a/sql/unireg.cc b/sql/unireg.cc index bab021aed59..b5f6c3546a4 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -29,7 +29,6 @@ #include <m_ctype.h> #define FCOMP 17 /* Bytes for a packed field */ -#define FCOMP 17 /* Bytes for a packed field */ static uchar * pack_screens(List<create_field> &create_fields, uint *info_length, uint *screens, bool small_file); @@ -633,6 +632,7 @@ static bool make_empty_rec(File file,enum db_type table_type, DBUG_RETURN(1); } + table.in_use= current_thd; table.db_low_byte_first= handler->low_byte_first(); table.blob_ptr_size=portable_sizeof_char_ptr; |