summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore1
-rw-r--r--BitKeeper/etc/collapsed4
-rwxr-xr-xCMakeLists.txt6
-rw-r--r--Makefile.am10
-rw-r--r--client/mysql.cc69
-rw-r--r--client/mysqltest.c106
-rw-r--r--config/ac-macros/yassl.m43
-rw-r--r--configure.in4
-rw-r--r--extra/Makefile.am10
-rwxr-xr-xextra/yassl/CMakeLists.txt2
-rw-r--r--extra/yassl/FLOSS-EXCEPTIONS3
-rw-r--r--extra/yassl/Makefile.am2
-rw-r--r--extra/yassl/README13
-rw-r--r--extra/yassl/examples/client/client.cpp31
-rw-r--r--extra/yassl/examples/echoclient/echoclient.cpp15
-rw-r--r--extra/yassl/examples/echoserver/echoserver.cpp35
-rw-r--r--extra/yassl/examples/server/server.cpp27
-rw-r--r--extra/yassl/include/buffer.hpp7
-rw-r--r--extra/yassl/include/cert_wrapper.hpp11
-rw-r--r--extra/yassl/include/crypto_wrapper.hpp12
-rw-r--r--extra/yassl/include/factory.hpp18
-rw-r--r--extra/yassl/include/openssl/ssl.h4
-rw-r--r--extra/yassl/include/socket_wrapper.hpp2
-rw-r--r--extra/yassl/include/yassl_error.hpp6
-rw-r--r--extra/yassl/include/yassl_imp.hpp7
-rw-r--r--extra/yassl/include/yassl_int.hpp106
-rw-r--r--extra/yassl/include/yassl_types.hpp38
-rw-r--r--extra/yassl/src/Makefile.am6
-rw-r--r--extra/yassl/src/cert_wrapper.cpp31
-rw-r--r--extra/yassl/src/crypto_wrapper.cpp35
-rw-r--r--extra/yassl/src/handshake.cpp83
-rw-r--r--extra/yassl/src/socket_wrapper.cpp12
-rw-r--r--extra/yassl/src/ssl.cpp209
-rw-r--r--extra/yassl/src/template_instnt.cpp18
-rw-r--r--extra/yassl/src/yassl.cpp12
-rw-r--r--extra/yassl/src/yassl_error.cpp14
-rw-r--r--extra/yassl/src/yassl_imp.cpp46
-rw-r--r--extra/yassl/src/yassl_int.cpp249
-rwxr-xr-xextra/yassl/taocrypt/CMakeLists.txt2
-rw-r--r--extra/yassl/taocrypt/COPYING340
-rw-r--r--extra/yassl/taocrypt/INSTALL229
-rw-r--r--extra/yassl/taocrypt/Makefile.am2
-rw-r--r--extra/yassl/taocrypt/README37
-rw-r--r--extra/yassl/taocrypt/benchmark/Makefile.am6
-rw-r--r--extra/yassl/taocrypt/include/asn.hpp6
-rw-r--r--extra/yassl/taocrypt/include/block.hpp12
-rw-r--r--extra/yassl/taocrypt/include/blowfish.hpp6
-rw-r--r--extra/yassl/taocrypt/include/error.hpp4
-rw-r--r--extra/yassl/taocrypt/include/file.hpp2
-rw-r--r--extra/yassl/taocrypt/include/integer.hpp2
-rw-r--r--extra/yassl/taocrypt/include/misc.hpp17
-rw-r--r--extra/yassl/taocrypt/include/pwdbased.hpp2
-rw-r--r--extra/yassl/taocrypt/include/twofish.hpp6
-rw-r--r--extra/yassl/taocrypt/mySTL/algorithm.hpp (renamed from extra/yassl/mySTL/algorithm.hpp)2
-rw-r--r--extra/yassl/taocrypt/mySTL/helpers.hpp (renamed from extra/yassl/mySTL/helpers.hpp)41
-rw-r--r--extra/yassl/taocrypt/mySTL/list.hpp (renamed from extra/yassl/mySTL/list.hpp)151
-rw-r--r--extra/yassl/taocrypt/mySTL/memory.hpp (renamed from extra/yassl/mySTL/memory.hpp)29
-rw-r--r--extra/yassl/taocrypt/mySTL/memory_array.hpp142
-rw-r--r--extra/yassl/taocrypt/mySTL/pair.hpp (renamed from extra/yassl/mySTL/pair.hpp)0
-rw-r--r--extra/yassl/taocrypt/mySTL/stdexcept.hpp (renamed from extra/yassl/mySTL/stdexcept.hpp)0
-rw-r--r--extra/yassl/taocrypt/mySTL/vector.hpp (renamed from extra/yassl/mySTL/vector.hpp)13
-rw-r--r--extra/yassl/taocrypt/src/Makefile.am6
-rw-r--r--extra/yassl/taocrypt/src/algebra.cpp15
-rw-r--r--extra/yassl/taocrypt/src/asn.cpp9
-rw-r--r--extra/yassl/taocrypt/src/blowfish.cpp2
-rw-r--r--extra/yassl/taocrypt/src/crypto.cpp39
-rw-r--r--extra/yassl/taocrypt/src/des.cpp9
-rw-r--r--extra/yassl/taocrypt/src/dh.cpp2
-rw-r--r--extra/yassl/taocrypt/src/integer.cpp12
-rw-r--r--extra/yassl/taocrypt/src/md4.cpp10
-rw-r--r--extra/yassl/taocrypt/src/md5.cpp11
-rw-r--r--extra/yassl/taocrypt/src/misc.cpp9
-rw-r--r--extra/yassl/taocrypt/src/random.cpp68
-rw-r--r--extra/yassl/taocrypt/src/ripemd.cpp10
-rw-r--r--extra/yassl/taocrypt/src/sha.cpp11
-rw-r--r--extra/yassl/taocrypt/src/template_instnt.cpp7
-rw-r--r--extra/yassl/taocrypt/test/Makefile.am6
-rw-r--r--extra/yassl/testsuite/Makefile.am11
-rw-r--r--extra/yassl/testsuite/test.hpp51
-rw-r--r--include/m_ctype.h19
-rw-r--r--include/m_string.h3
-rw-r--r--include/my_base.h7
-rw-r--r--include/my_global.h42
-rw-r--r--include/my_sys.h26
-rw-r--r--include/myisam.h2
-rw-r--r--include/mysql.h6
-rw-r--r--include/mysql_com.h8
-rw-r--r--innobase/ibuf/ibuf0ibuf.c19
-rw-r--r--innobase/include/data0type.h4
-rw-r--r--innobase/include/data0type.ic9
-rw-r--r--innobase/include/univ.i2
-rw-r--r--innobase/srv/srv0start.c2
-rw-r--r--libmysql/libmysql.c8
-rw-r--r--libmysqld/lib_sql.cc2
-rw-r--r--myisam/mi_check.c306
-rw-r--r--myisam/mi_delete.c2
-rw-r--r--myisam/mi_locking.c15
-rw-r--r--myisam/mi_open.c5
-rw-r--r--myisam/mi_packrec.c76
-rw-r--r--myisam/mi_range.c15
-rw-r--r--myisam/myisam_ftdump.c3
-rw-r--r--myisam/myisamdef.h32
-rw-r--r--myisam/sort.c134
-rw-r--r--myisammrg/myrg_locking.c13
-rw-r--r--myisammrg/myrg_open.c10
-rw-r--r--myisammrg/myrg_queue.c2
-rw-r--r--mysql-test/lib/mtr_im.pl761
-rw-r--r--mysql-test/lib/mtr_process.pl709
-rw-r--r--mysql-test/lib/mtr_stress.pl1
-rwxr-xr-xmysql-test/mysql-test-run.pl150
-rw-r--r--mysql-test/r/analyse.result13
-rw-r--r--mysql-test/r/bdb.result72
-rw-r--r--mysql-test/r/client_xml.result2
-rw-r--r--mysql-test/r/ctype_gbk.result10
-rw-r--r--mysql-test/r/ctype_utf8.result105
-rw-r--r--mysql-test/r/delayed.result174
-rw-r--r--mysql-test/r/execution_constants.result12
-rw-r--r--mysql-test/r/func_gconcat.result5
-rw-r--r--mysql-test/r/func_group.result26
-rw-r--r--mysql-test/r/func_str.result4
-rw-r--r--mysql-test/r/func_time.result12
-rw-r--r--mysql-test/r/gis-rtree.result10
-rw-r--r--mysql-test/r/group_by.result116
-rw-r--r--mysql-test/r/group_min_max.result20
-rw-r--r--mysql-test/r/im_daemon_life_cycle.result14
-rw-r--r--mysql-test/r/innodb.result16
-rw-r--r--mysql-test/r/innodb_mysql.result16
-rw-r--r--mysql-test/r/loaddata.result7
-rw-r--r--mysql-test/r/merge.result21
-rw-r--r--mysql-test/r/myisam.result142
-rw-r--r--mysql-test/r/mysql.result10
-rw-r--r--mysql-test/r/mysqltest.result5
-rw-r--r--mysql-test/r/olap.result15
-rw-r--r--mysql-test/r/ps.result21
-rw-r--r--mysql-test/r/ps_2myisam.result48
-rw-r--r--mysql-test/r/ps_3innodb.result48
-rw-r--r--mysql-test/r/ps_4heap.result48
-rw-r--r--mysql-test/r/ps_5merge.result96
-rw-r--r--mysql-test/r/ps_6bdb.result48
-rw-r--r--mysql-test/r/ps_7ndb.result48
-rw-r--r--mysql-test/r/rename.result10
-rw-r--r--mysql-test/r/repair.result38
-rw-r--r--mysql-test/r/round.result272
-rw-r--r--mysql-test/r/rpl_insert_id.result147
-rw-r--r--mysql-test/r/rpl_rewrite_db.result7
-rw-r--r--mysql-test/r/select.result96
-rw-r--r--mysql-test/r/sp-vars.result2
-rw-r--r--mysql-test/r/sp.result18
-rw-r--r--mysql-test/r/strict.result12
-rw-r--r--mysql-test/r/subselect.result77
-rw-r--r--mysql-test/r/subselect3.result153
-rw-r--r--mysql-test/r/temp_table.result17
-rw-r--r--mysql-test/r/trigger.result12
-rw-r--r--mysql-test/r/type_bit.result8
-rw-r--r--mysql-test/r/type_datetime.result12
-rw-r--r--mysql-test/r/type_decimal.result11
-rw-r--r--mysql-test/r/type_enum.result9
-rw-r--r--mysql-test/r/type_float.result7
-rw-r--r--mysql-test/r/type_newdecimal.result8
-rw-r--r--mysql-test/r/udf.result79
-rw-r--r--mysql-test/r/view.result14
-rw-r--r--mysql-test/r/warnings.result116
-rw-r--r--mysql-test/t/analyse.test13
-rw-r--r--mysql-test/t/bdb-deadlock.test8
-rw-r--r--mysql-test/t/ctype_gbk.test10
-rw-r--r--mysql-test/t/ctype_utf8.test100
-rw-r--r--mysql-test/t/delayed.test148
-rw-r--r--mysql-test/t/execution_constants.test74
-rw-r--r--mysql-test/t/flush.test8
-rw-r--r--mysql-test/t/flush_block_commit.test3
-rw-r--r--mysql-test/t/func_gconcat.test1
-rw-r--r--mysql-test/t/func_group.test25
-rw-r--r--mysql-test/t/func_time.test19
-rw-r--r--mysql-test/t/gis-rtree.test10
-rw-r--r--mysql-test/t/group_by.test46
-rw-r--r--mysql-test/t/group_min_max.test16
-rw-r--r--mysql-test/t/im_daemon_life_cycle.imtest44
-rw-r--r--mysql-test/t/innodb-deadlock.test2
-rw-r--r--mysql-test/t/innodb-lock.test2
-rw-r--r--mysql-test/t/innodb_mysql.test18
-rwxr-xr-xmysql-test/t/kill_n_check.sh2
-rw-r--r--mysql-test/t/lock_multi.test8
-rw-r--r--mysql-test/t/lowercase_fs_off.test1
-rw-r--r--mysql-test/t/merge.test25
-rw-r--r--mysql-test/t/myisam.test91
-rw-r--r--mysql-test/t/mysql.test6
-rw-r--r--mysql-test/t/mysqltest.test12
-rw-r--r--mysql-test/t/olap.test10
-rw-r--r--mysql-test/t/ps.test27
-rw-r--r--mysql-test/t/rename.test17
-rw-r--r--mysql-test/t/repair.test38
-rw-r--r--mysql-test/t/round.test145
-rw-r--r--mysql-test/t/rpl_insert_id.test129
-rw-r--r--mysql-test/t/select.test94
-rw-r--r--mysql-test/t/show_check.test3
-rw-r--r--mysql-test/t/sp.test48
-rw-r--r--mysql-test/t/status.test7
-rw-r--r--mysql-test/t/strict.test8
-rw-r--r--mysql-test/t/subselect.test80
-rw-r--r--mysql-test/t/subselect3.test137
-rw-r--r--mysql-test/t/temp_table.test48
-rw-r--r--mysql-test/t/trigger.test19
-rw-r--r--mysql-test/t/type_bit.test8
-rw-r--r--mysql-test/t/type_datetime.test10
-rw-r--r--mysql-test/t/type_decimal.test9
-rw-r--r--mysql-test/t/type_enum.test9
-rw-r--r--mysql-test/t/type_float.test11
-rw-r--r--mysql-test/t/type_newdecimal.test8
-rw-r--r--mysql-test/t/udf.test44
-rw-r--r--mysql-test/t/view.test15
-rw-r--r--mysql-test/t/warnings.test58
-rw-r--r--mysql-test/valgrind.supp27
-rw-r--r--mysys/mf_iocache.c582
-rw-r--r--mysys/my_libwrap.c4
-rw-r--r--mysys/queues.c48
-rwxr-xr-xnetware/BUILD/mwccnlm9
-rwxr-xr-xnetware/BUILD/mwenv36
-rw-r--r--netware/Makefile.am19
-rw-r--r--netware/libmysql.imp85
-rw-r--r--scripts/mysqlhotcopy.sh7
-rw-r--r--server-tools/instance-manager/guardian.cc27
-rw-r--r--server-tools/instance-manager/instance.cc25
-rw-r--r--server-tools/instance-manager/instance_options.cc3
-rw-r--r--server-tools/instance-manager/listener.cc42
-rw-r--r--sql/Makefile.am8
-rw-r--r--sql/field.cc220
-rw-r--r--sql/field.h1
-rw-r--r--sql/field_conv.cc18
-rw-r--r--sql/filesort.cc42
-rw-r--r--sql/ha_archive.cc34
-rw-r--r--sql/ha_archive.h1
-rw-r--r--sql/ha_innodb.cc13
-rw-r--r--sql/ha_myisammrg.cc15
-rw-r--r--sql/item.cc74
-rw-r--r--sql/item.h15
-rw-r--r--sql/item_buff.cc12
-rw-r--r--sql/item_cmpfunc.cc36
-rw-r--r--sql/item_cmpfunc.h49
-rw-r--r--sql/item_func.cc50
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/item_strfunc.cc3
-rw-r--r--sql/item_subselect.cc450
-rw-r--r--sql/item_subselect.h77
-rw-r--r--sql/item_sum.cc47
-rw-r--r--sql/item_sum.h34
-rw-r--r--sql/item_timefunc.cc15
-rw-r--r--sql/item_timefunc.h151
-rw-r--r--sql/key.cc24
-rw-r--r--sql/log.cc15
-rw-r--r--sql/log_event.cc1
-rw-r--r--sql/my_decimal.cc19
-rw-r--r--sql/my_decimal.h7
-rw-r--r--sql/mysql_priv.h32
-rw-r--r--sql/mysqld.cc19
-rw-r--r--sql/opt_range.cc60
-rw-r--r--sql/opt_range.h11
-rw-r--r--sql/records.cc7
-rw-r--r--sql/set_var.cc30
-rw-r--r--sql/share/errmsg.txt2
-rw-r--r--sql/slave.cc2
-rw-r--r--sql/slave.h3
-rw-r--r--sql/sp.cc39
-rw-r--r--sql/sql_acl.cc1
-rw-r--r--sql/sql_analyse.cc8
-rw-r--r--sql/sql_base.cc14
-rw-r--r--sql/sql_class.cc24
-rw-r--r--sql/sql_class.h65
-rw-r--r--sql/sql_delete.cc2
-rw-r--r--sql/sql_insert.cc54
-rw-r--r--sql/sql_lex.cc8
-rw-r--r--sql/sql_lex.h9
-rw-r--r--sql/sql_load.cc12
-rw-r--r--sql/sql_parse.cc17
-rw-r--r--sql/sql_rename.cc194
-rw-r--r--sql/sql_select.cc423
-rw-r--r--sql/sql_select.h26
-rw-r--r--sql/sql_show.cc4
-rw-r--r--sql/sql_table.cc58
-rw-r--r--sql/sql_trigger.cc32
-rw-r--r--sql/sql_trigger.h7
-rw-r--r--sql/sql_update.cc28
-rw-r--r--sql/sql_yacc.yy41
-rw-r--r--sql/stacktrace.c2
-rw-r--r--sql/table.cc38
-rw-r--r--sql/table.h5
-rw-r--r--sql/unireg.cc15
-rw-r--r--strings/CHARSET_INFO.txt12
-rw-r--r--strings/ctype-big5.c1
-rw-r--r--strings/ctype-bin.c1
-rw-r--r--strings/ctype-cp932.c1
-rw-r--r--strings/ctype-euc_kr.c1
-rw-r--r--strings/ctype-eucjpms.c1
-rw-r--r--strings/ctype-gb2312.c1
-rw-r--r--strings/ctype-gbk.c1
-rw-r--r--strings/ctype-latin1.c1
-rw-r--r--strings/ctype-mb.c32
-rw-r--r--strings/ctype-simple.c337
-rw-r--r--strings/ctype-sjis.c1
-rw-r--r--strings/ctype-tis620.c1
-rw-r--r--strings/ctype-ucs2.c30
-rw-r--r--strings/ctype-ujis.c1
-rw-r--r--strings/ctype-utf8.c3
-rw-r--r--strings/strtod.c67
-rw-r--r--tests/mysql_client_test.c40
-rw-r--r--zlib/Makefile.am2
305 files changed, 10526 insertions, 2629 deletions
diff --git a/.bzrignore b/.bzrignore
index 7e6c6985e23..ecaa4b60c51 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1051,6 +1051,7 @@ ndbcluster-1186/ndb_3.pid
ndbcluster-1186/ndb_3_cluster.log
ndbcluster-1186/ndb_3_out.log
ndbcluster-1186/ndbcluster.pid
+netware/libmysql.imp
pack_isam/*.ds?
perror/*.ds?
perror/*.vcproj
diff --git a/BitKeeper/etc/collapsed b/BitKeeper/etc/collapsed
index fd33e4fc902..79836bb030e 100644
--- a/BitKeeper/etc/collapsed
+++ b/BitKeeper/etc/collapsed
@@ -2,4 +2,8 @@
44ec850ac2k4y2Omgr92GiWPBAVKGQ
44edb86b1iE5knJ97MbliK_3lCiAXA
44f33f3aj5KW5qweQeekY1LU0E9ZCg
+45001f7c3b2hhCXDKfUvzkX9TNe6VA
+45002051rHJfMEXAIMiAZV0clxvKSA
4513d8e4Af4dQWuk13sArwofRgFDQw
+4519a6c5BVUxEHTf5iJnjZkixMBs8g
+451ab499rgdjXyOnUDqHu-wBDoS-OQ
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fd780ec6a13..8058f615f7c 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,8 +29,6 @@ IF (WITH_MYISAMMRG_STORAGE_ENGINE)
ENDIF (WITH_MYISAMMRG_STORAGE_ENGINE)
IF(WITH_INNOBASE_STORAGE_ENGINE)
- CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/innobase/ib_config.h.in
- ${CMAKE_SOURCE_DIR}/innobase/ib_config.h @ONLY)
ADD_DEFINITIONS(-D HAVE_INNOBASE_DB)
ADD_DEFINITIONS(-D WITH_INNOBASE_STORAGE_ENGINE)
SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_innobase_plugin")
@@ -123,8 +121,12 @@ ADD_SUBDIRECTORY(heap)
ADD_SUBDIRECTORY(myisam)
ADD_SUBDIRECTORY(myisammrg)
ADD_SUBDIRECTORY(client)
+IF(WITH_BERKELEY_STORAGE_ENGINE)
ADD_SUBDIRECTORY(bdb)
+ENDIF(WITH_BERKELEY_STORAGE_ENGINE)
+IF(WITH_INNOBASE_STORAGE_ENGINE)
ADD_SUBDIRECTORY(innobase)
+ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
ADD_SUBDIRECTORY(sql)
ADD_SUBDIRECTORY(sql/examples)
ADD_SUBDIRECTORY(server-tools/instance-manager)
diff --git a/Makefile.am b/Makefile.am
index d48f0e24966..474d268db38 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -89,8 +89,18 @@ bin-dist: all
$(top_builddir)/scripts/make_binary_distribution @MAKE_BINARY_DISTRIBUTION_OPTIONS@
# Remove BK's "SCCS" subdirectories from source distribution
+# Create initial database files for Windows installations.
dist-hook:
rm -rf `find $(distdir) -type d -name SCCS -print`
+ if echo "$(distdir)" | grep -q '^/' ; then \
+ scripts/mysql_install_db --no-defaults --windows \
+ --basedir=$(top_srcdir) \
+ --datadir="$(distdir)/win/data"; \
+ else \
+ scripts/mysql_install_db --no-defaults --windows \
+ --basedir=$(top_srcdir) \
+ --datadir="$$(pwd)/$(distdir)/win/data"; \
+ fi
tags:
support-files/build-tags
diff --git a/client/mysql.cc b/client/mysql.cc
index 5e09c309917..1d7abbbc38a 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -49,6 +49,9 @@ const char *VER= "14.12";
/* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024
+/* Buffer to hold 'version' and 'version_comment' */
+#define MAX_SERVER_VERSION_LENGTH 128
+
gptr sql_alloc(unsigned size); // Don't use mysqld alloc for these
void sql_element_free(void *ptr);
#include "sql_string.h"
@@ -208,6 +211,7 @@ static int com_nopager(String *str, char*), com_pager(String *str, char*),
static int read_and_execute(bool interactive);
static int sql_connect(char *host,char *database,char *user,char *password,
uint silent);
+static const char *server_version_string(MYSQL *mysql);
static int put_info(const char *str,INFO_TYPE info,uint error=0,
const char *sql_state=0);
static int put_error(MYSQL *mysql);
@@ -432,8 +436,8 @@ int main(int argc,char *argv[])
put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.",
INFO_INFO);
sprintf((char*) glob_buffer.ptr(),
- "Your MySQL connection id is %lu to server version: %s\n",
- mysql_thread_id(&mysql),mysql_get_server_info(&mysql));
+ "Your MySQL connection id is %lu\nServer version: %s\n",
+ mysql_thread_id(&mysql), server_version_string(&mysql));
put_info((char*) glob_buffer.ptr(),INFO_INFO);
#ifdef HAVE_READLINE
@@ -2509,9 +2513,14 @@ print_table_data_xml(MYSQL_RES *result)
{
tee_fprintf(PAGER, "\t<field name=\"");
xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
- tee_fprintf(PAGER, "\">");
- xmlencode_print(cur[i], lengths[i]);
- tee_fprintf(PAGER, "</field>\n");
+ if (cur[i])
+ {
+ tee_fprintf(PAGER, "\">");
+ xmlencode_print(cur[i], lengths[i]);
+ tee_fprintf(PAGER, "</field>\n");
+ }
+ else
+ tee_fprintf(PAGER, "\" xsi:nil=\"true\" />\n");
}
(void) tee_fputs(" </row>\n", PAGER);
}
@@ -2910,7 +2919,7 @@ com_connect(String *buffer, char *line)
bzero(buff, sizeof(buff));
if (buffer)
{
- strmake(buff, line, sizeof(buff));
+ strmake(buff, line, sizeof(buff) - 1);
tmp= get_arg(buff, 0);
if (tmp && *tmp)
{
@@ -3025,7 +3034,7 @@ com_use(String *buffer __attribute__((unused)), char *line)
int select_db;
bzero(buff, sizeof(buff));
- strmov(buff, line);
+ strmake(buff, line, sizeof(buff) - 1);
tmp= get_arg(buff, 0);
if (!tmp || !*tmp)
{
@@ -3335,16 +3344,13 @@ com_status(String *buffer __attribute__((unused)),
tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
#endif
tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
- tee_fprintf(stdout, "Server version:\t\t%s\n", mysql_get_server_info(&mysql));
+ tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql));
tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
if ((id= mysql_insert_id(&mysql)))
tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
- /*
- Don't remove "limit 1",
- it is protection againts SQL_SELECT_LIMIT=0
- */
+ /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
if (!mysql_query(&mysql,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
(result=mysql_use_result(&mysql)))
{
@@ -3409,6 +3415,39 @@ select_limit, max_join_size);
return 0;
}
+static const char *
+server_version_string(MYSQL *mysql)
+{
+ static char buf[MAX_SERVER_VERSION_LENGTH] = "";
+
+ /* Only one thread calls this, so no synchronization is needed */
+ if (buf[0] == '\0')
+ {
+ char *bufp = buf;
+ MYSQL_RES *result;
+ MYSQL_ROW cur;
+
+ bufp = strnmov(buf, mysql_get_server_info(mysql), sizeof buf);
+
+ /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
+ if (!mysql_query(mysql, "select @@version_comment limit 1") &&
+ (result = mysql_use_result(mysql)))
+ {
+ MYSQL_ROW cur = mysql_fetch_row(result);
+ if (cur && cur[0])
+ {
+ bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
+ }
+ mysql_free_result(result);
+ }
+
+ /* str*nmov doesn't guarantee NUL-termination */
+ if (bufp == buf + sizeof buf)
+ buf[sizeof buf - 1] = '\0';
+ }
+
+ return buf;
+}
static int
put_info(const char *str,INFO_TYPE info_type, uint error, const char *sqlstate)
@@ -3536,14 +3575,14 @@ void tee_puts(const char *s, FILE *file)
{
NETWARE_YIELD;
fputs(s, file);
- fputs("\n", file);
+ fputc('\n', file);
#ifdef OS2
- fflush( file);
+ fflush(file);
#endif
if (opt_outfile)
{
fputs(s, OUTFILE);
- fputs("\n", OUTFILE);
+ fputc('\n', OUTFILE);
}
}
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 0f0abe682b5..261a2ae2870 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -23,6 +23,7 @@
* Matt Wagner <matt@mysql.com>
* Monty
* Jani
+ * Holyfoot
**/
/**********************************************************************
@@ -243,6 +244,12 @@ struct connection
MYSQL* util_mysql;
char *name;
MYSQL_STMT* stmt;
+
+ const char *cur_query;
+ int cur_query_len;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ int query_done;
};
typedef struct
@@ -480,6 +487,58 @@ static void handle_error(const char *query, struct st_query *q,
const char *err_sqlstate, DYNAMIC_STRING *ds);
static void handle_no_error(struct st_query *q);
+
+#ifdef EMBEDDED_LIBRARY
+/*
+ send_one_query executes query in separate thread what is
+ necessary in embedded library to run 'send' in proper way.
+ This implementation doesn't handle errors returned
+ by mysql_send_query. It's technically possible, though
+ i don't see where it is needed.
+*/
+pthread_handler_t send_one_query(void *arg)
+{
+ struct connection *cn= (struct connection*)arg;
+
+ mysql_thread_init();
+ VOID(mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len));
+
+ mysql_thread_end();
+ pthread_mutex_lock(&cn->mutex);
+ cn->query_done= 1;
+ VOID(pthread_cond_signal(&cn->cond));
+ pthread_mutex_unlock(&cn->mutex);
+ pthread_exit(0);
+ return 0;
+}
+
+static int do_send_query(struct connection *cn, const char *q, int q_len,
+ int flags)
+{
+ pthread_t tid;
+
+ if (flags & QUERY_REAP)
+ return mysql_send_query(&cn->mysql, q, q_len);
+
+ if (pthread_mutex_init(&cn->mutex, NULL) ||
+ pthread_cond_init(&cn->cond, NULL))
+ die("Error in the thread library");
+
+ cn->cur_query= q;
+ cn->cur_query_len= q_len;
+ cn->query_done= 0;
+ if (pthread_create(&tid, NULL, send_one_query, (void*)cn))
+ die("Cannot start new thread for query");
+
+ return 0;
+}
+
+#else /*EMBEDDED_LIBRARY*/
+
+#define do_send_query(cn,q,q_len,flags) mysql_send_query(&cn->mysql, q, q_len)
+
+#endif /*EMBEDDED_LIBRARY*/
+
static void do_eval(DYNAMIC_STRING* query_eval, const char *query,
my_bool pass_through_escape_chars)
{
@@ -1608,8 +1667,12 @@ int do_save_master_pos()
int do_let(struct st_query *query)
{
+ int ret;
char *p= query->first_argument;
- char *var_name, *var_name_end, *var_val_start;
+ char *var_name, *var_name_end;
+ DYNAMIC_STRING let_rhs_expr;
+
+ init_dynamic_string(&let_rhs_expr, "", 512, 2048);
/* Find <var_name> */
if (!*p)
@@ -1628,10 +1691,16 @@ int do_let(struct st_query *query)
/* Find start of <var_val> */
while (*p && my_isspace(charset_info,*p))
p++;
- var_val_start= p;
+
+ do_eval(&let_rhs_expr, p, FALSE);
+
query->last_argument= query->end;
/* Assign var_val to var_name */
- return var_set(var_name, var_name_end, var_val_start, query->end);
+ ret= var_set(var_name, var_name_end, let_rhs_expr.str,
+ (let_rhs_expr.str + let_rhs_expr.length));
+ dynstr_free(&let_rhs_expr);
+
+ return(ret);
}
@@ -3568,7 +3637,6 @@ static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
}
-
/*
Run query using MySQL C API
@@ -3585,11 +3653,12 @@ static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
error - function will not return
*/
-static void run_query_normal(MYSQL *mysql, struct st_query *command,
+static void run_query_normal(struct connection *cn, struct st_query *command,
int flags, char *query, int query_len,
DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings)
{
MYSQL_RES *res= 0;
+ MYSQL *mysql= &cn->mysql;
int err= 0, counter= 0;
DBUG_ENTER("run_query_normal");
DBUG_PRINT("enter",("flags: %d", flags));
@@ -3600,13 +3669,26 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command,
/*
Send the query
*/
- if (mysql_send_query(mysql, query, query_len))
+ if (do_send_query(cn, query, query_len, flags))
{
handle_error(query, command, mysql_errno(mysql), mysql_error(mysql),
mysql_sqlstate(mysql), ds);
goto end;
}
}
+#ifdef EMBEDDED_LIBRARY
+ /*
+ Here we handle 'reap' command, so we need to check if the
+ query's thread was finished and probably wait
+ */
+ else if (flags & QUERY_REAP)
+ {
+ pthread_mutex_lock(&cn->mutex);
+ while (!cn->query_done)
+ pthread_cond_wait(&cn->cond, &cn->mutex);
+ pthread_mutex_unlock(&cn->mutex);
+ }
+#endif /*EMBEDDED_LIBRARY*/
if (!(flags & QUERY_REAP))
DBUG_VOID_RETURN;
@@ -4092,8 +4174,10 @@ static int util_query(MYSQL* org_mysql, const char* query){
*/
-static void run_query(MYSQL *mysql, struct st_query *command, int flags)
+static void run_query(struct connection *cn, struct st_query *command,
+ int flags)
{
+ MYSQL *mysql= &cn->mysql;
DYNAMIC_STRING *ds;
DYNAMIC_STRING ds_result;
DYNAMIC_STRING ds_warnings;
@@ -4246,7 +4330,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags)
match_re(&ps_re, query))
run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
else
- run_query_normal(mysql, command, flags, query, query_len,
+ run_query_normal(cn, command, flags, query, query_len,
ds, &ds_warnings);
if (sp_created)
@@ -4730,7 +4814,7 @@ int main(int argc, char **argv)
q->require_file=require_file;
save_file[0]=0;
}
- run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND);
+ run_query(cur_con, q, QUERY_REAP|QUERY_SEND);
display_result_vertically= old_display_result_vertically;
q->last_argument= q->end;
query_executed= 1;
@@ -4765,7 +4849,7 @@ int main(int argc, char **argv)
{
q->query= q->first_argument;
}
- run_query(&cur_con->mysql, q, flags);
+ run_query(cur_con, q, flags);
query_executed= 1;
q->last_argument= q->end;
break;
@@ -4786,7 +4870,7 @@ int main(int argc, char **argv)
query and read the result some time later when reap instruction
is given on this connection.
*/
- run_query(&cur_con->mysql, q, QUERY_SEND);
+ run_query(cur_con, q, QUERY_SEND);
query_executed= 1;
q->last_argument= q->end;
break;
diff --git a/config/ac-macros/yassl.m4 b/config/ac-macros/yassl.m4
index 2dc231c1f5a..967dcbf764a 100644
--- a/config/ac-macros/yassl.m4
+++ b/config/ac-macros/yassl.m4
@@ -18,7 +18,8 @@ AC_DEFUN([MYSQL_CHECK_YASSL], [
fi
AC_MSG_RESULT([using bundled yaSSL])
yassl_dir="extra/yassl"
- yassl_libs="-L\$(top_srcdir)/extra/yassl/src -lyassl -L\$(top_srcdir)/extra/yassl/taocrypt/src -ltaocrypt"
+ yassl_libs="\$(top_builddir)/extra/yassl/src/libyassl.la \
+ \$(top_builddir)/extra/yassl/taocrypt/src/libtaocrypt.la"
AC_DEFINE([HAVE_OPENSSL], [1], [Defined by configure. Using yaSSL for OpenSSL emulation.])
AC_DEFINE([HAVE_YASSL], [1], [Defined by configure. Using yaSSL for OpenSSL emulation.])
# System specific checks
diff --git a/configure.in b/configure.in
index 7bc4fe77675..55da1dfb241 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc)
AC_CANONICAL_SYSTEM
# The Docs Makefile.am parses this line!
# remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.26)
+AM_INIT_AUTOMAKE(mysql, 5.0.27)
AM_CONFIG_HEADER(config.h)
PROTOCOL_VERSION=10
@@ -19,7 +19,7 @@ SHARED_LIB_VERSION=$SHARED_LIB_MAJOR_VERSION:0:0
# ndb version
NDB_VERSION_MAJOR=5
NDB_VERSION_MINOR=0
-NDB_VERSION_BUILD=26
+NDB_VERSION_BUILD=27
NDB_VERSION_STATUS=""
# Set all version vars based on $VERSION. How do we do this more elegant ?
diff --git a/extra/Makefile.am b/extra/Makefile.am
index 0de513ba15a..63d2b4055f7 100644
--- a/extra/Makefile.am
+++ b/extra/Makefile.am
@@ -22,14 +22,18 @@ BUILT_SOURCES= $(top_builddir)/include/mysqld_error.h \
$(top_builddir)/include/sql_state.h \
$(top_builddir)/include/mysqld_ername.h
pkginclude_HEADERS= $(BUILT_SOURCES)
-CLEANFILES = $(BUILT_SOURCES)
+DISTCLEANFILES = $(BUILT_SOURCES)
# We never use SUBDIRS here, but needed for automake 1.6.3
# to generate code to handle DIST_SUBDIRS
SUBDIRS=
DIST_SUBDIRS= yassl
-# This will build mysqld_error.h and sql_state.h
-$(top_builddir)/include/mysqld_error.h: comp_err$(EXEEXT)
+# This will build mysqld_error.h, mysqld_ername.h and sql_state.h
+# NOTE Built files should depend on their sources to avoid
+# the built files being rebuilt in source dist
+$(top_builddir)/include/mysqld_error.h: comp_err.c \
+ $(top_srcdir)/sql/share/errmsg.txt
+ $(MAKE) $(AM_MAKEFLAGS) comp_err$(EXEEXT)
$(top_builddir)/extra/comp_err$(EXEEXT) \
--charset=$(top_srcdir)/sql/share/charsets \
--out-dir=$(top_builddir)/sql/share/ \
diff --git a/extra/yassl/CMakeLists.txt b/extra/yassl/CMakeLists.txt
index e5429876072..09bd2b046da 100755
--- a/extra/yassl/CMakeLists.txt
+++ b/extra/yassl/CMakeLists.txt
@@ -1,6 +1,6 @@
ADD_DEFINITIONS("-DWIN32 -D_LIB -DYASSL_PREFIX")
-INCLUDE_DIRECTORIES(include taocrypt/include mySTL)
+INCLUDE_DIRECTORIES(include taocrypt/include taocrypt/mySTL)
ADD_LIBRARY(yassl src/buffer.cpp src/cert_wrapper.cpp src/crypto_wrapper.cpp src/handshake.cpp src/lock.cpp
src/log.cpp src/socket_wrapper.cpp src/ssl.cpp src/timer.cpp src/yassl_error.cpp
src/yassl_imp.cpp src/yassl_int.cpp)
diff --git a/extra/yassl/FLOSS-EXCEPTIONS b/extra/yassl/FLOSS-EXCEPTIONS
index 344083b0114..47f86ff65f2 100644
--- a/extra/yassl/FLOSS-EXCEPTIONS
+++ b/extra/yassl/FLOSS-EXCEPTIONS
@@ -1,7 +1,7 @@
yaSSL FLOSS License Exception
****************************************
-Version 0.1, 26 June 2006
+Version 0.2, 31 August 2006
The Sawtooth Consulting Ltd. Exception for Free/Libre and Open Source
Software-only Applications Using yaSSL Libraries (the "FLOSS Exception").
@@ -81,6 +81,7 @@ the GPL:
Python license (CNRI Python License) -
Python Software Foundation License 2.1.1
Sleepycat License "1999"
+ University of Illinois/NCSA Open Source License -
W3C License "2001"
X11 License "2001"
Zlib/libpng License -
diff --git a/extra/yassl/Makefile.am b/extra/yassl/Makefile.am
index 12a7da1085b..b7657dc28f9 100644
--- a/extra/yassl/Makefile.am
+++ b/extra/yassl/Makefile.am
@@ -1,2 +1,2 @@
SUBDIRS = taocrypt src testsuite
-EXTRA_DIST = yassl.dsp yassl.dsw $(wildcard mySTL/*.hpp) CMakeLists.txt
+EXTRA_DIST = yassl.dsp yassl.dsw CMakeLists.txt
diff --git a/extra/yassl/README b/extra/yassl/README
index 25d4d94c306..2af4e98fe4c 100644
--- a/extra/yassl/README
+++ b/extra/yassl/README
@@ -1,4 +1,15 @@
-yaSSL Release notes, version 1.3.7 (06/26/06)
+yaSSL Release notes, version 1.4.0 (08/13/06)
+
+
+ This release of yaSSL contains bug fixes, portability enhancements,
+ nonblocking connect and accept, better OpenSSL error mapping, and
+ certificate caching for session resumption.
+
+See normal build instructions below under 1.0.6.
+See libcurl build instructions below under 1.3.0.
+
+
+********************yaSSL Release notes, version 1.3.7 (06/26/06)
This release of yaSSL contains bug fixes, portability enhancements,
diff --git a/extra/yassl/examples/client/client.cpp b/extra/yassl/examples/client/client.cpp
index 94bf753210b..d655011deb6 100644
--- a/extra/yassl/examples/client/client.cpp
+++ b/extra/yassl/examples/client/client.cpp
@@ -27,7 +27,13 @@ void client_test(void* args)
SSL_set_fd(ssl, sockfd);
- if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
+ if (SSL_connect(ssl) != SSL_SUCCESS)
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
+ err_sys("SSL_connect failed");
+ }
showPeer(ssl);
const char* cipher = 0;
@@ -39,11 +45,16 @@ void client_test(void* args)
strncat(list, cipher, strlen(cipher) + 1);
}
printf("%s\n", list);
- printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl));
+ printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
char msg[] = "hello yassl!";
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
err_sys("SSL_write failed");
+ }
char reply[1024];
reply[SSL_read(ssl, reply, sizeof(reply))] = 0;
@@ -56,22 +67,36 @@ void client_test(void* args)
SSL_shutdown(ssl);
SSL_free(ssl);
+ tcp_close(sockfd);
#ifdef TEST_RESUME
tcp_connect(sockfd);
SSL_set_fd(sslResume, sockfd);
SSL_set_session(sslResume, session);
- if (SSL_connect(sslResume) != SSL_SUCCESS) err_sys("SSL resume failed");
+ if (SSL_connect(sslResume) != SSL_SUCCESS)
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
+ err_sys("SSL resume failed");
+ }
+ showPeer(sslResume);
if (SSL_write(sslResume, msg, sizeof(msg)) != sizeof(msg))
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
err_sys("SSL_write failed");
+ }
reply[SSL_read(sslResume, reply, sizeof(reply))] = 0;
printf("Server response: %s\n", reply);
SSL_shutdown(sslResume);
SSL_free(sslResume);
+ tcp_close(sockfd);
#endif // TEST_RESUME
SSL_CTX_free(ctx);
diff --git a/extra/yassl/examples/echoclient/echoclient.cpp b/extra/yassl/examples/echoclient/echoclient.cpp
index fd3f7dd48a3..983254bf8a7 100644
--- a/extra/yassl/examples/echoclient/echoclient.cpp
+++ b/extra/yassl/examples/echoclient/echoclient.cpp
@@ -41,7 +41,14 @@ void echoclient_test(void* args)
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, sockfd);
- if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
+
+ if (SSL_connect(ssl) != SSL_SUCCESS)
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
+ err_sys("SSL_connect failed");
+ }
char send[1024];
char reply[1024];
@@ -50,7 +57,12 @@ void echoclient_test(void* args)
int sendSz = strlen(send) + 1;
if (SSL_write(ssl, send, sendSz) != sendSz)
+ {
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
err_sys("SSL_write failed");
+ }
if (strncmp(send, "quit", 4) == 0) {
fputs("sending server shutdown command: quit!\n", fout);
@@ -63,6 +75,7 @@ void echoclient_test(void* args)
SSL_CTX_free(ctx);
SSL_free(ssl);
+ tcp_close(sockfd);
fflush(fout);
if (inCreated) fclose(fin);
diff --git a/extra/yassl/examples/echoserver/echoserver.cpp b/extra/yassl/examples/echoserver/echoserver.cpp
index 8e23ead20ab..cd31fedddd8 100644
--- a/extra/yassl/examples/echoserver/echoserver.cpp
+++ b/extra/yassl/examples/echoserver/echoserver.cpp
@@ -23,6 +23,18 @@
#endif // NO_MAIN_DRIVER
+
+void EchoError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& s1, SOCKET_T& s2,
+ const char* msg)
+{
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(s1);
+ tcp_close(s2);
+ err_sys(msg);
+}
+
+
THREAD_RETURN YASSL_API echoserver_test(void* args)
{
#ifdef _WIN32
@@ -65,13 +77,18 @@ THREAD_RETURN YASSL_API echoserver_test(void* args)
while (!shutdown) {
sockaddr_in client;
socklen_t client_len = sizeof(client);
- int clientfd = accept(sockfd, (sockaddr*)&client,
+ SOCKET_T clientfd = accept(sockfd, (sockaddr*)&client,
(ACCEPT_THIRD_T)&client_len);
- if (clientfd == -1) err_sys("tcp accept failed");
+ if (clientfd == -1) {
+ SSL_CTX_free(ctx);
+ tcp_close(sockfd);
+ err_sys("tcp accept failed");
+ }
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, clientfd);
- if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed");
+ if (SSL_accept(ssl) != SSL_SUCCESS)
+ EchoError(ctx, ssl, sockfd, clientfd, "SSL_accept failed");
char command[1024];
int echoSz(0);
@@ -100,7 +117,8 @@ THREAD_RETURN YASSL_API echoserver_test(void* args)
echoSz += sizeof(footer);
if (SSL_write(ssl, command, echoSz) != echoSz)
- err_sys("SSL_write failed");
+ EchoError(ctx, ssl, sockfd, clientfd, "SSL_write failed");
+
break;
}
command[echoSz] = 0;
@@ -110,16 +128,13 @@ THREAD_RETURN YASSL_API echoserver_test(void* args)
#endif
if (SSL_write(ssl, command, echoSz) != echoSz)
- err_sys("SSL_write failed");
+ EchoError(ctx, ssl, sockfd, clientfd, "SSL_write failed");
}
SSL_free(ssl);
+ tcp_close(clientfd);
}
-#ifdef _WIN32
- closesocket(sockfd);
-#else
- close(sockfd);
-#endif
+ tcp_close(sockfd);
DH_free(dh);
SSL_CTX_free(ctx);
diff --git a/extra/yassl/examples/server/server.cpp b/extra/yassl/examples/server/server.cpp
index 73cff19e371..d0bf70cd634 100644
--- a/extra/yassl/examples/server/server.cpp
+++ b/extra/yassl/examples/server/server.cpp
@@ -4,6 +4,15 @@
#include "../../testsuite/test.hpp"
+void ServerError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& sockfd, const char* msg)
+{
+ SSL_CTX_free(ctx);
+ SSL_free(ssl);
+ tcp_close(sockfd);
+ err_sys(msg);
+}
+
+
THREAD_RETURN YASSL_API server_test(void* args)
{
#ifdef _WIN32
@@ -12,18 +21,14 @@ THREAD_RETURN YASSL_API server_test(void* args)
#endif
SOCKET_T sockfd = 0;
- int clientfd = 0;
+ SOCKET_T clientfd = 0;
int argc = 0;
char** argv = 0;
set_args(argc, argv, *static_cast<func_args*>(args));
tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args));
-#ifdef _WIN32
- closesocket(sockfd);
-#else
- close(sockfd);
-#endif
+ tcp_close(sockfd);
SSL_METHOD* method = TLSv1_server_method();
SSL_CTX* ctx = SSL_CTX_new(method);
@@ -36,9 +41,11 @@ THREAD_RETURN YASSL_API server_test(void* args)
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, clientfd);
- if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed");
+ if (SSL_accept(ssl) != SSL_SUCCESS)
+ ServerError(ctx, ssl, clientfd, "SSL_accept failed");
+
showPeer(ssl);
- printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl));
+ printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
char command[1024];
command[SSL_read(ssl, command, sizeof(command))] = 0;
@@ -46,12 +53,14 @@ THREAD_RETURN YASSL_API server_test(void* args)
char msg[] = "I hear you, fa shizzle!";
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
- err_sys("SSL_write failed");
+ ServerError(ctx, ssl, clientfd, "SSL_write failed");
DH_free(dh);
SSL_CTX_free(ctx);
SSL_free(ssl);
+ tcp_close(clientfd);
+
((func_args*)args)->return_code = 0;
return 0;
}
diff --git a/extra/yassl/include/buffer.hpp b/extra/yassl/include/buffer.hpp
index 4816f79a9bc..c2709a8c847 100644
--- a/extra/yassl/include/buffer.hpp
+++ b/extra/yassl/include/buffer.hpp
@@ -34,7 +34,10 @@
#include <assert.h> // assert
#include "yassl_types.hpp" // ysDelete
#include "memory.hpp" // mySTL::auto_ptr
-#include "algorithm.hpp" // mySTL::swap
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
#ifdef _MSC_VER
@@ -199,7 +202,7 @@ struct del_ptr_zero
void operator()(T*& p) const
{
T* tmp = 0;
- mySTL::swap(tmp, p);
+ STL::swap(tmp, p);
checked_delete(tmp);
}
};
diff --git a/extra/yassl/include/cert_wrapper.hpp b/extra/yassl/include/cert_wrapper.hpp
index 8b5b7491772..761be0e9b04 100644
--- a/extra/yassl/include/cert_wrapper.hpp
+++ b/extra/yassl/include/cert_wrapper.hpp
@@ -41,8 +41,12 @@
#include "yassl_types.hpp" // SignatureAlgorithm
#include "buffer.hpp" // input_buffer
#include "asn.hpp" // SignerList
-#include "list.hpp" // mySTL::list
-#include "algorithm.hpp" // mySTL::for_each
+#include STL_LIST_FILE
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
+
namespace yaSSL {
@@ -72,7 +76,7 @@ private:
// Certificate Manager keeps a list of the cert chain and public key
class CertManager {
- typedef mySTL::list<x509*> CertList;
+ typedef STL::list<x509*> CertList;
CertList list_; // self
input_buffer privateKey_;
@@ -120,6 +124,7 @@ public:
void setVerifyNone();
void setFailNoCert();
void setSendVerify();
+ void setPeerX509(X509*);
private:
CertManager(const CertManager&); // hide copy
CertManager& operator=(const CertManager&); // and assign
diff --git a/extra/yassl/include/crypto_wrapper.hpp b/extra/yassl/include/crypto_wrapper.hpp
index 4c4e4d5da5b..83cf3d26398 100644
--- a/extra/yassl/include/crypto_wrapper.hpp
+++ b/extra/yassl/include/crypto_wrapper.hpp
@@ -416,7 +416,17 @@ private:
class x509;
-x509* PemToDer(FILE*, CertType);
+struct EncryptedInfo {
+ enum { IV_SZ = 32, NAME_SZ = 80 };
+ char name[NAME_SZ]; // max one line
+ byte iv[IV_SZ]; // in base16 rep
+ uint ivSz;
+ bool set;
+
+ EncryptedInfo() : ivSz(0), set(false) {}
+};
+
+x509* PemToDer(FILE*, CertType, EncryptedInfo* info = 0);
} // naemspace
diff --git a/extra/yassl/include/factory.hpp b/extra/yassl/include/factory.hpp
index 5619e90cd62..04d742431dc 100644
--- a/extra/yassl/include/factory.hpp
+++ b/extra/yassl/include/factory.hpp
@@ -35,10 +35,12 @@
#ifndef yaSSL_FACTORY_HPP
#define yaSSL_FACTORY_HPP
-#include "vector.hpp"
-#include "pair.hpp"
+#include STL_VECTOR_FILE
+#include STL_PAIR_FILE
+namespace STL = STL_NAMESPACE;
+
// VC60 workaround: it doesn't allow typename in some places
#if defined(_MSC_VER) && (_MSC_VER < 1300)
@@ -58,8 +60,8 @@ template<class AbstractProduct,
typename ProductCreator = AbstractProduct* (*)()
>
class Factory {
- typedef mySTL::pair<IdentifierType, ProductCreator> CallBack;
- typedef mySTL::vector<CallBack> CallBackVector;
+ typedef STL::pair<IdentifierType, ProductCreator> CallBack;
+ typedef STL::vector<CallBack> CallBackVector;
CallBackVector callbacks_;
public:
@@ -79,14 +81,16 @@ public:
// register callback
void Register(const IdentifierType& id, ProductCreator pc)
{
- callbacks_.push_back(mySTL::make_pair(id, pc));
+ callbacks_.push_back(STL::make_pair(id, pc));
}
// THE Creator, returns a new object of the proper type or 0
AbstractProduct* CreateObject(const IdentifierType& id) const
{
- const CallBack* first = callbacks_.begin();
- const CallBack* last = callbacks_.end();
+ typedef typename STL::vector<CallBack>::const_iterator cIter;
+
+ cIter first = callbacks_.begin();
+ cIter last = callbacks_.end();
while (first != last) {
if (first->first == id)
diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h
index 47b4d075894..5e7290d2a7a 100644
--- a/extra/yassl/include/openssl/ssl.h
+++ b/extra/yassl/include/openssl/ssl.h
@@ -41,7 +41,7 @@
#include "rsa.h"
-#define YASSL_VERSION "1.3.7"
+#define YASSL_VERSION "1.4.3"
#if defined(__cplusplus)
@@ -505,6 +505,8 @@ ASN1_TIME* X509_get_notAfter(X509* x);
#define V_ASN1_UTF8STRING 12
#define GEN_DNS 2
+#define CERTFICATE_ERROR 0x14090086 /* SSLv3 error */
+
typedef struct MD4_CTX {
int buffer[32]; /* big enough to hold, check size in Init */
diff --git a/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp
index 1dd61b63148..9fc0d62f90e 100644
--- a/extra/yassl/include/socket_wrapper.hpp
+++ b/extra/yassl/include/socket_wrapper.hpp
@@ -71,6 +71,7 @@ typedef unsigned char byte;
class Socket {
socket_t socket_; // underlying socket descriptor
bool wouldBlock_; // for non-blocking data
+ bool blocking_; // is option set
public:
explicit Socket(socket_t s = INVALID_SOCKET);
~Socket();
@@ -84,6 +85,7 @@ public:
bool wait();
bool WouldBlock() const;
+ bool IsBlocking() const;
void closeSocket();
void shutDown(int how = SD_SEND);
diff --git a/extra/yassl/include/yassl_error.hpp b/extra/yassl/include/yassl_error.hpp
index 3c3d5fa5231..72b79b05dbd 100644
--- a/extra/yassl/include/yassl_error.hpp
+++ b/extra/yassl/include/yassl_error.hpp
@@ -54,7 +54,11 @@ enum YasslError {
verify_error = 112,
send_error = 113,
receive_error = 114,
- certificate_error = 115
+ certificate_error = 115,
+ privateKey_error = 116,
+ badVersion_error = 117
+
+ // !!!! add error message to .cpp !!!!
// 1000+ from TaoCrypt error.hpp
diff --git a/extra/yassl/include/yassl_imp.hpp b/extra/yassl/include/yassl_imp.hpp
index 6e475c23db8..180d7fe7fe1 100644
--- a/extra/yassl/include/yassl_imp.hpp
+++ b/extra/yassl/include/yassl_imp.hpp
@@ -39,7 +39,10 @@
#include "yassl_types.hpp"
#include "factory.hpp"
-#include "list.hpp" // mySTL::list
+#include STL_LIST_FILE
+
+
+namespace STL = STL_NAMESPACE;
namespace yaSSL {
@@ -427,7 +430,7 @@ private:
class CertificateRequest : public HandShakeBase {
ClientCertificateType certificate_types_[CERT_TYPES];
int typeTotal_;
- mySTL::list<DistinguishedName> certificate_authorities_;
+ STL::list<DistinguishedName> certificate_authorities_;
public:
CertificateRequest();
~CertificateRequest();
diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp
index 26900aed3af..28e9d237622 100644
--- a/extra/yassl/include/yassl_int.hpp
+++ b/extra/yassl/include/yassl_int.hpp
@@ -40,6 +40,13 @@
#include "lock.hpp"
#include "openssl/ssl.h" // ASN1_STRING and DH
+#ifdef _POSIX_THREADS
+ #include <pthread.h>
+#endif
+
+
+namespace STL = STL_NAMESPACE;
+
namespace yaSSL {
@@ -80,12 +87,35 @@ enum ServerState {
};
+// client connect state for nonblocking restart
+enum ConnectState {
+ CONNECT_BEGIN = 0,
+ CLIENT_HELLO_SENT,
+ FIRST_REPLY_DONE,
+ FINISHED_DONE,
+ SECOND_REPLY_DONE
+};
+
+
+// server accpet state for nonblocking restart
+enum AcceptState {
+ ACCEPT_BEGIN = 0,
+ ACCEPT_FIRST_REPLY_DONE,
+ SERVER_HELLO_DONE,
+ ACCEPT_SECOND_REPLY_DONE,
+ ACCEPT_FINISHED_DONE,
+ ACCEPT_THIRD_REPLY_DONE
+};
+
+
// combines all states
class States {
RecordLayerState recordLayer_;
HandShakeState handshakeLayer_;
ClientState clientState_;
ServerState serverState_;
+ ConnectState connectState_;
+ AcceptState acceptState_;
char errorString_[MAX_ERROR_SZ];
YasslError what_;
public:
@@ -95,6 +125,8 @@ public:
const HandShakeState& getHandShake() const;
const ClientState& getClient() const;
const ServerState& getServer() const;
+ const ConnectState& GetConnect() const;
+ const AcceptState& GetAccept() const;
const char* getString() const;
YasslError What() const;
@@ -102,6 +134,8 @@ public:
HandShakeState& useHandShake();
ClientState& useClient();
ServerState& useServer();
+ ConnectState& UseConnect();
+ AcceptState& UseAccept();
char* useString();
void SetError(YasslError);
private:
@@ -142,8 +176,9 @@ public:
X509_NAME(const char*, size_t sz);
~X509_NAME();
- char* GetName();
+ const char* GetName() const;
ASN1_STRING* GetEntry(int i);
+ size_t GetLength() const;
private:
X509_NAME(const X509_NAME&); // hide copy
X509_NAME& operator=(const X509_NAME&); // and assign
@@ -157,6 +192,9 @@ public:
~StringHolder();
ASN1_STRING* GetString();
+private:
+ StringHolder(const StringHolder&); // hide copy
+ StringHolder& operator=(const StringHolder&); // and assign
};
@@ -176,6 +214,7 @@ public:
ASN1_STRING* GetBefore();
ASN1_STRING* GetAfter();
+
private:
X509(const X509&); // hide copy
X509& operator=(const X509&); // and assign
@@ -202,6 +241,7 @@ class SSL_SESSION {
uint bornOn_; // create time in seconds
uint timeout_; // timeout in seconds
RandomPool& random_; // will clean master secret
+ X509* peerX509_;
public:
explicit SSL_SESSION(RandomPool&);
SSL_SESSION(const SSL&, RandomPool&);
@@ -212,17 +252,20 @@ public:
const Cipher* GetSuite() const;
uint GetBornOn() const;
uint GetTimeOut() const;
+ X509* GetPeerX509() const;
void SetTimeOut(uint);
SSL_SESSION& operator=(const SSL_SESSION&); // allow assign for resumption
private:
SSL_SESSION(const SSL_SESSION&); // hide copy
+
+ void CopyX509(X509*);
};
// holds all sessions
class Sessions {
- mySTL::list<SSL_SESSION*> list_;
+ STL::list<SSL_SESSION*> list_;
RandomPool random_; // for session cleaning
Mutex mutex_; // no-op for single threaded
@@ -241,8 +284,42 @@ private:
};
+#ifdef _POSIX_THREADS
+ typedef pthread_t THREAD_ID_T;
+#else
+ typedef DWORD THREAD_ID_T;
+#endif
+
+// thread error data
+struct ThreadError {
+ THREAD_ID_T threadID_;
+ int errorID_;
+};
+
+
+// holds all errors
+class Errors {
+ STL::list<ThreadError> list_;
+ Mutex mutex_;
+
+ Errors() {} // only GetErrors can create
+public:
+ int Lookup(bool peek); // self lookup
+ void Add(int);
+ void Remove(); // remove self
+
+ ~Errors() {}
+
+ friend Errors& GetErrors(); // singleton creator
+private:
+ Errors(const Errors&); // hide copy
+ Errors& operator=(const Errors); // and assign
+};
+
+
Sessions& GetSessions(); // forward singletons
sslFactory& GetSSL_Factory();
+Errors& GetErrors();
// openSSL method and context types
@@ -252,8 +329,10 @@ class SSL_METHOD {
bool verifyPeer_; // request or send certificate
bool verifyNone_; // whether to verify certificate
bool failNoCert_;
+ bool multipleProtocol_; // for SSLv23 compatibility
public:
- explicit SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv);
+ SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv,
+ bool multipleProtocol = false);
ProtocolVersion getVersion() const;
ConnectionEnd getSide() const;
@@ -265,6 +344,7 @@ public:
bool verifyPeer() const;
bool verifyNone() const;
bool failNoCert() const;
+ bool multipleProtocol() const;
private:
SSL_METHOD(const SSL_METHOD&); // hide copy
SSL_METHOD& operator=(const SSL_METHOD&); // and assign
@@ -334,7 +414,7 @@ private:
// the SSL context
class SSL_CTX {
public:
- typedef mySTL::list<x509*> CertList;
+ typedef STL::list<x509*> CertList;
private:
SSL_METHOD* method_;
x509* certificate_;
@@ -342,6 +422,8 @@ private:
CertList caList_;
Ciphers ciphers_;
DH_Parms dhParms_;
+ pem_password_cb passwordCb_;
+ void* userData_;
Stats stats_;
Mutex mutex_; // for Stats
public:
@@ -354,12 +436,16 @@ public:
const Ciphers& GetCiphers() const;
const DH_Parms& GetDH_Parms() const;
const Stats& GetStats() const;
+ pem_password_cb GetPasswordCb() const;
+ void* GetUserData() const;
void setVerifyPeer();
void setVerifyNone();
void setFailNoCert();
bool SetCipherList(const char*);
bool SetDH(const DH&);
+ void SetPasswordCb(pem_password_cb cb);
+ void SetUserData(void*);
void IncrementStats(StatsField);
void AddCA(x509* ca);
@@ -434,13 +520,14 @@ private:
// holds input and output buffers
class Buffers {
public:
- typedef mySTL::list<input_buffer*> inputList;
- typedef mySTL::list<output_buffer*> outputList;
+ typedef STL::list<input_buffer*> inputList;
+ typedef STL::list<output_buffer*> outputList;
private:
inputList dataList_; // list of users app data / handshake
outputList handShakeList_; // buffered handshake msgs
+ input_buffer* rawInput_; // buffered raw input yet to process
public:
- Buffers() {}
+ Buffers();
~Buffers();
const inputList& getData() const;
@@ -448,6 +535,9 @@ public:
inputList& useData();
outputList& useHandShake();
+
+ void SetRawInput(input_buffer*); // takes ownership
+ input_buffer* TakeRawInput(); // takes ownership
private:
Buffers(const Buffers&); // hide copy
Buffers& operator=(const Buffers&); // and assign
@@ -502,6 +592,7 @@ public:
const sslFactory& getFactory() const;
const Socket& getSocket() const;
YasslError GetError() const;
+ bool GetMultiProtocol() const;
Crypto& useCrypto();
Security& useSecurity();
@@ -509,6 +600,7 @@ public:
sslHashes& useHashes();
Socket& useSocket();
Log& useLog();
+ Buffers& useBuffers();
// sets
void set_pending(Cipher suite);
diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp
index b75a2a45302..e602ee180bf 100644
--- a/extra/yassl/include/yassl_types.hpp
+++ b/extra/yassl/include/yassl_types.hpp
@@ -38,6 +38,8 @@
namespace yaSSL {
+#define YASSL_LIB
+
#ifdef YASSL_PURE_C
@@ -76,7 +78,7 @@ namespace yaSSL {
::operator delete[](ptr, yaSSL::ys);
}
- #define NEW_YS new (ys)
+ #define NEW_YS new (yaSSL::ys)
// to resolve compiler generated operator delete on base classes with
// virtual destructors (when on stack), make sure doesn't get called
@@ -122,6 +124,39 @@ typedef opaque byte;
typedef unsigned int uint;
+#ifdef USE_SYS_STL
+ // use system STL
+ #define STL_VECTOR_FILE <vector>
+ #define STL_LIST_FILE <list>
+ #define STL_ALGORITHM_FILE <algorithm>
+ #define STL_MEMORY_FILE <memory>
+ #define STL_PAIR_FILE <utility>
+
+ #define STL_NAMESPACE std
+#else
+ // use mySTL
+ #define STL_VECTOR_FILE "vector.hpp"
+ #define STL_LIST_FILE "list.hpp"
+ #define STL_ALGORITHM_FILE "algorithm.hpp"
+ #define STL_MEMORY_FILE "memory.hpp"
+ #define STL_PAIR_FILE "pair.hpp"
+
+ #define STL_NAMESPACE mySTL
+#endif
+
+
+#ifdef min
+ #undef min
+#endif
+
+template <typename T>
+T min(T a, T b)
+{
+ return a < b ? a : b;
+}
+
+
+
// all length constants in bytes
const int ID_LEN = 32; // session id length
const int SUITE_LEN = 2; // cipher suite length
@@ -163,6 +198,7 @@ const int DES_BLOCK = 8; // DES is always fixed block size 8
const int DES_IV_SZ = DES_BLOCK; // Init Vector length for DES
const int RC4_KEY_SZ = 16; // RC4 Key length
const int AES_128_KEY_SZ = 16; // AES 128bit Key length
+const int AES_192_KEY_SZ = 24; // AES 192bit Key length
const int AES_256_KEY_SZ = 32; // AES 256bit Key length
const int AES_BLOCK_SZ = 16; // AES 128bit block size, rfc 3268
const int AES_IV_SZ = AES_BLOCK_SZ; // AES Init Vector length
diff --git a/extra/yassl/src/Makefile.am b/extra/yassl/src/Makefile.am
index 2b3e1aea5f5..910bbbdd13f 100644
--- a/extra/yassl/src/Makefile.am
+++ b/extra/yassl/src/Makefile.am
@@ -1,4 +1,4 @@
-INCLUDES = -I../include -I../taocrypt/include -I../mySTL
+INCLUDES = -I../include -I../taocrypt/include -I../taocrypt/mySTL
noinst_LTLIBRARIES = libyassl.la
libyassl_la_SOURCES = buffer.cpp cert_wrapper.cpp crypto_wrapper.cpp \
@@ -6,3 +6,7 @@ libyassl_la_SOURCES = buffer.cpp cert_wrapper.cpp crypto_wrapper.cpp \
template_instnt.cpp timer.cpp yassl_imp.cpp yassl_error.cpp yassl_int.cpp
EXTRA_DIST = $(wildcard ../include/*.hpp) $(wildcard ../include/openssl/*.h)
AM_CXXFLAGS = -DYASSL_PURE_C -DYASSL_PREFIX
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
+
diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp
index 6ad0aa568ed..c3ae9c0c561 100644
--- a/extra/yassl/src/cert_wrapper.cpp
+++ b/extra/yassl/src/cert_wrapper.cpp
@@ -63,8 +63,8 @@ x509::x509(const x509& that) : length_(that.length_),
void x509::Swap(x509& that)
{
- mySTL::swap(length_, that.length_);
- mySTL::swap(buffer_, that.buffer_);
+ STL::swap(length_, that.length_);
+ STL::swap(buffer_, that.buffer_);
}
@@ -105,11 +105,11 @@ CertManager::~CertManager()
{
ysDelete(peerX509_);
- mySTL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ;
+ STL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ;
- mySTL::for_each(peerList_.begin(), peerList_.end(), del_ptr_zero()) ;
+ STL::for_each(peerList_.begin(), peerList_.end(), del_ptr_zero()) ;
- mySTL::for_each(list_.begin(), list_.end(), del_ptr_zero()) ;
+ STL::for_each(list_.begin(), list_.end(), del_ptr_zero()) ;
}
@@ -242,7 +242,7 @@ uint CertManager::get_privateKeyLength() const
// Validate the peer's certificate list, from root to peer (last to first)
int CertManager::Validate()
{
- CertList::iterator last = peerList_.rbegin(); // fix this
+ CertList::reverse_iterator last = peerList_.rbegin();
int count = peerList_.size();
while ( count > 1 ) {
@@ -255,7 +255,7 @@ int CertManager::Validate()
const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(NEW_YS TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash()));
- --last;
+ ++last;
--count;
}
@@ -310,6 +310,23 @@ int CertManager::SetPrivateKey(const x509& key)
}
+// Store OpenSSL type peer's cert
+void CertManager::setPeerX509(X509* x)
+{
+ assert(peerX509_ == 0);
+ if (x == 0) return;
+
+ X509_NAME* issuer = x->GetIssuer();
+ X509_NAME* subject = x->GetSubject();
+ ASN1_STRING* before = x->GetBefore();
+ ASN1_STRING* after = x->GetAfter();
+
+ peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(),
+ subject->GetName(), subject->GetLength(), (const char*) before->data,
+ before->length, (const char*) after->data, after->length);
+}
+
+
#if defined(USE_CML_LIB)
// Get the peer's certificate, extract and save public key
diff --git a/extra/yassl/src/crypto_wrapper.cpp b/extra/yassl/src/crypto_wrapper.cpp
index 799106ec7c0..7344a70b367 100644
--- a/extra/yassl/src/crypto_wrapper.cpp
+++ b/extra/yassl/src/crypto_wrapper.cpp
@@ -908,7 +908,7 @@ void DiffieHellman::get_parms(byte* bp, byte* bg, byte* bpub) const
// convert PEM file to DER x509 type
-x509* PemToDer(FILE* file, CertType type)
+x509* PemToDer(FILE* file, CertType type, EncryptedInfo* info)
{
using namespace TaoCrypt;
@@ -935,6 +935,37 @@ x509* PemToDer(FILE* file, CertType type)
break;
}
+ // remove encrypted header if there
+ if (fgets(line, sizeof(line), file)) {
+ char encHeader[] = "Proc-Type";
+ if (strncmp(encHeader, line, strlen(encHeader)) == 0 &&
+ fgets(line,sizeof(line), file)) {
+
+ char* start = strstr(line, "DES");
+ char* finish = strstr(line, ",");
+ if (!start)
+ start = strstr(line, "AES");
+
+ if (!info) return 0;
+
+ if ( start && finish && (start < finish)) {
+ memcpy(info->name, start, finish - start);
+ info->name[finish - start] = 0;
+ memcpy(info->iv, finish + 1, sizeof(info->iv));
+
+ char* newline = strstr(line, "\r");
+ if (!newline) newline = strstr(line, "\n");
+ if (newline && (newline > finish)) {
+ info->ivSz = newline - (finish + 1);
+ info->set = true;
+ }
+ }
+ fgets(line,sizeof(line), file); // get blank line
+ begin = ftell(file);
+ }
+
+ }
+
while(fgets(line, sizeof(line), file))
if (strncmp(footer, line, strlen(footer)) == 0) {
foundEnd = true;
@@ -956,7 +987,7 @@ x509* PemToDer(FILE* file, CertType type)
Base64Decoder b64Dec(der);
uint sz = der.size();
- mySTL::auto_ptr<x509> x(NEW_YS x509(sz), ysDelete);
+ mySTL::auto_ptr<x509> x(NEW_YS x509(sz));
memcpy(x->use_buffer(), der.get_buffer(), sz);
return x.release();
diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp
index e93f5385b3d..25f36c4ea8c 100644
--- a/extra/yassl/src/handshake.cpp
+++ b/extra/yassl/src/handshake.cpp
@@ -37,7 +37,6 @@
namespace yaSSL {
-using mySTL::min;
// Build a client hello message from cipher suites and compression method
@@ -363,7 +362,7 @@ void p_hash(output_buffer& result, const output_buffer& secret,
uint lastLen = result.get_capacity() % len;
opaque previous[SHA_LEN]; // max size
opaque current[SHA_LEN]; // max size
- mySTL::auto_ptr<Digest> hmac(ysDelete);
+ mySTL::auto_ptr<Digest> hmac;
if (lastLen) times += 1;
@@ -582,7 +581,7 @@ void hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
ContentType content, bool verify)
{
- mySTL::auto_ptr<Digest> hmac(ysDelete);
+ mySTL::auto_ptr<Digest> hmac;
opaque seq[SEQ_SZ] = { 0x00, 0x00, 0x00, 0x00 };
opaque length[LENGTH_SZ];
opaque inner[SIZEOF_ENUM + VERSION_SZ + LENGTH_SZ]; // type + version + len
@@ -660,25 +659,25 @@ void build_certHashes(SSL& ssl, Hashes& hashes)
-// do process input requests
-mySTL::auto_ptr<input_buffer>
-DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
+// do process input requests, return 0 is done, 1 is call again to complete
+int DoProcessReply(SSL& ssl)
{
// wait for input if blocking
if (!ssl.useSocket().wait()) {
ssl.SetError(receive_error);
- buffered.reset(0);
- return buffered;
+ return 0;
}
uint ready = ssl.getSocket().get_ready();
- if (!ready) return buffered;
+ if (!ready) return 1;
// add buffered data if its there
- uint buffSz = buffered.get() ? buffered.get()->get_size() : 0;
+ input_buffer* buffered = ssl.useBuffers().TakeRawInput();
+ uint buffSz = buffered ? buffered->get_size() : 0;
input_buffer buffer(buffSz + ready);
if (buffSz) {
- buffer.assign(buffered.get()->get_buffer(), buffSz);
- buffered.reset(0);
+ buffer.assign(buffered->get_buffer(), buffSz);
+ ysDelete(buffered);
+ buffered = 0;
}
// add new data
@@ -692,10 +691,8 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
ssl.getStates().getServer() == clientNull)
if (buffer.peek() != handshake) {
ProcessOldClientHello(buffer, ssl);
- if (ssl.GetError()) {
- buffered.reset(0);
- return buffered;
- }
+ if (ssl.GetError())
+ return 0;
}
while(!buffer.eof()) {
@@ -715,31 +712,28 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// put header in front for next time processing
uint extra = needHdr ? 0 : RECORD_HEADER;
uint sz = buffer.get_remaining() + extra;
- buffered.reset(NEW_YS input_buffer(sz, buffer.get_buffer() +
- buffer.get_current() - extra, sz));
- break;
+ ssl.useBuffers().SetRawInput(NEW_YS input_buffer(sz,
+ buffer.get_buffer() + buffer.get_current() - extra, sz));
+ return 1;
}
while (buffer.get_current() < hdr.length_ + RECORD_HEADER + offset) {
// each message in record, can be more than 1 if not encrypted
if (ssl.getSecurity().get_parms().pending_ == false) // cipher on
decrypt_message(ssl, buffer, hdr.length_);
- mySTL::auto_ptr<Message> msg(mf.CreateObject(hdr.type_), ysDelete);
+ mySTL::auto_ptr<Message> msg(mf.CreateObject(hdr.type_));
if (!msg.get()) {
ssl.SetError(factory_error);
- buffered.reset(0);
- return buffered;
+ return 0;
}
buffer >> *msg;
msg->Process(buffer, ssl);
- if (ssl.GetError()) {
- buffered.reset(0);
- return buffered;
- }
+ if (ssl.GetError())
+ return 0;
}
offset += hdr.length_ + RECORD_HEADER;
}
- return buffered;
+ return 0;
}
@@ -747,16 +741,17 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
void processReply(SSL& ssl)
{
if (ssl.GetError()) return;
- mySTL::auto_ptr<input_buffer> buffered(ysDelete);
- for (;;) {
- mySTL::auto_ptr<input_buffer> tmp(DoProcessReply(ssl, buffered));
- if (tmp.get()) // had only part of a record's data, call again
- buffered = tmp;
- else
- break;
- if (ssl.GetError()) return;
+ if (DoProcessReply(ssl))
+ // didn't complete process
+ if (!ssl.getSocket().IsBlocking()) {
+ // keep trying now
+ while (!ssl.GetError())
+ if (DoProcessReply(ssl) == 0) break;
}
+ else
+ // user will have try again later
+ ssl.SetError(YasslError(SSL_ERROR_WANT_READ));
}
@@ -793,7 +788,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, ck);
buildOutput(*out.get(), rlHeader, hsHeader, ck);
hashHandShake(ssl, *out.get());
@@ -814,7 +809,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, sk);
buildOutput(*out.get(), rlHeader, hsHeader, sk);
hashHandShake(ssl, *out.get());
@@ -839,7 +834,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer)
ChangeCipherSpec ccs;
RecordLayerHeader rlHeader;
buildHeader(ssl, rlHeader, ccs);
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildOutput(*out.get(), rlHeader, ccs);
if (buffer == buffered)
@@ -856,7 +851,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer)
Finished fin;
buildFinished(ssl, fin, side == client_end ? client : server);
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
cipherFinished(ssl, fin, *out.get()); // hashes handshake
if (ssl.getSecurity().get_resuming()) {
@@ -955,7 +950,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer)
ServerHello sh(ssl.getSecurity().get_connection().version_);
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildServerHello(ssl, sh);
ssl.set_random(sh.get_random(), server_end);
@@ -978,7 +973,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer)
ServerHelloDone shd;
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, shd);
buildOutput(*out.get(), rlHeader, hsHeader, shd);
@@ -999,7 +994,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer)
Certificate cert(ssl.getCrypto().get_certManager().get_cert());
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, cert);
buildOutput(*out.get(), rlHeader, hsHeader, cert);
@@ -1021,7 +1016,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer)
request.Build();
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, request);
buildOutput(*out.get(), rlHeader, hsHeader, request);
@@ -1043,7 +1038,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer)
verify.Build(ssl);
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
- mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
+ mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, verify);
buildOutput(*out.get(), rlHeader, hsHeader, verify);
diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp
index 7790001fc2d..70944831884 100644
--- a/extra/yassl/src/socket_wrapper.cpp
+++ b/extra/yassl/src/socket_wrapper.cpp
@@ -41,9 +41,10 @@
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <string.h>
+ #include <fcntl.h>
#endif // _WIN32
-#if defined(__sun) || defined(__SCO_VERSION__)
+#if defined(__sun) || defined(__SCO_VERSION__) || defined(__NETWARE__)
#include <sys/filio.h>
#endif
@@ -62,7 +63,7 @@ namespace yaSSL {
Socket::Socket(socket_t s)
- : socket_(s), wouldBlock_(false)
+ : socket_(s), wouldBlock_(false), blocking_(false)
{}
@@ -148,6 +149,7 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags)
if (get_lastError() == SOCKET_EWOULDBLOCK ||
get_lastError() == SOCKET_EAGAIN) {
wouldBlock_ = true;
+ blocking_ = true; // socket can block, only way to tell for win32
return 0;
}
}
@@ -189,6 +191,12 @@ bool Socket::WouldBlock() const
}
+bool Socket::IsBlocking() const
+{
+ return blocking_;
+}
+
+
void Socket::set_lastError(int errorCode)
{
#ifdef _WIN32
diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp
index 81e585ff735..a008ea7228b 100644
--- a/extra/yassl/src/ssl.cpp
+++ b/extra/yassl/src/ssl.cpp
@@ -42,6 +42,9 @@
#include "yassl_int.hpp"
#include "md5.hpp" // for TaoCrypt MD5 size assert
#include "md4.hpp" // for TaoCrypt MD4 size assert
+#include "file.hpp" // for TaoCrypt Source
+#include "coding.hpp" // HexDecoder
+#include "helpers.hpp" // for placement new hack
#include <stdio.h>
#ifdef _WIN32
@@ -55,7 +58,6 @@
namespace yaSSL {
-using mySTL::min;
int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
@@ -93,11 +95,55 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
}
}
else {
- x = PemToDer(input, type);
+ EncryptedInfo info;
+ x = PemToDer(input, type, &info);
if (!x) {
fclose(input);
return SSL_BAD_FILE;
}
+ if (info.set) {
+ // decrypt
+ char password[80];
+ pem_password_cb cb = ctx->GetPasswordCb();
+ if (!cb) {
+ fclose(input);
+ return SSL_BAD_FILE;
+ }
+ int passwordSz = cb(password, sizeof(password), 0,
+ ctx->GetUserData());
+ byte key[AES_256_KEY_SZ]; // max sizes
+ byte iv[AES_IV_SZ];
+
+ // use file's salt for key derivation, but not real iv
+ TaoCrypt::Source source(info.iv, info.ivSz);
+ TaoCrypt::HexDecoder dec(source);
+ memcpy(info.iv, source.get_buffer(), min((uint)sizeof(info.iv),
+ source.size()));
+ EVP_BytesToKey(info.name, "MD5", info.iv, (byte*)password,
+ passwordSz, 1, key, iv);
+
+ STL::auto_ptr<BulkCipher> cipher;
+ if (strncmp(info.name, "DES-CBC", 7) == 0)
+ cipher.reset(NEW_YS DES);
+ else if (strncmp(info.name, "DES-EDE3-CBC", 13) == 0)
+ cipher.reset(NEW_YS DES_EDE);
+ else if (strncmp(info.name, "AES-128-CBC", 13) == 0)
+ cipher.reset(NEW_YS AES(AES_128_KEY_SZ));
+ else if (strncmp(info.name, "AES-192-CBC", 13) == 0)
+ cipher.reset(NEW_YS AES(AES_192_KEY_SZ));
+ else if (strncmp(info.name, "AES-256-CBC", 13) == 0)
+ cipher.reset(NEW_YS AES(AES_256_KEY_SZ));
+ else {
+ fclose(input);
+ return SSL_BAD_FILE;
+ }
+ cipher->set_decryptKey(key, info.iv);
+ STL::auto_ptr<x509> newx(NEW_YS x509(x->get_length()));
+ cipher->decrypt(newx->use_buffer(), x->get_buffer(),
+ x->get_length());
+ ysDelete(x);
+ x = newx.release();
+ }
}
}
fclose(input);
@@ -140,8 +186,17 @@ SSL_METHOD* TLSv1_client_method()
SSL_METHOD* SSLv23_server_method()
{
- // compatibility only, no version 2 support
- return SSLv3_server_method();
+ // compatibility only, no version 2 support, but does SSL 3 and TLS 1
+ return NEW_YS SSL_METHOD(server_end, ProtocolVersion(3,1), true);
+}
+
+
+SSL_METHOD* SSLv23_client_method()
+{
+ // compatibility only, no version 2 support, but does SSL 3 and TLS 1
+ // though it sends TLS1 hello not SSLv2 so SSLv3 only servers will decline
+ // TODO: maybe add support to send SSLv2 hello ???
+ return NEW_YS SSL_METHOD(client_end, ProtocolVersion(3,1), true);
}
@@ -178,14 +233,29 @@ int SSL_set_fd(SSL* ssl, int fd)
int SSL_connect(SSL* ssl)
{
+ if (ssl->GetError() == YasslError(SSL_ERROR_WANT_READ))
+ ssl->SetError(no_error);
+
+ ClientState neededState;
+
+ switch (ssl->getStates().GetConnect()) {
+
+ case CONNECT_BEGIN :
sendClientHello(*ssl);
- ClientState neededState = ssl->getSecurity().get_resuming() ?
+ if (!ssl->GetError())
+ ssl->useStates().UseConnect() = CLIENT_HELLO_SENT;
+
+ case CLIENT_HELLO_SENT :
+ neededState = ssl->getSecurity().get_resuming() ?
serverFinishedComplete : serverHelloDoneComplete;
while (ssl->getStates().getClient() < neededState) {
if (ssl->GetError()) break;
processReply(*ssl);
}
+ if (!ssl->GetError())
+ ssl->useStates().UseConnect() = FIRST_REPLY_DONE;
+ case FIRST_REPLY_DONE :
if(ssl->getCrypto().get_certManager().sendVerify())
sendCertificate(*ssl);
@@ -198,18 +268,32 @@ int SSL_connect(SSL* ssl)
sendChangeCipher(*ssl);
sendFinished(*ssl, client_end);
ssl->flushBuffer();
+
+ if (!ssl->GetError())
+ ssl->useStates().UseConnect() = FINISHED_DONE;
+
+ case FINISHED_DONE :
if (!ssl->getSecurity().get_resuming())
while (ssl->getStates().getClient() < serverFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
+ if (!ssl->GetError())
+ ssl->useStates().UseConnect() = SECOND_REPLY_DONE;
+ case SECOND_REPLY_DONE :
ssl->verifyState(serverFinishedComplete);
ssl->useLog().ShowTCP(ssl->getSocket().get_fd());
- if (ssl->GetError())
+ if (ssl->GetError()) {
+ GetErrors().Add(ssl->GetError());
return SSL_FATAL_ERROR;
+ }
return SSL_SUCCESS;
+
+ default :
+ return SSL_FATAL_ERROR; // unkown state
+ }
}
@@ -228,7 +312,17 @@ int SSL_read(SSL* ssl, void* buffer, int sz)
int SSL_accept(SSL* ssl)
{
+ if (ssl->GetError() == YasslError(SSL_ERROR_WANT_READ))
+ ssl->SetError(no_error);
+
+ switch (ssl->getStates().GetAccept()) {
+
+ case ACCEPT_BEGIN :
processReply(*ssl);
+ if (!ssl->GetError())
+ ssl->useStates().UseAccept() = ACCEPT_FIRST_REPLY_DONE;
+
+ case ACCEPT_FIRST_REPLY_DONE :
sendServerHello(*ssl);
if (!ssl->getSecurity().get_resuming()) {
@@ -242,27 +336,51 @@ int SSL_accept(SSL* ssl)
sendServerHelloDone(*ssl);
ssl->flushBuffer();
+ }
+
+ if (!ssl->GetError())
+ ssl->useStates().UseAccept() = SERVER_HELLO_DONE;
+ case SERVER_HELLO_DONE :
+ if (!ssl->getSecurity().get_resuming()) {
while (ssl->getStates().getServer() < clientFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
}
+ if (!ssl->GetError())
+ ssl->useStates().UseAccept() = ACCEPT_SECOND_REPLY_DONE;
+
+ case ACCEPT_SECOND_REPLY_DONE :
sendChangeCipher(*ssl);
sendFinished(*ssl, server_end);
ssl->flushBuffer();
+
+ if (!ssl->GetError())
+ ssl->useStates().UseAccept() = ACCEPT_FINISHED_DONE;
+
+ case ACCEPT_FINISHED_DONE :
if (ssl->getSecurity().get_resuming()) {
while (ssl->getStates().getServer() < clientFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
}
+ if (!ssl->GetError())
+ ssl->useStates().UseAccept() = ACCEPT_THIRD_REPLY_DONE;
+ case ACCEPT_THIRD_REPLY_DONE :
ssl->useLog().ShowTCP(ssl->getSocket().get_fd());
- if (ssl->GetError())
+ if (ssl->GetError()) {
+ GetErrors().Add(ssl->GetError());
return SSL_FATAL_ERROR;
+ }
return SSL_SUCCESS;
+
+ default:
+ return SSL_FATAL_ERROR; // unknown state
+ }
}
@@ -278,6 +396,8 @@ int SSL_do_handshake(SSL* ssl)
int SSL_clear(SSL* ssl)
{
ssl->useSocket().closeSocket();
+ GetErrors().Remove();
+
return SSL_SUCCESS;
}
@@ -289,6 +409,8 @@ int SSL_shutdown(SSL* ssl)
ssl->useLog().ShowTCP(ssl->getSocket().get_fd(), true);
ssl->useSocket().closeSocket();
+ GetErrors().Remove();
+
return SSL_SUCCESS;
}
@@ -762,9 +884,8 @@ void DH_free(DH* dh)
// be created
BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
{
- using mySTL::auto_ptr;
bool created = false;
- auto_ptr<BIGNUM> bn(ysDelete);
+ mySTL::auto_ptr<BIGNUM> bn;
if (!retVal) {
created = true;
@@ -825,7 +946,7 @@ const EVP_MD* EVP_md5(void)
const EVP_CIPHER* EVP_des_ede3_cbc(void)
{
- static const char* type = "DES_EDE3_CBC";
+ static const char* type = "DES-EDE3-CBC";
return type;
}
@@ -836,16 +957,37 @@ int EVP_BytesToKey(const EVP_CIPHER* type, const EVP_MD* md, const byte* salt,
// only support MD5 for now
if (strncmp(md, "MD5", 3)) return 0;
- // only support DES_EDE3_CBC for now
- if (strncmp(type, "DES_EDE3_CBC", 12)) return 0;
+ int keyLen = 0;
+ int ivLen = 0;
+
+ // only support CBC DES and AES for now
+ if (strncmp(type, "DES-CBC", 7) == 0) {
+ keyLen = DES_KEY_SZ;
+ ivLen = DES_IV_SZ;
+ }
+ else if (strncmp(type, "DES-EDE3-CBC", 12) == 0) {
+ keyLen = DES_EDE_KEY_SZ;
+ ivLen = DES_IV_SZ;
+ }
+ else if (strncmp(type, "AES-128-CBC", 11) == 0) {
+ keyLen = AES_128_KEY_SZ;
+ ivLen = AES_IV_SZ;
+ }
+ else if (strncmp(type, "AES-192-CBC", 11) == 0) {
+ keyLen = AES_192_KEY_SZ;
+ ivLen = AES_IV_SZ;
+ }
+ else if (strncmp(type, "AES-256-CBC", 11) == 0) {
+ keyLen = AES_256_KEY_SZ;
+ ivLen = AES_IV_SZ;
+ }
+ else
+ return 0;
yaSSL::MD5 myMD;
uint digestSz = myMD.get_digestSize();
byte digest[SHA_LEN]; // max size
- yaSSL::DES_EDE cipher;
- int keyLen = cipher.get_keySize();
- int ivLen = cipher.get_ivSize();
int keyLeft = keyLen;
int ivLeft = ivLen;
int keyOutput = 0;
@@ -878,7 +1020,7 @@ int EVP_BytesToKey(const EVP_CIPHER* type, const EVP_MD* md, const byte* salt,
if (ivLeft && digestLeft) {
int store = min(ivLeft, digestLeft);
- memcpy(&iv[ivLen - ivLeft], digest, store);
+ memcpy(&iv[ivLen - ivLeft], &digest[digestSz - digestLeft], store);
keyOutput += store;
ivLeft -= store;
@@ -954,10 +1096,9 @@ void DES_ecb_encrypt(DES_cblock* input, DES_cblock* output,
}
-void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX*, void* userdata)
+void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX* ctx, void* userdata)
{
- // yaSSL doesn't support yet, unencrypt your PEM file with userdata
- // before handing off to yaSSL
+ ctx->SetUserData(userdata);
}
@@ -1034,12 +1175,6 @@ ASN1_TIME* X509_get_notAfter(X509* x)
}
-SSL_METHOD* SSLv23_client_method(void) /* doesn't actually roll back */
-{
- return SSLv3_client_method();
-}
-
-
SSL_METHOD* SSLv2_client_method(void) /* will never work, no v 2 */
{
return 0;
@@ -1363,9 +1498,9 @@ int SSL_pending(SSL* ssl)
}
- void SSL_CTX_set_default_passwd_cb(SSL_CTX*, pem_password_cb)
+ void SSL_CTX_set_default_passwd_cb(SSL_CTX* ctx, pem_password_cb cb)
{
- // TDOD:
+ ctx->SetPasswordCb(cb);
}
@@ -1428,7 +1563,7 @@ int SSL_pending(SSL* ssl)
void ERR_remove_state(unsigned long)
{
- // TODO:
+ GetErrors().Remove();
}
@@ -1437,16 +1572,30 @@ int SSL_pending(SSL* ssl)
return l & 0xfff;
}
+ unsigned long err_helper(bool peek = false)
+ {
+ int ysError = GetErrors().Lookup(peek);
+
+ // translate cert error for libcurl, it uses OpenSSL hex code
+ switch (ysError) {
+ case TaoCrypt::SIG_OTHER_E:
+ return CERTFICATE_ERROR;
+ break;
+ default :
+ return 0;
+ }
+ }
+
unsigned long ERR_peek_error()
{
- return 0; // TODO:
+ return err_helper(true);
}
unsigned long ERR_get_error()
{
- return ERR_peek_error();
+ return err_helper();
}
diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp
index c5fc23dabdb..fb488e47672 100644
--- a/extra/yassl/src/template_instnt.cpp
+++ b/extra/yassl/src/template_instnt.cpp
@@ -65,6 +65,19 @@ template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::output_buffer*>::iterat
template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::x509*>::iterator, mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero);
template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::Digest*>::iterator, mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero);
template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::BulkCipher*>::iterator, mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero);
+template bool list<yaSSL::ThreadError>::erase(list<yaSSL::ThreadError>::iterator);
+template void list<yaSSL::ThreadError>::push_back(yaSSL::ThreadError);
+template void list<yaSSL::ThreadError>::pop_front();
+template void list<yaSSL::ThreadError>::pop_back();
+template list<yaSSL::ThreadError>::~list();
+template pair<int, yaSSL::Message* (*)()>* GetArrayMemory<pair<int, yaSSL::Message* (*)()> >(size_t);
+template void FreeArrayMemory<pair<int, yaSSL::Message* (*)()> >(pair<int, yaSSL::Message* (*)()>*);
+template pair<int, yaSSL::HandShakeBase* (*)()>* GetArrayMemory<pair<int, yaSSL::HandShakeBase* (*)()> >(size_t);
+template void FreeArrayMemory<pair<int, yaSSL::HandShakeBase* (*)()> >(pair<int, yaSSL::HandShakeBase* (*)()>*);
+template pair<int, yaSSL::ServerKeyBase* (*)()>* GetArrayMemory<pair<int, yaSSL::ServerKeyBase* (*)()> >(size_t);
+template void FreeArrayMemory<pair<int, yaSSL::ServerKeyBase* (*)()> >(pair<int, yaSSL::ServerKeyBase* (*)()>*);
+template pair<int, yaSSL::ClientKeyBase* (*)()>* GetArrayMemory<pair<int, yaSSL::ClientKeyBase* (*)()> >(size_t);
+template void FreeArrayMemory<pair<int, yaSSL::ClientKeyBase* (*)()> >(pair<int, yaSSL::ClientKeyBase* (*)()>*);
}
namespace yaSSL {
@@ -90,8 +103,13 @@ template void ysDelete<X509>(X509*);
template void ysDelete<Message>(Message*);
template void ysDelete<sslFactory>(sslFactory*);
template void ysDelete<Sessions>(Sessions*);
+template void ysDelete<Errors>(Errors*);
template void ysArrayDelete<unsigned char>(unsigned char*);
template void ysArrayDelete<char>(char*);
+
+template int min<int>(int, int);
+template unsigned int min<unsigned int>(unsigned int, unsigned int);
+template unsigned long min<unsigned long>(unsigned long, unsigned long);
}
#endif // HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
diff --git a/extra/yassl/src/yassl.cpp b/extra/yassl/src/yassl.cpp
index 5bc8bad8bbc..e253ef84bb5 100644
--- a/extra/yassl/src/yassl.cpp
+++ b/extra/yassl/src/yassl.cpp
@@ -36,21 +36,9 @@
#include "openssl/ssl.h" // get rid of this
-// yaSSL overloads hide these
-void* operator new[](size_t sz)
-{
- return ::operator new(sz);
-}
-
-void operator delete[](void* ptr)
-{
- ::operator delete(ptr);
-}
-
namespace yaSSL {
-using mySTL::min;
struct Base {
diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp
index 4f75de34a98..3531c0a2c74 100644
--- a/extra/yassl/src/yassl_error.cpp
+++ b/extra/yassl/src/yassl_error.cpp
@@ -125,13 +125,21 @@ void SetErrorString(YasslError error, char* buffer)
strncpy(buffer, "unable to proccess cerificate", max);
break;
+ case privateKey_error :
+ strncpy(buffer, "unable to proccess private key, bad format", max);
+ break;
+
+ case badVersion_error :
+ strncpy(buffer, "protocl version mismatch", max);
+ break;
+
// openssl errors
case SSL_ERROR_WANT_READ :
strncpy(buffer, "the read operation would block", max);
break;
// TaoCrypt errors
- case NO_ERROR :
+ case NO_ERROR_E :
strncpy(buffer, "not in error state", max);
break;
@@ -235,6 +243,10 @@ void SetErrorString(YasslError error, char* buffer)
strncpy(buffer, "ASN: bad other signature confirmation", max);
break;
+ case CERTFICATE_ERROR :
+ strncpy(buffer, "Unable to verify certificate", max);
+ break;
+
default :
strncpy(buffer, "unknown error number", max);
}
diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp
index 98f8035732e..bd07f8b70f2 100644
--- a/extra/yassl/src/yassl_imp.cpp
+++ b/extra/yassl/src/yassl_imp.cpp
@@ -139,7 +139,7 @@ void DH_Server::build(SSL& ssl)
parms_.alloc_pub(pubSz));
short sigSz = 0;
- mySTL::auto_ptr<Auth> auth(ysDelete);
+ mySTL::auto_ptr<Auth> auth;
const CertManager& cert = ssl.getCrypto().get_certManager();
if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo)
@@ -151,9 +151,11 @@ void DH_Server::build(SSL& ssl)
sigSz += DSS_ENCODED_EXTRA;
}
-
sigSz += auth->get_signatureLength();
-
+ if (!sigSz) {
+ ssl.SetError(privateKey_error);
+ return;
+ }
length_ = 8; // pLen + gLen + YsLen + SigLen
length_ += pSz + gSz + pubSz + sigSz;
@@ -612,7 +614,7 @@ void HandShakeHeader::Process(input_buffer& input, SSL& ssl)
{
ssl.verifyState(*this);
const HandShakeFactory& hsf = ssl.getFactory().getHandShake();
- mySTL::auto_ptr<HandShakeBase> hs(hsf.CreateObject(type_), ysDelete);
+ mySTL::auto_ptr<HandShakeBase> hs(hsf.CreateObject(type_));
if (!hs.get()) {
ssl.SetError(factory_error);
return;
@@ -1214,6 +1216,20 @@ output_buffer& operator<<(output_buffer& output, const ServerHello& hello)
// Server Hello processing handler
void ServerHello::Process(input_buffer&, SSL& ssl)
{
+ if (ssl.GetMultiProtocol()) { // SSLv23 support
+ if (ssl.isTLS() && server_version_.minor_ < 1)
+ // downgrade to SSLv3
+ ssl.useSecurity().use_connection().TurnOffTLS();
+ }
+ else if (ssl.isTLS() && server_version_.minor_ < 1) {
+ ssl.SetError(badVersion_error);
+ return;
+ }
+ else if (!ssl.isTLS() && (server_version_.major_ == 3 &&
+ server_version_.minor_ >= 1)) {
+ ssl.SetError(badVersion_error);
+ return;
+ }
ssl.set_pending(cipher_suite_[1]);
ssl.set_random(random_, server_end);
if (id_len_)
@@ -1384,11 +1400,23 @@ output_buffer& operator<<(output_buffer& output, const ClientHello& hello)
// Client Hello processing handler
void ClientHello::Process(input_buffer&, SSL& ssl)
{
- if (ssl.isTLS() && client_version_.minor_ == 0) {
+ if (ssl.GetMultiProtocol()) { // SSLv23 support
+ if (ssl.isTLS() && client_version_.minor_ < 1) {
+ // downgrade to SSLv3
ssl.useSecurity().use_connection().TurnOffTLS();
ProtocolVersion pv = ssl.getSecurity().get_connection().version_;
ssl.useSecurity().use_parms().SetSuites(pv); // reset w/ SSL suites
}
+ }
+ else if (ssl.isTLS() && client_version_.minor_ < 1) {
+ ssl.SetError(badVersion_error);
+ return;
+ }
+ else if (!ssl.isTLS() && (client_version_.major_ == 3 &&
+ client_version_.minor_ >= 1)) {
+ ssl.SetError(badVersion_error);
+ return;
+ }
ssl.set_random(random_, client_end);
while (id_len_) { // trying to resume
@@ -1541,7 +1569,7 @@ CertificateRequest::CertificateRequest()
CertificateRequest::~CertificateRequest()
{
- mySTL::for_each(certificate_authorities_.begin(),
+ STL::for_each(certificate_authorities_.begin(),
certificate_authorities_.end(),
del_ptr_zero()) ;
}
@@ -1634,9 +1662,9 @@ output_buffer& operator<<(output_buffer& output,
request.typeTotal_ - REQUEST_HEADER, tmp);
output.write(tmp, sizeof(tmp));
- mySTL::list<DistinguishedName>::const_iterator first =
+ STL::list<DistinguishedName>::const_iterator first =
request.certificate_authorities_.begin();
- mySTL::list<DistinguishedName>::const_iterator last =
+ STL::list<DistinguishedName>::const_iterator last =
request.certificate_authorities_.end();
while (first != last) {
uint16 sz;
@@ -1684,7 +1712,7 @@ void CertificateVerify::Build(SSL& ssl)
uint16 sz = 0;
byte len[VERIFY_HEADER];
- mySTL::auto_ptr<byte> sig(ysArrayDelete);
+ mySTL::auto_array<byte> sig;
// sign
const CertManager& cert = ssl.getCrypto().get_certManager();
diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp
index 9b83f964348..5288acb2bcd 100644
--- a/extra/yassl/src/yassl_int.cpp
+++ b/extra/yassl/src/yassl_int.cpp
@@ -33,6 +33,10 @@
#include "handshake.hpp"
#include "timer.hpp"
+#ifdef _POSIX_THREADS
+ #include "pthread.h"
+#endif
+
#ifdef YASSL_PURE_C
@@ -74,7 +78,6 @@
namespace yaSSL {
-using mySTL::min;
@@ -155,6 +158,7 @@ void c32toa(uint32 u32, opaque* c)
States::States() : recordLayer_(recordReady), handshakeLayer_(preHandshake),
clientState_(serverNull), serverState_(clientNull),
+ connectState_(CONNECT_BEGIN), acceptState_(ACCEPT_BEGIN),
what_(no_error) {}
const RecordLayerState& States::getRecord() const
@@ -181,6 +185,18 @@ const ServerState& States::getServer() const
}
+const ConnectState& States::GetConnect() const
+{
+ return connectState_;
+}
+
+
+const AcceptState& States::GetAccept() const
+{
+ return acceptState_;
+}
+
+
const char* States::getString() const
{
return errorString_;
@@ -217,6 +233,18 @@ ServerState& States::useServer()
}
+ConnectState& States::UseConnect()
+{
+ return connectState_;
+}
+
+
+AcceptState& States::UseAccept()
+{
+ return acceptState_;
+}
+
+
char* States::useString()
{
return errorString_;
@@ -722,6 +750,12 @@ void SSL::SetError(YasslError ye)
}
+Buffers& SSL::useBuffers()
+{
+ return buffers_;
+}
+
+
// locals
namespace {
@@ -959,7 +993,7 @@ using namespace yassl_int_cpp_local1;
uint SSL::bufferedData()
{
- return mySTL::for_each(buffers_.getData().begin(),buffers_.getData().end(),
+ return STL::for_each(buffers_.getData().begin(),buffers_.getData().end(),
SumData()).total_;
}
@@ -1002,7 +1036,7 @@ void SSL::PeekData(Data& data)
data.set_length(0); // output, actual data filled
dataSz = min(dataSz, bufferedData());
- Buffers::inputList::iterator front = buffers_.getData().begin();
+ Buffers::inputList::iterator front = buffers_.useData().begin();
while (elements) {
uint frontSz = (*front)->get_remaining();
@@ -1027,7 +1061,7 @@ void SSL::flushBuffer()
{
if (GetError()) return;
- uint sz = mySTL::for_each(buffers_.getHandShake().begin(),
+ uint sz = STL::for_each(buffers_.getHandShake().begin(),
buffers_.getHandShake().end(),
SumBuffer()).total_;
output_buffer out(sz);
@@ -1213,8 +1247,10 @@ void SSL::matchSuite(const opaque* peer, uint length)
void SSL::set_session(SSL_SESSION* s)
{
- if (s && GetSessions().lookup(s->GetID(), &secure_.use_resume()))
+ if (s && GetSessions().lookup(s->GetID(), &secure_.use_resume())) {
secure_.set_resuming(true);
+ crypto_.use_certManager().setPeerX509(s->GetPeerX509());
+ }
}
@@ -1260,6 +1296,12 @@ YasslError SSL::GetError() const
}
+bool SSL::GetMultiProtocol() const
+{
+ return secure_.GetContext()->getMethod()->multipleProtocol();
+}
+
+
Crypto& SSL::useCrypto()
{
return crypto_;
@@ -1314,9 +1356,25 @@ void SSL::addBuffer(output_buffer* b)
}
+void SSL_SESSION::CopyX509(X509* x)
+{
+ assert(peerX509_ == 0);
+ if (x == 0) return;
+
+ X509_NAME* issuer = x->GetIssuer();
+ X509_NAME* subject = x->GetSubject();
+ ASN1_STRING* before = x->GetBefore();
+ ASN1_STRING* after = x->GetAfter();
+
+ peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(),
+ subject->GetName(), subject->GetLength(), (const char*) before->data,
+ before->length, (const char*) after->data, after->length);
+}
+
+
// store connection parameters
SSL_SESSION::SSL_SESSION(const SSL& ssl, RandomPool& ran)
- : timeout_(DEFAULT_TIMEOUT), random_(ran)
+ : timeout_(DEFAULT_TIMEOUT), random_(ran), peerX509_(0)
{
const Connection& conn = ssl.getSecurity().get_connection();
@@ -1325,12 +1383,14 @@ SSL_SESSION::SSL_SESSION(const SSL& ssl, RandomPool& ran)
memcpy(suite_, ssl.getSecurity().get_parms().suite_, SUITE_LEN);
bornOn_ = lowResTimer();
+
+ CopyX509(ssl.getCrypto().get_certManager().get_peerX509());
}
// for resumption copy in ssl::parameters
SSL_SESSION::SSL_SESSION(RandomPool& ran)
- : bornOn_(0), timeout_(0), random_(ran)
+ : bornOn_(0), timeout_(0), random_(ran), peerX509_(0)
{
memset(sessionID_, 0, ID_LEN);
memset(master_secret_, 0, SECRET_LEN);
@@ -1347,6 +1407,12 @@ SSL_SESSION& SSL_SESSION::operator=(const SSL_SESSION& that)
bornOn_ = that.bornOn_;
timeout_ = that.timeout_;
+ if (peerX509_) {
+ ysDelete(peerX509_);
+ peerX509_ = 0;
+ }
+ CopyX509(that.peerX509_);
+
return *this;
}
@@ -1369,6 +1435,12 @@ const Cipher* SSL_SESSION::GetSuite() const
}
+X509* SSL_SESSION::GetPeerX509() const
+{
+ return peerX509_;
+}
+
+
uint SSL_SESSION::GetBornOn() const
{
return bornOn_;
@@ -1395,6 +1467,8 @@ SSL_SESSION::~SSL_SESSION()
{
volatile opaque* p = master_secret_;
clean(p, SECRET_LEN, random_);
+
+ ysDelete(peerX509_);
}
@@ -1418,6 +1492,15 @@ sslFactory& GetSSL_Factory()
}
+static Errors* errorsInstance = 0;
+
+Errors& GetErrors()
+{
+ if (!errorsInstance)
+ errorsInstance = NEW_YS Errors;
+ return *errorsInstance;
+}
+
typedef Mutex::Lock Lock;
@@ -1433,14 +1516,15 @@ void Sessions::add(const SSL& ssl)
Sessions::~Sessions()
{
- mySTL::for_each(list_.begin(), list_.end(), del_ptr_zero());
+ STL::for_each(list_.begin(), list_.end(), del_ptr_zero());
}
// locals
namespace yassl_int_cpp_local2 { // for explicit templates
-typedef mySTL::list<SSL_SESSION*>::iterator iterator;
+typedef STL::list<SSL_SESSION*>::iterator sess_iterator;
+typedef STL::list<ThreadError>::iterator thr_iterator;
struct sess_match {
const opaque* id_;
@@ -1455,6 +1539,28 @@ struct sess_match {
};
+THREAD_ID_T GetSelf()
+{
+#ifndef _POSIX_THREADS
+ return GetCurrentThreadId();
+#else
+ return pthread_self();
+#endif
+}
+
+struct thr_match {
+ THREAD_ID_T id_;
+ explicit thr_match() : id_(GetSelf()) {}
+
+ bool operator()(ThreadError thr)
+ {
+ if (thr.threadID_ == id_)
+ return true;
+ return false;
+ }
+};
+
+
} // local namespace
using namespace yassl_int_cpp_local2;
@@ -1463,8 +1569,8 @@ using namespace yassl_int_cpp_local2;
SSL_SESSION* Sessions::lookup(const opaque* id, SSL_SESSION* copy)
{
Lock guard(mutex_);
- iterator find = mySTL::find_if(list_.begin(), list_.end(), sess_match(id));
-
+ sess_iterator find = STL::find_if(list_.begin(), list_.end(),
+ sess_match(id));
if (find != list_.end()) {
uint current = lowResTimer();
if ( ((*find)->GetBornOn() + (*find)->GetTimeOut()) < current) {
@@ -1484,8 +1590,8 @@ SSL_SESSION* Sessions::lookup(const opaque* id, SSL_SESSION* copy)
void Sessions::remove(const opaque* id)
{
Lock guard(mutex_);
- iterator find = mySTL::find_if(list_.begin(), list_.end(), sess_match(id));
-
+ sess_iterator find = STL::find_if(list_.begin(), list_.end(),
+ sess_match(id));
if (find != list_.end()) {
del_ptr_zero()(*find);
list_.erase(find);
@@ -1493,9 +1599,51 @@ void Sessions::remove(const opaque* id)
}
-SSL_METHOD::SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv)
+// remove a self thread error
+void Errors::Remove()
+{
+ Lock guard(mutex_);
+ thr_iterator find = STL::find_if(list_.begin(), list_.end(),
+ thr_match());
+ if (find != list_.end())
+ list_.erase(find);
+}
+
+
+// lookup self error code
+int Errors::Lookup(bool peek)
+{
+ Lock guard(mutex_);
+ thr_iterator find = STL::find_if(list_.begin(), list_.end(),
+ thr_match());
+ if (find != list_.end()) {
+ int ret = find->errorID_;
+ if (!peek)
+ list_.erase(find);
+ return ret;
+ }
+ else
+ return 0;
+}
+
+
+// add a new error code for self
+void Errors::Add(int error)
+{
+ ThreadError add;
+ add.errorID_ = error;
+ add.threadID_ = GetSelf();
+
+ Remove(); // may have old error
+
+ Lock guard(mutex_);
+ list_.push_back(add);
+}
+
+
+SSL_METHOD::SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv, bool multiProto)
: version_(pv), side_(ce), verifyPeer_(false), verifyNone_(false),
- failNoCert_(false)
+ failNoCert_(false), multipleProtocol_(multiProto)
{}
@@ -1547,8 +1695,15 @@ bool SSL_METHOD::failNoCert() const
}
+bool SSL_METHOD::multipleProtocol() const
+{
+ return multipleProtocol_;
+}
+
+
SSL_CTX::SSL_CTX(SSL_METHOD* meth)
- : method_(meth), certificate_(0), privateKey_(0)
+ : method_(meth), certificate_(0), privateKey_(0), passwordCb_(0),
+ userData_(0)
{}
@@ -1558,7 +1713,7 @@ SSL_CTX::~SSL_CTX()
ysDelete(certificate_);
ysDelete(privateKey_);
- mySTL::for_each(caList_.begin(), caList_.end(), del_ptr_zero());
+ STL::for_each(caList_.begin(), caList_.end(), del_ptr_zero());
}
@@ -1611,6 +1766,30 @@ const Stats& SSL_CTX::GetStats() const
}
+pem_password_cb SSL_CTX::GetPasswordCb() const
+{
+ return passwordCb_;
+}
+
+
+void SSL_CTX::SetPasswordCb(pem_password_cb cb)
+{
+ passwordCb_ = cb;
+}
+
+
+void* SSL_CTX::GetUserData() const
+{
+ return userData_;
+}
+
+
+void SSL_CTX::SetUserData(void* data)
+{
+ userData_ = data;
+}
+
+
void SSL_CTX::setVerifyPeer()
{
method_->setVerifyPeer();
@@ -1914,12 +2093,33 @@ Hashes& sslHashes::use_certVerify()
}
+Buffers::Buffers() : rawInput_(0)
+{}
+
+
Buffers::~Buffers()
{
- mySTL::for_each(handShakeList_.begin(), handShakeList_.end(),
+ STL::for_each(handShakeList_.begin(), handShakeList_.end(),
del_ptr_zero()) ;
- mySTL::for_each(dataList_.begin(), dataList_.end(),
+ STL::for_each(dataList_.begin(), dataList_.end(),
del_ptr_zero()) ;
+ ysDelete(rawInput_);
+}
+
+
+void Buffers::SetRawInput(input_buffer* ib)
+{
+ assert(rawInput_ == 0);
+ rawInput_ = ib;
+}
+
+
+input_buffer* Buffers::TakeRawInput()
+{
+ input_buffer* ret = rawInput_;
+ rawInput_ = 0;
+
+ return ret;
}
@@ -2026,12 +2226,18 @@ X509_NAME::~X509_NAME()
}
-char* X509_NAME::GetName()
+const char* X509_NAME::GetName() const
{
return name_;
}
+size_t X509_NAME::GetLength() const
+{
+ return sz_;
+}
+
+
X509::X509(const char* i, size_t iSz, const char* s, size_t sSz,
const char* b, int bSz, const char* a, int aSz)
: issuer_(i, iSz), subject_(s, sSz),
@@ -2114,10 +2320,12 @@ extern "C" void yaSSL_CleanUp()
TaoCrypt::CleanUp();
yaSSL::ysDelete(yaSSL::sslFactoryInstance);
yaSSL::ysDelete(yaSSL::sessionsInstance);
+ yaSSL::ysDelete(yaSSL::errorsInstance);
// In case user calls more than once, prevent seg fault
yaSSL::sslFactoryInstance = 0;
yaSSL::sessionsInstance = 0;
+ yaSSL::errorsInstance = 0;
}
@@ -2126,6 +2334,7 @@ namespace mySTL {
template yaSSL::yassl_int_cpp_local1::SumData for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData);
template yaSSL::yassl_int_cpp_local1::SumBuffer for_each<mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumBuffer>(mySTL::list<yaSSL::output_buffer*>::iterator, mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumBuffer);
template mySTL::list<yaSSL::SSL_SESSION*>::iterator find_if<mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::yassl_int_cpp_local2::sess_match>(mySTL::list<yaSSL::SSL_SESSION*>::iterator, mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::yassl_int_cpp_local2::sess_match);
+template mySTL::list<yaSSL::ThreadError>::iterator find_if<mySTL::list<yaSSL::ThreadError>::iterator, yaSSL::yassl_int_cpp_local2::thr_match>(mySTL::list<yaSSL::ThreadError>::iterator, mySTL::list<yaSSL::ThreadError>::iterator, yaSSL::yassl_int_cpp_local2::thr_match);
}
#endif
diff --git a/extra/yassl/taocrypt/CMakeLists.txt b/extra/yassl/taocrypt/CMakeLists.txt
index 0af0a242e5d..540827954d0 100755
--- a/extra/yassl/taocrypt/CMakeLists.txt
+++ b/extra/yassl/taocrypt/CMakeLists.txt
@@ -1,4 +1,4 @@
-INCLUDE_DIRECTORIES(../mySTL include)
+INCLUDE_DIRECTORIES(mySTL include)
ADD_LIBRARY(taocrypt src/aes.cpp src/aestables.cpp src/algebra.cpp src/arc4.cpp src/asn.cpp src/coding.cpp
src/des.cpp src/dh.cpp src/dsa.cpp src/file.cpp src/hash.cpp src/integer.cpp src/md2.cpp
diff --git a/extra/yassl/taocrypt/COPYING b/extra/yassl/taocrypt/COPYING
new file mode 100644
index 00000000000..d60c31a97a5
--- /dev/null
+++ b/extra/yassl/taocrypt/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/extra/yassl/taocrypt/INSTALL b/extra/yassl/taocrypt/INSTALL
new file mode 100644
index 00000000000..54caf7c190f
--- /dev/null
+++ b/extra/yassl/taocrypt/INSTALL
@@ -0,0 +1,229 @@
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
+Foundation, Inc.
+
+ This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+ These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+ It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring. (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+ The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'. You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+ You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment. Here
+is an example:
+
+ ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+ *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory. After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+ By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc. You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on. Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+ CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+ OS KERNEL-OS
+
+ See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+ If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+ If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+ Variables not defined in a site shell script can be set in the
+environment passed to `configure'. However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost. In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'. For example:
+
+ ./configure CC=/usr/local2/bin/gcc
+
+will cause the specified gcc to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+`configure' Invocation
+======================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+ Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`--cache-file=FILE'
+ Enable the cache: use and save the results of the tests in FILE,
+ traditionally `config.cache'. FILE defaults to `/dev/null' to
+ disable caching.
+
+`--config-cache'
+`-C'
+ Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options. Run
+`configure --help' for more details.
+
diff --git a/extra/yassl/taocrypt/Makefile.am b/extra/yassl/taocrypt/Makefile.am
index e232b499cc7..f1340b38437 100644
--- a/extra/yassl/taocrypt/Makefile.am
+++ b/extra/yassl/taocrypt/Makefile.am
@@ -1,2 +1,2 @@
SUBDIRS = src test benchmark
-EXTRA_DIST = taocrypt.dsw taocrypt.dsp CMakeLists.txt
+EXTRA_DIST = taocrypt.dsw taocrypt.dsp CMakeLists.txt $(wildcard mySTL/*.hpp)
diff --git a/extra/yassl/taocrypt/README b/extra/yassl/taocrypt/README
new file mode 100644
index 00000000000..34e1744492e
--- /dev/null
+++ b/extra/yassl/taocrypt/README
@@ -0,0 +1,37 @@
+TaoCrypt release 0.9.0 09/18/2006
+
+This is the first release of TaoCrypt, it was previously only included with
+yaSSL. TaoCrypt is highly portable and fast, its features include:
+
+One way hash functions: SHA-1, MD2, MD4, MD5, RIPEMD-160
+Message authentication codes: HMAC
+Block Ciphers: DES, Triple-DES, AES, Blowfish, Twofish
+Stream Ciphers: ARC4
+Public Key Crypto: RSA, DSA, Diffie-Hellman
+Password based key derivation: PBKDF2 from PKCS #5
+Pseudo Random Number Generators
+Lare Integer Support
+Base 16/64 encoding/decoding
+DER encoding/decoding
+X.509 processing
+SSE2 and ia32 asm for the right processors and compilers
+
+
+To build on Unix
+
+ ./configure
+ make
+
+ To test the build, from the ./test directory run ./test
+
+
+On Windows
+
+ Open the taocrypt project workspace
+ Choose (Re)Build All
+
+ To test the build, run the test executable
+
+
+Please send any questions or comments to todd@yassl.com.
+
diff --git a/extra/yassl/taocrypt/benchmark/Makefile.am b/extra/yassl/taocrypt/benchmark/Makefile.am
index 81200ff7e6a..a5b1713427c 100644
--- a/extra/yassl/taocrypt/benchmark/Makefile.am
+++ b/extra/yassl/taocrypt/benchmark/Makefile.am
@@ -1,8 +1,6 @@
-INCLUDES = -I../include -I../../mySTL
+INCLUDES = -I../include -I../mySTL
bin_PROGRAMS = benchmark
benchmark_SOURCES = benchmark.cpp
-benchmark_LDFLAGS = -L../src
-benchmark_LDADD = -ltaocrypt
+benchmark_LDADD = $(top_builddir)/extra/yassl/taocrypt/src/libtaocrypt.la
benchmark_CXXFLAGS = -DYASSL_PURE_C
-benchmark_DEPENDENCIES = ../src/libtaocrypt.la
EXTRA_DIST = benchmark.dsp rsa1024.der dh1024.der dsa1024.der make.bat
diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp
index 8bea2ae780b..dbee54be6f1 100644
--- a/extra/yassl/taocrypt/include/asn.hpp
+++ b/extra/yassl/taocrypt/include/asn.hpp
@@ -33,10 +33,12 @@
#include "misc.hpp"
#include "block.hpp"
-#include "list.hpp"
#include "error.hpp"
+#include STL_LIST_FILE
+namespace STL = STL_NAMESPACE;
+
namespace TaoCrypt {
@@ -232,7 +234,7 @@ private:
};
-typedef mySTL::list<Signer*> SignerList;
+typedef STL::list<Signer*> SignerList;
enum SigType { SHAwDSA = 517, MD2wRSA = 646, MD5wRSA = 648, SHAwRSA =649};
diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp
index 88cb06f62f1..a931158a83d 100644
--- a/extra/yassl/taocrypt/include/block.hpp
+++ b/extra/yassl/taocrypt/include/block.hpp
@@ -31,12 +31,14 @@
#ifndef TAO_CRYPT_BLOCK_HPP
#define TAO_CRYPT_BLOCK_HPP
-#include "algorithm.hpp" // mySTL::swap
#include "misc.hpp"
#include <string.h> // memcpy
#include <stddef.h> // ptrdiff_t
+#include STL_ALGORITHM_FILE
+namespace STL = STL_NAMESPACE;
+
namespace TaoCrypt {
@@ -80,7 +82,7 @@ typename A::pointer StdReallocate(A& a, T* p, typename A::size_type oldSize,
typename A::pointer newPointer = b.allocate(newSize, 0);
memcpy(newPointer, p, sizeof(T) * min(oldSize, newSize));
a.deallocate(p, oldSize);
- mySTL::swap(a, b);
+ STL::swap(a, b);
return newPointer;
}
else {
@@ -183,9 +185,9 @@ public:
}
void Swap(Block& other) {
- mySTL::swap(sz_, other.sz_);
- mySTL::swap(buffer_, other.buffer_);
- mySTL::swap(allocator_, other.allocator_);
+ STL::swap(sz_, other.sz_);
+ STL::swap(buffer_, other.buffer_);
+ STL::swap(allocator_, other.allocator_);
}
~Block() { allocator_.deallocate(buffer_, sz_); }
diff --git a/extra/yassl/taocrypt/include/blowfish.hpp b/extra/yassl/taocrypt/include/blowfish.hpp
index fbc4f223702..40953624232 100644
--- a/extra/yassl/taocrypt/include/blowfish.hpp
+++ b/extra/yassl/taocrypt/include/blowfish.hpp
@@ -32,7 +32,11 @@
#include "misc.hpp"
#include "modes.hpp"
-#include "algorithm.hpp"
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
+
namespace TaoCrypt {
diff --git a/extra/yassl/taocrypt/include/error.hpp b/extra/yassl/taocrypt/include/error.hpp
index b0ff9b280ba..1a93056db45 100644
--- a/extra/yassl/taocrypt/include/error.hpp
+++ b/extra/yassl/taocrypt/include/error.hpp
@@ -37,7 +37,7 @@ namespace TaoCrypt {
enum ErrorNumber {
-NO_ERROR = 0, // "not in error state"
+NO_ERROR_E = 0, // "not in error state"
// RandomNumberGenerator
WINCRYPT_E = 1001, // "bad wincrypt acquire"
@@ -78,7 +78,7 @@ SIG_OTHER_E = 1039 // "bad other signature confirmation"
struct Error {
ErrorNumber what_; // description number, 0 for no error
- explicit Error(ErrorNumber w = NO_ERROR) : what_(w) {}
+ explicit Error(ErrorNumber w = NO_ERROR_E) : what_(w) {}
ErrorNumber What() const { return what_; }
void SetError(ErrorNumber w) { what_ = w; }
diff --git a/extra/yassl/taocrypt/include/file.hpp b/extra/yassl/taocrypt/include/file.hpp
index 87fc6139f8f..c12b5c73bac 100644
--- a/extra/yassl/taocrypt/include/file.hpp
+++ b/extra/yassl/taocrypt/include/file.hpp
@@ -83,7 +83,7 @@ private:
void Swap(Source& other)
{
buffer_.Swap(other.buffer_);
- mySTL::swap(current_, other.current_);
+ STL::swap(current_, other.current_);
}
};
diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp
index 7e4f6450316..70b4dc79e73 100644
--- a/extra/yassl/taocrypt/include/integer.hpp
+++ b/extra/yassl/taocrypt/include/integer.hpp
@@ -44,8 +44,8 @@
#include "block.hpp"
#include "random.hpp"
#include "file.hpp"
-#include "algorithm.hpp" // mySTL::swap
#include <string.h>
+#include STL_ALGORITHM_FILE
#ifdef TAOCRYPT_X86ASM_AVAILABLE
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index 48604620706..3d2d4c62466 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -198,6 +198,23 @@ void CleanUp();
#endif
+#ifdef USE_SYS_STL
+ // use system STL
+ #define STL_VECTOR_FILE <vector>
+ #define STL_LIST_FILE <list>
+ #define STL_ALGORITHM_FILE <algorithm>
+ #define STL_MEMORY_FILE <memory>
+ #define STL_NAMESPACE std
+#else
+ // use mySTL
+ #define STL_VECTOR_FILE "vector.hpp"
+ #define STL_LIST_FILE "list.hpp"
+ #define STL_ALGORITHM_FILE "algorithm.hpp"
+ #define STL_MEMORY_FILE "memory.hpp"
+ #define STL_NAMESPACE mySTL
+#endif
+
+
// ***************** DLL related ********************
#ifdef TAOCRYPT_WIN32_AVAILABLE
diff --git a/extra/yassl/taocrypt/include/pwdbased.hpp b/extra/yassl/taocrypt/include/pwdbased.hpp
index c3e916e3d83..78df7ede02e 100644
--- a/extra/yassl/taocrypt/include/pwdbased.hpp
+++ b/extra/yassl/taocrypt/include/pwdbased.hpp
@@ -74,7 +74,7 @@ word32 PBKDF2_HMAC<T>::DeriveKey(byte* derived, word32 dLen, const byte* pwd,
}
hmac.Final(buffer.get_buffer());
- word32 segmentLen = mySTL::min(dLen, buffer.size());
+ word32 segmentLen = min(dLen, buffer.size());
memcpy(derived, buffer.get_buffer(), segmentLen);
for (j = 1; j < iterations; j++) {
diff --git a/extra/yassl/taocrypt/include/twofish.hpp b/extra/yassl/taocrypt/include/twofish.hpp
index 0529c37d6c5..ba144d2defb 100644
--- a/extra/yassl/taocrypt/include/twofish.hpp
+++ b/extra/yassl/taocrypt/include/twofish.hpp
@@ -32,7 +32,11 @@
#include "misc.hpp"
#include "modes.hpp"
-#include "algorithm.hpp"
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
+
namespace TaoCrypt {
diff --git a/extra/yassl/mySTL/algorithm.hpp b/extra/yassl/taocrypt/mySTL/algorithm.hpp
index efc7aa21a07..9a51d1f2281 100644
--- a/extra/yassl/mySTL/algorithm.hpp
+++ b/extra/yassl/taocrypt/mySTL/algorithm.hpp
@@ -8,7 +8,7 @@
* 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.
- *
+ *
* There are special exceptions to the terms and conditions of the GPL as it
* is applied to yaSSL. View the full text of the exception in the file
* FLOSS-EXCEPTIONS in the directory of this software distribution.
diff --git a/extra/yassl/mySTL/helpers.hpp b/extra/yassl/taocrypt/mySTL/helpers.hpp
index c4449519db3..43381c0f6ea 100644
--- a/extra/yassl/mySTL/helpers.hpp
+++ b/extra/yassl/taocrypt/mySTL/helpers.hpp
@@ -113,6 +113,47 @@ PlaceIter uninit_fill_n(PlaceIter place, Size n, const T& value)
}
+template <typename T>
+T* GetArrayMemory(size_t items)
+{
+ unsigned char* ret;
+
+ #ifdef YASSL_LIB
+ ret = NEW_YS unsigned char[sizeof(T) * items];
+ #else
+ ret = NEW_TC unsigned char[sizeof(T) * items];
+ #endif
+
+ return reinterpret_cast<T*>(ret);
+}
+
+
+template <typename T>
+void FreeArrayMemory(T* ptr)
+{
+ unsigned char* p = reinterpret_cast<unsigned char*>(ptr);
+
+ #ifdef YASSL_LIB
+ yaSSL::ysArrayDelete(p);
+ #else
+ TaoCrypt::tcArrayDelete(p);
+ #endif
+}
+
+
+
+inline void* GetMemory(size_t bytes)
+{
+ return GetArrayMemory<unsigned char>(bytes);
+}
+
+
+inline void FreeMemory(void* ptr)
+{
+ FreeArrayMemory(ptr);
+}
+
+
} // namespace mySTL
diff --git a/extra/yassl/mySTL/list.hpp b/extra/yassl/taocrypt/mySTL/list.hpp
index 11a1a914868..831c5bbbbbd 100644
--- a/extra/yassl/mySTL/list.hpp
+++ b/extra/yassl/taocrypt/mySTL/list.hpp
@@ -33,7 +33,6 @@
#include "helpers.hpp"
-#include <stdlib.h>
namespace mySTL {
@@ -75,8 +74,7 @@ public:
class iterator {
node* current_;
public:
- iterator() : current_(0) {}
- explicit iterator(node* p) : current_(p) {}
+ explicit iterator(node* p = 0) : current_(p) {}
T& operator*() const
{
@@ -127,11 +125,67 @@ public:
friend class list<T>;
};
+
+ class reverse_iterator {
+ node* current_;
+ public:
+ explicit reverse_iterator(node* p = 0) : current_(p) {}
+
+ T& operator*() const
+ {
+ return current_->value_;
+ }
+
+ T* operator->() const
+ {
+ return &(operator*());
+ }
+
+ reverse_iterator& operator++()
+ {
+ current_ = current_->prev_;
+ return *this;
+ }
+
+ reverse_iterator& operator--()
+ {
+ current_ = current_->next_;
+ return *this;
+ }
+
+ reverse_iterator operator++(int)
+ {
+ reverse_iterator tmp = *this;
+ current_ = current_->prev_;
+ return tmp;
+ }
+
+ reverse_iterator operator--(int)
+ {
+ reverse_iterator tmp = *this;
+ current_ = current_->next_;
+ return tmp;
+ }
+
+ bool operator==(const reverse_iterator& other) const
+ {
+ return current_ == other.current_;
+ }
+
+ bool operator!=(const reverse_iterator& other) const
+ {
+ return current_ != other.current_;
+ }
+
+ friend class list<T>;
+ };
+
bool erase(iterator);
- iterator begin() const { return iterator(head_); }
- iterator rbegin() const { return iterator(tail_); }
- iterator end() const { return iterator(); }
+ iterator begin() const { return iterator(head_); }
+ reverse_iterator rbegin() const { return reverse_iterator(tail_); }
+ iterator end() const { return iterator(); }
+ reverse_iterator rend() const { return reverse_iterator(); }
typedef iterator const_iterator; // for now
@@ -158,7 +212,7 @@ list<T>::~list()
for (; start; start = next_) {
next_ = start->next_;
destroy(start);
- free(start);
+ FreeMemory(start);
}
}
@@ -166,8 +220,7 @@ list<T>::~list()
template<typename T>
void list<T>::push_front(T t)
{
- void* mem = malloc(sizeof(node));
- if (!mem) abort();
+ void* mem = GetMemory(sizeof(node));
node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t);
if (head_) {
@@ -196,7 +249,7 @@ void list<T>::pop_front()
head_->prev_ = 0;
}
destroy(front);
- free(front);
+ FreeMemory(front);
--sz_;
}
@@ -204,7 +257,7 @@ void list<T>::pop_front()
template<typename T>
T list<T>::front() const
{
- if (head_ == 0) return 0;
+ if (head_ == 0) return T();
return head_->value_;
}
@@ -212,8 +265,7 @@ T list<T>::front() const
template<typename T>
void list<T>::push_back(T t)
{
- void* mem = malloc(sizeof(node));
- if (!mem) abort();
+ void* mem = GetMemory(sizeof(node));
node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t);
if (tail_) {
@@ -242,7 +294,7 @@ void list<T>::pop_back()
tail_->next_ = 0;
}
destroy(rear);
- free(rear);
+ FreeMemory(rear);
--sz_;
}
@@ -250,7 +302,7 @@ void list<T>::pop_back()
template<typename T>
T list<T>::back() const
{
- if (tail_ == 0) return 0;
+ if (tail_ == 0) return T();
return tail_->value_;
}
@@ -286,7 +338,7 @@ bool list<T>::remove(T t)
del->next_->prev_ = del->prev_;
destroy(del);
- free(del);
+ FreeMemory(del);
--sz_;
}
return true;
@@ -309,78 +361,13 @@ bool list<T>::erase(iterator iter)
del->next_->prev_ = del->prev_;
destroy(del);
- free(del);
+ FreeMemory(del);
--sz_;
}
return true;
}
-/* MSVC can't handle ??
-
-template<typename T>
-T& list<T>::iterator::operator*() const
-{
- return current_->value_;
-}
-
-
-template<typename T>
-T* list<T>::iterator::operator->() const
-{
- return &(operator*());
-}
-
-
-template<typename T>
-typename list<T>::iterator& list<T>::iterator::operator++()
-{
- current_ = current_->next_;
- return *this;
-}
-
-
-template<typename T>
-typename list<T>::iterator& list<T>::iterator::operator--()
-{
- current_ = current_->prev_;
- return *this;
-}
-
-
-template<typename T>
-typename list<T>::iterator& list<T>::iterator::operator++(int)
-{
- iterator tmp = *this;
- current_ = current_->next_;
- return tmp;
-}
-
-
-template<typename T>
-typename list<T>::iterator& list<T>::iterator::operator--(int)
-{
- iterator tmp = *this;
- current_ = current_->prev_;
- return tmp;
-}
-
-
-template<typename T>
-bool list<T>::iterator::operator==(const iterator& other) const
-{
- return current_ == other.current_;
-}
-
-
-template<typename T>
-bool list<T>::iterator::operator!=(const iterator& other) const
-{
- return current_ != other.current_;
-}
-*/ // end MSVC 6 can't handle
-
-
} // namespace mySTL
diff --git a/extra/yassl/mySTL/memory.hpp b/extra/yassl/taocrypt/mySTL/memory.hpp
index f480af12316..5855423c6fc 100644
--- a/extra/yassl/mySTL/memory.hpp
+++ b/extra/yassl/taocrypt/mySTL/memory.hpp
@@ -31,6 +31,7 @@
#ifndef mySTL_MEMORY_HPP
#define mySTL_MEMORY_HPP
+#include "memory_array.hpp" // for auto_array
#ifdef _MSC_VER
// disable operator-> warning for builtins
@@ -43,27 +44,25 @@ namespace mySTL {
template<typename T>
struct auto_ptr_ref {
- typedef void (*Deletor)(T*);
- T* ptr_;
- Deletor del_;
- auto_ptr_ref(T* p, Deletor d) : ptr_(p), del_(d) {}
+ T* ptr_;
+ explicit auto_ptr_ref(T* p) : ptr_(p) {}
};
template<typename T>
class auto_ptr {
- typedef void (*Deletor)(T*);
T* ptr_;
- Deletor del_;
void Destroy()
{
- del_(ptr_);
+ #ifdef YASSL_LIB
+ yaSSL::ysDelete(ptr_);
+ #else
+ TaoCrypt::tcDelete(ptr_);
+ #endif
}
public:
- auto_ptr(T* p, Deletor d) : ptr_(p), del_(d) {}
-
- explicit auto_ptr(Deletor d) : ptr_(0), del_(d) {}
+ explicit auto_ptr(T* p = 0) : ptr_(p) {}
~auto_ptr()
{
@@ -71,14 +70,13 @@ public:
}
- auto_ptr(auto_ptr& other) : ptr_(other.release()), del_(other.del_) {}
+ auto_ptr(auto_ptr& other) : ptr_(other.release()) {}
auto_ptr& operator=(auto_ptr& that)
{
if (this != &that) {
Destroy();
ptr_ = that.release();
- del_ = that.del_;
}
return *this;
}
@@ -115,14 +113,13 @@ public:
}
// auto_ptr_ref conversions
- auto_ptr(auto_ptr_ref<T> ref) : ptr_(ref.ptr_), del_(ref.del_) {}
+ auto_ptr(auto_ptr_ref<T> ref) : ptr_(ref.ptr_) {}
auto_ptr& operator=(auto_ptr_ref<T> ref)
{
if (this->ptr_ != ref.ptr_) {
Destroy();
ptr_ = ref.ptr_;
- del_ = ref.del_;
}
return *this;
}
@@ -130,13 +127,13 @@ public:
template<typename T2>
operator auto_ptr<T2>()
{
- return auto_ptr<T2>(this->release(), this->del_);
+ return auto_ptr<T2>(this->release());
}
template<typename T2>
operator auto_ptr_ref<T2>()
{
- return auto_ptr_ref<T2>(this->release(), this->del_);
+ return auto_ptr_ref<T2>(this->release());
}
};
diff --git a/extra/yassl/taocrypt/mySTL/memory_array.hpp b/extra/yassl/taocrypt/mySTL/memory_array.hpp
new file mode 100644
index 00000000000..f089c69f815
--- /dev/null
+++ b/extra/yassl/taocrypt/mySTL/memory_array.hpp
@@ -0,0 +1,142 @@
+/* mySTL memory_array.hpp
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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.
+ *
+ * There are special exceptions to the terms and conditions of the GPL as it
+ * is applied to yaSSL. View the full text of the exception in the file
+ * FLOSS-EXCEPTIONS in the directory of this software distribution.
+ *
+ * yaSSL 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
+ */
+
+
+/* mySTL memory_arry implements auto_array
+ *
+ */
+
+#ifndef mySTL_MEMORY_ARRAY_HPP
+#define mySTL_MEMORY_ARRAY_HPP
+
+
+#ifdef _MSC_VER
+ // disable operator-> warning for builtins
+ #pragma warning(disable:4284)
+#endif
+
+
+namespace mySTL {
+
+
+template<typename T>
+struct auto_array_ref {
+ T* ptr_;
+ explicit auto_array_ref(T* p) : ptr_(p) {}
+};
+
+
+template<typename T>
+class auto_array {
+ T* ptr_;
+
+ void Destroy()
+ {
+ #ifdef YASSL_LIB
+ yaSSL::ysArrayDelete(ptr_);
+ #else
+ TaoCrypt::tcArrayDelete(ptr_);
+ #endif
+ }
+public:
+ explicit auto_array(T* p = 0) : ptr_(p) {}
+
+ ~auto_array()
+ {
+ Destroy();
+ }
+
+
+ auto_array(auto_array& other) : ptr_(other.release()) {}
+
+ auto_array& operator=(auto_array& that)
+ {
+ if (this != &that) {
+ Destroy();
+ ptr_ = that.release();
+ }
+ return *this;
+ }
+
+
+ T* operator->() const
+ {
+ return ptr_;
+ }
+
+ T& operator*() const
+ {
+ return *ptr_;
+ }
+
+ T* get() const
+ {
+ return ptr_;
+ }
+
+ T* release()
+ {
+ T* tmp = ptr_;
+ ptr_ = 0;
+ return tmp;
+ }
+
+ void reset(T* p = 0)
+ {
+ if (ptr_ != p) {
+ Destroy();
+ ptr_ = p;
+ }
+ }
+
+ // auto_array_ref conversions
+ auto_array(auto_array_ref<T> ref) : ptr_(ref.ptr_) {}
+
+ auto_array& operator=(auto_array_ref<T> ref)
+ {
+ if (this->ptr_ != ref.ptr_) {
+ Destroy();
+ ptr_ = ref.ptr_;
+ }
+ return *this;
+ }
+
+ template<typename T2>
+ operator auto_array<T2>()
+ {
+ return auto_array<T2>(this->release());
+ }
+
+ template<typename T2>
+ operator auto_array_ref<T2>()
+ {
+ return auto_array_ref<T2>(this->release());
+ }
+};
+
+
+} // namespace mySTL
+
+#endif // mySTL_MEMORY_ARRAY_HPP
diff --git a/extra/yassl/mySTL/pair.hpp b/extra/yassl/taocrypt/mySTL/pair.hpp
index 13916fece13..13916fece13 100644
--- a/extra/yassl/mySTL/pair.hpp
+++ b/extra/yassl/taocrypt/mySTL/pair.hpp
diff --git a/extra/yassl/mySTL/stdexcept.hpp b/extra/yassl/taocrypt/mySTL/stdexcept.hpp
index 4fd343ae6fd..4fd343ae6fd 100644
--- a/extra/yassl/mySTL/stdexcept.hpp
+++ b/extra/yassl/taocrypt/mySTL/stdexcept.hpp
diff --git a/extra/yassl/mySTL/vector.hpp b/extra/yassl/taocrypt/mySTL/vector.hpp
index 6a412447b91..902e014f75b 100644
--- a/extra/yassl/mySTL/vector.hpp
+++ b/extra/yassl/taocrypt/mySTL/vector.hpp
@@ -34,7 +34,6 @@
#include "helpers.hpp" // construct, destory, fill, etc.
#include "algorithm.hpp" // swap
#include <assert.h> // assert
-#include <stdlib.h> // malloc
namespace mySTL {
@@ -49,14 +48,15 @@ struct vector_base {
vector_base() : start_(0), finish_(0), end_of_storage_(0) {}
vector_base(size_t n)
{
- // Don't allow malloc(0), if n is 0 use 1
- start_ = static_cast<T*>(malloc((n ? n : 1) * sizeof(T)));
- if (!start_) abort();
+ start_ = GetArrayMemory<T>(n);
finish_ = start_;
end_of_storage_ = start_ + n;
}
- ~vector_base() { if (start_) free(start_); }
+ ~vector_base()
+ {
+ FreeArrayMemory(start_);
+ }
void Swap(vector_base& that)
{
@@ -71,6 +71,9 @@ struct vector_base {
template <typename T>
class vector {
public:
+ typedef T* iterator;
+ typedef const T* const_iterator;
+
vector() {}
explicit vector(size_t n) : vec_(n)
{
diff --git a/extra/yassl/taocrypt/src/Makefile.am b/extra/yassl/taocrypt/src/Makefile.am
index 1110ed335b8..6d02a625275 100644
--- a/extra/yassl/taocrypt/src/Makefile.am
+++ b/extra/yassl/taocrypt/src/Makefile.am
@@ -1,4 +1,4 @@
-INCLUDES = -I../include -I../../mySTL
+INCLUDES = -I../include -I../mySTL
noinst_LTLIBRARIES = libtaocrypt.la
@@ -11,3 +11,7 @@ libtaocrypt_la_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp \
libtaocrypt_la_CXXFLAGS = @yassl_taocrypt_extra_cxxflags@ -DYASSL_PURE_C
EXTRA_DIST = $(wildcard ../include/*.hpp)
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
+
diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp
index e9bc3fceac0..375cd6cd524 100644
--- a/extra/yassl/taocrypt/src/algebra.cpp
+++ b/extra/yassl/taocrypt/src/algebra.cpp
@@ -29,7 +29,10 @@
#include "runtime.hpp"
#include "algebra.hpp"
-#include "vector.hpp" // mySTL::vector (simple)
+#include STL_VECTOR_FILE
+
+
+namespace STL = STL_NAMESPACE;
namespace TaoCrypt {
@@ -82,7 +85,7 @@ const Integer& AbstractEuclideanDomain::Mod(const Element &a,
const Integer& AbstractEuclideanDomain::Gcd(const Element &a,
const Element &b) const
{
- mySTL::vector<Element> g(3);
+ STL::vector<Element> g(3);
g[0]= b;
g[1]= a;
unsigned int i0=0, i1=1, i2=2;
@@ -115,7 +118,7 @@ Integer AbstractGroup::CascadeScalarMultiply(const Element &x,
const unsigned w = (expLen <= 46 ? 1 : (expLen <= 260 ? 2 : 3));
const unsigned tableSize = 1<<w;
- mySTL::vector<Element> powerTable(tableSize << w);
+ STL::vector<Element> powerTable(tableSize << w);
powerTable[1] = x;
powerTable[tableSize] = y;
@@ -240,8 +243,8 @@ struct WindowSlider
void AbstractGroup::SimultaneousMultiply(Integer *results, const Integer &base,
const Integer *expBegin, unsigned int expCount) const
{
- mySTL::vector<mySTL::vector<Element> > buckets(expCount);
- mySTL::vector<WindowSlider> exponents;
+ STL::vector<STL::vector<Element> > buckets(expCount);
+ STL::vector<WindowSlider> exponents;
exponents.reserve(expCount);
unsigned int i;
@@ -332,6 +335,8 @@ void AbstractRing::SimultaneousExponentiate(Integer *results,
namespace mySTL {
template TaoCrypt::WindowSlider* uninit_copy<TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
template void destroy<TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
+template TaoCrypt::WindowSlider* GetArrayMemory<TaoCrypt::WindowSlider>(size_t);
+template void FreeArrayMemory<TaoCrypt::WindowSlider>(TaoCrypt::WindowSlider*);
}
#endif
diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp
index 45fb1e60a0c..3dc3638d85f 100644
--- a/extra/yassl/taocrypt/src/asn.cpp
+++ b/extra/yassl/taocrypt/src/asn.cpp
@@ -38,7 +38,8 @@
#include "sha.hpp"
#include "coding.hpp"
#include <time.h> // gmtime();
-#include "memory.hpp" // mySTL::auto_ptr
+#include "memory.hpp" // some auto_ptr don't have reset, also need auto_array
+
namespace TaoCrypt {
@@ -202,13 +203,13 @@ void PublicKey::SetKey(const byte* k)
void PublicKey::AddToEnd(const byte* data, word32 len)
{
- mySTL::auto_ptr<byte> tmp(NEW_TC byte[sz_ + len], tcArrayDelete);
+ mySTL::auto_array<byte> tmp(NEW_TC byte[sz_ + len]);
memcpy(tmp.get(), key_, sz_);
memcpy(tmp.get() + sz_, data, len);
byte* del = 0;
- mySTL::swap(del, key_);
+ STL::swap(del, key_);
tcArrayDelete(del);
key_ = tmp.release();
@@ -856,7 +857,7 @@ bool CertDecoder::ValidateSignature(SignerList* signers)
bool CertDecoder::ConfirmSignature(Source& pub)
{
HashType ht;
- mySTL::auto_ptr<HASH> hasher(tcDelete);
+ mySTL::auto_ptr<HASH> hasher;
if (signatureOID_ == MD5wRSA) {
hasher.reset(NEW_TC MD5);
diff --git a/extra/yassl/taocrypt/src/blowfish.cpp b/extra/yassl/taocrypt/src/blowfish.cpp
index cc929cd7d41..40ae1a17e6c 100644
--- a/extra/yassl/taocrypt/src/blowfish.cpp
+++ b/extra/yassl/taocrypt/src/blowfish.cpp
@@ -133,7 +133,7 @@ void Blowfish::SetKey(const byte* key_string, word32 keylength, CipherDir dir)
if (dir==DECRYPTION)
for (i=0; i<(ROUNDS+2)/2; i++)
- mySTL::swap(pbox_[i], pbox_[ROUNDS+1-i]);
+ STL::swap(pbox_[i], pbox_[ROUNDS+1-i]);
}
diff --git a/extra/yassl/taocrypt/src/crypto.cpp b/extra/yassl/taocrypt/src/crypto.cpp
new file mode 100644
index 00000000000..95238100f5d
--- /dev/null
+++ b/extra/yassl/taocrypt/src/crypto.cpp
@@ -0,0 +1,39 @@
+/* crypto.cpp
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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.
+ *
+ * There are special exceptions to the terms and conditions of the GPL as it
+ * is applied to yaSSL. View the full text of the exception in the file
+ * FLOSS-EXCEPTIONS in the directory of this software distribution.
+ *
+ * yaSSL 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
+ */
+
+/* put features that other apps expect from OpenSSL type crypto */
+
+
+
+extern "C" {
+
+ // for libcurl configure test, these are the signatures they use
+ // locking handled internally by library
+ char CRYPTO_lock() { return 0;}
+ char CRYPTO_add_lock() { return 0;}
+} // extern "C"
+
+
+
diff --git a/extra/yassl/taocrypt/src/des.cpp b/extra/yassl/taocrypt/src/des.cpp
index 054c8c2eb78..2628e142bae 100644
--- a/extra/yassl/taocrypt/src/des.cpp
+++ b/extra/yassl/taocrypt/src/des.cpp
@@ -34,7 +34,10 @@
#include "runtime.hpp"
#include "des.hpp"
-#include "algorithm.hpp" // mySTL::swap
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
@@ -265,8 +268,8 @@ void BasicDES::SetKey(const byte* key, word32 /*length*/, CipherDir dir)
// reverse key schedule order
if (dir == DECRYPTION)
for (i = 0; i < 16; i += 2) {
- mySTL::swap(k_[i], k_[32 - 2 - i]);
- mySTL::swap(k_[i+1], k_[32 - 1 - i]);
+ STL::swap(k_[i], k_[32 - 2 - i]);
+ STL::swap(k_[i+1], k_[32 - 1 - i]);
}
}
diff --git a/extra/yassl/taocrypt/src/dh.cpp b/extra/yassl/taocrypt/src/dh.cpp
index aec7122b70b..671a20d0d78 100644
--- a/extra/yassl/taocrypt/src/dh.cpp
+++ b/extra/yassl/taocrypt/src/dh.cpp
@@ -61,7 +61,7 @@ void DH::GenerateKeyPair(RandomNumberGenerator& rng, byte* priv, byte* pub)
// Generate private value
void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
{
- Integer x(rng, Integer::One(), mySTL::min(p_ - 1,
+ Integer x(rng, Integer::One(), min(p_ - 1,
Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
x.Encode(priv, p_.ByteCount());
}
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index 823c0c5e193..500160cfe37 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -1094,7 +1094,7 @@ static bool IsP4()
word32 cpuid[4];
CpuId(0, cpuid);
- mySTL::swap(cpuid[2], cpuid[3]);
+ STL::swap(cpuid[2], cpuid[3]);
if (memcmp(cpuid+1, "GenuineIntel", 12) != 0)
return false;
@@ -2384,8 +2384,8 @@ void AsymmetricMultiply(word *R, word *T, const word *A, unsigned int NA,
if (NA > NB)
{
- mySTL::swap(A, B);
- mySTL::swap(NA, NB);
+ STL::swap(A, B);
+ STL::swap(NA, NB);
}
assert(NB % NA == 0);
@@ -2521,8 +2521,8 @@ unsigned int AlmostInverse(word *R, word *T, const word *A, unsigned int NA,
if (Compare(f, g, fgLen)==-1)
{
- mySTL::swap(f, g);
- mySTL::swap(b, c);
+ STL::swap(f, g);
+ STL::swap(b, c);
s++;
}
@@ -3162,7 +3162,7 @@ signed long Integer::ConvertToLong() const
void Integer::Swap(Integer& a)
{
reg_.Swap(a.reg_);
- mySTL::swap(sign_, a.sign_);
+ STL::swap(sign_, a.sign_);
}
diff --git a/extra/yassl/taocrypt/src/md4.cpp b/extra/yassl/taocrypt/src/md4.cpp
index 6012330cba3..0dee8bf40cb 100644
--- a/extra/yassl/taocrypt/src/md4.cpp
+++ b/extra/yassl/taocrypt/src/md4.cpp
@@ -28,9 +28,11 @@
#include "runtime.hpp"
#include "md4.hpp"
-#include "algorithm.hpp" // mySTL::swap
+#include STL_ALGORITHM_FILE
+namespace STL = STL_NAMESPACE;
+
namespace TaoCrypt {
@@ -69,9 +71,9 @@ MD4& MD4::operator= (const MD4& that)
void MD4::Swap(MD4& other)
{
- mySTL::swap(loLen_, other.loLen_);
- mySTL::swap(hiLen_, other.hiLen_);
- mySTL::swap(buffLen_, other.buffLen_);
+ STL::swap(loLen_, other.loLen_);
+ STL::swap(hiLen_, other.hiLen_);
+ STL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
memcpy(buffer_, other.buffer_, BLOCK_SIZE);
diff --git a/extra/yassl/taocrypt/src/md5.cpp b/extra/yassl/taocrypt/src/md5.cpp
index f7b0b1ee2dc..2bddc7fe308 100644
--- a/extra/yassl/taocrypt/src/md5.cpp
+++ b/extra/yassl/taocrypt/src/md5.cpp
@@ -28,7 +28,10 @@
#include "runtime.hpp"
#include "md5.hpp"
-#include "algorithm.hpp" // mySTL::swap
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
@@ -72,9 +75,9 @@ MD5& MD5::operator= (const MD5& that)
void MD5::Swap(MD5& other)
{
- mySTL::swap(loLen_, other.loLen_);
- mySTL::swap(hiLen_, other.hiLen_);
- mySTL::swap(buffLen_, other.buffLen_);
+ STL::swap(loLen_, other.loLen_);
+ STL::swap(hiLen_, other.hiLen_);
+ STL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
memcpy(buffer_, other.buffer_, BLOCK_SIZE);
diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp
index a33ca4fa432..084a263a4ae 100644
--- a/extra/yassl/taocrypt/src/misc.cpp
+++ b/extra/yassl/taocrypt/src/misc.cpp
@@ -29,15 +29,6 @@
#include "runtime.hpp"
#include "misc.hpp"
-#if !defined(YASSL_MYSQL_COMPATIBLE)
-extern "C" {
-
- // for libcurl configure test, these are the signatures they use
- // locking handled internally by library
- char CRYPTO_lock() { return 0;}
- char CRYPTO_add_lock() { return 0;}
-} // extern "C"
-#endif
#ifdef YASSL_PURE_C
diff --git a/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp
index 2ee1e57a663..c7bb6ae9549 100644
--- a/extra/yassl/taocrypt/src/random.cpp
+++ b/extra/yassl/taocrypt/src/random.cpp
@@ -31,7 +31,7 @@
#include "runtime.hpp"
#include "random.hpp"
#include <string.h>
-
+#include <time.h>
#if defined(_WIN32)
#define _WIN32_WINNT 0x0400
@@ -74,6 +74,8 @@ byte RandomNumberGenerator::GenerateByte()
#if defined(_WIN32)
+/* The OS_Seed implementation for windows */
+
OS_Seed::OS_Seed()
{
if(!CryptAcquireContext(&handle_, 0, 0, PROV_RSA_FULL,
@@ -95,8 +97,70 @@ void OS_Seed::GenerateSeed(byte* output, word32 sz)
}
-#else // _WIN32
+#elif defined(__NETWARE__)
+
+/* The OS_Seed implementation for Netware */
+
+#include <nks/thread.h>
+#include <nks/plat.h>
+
+// Loop on high resulution Read Time Stamp Counter
+static void NetwareSeed(byte* output, word32 sz)
+{
+ word32 tscResult;
+
+ for (word32 i = 0; i < sz; i += sizeof(tscResult)) {
+ #if defined(__GNUC__)
+ asm volatile("rdtsc" : "=A" (tscResult));
+ #else
+ #ifdef __MWERKS__
+ asm {
+ #else
+ __asm {
+ #endif
+ rdtsc
+ mov tscResult, eax
+ }
+ #endif
+
+ memcpy(output, &tscResult, sizeof(tscResult));
+ output += sizeof(tscResult);
+
+ NXThreadYield(); // induce more variance
+ }
+}
+
+
+OS_Seed::OS_Seed()
+{
+}
+
+
+OS_Seed::~OS_Seed()
+{
+}
+
+
+void OS_Seed::GenerateSeed(byte* output, word32 sz)
+{
+ /*
+ Try to use NXSeedRandom as it will generate a strong
+ seed using the onboard 82802 chip
+
+ As it's not always supported, fallback to default
+ implementation if an error is returned
+ */
+
+ if (NXSeedRandom(sz, output) != 0)
+ {
+ NetwareSeed(output, sz);
+ }
+}
+
+
+#else
+/* The default OS_Seed implementation */
OS_Seed::OS_Seed()
{
diff --git a/extra/yassl/taocrypt/src/ripemd.cpp b/extra/yassl/taocrypt/src/ripemd.cpp
index c791189544f..03c09edde84 100644
--- a/extra/yassl/taocrypt/src/ripemd.cpp
+++ b/extra/yassl/taocrypt/src/ripemd.cpp
@@ -28,9 +28,11 @@
#include "runtime.hpp"
#include "ripemd.hpp"
-#include "algorithm.hpp" // mySTL::swap
+#include STL_ALGORITHM_FILE
+namespace STL = STL_NAMESPACE;
+
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_RIPEMD_ASM
@@ -75,9 +77,9 @@ RIPEMD160& RIPEMD160::operator= (const RIPEMD160& that)
void RIPEMD160::Swap(RIPEMD160& other)
{
- mySTL::swap(loLen_, other.loLen_);
- mySTL::swap(hiLen_, other.hiLen_);
- mySTL::swap(buffLen_, other.buffLen_);
+ STL::swap(loLen_, other.loLen_);
+ STL::swap(hiLen_, other.hiLen_);
+ STL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
memcpy(buffer_, other.buffer_, BLOCK_SIZE);
diff --git a/extra/yassl/taocrypt/src/sha.cpp b/extra/yassl/taocrypt/src/sha.cpp
index b877e2b7857..280d42fb3d4 100644
--- a/extra/yassl/taocrypt/src/sha.cpp
+++ b/extra/yassl/taocrypt/src/sha.cpp
@@ -27,8 +27,11 @@
#include "runtime.hpp"
#include <string.h>
-#include "algorithm.hpp" // mySTL::swap
#include "sha.hpp"
+#include STL_ALGORITHM_FILE
+
+
+namespace STL = STL_NAMESPACE;
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
@@ -96,9 +99,9 @@ SHA& SHA::operator= (const SHA& that)
void SHA::Swap(SHA& other)
{
- mySTL::swap(loLen_, other.loLen_);
- mySTL::swap(hiLen_, other.hiLen_);
- mySTL::swap(buffLen_, other.buffLen_);
+ STL::swap(loLen_, other.loLen_);
+ STL::swap(hiLen_, other.hiLen_);
+ STL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
memcpy(buffer_, other.buffer_, BLOCK_SIZE);
diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp
index 512c5cf9dce..db1ae645e09 100644
--- a/extra/yassl/taocrypt/src/template_instnt.cpp
+++ b/extra/yassl/taocrypt/src/template_instnt.cpp
@@ -77,6 +77,13 @@ template void destroy<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, ve
template TaoCrypt::Integer* uninit_copy<TaoCrypt::Integer*, TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*);
template TaoCrypt::Integer* uninit_fill_n<TaoCrypt::Integer*, size_t, TaoCrypt::Integer>(TaoCrypt::Integer*, size_t, TaoCrypt::Integer const&);
template void destroy<TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*);
+template TaoCrypt::byte* GetArrayMemory<TaoCrypt::byte>(size_t);
+template void FreeArrayMemory<TaoCrypt::byte>(TaoCrypt::byte*);
+template TaoCrypt::Integer* GetArrayMemory<TaoCrypt::Integer>(size_t);
+template void FreeArrayMemory<TaoCrypt::Integer>(TaoCrypt::Integer*);
+template vector<TaoCrypt::Integer>* GetArrayMemory<vector<TaoCrypt::Integer> >(size_t);
+template void FreeArrayMemory<vector<TaoCrypt::Integer> >(vector<TaoCrypt::Integer>*);
+template void FreeArrayMemory<void>(void*);
}
#endif
diff --git a/extra/yassl/taocrypt/test/Makefile.am b/extra/yassl/taocrypt/test/Makefile.am
index 0b238f1e057..988d00c7bef 100644
--- a/extra/yassl/taocrypt/test/Makefile.am
+++ b/extra/yassl/taocrypt/test/Makefile.am
@@ -1,8 +1,6 @@
-INCLUDES = -I../include -I../../mySTL
+INCLUDES = -I../include -I../mySTL
bin_PROGRAMS = test
test_SOURCES = test.cpp
-test_LDFLAGS = -L../src
-test_LDADD = -ltaocrypt
-test_DEPENDENCIES = ../src/libtaocrypt.la
+test_LDADD = $(top_builddir)/extra/yassl/taocrypt/src/libtaocrypt.la
test_CXXFLAGS = -DYASSL_PURE_C
EXTRA_DIST = make.bat
diff --git a/extra/yassl/testsuite/Makefile.am b/extra/yassl/testsuite/Makefile.am
index 2ae46a1b409..e8abffd6bb0 100644
--- a/extra/yassl/testsuite/Makefile.am
+++ b/extra/yassl/testsuite/Makefile.am
@@ -1,11 +1,14 @@
-INCLUDES = -I../include -I../taocrypt/include -I../mySTL
+INCLUDES = -I../include -I../taocrypt/include -I../taocrypt/mySTL
bin_PROGRAMS = testsuite
testsuite_SOURCES = testsuite.cpp ../taocrypt/test/test.cpp \
../examples/client/client.cpp ../examples/server/server.cpp \
../examples/echoclient/echoclient.cpp \
../examples/echoserver/echoserver.cpp
-testsuite_LDFLAGS = -L../src/ -L../taocrypt/src
testsuite_CXXFLAGS = -DYASSL_PURE_C -DYASSL_PREFIX -DNO_MAIN_DRIVER
-testsuite_LDADD = -lyassl -ltaocrypt
-testsuite_DEPENDENCIES = ../src/libyassl.la ../taocrypt/src/libtaocrypt.la
+testsuite_LDADD = $(top_builddir)/extra/yassl/src/libyassl.la \
+ $(top_builddir)/extra/yassl/taocrypt/src/libtaocrypt.la
EXTRA_DIST = testsuite.dsp test.hpp input quit make.bat
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
+
diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp
index 482d384d415..0266c802657 100644
--- a/extra/yassl/testsuite/test.hpp
+++ b/extra/yassl/testsuite/test.hpp
@@ -27,24 +27,27 @@
#endif /* _WIN32 */
-#if !defined(_SOCKLEN_T) && defined(_WIN32)
+#if !defined(_SOCKLEN_T) && (defined(_WIN32) || defined(__NETWARE__))
typedef int socklen_t;
#endif
+// Check type of third arg to accept
+#if defined(__hpux)
// HPUX doesn't use socklent_t for third parameter to accept
-#if !defined(__hpux)
- typedef socklen_t* ACCEPT_THIRD_T;
-#else
typedef int* ACCEPT_THIRD_T;
+#else
+ typedef socklen_t* ACCEPT_THIRD_T;
+#endif
+
+// Check if _POSIX_THREADS should be forced
+#if !defined(_POSIX_THREADS) && (defined(__NETWARE__) || defined(__hpux))
// HPUX does not define _POSIX_THREADS as it's not _fully_ implemented
-#ifndef _POSIX_THREADS
+// Netware supports pthreads but does not announce it
#define _POSIX_THREADS
#endif
-#endif
-
#ifndef _POSIX_THREADS
typedef unsigned int THREAD_RETURN;
@@ -148,6 +151,13 @@ inline void err_sys(const char* msg)
}
+static int PasswordCallBack(char* passwd, int sz, int rw, void* userdata)
+{
+ strncpy(passwd, "12345678", sz);
+ return 8;
+}
+
+
inline void store_ca(SSL_CTX* ctx)
{
// To allow testing from serveral dirs
@@ -168,6 +178,7 @@ inline void store_ca(SSL_CTX* ctx)
inline void set_certs(SSL_CTX* ctx)
{
store_ca(ctx);
+ SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
// To allow testing from serveral dirs
if (SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM)
@@ -193,6 +204,7 @@ inline void set_certs(SSL_CTX* ctx)
inline void set_serverCerts(SSL_CTX* ctx)
{
store_ca(ctx);
+ SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
// To allow testing from serveral dirs
if (SSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM)
@@ -258,13 +270,27 @@ inline void tcp_socket(SOCKET_T& sockfd, sockaddr_in& addr)
}
+inline void tcp_close(SOCKET_T& sockfd)
+{
+#ifdef _WIN32
+ closesocket(sockfd);
+#else
+ close(sockfd);
+#endif
+ sockfd = -1;
+}
+
+
inline void tcp_connect(SOCKET_T& sockfd)
{
sockaddr_in addr;
tcp_socket(sockfd, addr);
if (connect(sockfd, (const sockaddr*)&addr, sizeof(addr)) != 0)
+ {
+ tcp_close(sockfd);
err_sys("tcp connect failed");
+ }
}
@@ -274,13 +300,19 @@ inline void tcp_listen(SOCKET_T& sockfd)
tcp_socket(sockfd, addr);
if (bind(sockfd, (const sockaddr*)&addr, sizeof(addr)) != 0)
+ {
+ tcp_close(sockfd);
err_sys("tcp bind failed");
+ }
if (listen(sockfd, 3) != 0)
+ {
+ tcp_close(sockfd);
err_sys("tcp listen failed");
+ }
}
-inline void tcp_accept(SOCKET_T& sockfd, int& clientfd, func_args& args)
+inline void tcp_accept(SOCKET_T& sockfd, SOCKET_T& clientfd, func_args& args)
{
tcp_listen(sockfd);
@@ -299,7 +331,10 @@ inline void tcp_accept(SOCKET_T& sockfd, int& clientfd, func_args& args)
clientfd = accept(sockfd, (sockaddr*)&client, (ACCEPT_THIRD_T)&client_len);
if (clientfd == -1)
+ {
+ tcp_close(sockfd);
err_sys("tcp accept failed");
+ }
}
diff --git a/include/m_ctype.h b/include/m_ctype.h
index 54ae41bf2e0..35d2889bdd5 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -112,6 +112,8 @@ enum my_lex_states
struct charset_info_st;
+
+/* See strings/CHARSET_INFO.txt for information about this structure */
typedef struct my_collation_handler_st
{
my_bool (*init)(struct charset_info_st *, void *(*alloc)(uint));
@@ -154,6 +156,7 @@ extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
+/* See strings/CHARSET_INFO.txt about information on this structure */
typedef struct my_charset_handler_st
{
my_bool (*init)(struct charset_info_st *, void *(*alloc)(uint));
@@ -184,7 +187,7 @@ typedef struct my_charset_handler_st
/* Charset dependant snprintf() */
int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt,
- ...);
+ ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5);
int (*long10_to_str)(struct charset_info_st *, char *to, uint n, int radix,
long int val);
int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n,
@@ -205,6 +208,9 @@ typedef struct my_charset_handler_st
int *err);
longlong (*strtoll10)(struct charset_info_st *cs,
const char *nptr, char **endptr, int *error);
+ ulonglong (*strntoull10rnd)(struct charset_info_st *cs,
+ const char *str, uint length, int unsigned_fl,
+ char **endptr, int *error);
ulong (*scan)(struct charset_info_st *, const char *b, const char *e,
int sq);
} MY_CHARSET_HANDLER;
@@ -213,6 +219,7 @@ extern MY_CHARSET_HANDLER my_charset_8bit_handler;
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
+/* See strings/CHARSET_INFO.txt about information on this structure */
typedef struct charset_info_st
{
uint number;
@@ -319,7 +326,8 @@ int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
ulong my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
int my_snprintf_8bit(struct charset_info_st *, char *to, uint n,
- const char *fmt, ...);
+ const char *fmt, ...)
+ ATTRIBUTE_FORMAT(printf, 4, 5);
long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l, int base,
char **e, int *err);
@@ -341,6 +349,13 @@ longlong my_strtoll10_8bit(CHARSET_INFO *cs,
longlong my_strtoll10_ucs2(CHARSET_INFO *cs,
const char *nptr, char **endptr, int *error);
+ulonglong my_strntoull10rnd_8bit(CHARSET_INFO *cs,
+ const char *str, uint length, int unsigned_fl,
+ char **endptr, int *error);
+ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs,
+ const char *str, uint length, int unsigned_fl,
+ char **endptr, int *error);
+
void my_fill_8bit(CHARSET_INFO *cs, char* to, uint l, int fill);
my_bool my_like_range_simple(CHARSET_INFO *cs,
diff --git a/include/m_string.h b/include/m_string.h
index c02ce92cd88..8a526d70d1d 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -254,7 +254,8 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
extern int my_vsnprintf( char *str, size_t n,
const char *format, va_list ap );
-extern int my_snprintf(char* to, size_t n, const char* fmt, ...);
+extern int my_snprintf(char *to, size_t n, const char *fmt, ...)
+ ATTRIBUTE_FORMAT(printf, 3, 4);
#if defined(__cplusplus) && !defined(OS2)
}
diff --git a/include/my_base.h b/include/my_base.h
index cffe1c3caf4..dda64db2ef9 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -224,12 +224,17 @@ enum ha_base_keytype {
/* poor old NISAM has 8-bit flags :-( */
#define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */
#endif
+#if MYSQL_VERSION_ID < 0x50200
/*
Key has a part that can have end space. If this is an unique key
we have to handle it differently from other unique keys as we can find
many matching rows for one key (because end space are not compared)
*/
-#define HA_END_SPACE_KEY 4096
+#define HA_END_SPACE_KEY 0 /* was: 4096 */
+#else
+#error HA_END_SPACE_KEY is obsolete, please remove it
+#endif
+
/* These flags can be added to key-seg-flag */
diff --git a/include/my_global.h b/include/my_global.h
index 4a9e1673de4..f94cedbc91a 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -454,12 +454,50 @@ typedef unsigned short ushort;
#define function_volatile volatile
#define my_reinterpret_cast(A) reinterpret_cast<A>
#define my_const_cast(A) const_cast<A>
+# ifndef GCC_VERSION
+# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
+# endif
#elif !defined(my_reinterpret_cast)
#define my_reinterpret_cast(A) (A)
#define my_const_cast(A) (A)
#endif
-#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
-#define __attribute__(A)
+
+/*
+ Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers.
+ Some forms of __attribute__ are actually supported in earlier versions of
+ g++, but we just disable them all because we only use them to generate
+ compilation warnings.
+*/
+#ifndef __attribute__
+# if !defined(__GNUC__)
+# define __attribute__(A)
+# elif GCC_VERSION < 2008
+# define __attribute__(A)
+# elif defined(__cplusplus) && GCC_VERSION < 3004
+# define __attribute__(A)
+# endif
+#endif
+
+/*
+ __attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4
+ But that's already covered by the __attribute__ tests above, so this is
+ just a convenience macro.
+*/
+#ifndef ATTRIBUTE_FORMAT
+# define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n)))
+#endif
+
+/*
+
+ __attribute__((format(...))) on a function pointer is not supported
+ until gcc 3.1
+*/
+#ifndef ATTRIBUTE_FORMAT_FPTR
+# if (GCC_VERSION >= 3001)
+# define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n)
+# else
+# define ATTRIBUTE_FORMAT_FPTR(style, m, n)
+# endif /* GNUC >= 3.1 */
#endif
/*
diff --git a/include/my_sys.h b/include/my_sys.h
index 9b283ace029..ebb518314b2 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -351,12 +351,18 @@ typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
#ifdef THREAD
typedef struct st_io_cache_share
{
- /* to sync on reads into buffer */
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- int count, total;
- /* actual IO_CACHE that filled the buffer */
- struct st_io_cache *active;
+ pthread_mutex_t mutex; /* To sync on reads into buffer. */
+ pthread_cond_t cond; /* To wait for signals. */
+ pthread_cond_t cond_writer; /* For a synchronized writer. */
+ /* Offset in file corresponding to the first byte of buffer. */
+ my_off_t pos_in_file;
+ /* If a synchronized write cache is the source of the data. */
+ struct st_io_cache *source_cache;
+ byte *buffer; /* The read buffer. */
+ byte *read_end; /* Behind last valid byte of buffer. */
+ int running_threads; /* threads not in lock. */
+ int total_threads; /* threads sharing the cache. */
+ int error; /* Last error. */
#ifdef NOT_YET_IMPLEMENTED
/* whether the structure should be free'd */
my_bool alloced;
@@ -632,8 +638,8 @@ extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
extern int my_sync(File fd, myf my_flags);
extern int my_error _VARARGS((int nr,myf MyFlags, ...));
extern int my_printf_error _VARARGS((uint my_err, const char *format,
- myf MyFlags, ...)
- __attribute__ ((format (printf, 2, 4))));
+ myf MyFlags, ...))
+ ATTRIBUTE_FORMAT(printf, 2, 4);
extern int my_error_register(const char **errmsgs, int first, int last);
extern const char **my_error_unregister(int first, int last);
extern int my_message(uint my_err, const char *str,myf MyFlags);
@@ -720,8 +726,8 @@ extern void setup_io_cache(IO_CACHE* info);
extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count);
#ifdef THREAD
extern int _my_b_read_r(IO_CACHE *info,byte *Buffer,uint Count);
-extern void init_io_cache_share(IO_CACHE *info,
- IO_CACHE_SHARE *s, uint num_threads);
+extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
+ IO_CACHE *write_cache, uint num_threads);
extern void remove_io_thread(IO_CACHE *info);
#endif
extern int _my_b_seq_read(IO_CACHE *info,byte *Buffer,uint Count);
diff --git a/include/myisam.h b/include/myisam.h
index 321952dcf4c..95852366251 100644
--- a/include/myisam.h
+++ b/include/myisam.h
@@ -419,7 +419,7 @@ typedef struct st_mi_check_param
uint testflag, key_cache_block_size;
uint8 language;
my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
- my_bool retry_repair, force_sort, calc_checksum;
+ my_bool retry_repair, force_sort;
char temp_filename[FN_REFLEN],*isam_file_name;
MY_TMPDIR *tmpdir;
int tmpfile_createflag;
diff --git a/include/mysql.h b/include/mysql.h
index ae4a8222c5b..8ef3f1273ec 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -293,12 +293,6 @@ typedef struct st_mysql
/* needed for embedded server - no net buffer to store the 'info' */
char *info_buffer;
#endif
- /*
- In embedded server it points to the statement that is processed
- in the current query. We store some results directly in statement
- fields then.
- */
- struct st_mysql_stmt *current_stmt;
} MYSQL;
typedef struct st_mysql_res {
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 4c7640376a6..1bbb3cf1737 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -134,11 +134,11 @@ enum enum_server_command
#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
-#define CLIENT_MULTI_STATEMENTS (((ulong) 1) << 16) /* Enable/disable multi-stmt support */
-#define CLIENT_MULTI_RESULTS (((ulong) 1) << 17) /* Enable/disable multi-results */
+#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
+#define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */
-#define CLIENT_SSL_VERIFY_SERVER_CERT (((ulong) 1) << 30)
-#define CLIENT_REMEMBER_OPTIONS (((ulong) 1) << 31)
+#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
+#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c
index 9c7d9c5c3da..eb10a88d1d1 100644
--- a/innobase/ibuf/ibuf0ibuf.c
+++ b/innobase/ibuf/ibuf0ibuf.c
@@ -1361,8 +1361,8 @@ ibuf_entry_build(
index tree; NOTE that the original entry
must be kept because we copy pointers to its
fields */
+ dict_index_t* index, /* in: non-clustered index */
dtuple_t* entry, /* in: entry for a non-clustered index */
- ibool comp, /* in: flag: TRUE=compact record format */
ulint space, /* in: space id */
ulint page_no,/* in: index page number where entry should
be inserted */
@@ -1426,13 +1426,13 @@ ibuf_entry_build(
dfield_set_data(field, buf, 4);
- ut_ad(comp == 0 || comp == 1);
+ ut_ad(index->table->comp <= 1);
/* Store the type info in buf2, and add the fields from entry to
tuple */
buf2 = mem_heap_alloc(heap, n_fields
* DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
- + comp);
- if (comp) {
+ + index->table->comp);
+ if (index->table->comp) {
*buf2++ = 0; /* write the compact format indicator */
}
for (i = 0; i < n_fields; i++) {
@@ -1445,20 +1445,22 @@ ibuf_entry_build(
dtype_new_store_for_order_and_null_size(
buf2 + i * DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE,
- dfield_get_type(entry_field));
+ dfield_get_type(entry_field),
+ dict_index_get_nth_field(index, i)
+ ->prefix_len);
}
/* Store the type info in buf2 to field 3 of tuple */
field = dtuple_get_nth_field(tuple, 3);
- if (comp) {
+ if (index->table->comp) {
buf2--;
}
dfield_set_data(field, buf2, n_fields
* DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
- + comp);
+ + index->table->comp);
/* Set all the types in the new tuple binary */
dtuple_set_types_binary(tuple, n_fields + 4);
@@ -2589,8 +2591,7 @@ ibuf_insert_low(
the first fields and the type information for other fields, and which
will be inserted to the insert buffer. */
- ibuf_entry = ibuf_entry_build(entry, index->table->comp,
- space, page_no, heap);
+ ibuf_entry = ibuf_entry_build(index, entry, space, page_no, heap);
/* Open a cursor to the insert buffer tree to calculate if we can add
the new entry to it without exceeding the free space limit for the
diff --git a/innobase/include/data0type.h b/innobase/include/data0type.h
index 30c0f732c34..abfbc24e336 100644
--- a/innobase/include/data0type.h
+++ b/innobase/include/data0type.h
@@ -366,7 +366,9 @@ dtype_new_store_for_order_and_null_size(
byte* buf, /* in: buffer for
DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
bytes where we store the info */
- dtype_t* type); /* in: type struct */
+ dtype_t* type, /* in: type struct */
+ ulint prefix_len);/* in: prefix length to
+ replace type->len, or 0 */
/**************************************************************************
Reads to a type the stored information which determines its alphabetical
ordering and the storage size of an SQL NULL value. This is the 4.1.x storage
diff --git a/innobase/include/data0type.ic b/innobase/include/data0type.ic
index ad0f02fa63d..032c1d7efd7 100644
--- a/innobase/include/data0type.ic
+++ b/innobase/include/data0type.ic
@@ -230,11 +230,14 @@ dtype_new_store_for_order_and_null_size(
byte* buf, /* in: buffer for
DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
bytes where we store the info */
- dtype_t* type) /* in: type struct */
+ dtype_t* type, /* in: type struct */
+ ulint prefix_len)/* in: prefix length to
+ replace type->len, or 0 */
{
#if 6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
#error "6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE"
#endif
+ ulint len;
buf[0] = (byte)(type->mtype & 0xFFUL);
@@ -249,7 +252,9 @@ dtype_new_store_for_order_and_null_size(
buf[1] = (byte)(type->prtype & 0xFFUL);
- mach_write_to_2(buf + 2, type->len & 0xFFFFUL);
+ len = prefix_len ? prefix_len : type->len;
+
+ mach_write_to_2(buf + 2, len & 0xFFFFUL);
ut_ad(dtype_get_charset_coll(type->prtype) < 256);
mach_write_to_2(buf + 4, dtype_get_charset_coll(type->prtype));
diff --git a/innobase/include/univ.i b/innobase/include/univ.i
index bc3bd031f0c..64a240ae8a7 100644
--- a/innobase/include/univ.i
+++ b/innobase/include/univ.i
@@ -39,8 +39,10 @@ if we are compiling on Windows. */
#undef PACKAGE
#undef VERSION
+#if !defined(__WIN__) && !defined(WIN64) && !defined(_WIN64)
/* Include the header file generated by GNU autoconf */
#include "../ib_config.h"
+#endif
#ifdef HAVE_SCHED_H
#include <sched.h>
diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c
index 6e0dc720bf8..8530f117c9d 100644
--- a/innobase/srv/srv0start.c
+++ b/innobase/srv/srv0start.c
@@ -1140,7 +1140,7 @@ innobase_start_or_create_for_mysql(void)
maximum number of threads that can wait in the 'srv_conc array' for
their time to enter InnoDB. */
-#if defined(__WIN__) || defined(__NETWARE__)
+#if defined(__NETWARE__)
/* Create less event semaphores because Win 98/ME had difficulty creating
40000 event semaphores.
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 21fb84fb19a..8786655d9c3 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -4769,14 +4769,6 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
DBUG_RETURN(1);
}
- if (result->data)
- {
- free_root(&result->alloc, MYF(MY_KEEP_PREALLOC));
- result->data= NULL;
- result->rows= 0;
- stmt->data_cursor= NULL;
- }
-
if (stmt->update_max_length && !stmt->bind_result_done)
{
/*
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 40966be46a5..a88c0b135db 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -100,7 +100,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
mysql->affected_rows= ~(my_ulonglong) 0;
mysql->field_count= 0;
net->last_errno= 0;
- mysql->current_stmt= stmt;
+ thd->current_stmt= stmt;
thd->store_globals(); // Fix if more than one connect
/*
diff --git a/myisam/mi_check.c b/myisam/mi_check.c
index 5a81d221d2a..06fdd3bff4c 100644
--- a/myisam/mi_check.c
+++ b/myisam/mi_check.c
@@ -16,6 +16,31 @@
/* Describe, check and repair of MyISAM tables */
+/*
+ About checksum calculation.
+
+ There are two types of checksums. Table checksum and row checksum.
+
+ Row checksum is an additional byte at the end of dynamic length
+ records. It must be calculated if the table is configured for them.
+ Otherwise they must not be used. The variable
+ MYISAM_SHARE::calc_checksum determines if row checksums are used.
+ MI_INFO::checksum is used as temporary storage during row handling.
+ For parallel repair we must assure that only one thread can use this
+ variable. There is no problem on the write side as this is done by one
+ thread only. But when checking a record after read this could go
+ wrong. But since all threads read through a common read buffer, it is
+ sufficient if only one thread checks it.
+
+ Table checksum is an eight byte value in the header of the index file.
+ It can be calculated even if row checksums are not used. The variable
+ MI_CHECK::glob_crc is calculated over all records.
+ MI_SORT_PARAM::calc_checksum determines if this should be done. This
+ variable is not part of MI_CHECK because it must be set per thread for
+ parallel repair. The global glob_crc must be changed by one thread
+ only. And it is sufficient to calculate the checksum once only.
+*/
+
#include "ftdefs.h"
#include <m_ctype.h>
#include <stdarg.h>
@@ -41,8 +66,7 @@ static int chk_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
ha_checksum *key_checksum, uint level);
static uint isam_key_length(MI_INFO *info,MI_KEYDEF *keyinfo);
static ha_checksum calc_checksum(ha_rows count);
-static int writekeys(MI_CHECK *param, MI_INFO *info,byte *buff,
- my_off_t filepos);
+static int writekeys(MI_SORT_PARAM *sort_param);
static int sort_one_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
my_off_t pagepos, File new_file);
static int sort_key_read(MI_SORT_PARAM *sort_param,void *key);
@@ -1102,7 +1126,8 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
goto err;
start_recpos=pos;
splits++;
- VOID(_mi_pack_get_block_info(info,&block_info, -1, start_recpos));
+ VOID(_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, -1, start_recpos));
pos=block_info.filepos+block_info.rec_len;
if (block_info.rec_len < (uint) info->s->min_pack_length ||
block_info.rec_len > (uint) info->s->max_pack_length)
@@ -1116,7 +1141,8 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
if (_mi_read_cache(&param->read_cache,(byte*) info->rec_buff,
block_info.filepos, block_info.rec_len, READING_NEXT))
goto err;
- if (_mi_pack_rec_unpack(info,record,info->rec_buff,block_info.rec_len))
+ if (_mi_pack_rec_unpack(info, &info->bit_buff, record,
+ info->rec_buff, block_info.rec_len))
{
mi_check_print_error(param,"Found wrong record at %s",
llstr(start_recpos,llbuff));
@@ -1400,7 +1426,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
info->state->empty=0;
param->glob_crc=0;
if (param->testflag & T_CALC_CHECKSUM)
- param->calc_checksum=1;
+ sort_param.calc_checksum= 1;
info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
@@ -1429,7 +1455,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
/* Re-create all keys, which are set in key_map. */
while (!(error=sort_get_next_record(&sort_param)))
{
- if (writekeys(param,info,(byte*)sort_param.record,sort_param.filepos))
+ if (writekeys(&sort_param))
{
if (my_errno != HA_ERR_FOUND_DUPP_KEY)
goto err;
@@ -1574,11 +1600,13 @@ err:
/* Uppate keyfile when doing repair */
-static int writekeys(MI_CHECK *param, register MI_INFO *info, byte *buff,
- my_off_t filepos)
+static int writekeys(MI_SORT_PARAM *sort_param)
{
register uint i;
- uchar *key;
+ uchar *key;
+ MI_INFO *info= sort_param->sort_info->info;
+ byte *buff= sort_param->record;
+ my_off_t filepos= sort_param->filepos;
DBUG_ENTER("writekeys");
key=info->lastkey+info->s->base.max_key_length;
@@ -1632,8 +1660,8 @@ static int writekeys(MI_CHECK *param, register MI_INFO *info, byte *buff,
}
}
/* Remove checksum that was added to glob_crc in sort_get_next_record */
- if (param->calc_checksum)
- param->glob_crc-= info->checksum;
+ if (sort_param->calc_checksum)
+ sort_param->sort_info->param->glob_crc-= info->checksum;
DBUG_PRINT("error",("errno: %d",my_errno));
DBUG_RETURN(-1);
} /* writekeys */
@@ -2139,7 +2167,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
del=info->state->del;
param->glob_crc=0;
if (param->testflag & T_CALC_CHECKSUM)
- param->calc_checksum=1;
+ sort_param.calc_checksum= 1;
rec_per_key_part= param->rec_per_key_part;
for (sort_param.key=0 ; sort_param.key < share->base.keys ;
@@ -2201,7 +2229,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
param->retry_repair=1;
goto err;
}
- param->calc_checksum=0; /* No need to calc glob_crc */
+ /* No need to calculate checksum again. */
+ sort_param.calc_checksum= 0;
/* Set for next loop */
sort_info.max_records= (ha_rows) info->state->records;
@@ -2364,6 +2393,28 @@ err:
Each key is handled by a separate thread.
TODO: make a number of threads a parameter
+ In parallel repair we use one thread per index. There are two modes:
+
+ Quick
+
+ Only the indexes are rebuilt. All threads share a read buffer.
+ Every thread that needs fresh data in the buffer enters the shared
+ cache lock. The last thread joining the lock reads the buffer from
+ the data file and wakes all other threads.
+
+ Non-quick
+
+ The data file is rebuilt and all indexes are rebuilt to point to
+ the new record positions. One thread is the master thread. It
+ reads from the old data file and writes to the new data file. It
+ also creates one of the indexes. The other threads read from a
+ buffer which is filled by the master. If they need fresh data,
+ they enter the shared cache lock. If the masters write buffer is
+ full, it flushes it to the new data file and enters the shared
+ cache lock too. When all threads joined in the lock, the master
+ copies its write buffer to the read buffer for the other threads
+ and wakes them.
+
RESULT
0 ok
<>0 Error
@@ -2386,6 +2437,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
ulong *rec_per_key_part;
HA_KEYSEG *keyseg;
char llbuff[22];
+ IO_CACHE new_data_cache; /* For non-quick repair. */
IO_CACHE_SHARE io_share;
SORT_INFO sort_info;
ulonglong key_map=share->state.key_map;
@@ -2407,19 +2459,55 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (info->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
param->testflag|=T_CALC_CHECKSUM;
+ /*
+ Quick repair (not touching data file, rebuilding indexes):
+ {
+ Read cache is (MI_CHECK *param)->read_cache using info->dfile.
+ }
+
+ Non-quick repair (rebuilding data file and indexes):
+ {
+ Master thread:
+
+ Read cache is (MI_CHECK *param)->read_cache using info->dfile.
+ Write cache is (MI_INFO *info)->rec_cache using new_file.
+
+ Slave threads:
+
+ Read cache is new_data_cache synced to master rec_cache.
+
+ The final assignment of the filedescriptor for rec_cache is done
+ after the cache creation.
+
+ Don't check file size on new_data_cache, as the resulting file size
+ is not known yet.
+
+ As rec_cache and new_data_cache are synced, write_buffer_length is
+ used for the read cache 'new_data_cache'. Both start at the same
+ position 'new_header_length'.
+ }
+ */
+ DBUG_PRINT("info", ("is quick repair: %d", rep_quick));
bzero((char*)&sort_info,sizeof(sort_info));
+ /* Initialize pthread structures before goto err. */
+ pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST);
+ pthread_cond_init(&sort_info.cond, 0);
+
if (!(sort_info.key_block=
- alloc_key_blocks(param,
- (uint) param->sort_key_blocks,
- share->base.max_key_block_length))
- || init_io_cache(&param->read_cache,info->dfile,
- (uint) param->read_buffer_length,
- READ_CACHE,share->pack.header_length,1,MYF(MY_WME)) ||
- (! rep_quick &&
- init_io_cache(&info->rec_cache,info->dfile,
- (uint) param->write_buffer_length,
- WRITE_CACHE,new_header_length,1,
- MYF(MY_WME | MY_WAIT_IF_FULL) & param->myf_rw)))
+ alloc_key_blocks(param, (uint) param->sort_key_blocks,
+ share->base.max_key_block_length)) ||
+ init_io_cache(&param->read_cache, info->dfile,
+ (uint) param->read_buffer_length,
+ READ_CACHE, share->pack.header_length, 1, MYF(MY_WME)) ||
+ (!rep_quick &&
+ (init_io_cache(&info->rec_cache, info->dfile,
+ (uint) param->write_buffer_length,
+ WRITE_CACHE, new_header_length, 1,
+ MYF(MY_WME | MY_WAIT_IF_FULL) & param->myf_rw) ||
+ init_io_cache(&new_data_cache, -1,
+ (uint) param->write_buffer_length,
+ READ_CACHE, new_header_length, 1,
+ MYF(MY_WME | MY_DONT_CHECK_FILESIZE)))))
goto err;
sort_info.key_block_end=sort_info.key_block+param->sort_key_blocks;
info->opt_flag|=WRITE_CACHE_USED;
@@ -2510,8 +2598,6 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
del=info->state->del;
param->glob_crc=0;
- if (param->testflag & T_CALC_CHECKSUM)
- param->calc_checksum=1;
if (!(sort_param=(MI_SORT_PARAM *)
my_malloc((uint) share->base.keys *
@@ -2561,6 +2647,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
sort_param[i].sort_info=&sort_info;
sort_param[i].master=0;
sort_param[i].fix_datafile=0;
+ sort_param[i].calc_checksum= 0;
sort_param[i].filepos=new_header_length;
sort_param[i].max_pos=sort_param[i].pos=share->pack.header_length;
@@ -2597,19 +2684,45 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
sort_info.total_keys=i;
sort_param[0].master= 1;
sort_param[0].fix_datafile= (my_bool)(! rep_quick);
+ sort_param[0].calc_checksum= test(param->testflag & T_CALC_CHECKSUM);
sort_info.got_error=0;
- pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST);
- pthread_cond_init(&sort_info.cond, 0);
pthread_mutex_lock(&sort_info.mutex);
- init_io_cache_share(&param->read_cache, &io_share, i);
+ /*
+ Initialize the I/O cache share for use with the read caches and, in
+ case of non-quick repair, the write cache. When all threads join on
+ the cache lock, the writer copies the write cache contents to the
+ read caches.
+ */
+ if (i > 1)
+ {
+ if (rep_quick)
+ init_io_cache_share(&param->read_cache, &io_share, NULL, i);
+ else
+ init_io_cache_share(&new_data_cache, &io_share, &info->rec_cache, i);
+ }
+ else
+ io_share.total_threads= 0; /* share not used */
+
(void) pthread_attr_init(&thr_attr);
(void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
for (i=0 ; i < sort_info.total_keys ; i++)
{
- sort_param[i].read_cache=param->read_cache;
+ /*
+ Copy the properly initialized IO_CACHE structure so that every
+ thread has its own copy. In quick mode param->read_cache is shared
+ for use by all threads. In non-quick mode all threads but the
+ first copy the shared new_data_cache, which is synchronized to the
+ write cache of the first thread. The first thread copies
+ param->read_cache, which is not shared.
+ */
+ sort_param[i].read_cache= ((rep_quick || !i) ? param->read_cache :
+ new_data_cache);
+ DBUG_PRINT("io_cache_share", ("thread: %u read_cache: 0x%lx",
+ i, (long) &sort_param[i].read_cache));
+
/*
two approaches: the same amount of memory for each thread
or the memory for the same number of keys for each thread...
@@ -2627,7 +2740,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
(void *) (sort_param+i)))
{
mi_check_print_error(param,"Cannot start a repair thread");
- remove_io_thread(&param->read_cache);
+ /* Cleanup: Detach from the share. Avoid others to be blocked. */
+ if (io_share.total_threads)
+ remove_io_thread(&sort_param[i].read_cache);
+ DBUG_PRINT("error", ("Cannot start a repair thread"));
sort_info.got_error=1;
}
else
@@ -2649,6 +2765,11 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (sort_param[0].fix_datafile)
{
+ /*
+ Append some nuls to the end of a memory mapped file. Destroy the
+ write cache. The master thread did already detach from the share
+ by remove_io_thread() in sort.c:thr_find_all_keys().
+ */
if (write_data_suffix(&sort_info,1) || end_io_cache(&info->rec_cache))
goto err;
if (param->testflag & T_SAFE_REPAIR)
@@ -2664,8 +2785,14 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
sort_param->filepos;
/* Only whole records */
share->state.version=(ulong) time((time_t*) 0);
+
+ /*
+ Exchange the data file descriptor of the table, so that we use the
+ new file from now on.
+ */
my_close(info->dfile,MYF(0));
info->dfile=new_file;
+
share->data_file_type=sort_info.new_data_file_type;
share->pack.header_length=(ulong) new_header_length;
}
@@ -2720,7 +2847,20 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
err:
got_error|= flush_blocks(param, share->key_cache, share->kfile);
+ /*
+ Destroy the write cache. The master thread did already detach from
+ the share by remove_io_thread() or it was not yet started (if the
+ error happend before creating the thread).
+ */
VOID(end_io_cache(&info->rec_cache));
+ /*
+ Destroy the new data cache in case of non-quick repair. All slave
+ threads did either detach from the share by remove_io_thread()
+ already or they were not yet started (if the error happend before
+ creating the threads).
+ */
+ if (!rep_quick)
+ VOID(end_io_cache(&new_data_cache));
if (!got_error)
{
/* Replace the actual file with the temporary file */
@@ -2851,12 +2991,41 @@ static int sort_ft_key_read(MI_SORT_PARAM *sort_param, void *key)
} /* sort_ft_key_read */
- /* Read next record from file using parameters in sort_info */
- /* Return -1 if end of file, 0 if ok and > 0 if error */
+/*
+ Read next record from file using parameters in sort_info.
+
+ SYNOPSIS
+ sort_get_next_record()
+ sort_param Information about and for the sort process
+
+ NOTE
+
+ Dynamic Records With Non-Quick Parallel Repair
+
+ For non-quick parallel repair we use a synchronized read/write
+ cache. This means that one thread is the master who fixes the data
+ file by reading each record from the old data file and writing it
+ to the new data file. By doing this the records in the new data
+ file are written contiguously. Whenever the write buffer is full,
+ it is copied to the read buffer. The slaves read from the read
+ buffer, which is not associated with a file. Thus read_cache.file
+ is -1. When using _mi_read_cache(), the slaves must always set
+ flag to READING_NEXT so that the function never tries to read from
+ file. This is safe because the records are contiguous. There is no
+ need to read outside the cache. This condition is evaluated in the
+ variable 'parallel_flag' for quick reference. read_cache.file must
+ be >= 0 in every other case.
+
+ RETURN
+ -1 end of file
+ 0 ok
+ > 0 error
+*/
static int sort_get_next_record(MI_SORT_PARAM *sort_param)
{
int searching;
+ int parallel_flag;
uint found_record,b_type,left_length;
my_off_t pos;
byte *to;
@@ -2894,7 +3063,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
sort_param->max_pos=(sort_param->pos+=share->base.pack_reclength);
if (*sort_param->record)
{
- if (param->calc_checksum)
+ if (sort_param->calc_checksum)
param->glob_crc+= (info->checksum=
mi_static_checksum(info,sort_param->record));
DBUG_RETURN(0);
@@ -2909,6 +3078,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
LINT_INIT(to);
pos=sort_param->pos;
searching=(sort_param->fix_datafile && (param->testflag & T_EXTEND));
+ parallel_flag= (sort_param->read_cache.file < 0) ? READING_NEXT : 0;
for (;;)
{
found_record=block_info.second_read= 0;
@@ -2939,7 +3109,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
(byte*) block_info.header,pos,
MI_BLOCK_INFO_HEADER_LENGTH,
(! found_record ? READING_NEXT : 0) |
- READING_HEADER))
+ parallel_flag | READING_HEADER))
{
if (found_record)
{
@@ -3116,9 +3286,31 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
llstr(sort_param->start_recpos,llbuff));
goto try_next;
}
- if (_mi_read_cache(&sort_param->read_cache,to,block_info.filepos,
- block_info.data_len,
- (found_record == 1 ? READING_NEXT : 0)))
+ /*
+ Copy information that is already read. Avoid accessing data
+ below the cache start. This could happen if the header
+ streched over the end of the previous buffer contents.
+ */
+ {
+ uint header_len= (uint) (block_info.filepos - pos);
+ uint prefetch_len= (MI_BLOCK_INFO_HEADER_LENGTH - header_len);
+
+ if (prefetch_len > block_info.data_len)
+ prefetch_len= block_info.data_len;
+ if (prefetch_len)
+ {
+ memcpy(to, block_info.header + header_len, prefetch_len);
+ block_info.filepos+= prefetch_len;
+ block_info.data_len-= prefetch_len;
+ left_length-= prefetch_len;
+ to+= prefetch_len;
+ }
+ }
+ if (block_info.data_len &&
+ _mi_read_cache(&sort_param->read_cache,to,block_info.filepos,
+ block_info.data_len,
+ (found_record == 1 ? READING_NEXT : 0) |
+ parallel_flag))
{
mi_check_print_info(param,
"Read error for block at: %s (error: %d); Skipped",
@@ -3148,13 +3340,14 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
{
if (sort_param->read_cache.error < 0)
DBUG_RETURN(1);
- if (info->s->calc_checksum)
- info->checksum=mi_checksum(info,sort_param->record);
+ if (sort_param->calc_checksum)
+ info->checksum= mi_checksum(info, sort_param->record);
if ((param->testflag & (T_EXTEND | T_REP)) || searching)
{
if (_mi_rec_check(info, sort_param->record, sort_param->rec_buff,
sort_param->find_length,
(param->testflag & T_QUICK) &&
+ sort_param->calc_checksum &&
test(info->s->calc_checksum)))
{
mi_check_print_info(param,"Found wrong packed record at %s",
@@ -3162,7 +3355,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
goto try_next;
}
}
- if (param->calc_checksum)
+ if (sort_param->calc_checksum)
param->glob_crc+= info->checksum;
DBUG_RETURN(0);
}
@@ -3189,7 +3382,8 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
DBUG_RETURN(1); /* Something wrong with data */
}
sort_param->start_recpos=sort_param->pos;
- if (_mi_pack_get_block_info(info,&block_info,-1,sort_param->pos))
+ if (_mi_pack_get_block_info(info, &sort_param->bit_buff, &block_info,
+ &sort_param->rec_buff, -1, sort_param->pos))
DBUG_RETURN(-1);
if (!block_info.rec_len &&
sort_param->pos + MEMMAP_EXTRA_MARGIN ==
@@ -3213,15 +3407,14 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
llstr(sort_param->pos,llbuff));
continue;
}
- if (_mi_pack_rec_unpack(info,sort_param->record,sort_param->rec_buff,
- block_info.rec_len))
+ if (_mi_pack_rec_unpack(info, &sort_param->bit_buff, sort_param->record,
+ sort_param->rec_buff, block_info.rec_len))
{
if (! searching)
mi_check_print_info(param,"Found wrong record at %s",
llstr(sort_param->pos,llbuff));
continue;
}
- info->checksum=mi_checksum(info,sort_param->record);
if (!sort_param->fix_datafile)
{
sort_param->filepos=sort_param->pos;
@@ -3231,8 +3424,9 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
sort_param->max_pos=(sort_param->pos=block_info.filepos+
block_info.rec_len);
info->packed_length=block_info.rec_len;
- if (param->calc_checksum)
- param->glob_crc+= info->checksum;
+ if (sort_param->calc_checksum)
+ param->glob_crc+= (info->checksum=
+ mi_checksum(info, sort_param->record));
DBUG_RETURN(0);
}
}
@@ -3240,7 +3434,20 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
}
- /* Write record to new file */
+/*
+ Write record to new file.
+
+ SYNOPSIS
+ sort_write_record()
+ sort_param Sort parameters.
+
+ NOTE
+ This is only called by a master thread if parallel repair is used.
+
+ RETURN
+ 0 OK
+ 1 Error
+*/
int sort_write_record(MI_SORT_PARAM *sort_param)
{
@@ -3289,6 +3496,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
}
from=sort_info->buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER);
}
+ /* We can use info->checksum here as only one thread calls this. */
info->checksum=mi_checksum(info,sort_param->record);
reclength=_mi_rec_pack(info,from,sort_param->record);
flag=0;
@@ -3698,7 +3906,7 @@ static int sort_delete_record(MI_SORT_PARAM *sort_param)
DBUG_RETURN(1);
}
}
- if (param->calc_checksum)
+ if (sort_param->calc_checksum)
param->glob_crc-=(*info->s->calc_checksum)(info, sort_param->record);
}
error=flush_io_cache(&info->rec_cache) || (*info->s->delete_record)(info);
diff --git a/myisam/mi_delete.c b/myisam/mi_delete.c
index 2bc99d65dd2..85cc60bdd9d 100644
--- a/myisam/mi_delete.c
+++ b/myisam/mi_delete.c
@@ -446,7 +446,7 @@ static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key,
else
{
DBUG_PRINT("test",("Inserting of key when deleting"));
- if (_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
+ if (!_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
&tmp))
goto err;
ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c
index 8d48c5242e5..36b793363c5 100644
--- a/myisam/mi_locking.c
+++ b/myisam/mi_locking.c
@@ -224,6 +224,21 @@ int mi_lock_database(MI_INFO *info, int lock_type)
break; /* Impossible */
}
}
+#ifdef __WIN__
+ else
+ {
+ /*
+ Check for bad file descriptors if this table is part
+ of a merge union. Failing to capture this may cause
+ a crash on windows if the table is renamed and
+ later on referenced by the merge table.
+ */
+ if( info->owned_by_merge && (info->s)->kfile < 0 )
+ {
+ error = HA_ERR_NO_SUCH_TABLE;
+ }
+ }
+#endif
pthread_mutex_unlock(&share->intern_lock);
#if defined(FULL_LOG) || defined(_lint)
lock_type|=(int) (flag << 8); /* Set bit to set if real lock */
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index 955d55cf765..a52ab5aad1f 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -208,7 +208,10 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
((open_flags & HA_OPEN_ABORT_IF_CRASHED) &&
(my_disable_locking && share->state.open_count))))
{
- DBUG_PRINT("error",("Table is marked as crashed"));
+ DBUG_PRINT("error",("Table is marked as crashed. open_flags: %u "
+ "changed: %u open_count: %u !locking: %d",
+ open_flags, share->state.changed,
+ share->state.open_count, my_disable_locking));
my_errno=((share->state.changed & STATE_CRASHED_ON_REPAIR) ?
HA_ERR_CRASHED_ON_REPAIR : HA_ERR_CRASHED_ON_USAGE);
goto err;
diff --git a/myisam/mi_packrec.c b/myisam/mi_packrec.c
index c9653eadc28..13898df0466 100644
--- a/myisam/mi_packrec.c
+++ b/myisam/mi_packrec.c
@@ -103,7 +103,8 @@ static uint fill_and_get_bits(MI_BIT_BUFF *bit_buff,uint count);
static void fill_buffer(MI_BIT_BUFF *bit_buff);
static uint max_bit(uint value);
#ifdef HAVE_MMAP
-static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
+static uchar *_mi_mempack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
uchar *header);
#endif
@@ -449,13 +450,15 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, byte *buf)
DBUG_RETURN(-1); /* _search() didn't find record */
file=info->dfile;
- if (_mi_pack_get_block_info(info, &block_info, file, filepos))
+ if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, file, filepos))
goto err;
if (my_read(file,(byte*) info->rec_buff + block_info.offset ,
block_info.rec_len - block_info.offset, MYF(MY_NABP)))
goto panic;
info->update|= HA_STATE_AKTIV;
- DBUG_RETURN(_mi_pack_rec_unpack(info,buf,info->rec_buff,block_info.rec_len));
+ DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ info->rec_buff, block_info.rec_len));
panic:
my_errno=HA_ERR_WRONG_IN_RECORD;
err:
@@ -464,8 +467,8 @@ err:
-int _mi_pack_rec_unpack(register MI_INFO *info, register byte *to, byte *from,
- ulong reclength)
+int _mi_pack_rec_unpack(register MI_INFO *info, MI_BIT_BUFF *bit_buff,
+ register byte *to, byte *from, ulong reclength)
{
byte *end_field;
reg3 MI_COLUMNDEF *end;
@@ -473,18 +476,18 @@ int _mi_pack_rec_unpack(register MI_INFO *info, register byte *to, byte *from,
MYISAM_SHARE *share=info->s;
DBUG_ENTER("_mi_pack_rec_unpack");
- init_bit_buffer(&info->bit_buff, (uchar*) from,reclength);
+ init_bit_buffer(bit_buff, (uchar*) from, reclength);
for (current_field=share->rec, end=current_field+share->base.fields ;
current_field < end ;
current_field++,to=end_field)
{
end_field=to+current_field->length;
- (*current_field->unpack)(current_field,&info->bit_buff,(uchar*) to,
+ (*current_field->unpack)(current_field, bit_buff, (uchar*) to,
(uchar*) end_field);
}
- if (! info->bit_buff.error &&
- info->bit_buff.pos - info->bit_buff.bits/8 == info->bit_buff.end)
+ if (!bit_buff->error &&
+ bit_buff->pos - bit_buff->bits / 8 == bit_buff->end)
DBUG_RETURN(0);
info->update&= ~HA_STATE_AKTIV;
DBUG_RETURN(my_errno=HA_ERR_WRONG_IN_RECORD);
@@ -1015,13 +1018,16 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
if (info->opt_flag & READ_CACHE_USED)
{
- if (_mi_read_cache(&info->rec_cache,(byte*) block_info.header,filepos,
- share->pack.ref_length, skip_deleted_blocks))
+ if (_mi_read_cache(&info->rec_cache, (byte*) block_info.header,
+ filepos, share->pack.ref_length,
+ skip_deleted_blocks ? READING_NEXT : 0))
goto err;
- b_type=_mi_pack_get_block_info(info,&block_info,-1, filepos);
+ b_type=_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, -1, filepos);
}
else
- b_type=_mi_pack_get_block_info(info,&block_info,info->dfile,filepos);
+ b_type=_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, info->dfile, filepos);
if (b_type)
goto err; /* Error code is already set */
#ifndef DBUG_OFF
@@ -1034,9 +1040,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
if (info->opt_flag & READ_CACHE_USED)
{
- if (_mi_read_cache(&info->rec_cache,(byte*) info->rec_buff,
- block_info.filepos, block_info.rec_len,
- skip_deleted_blocks))
+ if (_mi_read_cache(&info->rec_cache, (byte*) info->rec_buff,
+ block_info.filepos, block_info.rec_len,
+ skip_deleted_blocks ? READING_NEXT : 0))
goto err;
}
else
@@ -1051,8 +1057,8 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
info->nextpos=block_info.filepos+block_info.rec_len;
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
- DBUG_RETURN (_mi_pack_rec_unpack(info,buf,info->rec_buff,
- block_info.rec_len));
+ DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ info->rec_buff, block_info.rec_len));
err:
DBUG_RETURN(my_errno);
}
@@ -1060,8 +1066,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
/* Read and process header from a huff-record-file */
-uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file,
- my_off_t filepos)
+uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
+ File file, my_off_t filepos)
{
uchar *header=info->header;
uint head_length,ref_length;
@@ -1086,17 +1093,17 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file,
head_length+= read_pack_length((uint) myisam->s->pack.version,
header + head_length, &info->blob_len);
if (!(mi_alloc_rec_buff(myisam,info->rec_len + info->blob_len,
- &myisam->rec_buff)))
+ rec_buff_p)))
return BLOCK_FATAL_ERROR; /* not enough memory */
- myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff+info->rec_len;
- myisam->bit_buff.blob_end= myisam->bit_buff.blob_pos+info->blob_len;
+ bit_buff->blob_pos= (uchar*) *rec_buff_p + info->rec_len;
+ bit_buff->blob_end= bit_buff->blob_pos + info->blob_len;
myisam->blob_length=info->blob_len;
}
info->filepos=filepos+head_length;
if (file > 0)
{
info->offset=min(info->rec_len, ref_length - head_length);
- memcpy(myisam->rec_buff, header+head_length, info->offset);
+ memcpy(*rec_buff_p, header + head_length, info->offset);
}
return 0;
}
@@ -1237,7 +1244,8 @@ void _mi_unmap_file(MI_INFO *info)
}
-static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
+static uchar *_mi_mempack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
uchar *header)
{
header+= read_pack_length((uint) myisam->s->pack.version, header,
@@ -1248,10 +1256,10 @@ static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
&info->blob_len);
/* mi_alloc_rec_buff sets my_errno on error */
if (!(mi_alloc_rec_buff(myisam, info->blob_len,
- &myisam->rec_buff)))
+ rec_buff_p)))
return 0; /* not enough memory */
- myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff;
- myisam->bit_buff.blob_end= (uchar*) myisam->rec_buff + info->blob_len;
+ bit_buff->blob_pos= (uchar*) *rec_buff_p;
+ bit_buff->blob_end= (uchar*) *rec_buff_p + info->blob_len;
}
return header;
}
@@ -1267,11 +1275,13 @@ static int _mi_read_mempack_record(MI_INFO *info, my_off_t filepos, byte *buf)
if (filepos == HA_OFFSET_ERROR)
DBUG_RETURN(-1); /* _search() didn't find record */
- if (!(pos= (byte*) _mi_mempack_get_block_info(info,&block_info,
+ if (!(pos= (byte*) _mi_mempack_get_block_info(info, &info->bit_buff,
+ &block_info, &info->rec_buff,
(uchar*) share->file_map+
filepos)))
DBUG_RETURN(-1);
- DBUG_RETURN(_mi_pack_rec_unpack(info, buf, pos, block_info.rec_len));
+ DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ pos, block_info.rec_len));
}
@@ -1291,7 +1301,8 @@ static int _mi_read_rnd_mempack_record(MI_INFO *info, byte *buf,
my_errno=HA_ERR_END_OF_FILE;
goto err;
}
- if (!(pos= (byte*) _mi_mempack_get_block_info(info,&block_info,
+ if (!(pos= (byte*) _mi_mempack_get_block_info(info, &info->bit_buff,
+ &block_info, &info->rec_buff,
(uchar*)
(start=share->file_map+
filepos))))
@@ -1308,7 +1319,8 @@ static int _mi_read_rnd_mempack_record(MI_INFO *info, byte *buf,
info->nextpos=filepos+(uint) (pos-start)+block_info.rec_len;
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
- DBUG_RETURN (_mi_pack_rec_unpack(info,buf,pos, block_info.rec_len));
+ DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ pos, block_info.rec_len));
err:
DBUG_RETURN(my_errno);
}
diff --git a/myisam/mi_range.c b/myisam/mi_range.c
index e78f3b11625..a28aed81aec 100644
--- a/myisam/mi_range.c
+++ b/myisam/mi_range.c
@@ -71,6 +71,21 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key,
uchar * key_buff;
uint start_key_len;
+ /*
+ The problem is that the optimizer doesn't support
+ RTree keys properly at the moment.
+ Hope this will be fixed some day.
+ But now NULL in the min_key means that we
+ didn't make the task for the RTree key
+ and expect BTree functionality from it.
+ As it's not able to handle such request
+ we return the error.
+ */
+ if (!min_key)
+ {
+ res= HA_POS_ERROR;
+ break;
+ }
key_buff= info->lastkey+info->s->base.max_key_length;
start_key_len= _mi_pack_key(info,inx, key_buff,
(uchar*) min_key->key, min_key->length,
diff --git a/myisam/myisam_ftdump.c b/myisam/myisam_ftdump.c
index 809d7bcca89..2be95d11714 100644
--- a/myisam/myisam_ftdump.c
+++ b/myisam/myisam_ftdump.c
@@ -126,7 +126,6 @@ int main(int argc,char *argv[])
if (count || stats)
{
- doc_cnt++;
if (strcmp(buf, buf2))
{
if (*buf2)
@@ -151,6 +150,7 @@ int main(int argc,char *argv[])
keylen2=keylen;
doc_cnt=0;
}
+ doc_cnt+= (subkeys >= 0 ? 1 : -subkeys);
}
if (dump)
{
@@ -166,7 +166,6 @@ int main(int argc,char *argv[])
if (count || stats)
{
- doc_cnt++;
if (*buf2)
{
uniq++;
diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h
index d589173f0e7..12e2c8e4bec 100644
--- a/myisam/myisamdef.h
+++ b/myisam/myisamdef.h
@@ -76,6 +76,7 @@ typedef struct st_mi_state_info
ulong sec_index_changed; /* Updated when new sec_index */
ulong sec_index_used; /* which extra index are in use */
ulonglong key_map; /* Which keys are in use */
+ ha_checksum checksum; /* Table checksum */
ulong version; /* timestamp of create */
time_t create_time; /* Time when created database */
time_t recover_time; /* Time for last recover */
@@ -176,6 +177,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */
int (*delete_record)(struct st_myisam_info*);
int (*read_rnd)(struct st_myisam_info*, byte*, my_off_t, my_bool);
int (*compare_record)(struct st_myisam_info*, const byte *);
+ /* Function to use for a row checksum. */
ha_checksum (*calc_checksum)(struct st_myisam_info*, const byte *);
int (*compare_unique)(struct st_myisam_info*, MI_UNIQUEDEF *,
const byte *record, my_off_t pos);
@@ -249,7 +251,7 @@ struct st_myisam_info {
my_off_t last_keypage; /* Last key page read */
my_off_t last_search_keypage; /* Last keypage when searching */
my_off_t dupp_key_pos;
- ha_checksum checksum;
+ ha_checksum checksum; /* Temp storage for row checksum */
/* QQ: the folloing two xxx_length fields should be removed,
as they are not compatible with parallel repair */
ulong packed_length,blob_length; /* Length of found, packed record */
@@ -278,6 +280,9 @@ struct st_myisam_info {
my_bool page_changed; /* If info->buff can't be used for rnext */
my_bool buff_used; /* If info->buff has to be reread for rnext */
my_bool once_flags; /* For MYISAMMRG */
+#ifdef __WIN__
+ my_bool owned_by_merge; /* This MyISAM table is part of a merge union */
+#endif
#ifdef THREAD
THR_LOCK_DATA lock;
#endif
@@ -298,8 +303,9 @@ typedef struct st_mi_sort_param
pthread_t thr;
IO_CACHE read_cache, tempfile, tempfile_for_exceptions;
DYNAMIC_ARRAY buffpek;
-
- /*
+ MI_BIT_BUFF bit_buff; /* For parallel repair of packrec. */
+
+ /*
The next two are used to collect statistics, see update_key_parts for
description.
*/
@@ -310,6 +316,7 @@ typedef struct st_mi_sort_param
uint key, key_length,real_key_length,sortbuff_size;
uint maxbuffers, keys, find_length, sort_keys_length;
my_bool fix_datafile, master;
+ my_bool calc_checksum; /* calculate table checksum */
MI_KEYDEF *keyinfo;
HA_KEYSEG *seg;
SORT_INFO *sort_info;
@@ -362,8 +369,15 @@ typedef struct st_mi_sort_param
#define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\
mi_int2store(x,boh); }
#define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0)
-#define mi_mark_crashed(x) (x)->s->state.changed|=STATE_CRASHED
-#define mi_mark_crashed_on_repair(x) { (x)->s->state.changed|=STATE_CRASHED|STATE_CRASHED_ON_REPAIR ; (x)->update|= HA_STATE_CHANGED; }
+#define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \
+ DBUG_PRINT("error", ("Marked table crashed")); \
+ }while(0)
+#define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \
+ STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \
+ (x)->update|= HA_STATE_CHANGED; \
+ DBUG_PRINT("error", \
+ ("Marked table crashed")); \
+ }while(0)
#define mi_is_crashed(x) ((x)->s->state.changed & STATE_CRASHED)
#define mi_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR)
#define mi_print_error(SHARE, ERRNO) \
@@ -603,8 +617,8 @@ extern void _mi_print_key(FILE *stream,HA_KEYSEG *keyseg,const uchar *key,
extern my_bool _mi_read_pack_info(MI_INFO *info,pbool fix_keys);
extern int _mi_read_pack_record(MI_INFO *info,my_off_t filepos,byte *buf);
extern int _mi_read_rnd_pack_record(MI_INFO*, byte *,my_off_t, my_bool);
-extern int _mi_pack_rec_unpack(MI_INFO *info,byte *to,byte *from,
- ulong reclength);
+extern int _mi_pack_rec_unpack(MI_INFO *info, MI_BIT_BUFF *bit_buff,
+ byte *to, byte *from, ulong reclength);
extern ulonglong mi_safe_mul(ulonglong a,ulonglong b);
extern int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
const byte *oldrec, const byte *newrec, my_off_t pos);
@@ -669,7 +683,9 @@ extern "C" {
extern uint _mi_get_block_info(MI_BLOCK_INFO *,File, my_off_t);
extern uint _mi_rec_pack(MI_INFO *info,byte *to,const byte *from);
-extern uint _mi_pack_get_block_info(MI_INFO *, MI_BLOCK_INFO *, File, my_off_t);
+extern uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
+ File file, my_off_t filepos);
extern void _my_store_blob_length(byte *pos,uint pack_length,uint length);
extern void _myisam_log(enum myisam_log_commands command,MI_INFO *info,
const byte *buffert,uint length);
diff --git a/myisam/sort.c b/myisam/sort.c
index 00fbfe768dc..f3a5fe59e13 100644
--- a/myisam/sort.c
+++ b/myisam/sort.c
@@ -148,7 +148,8 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
skr=maxbuffer;
if (memavl < sizeof(BUFFPEK)*(uint) maxbuffer ||
(keys=(memavl-sizeof(BUFFPEK)*(uint) maxbuffer)/
- (sort_length+sizeof(char*))) <= 1)
+ (sort_length+sizeof(char*))) <= 1 ||
+ keys < (uint) maxbuffer)
{
mi_check_print_error(info->sort_info->param,
"sort_buffer_size is to small");
@@ -309,7 +310,7 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys,
pthread_handler_t thr_find_all_keys(void *arg)
{
- MI_SORT_PARAM *info= (MI_SORT_PARAM*) arg;
+ MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg;
int error;
uint memavl,old_memavl,keys,sort_length;
uint idx, maxbuffer;
@@ -321,32 +322,34 @@ pthread_handler_t thr_find_all_keys(void *arg)
if (my_thread_init())
goto err;
- if (info->sort_info->got_error)
+ DBUG_ENTER("thr_find_all_keys");
+ DBUG_PRINT("enter", ("master: %d", sort_param->master));
+ if (sort_param->sort_info->got_error)
goto err;
- if (info->keyinfo->flag && HA_VAR_LENGTH_KEY)
+ if (sort_param->keyinfo->flag && HA_VAR_LENGTH_KEY)
{
- info->write_keys=write_keys_varlen;
- info->read_to_buffer=read_to_buffer_varlen;
- info->write_key=write_merge_key_varlen;
+ sort_param->write_keys= write_keys_varlen;
+ sort_param->read_to_buffer= read_to_buffer_varlen;
+ sort_param->write_key= write_merge_key_varlen;
}
else
{
- info->write_keys=write_keys;
- info->read_to_buffer=read_to_buffer;
- info->write_key=write_merge_key;
+ sort_param->write_keys= write_keys;
+ sort_param->read_to_buffer= read_to_buffer;
+ sort_param->write_key= write_merge_key;
}
- my_b_clear(&info->tempfile);
- my_b_clear(&info->tempfile_for_exceptions);
- bzero((char*) &info->buffpek,sizeof(info->buffpek));
- bzero((char*) &info->unique, sizeof(info->unique));
+ my_b_clear(&sort_param->tempfile);
+ my_b_clear(&sort_param->tempfile_for_exceptions);
+ bzero((char*) &sort_param->buffpek, sizeof(sort_param->buffpek));
+ bzero((char*) &sort_param->unique, sizeof(sort_param->unique));
sort_keys= (uchar **) NULL;
- memavl=max(info->sortbuff_size, MIN_SORT_MEMORY);
- idx= info->sort_info->max_records;
- sort_length= info->key_length;
- maxbuffer= 1;
+ memavl= max(sort_param->sortbuff_size, MIN_SORT_MEMORY);
+ idx= sort_param->sort_info->max_records;
+ sort_length= sort_param->key_length;
+ maxbuffer= 1;
while (memavl >= MIN_SORT_MEMORY)
{
@@ -361,20 +364,22 @@ pthread_handler_t thr_find_all_keys(void *arg)
skr=maxbuffer;
if (memavl < sizeof(BUFFPEK)*maxbuffer ||
(keys=(memavl-sizeof(BUFFPEK)*maxbuffer)/
- (sort_length+sizeof(char*))) <= 1)
+ (sort_length+sizeof(char*))) <= 1 ||
+ keys < (uint) maxbuffer)
{
- mi_check_print_error(info->sort_info->param,
+ mi_check_print_error(sort_param->sort_info->param,
"sort_buffer_size is to small");
goto err;
}
}
while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr);
}
- if ((sort_keys=(uchar **)my_malloc(keys*(sort_length+sizeof(char*))+
- ((info->keyinfo->flag & HA_FULLTEXT) ?
- HA_FT_MAXBYTELEN : 0), MYF(0))))
+ if ((sort_keys= (uchar**)
+ my_malloc(keys*(sort_length+sizeof(char*))+
+ ((sort_param->keyinfo->flag & HA_FULLTEXT) ?
+ HA_FT_MAXBYTELEN : 0), MYF(0))))
{
- if (my_init_dynamic_array(&info->buffpek, sizeof(BUFFPEK),
+ if (my_init_dynamic_array(&sort_param->buffpek, sizeof(BUFFPEK),
maxbuffer, maxbuffer/2))
{
my_free((gptr) sort_keys,MYF(0));
@@ -389,69 +394,87 @@ pthread_handler_t thr_find_all_keys(void *arg)
}
if (memavl < MIN_SORT_MEMORY)
{
- mi_check_print_error(info->sort_info->param,"Sort buffer to small"); /* purecov: tested */
+ mi_check_print_error(sort_param->sort_info->param, "Sort buffer too small");
goto err; /* purecov: tested */
}
- if (info->sort_info->param->testflag & T_VERBOSE)
- printf("Key %d - Allocating buffer for %d keys\n",info->key+1,keys);
- info->sort_keys=sort_keys;
+ if (sort_param->sort_info->param->testflag & T_VERBOSE)
+ printf("Key %d - Allocating buffer for %d keys\n",
+ sort_param->key + 1, keys);
+ sort_param->sort_keys= sort_keys;
idx=error=0;
sort_keys[0]=(uchar*) (sort_keys+keys);
- while (!(error=info->sort_info->got_error) &&
- !(error=(*info->key_read)(info,sort_keys[idx])))
+ DBUG_PRINT("info", ("reading keys"));
+ while (!(error= sort_param->sort_info->got_error) &&
+ !(error= (*sort_param->key_read)(sort_param, sort_keys[idx])))
{
- if (info->real_key_length > info->key_length)
+ if (sort_param->real_key_length > sort_param->key_length)
{
- if (write_key(info,sort_keys[idx], &info->tempfile_for_exceptions))
+ if (write_key(sort_param, sort_keys[idx],
+ &sort_param->tempfile_for_exceptions))
goto err;
continue;
}
if (++idx == keys)
{
- if (info->write_keys(info,sort_keys,idx-1,
- (BUFFPEK *)alloc_dynamic(&info->buffpek),
- &info->tempfile))
+ if (sort_param->write_keys(sort_param, sort_keys, idx - 1,
+ (BUFFPEK*) alloc_dynamic(&sort_param->buffpek),
+ &sort_param->tempfile))
goto err;
sort_keys[0]=(uchar*) (sort_keys+keys);
- memcpy(sort_keys[0],sort_keys[idx-1],(size_t) info->key_length);
+ memcpy(sort_keys[0], sort_keys[idx - 1], (size_t) sort_param->key_length);
idx=1;
}
- sort_keys[idx]=sort_keys[idx-1]+info->key_length;
+ sort_keys[idx]= sort_keys[idx - 1] + sort_param->key_length;
}
if (error > 0)
goto err;
- if (info->buffpek.elements)
+ if (sort_param->buffpek.elements)
{
- if (info->write_keys(info,sort_keys, idx,
- (BUFFPEK *) alloc_dynamic(&info->buffpek), &info->tempfile))
+ if (sort_param->write_keys(sort_param, sort_keys, idx,
+ (BUFFPEK*) alloc_dynamic(&sort_param->buffpek),
+ &sort_param->tempfile))
goto err;
- info->keys=(info->buffpek.elements-1)*(keys-1)+idx;
+ sort_param->keys= (sort_param->buffpek.elements - 1) * (keys - 1) + idx;
}
else
- info->keys=idx;
+ sort_param->keys= idx;
- info->sort_keys_length=keys;
+ sort_param->sort_keys_length= keys;
goto ok;
err:
- info->sort_info->got_error=1; /* no need to protect this with a mutex */
+ DBUG_PRINT("error", ("got some error"));
+ sort_param->sort_info->got_error= 1; /* no need to protect with a mutex */
if (sort_keys)
my_free((gptr) sort_keys,MYF(0));
- info->sort_keys=0;
- delete_dynamic(& info->buffpek);
- close_cached_file(&info->tempfile);
- close_cached_file(&info->tempfile_for_exceptions);
+ sort_param->sort_keys= 0;
+ delete_dynamic(& sort_param->buffpek);
+ close_cached_file(&sort_param->tempfile);
+ close_cached_file(&sort_param->tempfile_for_exceptions);
ok:
- remove_io_thread(&info->read_cache);
- pthread_mutex_lock(&info->sort_info->mutex);
- info->sort_info->threads_running--;
- pthread_cond_signal(&info->sort_info->cond);
- pthread_mutex_unlock(&info->sort_info->mutex);
+ /*
+ Detach from the share if the writer is involved. Avoid others to
+ be blocked. This includes a flush of the write buffer. This will
+ also indicate EOF to the readers.
+ */
+ if (sort_param->sort_info->info->rec_cache.share)
+ remove_io_thread(&sort_param->sort_info->info->rec_cache);
+
+ /* Readers detach from the share if any. Avoid others to be blocked. */
+ if (sort_param->read_cache.share)
+ remove_io_thread(&sort_param->read_cache);
+
+ pthread_mutex_lock(&sort_param->sort_info->mutex);
+ if (!--sort_param->sort_info->threads_running)
+ pthread_cond_signal(&sort_param->sort_info->cond);
+ pthread_mutex_unlock(&sort_param->sort_info->mutex);
+
+ DBUG_PRINT("exit", ("======== ending thread ========"));
my_thread_end();
return NULL;
}
@@ -469,6 +492,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
MYISAM_SHARE *share=info->s;
MI_SORT_PARAM *sinfo;
byte *mergebuf=0;
+ DBUG_ENTER("thr_write_keys");
LINT_INIT(length);
for (i= 0, sinfo= sort_param ;
@@ -478,6 +502,8 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
if (!sinfo->sort_keys)
{
got_error=1;
+ my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff),
+ MYF(MY_ALLOW_ZERO_PTR));
continue;
}
if (!got_error)
@@ -605,7 +631,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
}
}
my_free((gptr) mergebuf,MYF(MY_ALLOW_ZERO_PTR));
- return got_error;
+ DBUG_RETURN(got_error);
}
#endif /* THREAD */
diff --git a/myisammrg/myrg_locking.c b/myisammrg/myrg_locking.c
index e5a8d3f3d9d..98e8305b9ce 100644
--- a/myisammrg/myrg_locking.c
+++ b/myisammrg/myrg_locking.c
@@ -26,8 +26,19 @@ int myrg_lock_database(MYRG_INFO *info, int lock_type)
MYRG_TABLE *file;
error=0;
- for (file=info->open_tables ; file != info->end_table ; file++)
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ {
+#ifdef __WIN__
+ /*
+ Make sure this table is marked as owned by a merge table.
+ The semaphore is never released as long as table remains
+ in memory. This should be refactored into a more generic
+ approach (observer pattern)
+ */
+ (file->table)->owned_by_merge = TRUE;
+#endif
if ((new_error=mi_lock_database(file->table,lock_type)))
error=new_error;
+ }
return(error);
}
diff --git a/myisammrg/myrg_open.c b/myisammrg/myrg_open.c
index f9cdc2bb205..af10f0da90b 100644
--- a/myisammrg/myrg_open.c
+++ b/myisammrg/myrg_open.c
@@ -33,7 +33,7 @@
MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
{
int save_errno,errpos=0;
- uint files=0,i,dir_length,length,key_parts;
+ uint files= 0, i, dir_length, length, key_parts, min_keys= 0;
ulonglong file_offset=0;
char name_buff[FN_REFLEN*2],buff[FN_REFLEN],*end;
MYRG_INFO *m_info=0;
@@ -89,7 +89,10 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
else
fn_format(buff, buff, "", "", 0);
if (!(isam=mi_open(buff,mode,(handle_locking?HA_OPEN_WAIT_IF_LOCKED:0))))
+ {
+ my_errno= HA_ERR_WRONG_MRG_TABLE_DEF;
goto err;
+ }
if (!m_info) /* First file */
{
key_parts=isam->s->base.key_parts;
@@ -106,6 +109,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
files= 0;
}
m_info->reclength=isam->s->base.reclength;
+ min_keys= isam->s->base.keys;
errpos=3;
}
m_info->open_tables[files].table= isam;
@@ -121,6 +125,8 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
m_info->records+= isam->state->records;
m_info->del+= isam->state->del;
m_info->data_file_length+= isam->state->data_file_length;
+ if (min_keys > isam->s->base.keys)
+ min_keys= isam->s->base.keys;
for (i=0; i < key_parts; i++)
m_info->rec_per_key_part[i]+= (isam->s->state.rec_per_key_part[i] /
m_info->tables);
@@ -138,7 +144,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
my_errno=HA_ERR_RECORD_FILE_FULL;
goto err;
}
- m_info->keys= files ? isam->s->base.keys : 0;
+ m_info->keys= min_keys;
bzero((char*) &m_info->by_key,sizeof(m_info->by_key));
/* this works ok if the table list is empty */
diff --git a/myisammrg/myrg_queue.c b/myisammrg/myrg_queue.c
index 2e600a526c0..74fdddc7748 100644
--- a/myisammrg/myrg_queue.c
+++ b/myisammrg/myrg_queue.c
@@ -65,6 +65,8 @@ int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag)
error=my_errno;
}
}
+ else
+ my_errno= error= HA_ERR_WRONG_INDEX;
return error;
}
diff --git a/mysql-test/lib/mtr_im.pl b/mysql-test/lib/mtr_im.pl
new file mode 100644
index 00000000000..4a497cc7ed2
--- /dev/null
+++ b/mysql-test/lib/mtr_im.pl
@@ -0,0 +1,761 @@
+# -*- cperl -*-
+
+# This is a library file used by the Perl version of mysql-test-run,
+# and is part of the translation of the Bourne shell script with the
+# same name.
+
+use strict;
+
+# Private IM-related operations.
+
+sub mtr_im_kill_process ($$$$);
+sub mtr_im_load_pids ($);
+sub mtr_im_terminate ($);
+sub mtr_im_check_alive ($);
+sub mtr_im_check_main_alive ($);
+sub mtr_im_check_angel_alive ($);
+sub mtr_im_check_mysqlds_alive ($);
+sub mtr_im_check_mysqld_alive ($);
+sub mtr_im_cleanup ($);
+sub mtr_im_rm_file ($);
+sub mtr_im_errlog ($);
+sub mtr_im_kill ($);
+sub mtr_im_wait_for_connection ($$$);
+sub mtr_im_wait_for_mysqld($$$);
+
+# Public IM-related operations.
+
+sub mtr_im_start ($$);
+sub mtr_im_stop ($);
+
+##############################################################################
+#
+# Private operations.
+#
+##############################################################################
+
+sub mtr_im_kill_process ($$$$) {
+ my $pid_lst= shift;
+ my $signal= shift;
+ my $total_retries= shift;
+ my $timeout= shift;
+
+ my %pids;
+
+ foreach my $pid ( @{$pid_lst} )
+ {
+ $pids{$pid}= 1;
+ }
+
+ for ( my $cur_attempt= 1; $cur_attempt <= $total_retries; ++$cur_attempt )
+ {
+ foreach my $pid ( keys %pids )
+ {
+ mtr_debug("Sending $signal to $pid...");
+
+ kill($signal, $pid);
+
+ unless ( kill (0, $pid) )
+ {
+ mtr_debug("Process $pid died.");
+ delete $pids{$pid};
+ }
+ }
+
+ return if scalar keys %pids == 0;
+
+ mtr_debug("Sleeping $timeout second(s) waiting for processes to die...");
+
+ sleep($timeout);
+ }
+
+ mtr_debug("Process(es) " .
+ join(' ', keys %pids) .
+ " is still alive after $total_retries " .
+ "of sending signal $signal.");
+}
+
+###########################################################################
+
+sub mtr_im_load_pids($) {
+ my $im= shift;
+
+ mtr_debug("Loading PID files...");
+
+ # Obtain mysqld-process pids.
+
+ my $instances = $im->{'instances'};
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ mtr_debug("IM-guarded mysqld[$idx] PID file: '" .
+ $instances->[$idx]->{'path_pid'} . "'.");
+
+ my $mysqld_pid;
+
+ if ( -r $instances->[$idx]->{'path_pid'} )
+ {
+ $mysqld_pid= mtr_get_pid_from_file($instances->[$idx]->{'path_pid'});
+ mtr_debug("IM-guarded mysqld[$idx] PID: $mysqld_pid.");
+ }
+ else
+ {
+ $mysqld_pid= undef;
+ mtr_debug("IM-guarded mysqld[$idx]: no PID file.");
+ }
+
+ $instances->[$idx]->{'pid'}= $mysqld_pid;
+ }
+
+ # Re-read Instance Manager PIDs from the file, since during tests Instance
+ # Manager could have been restarted, so its PIDs could have been changed.
+
+ # - IM-main
+
+ mtr_debug("IM-main PID file: '$im->{path_pid}'.");
+
+ if ( -f $im->{'path_pid'} )
+ {
+ $im->{'pid'} =
+ mtr_get_pid_from_file($im->{'path_pid'});
+
+ mtr_debug("IM-main PID: $im->{pid}.");
+ }
+ else
+ {
+ mtr_debug("IM-main: no PID file.");
+ $im->{'pid'}= undef;
+ }
+
+ # - IM-angel
+
+ mtr_debug("IM-angel PID file: '$im->{path_angel_pid}'.");
+
+ if ( -f $im->{'path_angel_pid'} )
+ {
+ $im->{'angel_pid'} =
+ mtr_get_pid_from_file($im->{'path_angel_pid'});
+
+ mtr_debug("IM-angel PID: $im->{'angel_pid'}.");
+ }
+ else
+ {
+ mtr_debug("IM-angel: no PID file.");
+ $im->{'angel_pid'} = undef;
+ }
+}
+
+###########################################################################
+
+sub mtr_im_terminate($) {
+ my $im= shift;
+
+ # Load pids from pid-files. We should do it first of all, because IM deletes
+ # them on shutdown.
+
+ mtr_im_load_pids($im);
+
+ mtr_debug("Shutting Instance Manager down...");
+
+ # Ignoring SIGCHLD so that all children could rest in peace.
+
+ start_reap_all();
+
+ # Send SIGTERM to IM-main.
+
+ if ( defined $im->{'pid'} )
+ {
+ mtr_debug("IM-main pid: $im->{pid}.");
+ mtr_debug("Stopping IM-main...");
+
+ mtr_im_kill_process([ $im->{'pid'} ], 'TERM', 10, 1);
+ }
+ else
+ {
+ mtr_debug("IM-main pid: n/a.");
+ }
+
+ # If IM-angel was alive, wait for it to die.
+
+ if ( defined $im->{'angel_pid'} )
+ {
+ mtr_debug("IM-angel pid: $im->{'angel_pid'}.");
+ mtr_debug("Waiting for IM-angel to die...");
+
+ my $total_attempts= 10;
+
+ for ( my $cur_attempt=1; $cur_attempt <= $total_attempts; ++$cur_attempt )
+ {
+ unless ( kill (0, $im->{'angel_pid'}) )
+ {
+ mtr_debug("IM-angel died.");
+ last;
+ }
+
+ sleep(1);
+ }
+ }
+ else
+ {
+ mtr_debug("IM-angel pid: n/a.");
+ }
+
+ stop_reap_all();
+
+ # Re-load PIDs.
+
+ mtr_im_load_pids($im);
+}
+
+###########################################################################
+
+sub mtr_im_check_alive($) {
+ my $im= shift;
+
+ mtr_debug("Checking whether IM-components are alive...");
+
+ return 1 if mtr_im_check_main_alive($im);
+
+ return 1 if mtr_im_check_angel_alive($im);
+
+ return 1 if mtr_im_check_mysqlds_alive($im);
+
+ return 0;
+}
+
+###########################################################################
+
+sub mtr_im_check_main_alive($) {
+ my $im= shift;
+
+ # Check that the process, that we know to be IM's, is dead.
+
+ if ( defined $im->{'pid'} )
+ {
+ if ( kill (0, $im->{'pid'}) )
+ {
+ mtr_debug("IM-main (PID: $im->{pid}) is alive.");
+ return 1;
+ }
+ else
+ {
+ mtr_debug("IM-main (PID: $im->{pid}) is dead.");
+ }
+ }
+ else
+ {
+ mtr_debug("No PID file for IM-main.");
+ }
+
+ # Check that IM does not accept client connections.
+
+ if ( mtr_ping_mysqld_server($im->{'port'}) )
+ {
+ mtr_debug("IM-main (port: $im->{port}) " .
+ "is accepting connections.");
+
+ mtr_im_errlog("IM-main is accepting connections on port " .
+ "$im->{port}, but there is no " .
+ "process information.");
+ return 1;
+ }
+ else
+ {
+ mtr_debug("IM-main (port: $im->{port}) " .
+ "does not accept connections.");
+ return 0;
+ }
+}
+
+###########################################################################
+
+sub mtr_im_check_angel_alive($) {
+ my $im= shift;
+
+ # Check that the process, that we know to be the Angel, is dead.
+
+ if ( defined $im->{'angel_pid'} )
+ {
+ if ( kill (0, $im->{'angel_pid'}) )
+ {
+ mtr_debug("IM-angel (PID: $im->{angel_pid}) is alive.");
+ return 1;
+ }
+ else
+ {
+ mtr_debug("IM-angel (PID: $im->{angel_pid}) is dead.");
+ return 0;
+ }
+ }
+ else
+ {
+ mtr_debug("No PID file for IM-angel.");
+ return 0;
+ }
+}
+
+###########################################################################
+
+sub mtr_im_check_mysqlds_alive($) {
+ my $im= shift;
+
+ mtr_debug("Checking for IM-guarded mysqld instances...");
+
+ my $instances = $im->{'instances'};
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ mtr_debug("Checking mysqld[$idx]...");
+
+ return 1
+ if mtr_im_check_mysqld_alive($instances->[$idx]);
+ }
+}
+
+###########################################################################
+
+sub mtr_im_check_mysqld_alive($) {
+ my $mysqld_instance= shift;
+
+ # Check that the process is dead.
+
+ if ( defined $mysqld_instance->{'pid'} )
+ {
+ if ( kill (0, $mysqld_instance->{'pid'}) )
+ {
+ mtr_debug("Mysqld instance (PID: $mysqld_instance->{pid}) is alive.");
+ return 1;
+ }
+ else
+ {
+ mtr_debug("Mysqld instance (PID: $mysqld_instance->{pid}) is dead.");
+ }
+ }
+ else
+ {
+ mtr_debug("No PID file for mysqld instance.");
+ }
+
+ # Check that mysqld does not accept client connections.
+
+ if ( mtr_ping_mysqld_server($mysqld_instance->{'port'}) )
+ {
+ mtr_debug("Mysqld instance (port: $mysqld_instance->{port}) " .
+ "is accepting connections.");
+
+ mtr_im_errlog("Mysqld is accepting connections on port " .
+ "$mysqld_instance->{port}, but there is no " .
+ "process information.");
+ return 1;
+ }
+ else
+ {
+ mtr_debug("Mysqld instance (port: $mysqld_instance->{port}) " .
+ "does not accept connections.");
+ return 0;
+ }
+}
+
+###########################################################################
+
+sub mtr_im_cleanup($) {
+ my $im= shift;
+
+ mtr_im_rm_file($im->{'path_pid'});
+ mtr_im_rm_file($im->{'path_sock'});
+
+ mtr_im_rm_file($im->{'path_angel_pid'});
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ mtr_im_rm_file($im->{'instances'}->[$idx]->{'path_pid'});
+ mtr_im_rm_file($im->{'instances'}->[$idx]->{'path_sock'});
+ }
+}
+
+###########################################################################
+
+sub mtr_im_rm_file($)
+{
+ my $file_path= shift;
+
+ if ( -f $file_path )
+ {
+ mtr_debug("Removing '$file_path'...");
+
+ unless ( unlink($file_path) )
+ {
+ mtr_warning("Can not remove '$file_path'.")
+ }
+ }
+ else
+ {
+ mtr_debug("File '$file_path' does not exist already.");
+ }
+}
+
+###########################################################################
+
+sub mtr_im_errlog($) {
+ my $msg= shift;
+
+ # Complain in error log so that a warning will be shown.
+ #
+ # TODO: unless BUG#20761 is fixed, we will print the warning to stdout, so
+ # that it can be seen on console and does not produce pushbuild error.
+
+ # my $errlog= "$opt_vardir/log/mysql-test-run.pl.err";
+ #
+ # open (ERRLOG, ">>$errlog") ||
+ # mtr_error("Can not open error log ($errlog)");
+ #
+ # my $ts= localtime();
+ # print ERRLOG
+ # "Warning: [$ts] $msg\n";
+ #
+ # close ERRLOG;
+
+ my $ts= localtime();
+ print "Warning: [$ts] $msg\n";
+}
+
+###########################################################################
+
+sub mtr_im_kill($) {
+ my $im= shift;
+
+ # Re-load PIDs. That can be useful because some processes could have been
+ # restarted.
+
+ mtr_im_load_pids($im);
+
+ # Ignoring SIGCHLD so that all children could rest in peace.
+
+ start_reap_all();
+
+ # Kill IM-angel first of all.
+
+ if ( defined $im->{'angel_pid'} )
+ {
+ mtr_debug("Killing IM-angel (PID: $im->{angel_pid})...");
+ mtr_im_kill_process([ $im->{'angel_pid'} ], 'KILL', 10, 1)
+ }
+ else
+ {
+ mtr_debug("IM-angel is dead.");
+ }
+
+ # Re-load PIDs again.
+
+ mtr_im_load_pids($im);
+
+ # Kill IM-main.
+
+ if ( defined $im->{'pid'} )
+ {
+ mtr_debug("Killing IM-main (PID: $im->pid})...");
+ mtr_im_kill_process([ $im->{'pid'} ], 'KILL', 10, 1);
+ }
+ else
+ {
+ mtr_debug("IM-main is dead.");
+ }
+
+ # Re-load PIDs again.
+
+ mtr_im_load_pids($im);
+
+ # Kill guarded mysqld instances.
+
+ my @mysqld_pids;
+
+ mtr_debug("Collecting PIDs of mysqld instances to kill...");
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ my $pid= $im->{'instances'}->[$idx]->{'pid'};
+
+ unless ( defined $pid )
+ {
+ next;
+ }
+
+ mtr_debug(" - IM-guarded mysqld[$idx] PID: $pid.");
+
+ push (@mysqld_pids, $pid);
+ }
+
+ if ( scalar @mysqld_pids > 0 )
+ {
+ mtr_debug("Killing IM-guarded mysqld instances...");
+ mtr_im_kill_process(\@mysqld_pids, 'KILL', 10, 1);
+ }
+
+ # That's all.
+
+ stop_reap_all();
+}
+
+##############################################################################
+
+sub mtr_im_wait_for_connection($$$) {
+ my $im= shift;
+ my $total_attempts= shift;
+ my $connect_timeout= shift;
+
+ mtr_debug("Waiting for IM on port $im->{port} " .
+ "to start accepting connections...");
+
+ for ( my $cur_attempt= 1; $cur_attempt <= $total_attempts; ++$cur_attempt )
+ {
+ mtr_debug("Trying to connect to IM ($cur_attempt of $total_attempts)...");
+
+ if ( mtr_ping_mysqld_server($im->{'port'}) )
+ {
+ mtr_debug("IM is accepting connections " .
+ "on port $im->{port}.");
+ return 1;
+ }
+
+ mtr_debug("Sleeping $connect_timeout...");
+ sleep($connect_timeout);
+ }
+
+ mtr_debug("IM does not accept connections " .
+ "on port $im->{port} after " .
+ ($total_attempts * $connect_timeout) . " seconds.");
+
+ return 0;
+}
+
+##############################################################################
+
+sub mtr_im_wait_for_mysqld($$$) {
+ my $mysqld= shift;
+ my $total_attempts= shift;
+ my $connect_timeout= shift;
+
+ mtr_debug("Waiting for IM-guarded mysqld on port $mysqld->{port} " .
+ "to start accepting connections...");
+
+ for ( my $cur_attempt= 1; $cur_attempt <= $total_attempts; ++$cur_attempt )
+ {
+ mtr_debug("Trying to connect to mysqld " .
+ "($cur_attempt of $total_attempts)...");
+
+ if ( mtr_ping_mysqld_server($mysqld->{'port'}) )
+ {
+ mtr_debug("Mysqld is accepting connections " .
+ "on port $mysqld->{port}.");
+ return 1;
+ }
+
+ mtr_debug("Sleeping $connect_timeout...");
+ sleep($connect_timeout);
+ }
+
+ mtr_debug("Mysqld does not accept connections " .
+ "on port $mysqld->{port} after " .
+ ($total_attempts * $connect_timeout) . " seconds.");
+
+ return 0;
+}
+
+##############################################################################
+#
+# Public operations.
+#
+##############################################################################
+
+sub mtr_im_start($$) {
+ my $im = shift;
+ my $opts = shift;
+
+ mtr_debug("Starting Instance Manager...");
+
+ my $args;
+ mtr_init_args(\$args);
+ mtr_add_arg($args, "--defaults-file=%s", $im->{'defaults_file'});
+
+ foreach my $opt ( @{$opts} )
+ {
+ mtr_add_arg($args, $opt);
+ }
+
+ $im->{'pid'} =
+ mtr_spawn(
+ $::exe_im, # path to the executable
+ $args, # cmd-line args
+ '', # stdin
+ $im->{'path_log'}, # stdout
+ $im->{'path_err'}, # stderr
+ '', # pid file path (not used)
+ { append_log_file => 1 } # append log files
+ );
+
+ unless ( $im->{'pid'} )
+ {
+ mtr_error('Could not start Instance Manager.')
+ }
+
+ # Instance Manager can be run in daemon mode. In this case, it creates
+ # several processes and the parent process, created by mtr_spawn(), exits just
+ # after start. So, we have to obtain Instance Manager PID from the PID file.
+
+ mtr_debug("Waiting for IM to create PID file (" .
+ "path: '$im->{path_pid}'; " .
+ "timeout: $im->{start_timeout})...");
+
+ unless ( sleep_until_file_created($im->{'path_pid'},
+ $im->{'start_timeout'},
+ -1) ) # real PID is still unknown
+ {
+ mtr_debug("IM has not created PID file in $im->{start_timeout} secs.");
+ mtr_debug("Aborting test suite...");
+
+ mtr_kill_leftovers();
+
+ mtr_report("IM has not created PID file in $im->{start_timeout} secs.");
+ return 0;
+ }
+
+ $im->{'pid'}= mtr_get_pid_from_file($im->{'path_pid'});
+
+ mtr_debug("Instance Manager started. PID: $im->{pid}.");
+
+ # Wait until we can connect to IM.
+
+ my $IM_CONNECT_TIMEOUT= 30;
+
+ unless ( mtr_im_wait_for_connection($im,
+ $IM_CONNECT_TIMEOUT, 1) )
+ {
+ mtr_debug("Can not connect to Instance Manager " .
+ "in $IM_CONNECT_TIMEOUT seconds after start.");
+ mtr_debug("Aborting test suite...");
+
+ mtr_kill_leftovers();
+
+ mtr_report("Can not connect to Instance Manager " .
+ "in $IM_CONNECT_TIMEOUT seconds after start.");
+ return 0;
+ }
+
+ # Wait for IM to start guarded instances:
+ # - wait for PID files;
+
+ mtr_debug("Waiting for guarded mysqlds instances to create PID files...");
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ my $mysqld= $im->{'instances'}->[$idx];
+
+ if ( exists $mysqld->{'nonguarded'} )
+ {
+ next;
+ }
+
+ mtr_debug("Waiting for mysqld[$idx] to create PID file (" .
+ "path: '$mysqld->{path_pid}'; " .
+ "timeout: $mysqld->{start_timeout})...");
+
+ unless ( sleep_until_file_created($mysqld->{'path_pid'},
+ $mysqld->{'start_timeout'},
+ -1) ) # real PID is still unknown
+ {
+ mtr_debug("mysqld[$idx] has not created PID file in " .
+ "$mysqld->{start_timeout} secs.");
+ mtr_debug("Aborting test suite...");
+
+ mtr_kill_leftovers();
+
+ mtr_report("mysqld[$idx] has not created PID file in " .
+ "$mysqld->{start_timeout} secs.");
+ return 0;
+ }
+
+ mtr_debug("PID file for mysqld[$idx] ($mysqld->{path_pid} created.");
+ }
+
+ # Wait until we can connect to guarded mysqld-instances
+ # (in other words -- wait for IM to start guarded instances).
+
+ mtr_debug("Waiting for guarded mysqlds to start accepting connections...");
+
+ for ( my $idx= 0; $idx < 2; ++$idx )
+ {
+ my $mysqld= $im->{'instances'}->[$idx];
+
+ if ( exists $mysqld->{'nonguarded'} )
+ {
+ next;
+ }
+
+ mtr_debug("Waiting for mysqld[$idx] to accept connection...");
+
+ unless ( mtr_im_wait_for_mysqld($mysqld, 30, 1) )
+ {
+ mtr_debug("Can not connect to mysqld[$idx] " .
+ "in $IM_CONNECT_TIMEOUT seconds after start.");
+ mtr_debug("Aborting test suite...");
+
+ mtr_kill_leftovers();
+
+ mtr_report("Can not connect to mysqld[$idx] " .
+ "in $IM_CONNECT_TIMEOUT seconds after start.");
+ return 0;
+ }
+
+ mtr_debug("mysqld[$idx] started.");
+ }
+
+ mtr_debug("Instance Manager and its components are up and running.");
+
+ return 1;
+}
+
+##############################################################################
+
+sub mtr_im_stop($) {
+ my $im= shift;
+
+ mtr_debug("Stopping Instance Manager...");
+
+ # Try graceful shutdown.
+
+ mtr_im_terminate($im);
+
+ # Check that all processes died.
+
+ unless ( mtr_im_check_alive($im) )
+ {
+ mtr_debug("Instance Manager has been stopped successfully.");
+ mtr_im_cleanup($im);
+ return 1;
+ }
+
+ # Instance Manager don't want to die. We should kill it.
+
+ mtr_im_errlog("Instance Manager did not shutdown gracefully.");
+
+ mtr_im_kill($im);
+
+ # Check again that all IM-related processes have been killed.
+
+ my $im_is_alive= mtr_im_check_alive($im);
+
+ mtr_im_cleanup($im);
+
+ if ( $im_is_alive )
+ {
+ mtr_debug("Can not kill Instance Manager or its children.");
+ return 0;
+ }
+
+ mtr_debug("Instance Manager has been killed successfully.");
+ return 1;
+}
+
+###########################################################################
+
+1;
diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index bf869ca91c4..00b12ba5fb5 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -22,28 +22,6 @@ sub sleep_until_file_created ($$$);
sub mtr_kill_processes ($);
sub mtr_ping_mysqld_server ($);
-# Private IM-related operations.
-
-sub mtr_im_kill_process ($$$$);
-sub mtr_im_load_pids ($);
-sub mtr_im_terminate ($);
-sub mtr_im_check_alive ($);
-sub mtr_im_check_main_alive ($);
-sub mtr_im_check_angel_alive ($);
-sub mtr_im_check_mysqlds_alive ($);
-sub mtr_im_check_mysqld_alive ($$);
-sub mtr_im_cleanup ($);
-sub mtr_im_rm_file ($);
-sub mtr_im_errlog ($);
-sub mtr_im_kill ($);
-sub mtr_im_wait_for_connection ($$$);
-sub mtr_im_wait_for_mysqld($$$);
-
-# Public IM-related operations.
-
-sub mtr_im_start ($$);
-sub mtr_im_stop ($);
-
# static in C
sub spawn_impl ($$$$$$$$);
@@ -381,9 +359,16 @@ sub mtr_process_exit_status {
sub mtr_kill_leftovers () {
+ mtr_report("Killing Possible Leftover Processes");
mtr_debug("mtr_kill_leftovers(): started.");
- mtr_im_stop($::instance_manager);
+ mkpath("$::opt_vardir/log"); # Needed for mysqladmin log
+
+ # Stop or kill Instance Manager and all its children. If we failed to do
+ # that, we can only abort -- there is nothing left to do.
+
+ mtr_error("Failed to stop Instance Manager.")
+ unless mtr_im_stop($::instance_manager);
# Kill mysqld servers (masters and slaves) that would conflict with this
# run. Make sure to remove the PID file, if any.
@@ -470,14 +455,6 @@ sub mtr_kill_leftovers () {
mtr_debug("Got pid: $pid from file '$pidfile'");
- # Race, could have been removed between I tested with -f
- # and the unlink() below, so I better check again with -f
-
- if ( ! unlink($pidfile) and -f $pidfile )
- {
- mtr_error("can't remove $pidfile");
- }
-
if ( $::glob_cygwin_perl or kill(0, $pid) )
{
mtr_debug("There is process with pid $pid -- scheduling for kill.");
@@ -1002,676 +979,6 @@ sub mtr_exit ($) {
exit($code);
}
-##############################################################################
-#
-# Instance Manager management routines.
-#
-##############################################################################
-
-sub mtr_im_kill_process ($$$$) {
- my $pid_lst= shift;
- my $signal= shift;
- my $total_retries= shift;
- my $timeout= shift;
-
- my %pids;
-
- foreach my $pid (@{$pid_lst})
- {
- $pids{$pid}= 1;
- }
-
- for (my $cur_attempt= 1; $cur_attempt <= $total_retries; ++$cur_attempt)
- {
- foreach my $pid (keys %pids)
- {
- mtr_debug("Sending $signal to $pid...");
-
- kill($signal, $pid);
-
- unless (kill (0, $pid))
- {
- mtr_debug("Process $pid died.");
- delete $pids{$pid};
- }
- }
-
- return if scalar keys %pids == 0;
-
- mtr_debug("Sleeping $timeout second(s) waiting for processes to die...");
-
- sleep($timeout);
- }
-
- mtr_debug("Process(es) " .
- join(' ', keys %pids) .
- " is still alive after $total_retries " .
- "of sending signal $signal.");
-}
-
-###########################################################################
-
-sub mtr_im_load_pids($) {
- my $instance_manager= shift;
-
- mtr_debug("Loading PID files...");
-
- # Obtain mysqld-process pids.
-
- my $instances = $instance_manager->{'instances'};
-
- for (my $idx= 0; $idx < 2; ++$idx)
- {
- mtr_debug("IM-guarded mysqld[$idx] PID file: '" .
- $instances->[$idx]->{'path_pid'} . "'.");
-
- my $mysqld_pid;
-
- if (-r $instances->[$idx]->{'path_pid'})
- {
- $mysqld_pid= mtr_get_pid_from_file($instances->[$idx]->{'path_pid'});
- mtr_debug("IM-guarded mysqld[$idx] PID: $mysqld_pid.");
- }
- else
- {
- $mysqld_pid= undef;
- mtr_debug("IM-guarded mysqld[$idx]: no PID file.");
- }
-
- $instances->[$idx]->{'pid'}= $mysqld_pid;
- }
-
- # Re-read Instance Manager PIDs from the file, since during tests Instance
- # Manager could have been restarted, so its PIDs could have been changed.
-
- # - IM-main
-
- mtr_debug("IM-main PID file: '$instance_manager->{path_pid}'.");
-
- if (-f $instance_manager->{'path_pid'})
- {
- $instance_manager->{'pid'} =
- mtr_get_pid_from_file($instance_manager->{'path_pid'});
-
- mtr_debug("IM-main PID: $instance_manager->{pid}.");
- }
- else
- {
- mtr_debug("IM-main: no PID file.");
- $instance_manager->{'pid'}= undef;
- }
-
- # - IM-angel
-
- mtr_debug("IM-angel PID file: '$instance_manager->{path_angel_pid}'.");
-
- if (-f $instance_manager->{'path_angel_pid'})
- {
- $instance_manager->{'angel_pid'} =
- mtr_get_pid_from_file($instance_manager->{'path_angel_pid'});
-
- mtr_debug("IM-angel PID: $instance_manager->{'angel_pid'}.");
- }
- else
- {
- mtr_debug("IM-angel: no PID file.");
- $instance_manager->{'angel_pid'} = undef;
- }
-}
-
-###########################################################################
-
-sub mtr_im_terminate($) {
- my $instance_manager= shift;
-
- # Load pids from pid-files. We should do it first of all, because IM deletes
- # them on shutdown.
-
- mtr_im_load_pids($instance_manager);
-
- mtr_debug("Shutting Instance Manager down...");
-
- # Ignoring SIGCHLD so that all children could rest in peace.
-
- start_reap_all();
-
- # Send SIGTERM to IM-main.
-
- if (defined $instance_manager->{'pid'})
- {
- mtr_debug("IM-main pid: $instance_manager->{pid}.");
- mtr_debug("Stopping IM-main...");
-
- mtr_im_kill_process([ $instance_manager->{'pid'} ], 'TERM', 10, 1);
- }
- else
- {
- mtr_debug("IM-main pid: n/a.");
- }
-
- # If IM-angel was alive, wait for it to die.
-
- if (defined $instance_manager->{'angel_pid'})
- {
- mtr_debug("IM-angel pid: $instance_manager->{'angel_pid'}.");
- mtr_debug("Waiting for IM-angel to die...");
-
- my $total_attempts= 10;
-
- for (my $cur_attempt=1; $cur_attempt <= $total_attempts; ++$cur_attempt)
- {
- unless (kill (0, $instance_manager->{'angel_pid'}))
- {
- mtr_debug("IM-angel died.");
- last;
- }
-
- sleep(1);
- }
- }
- else
- {
- mtr_debug("IM-angel pid: n/a.");
- }
-
- stop_reap_all();
-
- # Re-load PIDs.
-
- mtr_im_load_pids($instance_manager);
-}
-
-###########################################################################
-
-sub mtr_im_check_alive($) {
- my $instance_manager= shift;
-
- mtr_debug("Checking whether IM-components are alive...");
-
- return 1 if mtr_im_check_main_alive($instance_manager);
-
- return 1 if mtr_im_check_angel_alive($instance_manager);
-
- return 1 if mtr_im_check_mysqlds_alive($instance_manager);
-
- return 0;
-}
-
-###########################################################################
-
-sub mtr_im_check_main_alive($) {
- my $instance_manager= shift;
-
- # Check that the process, that we know to be IM's, is dead.
-
- if (defined $instance_manager->{'pid'})
- {
- if (kill (0, $instance_manager->{'pid'}))
- {
- mtr_debug("IM-main (PID: $instance_manager->{pid}) is alive.");
- return 1;
- }
- else
- {
- mtr_debug("IM-main (PID: $instance_manager->{pid}) is dead.");
- }
- }
- else
- {
- mtr_debug("No PID file for IM-main.");
- }
-
- # Check that IM does not accept client connections.
-
- if (mtr_ping_mysqld_server($instance_manager->{'port'}))
- {
- mtr_debug("IM-main (port: $instance_manager->{port}) " .
- "is accepting connections.");
-
- mtr_im_errlog("IM-main is accepting connections on port " .
- "$instance_manager->{port}, but there is no " .
- "process information.");
- return 1;
- }
- else
- {
- mtr_debug("IM-main (port: $instance_manager->{port}) " .
- "does not accept connections.");
- return 0;
- }
-}
-
-###########################################################################
-
-sub mtr_im_check_angel_alive($) {
- my $instance_manager= shift;
-
- # Check that the process, that we know to be the Angel, is dead.
-
- if (defined $instance_manager->{'angel_pid'})
- {
- if (kill (0, $instance_manager->{'angel_pid'}))
- {
- mtr_debug("IM-angel (PID: $instance_manager->{angel_pid}) is alive.");
- return 1;
- }
- else
- {
- mtr_debug("IM-angel (PID: $instance_manager->{angel_pid}) is dead.");
- return 0;
- }
- }
- else
- {
- mtr_debug("No PID file for IM-angel.");
- return 0;
- }
-}
-
-###########################################################################
-
-sub mtr_im_check_mysqlds_alive($) {
- my $instance_manager= shift;
-
- mtr_debug("Checking for IM-guarded mysqld instances...");
-
- my $instances = $instance_manager->{'instances'};
-
- for (my $idx= 0; $idx < 2; ++$idx)
- {
- mtr_debug("Checking mysqld[$idx]...");
-
- return 1
- if mtr_im_check_mysqld_alive($instance_manager, $instances->[$idx]);
- }
-}
-
-###########################################################################
-
-sub mtr_im_check_mysqld_alive($$) {
- my $instance_manager= shift;
- my $mysqld_instance= shift;
-
- # Check that the process is dead.
-
- if (defined $instance_manager->{'pid'})
- {
- if (kill (0, $instance_manager->{'pid'}))
- {
- mtr_debug("Mysqld instance (PID: $mysqld_instance->{pid}) is alive.");
- return 1;
- }
- else
- {
- mtr_debug("Mysqld instance (PID: $mysqld_instance->{pid}) is dead.");
- }
- }
- else
- {
- mtr_debug("No PID file for mysqld instance.");
- }
-
- # Check that mysqld does not accept client connections.
-
- if (mtr_ping_mysqld_server($mysqld_instance->{'port'}))
- {
- mtr_debug("Mysqld instance (port: $mysqld_instance->{port}) " .
- "is accepting connections.");
-
- mtr_im_errlog("Mysqld is accepting connections on port " .
- "$mysqld_instance->{port}, but there is no " .
- "process information.");
- return 1;
- }
- else
- {
- mtr_debug("Mysqld instance (port: $mysqld_instance->{port}) " .
- "does not accept connections.");
- return 0;
- }
-}
-
-###########################################################################
-
-sub mtr_im_cleanup($) {
- my $instance_manager= shift;
-
- mtr_im_rm_file($instance_manager->{'path_pid'});
- mtr_im_rm_file($instance_manager->{'path_sock'});
-
- mtr_im_rm_file($instance_manager->{'path_angel_pid'});
-
- for (my $idx= 0; $idx < 2; ++$idx)
- {
- mtr_im_rm_file($instance_manager->{'instances'}->[$idx]->{'path_pid'});
- mtr_im_rm_file($instance_manager->{'instances'}->[$idx]->{'path_sock'});
- }
-}
-
-###########################################################################
-
-sub mtr_im_rm_file($)
-{
- my $file_path= shift;
-
- if (-f $file_path)
- {
- mtr_debug("Removing '$file_path'...");
-
- mtr_warning("Can not remove '$file_path'.")
- unless unlink($file_path);
- }
- else
- {
- mtr_debug("File '$file_path' does not exist already.");
- }
-}
-
-###########################################################################
-
-sub mtr_im_errlog($) {
- my $msg= shift;
-
- # Complain in error log so that a warning will be shown.
- #
- # TODO: unless BUG#20761 is fixed, we will print the warning to stdout, so
- # that it can be seen on console and does not produce pushbuild error.
-
- # my $errlog= "$opt_vardir/log/mysql-test-run.pl.err";
- #
- # open (ERRLOG, ">>$errlog") ||
- # mtr_error("Can not open error log ($errlog)");
- #
- # my $ts= localtime();
- # print ERRLOG
- # "Warning: [$ts] $msg\n";
- #
- # close ERRLOG;
-
- my $ts= localtime();
- print "Warning: [$ts] $msg\n";
-}
-
-###########################################################################
-
-sub mtr_im_kill($) {
- my $instance_manager= shift;
-
- # Re-load PIDs. That can be useful because some processes could have been
- # restarted.
-
- mtr_im_load_pids($instance_manager);
-
- # Ignoring SIGCHLD so that all children could rest in peace.
-
- start_reap_all();
-
- # Kill IM-angel first of all.
-
- if (defined $instance_manager->{'angel_pid'})
- {
- mtr_debug("Killing IM-angel (PID: $instance_manager->{angel_pid})...");
- mtr_im_kill_process([ $instance_manager->{'angel_pid'} ], 'KILL', 10, 1)
- }
- else
- {
- mtr_debug("IM-angel is dead.");
- }
-
- # Re-load PIDs again.
-
- mtr_im_load_pids($instance_manager);
-
- # Kill IM-main.
-
- if (defined $instance_manager->{'pid'})
- {
- mtr_debug("Killing IM-main (PID: $instance_manager->pid})...");
- mtr_im_kill_process([ $instance_manager->{'pid'} ], 'KILL', 10, 1);
- }
- else
- {
- mtr_debug("IM-main is dead.");
- }
-
- # Re-load PIDs again.
-
- mtr_im_load_pids($instance_manager);
-
- # Kill guarded mysqld instances.
-
- my @mysqld_pids;
-
- mtr_debug("Collecting PIDs of mysqld instances to kill...");
-
- for (my $idx= 0; $idx < 2; ++$idx)
- {
- my $pid= $instance_manager->{'instances'}->[$idx]->{'pid'};
-
- next unless defined $pid;
-
- mtr_debug(" - IM-guarded mysqld[$idx] PID: $pid.");
-
- push (@mysqld_pids, $pid);
- }
-
- if (scalar @mysqld_pids > 0)
- {
- mtr_debug("Killing IM-guarded mysqld instances...");
- mtr_im_kill_process(\@mysqld_pids, 'KILL', 10, 1);
- }
-
- # That's all.
-
- stop_reap_all();
-}
-
-##############################################################################
-
-sub mtr_im_wait_for_connection($$$) {
- my $instance_manager= shift;
- my $total_attempts= shift;
- my $connect_timeout= shift;
-
- mtr_debug("Waiting for IM on port $instance_manager->{port} " .
- "to start accepting connections...");
-
- for (my $cur_attempt= 1; $cur_attempt <= $total_attempts; ++$cur_attempt)
- {
- mtr_debug("Trying to connect to IM ($cur_attempt of $total_attempts)...");
-
- if (mtr_ping_mysqld_server($instance_manager->{'port'}))
- {
- mtr_debug("IM is accepting connections " .
- "on port $instance_manager->{port}.");
- return 1;
- }
-
- mtr_debug("Sleeping $connect_timeout...");
- sleep($connect_timeout);
- }
-
- mtr_debug("IM does not accept connections " .
- "on port $instance_manager->{port} after " .
- ($total_attempts * $connect_timeout) . " seconds.");
-
- return 0;
-}
-
-##############################################################################
-
-sub mtr_im_wait_for_mysqld($$$) {
- my $mysqld= shift;
- my $total_attempts= shift;
- my $connect_timeout= shift;
-
- mtr_debug("Waiting for IM-guarded mysqld on port $mysqld->{port} " .
- "to start accepting connections...");
-
- for (my $cur_attempt= 1; $cur_attempt <= $total_attempts; ++$cur_attempt)
- {
- mtr_debug("Trying to connect to mysqld " .
- "($cur_attempt of $total_attempts)...");
-
- if (mtr_ping_mysqld_server($mysqld->{'port'}))
- {
- mtr_debug("Mysqld is accepting connections " .
- "on port $mysqld->{port}.");
- return 1;
- }
-
- mtr_debug("Sleeping $connect_timeout...");
- sleep($connect_timeout);
- }
-
- mtr_debug("Mysqld does not accept connections " .
- "on port $mysqld->{port} after " .
- ($total_attempts * $connect_timeout) . " seconds.");
-
- return 0;
-}
-
-##############################################################################
-
-sub mtr_im_start($$) {
- my $instance_manager = shift;
- my $opts = shift;
-
- mtr_debug("Starting Instance Manager...");
-
- my $args;
- mtr_init_args(\$args);
- mtr_add_arg($args, "--defaults-file=%s",
- $instance_manager->{'defaults_file'});
-
- foreach my $opt (@{$opts})
- {
- mtr_add_arg($args, $opt);
- }
-
- $instance_manager->{'pid'} =
- mtr_spawn(
- $::exe_im, # path to the executable
- $args, # cmd-line args
- '', # stdin
- $instance_manager->{'path_log'}, # stdout
- $instance_manager->{'path_err'}, # stderr
- '', # pid file path (not used)
- { append_log_file => 1 } # append log files
- );
-
- if ( ! $instance_manager->{'pid'} )
- {
- mtr_report('Could not start Instance Manager');
- return;
- }
-
- # Instance Manager can be run in daemon mode. In this case, it creates
- # several processes and the parent process, created by mtr_spawn(), exits just
- # after start. So, we have to obtain Instance Manager PID from the PID file.
-
- if ( ! sleep_until_file_created(
- $instance_manager->{'path_pid'},
- $instance_manager->{'start_timeout'},
- -1)) # real PID is still unknown
- {
- mtr_report("Instance Manager PID file is missing");
- return;
- }
-
- $instance_manager->{'pid'} =
- mtr_get_pid_from_file($instance_manager->{'path_pid'});
-
- mtr_debug("Instance Manager started. PID: $instance_manager->{pid}.");
-
- # Wait until we can connect to IM.
-
- my $IM_CONNECT_TIMEOUT= 30;
-
- unless (mtr_im_wait_for_connection($instance_manager,
- $IM_CONNECT_TIMEOUT, 1))
- {
- mtr_debug("Can not connect to Instance Manager " .
- "in $IM_CONNECT_TIMEOUT seconds after start.");
- mtr_debug("Aborting test suite...");
-
- mtr_kill_leftovers();
-
- mtr_error("Can not connect to Instance Manager " .
- "in $IM_CONNECT_TIMEOUT seconds after start.");
- }
-
- # Wait until we can connect to guarded mysqld-instances
- # (in other words -- wait for IM to start guarded instances).
-
- for (my $idx= 0; $idx < 2; ++$idx)
- {
- my $mysqld= $instance_manager->{'instances'}->[$idx];
-
- next if exists $mysqld->{'nonguarded'};
-
- mtr_debug("Waiting for mysqld[$idx] to start...");
-
- unless (mtr_im_wait_for_mysqld($mysqld, 30, 1))
- {
- mtr_debug("Can not connect to mysqld[$idx] " .
- "in $IM_CONNECT_TIMEOUT seconds after start.");
- mtr_debug("Aborting test suite...");
-
- mtr_kill_leftovers();
-
- mtr_error("Can not connect to mysqld[$idx] " .
- "in $IM_CONNECT_TIMEOUT seconds after start.");
- }
-
- mtr_debug("mysqld[$idx] started.");
- }
-
- mtr_debug("Instance Manager started.");
-}
-
-##############################################################################
-
-sub mtr_im_stop($) {
- my $instance_manager= shift;
-
- mtr_debug("Stopping Instance Manager...");
-
- # Try graceful shutdown.
-
- mtr_im_terminate($instance_manager);
-
- # Check that all processes died.
-
- unless (mtr_im_check_alive($instance_manager))
- {
- mtr_debug("Instance Manager has been stopped successfully.");
- mtr_im_cleanup($instance_manager);
- return 1;
- }
-
- # Instance Manager don't want to die. We should kill it.
-
- mtr_im_errlog("Instance Manager did not shutdown gracefully.");
-
- mtr_im_kill($instance_manager);
-
- # Check again that all IM-related processes have been killed.
-
- my $im_is_alive= mtr_im_check_alive($instance_manager);
-
- mtr_im_cleanup($instance_manager);
-
- if ($im_is_alive)
- {
- mtr_error("Can not kill Instance Manager or its children.");
- return 0;
- }
-
- mtr_debug("Instance Manager has been killed successfully.");
- return 1;
-}
-
###########################################################################
1;
diff --git a/mysql-test/lib/mtr_stress.pl b/mysql-test/lib/mtr_stress.pl
index 77c3d8bb030..92bb220461b 100644
--- a/mysql-test/lib/mtr_stress.pl
+++ b/mysql-test/lib/mtr_stress.pl
@@ -21,7 +21,6 @@ sub run_stress_test ()
{
my $args;
- my $stress_basedir;
my $stress_suitedir;
mtr_report("Starting stress testing\n");
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 994a0d044f5..13ce7ccc66e 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -88,6 +88,7 @@ use strict;
#use diagnostics;
require "lib/mtr_cases.pl";
+require "lib/mtr_im.pl";
require "lib/mtr_process.pl";
require "lib/mtr_timer.pl";
require "lib/mtr_io.pl";
@@ -255,7 +256,7 @@ our $opt_result_ext;
our $opt_skip;
our $opt_skip_rpl;
-our $use_slaves;
+our $max_slave_num= 0;
our $opt_skip_test;
our $opt_skip_im;
@@ -266,7 +267,7 @@ our $opt_sleep_time_for_delete= 10;
our $opt_testcase_timeout;
our $opt_suite_timeout;
my $default_testcase_timeout= 15; # 15 min max
-my $default_suite_timeout= 120; # 2 hours max
+my $default_suite_timeout= 180; # 3 hours max
our $opt_socket;
@@ -409,7 +410,13 @@ sub main () {
{
$need_ndbcluster||= $test->{ndb_test};
$need_im||= $test->{component_id} eq 'im';
- $use_slaves||= $test->{slave_num};
+
+ # Count max number of slaves used by a test case
+ if ( $test->{slave_num} > $max_slave_num)
+ {
+ $max_slave_num= $test->{slave_num};
+ mtr_error("Too many slaves") if $max_slave_num > 3;
+ }
}
$opt_with_ndbcluster= 0 unless $need_ndbcluster;
$opt_skip_im= 1 unless $need_im;
@@ -844,13 +851,13 @@ sub command_line_setup () {
if ( ! $opt_testcase_timeout )
{
$opt_testcase_timeout= $default_testcase_timeout;
- $opt_testcase_timeout*= 10 if defined $opt_valgrind;
+ $opt_testcase_timeout*= 10 if $opt_valgrind;
}
if ( ! $opt_suite_timeout )
{
$opt_suite_timeout= $default_suite_timeout;
- $opt_suite_timeout*= 4 if defined $opt_valgrind;
+ $opt_suite_timeout*= 6 if $opt_valgrind;
}
# Increase times to wait for executables to start if using valgrind
@@ -960,6 +967,7 @@ sub command_line_setup () {
path_datadir => "$opt_vardir/im_mysqld_1.data",
path_sock => "$sockdir/mysqld_1.sock",
path_pid => "$opt_vardir/run/mysqld_1.pid",
+ start_timeout => 400, # enough time create innodb tables
};
$instance_manager->{'instances'}->[1]=
@@ -970,6 +978,7 @@ sub command_line_setup () {
path_sock => "$sockdir/mysqld_2.sock",
path_pid => "$opt_vardir/run/mysqld_2.pid",
nonguarded => 1,
+ start_timeout => 400, # enough time create innodb tables
};
if ( $opt_extern )
@@ -993,11 +1002,9 @@ sub snapshot_setup () {
$master->[0]->{'path_myddir'},
$master->[1]->{'path_myddir'});
- if ($use_slaves)
+ for (my $idx= 0; $idx < $max_slave_num; $idx++)
{
- push @data_dir_lst, ($slave->[0]->{'path_myddir'},
- $slave->[1]->{'path_myddir'},
- $slave->[2]->{'path_myddir'});
+ push(@data_dir_lst, $slave->[$idx]->{'path_myddir'});
}
unless ($opt_skip_im)
@@ -1191,7 +1198,7 @@ sub executable_setup () {
sub environment_setup () {
- my $extra_ld_library_paths;
+ my @ld_library_paths;
# --------------------------------------------------------------------------
# Setup LD_LIBRARY_PATH so the libraries from this distro/clone
@@ -1199,25 +1206,40 @@ sub environment_setup () {
# --------------------------------------------------------------------------
if ( $opt_source_dist )
{
- $extra_ld_library_paths= "$glob_basedir/libmysql/.libs/";
+ push(@ld_library_paths, "$glob_basedir/libmysql/.libs/")
}
else
{
- $extra_ld_library_paths= "$glob_basedir/lib";
+ push(@ld_library_paths, "$glob_basedir/lib")
}
# --------------------------------------------------------------------------
# Add the path where mysqld will find udf_example.so
# --------------------------------------------------------------------------
- $extra_ld_library_paths .= ":" .
- ($lib_udf_example ? dirname($lib_udf_example) : "");
+ if ( $lib_udf_example )
+ {
+ push(@ld_library_paths, dirname($lib_udf_example));
+ }
+
+ # --------------------------------------------------------------------------
+ #Valgrind need to be run with debug libraries otherwise it's almost
+ # impossible to add correct supressions, that means if "/usr/lib/debug"
+ # is available, it should be added to
+ # LD_LIBRARY_PATH
+ # --------------------------------------------------------------------------
+ my $debug_libraries_path= "/usr/lib/debug";
+ if ( $opt_valgrind and -d $debug_libraries_path )
+ {
+ push(@ld_library_paths, $debug_libraries_path);
+ }
- $ENV{'LD_LIBRARY_PATH'}=
- "$extra_ld_library_paths" .
- ($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
- $ENV{'DYLD_LIBRARY_PATH'}=
- "$extra_ld_library_paths" .
- ($ENV{'DYLD_LIBRARY_PATH'} ? ":$ENV{'DYLD_LIBRARY_PATH'}" : "");
+ $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
+ split(':', $ENV{'LD_LIBRARY_PATH'}));
+ mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
+
+ $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
+ split(':', $ENV{'DYLD_LIBRARY_PATH'}));
+ mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
# --------------------------------------------------------------------------
# Also command lines in .opt files may contain env vars
@@ -1311,12 +1333,9 @@ sub kill_running_server () {
{
# Ensure that no old mysqld test servers are running
# This is different from terminating processes we have
- # started from ths run of the script, this is terminating
+ # started from this run of the script, this is terminating
# leftovers from previous runs.
- mtr_report("Killing Possible Leftover Processes");
- mkpath("$opt_vardir/log"); # Needed for mysqladmin log
-
mtr_kill_leftovers();
$using_ndbcluster_master= $opt_with_ndbcluster;
@@ -1721,15 +1740,13 @@ sub initialize_servers () {
sub mysql_install_db () {
- # FIXME not exactly true I think, needs improvements
- install_db('master', $master->[0]->{'path_myddir'});
- install_db('master', $master->[1]->{'path_myddir'});
+ install_db('master1', $master->[0]->{'path_myddir'});
+ copy_install_db('master2', $master->[1]->{'path_myddir'});
- if ( $use_slaves )
+ # Install the number of slave databses needed
+ for (my $idx= 0; $idx < $max_slave_num; $idx++)
{
- install_db('slave', $slave->[0]->{'path_myddir'});
- install_db('slave', $slave->[1]->{'path_myddir'});
- install_db('slave', $slave->[2]->{'path_myddir'});
+ copy_install_db("slave".($idx+1), $slave->[$idx]->{'path_myddir'});
}
if ( ! $opt_skip_im )
@@ -1759,6 +1776,17 @@ sub mysql_install_db () {
}
+sub copy_install_db ($$) {
+ my $type= shift;
+ my $data_dir= shift;
+
+ mtr_report("Installing \u$type Database");
+
+ # Just copy the installed db from first master
+ mtr_copy_dir($master->[0]->{'path_myddir'}, $data_dir);
+
+}
+
sub install_db ($$) {
my $type= shift;
my $data_dir= shift;
@@ -1805,6 +1833,12 @@ sub install_db ($$) {
mtr_add_arg($args, "--skip-ndbcluster");
mtr_add_arg($args, "--skip-bdb");
+ if ( $opt_debug )
+ {
+ mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap_%s.trace",
+ $opt_vardir_trace, $type);
+ }
+
if ( ! $opt_netware )
{
mtr_add_arg($args, "--language=%s", $path_language);
@@ -1913,13 +1947,33 @@ sub im_prepare_data_dir($) {
foreach my $instance (@{$instance_manager->{'instances'}})
{
- install_db(
+ copy_install_db(
'im_mysqld_' . $instance->{'server_id'},
$instance->{'path_datadir'});
}
}
+#
+# Restore snapshot of the installed slave databases
+# if the snapshot exists
+#
+sub restore_slave_databases () {
+
+ if ( -d $path_snapshot)
+ {
+ # Restore the number of slave databases being used
+ for (my $idx= 0; $idx < $max_slave_num; $idx++)
+ {
+ my $data_dir= $slave->[$idx]->{'path_myddir'};
+ my $name= basename($data_dir);
+ rmtree($data_dir);
+ mtr_copy_dir("$path_snapshot/$name", $data_dir);
+ }
+ }
+}
+
+
##############################################################################
#
# Run a single test case
@@ -2020,6 +2074,7 @@ sub run_testcase ($) {
# ----------------------------------------------------------------------
stop_slaves();
+ restore_slave_databases();
}
# ----------------------------------------------------------------------
@@ -2110,7 +2165,13 @@ sub run_testcase ($) {
im_create_defaults_file($instance_manager);
- mtr_im_start($instance_manager, $tinfo->{im_opts});
+ unless ( mtr_im_start($instance_manager, $tinfo->{im_opts}) )
+ {
+ report_failure_and_restart($tinfo);
+ mtr_report("Failed to start Instance Manager. " .
+ "The test '$tname' is marked as failed.");
+ return;
+ }
}
# ----------------------------------------------------------------------
@@ -2207,7 +2268,10 @@ sub run_testcase ($) {
if ( ! $glob_use_running_server and $tinfo->{'component_id'} eq 'im' )
{
- mtr_im_stop($instance_manager);
+ unless ( mtr_im_stop($instance_manager) )
+ {
+ mtr_error("Failed to stop Instance Manager.")
+ }
}
}
@@ -2401,7 +2465,7 @@ sub do_before_start_slave ($$) {
sub mysqld_arguments ($$$$$$) {
my $args= shift;
- my $type= shift; # master/slave/bootstrap
+ my $type= shift; # master/slave
my $idx= shift;
my $extra_opt= shift;
my $slave_master_info= shift;
@@ -2630,7 +2694,7 @@ sub mysqld_arguments ($$$$$$) {
##############################################################################
sub mysqld_start ($$$$$) {
- my $type= shift; # master/slave/bootstrap
+ my $type= shift; # master/slave
my $idx= shift;
my $extra_opt= shift;
my $slave_master_info= shift;
@@ -2651,7 +2715,7 @@ sub mysqld_start ($$$$$) {
}
else
{
- $exe= $exe_mysqld;
+ mtr_error("Unknown 'type' passed to mysqld_start");
}
mtr_init_args(\$args);
@@ -2736,7 +2800,10 @@ sub stop_masters_slaves () {
print "Ending Tests\n";
print "Shutting-down Instance Manager\n";
- mtr_im_stop($instance_manager);
+ unless ( mtr_im_stop($instance_manager) )
+ {
+ mtr_error("Failed to stop Instance Manager.")
+ }
print "Shutting-down MySQL daemon\n\n";
stop_masters();
@@ -2750,7 +2817,7 @@ sub stop_masters () {
my @args;
- for ( my $idx; $idx < 2; $idx++ )
+ for ( my $idx= 0; $idx < 2; $idx++ )
{
# FIXME if we hit ^C before fully started, this test will prevent
# the mysqld process from being killed
@@ -2781,7 +2848,7 @@ sub stop_slaves () {
my @args;
- for ( my $idx; $idx < 3; $idx++ )
+ for ( my $idx= 0; $idx < $max_slave_num; $idx++ )
{
if ( $slave->[$idx]->{'pid'} )
{
@@ -2899,7 +2966,8 @@ sub run_mysqltest ($) {
my $cmdline_mysql=
"$exe_mysql --host=localhost --user=root --password= " .
"--port=$master->[0]->{'path_myport'} " .
- "--socket=$master->[0]->{'path_mysock'}";
+ "--socket=$master->[0]->{'path_mysock'} ".
+ "--character-sets-dir=$path_charsetsdir";
my $cmdline_mysql_client_test=
"$exe_mysql_client_test --no-defaults --testcase --user=root --silent " .
diff --git a/mysql-test/r/analyse.result b/mysql-test/r/analyse.result
index 56f67cce4d6..0ecc462fb70 100644
--- a/mysql-test/r/analyse.result
+++ b/mysql-test/r/analyse.result
@@ -141,3 +141,16 @@ test.t1.product Computer TV 2 8 0 0 4.2500 NULL ENUM('Computer','Phone','TV') NO
sum(profit) 10 6900 11 11 0 0 1946.2500 2867.6719 ENUM('10','275','600','6900') NOT NULL
avg(profit) 10.0000 1380.0000 16 16 0 0 394.68750000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL
drop table t1,t2;
+create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
+insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
+select f1 from t1 procedure analyse(1, 1);
+Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
+test.t1.f1 5.99900 9.55500 7 7 0 0 7.77700 1.77800 FLOAT(4,3) NOT NULL
+select f2 from t1 procedure analyse(1, 1);
+Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
+test.t1.f2 5.9999 9.5555 6 6 0 0 6.0000 NULL FLOAT(5,4) UNSIGNED NOT NULL
+select f3 from t1 procedure analyse(1, 1);
+Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
+test.t1.f3 5.99999 9.55555 7 7 0 0 7.77777 1.77778 FLOAT(6,5) NOT NULL
+drop table t1;
+End of 4.1 tests
diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result
index ee7cdceefda..c5b3b1f86e7 100644
--- a/mysql-test/r/bdb.result
+++ b/mysql-test/r/bdb.result
@@ -1509,27 +1509,27 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
-h 10
-i 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
+h 10
+i 10
select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
-h 10
-i 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
+h 10
+i 10
select c,count(*) from t1 group by c limit 10;
c count(*)
a 1
@@ -1673,15 +1673,15 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
-h 10
-i 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
+h 10
+i 10
alter table t1 drop key v, add key v (v(30));
show create table t1;
Table Create Table
@@ -1800,15 +1800,15 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
-h 10
-i 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
+h 10
+i 10
drop table t1;
create table t1 (a char(10), unique (a));
insert into t1 values ('a ');
diff --git a/mysql-test/r/client_xml.result b/mysql-test/r/client_xml.result
index 24c05c7f9d6..7395b2433e8 100644
--- a/mysql-test/r/client_xml.result
+++ b/mysql-test/r/client_xml.result
@@ -68,7 +68,7 @@ insert into t1 values (1, 2, 'a&b a<b a>b');
<resultset statement="select null from dual
">
<row>
- <field name="NULL">NULL</field>
+ <field name="NULL" xsi:nil="true" />
</row>
</resultset>
drop table t1;
diff --git a/mysql-test/r/ctype_gbk.result b/mysql-test/r/ctype_gbk.result
index 241539ecf42..3f5d8b0d8c6 100644
--- a/mysql-test/r/ctype_gbk.result
+++ b/mysql-test/r/ctype_gbk.result
@@ -168,3 +168,13 @@ DROP TABLE t1;
select hex(convert(_gbk 0xA14041 using ucs2));
hex(convert(_gbk 0xA14041 using ucs2))
003F0041
+create table t1 (c1 text not null, c2 text not null) character set gbk;
+alter table t1 change c1 c1 mediumtext character set gbk not null;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` mediumtext NOT NULL,
+ `c2` text NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=gbk
+drop table t1;
+End of 5.0 tests
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result
index bf271437fac..00fd5a0c9aa 100644
--- a/mysql-test/r/ctype_utf8.result
+++ b/mysql-test/r/ctype_utf8.result
@@ -1155,6 +1155,81 @@ check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
+set names utf8;
+create table t1 (s1 char(5) character set utf8);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_general_ci from t1 where s1 like 'ペテ%';
+before_delete_general_ci
+ペテルグル
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_general_ci from t1 where s1 like 'ペテ%';
+after_delete_general_ci
+ペテルグル
+drop table t1;
+set names utf8;
+create table t1 (s1 char(5) character set utf8 collate utf8_unicode_ci);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_unicode_ci from t1 where s1 like 'ペテ%';
+before_delete_unicode_ci
+ペテルグル
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_unicode_ci from t1 where s1 like 'ペテ%';
+after_delete_unicode_ci
+ペテルグル
+drop table t1;
+set names utf8;
+create table t1 (s1 char(5) character set utf8 collate utf8_bin);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_bin from t1 where s1 like 'ペテ%';
+before_delete_bin
+ペテルグル
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_bin from t1 where s1 like 'ペテ%';
+after_delete_bin
+ペテルグル
+drop table t1;
+set names utf8;
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_general_ci;
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as gci1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+gci1
+ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ
+select a as gci2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+gci2
+ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã
+drop table t1;
+set names utf8;
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_unicode_ci;
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as uci1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+uci1
+ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ
+select a as uci2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+uci2
+ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã
+drop table t1;
+set names utf8;
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_bin;
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as bin1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+bin1
+ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ
+select a as bin2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+bin2
+ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã
+drop table t1;
SET NAMES utf8;
CREATE TABLE t1 (id int PRIMARY KEY,
a varchar(16) collate utf8_unicode_ci NOT NULL default '',
@@ -1340,6 +1415,18 @@ select a from t1 group by a;
a
e
drop table t1;
+create table t1(a char(10)) default charset utf8;
+insert into t1 values ('123'), ('456');
+explain
+select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE Y ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+1 SIMPLE Z ALL NULL NULL NULL NULL 2 Using where
+select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
+substr(Z.a,-1) a
+3 123
+6 456
+drop table t1;
CREATE TABLE t1(id varchar(20) NOT NULL) DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES ('xxx'), ('aa'), ('yyy'), ('aa');
SELECT id FROM t1;
@@ -1449,3 +1536,21 @@ set @a:=null;
execute my_stmt using @a;
a b
drop table if exists t1;
+CREATE TABLE t1 (
+colA int(11) NOT NULL,
+colB varchar(255) character set utf8 NOT NULL,
+PRIMARY KEY (colA)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t1 (colA, colB) VALUES (1, 'foo'), (2, 'foo bar');
+CREATE TABLE t2 (
+colA int(11) NOT NULL,
+colB varchar(255) character set utf8 NOT NULL,
+KEY bad (colA,colB(3))
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t2 (colA, colB) VALUES (1, 'foo'),(2, 'foo bar');
+SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB
+WHERE t1.colA < 3;
+colA colB colA colB
+1 foo 1 foo
+2 foo bar 2 foo bar
+DROP TABLE t1, t2;
diff --git a/mysql-test/r/delayed.result b/mysql-test/r/delayed.result
index a336f3b4108..6295fceec2b 100644
--- a/mysql-test/r/delayed.result
+++ b/mysql-test/r/delayed.result
@@ -7,6 +7,7 @@ insert delayed into t1 set a = 4;
insert delayed into t1 set a = 5, tmsp = 19711006010203;
insert delayed into t1 (a, tmsp) values (6, 19711006010203);
insert delayed into t1 (a, tmsp) values (7, NULL);
+FLUSH TABLE t1;
insert into t1 set a = 8,tmsp=19711006010203;
select * from t1 where tmsp=0;
a tmsp
@@ -22,6 +23,7 @@ insert delayed into t1 values (null,"c");
insert delayed into t1 values (3,"d"),(null,"e");
insert delayed into t1 values (3,"this will give an","error");
ERROR 21S01: Column count doesn't match value count at row 1
+FLUSH TABLE t1;
show status like 'not_flushed_delayed_rows';
Variable_name Value
Not_flushed_delayed_rows 0
@@ -54,6 +56,7 @@ insert delayed into t1 values(null);
insert delayed into t1 values(null);
insert delayed into t1 values(null);
insert delayed into t1 values(null);
+FLUSH TABLE t1;
select * from t1 order by a;
a
1
@@ -69,3 +72,174 @@ a
12
13
DROP TABLE t1;
+SET @bug20627_old_auto_increment_offset=
+@@auto_increment_offset= 2;
+SET @bug20627_old_auto_increment_increment=
+@@auto_increment_increment= 3;
+SET @bug20627_old_session_auto_increment_offset=
+@@session.auto_increment_offset= 4;
+SET @bug20627_old_session_auto_increment_increment=
+@@session.auto_increment_increment= 5;
+SET @@auto_increment_offset= 2;
+SET @@auto_increment_increment= 3;
+SET @@session.auto_increment_offset= 4;
+SET @@session.auto_increment_increment= 5;
+CREATE TABLE t1 (
+c1 INT NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (c1)
+);
+INSERT INTO t1 VALUES (NULL),(NULL),(NULL);
+SELECT * FROM t1;
+c1
+4
+9
+14
+DROP TABLE t1;
+CREATE TABLE t1 (
+c1 INT NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (c1)
+);
+INSERT DELAYED INTO t1 VALUES (NULL),(NULL),(NULL);
+FLUSH TABLE t1;
+SELECT * FROM t1;
+c1
+4
+9
+14
+DROP TABLE t1;
+SET @@auto_increment_offset=
+@bug20627_old_auto_increment_offset;
+SET @@auto_increment_increment=
+@bug20627_old_auto_increment_increment;
+SET @@session.auto_increment_offset=
+@bug20627_old_session_auto_increment_offset;
+SET @@session.auto_increment_increment=
+@bug20627_old_session_auto_increment_increment;
+SET @bug20830_old_auto_increment_offset=
+@@auto_increment_offset= 2;
+SET @bug20830_old_auto_increment_increment=
+@@auto_increment_increment= 3;
+SET @bug20830_old_session_auto_increment_offset=
+@@session.auto_increment_offset= 4;
+SET @bug20830_old_session_auto_increment_increment=
+@@session.auto_increment_increment= 5;
+SET @@auto_increment_offset= 2;
+SET @@auto_increment_increment= 3;
+SET @@session.auto_increment_offset= 4;
+SET @@session.auto_increment_increment= 5;
+CREATE TABLE t1 (
+c1 INT(11) NOT NULL AUTO_INCREMENT,
+c2 INT(11) DEFAULT NULL,
+PRIMARY KEY (c1)
+);
+SET insert_id= 14;
+INSERT INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
+INSERT INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
+INSERT INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33);
+INSERT INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
+SET insert_id= 114;
+INSERT INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
+INSERT INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
+INSERT INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73);
+INSERT INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
+SET insert_id= 114;
+INSERT INTO t1 VALUES(NULL, 91);
+ERROR 23000: Duplicate entry '114' for key 1
+INSERT INTO t1 VALUES (NULL, 92), (NULL, 93);
+SELECT * FROM t1;
+c1 c2
+14 11
+19 12
+24 13
+29 21
+34 22
+39 23
+69 31
+74 32
+79 33
+84 41
+89 42
+94 43
+114 51
+119 52
+124 53
+129 61
+134 62
+139 63
+49 71
+144 72
+149 73
+154 81
+159 82
+164 83
+169 92
+174 93
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+26
+SELECT SUM(c1) FROM t1;
+SUM(c1)
+2569
+DROP TABLE t1;
+CREATE TABLE t1 (
+c1 INT(11) NOT NULL AUTO_INCREMENT,
+c2 INT(11) DEFAULT NULL,
+PRIMARY KEY (c1)
+);
+SET insert_id= 14;
+INSERT DELAYED INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
+INSERT DELAYED INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
+INSERT DELAYED INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33);
+INSERT DELAYED INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
+SET insert_id= 114;
+INSERT DELAYED INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
+INSERT DELAYED INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
+INSERT DELAYED INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73);
+INSERT DELAYED INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
+SET insert_id= 114;
+INSERT DELAYED INTO t1 VALUES(NULL, 91);
+INSERT DELAYED INTO t1 VALUES (NULL, 92), (NULL, 93);
+FLUSH TABLE t1;
+SELECT * FROM t1;
+c1 c2
+14 11
+19 12
+24 13
+29 21
+34 22
+39 23
+69 31
+74 32
+79 33
+84 41
+89 42
+94 43
+114 51
+119 52
+124 53
+129 61
+134 62
+139 63
+49 71
+144 72
+149 73
+154 81
+159 82
+164 83
+169 92
+174 93
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+26
+SELECT SUM(c1) FROM t1;
+SUM(c1)
+2569
+DROP TABLE t1;
+SET @@auto_increment_offset=
+@bug20830_old_auto_increment_offset;
+SET @@auto_increment_increment=
+@bug20830_old_auto_increment_increment;
+SET @@session.auto_increment_offset=
+@bug20830_old_session_auto_increment_offset;
+SET @@session.auto_increment_increment=
+@bug20830_old_session_auto_increment_increment;
diff --git a/mysql-test/r/execution_constants.result b/mysql-test/r/execution_constants.result
new file mode 100644
index 00000000000..293c88dc506
--- /dev/null
+++ b/mysql-test/r/execution_constants.result
@@ -0,0 +1,12 @@
+CREATE TABLE `t_bug21476` (
+`ID_BOARD` smallint(5) unsigned NOT NULL default '0',
+`ID_MEMBER` mediumint(8) unsigned NOT NULL default '0',
+`logTime` int(10) unsigned NOT NULL default '0',
+`ID_MSG` mediumint(8) unsigned NOT NULL default '0',
+PRIMARY KEY (`ID_MEMBER`,`ID_BOARD`),
+KEY `logTime` (`logTime`)
+) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bulgarian_ci;
+INSERT INTO `t_bug21476` VALUES (2,2,1154870939,0),(1,2,1154870957,0),(2,183,1154941362,0),(2,84,1154904301,0),(1,84,1154905867,0),(2,13,1154947484,10271),(3,84,1154880549,0),(1,6,1154892183,0),(2,25,1154947581,10271),(3,25,1154904760,0),(1,25,1154947373,10271),(1,179,1154899992,0),(2,179,1154899410,0),(5,25,1154901666,0),(2,329,1154902026,0),(3,329,1154902040,0),(1,329,1154902058,0),(1,13,1154930841,0),(3,85,1154904987,0),(1,183,1154929665,0),(3,13,1154931268,0),(1,85,1154936888,0),(1,169,1154937959,0),(2,169,1154941717,0),(3,183,1154939810,0),(3,169,1154941734,0);
+Assertion: mysql_errno 1436 == 1436
+DROP TABLE `t_bug21476`;
+End of 5.0 tests.
diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result
index 93925670d01..5dbbd891427 100644
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@ -74,11 +74,6 @@ grp group_concat(c order by 1)
1 a
2 b,c
3 C,D,d,d,D,E
-select grp,group_concat(c order by "c") from t1 group by grp;
-grp group_concat(c order by "c")
-1 a
-2 b,c
-3 C,D,d,d,D,E
select grp,group_concat(distinct c order by c) from t1 group by grp;
grp group_concat(distinct c order by c)
1 a
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index c6117053a60..23517f7b603 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -1029,3 +1029,29 @@ t1 CREATE TABLE `t1` (
`stddev(0)` double(8,4) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
+INSERT INTO t1 SELECT a, b+8 FROM t1;
+INSERT INTO t1 SELECT a, b+16 FROM t1;
+INSERT INTO t1 SELECT a, b+32 FROM t1;
+INSERT INTO t1 SELECT a, b+64 FROM t1;
+INSERT INTO t1 SELECT a, b+128 FROM t1;
+INSERT INTO t1 SELECT a, b+256 FROM t1;
+INSERT INTO t1 SELECT a, b+512 FROM t1;
+INSERT INTO t1 SELECT a, b+1024 FROM t1;
+INSERT INTO t1 SELECT a, b+2048 FROM t1;
+INSERT INTO t1 SELECT a, b+4096 FROM t1;
+INSERT INTO t1 SELECT a, b+8192 FROM t1;
+INSERT INTO t1 SELECT a, b+16384 FROM t1;
+INSERT INTO t1 SELECT a, b+32768 FROM t1;
+SELECT a,COUNT(DISTINCT b) AS cnt FROM t1 GROUP BY a HAVING cnt > 50;
+a cnt
+1 65536
+SELECT a,SUM(DISTINCT b) AS sumation FROM t1 GROUP BY a HAVING sumation > 50;
+a sumation
+1 2147516416
+SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
+a average
+1 32768.5000
+DROP TABLE t1;
+End of 5.0 tests
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index 00642e1a570..c2c12f8d291 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -1143,9 +1143,9 @@ EXPLAIN EXTENDED
SELECT * FROM t1 INNER JOIN t2 ON code=id
WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00');
id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 const PRIMARY PRIMARY 12 const 1 Using index
1 SIMPLE t1 ref code code 13 const 3 Using where; Using index
-1 SIMPLE t2 ref PRIMARY PRIMARY 12 const 1 Using where; Using index
Warnings:
-Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (`test`.`t2`.`id` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
+Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
DROP TABLE t1,t2;
End of 5.0 tests
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index 9fea857e4e5..25c910a711a 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -890,6 +890,18 @@ t1 CREATE TABLE `t1` (
`from_unixtime(1) + 0` double(23,6) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
+SET NAMES latin1;
+SET character_set_results = NULL;
+SHOW VARIABLES LIKE 'character_set_results';
+Variable_name Value
+character_set_results
+CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY);
+INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
+SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
+fmtddate field2
+Sep-4 12:00AM abcd
+DROP TABLE testBug8868;
+SET NAMES DEFAULT;
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H)
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H);
diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result
index f872838f6f3..64b21ca988d 100644
--- a/mysql-test/r/gis-rtree.result
+++ b/mysql-test/r/gis-rtree.result
@@ -869,4 +869,14 @@ INSERT INTO t1() VALUES ();
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
INSERT INTO t1(foo) VALUES ('');
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
+CREATE TABLE t1 (foo GEOMETRY NOT NULL, SPATIAL INDEX(foo) );
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,1)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,0)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,1)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,0)));
+SELECT 1 FROM t1 WHERE foo != PointFromWKB(POINT(0,0));
+1
+1
+1
+1
DROP TABLE t1;
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index 5eb2e5744c1..7d1e8832069 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -303,10 +303,10 @@ spid sum(userid)
1 1
explain select sql_big_result score,count(*) from t1 group by score desc;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index NULL score 3 NULL 8 Using index
+1 SIMPLE t1 index NULL score 3 NULL 8 Using index; Using filesort
explain select sql_big_result score,count(*) from t1 group by score desc order by null;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index NULL score 3 NULL 8 Using index
+1 SIMPLE t1 index NULL score 3 NULL 8 Using index; Using filesort
select sql_big_result score,count(*) from t1 group by score desc;
score count(*)
3 5
@@ -775,6 +775,55 @@ select sql_buffer_result max(f1)+1 from t1;
max(f1)+1
3
drop table t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1),(2);
+SELECT a FROM t1 GROUP BY 'a';
+a
+1
+SELECT a FROM t1 GROUP BY "a";
+a
+1
+SELECT a FROM t1 GROUP BY `a`;
+a
+1
+2
+set sql_mode=ANSI_QUOTES;
+SELECT a FROM t1 GROUP BY "a";
+a
+1
+2
+SELECT a FROM t1 GROUP BY 'a';
+a
+1
+SELECT a FROM t1 GROUP BY `a`;
+a
+1
+2
+set sql_mode='';
+SELECT a FROM t1 HAVING 'a' > 1;
+a
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+SELECT a FROM t1 HAVING "a" > 1;
+a
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'a'
+SELECT a FROM t1 HAVING `a` > 1;
+a
+2
+SELECT a FROM t1 ORDER BY 'a' DESC;
+a
+1
+2
+SELECT a FROM t1 ORDER BY "a" DESC;
+a
+1
+2
+SELECT a FROM t1 ORDER BY `a` DESC;
+a
+2
+1
+DROP TABLE t1;
create table t1 (c1 char(3), c2 char(3));
create table t2 (c3 char(3), c4 char(3));
insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2');
@@ -821,3 +870,66 @@ a b real_b
68 France France
DROP VIEW v1;
DROP TABLE t1,t2;
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, key (b));
+INSERT INTO t1 VALUES (1, 1);
+INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20) FROM t1;
+INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20) FROM t1;
+INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20) FROM t1;
+SELECT MIN(b), MAX(b) from t1;
+MIN(b) MAX(b)
+0 19
+EXPLAIN SELECT b, sum(1) FROM t1 GROUP BY b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 128 Using index
+EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 128 Using index; Using filesort
+SELECT b, sum(1) FROM t1 GROUP BY b;
+b sum(1)
+0 6
+1 7
+2 7
+3 7
+4 7
+5 7
+6 7
+7 7
+8 7
+9 6
+10 6
+11 6
+12 6
+13 6
+14 6
+15 6
+16 6
+17 6
+18 6
+19 6
+SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
+b sum(1)
+0 6
+1 7
+2 7
+3 7
+4 7
+5 7
+6 7
+7 7
+8 7
+9 6
+10 6
+11 6
+12 6
+13 6
+14 6
+15 6
+16 6
+17 6
+18 6
+19 6
+DROP TABLE t1;
diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result
index fe6f7c4ca55..0304919baf6 100644
--- a/mysql-test/r/group_min_max.result
+++ b/mysql-test/r/group_min_max.result
@@ -2142,3 +2142,23 @@ t1;
id2 id3 id5 id4 id3 id6 id5 id1
1 1 1 1 1 1 1 1
DROP TABLE t1,t2,t3,t4,t5,t6;
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b));
+INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
+explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 1 Using where; Using index for group-by
+SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
+MAX(b) a
+1 1
+SELECT MIN(b), a FROM t1 WHERE b > 1 AND a = 1 GROUP BY a;
+MIN(b) a
+2 1
+CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c));
+INSERT INTO t2 SELECT a,b,b FROM t1;
+explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index for group-by
+SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
+MIN(c)
+2
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result
index b805bdc9166..52a69d98fcf 100644
--- a/mysql-test/r/im_daemon_life_cycle.result
+++ b/mysql-test/r/im_daemon_life_cycle.result
@@ -8,3 +8,17 @@ mysqld2 offline
Killing the process...
Sleeping...
Success: the process was restarted.
+
+--------------------------------------------------------------------
+-- Test for BUG#12751
+--------------------------------------------------------------------
+START INSTANCE mysqld2;
+Success: the process has been started.
+Killing the process...
+Sleeping...
+Success: the process was restarted.
+SHOW INSTANCE STATUS mysqld1;
+instance_name status version
+mysqld1 online VERSION
+STOP INSTANCE mysqld2;
+Success: the process has been stopped.
diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result
index 1d1f26e4b01..38d71ac7a42 100644
--- a/mysql-test/r/innodb.result
+++ b/mysql-test/r/innodb.result
@@ -2070,15 +2070,15 @@ i 10
select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
h 10
-i 10
+i 10
select c,count(*) from t1 group by c limit 10;
c count(*)
a 1
diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result
index b4101e037f2..c4564251a35 100644
--- a/mysql-test/r/innodb_mysql.result
+++ b/mysql-test/r/innodb_mysql.result
@@ -337,3 +337,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where
DROP TABLE t1,t2;
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
+INSERT INTO t1 VALUES ( 1 , 1 , 1);
+INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
+EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 128
+EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort
+DROP TABLE t1;
diff --git a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result
index 17e1966dbc9..d415bd468e0 100644
--- a/mysql-test/r/loaddata.result
+++ b/mysql-test/r/loaddata.result
@@ -43,9 +43,9 @@ drop table t1;
create table t1 (a int, b char(10));
load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'error ' for column 'a' at row 3
Warning 1262 Row 3 was truncated; it contained more data than there were input columns
-Warning 1264 Out of range value adjusted for column 'a' at row 5
+Warning 1366 Incorrect integer value: 'wrong end ' for column 'a' at row 5
Warning 1262 Row 5 was truncated; it contained more data than there were input columns
select * from t1;
a b
@@ -57,7 +57,8 @@ a b
truncate table t1;
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 4
+Warning 1366 Incorrect integer value: '
+' for column 'a' at row 4
Warning 1261 Row 4 doesn't contain data for all columns
select * from t1;
a b
diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result
index b8fdd24be74..af8a2d61505 100644
--- a/mysql-test/r/merge.result
+++ b/mysql-test/r/merge.result
@@ -178,9 +178,9 @@ t3 CREATE TABLE `t3` (
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`)
create table t4 (a int not null, b char(10), key(a)) engine=MERGE UNION=(t1,t2);
select * from t4;
-ERROR HY000: All tables in the MERGE table are not identically defined
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
alter table t4 add column c int;
-ERROR HY000: All tables in the MERGE table are not identically defined
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
create database mysqltest;
create table mysqltest.t6 (a int not null primary key auto_increment, message char(20));
create table t5 (a int not null, b char(20), key(a)) engine=MERGE UNION=(test.t1,mysqltest.t6);
@@ -626,7 +626,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref PRIMARY,files PRIMARY 35 const,const 1 Using where
+1 SIMPLE t2 const PRIMARY,files PRIMARY 35 const,const 1
DROP TABLE t2, t1;
create table t1 (x int, y int, index xy(x, y));
create table t2 (x int, y int, index xy(x, y));
@@ -768,6 +768,21 @@ Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
drop table t1, t2, t3;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2),(1);
+CREATE TABLE t2(a INT, KEY(a)) ENGINE=MERGE UNION=(t1);
+SELECT * FROM t2 WHERE a=2;
+ERROR HY000: Got error 124 from storage engine
+DROP TABLE t1, t2;
+CREATE TABLE t1(a INT) ENGINE=MEMORY;
+CREATE TABLE t2(a INT) ENGINE=MERGE UNION=(t1);
+SELECT * FROM t2;
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+DROP TABLE t1, t2;
+CREATE TABLE t2(a INT) ENGINE=MERGE UNION=(t3);
+SELECT * FROM t2;
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+DROP TABLE t2;
create table t1 (b bit(1));
create table t2 (b bit(1));
create table tm (b bit(1)) engine = merge union = (t1,t2);
diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result
index 0021e6717ee..2ea317754ec 100644
--- a/mysql-test/r/myisam.result
+++ b/mysql-test/r/myisam.result
@@ -796,6 +796,132 @@ a b
xxxxxxxxx bbbbbb
xxxxxxxxx bbbbbb
DROP TABLE t1;
+SET @@myisam_repair_threads=2;
+SHOW VARIABLES LIKE 'myisam_repair%';
+Variable_name Value
+myisam_repair_threads 2
+CREATE TABLE t1 (
+`_id` int(11) NOT NULL default '0',
+`url` text,
+`email` text,
+`description` text,
+`loverlap` int(11) default NULL,
+`roverlap` int(11) default NULL,
+`lneighbor_id` int(11) default NULL,
+`rneighbor_id` int(11) default NULL,
+`length_` int(11) default NULL,
+`sequence` mediumtext,
+`name` text,
+`_obj_class` text NOT NULL,
+PRIMARY KEY (`_id`),
+UNIQUE KEY `sequence_name_index` (`name`(50)),
+KEY (`length_`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES
+(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
+(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
+(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
+(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
+(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
+(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
+(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
+(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
+(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
+SELECT _id FROM t1;
+_id
+1
+2
+3
+4
+5
+6
+7
+8
+9
+DELETE FROM t1 WHERE _id < 8;
+SHOW TABLE STATUS LIKE 't1';
+Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
+t1 MyISAM 10 Dynamic 2 # # # # 140 # # # # # #
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+OPTIMIZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 optimize status OK
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+SHOW TABLE STATUS LIKE 't1';
+Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
+t1 MyISAM 10 Dynamic 2 # # # # 0 # # # # # #
+SELECT _id FROM t1;
+_id
+8
+9
+DROP TABLE t1;
+CREATE TABLE t1 (
+`_id` int(11) NOT NULL default '0',
+`url` text,
+`email` text,
+`description` text,
+`loverlap` int(11) default NULL,
+`roverlap` int(11) default NULL,
+`lneighbor_id` int(11) default NULL,
+`rneighbor_id` int(11) default NULL,
+`length_` int(11) default NULL,
+`sequence` mediumtext,
+`name` text,
+`_obj_class` text NOT NULL,
+PRIMARY KEY (`_id`),
+UNIQUE KEY `sequence_name_index` (`name`(50)),
+KEY (`length_`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES
+(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
+(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
+(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
+(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
+(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
+(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
+(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
+(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
+(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
+SELECT _id FROM t1;
+_id
+1
+2
+3
+4
+5
+6
+7
+8
+9
+DELETE FROM t1 WHERE _id < 8;
+SHOW TABLE STATUS LIKE 't1';
+Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
+t1 MyISAM 10 Dynamic 2 # # # # 140 # # # # # #
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+REPAIR TABLE t1 QUICK;
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+SHOW TABLE STATUS LIKE 't1';
+Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
+t1 MyISAM 10 Dynamic 2 # # # # 140 # # # # # #
+SELECT _id FROM t1;
+_id
+8
+9
+DROP TABLE t1;
+SET @@myisam_repair_threads=1;
+SHOW VARIABLES LIKE 'myisam_repair%';
+Variable_name Value
+myisam_repair_threads 1
set storage_engine=MyISAM;
drop table if exists t1,t2,t3;
--- Testing varchar ---
@@ -1002,15 +1128,15 @@ i 10
select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c)
a 1
-a 10
-b 10
-c 10
-d 10
-e 10
-f 10
-g 10
+a 10
+b 10
+c 10
+d 10
+e 10
+f 10
+g 10
h 10
-i 10
+i 10
select c,count(*) from t1 group by c limit 10;
c count(*)
a 1
diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result
index 7dbff4beca5..1053b1918fb 100644
--- a/mysql-test/r/mysql.result
+++ b/mysql-test/r/mysql.result
@@ -76,6 +76,16 @@ c_cp932
| >a < | 0123456789 | 4 |
| >abcd< | | 4 |
+----------------------+------------+--------+
++-------------------+
+| __tañgè Ñãmé |
++-------------------+
+| John Doe |
++-------------------+
++-------------------+
+| John Doe |
++-------------------+
+| __tañgè Ñãmé |
++-------------------+
+------+------+---------------------------+
| i | j | k |
+------+------+---------------------------+
diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result
index d9ca863b6bc..123091841df 100644
--- a/mysql-test/r/mysqltest.result
+++ b/mysql-test/r/mysqltest.result
@@ -217,8 +217,11 @@ hej
a long variable content
a long variable content
-a long $where variable content
+a long a long variable content variable content
+a long \$where variable content
+banana = banana
+Not a banana: ba\$cat\$cat
mysqltest: At line 1: Missing arguments to let
mysqltest: At line 1: Missing variable name in let
mysqltest: At line 1: Variable name in hi=hi does not start with '$'
diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result
index 7cdd5e1b152..a392de613f8 100644
--- a/mysql-test/r/olap.result
+++ b/mysql-test/r/olap.result
@@ -592,6 +592,21 @@ a max(b)
NULL 2
a 1
drop table t1;
+create table t1 (a varchar(22) not null , b int);
+insert into t1 values ("2006-07-01 21:30", 1), ("2006-07-01 23:30", 10);
+select left(a,10), a, sum(b) from t1 group by 1,2 with rollup;
+left(a,10) a sum(b)
+2006-07-01 2006-07-01 21:30 1
+2006-07-01 2006-07-01 23:30 10
+2006-07-01 NULL 11
+NULL NULL 11
+select left(a,10) x, a, sum(b) from t1 group by x,a with rollup;
+x a sum(b)
+2006-07-01 2006-07-01 21:30 1
+2006-07-01 2006-07-01 23:30 10
+2006-07-01 NULL 11
+NULL NULL 11
+drop table t1;
CREATE TABLE t1(id int, type char(1));
INSERT INTO t1 VALUES
(1,"A"),(2,"C"),(3,"A"),(4,"A"),(5,"B"),
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 1727c4ddfbe..048c3ae46d3 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -1358,4 +1358,25 @@ EXECUTE stmt USING @a;
i j i i j
DEALLOCATE PREPARE stmt;
DROP TABLE IF EXISTS t1, t2, t3;
+DROP TABLE IF EXISTS t1, t2;
+CREATE TABLE t1 (i INT KEY);
+CREATE TABLE t2 (i INT);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1);
+PREPARE stmt FROM "SELECT t2.i FROM t1 LEFT JOIN t2 ON t2.i = t1.i
+ WHERE t1.i = ?";
+SET @arg= 1;
+EXECUTE stmt USING @arg;
+i
+1
+SET @arg= 2;
+EXECUTE stmt USING @arg;
+i
+NULL
+SET @arg= 1;
+EXECUTE stmt USING @arg;
+i
+1
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1, t2;
End of 5.0 tests.
diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result
index 205c084b71f..2a7b0e959af 100644
--- a/mysql-test/r/ps_2myisam.result
+++ b/mysql-test/r/ps_2myisam.result
@@ -2689,21 +2689,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2739,21 +2739,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result
index 2e7c4785542..88e8bf3ce04 100644
--- a/mysql-test/r/ps_3innodb.result
+++ b/mysql-test/r/ps_3innodb.result
@@ -2672,21 +2672,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2722,21 +2722,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result
index 8a0da364598..0e4c6fc3077 100644
--- a/mysql-test/r/ps_4heap.result
+++ b/mysql-test/r/ps_4heap.result
@@ -2673,21 +2673,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2723,21 +2723,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result
index 1c6e11f203c..1e337072ecb 100644
--- a/mysql-test/r/ps_5merge.result
+++ b/mysql-test/r/ps_5merge.result
@@ -2609,21 +2609,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2659,21 +2659,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
@@ -5623,21 +5623,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -5673,21 +5673,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result
index 3546b05870a..49e3f9d9bb7 100644
--- a/mysql-test/r/ps_6bdb.result
+++ b/mysql-test/r/ps_6bdb.result
@@ -2672,21 +2672,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2722,21 +2722,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result
index b1986ca62dc..c84cced15f5 100644
--- a/mysql-test/r/ps_7ndb.result
+++ b/mysql-test/r/ps_7ndb.result
@@ -2672,21 +2672,21 @@ set @arg00= '1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 1
-c2 1
-c3 1
-c4 1
-c5 1
-c6 1
+c1 127
+c2 32767
+c3 8388607
+c4 2147483647
+c5 2147483647
+c6 9223372036854775807
c7 3.40282e+38
c8 1.11111111111111e+50
c9 1.11111111111111e+50
@@ -2722,21 +2722,21 @@ set @arg00= '-1.11111111111111111111e+50' ;
execute my_insert using @arg00, @arg00, @arg00, @arg00, @arg00, @arg00,
@arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
-Warning 1265 Data truncated for column 'c1' at row 1
-Warning 1265 Data truncated for column 'c2' at row 1
-Warning 1265 Data truncated for column 'c3' at row 1
-Warning 1265 Data truncated for column 'c4' at row 1
-Warning 1265 Data truncated for column 'c5' at row 1
-Warning 1265 Data truncated for column 'c6' at row 1
+Warning 1264 Out of range value adjusted for column 'c1' at row 1
+Warning 1264 Out of range value adjusted for column 'c2' at row 1
+Warning 1264 Out of range value adjusted for column 'c3' at row 1
+Warning 1264 Out of range value adjusted for column 'c4' at row 1
+Warning 1264 Out of range value adjusted for column 'c5' at row 1
+Warning 1264 Out of range value adjusted for column 'c6' at row 1
Warning 1264 Out of range value adjusted for column 'c7' at row 1
Warning 1264 Out of range value adjusted for column 'c12' at row 1
execute my_select ;
-c1 -1
-c2 -1
-c3 -1
-c4 -1
-c5 -1
-c6 -1
+c1 -128
+c2 -32768
+c3 -8388608
+c4 -2147483648
+c5 -2147483648
+c6 -9223372036854775808
c7 -3.40282e+38
c8 -1.11111111111111e+50
c9 -1.11111111111111e+50
diff --git a/mysql-test/r/rename.result b/mysql-test/r/rename.result
index 76c0f4422fe..345270231ef 100644
--- a/mysql-test/r/rename.result
+++ b/mysql-test/r/rename.result
@@ -54,3 +54,13 @@ Tables_in_test
t2
t4
drop table t2, t4;
+create table t1(f1 int);
+create view v1 as select * from t1;
+alter table v1 rename to v2;
+alter table v1 rename to v2;
+ERROR 42S02: Table 'test.v1' doesn't exist
+rename table v2 to v1;
+rename table v2 to v1;
+ERROR 42S01: Table 'v1' already exists
+drop view v1;
+drop table t1;
diff --git a/mysql-test/r/repair.result b/mysql-test/r/repair.result
index 9b07281aa7b..54d53299743 100644
--- a/mysql-test/r/repair.result
+++ b/mysql-test/r/repair.result
@@ -52,3 +52,41 @@ Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_par
t1 1 a 1 a A 5 NULL NULL YES BTREE
SET myisam_repair_threads=@@global.myisam_repair_threads;
DROP TABLE t1;
+CREATE TABLE t1(a INT);
+USE mysql;
+REPAIR TABLE test.t1 USE_FRM;
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+USE test;
+DROP TABLE t1;
+CREATE TABLE t1(a CHAR(255), KEY(a));
+SET myisam_sort_buffer_size=4096;
+INSERT INTO t1 VALUES
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0');
+Warnings:
+Error 1034 sort_buffer_size is to small
+Error 1034 Number of rows changed from 0 to 157
+SET myisam_repair_threads=2;
+REPAIR TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 repair error sort_buffer_size is to small
+test.t1 repair warning Number of rows changed from 0 to 157
+test.t1 repair status OK
+SET myisam_repair_threads=@@global.myisam_repair_threads;
+SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
+DROP TABLE t1;
diff --git a/mysql-test/r/round.result b/mysql-test/r/round.result
new file mode 100644
index 00000000000..e9a80df0f49
--- /dev/null
+++ b/mysql-test/r/round.result
@@ -0,0 +1,272 @@
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (sint8 tinyint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('127.4');
+INSERT INTO t1 VALUES ('127.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint8' at row 1
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-127.4');
+INSERT INTO t1 VALUES ('-127.5');
+INSERT INTO t1 VALUES ('-128.4');
+INSERT INTO t1 VALUES ('-128.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint8' at row 1
+SELECT * FROM t1;
+sint8
+0
+1
+127
+127
+0
+-1
+-127
+-128
+-128
+-128
+DROP TABLE t1;
+CREATE TABLE t1 (uint8 tinyint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('127.4');
+INSERT INTO t1 VALUES ('127.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint8' at row 1
+INSERT INTO t1 VALUES ('255.4');
+INSERT INTO t1 VALUES ('255.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint8' at row 1
+SELECT * FROM t1;
+uint8
+0
+1
+127
+128
+0
+0
+255
+255
+DROP TABLE t1;
+CREATE TABLE t1 (sint16 smallint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('32767.4');
+INSERT INTO t1 VALUES ('32767.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint16' at row 1
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-32767.4');
+INSERT INTO t1 VALUES ('-32767.5');
+INSERT INTO t1 VALUES ('-32768.4');
+INSERT INTO t1 VALUES ('-32768.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint16' at row 1
+SELECT * FROM t1;
+sint16
+0
+1
+32767
+32767
+0
+-1
+-32767
+-32768
+-32768
+-32768
+DROP TABLE t1;
+CREATE TABLE t1 (uint16 smallint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('32767.4');
+INSERT INTO t1 VALUES ('32767.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint16' at row 1
+INSERT INTO t1 VALUES ('65535.4');
+INSERT INTO t1 VALUES ('65535.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint16' at row 1
+SELECT * FROM t1;
+uint16
+0
+1
+32767
+32768
+0
+0
+65535
+65535
+DROP TABLE t1;
+CREATE TABLE t1 (sint24 mediumint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('8388607.4');
+INSERT INTO t1 VALUES ('8388607.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint24' at row 1
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-8388607.4');
+INSERT INTO t1 VALUES ('-8388607.5');
+INSERT INTO t1 VALUES ('-8388608.4');
+INSERT INTO t1 VALUES ('-8388608.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint24' at row 1
+SELECT * FROM t1;
+sint24
+0
+1
+8388607
+8388607
+0
+-1
+-8388607
+-8388608
+-8388608
+-8388608
+DROP TABLE t1;
+CREATE TABLE t1 (uint24 mediumint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('8388607.4');
+INSERT INTO t1 VALUES ('8388607.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint24' at row 1
+INSERT INTO t1 VALUES ('16777215.4');
+INSERT INTO t1 VALUES ('16777215.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint24' at row 1
+SELECT * FROM t1;
+uint24
+0
+1
+8388607
+8388608
+0
+0
+16777215
+16777215
+DROP TABLE t1;
+CREATE TABLE t1 (sint64 bigint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('9223372036854775807.4');
+INSERT INTO t1 VALUES ('9223372036854775807.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint64' at row 1
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-9223372036854775807.4');
+INSERT INTO t1 VALUES ('-9223372036854775807.5');
+INSERT INTO t1 VALUES ('-9223372036854775808.4');
+INSERT INTO t1 VALUES ('-9223372036854775808.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sint64' at row 1
+SELECT * FROM t1;
+sint64
+0
+1
+9223372036854775807
+9223372036854775807
+0
+-1
+-9223372036854775807
+-9223372036854775808
+-9223372036854775808
+-9223372036854775808
+DROP TABLE t1;
+CREATE TABLE t1 (uint64 bigint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('9223372036854775807.4');
+INSERT INTO t1 VALUES ('9223372036854775807.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint64' at row 1
+INSERT INTO t1 VALUES ('18446744073709551615.4');
+INSERT INTO t1 VALUES ('18446744073709551615.5');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'uint64' at row 1
+INSERT INTO t1 VALUES ('1844674407370955161.0');
+INSERT INTO t1 VALUES ('1844674407370955161.1');
+INSERT INTO t1 VALUES ('1844674407370955161.2');
+INSERT INTO t1 VALUES ('1844674407370955161.3');
+INSERT INTO t1 VALUES ('1844674407370955161.4');
+INSERT INTO t1 VALUES ('1844674407370955161.5');
+INSERT INTO t1 VALUES ('1844674407370955161.0e1');
+INSERT INTO t1 VALUES ('1844674407370955161.1e1');
+INSERT INTO t1 VALUES ('1844674407370955161.2e1');
+INSERT INTO t1 VALUES ('1844674407370955161.3e1');
+INSERT INTO t1 VALUES ('1844674407370955161.4e1');
+INSERT INTO t1 VALUES ('1844674407370955161.5e1');
+INSERT INTO t1 VALUES ('18446744073709551610e-1');
+INSERT INTO t1 VALUES ('18446744073709551611e-1');
+INSERT INTO t1 VALUES ('18446744073709551612e-1');
+INSERT INTO t1 VALUES ('18446744073709551613e-1');
+INSERT INTO t1 VALUES ('18446744073709551614e-1');
+INSERT INTO t1 VALUES ('18446744073709551615e-1');
+SELECT * FROM t1;
+uint64
+0
+1
+9223372036854775807
+9223372036854775808
+0
+0
+18446744073709551615
+18446744073709551615
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955162
+18446744073709551610
+18446744073709551611
+18446744073709551612
+18446744073709551613
+18446744073709551614
+18446744073709551615
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955161
+1844674407370955162
+DROP TABLE t1;
+CREATE TABLE t1 (str varchar(128), sint64 bigint not null default 0);
+INSERT INTO t1 (str) VALUES ('1.5');
+INSERT INTO t1 (str) VALUES ('1.00005e4');
+INSERT INTO t1 (str) VALUES ('1.0005e3');
+INSERT INTO t1 (str) VALUES ('1.005e2');
+INSERT INTO t1 (str) VALUES ('1.05e1');
+INSERT INTO t1 (str) VALUES ('1.5e0');
+INSERT INTO t1 (str) VALUES ('100005e-1');
+INSERT INTO t1 (str) VALUES ('100050e-2');
+INSERT INTO t1 (str) VALUES ('100500e-3');
+INSERT INTO t1 (str) VALUES ('105000e-4');
+INSERT INTO t1 (str) VALUES ('150000e-5');
+UPDATE t1 SET sint64=str;
+SELECT * FROM t1;
+str sint64
+1.5 2
+1.00005e4 10001
+1.0005e3 1001
+1.005e2 101
+1.05e1 11
+1.5e0 2
+100005e-1 10001
+100050e-2 1001
+100500e-3 101
+105000e-4 11
+150000e-5 2
+DROP TABLE t1;
diff --git a/mysql-test/r/rpl_insert_id.result b/mysql-test/r/rpl_insert_id.result
index e425cce9508..d133a2ae8ed 100644
--- a/mysql-test/r/rpl_insert_id.result
+++ b/mysql-test/r/rpl_insert_id.result
@@ -234,6 +234,153 @@ n b
2 100
3 350
drop table t1;
+DROP PROCEDURE IF EXISTS p1;
+DROP TABLE IF EXISTS t1, t2;
+SELECT LAST_INSERT_ID(0);
+LAST_INSERT_ID(0)
+0
+CREATE TABLE t1 (
+id INT NOT NULL DEFAULT 0,
+last_id INT,
+PRIMARY KEY (id)
+);
+CREATE TABLE t2 (
+id INT NOT NULL AUTO_INCREMENT,
+last_id INT,
+PRIMARY KEY (id)
+);
+CREATE PROCEDURE p1()
+BEGIN
+INSERT INTO t2 (last_id) VALUES (LAST_INSERT_ID());
+INSERT INTO t1 (last_id) VALUES (LAST_INSERT_ID());
+END|
+CALL p1();
+SELECT * FROM t1;
+id last_id
+0 1
+SELECT * FROM t2;
+id last_id
+1 0
+SELECT * FROM t1;
+id last_id
+0 1
+SELECT * FROM t2;
+id last_id
+1 0
+DROP PROCEDURE p1;
+DROP TABLE t1, t2;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP FUNCTION IF EXISTS f2;
+DROP FUNCTION IF EXISTS f3;
+DROP TABLE IF EXISTS t1, t2;
+CREATE TABLE t1 (
+i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+j INT DEFAULT 0
+);
+CREATE TABLE t2 (i INT);
+CREATE PROCEDURE p1()
+BEGIN
+INSERT INTO t1 (i) VALUES (NULL);
+INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+INSERT INTO t1 (i) VALUES (NULL), (NULL);
+INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+END |
+CREATE FUNCTION f1() RETURNS INT MODIFIES SQL DATA
+BEGIN
+INSERT INTO t1 (i) VALUES (NULL);
+INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+INSERT INTO t1 (i) VALUES (NULL), (NULL);
+INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+RETURN 0;
+END |
+CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC
+RETURN LAST_INSERT_ID() |
+CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA
+BEGIN
+INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+RETURN 0;
+END |
+INSERT INTO t1 VALUES (NULL, -1);
+CALL p1();
+SELECT f1();
+f1()
+0
+INSERT INTO t1 VALUES (NULL, f2()), (NULL, LAST_INSERT_ID()),
+(NULL, LAST_INSERT_ID()), (NULL, f2()), (NULL, f2());
+INSERT INTO t1 VALUES (NULL, f2());
+INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)),
+(NULL, @@LAST_INSERT_ID);
+INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID());
+UPDATE t1 SET j= -1 WHERE i IS NULL;
+INSERT INTO t1 (i) VALUES (NULL);
+INSERT INTO t1 (i) VALUES (NULL);
+SELECT f3();
+f3()
+0
+SELECT * FROM t1;
+i j
+1 -1
+2 0
+3 0
+4 0
+5 0
+6 0
+7 0
+8 3
+9 3
+10 3
+11 3
+12 3
+13 8
+14 13
+15 5
+16 13
+17 -1
+18 14
+19 0
+20 0
+SELECT * FROM t2;
+i
+2
+3
+5
+6
+19
+SELECT * FROM t1;
+i j
+1 -1
+2 0
+3 0
+4 0
+5 0
+6 0
+7 0
+8 3
+9 3
+10 3
+11 3
+12 3
+13 8
+14 13
+15 5
+16 13
+17 -1
+18 14
+19 0
+20 0
+SELECT * FROM t2;
+i
+2
+3
+5
+6
+19
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
+DROP FUNCTION f2;
+DROP FUNCTION f3;
+DROP TABLE t1, t2;
# End of 5.0 tests
diff --git a/mysql-test/r/rpl_rewrite_db.result b/mysql-test/r/rpl_rewrite_db.result
index 71ac39010b5..1b843bffdca 100644
--- a/mysql-test/r/rpl_rewrite_db.result
+++ b/mysql-test/r/rpl_rewrite_db.result
@@ -67,9 +67,9 @@ drop table t1;
create table t1 (a int, b char(10));
load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'error ' for column 'a' at row 3
Warning 1262 Row 3 was truncated; it contained more data than there were input columns
-Warning 1264 Out of range value adjusted for column 'a' at row 5
+Warning 1366 Incorrect integer value: 'wrong end ' for column 'a' at row 5
Warning 1262 Row 5 was truncated; it contained more data than there were input columns
select * from rewrite.t1;
a b
@@ -81,7 +81,8 @@ a b
truncate table t1;
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 4
+Warning 1366 Incorrect integer value: '
+' for column 'a' at row 4
Warning 1261 Row 4 doesn't contain data for all columns
select * from rewrite.t1;
a b
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 0c62d3f570f..44063c1e890 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2734,7 +2734,7 @@ CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (10);
SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
i='1e+01' i=1e+01 i in (1e+01,1e+01) i in ('1e+01','1e+01')
-0 1 1 1
+1 1 1 1
DROP TABLE t1;
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
@@ -3517,3 +3517,97 @@ id a b c d e
2 NULL NULL NULL 2 40
2 NULL NULL NULL 2 50
DROP TABLE t1,t2,t3;
+create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
+c7 int, c8 int, c9 int, fulltext key (`c1`));
+select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
+from t1 where c9=1 order by c2, c2;
+match (`c1`) against ('z') c2 c3 c4 c5 c6 c7 c8
+drop table t1;
+CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
+CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
+INSERT INTO t1 VALUES
+('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'),
+('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
+INSERT INTO t2 VALUES
+('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
+('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
+('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
+('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
+EXPLAIN SELECT t2.*
+FROM t1 JOIN t2 ON t2.fk=t1.pk
+WHERE t2.fk < 'c' AND t2.pk=t1.fk;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 3 Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
+EXPLAIN SELECT t2.*
+FROM t1 JOIN t2 ON t2.fk=t1.pk
+WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 2 Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
+EXPLAIN SELECT t2.*
+FROM t1 JOIN t2 ON t2.fk=t1.pk
+WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 2 Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
+DROP TABLE t1,t2;
+CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
+CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
+PRIMARY KEY (a), UNIQUE KEY (b));
+INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
+INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
+EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 const b b 22 const 1 Using index
+DROP TABLE t1,t2;
+CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
+CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
+CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
+INSERT INTO t1 VALUES
+(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+(6,63,67), (5,55,58), (3,38,39), (8,81,89);
+INSERT INTO t2 VALUES
+(21,210), (41,410), (82,820), (83,830), (84,840),
+(65,650), (51,510), (37,370), (94,940), (76,760),
+(22,220), (33,330), (40,400), (95,950), (38,380),
+(67,670), (88,880), (57,570), (96,960), (97,970);
+INSERT INTO t3 VALUES
+(210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
+(440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
+(230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
+(450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
+t3.a=t2.a AND t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si si 5 NULL 4 Using where
+1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3
+WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
+t3.a=t2.a AND t3.c IN ('bb','ee') ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si,ai si 5 NULL 4 Using where
+1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
+t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si si 5 NULL 2 Using where
+1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3
+WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
+t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si,ai si 5 NULL 2 Using where
+1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+DROP TABLE t1,t2,t3;
diff --git a/mysql-test/r/sp-vars.result b/mysql-test/r/sp-vars.result
index 83ee188bfa4..14040f8420e 100644
--- a/mysql-test/r/sp-vars.result
+++ b/mysql-test/r/sp-vars.result
@@ -896,7 +896,7 @@ sp_var
@user_var
0
Warnings:
-Warning 1264 Out of range value adjusted for column 'sp_var' at row 1
+Warning 1366 Incorrect integer value: 'Hello, world!' for column 'sp_var' at row 1
DROP PROCEDURE p1;
DROP TABLE t1;
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 061b754b6cd..31aa96ab05d 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -5394,6 +5394,21 @@ Procedure sql_mode Create Procedure
bug21416 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug21416`()
show create procedure bug21416
drop procedure bug21416|
+DROP PROCEDURE IF EXISTS bug21414|
+CREATE PROCEDURE bug21414() SELECT 1|
+FLUSH TABLES WITH READ LOCK|
+DROP PROCEDURE bug21414|
+ERROR HY000: Can't execute the query because you have a conflicting read lock
+UNLOCK TABLES|
+The following should succeed.
+DROP PROCEDURE bug21414|
+set names utf8|
+drop database if exists това_е_дълго_име_за_база_данни_нали|
+create database това_е_дълго_име_за_база_данни_нали|
+INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','')|
+call това_е_дълго_име_за_база_данни_нали.това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго()|
+ERROR HY000: Failed to load routine това_е_дълго_име_за_база_данни_нали.това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+drop database това_е_дълго_име_за_база_данни_нали|
CREATE TABLE t3 (
Member_ID varchar(15) NOT NULL,
PRIMARY KEY (Member_ID)
@@ -5430,8 +5445,6 @@ INSERT INTO t4(Member_ID, Action, Action_Date, Track) VALUES
('666666', 'Enrolled', '2006-05-12', 'CHF' ),
('666666', 'Disenrolled', '2006-06-01', 'CAD' )|
DROP FUNCTION IF EXISTS bug21493|
-Warnings:
-Note 1305 FUNCTION bug21493 does not exist
CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45)
BEGIN
DECLARE tracks VARCHAR(45);
@@ -5457,4 +5470,5 @@ CAD
CHF
DROP FUNCTION bug21493|
DROP TABLE t3,t4|
+End of 5.0 tests
drop table t1,t2;
diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result
index e144eed92f5..702fc68bb25 100644
--- a/mysql-test/r/strict.result
+++ b/mysql-test/r/strict.result
@@ -619,9 +619,9 @@ ERROR 22012: Division by 0
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
-ERROR 22003: Out of range value adjusted for column 'col1' at row 1
+ERROR HY000: Incorrect integer value: '' for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES ('a59b');
-ERROR 22003: Out of range value adjusted for column 'col1' at row 1
+ERROR HY000: Incorrect integer value: 'a59b' for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES ('1a');
ERROR 01000: Data truncated for column 'col1' at row 1
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
@@ -701,9 +701,9 @@ ERROR 22012: Division by 0
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
-ERROR 22003: Out of range value adjusted for column 'col1' at row 1
+ERROR HY000: Incorrect integer value: '' for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES ('a59b');
-ERROR 22003: Out of range value adjusted for column 'col1' at row 1
+ERROR HY000: Incorrect integer value: 'a59b' for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES ('1a');
ERROR 01000: Data truncated for column 'col1' at row 1
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
@@ -925,10 +925,10 @@ Warning 1264 Out of range value adjusted for column 'col2' at row 1
Warning 1264 Out of range value adjusted for column 'col2' at row 1
SELECT * FROM t1;
col1 col2
-0 0
+-2.2e-307 0
1e-303 0
1.7e+308 1.7e+308
-0 0
+-2.2e-307 0
-2e-307 0
1.7e+308 1.7e+308
0 NULL
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 6bf85979002..131f652a178 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -363,12 +363,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t8 ref PRIMARY PRIMARY 37 const 1 Using where; Using index
-4 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index
-2 SUBQUERY t8 ref PRIMARY PRIMARY 37 const 1 Using where
-3 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index
+1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 Using index
+4 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
+2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1
+3 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
Warnings:
-Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce')))
+Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s)
@@ -744,7 +744,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
Warnings:
-Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `1` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 AS `3` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
+Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `1` having trigcond((<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1))) union select 3 AS `3` having trigcond((<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
id
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
@@ -907,7 +907,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 Using where; Using index
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
+Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and trigcond(((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`)))) having trigcond(<is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
drop table t1,t2,t3;
create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
@@ -2817,19 +2817,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where
Warnings:
-Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'0') and ((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) having (<is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`)))) AS `test` from `test`.`t1`
+Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'0') and trigcond((((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having trigcond((<is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where
Warnings:
-Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))
+Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'N') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))))
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
Warnings:
-Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = _latin1'0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)) and <is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`)))) AS `test` from `test`.`t1`
+Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = _latin1'0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having trigcond((((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)) and <is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
DROP TABLE t1,t2;
CREATE TABLE t1 (a char(5), b char(5));
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
@@ -3002,6 +3002,21 @@ field1 field2
1 1
1 3
DROP TABLE t1, t2;
+CREATE TABLE t1(a int, INDEX (a));
+INSERT INTO t1 VALUES (1), (3), (5), (7);
+INSERT INTO t1 VALUES (NULL);
+CREATE TABLE t2(a int);
+INSERT INTO t2 VALUES (1),(2),(3);
+EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index
+SELECT a, a IN (SELECT a FROM t1) FROM t2;
+a a IN (SELECT a FROM t1)
+1 1
+2 NULL
+3 1
+DROP TABLE t1,t2;
create table t1 (df decimal(5,1));
insert into t1 values(1.1);
insert into t1 values(2.2);
@@ -3458,6 +3473,32 @@ id select_type table type possible_keys key key_len ref rows Extra
4 UNION t12 system NULL NULL NULL NULL 0 const row not found
NULL UNION RESULT <union2,4> ALL NULL NULL NULL NULL NULL
DROP TABLE t1;
+CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
+insert into t1 (a) values (FLOOR(rand() * 100));
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+SELECT a,
+(SELECT REPEAT(' ',250) FROM t1 i1
+WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
+FROM t1 ORDER BY a LIMIT 5;
+a a
+0 NULL
+0 NULL
+0 NULL
+0 NULL
+0 NULL
+DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT);
INSERT INTO t2 values (1);
@@ -3519,3 +3560,19 @@ FROM t1 GROUP BY t1.a LIMIT 1)
2
2
DROP TABLE t1,t2;
+CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
+CREATE TABLE t2 (x int auto_increment, y int, z int,
+PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
+SET SESSION sort_buffer_size = 32 * 1024;
+SELECT SQL_NO_CACHE COUNT(*)
+FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
+FROM t1) t;
+COUNT(*)
+3000
+SET SESSION sort_buffer_size = 8 * 1024 * 1024;
+SELECT SQL_NO_CACHE COUNT(*)
+FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
+FROM t1) t;
+COUNT(*)
+3000
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result
new file mode 100644
index 00000000000..5ab8e448b39
--- /dev/null
+++ b/mysql-test/r/subselect3.result
@@ -0,0 +1,153 @@
+drop table if exists t0, t1, t2, t3, t4;
+create table t1 (oref int, grp int, ie int) ;
+insert into t1 (oref, grp, ie) values
+(1, 1, 1),
+(1, 1, 1),
+(1, 2, NULL),
+(2, 1, 3),
+(3, 1, 4),
+(3, 2, NULL);
+create table t2 (oref int, a int);
+insert into t2 values
+(1, 1),
+(2, 2),
+(3, 3),
+(4, NULL),
+(2, NULL);
+select a, oref, a in (select max(ie)
+from t1 where oref=t2.oref group by grp) from t2;
+a oref a in (select max(ie)
+from t1 where oref=t2.oref group by grp)
+1 1 1
+2 2 0
+3 3 NULL
+NULL 4 0
+NULL 2 NULL
+explain extended
+select a, oref, a in (select max(ie)
+from t1 where oref=t2.oref group by grp) from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 Using where; Using temporary; Using filesort
+Warnings:
+Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
+Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie)
+from t1 where oref=t2.oref group by grp)` from `test`.`t2`
+explain extended
+select a, oref from t2
+where a in (select max(ie) from t1 where oref=t2.oref group by grp);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 Using where; Using temporary; Using filesort
+Warnings:
+Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
+Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))
+create table t3 (a int);
+insert into t3 values (NULL), (NULL);
+flush status;
+select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
+a in (select max(ie) from t1 where oref=4 group by grp)
+0
+0
+show status like 'Handler_read_rnd_next';
+Variable_name Value
+Handler_read_rnd_next 11
+select ' ^ This must show 11' Z;
+Z
+ ^ This must show 11
+explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 Using where; Using temporary; Using filesort
+Warnings:
+Note 1003 select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
+drop table t1, t2, t3;
+create table t1 (a int, oref int, key(a));
+insert into t1 values
+(1, 1),
+(1, NULL),
+(2, 3),
+(2, NULL),
+(3, NULL);
+create table t2 (a int, oref int);
+insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+oref a Z
+1 1 1
+2 2 0
+3 NULL NULL
+4 NULL 0
+explain extended
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Using where
+Warnings:
+Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
+Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`)))) AS `Z` from `test`.`t2`
+flush status;
+select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
+oref a
+1 1
+show status like '%Handler_read_rnd_next';
+Variable_name Value
+Handler_read_rnd_next 5
+delete from t2;
+insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
+flush status;
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+oref a Z
+0 NULL 0
+0 NULL 0
+0 NULL 0
+0 NULL 0
+show status like '%Handler_read%';
+Variable_name Value
+Handler_read_first 0
+Handler_read_key 0
+Handler_read_next 0
+Handler_read_prev 0
+Handler_read_rnd 0
+Handler_read_rnd_next 29
+select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
+Z
+No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.
+drop table t1, t2;
+create table t1 (a int, b int, primary key (a));
+insert into t1 values (1,1), (3,1),(100,1);
+create table t2 (a int, b int);
+insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
+select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
+a b Z
+1 1 1
+2 1 0
+NULL 1 NULL
+NULL 0 0
+drop table t1, t2;
+create table t1 (a int, b int, key(a));
+insert into t1 values
+(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+create table t2 like t1;
+insert into t2 select * from t1;
+update t2 set b=1;
+create table t3 (a int, oref int);
+insert into t3 values (1, 1), (NULL,1), (NULL,0);
+select a, oref,
+t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
+from t3;
+a oref Z
+1 1 1
+NULL 1 NULL
+NULL 0 0
+explain extended
+select a, oref,
+t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
+from t3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 ALL NULL NULL NULL NULL 3
+2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 4 Using where
+2 DEPENDENT SUBQUERY t2 ref a a 5 test.t1.b 1 Using where
+Warnings:
+Note 1276 Field or reference 't3.oref' of SELECT #2 was resolved in SELECT #1
+Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`b`) and (`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))) AS `Z` from `test`.`t3`
+drop table t1, t2, t3;
diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result
index 82479504b10..139a7da77de 100644
--- a/mysql-test/r/temp_table.result
+++ b/mysql-test/r/temp_table.result
@@ -135,3 +135,20 @@ d c
bar 2
foo 1
drop table t1, t2;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (i INT);
+LOCK TABLE t1 WRITE;
+CREATE TEMPORARY TABLE t1 (i INT);
+The following command should not block
+DROP TEMPORARY TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (i INT);
+CREATE TEMPORARY TABLE t2 (i INT);
+DROP TEMPORARY TABLE t2, t1;
+ERROR 42S02: Unknown table 't1'
+SELECT * FROM t2;
+ERROR 42S02: Table 'test.t2' doesn't exist
+SELECT * FROM t1;
+i
+DROP TABLE t1;
+End of 4.1 tests.
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index c687d4c49c8..0b0bf1086db 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -1173,4 +1173,16 @@ TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW SET @a = 2;
ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60)
DROP TABLE t1;
DROP TABLE t2;
+drop table if exists t1;
+create table t1 (i int, j int key);
+insert into t1 values (1,1), (2,2), (3,3);
+create trigger t1_bu before update on t1 for each row
+set new.j = new.j + 10;
+update t1 set i= i+ 10 where j > 2;
+select * from t1;
+i j
+1 1
+2 2
+13 13
+drop table t1;
End of 5.0 tests
diff --git a/mysql-test/r/type_bit.result b/mysql-test/r/type_bit.result
index f0ac00cedfa..bd58e83bb3f 100644
--- a/mysql-test/r/type_bit.result
+++ b/mysql-test/r/type_bit.result
@@ -602,4 +602,12 @@ NULL NULL
0 0
11111111 11111111
drop table bug15583;
+create table t1(a bit(1), b smallint unsigned);
+insert into t1 (b, a) values ('2', '1');
+Warnings:
+Warning 1264 Out of range value adjusted for column 'a' at row 1
+select hex(a), b from t1;
+hex(a) b
+1 2
+drop table t1;
End of 5.0 tests
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result
index 49e4827cb97..7fc1c4f398d 100644
--- a/mysql-test/r/type_datetime.result
+++ b/mysql-test/r/type_datetime.result
@@ -179,3 +179,15 @@ a
2006-06-06 15:55:55
DROP PREPARE s;
DROP TABLE t1;
+SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));
+CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6))
+20060810.000000
+SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));
+CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6))
+20060810101112.000000
+SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));
+CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6))
+20060810101112.000014
+SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));
+CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6))
+101112.098700
diff --git a/mysql-test/r/type_decimal.result b/mysql-test/r/type_decimal.result
index 8b2c08065e0..c9c42d18d68 100644
--- a/mysql-test/r/type_decimal.result
+++ b/mysql-test/r/type_decimal.result
@@ -779,3 +779,14 @@ select f1 from t1 where f1 in (select f1 from t1);
f1
40
drop table t1;
+create table t1 as
+select from_days(s) as date,t
+from (select 1 as s,'t' as t union select null, null ) as sub1;
+select group_concat(t) from t1 group by week(date)/10;
+group_concat(t)
+t
+Warnings:
+Warning 1292 Truncated incorrect datetime value: '0000-00-00'
+Warning 1292 Truncated incorrect datetime value: '0000-00-00'
+Warning 1292 Truncated incorrect datetime value: '0000-00-00'
+drop table t1;
diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result
index 02ba3c7ebd3..f337d87eada 100644
--- a/mysql-test/r/type_enum.result
+++ b/mysql-test/r/type_enum.result
@@ -1745,3 +1745,12 @@ create table t1 (a set('x','y') default 'x');
alter table t1 alter a set default 'z';
ERROR 42000: Invalid default value for 'a'
drop table t1;
+create table t1 (f1 int);
+alter table t1 add f2 enum(0xFFFF);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) default NULL,
+ `f2` enum('ÿÿ') default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1;
diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result
index 61482ab282c..6790ae2c67d 100644
--- a/mysql-test/r/type_float.result
+++ b/mysql-test/r/type_float.result
@@ -262,6 +262,13 @@ desc t3;
Field Type Null Key Default Extra
a decimal(21,2) NO 0.00
drop table t1,t2,t3;
+select 1e-308, 1.00000001e-300, 100000000e-300;
+1e-308 1.00000001e-300 100000000e-300
+0 1.00000001e-300 1e-292
+select 10e307;
+10e307
+1e+308
+End of 4.1 tests
create table t1 (s1 float(0,2));
ERROR 42000: For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 's1').
create table t1 (s1 float(1,2));
diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
index 33f1ece0390..23e6f8266e9 100644
--- a/mysql-test/r/type_newdecimal.result
+++ b/mysql-test/r/type_newdecimal.result
@@ -1412,3 +1412,11 @@ i2 count(distinct j)
1.0 2
2.0 2
drop table t1;
+create table t1(f1 decimal(20,6));
+insert into t1 values (CAST('10:11:12' AS date) + interval 14 microsecond);
+insert into t1 values (CAST('10:11:12' AS time));
+select * from t1;
+f1
+20101112000000.000014
+101112.000000
+drop table t1;
diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result
index 8e37cca6aa9..396f1efa1b7 100644
--- a/mysql-test/r/udf.result
+++ b/mysql-test/r/udf.result
@@ -105,6 +105,85 @@ explain select myfunc_int(f1) from t1 order by 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
drop table t1;
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 values (1,1),(2,2);
+CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
+BEGIN
+RETURN a;
+END
+||
+CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
+SELECT myfunc_int(a AS attr_name) FROM t1;
+myfunc_int(a AS attr_name)
+1
+2
+EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2
+Warnings:
+Note 1003 select myfunc_int(`test`.`t1`.`a` AS `attr_name`) AS `myfunc_int(a AS attr_name)` from `test`.`t1`
+EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2
+Warnings:
+Note 1003 select myfunc_int(`test`.`t1`.`a` AS `a`) AS `myfunc_int(a)` from `test`.`t1`
+SELECT a,c FROM v1;
+a c
+1 1
+2 2
+SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx) as c FROM t1 GROUP BY a' at line 1
+SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx)) as c FROM t1 GROUP BY a' at line 1
+SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx)) as c FROM t1 GROUP BY a' at line 1
+SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
+c
+1
+2
+SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
+c
+1
+2
+EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+Warnings:
+Note 1003 select myfunc_int(min(`test`.`t1`.`b`) AS `xx`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
+EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+Warnings:
+Note 1003 select `test`.`fn`(min(`test`.`t1`.`b`)) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
+EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+Warnings:
+Note 1003 select myfunc_int(`test`.`fn`(min(`test`.`t1`.`b`)) AS `fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
+EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+Warnings:
+Note 1003 select myfunc_int(`test`.`fn`(min(`test`.`t1`.`b`)) AS `test.fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
+SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
+c
+1
+2
+SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
+c
+1
+2
+SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
+c
+1
+2
+SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
+c
+1
+2
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION fn;
End of 5.0 tests.
DROP FUNCTION metaphon;
DROP FUNCTION myfunc_double;
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 6364002993f..b7d2d13d495 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -1306,9 +1306,9 @@ a b
delete from t1;
load data infile '../std_data_ln/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'error ' for column 'a' at row 3
Error 1369 CHECK OPTION failed 'test.v1'
-Warning 1264 Out of range value adjusted for column 'a' at row 4
+Warning 1366 Incorrect integer value: 'wrong end ' for column 'a' at row 4
Error 1369 CHECK OPTION failed 'test.v1'
select * from t1;
a b
@@ -2956,4 +2956,14 @@ View Create View
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`pk` AS `pk` from (`t1` join `t2` on(((`t2`.`fk` = `t1`.`pk`) and (`t2`.`ver` = (select max(`t`.`ver`) AS `MAX(t.ver)` from `t2` `t` where (`t`.`org` = `t2`.`org`))))))
DROP VIEW v1;
DROP TABLE t1, t2;
+CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
+CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
+INSERT INTO v1 (val) VALUES (2);
+INSERT INTO v1 (val) VALUES (4);
+INSERT INTO v1 (val) VALUES (6);
+ERROR HY000: CHECK OPTION failed 'test.v1'
+UPDATE v1 SET val=6 WHERE id=2;
+ERROR HY000: CHECK OPTION failed 'test.v1'
+DROP VIEW v1;
+DROP TABLE t1;
End of 5.0 tests.
diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result
index 283a0661721..d0ad4ca6648 100644
--- a/mysql-test/r/warnings.result
+++ b/mysql-test/r/warnings.result
@@ -31,19 +31,19 @@ Error 1064 You have an error in your SQL syntax; check the manual that correspon
insert into t1 values (1);
insert into t1 values ("hej");
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'hej' for column 'a' at row 1
insert into t1 values ("hej"),("då");
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 1
-Warning 1264 Out of range value adjusted for column 'a' at row 2
+Warning 1366 Incorrect integer value: 'hej' for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'd?' for column 'a' at row 2
set SQL_WARNINGS=1;
insert into t1 values ("hej");
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'hej' for column 'a' at row 1
insert into t1 values ("hej"),("då");
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 1
-Warning 1264 Out of range value adjusted for column 'a' at row 2
+Warning 1366 Incorrect integer value: 'hej' for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'd?' for column 'a' at row 2
drop table t1;
set SQL_WARNINGS=0;
drop temporary table if exists not_exists;
@@ -194,44 +194,44 @@ create table t1 (a int);
insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
update t1 set a='abc';
Warnings:
-Warning 1264 Out of range value adjusted for column 'a' at row 1
-Warning 1264 Out of range value adjusted for column 'a' at row 2
-Warning 1264 Out of range value adjusted for column 'a' at row 3
-Warning 1264 Out of range value adjusted for column 'a' at row 4
-Warning 1264 Out of range value adjusted for column 'a' at row 5
-Warning 1264 Out of range value adjusted for column 'a' at row 6
-Warning 1264 Out of range value adjusted for column 'a' at row 7
-Warning 1264 Out of range value adjusted for column 'a' at row 8
-Warning 1264 Out of range value adjusted for column 'a' at row 9
-Warning 1264 Out of range value adjusted for column 'a' at row 10
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 2
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 4
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 5
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 6
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 7
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 8
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 9
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 10
show warnings limit 2, 1;
Level Code Message
-Warning 1264 Out of range value adjusted for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 3
show warnings limit 0, 10;
Level Code Message
-Warning 1264 Out of range value adjusted for column 'a' at row 1
-Warning 1264 Out of range value adjusted for column 'a' at row 2
-Warning 1264 Out of range value adjusted for column 'a' at row 3
-Warning 1264 Out of range value adjusted for column 'a' at row 4
-Warning 1264 Out of range value adjusted for column 'a' at row 5
-Warning 1264 Out of range value adjusted for column 'a' at row 6
-Warning 1264 Out of range value adjusted for column 'a' at row 7
-Warning 1264 Out of range value adjusted for column 'a' at row 8
-Warning 1264 Out of range value adjusted for column 'a' at row 9
-Warning 1264 Out of range value adjusted for column 'a' at row 10
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 2
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 3
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 4
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 5
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 6
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 7
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 8
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 9
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 10
show warnings limit 9, 1;
Level Code Message
-Warning 1264 Out of range value adjusted for column 'a' at row 10
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 10
show warnings limit 10, 1;
Level Code Message
show warnings limit 9, 2;
Level Code Message
-Warning 1264 Out of range value adjusted for column 'a' at row 10
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 10
show warnings limit 0, 0;
Level Code Message
show warnings limit 1;
Level Code Message
-Warning 1264 Out of range value adjusted for column 'a' at row 1
+Warning 1366 Incorrect integer value: 'abc' for column 'a' at row 1
show warnings limit 0;
Level Code Message
show warnings limit 1, 0;
@@ -243,3 +243,59 @@ a
select * from t1 limit 0, 0;
a
drop table t1;
+End of 4.1 tests
+CREATE TABLE t1( f1 CHAR(20) );
+CREATE TABLE t2( f1 CHAR(20), f2 CHAR(25) );
+CREATE TABLE t3( f1 CHAR(20), f2 CHAR(25), f3 DATE );
+INSERT INTO t1 VALUES ( 'a`' );
+INSERT INTO t2 VALUES ( 'a`', 'a`' );
+INSERT INTO t3 VALUES ( 'a`', 'a`', '1000-01-1' );
+DROP PROCEDURE IF EXISTS sp1;
+Warnings:
+Note 1305 PROCEDURE sp1 does not exist
+DROP PROCEDURE IF EXISTS sp2;
+Warnings:
+Note 1305 PROCEDURE sp2 does not exist
+DROP PROCEDURE IF EXISTS sp3;
+Warnings:
+Note 1305 PROCEDURE sp3 does not exist
+CREATE PROCEDURE sp1()
+BEGIN
+DECLARE x NUMERIC ZEROFILL;
+SELECT f1 INTO x FROM t1 LIMIT 1;
+END//
+CREATE PROCEDURE sp2()
+BEGIN
+DECLARE x NUMERIC ZEROFILL;
+SELECT f1 INTO x FROM t2 LIMIT 1;
+END//
+CREATE PROCEDURE sp3()
+BEGIN
+DECLARE x NUMERIC ZEROFILL;
+SELECT f1 INTO x FROM t3 LIMIT 1;
+END//
+CALL sp1();
+Warnings:
+Warning 1366 Incorrect decimal value: 'a`' for column 'x' at row 1
+CALL sp2();
+Warnings:
+Warning 1366 Incorrect decimal value: 'a`' for column 'x' at row 1
+CALL sp3();
+Warnings:
+Warning 1366 Incorrect decimal value: 'a`' for column 'x' at row 1
+DROP PROCEDURE IF EXISTS sp1;
+CREATE PROCEDURE sp1()
+BEGIN
+declare x numeric unsigned zerofill;
+SELECT f1 into x from t2 limit 1;
+END//
+CALL sp1();
+Warnings:
+Warning 1366 Incorrect decimal value: 'a`' for column 'x' at row 1
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP PROCEDURE sp1;
+DROP PROCEDURE sp2;
+DROP PROCEDURE sp3;
+End of 5.0 tests
diff --git a/mysql-test/t/analyse.test b/mysql-test/t/analyse.test
index a248c671c18..efcf5f6421c 100644
--- a/mysql-test/t/analyse.test
+++ b/mysql-test/t/analyse.test
@@ -90,5 +90,16 @@ create table t2 (country_id int primary key, country char(20) not null);
insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland');
select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse();
drop table t1,t2;
-# End of 4.1 tests
+#
+# Bug #20305 PROCEDURE ANALYSE() returns wrong M for FLOAT(M, D) and DOUBLE(M, D)
+#
+
+create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
+insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
+select f1 from t1 procedure analyse(1, 1);
+select f2 from t1 procedure analyse(1, 1);
+select f3 from t1 procedure analyse(1, 1);
+drop table t1;
+
+--echo End of 4.1 tests
diff --git a/mysql-test/t/bdb-deadlock.test b/mysql-test/t/bdb-deadlock.test
index 88243cfc860..b48648e0fd0 100644
--- a/mysql-test/t/bdb-deadlock.test
+++ b/mysql-test/t/bdb-deadlock.test
@@ -1,11 +1,3 @@
-# This test doesn't work with the embedded version as this code
-# assumes that one query is running while we are doing queries on
-# a second connection.
-# This would work if mysqltest run would be threaded and handle each
-# connection in a separate thread.
-#
-
--- source include/not_embedded.inc
-- source include/have_bdb.inc
connect (con1,localhost,root,,);
diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test
index 7aec48586d8..5ff138fa97b 100644
--- a/mysql-test/t/ctype_gbk.test
+++ b/mysql-test/t/ctype_gbk.test
@@ -42,3 +42,13 @@ DROP TABLE t1;
select hex(convert(_gbk 0xA14041 using ucs2));
# End of 4.1 tests
+
+#
+# Bug#21620 ALTER TABLE affects other columns
+#
+create table t1 (c1 text not null, c2 text not null) character set gbk;
+alter table t1 change c1 c1 mediumtext character set gbk not null;
+show create table t1;
+drop table t1;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index 39928f18f2e..29e6eab03de 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -942,6 +942,76 @@ check table t1;
drop table t1;
#
+# Bug#20471 LIKE search fails with indexed utf8 char column
+#
+set names utf8;
+create table t1 (s1 char(5) character set utf8);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_general_ci from t1 where s1 like 'ペテ%';
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_general_ci from t1 where s1 like 'ペテ%';
+drop table t1;
+
+set names utf8;
+create table t1 (s1 char(5) character set utf8 collate utf8_unicode_ci);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_unicode_ci from t1 where s1 like 'ペテ%';
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_unicode_ci from t1 where s1 like 'ペテ%';
+drop table t1;
+
+set names utf8;
+create table t1 (s1 char(5) character set utf8 collate utf8_bin);
+insert into t1 values
+('a'),('b'),(null),('ペテルグル'),('ü'),('Y');
+create index it1 on t1 (s1);
+select s1 as before_delete_bin from t1 where s1 like 'ペテ%';
+delete from t1 where s1 = 'Y';
+select s1 as after_delete_bin from t1 where s1 like 'ペテ%';
+drop table t1;
+
+# additional tests from duplicate bug#20744 MySQL return no result
+
+set names utf8;
+--disable_warnings
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_general_ci;
+--enable_warnings
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as gci1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+select a as gci2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+drop table t1;
+
+set names utf8;
+--disable_warnings
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_unicode_ci;
+--enable_warnings
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as uci1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+select a as uci2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+drop table t1;
+
+set names utf8;
+--disable_warnings
+create table t1 (a varchar(30) not null primary key)
+engine=innodb default character set utf8 collate utf8_bin;
+--enable_warnings
+insert into t1 values ('ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã');
+insert into t1 values ('ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ');
+select a as bin1 from t1 where a like 'ã•ã—ã™ã›ãã‹ããã‘ã“ã‚ã„ã†ãˆãŠ%';
+select a as bin2 from t1 where a like 'ã‚ã„ã†ãˆãŠã‹ããã‘ã“ã•ã—ã™ã›ã';
+drop table t1;
+
+
+
+#
# Bug#14896: Comparison with a key in a partial index over mb chararacter field
#
@@ -1069,6 +1139,16 @@ explain select a from t1 group by a;
select a from t1 group by a;
drop table t1;
+#
+# Bug #20204: "order by" changes the results returned
+#
+
+create table t1(a char(10)) default charset utf8;
+insert into t1 values ('123'), ('456');
+explain
+ select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
+select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
+drop table t1;
# End of 4.1 tests
#
@@ -1147,3 +1227,23 @@ execute my_stmt using @a;
set @a:=null;
execute my_stmt using @a;
drop table if exists t1;
+
+#
+# Bug#19960: Inconsistent results when joining
+# InnoDB tables using partial UTF8 indexes
+#
+CREATE TABLE t1 (
+ colA int(11) NOT NULL,
+ colB varchar(255) character set utf8 NOT NULL,
+ PRIMARY KEY (colA)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t1 (colA, colB) VALUES (1, 'foo'), (2, 'foo bar');
+CREATE TABLE t2 (
+ colA int(11) NOT NULL,
+ colB varchar(255) character set utf8 NOT NULL,
+ KEY bad (colA,colB(3))
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t2 (colA, colB) VALUES (1, 'foo'),(2, 'foo bar');
+SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB
+WHERE t1.colA < 3;
+DROP TABLE t1, t2;
diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test
index 55e8f81f763..03d8e20dd8f 100644
--- a/mysql-test/t/delayed.test
+++ b/mysql-test/t/delayed.test
@@ -17,7 +17,8 @@ insert delayed into t1 set a = 4;
insert delayed into t1 set a = 5, tmsp = 19711006010203;
insert delayed into t1 (a, tmsp) values (6, 19711006010203);
insert delayed into t1 (a, tmsp) values (7, NULL);
---sleep 2
+# Wait until the rows are flushed to the table files.
+FLUSH TABLE t1;
insert into t1 set a = 8,tmsp=19711006010203;
select * from t1 where tmsp=0;
select * from t1 where tmsp=19711006010203;
@@ -34,8 +35,8 @@ insert delayed into t1 values (null,"c");
insert delayed into t1 values (3,"d"),(null,"e");
--error 1136
insert delayed into t1 values (3,"this will give an","error");
-# 2 was not enough for --ps-protocol
---sleep 4
+# Wait until the rows are flushed to the table files.
+FLUSH TABLE t1;
show status like 'not_flushed_delayed_rows';
select * from t1;
drop table t1;
@@ -92,10 +93,145 @@ insert delayed into t1 values(null);
# Works, since the delayed-counter is 8, which is unused
insert delayed into t1 values(null);
+# Wait until the rows are flushed to the table files.
+FLUSH TABLE t1;
# Check what we have now
-# must wait so that the delayed thread finishes
-# Note: this must be increased if the test fails
---sleep 1
select * from t1 order by a;
DROP TABLE t1;
+
+#
+# Bug#20627 - INSERT DELAYED does not honour auto_increment_* variables
+#
+SET @bug20627_old_auto_increment_offset=
+ @@auto_increment_offset= 2;
+SET @bug20627_old_auto_increment_increment=
+ @@auto_increment_increment= 3;
+SET @bug20627_old_session_auto_increment_offset=
+ @@session.auto_increment_offset= 4;
+SET @bug20627_old_session_auto_increment_increment=
+ @@session.auto_increment_increment= 5;
+SET @@auto_increment_offset= 2;
+SET @@auto_increment_increment= 3;
+SET @@session.auto_increment_offset= 4;
+SET @@session.auto_increment_increment= 5;
+#
+# Normal insert as reference.
+CREATE TABLE t1 (
+ c1 INT NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (c1)
+ );
+INSERT INTO t1 VALUES (NULL),(NULL),(NULL);
+# Check what we have now
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# Delayed insert.
+CREATE TABLE t1 (
+ c1 INT NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (c1)
+ );
+INSERT DELAYED INTO t1 VALUES (NULL),(NULL),(NULL);
+# Wait until the rows are flushed to the table files.
+FLUSH TABLE t1;
+# Check what we have now
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# Cleanup
+SET @@auto_increment_offset=
+ @bug20627_old_auto_increment_offset;
+SET @@auto_increment_increment=
+ @bug20627_old_auto_increment_increment;
+SET @@session.auto_increment_offset=
+ @bug20627_old_session_auto_increment_offset;
+SET @@session.auto_increment_increment=
+ @bug20627_old_session_auto_increment_increment;
+
+#
+# Bug#20830 - INSERT DELAYED does not honour SET INSERT_ID
+#
+SET @bug20830_old_auto_increment_offset=
+ @@auto_increment_offset= 2;
+SET @bug20830_old_auto_increment_increment=
+ @@auto_increment_increment= 3;
+SET @bug20830_old_session_auto_increment_offset=
+ @@session.auto_increment_offset= 4;
+SET @bug20830_old_session_auto_increment_increment=
+ @@session.auto_increment_increment= 5;
+SET @@auto_increment_offset= 2;
+SET @@auto_increment_increment= 3;
+SET @@session.auto_increment_offset= 4;
+SET @@session.auto_increment_increment= 5;
+#
+# Normal insert as reference.
+CREATE TABLE t1 (
+ c1 INT(11) NOT NULL AUTO_INCREMENT,
+ c2 INT(11) DEFAULT NULL,
+ PRIMARY KEY (c1)
+ );
+SET insert_id= 14;
+INSERT INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
+INSERT INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
+# Restart sequence at a different value.
+INSERT INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33);
+INSERT INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
+# Restart sequence at a different value.
+SET insert_id= 114;
+INSERT INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
+INSERT INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
+# Set one value below the maximum value.
+INSERT INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73);
+INSERT INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
+# Create a duplicate value.
+SET insert_id= 114;
+--error 1062
+INSERT INTO t1 VALUES(NULL, 91);
+INSERT INTO t1 VALUES (NULL, 92), (NULL, 93);
+# Check what we have now
+SELECT * FROM t1;
+SELECT COUNT(*) FROM t1;
+SELECT SUM(c1) FROM t1;
+DROP TABLE t1;
+#
+# Delayed insert.
+CREATE TABLE t1 (
+ c1 INT(11) NOT NULL AUTO_INCREMENT,
+ c2 INT(11) DEFAULT NULL,
+ PRIMARY KEY (c1)
+ );
+SET insert_id= 14;
+INSERT DELAYED INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
+INSERT DELAYED INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
+# Restart sequence at a different value.
+INSERT DELAYED INTO t1 VALUES( 69, 31), (NULL, 32), (NULL, 33);
+INSERT DELAYED INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
+# Restart sequence at a different value.
+SET insert_id= 114;
+INSERT DELAYED INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
+INSERT DELAYED INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
+# Set one value below the maximum value.
+INSERT DELAYED INTO t1 VALUES( 49, 71), (NULL, 72), (NULL, 73);
+INSERT DELAYED INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
+# Create a duplicate value.
+SET insert_id= 114;
+INSERT DELAYED INTO t1 VALUES(NULL, 91);
+INSERT DELAYED INTO t1 VALUES (NULL, 92), (NULL, 93);
+# Wait until the rows are flushed to the table files.
+FLUSH TABLE t1;
+# Check what we have now
+SELECT * FROM t1;
+SELECT COUNT(*) FROM t1;
+SELECT SUM(c1) FROM t1;
+DROP TABLE t1;
+#
+# Cleanup
+SET @@auto_increment_offset=
+ @bug20830_old_auto_increment_offset;
+SET @@auto_increment_increment=
+ @bug20830_old_auto_increment_increment;
+SET @@session.auto_increment_offset=
+ @bug20830_old_session_auto_increment_offset;
+SET @@session.auto_increment_increment=
+ @bug20830_old_session_auto_increment_increment;
+
diff --git a/mysql-test/t/execution_constants.test b/mysql-test/t/execution_constants.test
new file mode 100644
index 00000000000..00967b2eeba
--- /dev/null
+++ b/mysql-test/t/execution_constants.test
@@ -0,0 +1,74 @@
+#
+# Bug#21476: Lost Database Connection During Query
+#
+# When the amount of stack space we think we need to report an error is
+# actually too small, then we can get SEGVs. But, we don't want to reserve
+# space that we could use to get real work done. So, we want the reserved
+# space small, and this test verifies that the reservation is not too small.
+
+CREATE TABLE `t_bug21476` (
+ `ID_BOARD` smallint(5) unsigned NOT NULL default '0',
+ `ID_MEMBER` mediumint(8) unsigned NOT NULL default '0',
+ `logTime` int(10) unsigned NOT NULL default '0',
+ `ID_MSG` mediumint(8) unsigned NOT NULL default '0',
+ PRIMARY KEY (`ID_MEMBER`,`ID_BOARD`),
+ KEY `logTime` (`logTime`)
+) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bulgarian_ci;
+
+INSERT INTO `t_bug21476` VALUES (2,2,1154870939,0),(1,2,1154870957,0),(2,183,1154941362,0),(2,84,1154904301,0),(1,84,1154905867,0),(2,13,1154947484,10271),(3,84,1154880549,0),(1,6,1154892183,0),(2,25,1154947581,10271),(3,25,1154904760,0),(1,25,1154947373,10271),(1,179,1154899992,0),(2,179,1154899410,0),(5,25,1154901666,0),(2,329,1154902026,0),(3,329,1154902040,0),(1,329,1154902058,0),(1,13,1154930841,0),(3,85,1154904987,0),(1,183,1154929665,0),(3,13,1154931268,0),(1,85,1154936888,0),(1,169,1154937959,0),(2,169,1154941717,0),(3,183,1154939810,0),(3,169,1154941734,0);
+
+delimiter //;
+let $query_head=UPDATE t_bug21476 SET ID_MSG = IF(logTime BETWEEN 1 AND 1101770053, 2, //
+let $query_tail =) WHERE logTime BETWEEN 1 AND 1104091539 AND ID_MSG = 0//
+
+# Scan over the possible stack heights, trying to recurse to exactly that
+# depth. Eventually, we will reach our imposed limit on height and try to
+# raise an error. If the remaining stack space is enough to raise that error,
+# we will get an error-number of 1436 and quit the loop. If it's not enough
+# space, we should get a SEGV
+
+# Well more than enough recursions to find the end of our stack.
+let $i = 100000//
+disable_query_log//
+disable_result_log//
+while ($i)
+{
+ # If we SEGV because the min stack size is exceeded, this would return error
+ # 2013 .
+ error 0,1436 //
+ eval $query_head 0 $query_tail//
+
+ if ($mysql_errno != 1436)
+ {
+ # We reached the place where we reported an error about the stack limit,
+ # and we successfully returned the error. That means that at the stack
+ # limit, we still have enough space reserved to report an error.
+ let $i = 1//
+ }
+
+ # Multiplying by three stack frames should be fine enough resolution.
+ # Trading exactness for speed.
+
+ # go one more level deep
+ let $query_head = $query_head IF(logTime <= 1104091$i, $i, //
+ let $query_tail =) $query_tail//
+
+ # go one more level deep
+ let $query_head = $query_head IF(logTime <= 1105091$i, $i, //
+ let $query_tail =) $query_tail//
+
+ # go one more level deep
+ let $query_head = $query_head IF(logTime <= 1106091$i, $i, //
+ let $query_tail =) $query_tail//
+
+ dec $i//
+}
+enable_result_log//
+enable_query_log//
+
+echo Assertion: mysql_errno 1436 == $mysql_errno//
+
+delimiter ;//
+DROP TABLE `t_bug21476`;
+
+--echo End of 5.0 tests.
diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test
index 95ba633fefd..3a4f2f2f5f2 100644
--- a/mysql-test/t/flush.test
+++ b/mysql-test/t/flush.test
@@ -1,11 +1,3 @@
-# This test doesn't work with the embedded version as this code
-# assumes that one query is running while we are doing queries on
-# a second connection.
-# This would work if mysqltest run would be threaded and handle each
-# connection in a separate thread.
-#
--- source include/not_embedded.inc
-
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
diff --git a/mysql-test/t/flush_block_commit.test b/mysql-test/t/flush_block_commit.test
index ebb48242a4d..4412b2c357c 100644
--- a/mysql-test/t/flush_block_commit.test
+++ b/mysql-test/t/flush_block_commit.test
@@ -3,9 +3,6 @@
# We verify that we did not introduce a deadlock.
# This is intended to mimick how mysqldump and innobackup work.
-# This test doesn't work with the embedded server
--- source include/not_embedded.inc
-
# And it requires InnoDB
-- source include/have_innodb.inc
diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test
index b5c468e1638..1065bb5b93e 100644
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@ -32,7 +32,6 @@ select grp,group_concat(d order by a desc) from t1 group by grp;
select grp,group_concat(a order by a,d+c-ascii(c)-a) from t1 group by grp;
select grp,group_concat(a order by d+c-ascii(c),a) from t1 group by grp;
select grp,group_concat(c order by 1) from t1 group by grp;
-select grp,group_concat(c order by "c") from t1 group by grp;
select grp,group_concat(distinct c order by c) from t1 group by grp;
select grp,group_concat(distinct c order by c desc) from t1 group by grp;
explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp;
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index 079d107fad8..089f5ed9911 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -700,3 +700,28 @@ create table t1 select stddev(0);
show create table t1;
drop table t1;
+#
+# Bug #23184: SELECT causes server crash
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
+INSERT INTO t1 SELECT a, b+8 FROM t1;
+INSERT INTO t1 SELECT a, b+16 FROM t1;
+INSERT INTO t1 SELECT a, b+32 FROM t1;
+INSERT INTO t1 SELECT a, b+64 FROM t1;
+INSERT INTO t1 SELECT a, b+128 FROM t1;
+INSERT INTO t1 SELECT a, b+256 FROM t1;
+INSERT INTO t1 SELECT a, b+512 FROM t1;
+INSERT INTO t1 SELECT a, b+1024 FROM t1;
+INSERT INTO t1 SELECT a, b+2048 FROM t1;
+INSERT INTO t1 SELECT a, b+4096 FROM t1;
+INSERT INTO t1 SELECT a, b+8192 FROM t1;
+INSERT INTO t1 SELECT a, b+16384 FROM t1;
+INSERT INTO t1 SELECT a, b+32768 FROM t1;
+SELECT a,COUNT(DISTINCT b) AS cnt FROM t1 GROUP BY a HAVING cnt > 50;
+SELECT a,SUM(DISTINCT b) AS sumation FROM t1 GROUP BY a HAVING sumation > 50;
+SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
+
+DROP TABLE t1;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 7303be31e03..2b3fb86829d 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -447,6 +447,25 @@ show create table t1;
drop table t1;
#
+# 21913: DATE_FORMAT() Crashes mysql server if I use it through
+# mysql-connector-j driver.
+#
+
+SET NAMES latin1;
+SET character_set_results = NULL;
+SHOW VARIABLES LIKE 'character_set_results';
+
+CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY);
+INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
+
+SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
+
+DROP TABLE testBug8868;
+
+SET NAMES DEFAULT;
+
+
+#
# Bug #19844 time_format in Union truncates values
#
diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test
index 091811b05b3..e34dd14dbfc 100644
--- a/mysql-test/t/gis-rtree.test
+++ b/mysql-test/t/gis-rtree.test
@@ -231,6 +231,16 @@ INSERT INTO t1 (c1) VALUES (
CHECK TABLE t1 EXTENDED;
DROP TABLE t1;
+#
+# Bug #21888: Query on GEOMETRY field using PointFromWKB() results in lost connection
+#
+CREATE TABLE t1 (foo GEOMETRY NOT NULL, SPATIAL INDEX(foo) );
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,1)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,0)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,1)));
+INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,0)));
+SELECT 1 FROM t1 WHERE foo != PointFromWKB(POINT(0,0));
+DROP TABLE t1;
# End of 4.1 tests
#
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index ce1e4e59600..3e926fba0c6 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -609,6 +609,30 @@ select sql_buffer_result max(f1) is null from t1;
select sql_buffer_result max(f1)+1 from t1;
drop table t1;
+#
+# BUG#14019-4.1-opt
+#
+CREATE TABLE t1(a INT); INSERT INTO t1 VALUES (1),(2);
+
+SELECT a FROM t1 GROUP BY 'a';
+SELECT a FROM t1 GROUP BY "a";
+SELECT a FROM t1 GROUP BY `a`;
+
+set sql_mode=ANSI_QUOTES;
+SELECT a FROM t1 GROUP BY "a";
+SELECT a FROM t1 GROUP BY 'a';
+SELECT a FROM t1 GROUP BY `a`;
+set sql_mode='';
+
+SELECT a FROM t1 HAVING 'a' > 1;
+SELECT a FROM t1 HAVING "a" > 1;
+SELECT a FROM t1 HAVING `a` > 1;
+
+SELECT a FROM t1 ORDER BY 'a' DESC;
+SELECT a FROM t1 ORDER BY "a" DESC;
+SELECT a FROM t1 ORDER BY `a` DESC;
+DROP TABLE t1;
+
# End of 4.1 tests
#
@@ -655,3 +679,25 @@ where t2.b=v1.a GROUP BY t2.b;
DROP VIEW v1;
DROP TABLE t1,t2;
+
+#
+# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, key (b));
+
+INSERT INTO t1 VALUES (1, 1);
+INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20) FROM t1;
+INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20) FROM t1;
+INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20) FROM t1;
+INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20) FROM t1;
+
+SELECT MIN(b), MAX(b) from t1;
+
+EXPLAIN SELECT b, sum(1) FROM t1 GROUP BY b;
+EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
+SELECT b, sum(1) FROM t1 GROUP BY b;
+SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
+DROP TABLE t1;
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index 5427727a8f4..08f0f54df60 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -794,3 +794,19 @@ SELECT * FROM
t1;
DROP TABLE t1,t2,t3,t4,t5,t6;
+
+#
+# Bug#22342: No results returned for query using max and group by
+#
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b));
+INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
+
+explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
+SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
+SELECT MIN(b), a FROM t1 WHERE b > 1 AND a = 1 GROUP BY a;
+CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c));
+INSERT INTO t2 SELECT a,b,b FROM t1;
+explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
+SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest
index a07da161279..acd1f0d887b 100644
--- a/mysql-test/t/im_daemon_life_cycle.imtest
+++ b/mysql-test/t/im_daemon_life_cycle.imtest
@@ -14,3 +14,47 @@
# process.
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30
+
+###########################################################################
+
+#
+# BUG#12751: Instance Manager: client hangs
+#
+
+--echo
+--echo --------------------------------------------------------------------
+--echo -- Test for BUG#12751
+--echo --------------------------------------------------------------------
+
+# Give some time to begin accepting connections after restart.
+# FIXME: race condition here.
+
+--sleep 3
+
+# 1. Start mysqld;
+
+START INSTANCE mysqld2;
+# FIXME: START INSTANCE should be synchronous.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
+
+# 2. Restart IM-main: kill it and IM-angel will restart it.
+
+--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30
+
+# 3. Issue some statement -- connection should be re-established.
+
+# Give some time to begin accepting connections after restart.
+# FIXME: race condition here.
+
+--sleep 3
+
+--replace_column 3 VERSION
+SHOW INSTANCE STATUS mysqld1;
+
+# 4. Stop mysqld2, because it will not be stopped by IM, as it is nonguarded.
+# So, if it we do not stop it, it will be stopped by mysql-test-run.pl with
+# warning.
+
+STOP INSTANCE mysqld2;
+# FIXME: STOP INSTANCE should be synchronous.
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped
diff --git a/mysql-test/t/innodb-deadlock.test b/mysql-test/t/innodb-deadlock.test
index 41741942963..81acfba5c93 100644
--- a/mysql-test/t/innodb-deadlock.test
+++ b/mysql-test/t/innodb-deadlock.test
@@ -1,6 +1,4 @@
-- source include/have_innodb.inc
-# Can't test this with embedded server
--- source include/not_embedded.inc
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
diff --git a/mysql-test/t/innodb-lock.test b/mysql-test/t/innodb-lock.test
index 55a712fef9b..eacf7e562be 100644
--- a/mysql-test/t/innodb-lock.test
+++ b/mysql-test/t/innodb-lock.test
@@ -1,6 +1,4 @@
-- source include/have_innodb.inc
-# Can't test this with embedded server
--- source include/not_embedded.inc
#
# Check and select innodb lock type
diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test
index 59dbe5e96d4..4d87e9dfb02 100644
--- a/mysql-test/t/innodb_mysql.test
+++ b/mysql-test/t/innodb_mysql.test
@@ -302,3 +302,21 @@ SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
WHERE t1.name LIKE 'A%' OR FALSE;
DROP TABLE t1,t2;
+
+#
+# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
+
+INSERT INTO t1 VALUES ( 1 , 1 , 1);
+INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
+
+EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
+EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
+DROP TABLE t1;
diff --git a/mysql-test/t/kill_n_check.sh b/mysql-test/t/kill_n_check.sh
index 64cc869d1ec..a54fb6ef8bb 100755
--- a/mysql-test/t/kill_n_check.sh
+++ b/mysql-test/t/kill_n_check.sh
@@ -49,7 +49,7 @@ if [ -z "$pid_path" ]; then
exit 0
fi
-if [ $expected_result = 'killed' -a ! -r "$pid_path" ]; then
+if [ ! -r "$pid_path" ]; then
echo "Error: PID file ($pid_path) does not exist."
exit 0
fi
diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test
index 627c33b3d82..466f312757b 100644
--- a/mysql-test/t/lock_multi.test
+++ b/mysql-test/t/lock_multi.test
@@ -1,11 +1,3 @@
-# This test doesn't work with the embedded version as this code
-# assumes that one query is running while we are doing queries on
-# a second connection.
-# This would work if mysqltest run would be threaded and handle each
-# connection in a separate thread.
-#
--- source include/not_embedded.inc
-
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
diff --git a/mysql-test/t/lowercase_fs_off.test b/mysql-test/t/lowercase_fs_off.test
index 7f7b573e7ee..883315994fe 100644
--- a/mysql-test/t/lowercase_fs_off.test
+++ b/mysql-test/t/lowercase_fs_off.test
@@ -3,6 +3,7 @@
# i.e. lower_case_filesystem=OFF
#
-- source include/have_case_sensitive_file_system.inc
+-- source include/not_embedded.inc
connect (master,localhost,root,,);
connection master;
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index 93fbc631680..1308b0b83a4 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -378,6 +378,31 @@ select * from t3;
check table t1, t2;
drop table t1, t2, t3;
+#
+# BUG#21617 - crash when selecting from merge table with inconsistent
+# indexes
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2),(1);
+CREATE TABLE t2(a INT, KEY(a)) ENGINE=MERGE UNION=(t1);
+--error 1030
+SELECT * FROM t2 WHERE a=2;
+DROP TABLE t1, t2;
+
+#
+# BUG#10974 - No error message if merge table based on union of innodb,
+# memory
+#
+CREATE TABLE t1(a INT) ENGINE=MEMORY;
+CREATE TABLE t2(a INT) ENGINE=MERGE UNION=(t1);
+--error 1168
+SELECT * FROM t2;
+DROP TABLE t1, t2;
+CREATE TABLE t2(a INT) ENGINE=MERGE UNION=(t3);
+--error 1168
+SELECT * FROM t2;
+DROP TABLE t2;
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test
index 5ec4edea8c7..d785002abdd 100644
--- a/mysql-test/t/myisam.test
+++ b/mysql-test/t/myisam.test
@@ -755,6 +755,97 @@ SELECT * FROM t1;
DROP TABLE t1;
#
+# Bug#8283 - OPTIMIZE TABLE causes data loss
+#
+SET @@myisam_repair_threads=2;
+SHOW VARIABLES LIKE 'myisam_repair%';
+#
+# Test OPTIMIZE. This creates a new data file.
+CREATE TABLE t1 (
+ `_id` int(11) NOT NULL default '0',
+ `url` text,
+ `email` text,
+ `description` text,
+ `loverlap` int(11) default NULL,
+ `roverlap` int(11) default NULL,
+ `lneighbor_id` int(11) default NULL,
+ `rneighbor_id` int(11) default NULL,
+ `length_` int(11) default NULL,
+ `sequence` mediumtext,
+ `name` text,
+ `_obj_class` text NOT NULL,
+ PRIMARY KEY (`_id`),
+ UNIQUE KEY `sequence_name_index` (`name`(50)),
+ KEY (`length_`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+#
+INSERT INTO t1 VALUES
+ (1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
+ (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
+ (3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
+ (4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
+ (5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
+ (6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
+ (7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
+ (8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
+ (9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
+#
+SELECT _id FROM t1;
+DELETE FROM t1 WHERE _id < 8;
+--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
+SHOW TABLE STATUS LIKE 't1';
+CHECK TABLE t1 EXTENDED;
+OPTIMIZE TABLE t1;
+CHECK TABLE t1 EXTENDED;
+--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
+SHOW TABLE STATUS LIKE 't1';
+SELECT _id FROM t1;
+DROP TABLE t1;
+#
+# Test REPAIR QUICK. This retains the old data file.
+CREATE TABLE t1 (
+ `_id` int(11) NOT NULL default '0',
+ `url` text,
+ `email` text,
+ `description` text,
+ `loverlap` int(11) default NULL,
+ `roverlap` int(11) default NULL,
+ `lneighbor_id` int(11) default NULL,
+ `rneighbor_id` int(11) default NULL,
+ `length_` int(11) default NULL,
+ `sequence` mediumtext,
+ `name` text,
+ `_obj_class` text NOT NULL,
+ PRIMARY KEY (`_id`),
+ UNIQUE KEY `sequence_name_index` (`name`(50)),
+ KEY (`length_`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+#
+INSERT INTO t1 VALUES
+ (1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
+ (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
+ (3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
+ (4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
+ (5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
+ (6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
+ (7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
+ (8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
+ (9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
+#
+SELECT _id FROM t1;
+DELETE FROM t1 WHERE _id < 8;
+--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
+SHOW TABLE STATUS LIKE 't1';
+CHECK TABLE t1 EXTENDED;
+REPAIR TABLE t1 QUICK;
+CHECK TABLE t1 EXTENDED;
+--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
+SHOW TABLE STATUS LIKE 't1';
+SELECT _id FROM t1;
+DROP TABLE t1;
+#
+SET @@myisam_repair_threads=1;
+SHOW VARIABLES LIKE 'myisam_repair%';
# Test varchar
#
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index 9e3eabf474b..f3296e6f706 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -63,6 +63,12 @@ drop table t1;
--exec $MYSQL -t test -e "create table t1 (col1 binary(4), col2 varchar(10), col3 int); insert into t1 values ('a', 'b', 123421),('a ', '0123456789', 4), ('abcd', '', 4); select concat('>',col1,'<'), col2, col3 from t1; drop table t1;" 2>&1
#
+# Bug#17939 Wrong table format when using UTF8 strings
+#
+--exec $MYSQL --default-character-set=utf8 --table -e "SELECT 'John Doe' as '__tañgè Ñãmé'" 2>&1
+--exec $MYSQL --default-character-set=utf8 --table -e "SELECT '__tañgè Ñãmé' as 'John Doe'" 2>&1
+
+#
# Bug#18265 -- mysql client: No longer right-justifies numeric columns
#
--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int, k char(25) charset utf8); insert into t1 (i) values (1); insert into t1 (k) values ('<----------------------->'); insert into t1 (k) values ('<-----'); insert into t1 (k) values ('Τη γλώσσα'); insert into t1 (k) values ('á›–áš´ áš·á›–á›'); select * from t1; DROP TABLE t1;"
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index 6a0b805f43b..c30af8c8f26 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -507,9 +507,21 @@ echo $where2;
let $where3=a long $where variable content;
echo $where3;
+let $where3=a long \\\$where variable content;
+echo $where3;
+
let $novar1= $novar2;
echo $novar1;
+let $cat=na;
+let $cat=ba$cat$cat;
+echo banana = $cat;
+
+# ba\$cat\$cat should have been sufficient.
+# ba\\\$cat\\\$cat -> ba\$cat\$cat -> ba$cat$cat -> banana
+# Magnus' upcoming patch will fix the missing second interpretation.
+let $cat=ba\\\$cat\\\$cat;
+echo Not a banana: $cat;
# Test illegal uses of let
diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test
index e34ac6a865c..4e5e7b72fc8 100644
--- a/mysql-test/t/olap.test
+++ b/mysql-test/t/olap.test
@@ -283,6 +283,15 @@ select a, max(b) from t1 group by a with rollup;
select distinct a, max(b) from t1 group by a with rollup;
drop table t1;
+#
+# Bug #20825: rollup puts non-equal values together
+#
+create table t1 (a varchar(22) not null , b int);
+insert into t1 values ("2006-07-01 21:30", 1), ("2006-07-01 23:30", 10);
+select left(a,10), a, sum(b) from t1 group by 1,2 with rollup;
+select left(a,10) x, a, sum(b) from t1 group by x,a with rollup;
+drop table t1;
+
# End of 4.1 tests
#
@@ -318,4 +327,3 @@ SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
-# End of 4.1 tests
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index cc239306558..f1e8e77d94e 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -1410,4 +1410,31 @@ DEALLOCATE PREPARE stmt;
DROP TABLE IF EXISTS t1, t2, t3;
+#
+# BUG#21081: SELECT inside stored procedure returns wrong results
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+CREATE TABLE t1 (i INT KEY);
+CREATE TABLE t2 (i INT);
+
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1);
+
+PREPARE stmt FROM "SELECT t2.i FROM t1 LEFT JOIN t2 ON t2.i = t1.i
+ WHERE t1.i = ?";
+
+SET @arg= 1;
+EXECUTE stmt USING @arg;
+SET @arg= 2;
+EXECUTE stmt USING @arg;
+SET @arg= 1;
+EXECUTE stmt USING @arg;
+
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1, t2;
+
+
--echo End of 5.0 tests.
diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test
index 86e4b6eed0a..dab2c629fdd 100644
--- a/mysql-test/t/rename.test
+++ b/mysql-test/t/rename.test
@@ -2,10 +2,6 @@
# Test of rename table
#
-# Test requires concurrent connections, which can't be tested on embedded
-# server
--- source include/not_embedded.inc
-
--disable_warnings
drop table if exists t0,t1,t2,t3,t4;
# Clear up from other tests (to ensure that SHOW TABLES below is right)
@@ -72,4 +68,17 @@ disconnect con2;
disconnect con1;
connection default;
+#
+# Bug#14959: ALTER TABLE isn't able to rename a view
+#
+create table t1(f1 int);
+create view v1 as select * from t1;
+alter table v1 rename to v2;
+--error 1146
+alter table v1 rename to v2;
+rename table v2 to v1;
+--error 1050
+rename table v2 to v1;
+drop view v1;
+drop table t1;
# End of 4.1 tests
diff --git a/mysql-test/t/repair.test b/mysql-test/t/repair.test
index 91a7442226a..f2e4c328218 100644
--- a/mysql-test/t/repair.test
+++ b/mysql-test/t/repair.test
@@ -45,4 +45,42 @@ SHOW INDEX FROM t1;
SET myisam_repair_threads=@@global.myisam_repair_threads;
DROP TABLE t1;
+#
+# BUG#22562 - REPAIR TABLE .. USE_FRM causes server crash on Windows and
+# server hangs on Linux
+#
+CREATE TABLE t1(a INT);
+USE mysql;
+REPAIR TABLE test.t1 USE_FRM;
+USE test;
+DROP TABLE t1;
+
+#
+# BUG#23175 - MYISAM crash/repair failed during repair
+#
+CREATE TABLE t1(a CHAR(255), KEY(a));
+SET myisam_sort_buffer_size=4096;
+INSERT INTO t1 VALUES
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
+('0'),('0'),('0'),('0'),('0'),('0'),('0');
+SET myisam_repair_threads=2;
+REPAIR TABLE t1;
+SET myisam_repair_threads=@@global.myisam_repair_threads;
+SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
+DROP TABLE t1;
+
# End of 4.1 tests
diff --git a/mysql-test/t/round.test b/mysql-test/t/round.test
new file mode 100644
index 00000000000..d018fa7e34e
--- /dev/null
+++ b/mysql-test/t/round.test
@@ -0,0 +1,145 @@
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (sint8 tinyint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('127.4');
+INSERT INTO t1 VALUES ('127.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-127.4');
+INSERT INTO t1 VALUES ('-127.5');
+INSERT INTO t1 VALUES ('-128.4');
+INSERT INTO t1 VALUES ('-128.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (uint8 tinyint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('127.4');
+INSERT INTO t1 VALUES ('127.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('255.4');
+INSERT INTO t1 VALUES ('255.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (sint16 smallint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('32767.4');
+INSERT INTO t1 VALUES ('32767.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-32767.4');
+INSERT INTO t1 VALUES ('-32767.5');
+INSERT INTO t1 VALUES ('-32768.4');
+INSERT INTO t1 VALUES ('-32768.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (uint16 smallint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('32767.4');
+INSERT INTO t1 VALUES ('32767.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('65535.4');
+INSERT INTO t1 VALUES ('65535.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (sint24 mediumint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('8388607.4');
+INSERT INTO t1 VALUES ('8388607.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-8388607.4');
+INSERT INTO t1 VALUES ('-8388607.5');
+INSERT INTO t1 VALUES ('-8388608.4');
+INSERT INTO t1 VALUES ('-8388608.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (uint24 mediumint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('8388607.4');
+INSERT INTO t1 VALUES ('8388607.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('16777215.4');
+INSERT INTO t1 VALUES ('16777215.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (sint64 bigint not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('9223372036854775807.4');
+INSERT INTO t1 VALUES ('9223372036854775807.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('-9223372036854775807.4');
+INSERT INTO t1 VALUES ('-9223372036854775807.5');
+INSERT INTO t1 VALUES ('-9223372036854775808.4');
+INSERT INTO t1 VALUES ('-9223372036854775808.5');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (uint64 bigint unsigned not null);
+INSERT INTO t1 VALUES ('0.1');
+INSERT INTO t1 VALUES ('0.5');
+INSERT INTO t1 VALUES ('9223372036854775807.4');
+INSERT INTO t1 VALUES ('9223372036854775807.5');
+INSERT INTO t1 VALUES ('-0.1');
+INSERT INTO t1 VALUES ('-0.5');
+INSERT INTO t1 VALUES ('18446744073709551615.4');
+INSERT INTO t1 VALUES ('18446744073709551615.5');
+INSERT INTO t1 VALUES ('1844674407370955161.0');
+INSERT INTO t1 VALUES ('1844674407370955161.1');
+INSERT INTO t1 VALUES ('1844674407370955161.2');
+INSERT INTO t1 VALUES ('1844674407370955161.3');
+INSERT INTO t1 VALUES ('1844674407370955161.4');
+INSERT INTO t1 VALUES ('1844674407370955161.5');
+INSERT INTO t1 VALUES ('1844674407370955161.0e1');
+INSERT INTO t1 VALUES ('1844674407370955161.1e1');
+INSERT INTO t1 VALUES ('1844674407370955161.2e1');
+INSERT INTO t1 VALUES ('1844674407370955161.3e1');
+INSERT INTO t1 VALUES ('1844674407370955161.4e1');
+INSERT INTO t1 VALUES ('1844674407370955161.5e1');
+INSERT INTO t1 VALUES ('18446744073709551610e-1');
+INSERT INTO t1 VALUES ('18446744073709551611e-1');
+INSERT INTO t1 VALUES ('18446744073709551612e-1');
+INSERT INTO t1 VALUES ('18446744073709551613e-1');
+INSERT INTO t1 VALUES ('18446744073709551614e-1');
+INSERT INTO t1 VALUES ('18446744073709551615e-1');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (str varchar(128), sint64 bigint not null default 0);
+INSERT INTO t1 (str) VALUES ('1.5');
+INSERT INTO t1 (str) VALUES ('1.00005e4');
+INSERT INTO t1 (str) VALUES ('1.0005e3');
+INSERT INTO t1 (str) VALUES ('1.005e2');
+INSERT INTO t1 (str) VALUES ('1.05e1');
+INSERT INTO t1 (str) VALUES ('1.5e0');
+INSERT INTO t1 (str) VALUES ('100005e-1');
+INSERT INTO t1 (str) VALUES ('100050e-2');
+INSERT INTO t1 (str) VALUES ('100500e-3');
+INSERT INTO t1 (str) VALUES ('105000e-4');
+INSERT INTO t1 (str) VALUES ('150000e-5');
+UPDATE t1 SET sint64=str;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
diff --git a/mysql-test/t/rpl_insert_id.test b/mysql-test/t/rpl_insert_id.test
index 3c46a5b4ca1..331a913256c 100644
--- a/mysql-test/t/rpl_insert_id.test
+++ b/mysql-test/t/rpl_insert_id.test
@@ -244,6 +244,135 @@ select * from t1 order by n;
connection master;
drop table t1;
+
+#
+# BUG#20339: stored procedure using LAST_INSERT_ID() does not
+# replicate statement-based
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+# Reset result of LAST_INSERT_ID().
+SELECT LAST_INSERT_ID(0);
+
+CREATE TABLE t1 (
+ id INT NOT NULL DEFAULT 0,
+ last_id INT,
+ PRIMARY KEY (id)
+);
+
+CREATE TABLE t2 (
+ id INT NOT NULL AUTO_INCREMENT,
+ last_id INT,
+ PRIMARY KEY (id)
+);
+
+delimiter |;
+CREATE PROCEDURE p1()
+BEGIN
+ INSERT INTO t2 (last_id) VALUES (LAST_INSERT_ID());
+ INSERT INTO t1 (last_id) VALUES (LAST_INSERT_ID());
+END|
+delimiter ;|
+
+CALL p1();
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+sync_slave_with_master;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection master;
+
+DROP PROCEDURE p1;
+DROP TABLE t1, t2;
+
+
+#
+# BUG#21726: Incorrect result with multiple invocations of
+# LAST_INSERT_ID
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP FUNCTION IF EXISTS f2;
+DROP FUNCTION IF EXISTS f3;
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+CREATE TABLE t1 (
+ i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ j INT DEFAULT 0
+);
+CREATE TABLE t2 (i INT);
+
+delimiter |;
+CREATE PROCEDURE p1()
+BEGIN
+ INSERT INTO t1 (i) VALUES (NULL);
+ INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+ INSERT INTO t1 (i) VALUES (NULL), (NULL);
+ INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+END |
+
+CREATE FUNCTION f1() RETURNS INT MODIFIES SQL DATA
+BEGIN
+ INSERT INTO t1 (i) VALUES (NULL);
+ INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+ INSERT INTO t1 (i) VALUES (NULL), (NULL);
+ INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+ RETURN 0;
+END |
+
+CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC
+ RETURN LAST_INSERT_ID() |
+
+CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA
+BEGIN
+ INSERT INTO t2 (i) VALUES (LAST_INSERT_ID());
+ RETURN 0;
+END |
+delimiter ;|
+
+INSERT INTO t1 VALUES (NULL, -1);
+CALL p1();
+SELECT f1();
+INSERT INTO t1 VALUES (NULL, f2()), (NULL, LAST_INSERT_ID()),
+ (NULL, LAST_INSERT_ID()), (NULL, f2()), (NULL, f2());
+INSERT INTO t1 VALUES (NULL, f2());
+INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)),
+ (NULL, @@LAST_INSERT_ID);
+# Test replication of substitution "IS NULL" -> "= LAST_INSERT_ID".
+INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID());
+UPDATE t1 SET j= -1 WHERE i IS NULL;
+
+# Test statement-based replication of function calls.
+INSERT INTO t1 (i) VALUES (NULL);
+
+connection master1;
+INSERT INTO t1 (i) VALUES (NULL);
+
+connection master;
+SELECT f3();
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+sync_slave_with_master;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection master;
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
+DROP FUNCTION f2;
+DROP FUNCTION f3;
+DROP TABLE t1, t2;
+
+
sync_slave_with_master;
--echo
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 36b3749b4d7..0f096d97d25 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -2996,5 +2996,99 @@ SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
+DROP TABLE t1,t2,t3;
+
+#
+# Bug#20503: Server crash due to the ORDER clause isn't taken into account
+# while space allocation
+#
+create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
+c7 int, c8 int, c9 int, fulltext key (`c1`));
+select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
+ from t1 where c9=1 order by c2, c2;
+drop table t1;
+
+#
+# Bug #22735: no equality propagation for BETWEEN and IN with STRING arguments
+#
+
+CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
+CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
+
+INSERT INTO t1 VALUES
+ ('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'),
+ ('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
+INSERT INTO t2 VALUES
+ ('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
+ ('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
+ ('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
+ ('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
+
+EXPLAIN SELECT t2.*
+ FROM t1 JOIN t2 ON t2.fk=t1.pk
+ WHERE t2.fk < 'c' AND t2.pk=t1.fk;
+EXPLAIN SELECT t2.*
+ FROM t1 JOIN t2 ON t2.fk=t1.pk
+ WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
+EXPLAIN SELECT t2.*
+ FROM t1 JOIN t2 ON t2.fk=t1.pk
+ WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
+
+DROP TABLE t1,t2;
+
+#
+# Bug #22367: Optimizer uses ref join type instead of eq_ref for simple
+# join on strings
+#
+CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
+CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
+ PRIMARY KEY (a), UNIQUE KEY (b));
+INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
+INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
+
+EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
+
+DROP TABLE t1,t2;
+
+#
+# Bug #19579: predicates that become sargable after reading const tables
+# are not taken into account by optimizer
+#
+
+CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
+CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
+CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
+
+INSERT INTO t1 VALUES
+ (1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+ (6,63,67), (5,55,58), (3,38,39), (8,81,89);
+INSERT INTO t2 VALUES
+ (21,210), (41,410), (82,820), (83,830), (84,840),
+ (65,650), (51,510), (37,370), (94,940), (76,760),
+ (22,220), (33,330), (40,400), (95,950), (38,380),
+ (67,670), (88,880), (57,570), (96,960), (97,970);
+INSERT INTO t3 VALUES
+ (210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
+ (440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
+ (230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
+ (450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
+
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+ WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
+ t3.a=t2.a AND t3.c IN ('bb','ee');
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3
+ WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
+ t3.a=t2.a AND t3.c IN ('bb','ee') ;
+
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+ WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
+ t3.c IN ('bb','ee');
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3
+ WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
+ t3.c IN ('bb','ee');
DROP TABLE t1,t2,t3;
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index 65a81545c87..d162f250fd7 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -1,5 +1,4 @@
-# Requires use of multiple simultaneous connections, not supported with
-# embedded server testing
+# Uses GRANT commands that usually disabled in embedded server
-- source include/not_embedded.inc
#
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 4707a9b0d30..87d19baf888 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -1,13 +1,9 @@
#
# Basic stored PROCEDURE tests
#
-# Please keep this file free of --error cases and other
-# things that will not run in a single debugged mysqld
-# process (e.g. master-slave things).
-#
# Test cases for bugs are added at the end. See template there.
#
-# Tests that require --error go into sp-error.test
+# Some tests that require --error go into sp-error.test
# Tests that require inndb go into sp_trans.test
# Tests that check privilege and security issues go to sp-security.test.
# Tests that require multiple connections, except security/privilege tests,
@@ -6322,6 +6318,41 @@ create procedure bug21416() show create procedure bug21416|
call bug21416()|
drop procedure bug21416|
+
+#
+# BUG#21414: SP: Procedure undroppable, to some extent
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS bug21414|
+--enable_warnings
+
+CREATE PROCEDURE bug21414() SELECT 1|
+
+FLUSH TABLES WITH READ LOCK|
+
+--error ER_CANT_UPDATE_WITH_READLOCK
+DROP PROCEDURE bug21414|
+
+UNLOCK TABLES|
+
+--echo The following should succeed.
+DROP PROCEDURE bug21414|
+
+
+#
+# BUG#21311: Possible stack overrun if SP has non-latin1 name
+#
+set names utf8|
+--disable_warnings
+drop database if exists това_е_дълго_име_за_база_данни_нали|
+--enable_warnings
+create database това_е_дълго_име_за_база_данни_нали|
+INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','')|
+--error ER_SP_PROC_TABLE_CORRUPT
+call това_е_дълго_име_за_база_данни_нали.това_е_процедура_Ñ_доÑта_дълго_име_нали_и_още_по_дълго()|
+drop database това_е_дълго_име_за_база_данни_нали|
+
+
#
# BUG#21493: Crash on the second call of a procedure containing
# a select statement that uses an IN aggregating subquery
@@ -6367,9 +6398,9 @@ INSERT INTO t4(Member_ID, Action, Action_Date, Track) VALUES
('666666', 'Enrolled', '2006-05-12', 'CHF' ),
('666666', 'Disenrolled', '2006-06-01', 'CAD' )|
-#--disable_warnings
+--disable_warnings
DROP FUNCTION IF EXISTS bug21493|
-#--enable_warnings
+--enable_warnings
CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45)
BEGIN
@@ -6389,6 +6420,9 @@ SELECT bug21493(Member_ID) FROM t3|
DROP FUNCTION bug21493|
DROP TABLE t3,t4|
+--echo End of 5.0 tests
+
+
#
# BUG#NNNN: New bug synopsis
#
diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test
index 1a71425d2a7..9d5adf57f81 100644
--- a/mysql-test/t/status.test
+++ b/mysql-test/t/status.test
@@ -1,10 +1,3 @@
-# This test doesn't work with the embedded version as this code
-# assumes that one query is running while we are doing queries on
-# a second connection.
-# This would work if mysqltest run would be threaded and handle each
-# connection in a separate thread.
-#
---source include/not_embedded.inc
# PS causes different statistics
--disable_ps_protocol
diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test
index 6f22b81172d..6ebbb53ed8e 100644
--- a/mysql-test/t/strict.test
+++ b/mysql-test/t/strict.test
@@ -649,9 +649,9 @@ UPDATE t1 SET col2 =col2 + 50 WHERE col2 > 0;
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
---error 1264
+--error 1366
INSERT INTO t1 (col1) VALUES ('');
---error 1264
+--error 1366
INSERT INTO t1 (col1) VALUES ('a59b');
--error 1265
INSERT INTO t1 (col1) VALUES ('1a');
@@ -710,9 +710,9 @@ INSERT INTO t1 (col2) VALUES(18446744073709551616.0);
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
---error 1264
+--error 1366
INSERT INTO t1 (col1) VALUES ('');
---error 1264
+--error 1366
INSERT INTO t1 (col1) VALUES ('a59b');
--error 1265
INSERT INTO t1 (col1) VALUES ('1a');
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 7811301a9bc..051a64b9f9a 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1955,6 +1955,23 @@ SELECT field1, field2
DROP TABLE t1, t2;
+#
+# Bug #23478: not top-level IN subquery returning a non-empty result set
+# with possible NULL values by index access from the outer query
+#
+
+CREATE TABLE t1(a int, INDEX (a));
+INSERT INTO t1 VALUES (1), (3), (5), (7);
+INSERT INTO t1 VALUES (NULL);
+
+CREATE TABLE t2(a int);
+INSERT INTO t2 VALUES (1),(2),(3);
+
+EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
+SELECT a, a IN (SELECT a FROM t1) FROM t2;
+
+DROP TABLE t1,t2;
+
# End of 4.1 tests
#
@@ -2371,6 +2388,32 @@ explain select * from t1 where not exists
DROP TABLE t1;
#
+# Bug#21798: memory leak during query execution with subquery in column
+# list using a function
+#
+CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
+insert into t1 (a) values (FLOOR(rand() * 100));
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+
+SELECT a,
+ (SELECT REPEAT(' ',250) FROM t1 i1
+ WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
+FROM t1 ORDER BY a LIMIT 5;
+DROP TABLE t1;
+
+#
# Bug #21540: Subqueries with no from and aggregate functions return
# wrong results
CREATE TABLE t1 (a INT, b INT);
@@ -2400,3 +2443,40 @@ SELECT (
FROM t1 t2
GROUP BY t2.a;
DROP TABLE t1,t2;
+
+#
+# Bug #21727: Correlated subquery that requires filesort:
+# slow with big sort_buffer_size
+#
+
+CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
+CREATE TABLE t2 (x int auto_increment, y int, z int,
+ PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
+
+disable_query_log;
+let $1=3000;
+while ($1)
+{
+ eval INSERT INTO t1(a) VALUES(RAND()*1000);
+ eval SELECT MAX(b) FROM t1 INTO @id;
+ let $2=10;
+ while ($2)
+ {
+ eval INSERT INTO t2(y,z) VALUES(@id,RAND()*1000);
+ dec $2;
+ }
+ dec $1;
+}
+enable_query_log;
+
+SET SESSION sort_buffer_size = 32 * 1024;
+SELECT SQL_NO_CACHE COUNT(*)
+ FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
+ FROM t1) t;
+
+SET SESSION sort_buffer_size = 8 * 1024 * 1024;
+SELECT SQL_NO_CACHE COUNT(*)
+ FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
+ FROM t1) t;
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/subselect3.test b/mysql-test/t/subselect3.test
new file mode 100644
index 00000000000..f7fbafdd17f
--- /dev/null
+++ b/mysql-test/t/subselect3.test
@@ -0,0 +1,137 @@
+--disable_warnings
+drop table if exists t0, t1, t2, t3, t4;
+--enable_warnings
+
+#
+# 1. Subquery with GROUP/HAVING
+#
+create table t1 (oref int, grp int, ie int) ;
+insert into t1 (oref, grp, ie) values
+ (1, 1, 1),
+ (1, 1, 1),
+ (1, 2, NULL),
+
+ (2, 1, 3),
+
+ (3, 1, 4),
+ (3, 2, NULL);
+
+# Ok, for
+# select max(ie) from t1 where oref=PARAM group by grp
+# we'll have:
+# 1 -> (1, NULL) matching + NULL
+# 2 -> (3) non-matching
+# 3 -> (3, NULL) non-matching + NULL
+# 4 -> () nothing.
+
+create table t2 (oref int, a int);
+insert into t2 values
+ (1, 1),
+ (2, 2),
+ (3, 3),
+ (4, NULL),
+ (2, NULL);
+
+# true, false, null, false, null
+select a, oref, a in (select max(ie)
+ from t1 where oref=t2.oref group by grp) from t2;
+
+# This must have a trigcond
+explain extended
+select a, oref, a in (select max(ie)
+ from t1 where oref=t2.oref group by grp) from t2;
+
+# This must not have a trigcond:
+explain extended
+select a, oref from t2
+where a in (select max(ie) from t1 where oref=t2.oref group by grp);
+
+
+# Non-correlated subquery, 2 NULL evaluations
+create table t3 (a int);
+insert into t3 values (NULL), (NULL);
+flush status;
+select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
+show status like 'Handler_read_rnd_next';
+select ' ^ This must show 11' Z;
+
+# This must show trigcond:
+explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
+
+drop table t1, t2, t3;
+
+#
+# 2. Subquery handled with 'index_subquery':
+#
+create table t1 (a int, oref int, key(a));
+insert into t1 values
+ (1, 1),
+ (1, NULL),
+ (2, 3),
+ (2, NULL),
+ (3, NULL);
+
+create table t2 (a int, oref int);
+insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
+
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+
+# The next explain shows "using index" but that is just incorrect display
+# (there is a bug filed about this).
+explain extended
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+
+flush status;
+select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
+# This will only show access to t2:
+show status like '%Handler_read_rnd_next';
+
+# Check that repeated NULL-scans are not cached (subq. is not correlated):
+delete from t2;
+insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
+
+flush status;
+select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
+show status like '%Handler_read%';
+select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
+
+drop table t1, t2;
+
+#
+# 3. Subquery handled with 'unique_index_subquery':
+#
+create table t1 (a int, b int, primary key (a));
+insert into t1 values (1,1), (3,1),(100,1);
+
+create table t2 (a int, b int);
+insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
+
+select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
+
+drop table t1, t2;
+
+#
+# 4. Subquery that is a join, with ref access
+#
+create table t1 (a int, b int, key(a));
+insert into t1 values
+ (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+
+create table t2 like t1;
+insert into t2 select * from t1;
+update t2 set b=1;
+
+create table t3 (a int, oref int);
+insert into t3 values (1, 1), (NULL,1), (NULL,0);
+select a, oref,
+ t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
+from t3;
+
+# This must have trigcond in WHERE and HAVING:
+explain extended
+select a, oref,
+ t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
+from t3;
+
+drop table t1, t2, t3;
+
diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test
index 3920b305b78..8cb9e34ca08 100644
--- a/mysql-test/t/temp_table.test
+++ b/mysql-test/t/temp_table.test
@@ -116,4 +116,50 @@ insert into t2 values (NULL, 'foo'), (NULL, 'bar');
select d, c from t1 left join t2 on b = c where a = 3 order by d;
drop table t1, t2;
-# End of 4.1 tests
+
+#
+# BUG#21096: locking issue ; temporary table conflicts.
+#
+# The problem was that on DROP TEMPORARY table name lock was acquired,
+# which should not be done.
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (i INT);
+
+LOCK TABLE t1 WRITE;
+
+connect (conn1, localhost, root,,);
+
+CREATE TEMPORARY TABLE t1 (i INT);
+
+--echo The following command should not block
+DROP TEMPORARY TABLE t1;
+
+disconnect conn1;
+connection default;
+
+DROP TABLE t1;
+
+#
+# Check that it's not possible to drop a base table with
+# DROP TEMPORARY statement.
+#
+CREATE TABLE t1 (i INT);
+CREATE TEMPORARY TABLE t2 (i INT);
+
+--error 1051
+DROP TEMPORARY TABLE t2, t1;
+
+# Table t2 should have been dropped.
+--error 1146
+SELECT * FROM t2;
+# But table t1 should still be there.
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+
+--echo End of 4.1 tests.
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index 2a145e1eeaa..6bd812d473e 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -1421,4 +1421,23 @@ DROP TABLE t1;
DROP TABLE t2;
+#
+# Bug#20670 "UPDATE using key and invoking trigger that modifies
+# this key does not stop"
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (i int, j int key);
+insert into t1 values (1,1), (2,2), (3,3);
+create trigger t1_bu before update on t1 for each row
+ set new.j = new.j + 10;
+# This should not work indefinitely and should cause
+# expected result
+update t1 set i= i+ 10 where j > 2;
+select * from t1;
+drop table t1;
+
+
--echo End of 5.0 tests
diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test
index 998f8f18fbe..d46ba667665 100644
--- a/mysql-test/t/type_bit.test
+++ b/mysql-test/t/type_bit.test
@@ -252,5 +252,13 @@ select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583;
select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583;
drop table bug15583;
+#
+# Bug #22271: data casting may affect data stored in the next column(s?)
+#
+
+create table t1(a bit(1), b smallint unsigned);
+insert into t1 (b, a) values ('2', '1');
+select hex(a), b from t1;
+drop table t1;
--echo End of 5.0 tests
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index cdf73bf6c89..3ad6bdc53e4 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -125,3 +125,13 @@ PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="2006060
EXECUTE s;
DROP PREPARE s;
DROP TABLE t1;
+
+
+#
+# Bug 19491 (CAST DATE AS DECIMAL returns incorrect result
+#
+SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));
+SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));
+SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));
+SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));
+
diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test
index 441d750004e..4fdb0c8458f 100644
--- a/mysql-test/t/type_decimal.test
+++ b/mysql-test/t/type_decimal.test
@@ -385,3 +385,12 @@ insert into t1 values (40);
flush tables;
select f1 from t1 where f1 in (select f1 from t1);
drop table t1;
+
+#
+# Bug#22183: Unhandled NULL caused server crash
+#
+create table t1 as
+ select from_days(s) as date,t
+ from (select 1 as s,'t' as t union select null, null ) as sub1;
+select group_concat(t) from t1 group by week(date)/10;
+drop table t1;
diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
index 0d479f312cd..68f5664c36d 100644
--- a/mysql-test/t/type_enum.test
+++ b/mysql-test/t/type_enum.test
@@ -127,4 +127,13 @@ create table t1 (a set('x','y') default 'x');
alter table t1 alter a set default 'z';
drop table t1;
+
+#
+# Bug#20922 mysql removes a name of first column in a table
+#
+create table t1 (f1 int);
+alter table t1 add f2 enum(0xFFFF);
+show create table t1;
+drop table t1;
+
# End of 4.1 tests
diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test
index 5bfd744e4a8..965826629bd 100644
--- a/mysql-test/t/type_float.test
+++ b/mysql-test/t/type_float.test
@@ -178,7 +178,16 @@ show warnings;
desc t3;
drop table t1,t2,t3;
-# End of 4.1 tests
+#
+# Bug #22129: A small double precision number becomes zero
+#
+# check if underflows are detected correctly
+select 1e-308, 1.00000001e-300, 100000000e-300;
+
+# check if overflows are detected correctly
+select 10e307;
+
+--echo End of 4.1 tests
#
# bug #12694 (float(m,d) specifications)
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index de1ebd74d17..12da41dcfd5 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -1108,3 +1108,11 @@ insert into t1 values (1,1), (1,2), (2,3), (2,4);
select i, count(distinct j) from t1 group by i;
select i+0.0 as i2, count(distinct j) from t1 group by i2;
drop table t1;
+
+
+create table t1(f1 decimal(20,6));
+insert into t1 values (CAST('10:11:12' AS date) + interval 14 microsecond);
+insert into t1 values (CAST('10:11:12' AS time));
+select * from t1;
+drop table t1;
+
diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test
index 96e559f5c05..37358a292be 100644
--- a/mysql-test/t/udf.test
+++ b/mysql-test/t/udf.test
@@ -127,6 +127,50 @@ create table t1(f1 int);
insert into t1 values(1),(2);
explain select myfunc_int(f1) from t1 order by 1;
drop table t1;
+
+#
+# Bug #21809: Error 1356 while selecting from view with grouping though
+# underlying select OK.
+#
+CREATE TABLE t1(a INT, b INT); INSERT INTO t1 values (1,1),(2,2);
+
+DELIMITER ||;
+CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
+BEGIN
+ RETURN a;
+END
+||
+DELIMITER ;||
+
+CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
+
+SELECT myfunc_int(a AS attr_name) FROM t1;
+EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
+EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
+SELECT a,c FROM v1;
+
+--error ER_PARSE_ERROR
+SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
+--error ER_PARSE_ERROR
+SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
+--error ER_PARSE_ERROR
+SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
+
+SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
+SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
+
+EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
+EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
+EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
+EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
+SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
+SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
+SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
+SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION fn;
+
--echo End of 5.0 tests.
#
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index b631d2032c4..21080dd00cc 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2879,4 +2879,19 @@ SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1, t2;
+
+#
+# Bug #16813 (WITH CHECK OPTION doesn't work with UPDATE)
+#
+CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
+CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
+INSERT INTO v1 (val) VALUES (2);
+INSERT INTO v1 (val) VALUES (4);
+-- error 1369
+INSERT INTO v1 (val) VALUES (6);
+-- error 1369
+UPDATE v1 SET val=6 WHERE id=2;
+DROP VIEW v1;
+DROP TABLE t1;
+
--echo End of 5.0 tests.
diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test
index 4768c7574e5..5e9d25aa09b 100644
--- a/mysql-test/t/warnings.test
+++ b/mysql-test/t/warnings.test
@@ -156,4 +156,60 @@ select * from t1 limit 1, 0;
select * from t1 limit 0, 0;
drop table t1;
-# End of 4.1 tests
+--echo End of 4.1 tests
+
+#
+# Bug#20778: strange characters in warning message 1366 when called in SP
+#
+
+let $engine_type= innodb;
+
+CREATE TABLE t1( f1 CHAR(20) );
+CREATE TABLE t2( f1 CHAR(20), f2 CHAR(25) );
+CREATE TABLE t3( f1 CHAR(20), f2 CHAR(25), f3 DATE );
+
+INSERT INTO t1 VALUES ( 'a`' );
+INSERT INTO t2 VALUES ( 'a`', 'a`' );
+INSERT INTO t3 VALUES ( 'a`', 'a`', '1000-01-1' );
+
+DROP PROCEDURE IF EXISTS sp1;
+DROP PROCEDURE IF EXISTS sp2;
+DROP PROCEDURE IF EXISTS sp3;
+delimiter //;
+CREATE PROCEDURE sp1()
+BEGIN
+ DECLARE x NUMERIC ZEROFILL;
+ SELECT f1 INTO x FROM t1 LIMIT 1;
+END//
+CREATE PROCEDURE sp2()
+BEGIN
+ DECLARE x NUMERIC ZEROFILL;
+ SELECT f1 INTO x FROM t2 LIMIT 1;
+END//
+CREATE PROCEDURE sp3()
+BEGIN
+ DECLARE x NUMERIC ZEROFILL;
+ SELECT f1 INTO x FROM t3 LIMIT 1;
+END//
+delimiter ;//
+CALL sp1();
+CALL sp2();
+CALL sp3();
+
+DROP PROCEDURE IF EXISTS sp1;
+delimiter //;
+CREATE PROCEDURE sp1()
+BEGIN
+declare x numeric unsigned zerofill;
+SELECT f1 into x from t2 limit 1;
+END//
+delimiter ;//
+CALL sp1();
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP PROCEDURE sp1;
+DROP PROCEDURE sp2;
+DROP PROCEDURE sp3;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp
index 24426727968..f7eb9baa4c7 100644
--- a/mysql-test/valgrind.supp
+++ b/mysql-test/valgrind.supp
@@ -15,6 +15,14 @@
}
{
+ pthread allocate_tls memory loss
+ Memcheck:Leak
+ fun:calloc
+ fun:_dl_allocate_tls
+ fun:pthread_create*
+}
+
+{
pthread allocate_dtv memory loss
Memcheck:Leak
fun:calloc
@@ -115,6 +123,24 @@
}
{
+ libz longest_match 3
+ Memcheck:Cond
+ fun:longest_match
+ fun:deflate_slow
+ fun:deflate
+ fun:gzclose
+}
+
+{
+ libz longest_match 4
+ Memcheck:Cond
+ fun:longest_match
+ fun:deflate_slow
+ fun:deflate
+ fun:gzflush
+}
+
+{
libz deflate
Memcheck:Cond
obj:*/libz.so.*
@@ -133,6 +159,7 @@
fun:gzflush
}
+
#
# Warning from my_thread_init becasue mysqld dies before kill thread exists
#
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index cd2a140182e..b1cf940d70d 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -70,7 +70,6 @@ static void my_aiowait(my_aio_result *result);
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1))
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1))
-
/*
Setup internal pointers inside IO_CACHE
@@ -502,65 +501,366 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count)
DBUG_RETURN(0);
}
+
#ifdef THREAD
-/* Prepare IO_CACHE for shared use */
-void init_io_cache_share(IO_CACHE *info, IO_CACHE_SHARE *s, uint num_threads)
+/*
+ Prepare IO_CACHE for shared use.
+
+ SYNOPSIS
+ init_io_cache_share()
+ read_cache A read cache. This will be copied for
+ every thread after setup.
+ cshare The share.
+ write_cache If non-NULL a write cache that is to be
+ synchronized with the read caches.
+ num_threads Number of threads sharing the cache
+ including the write thread if any.
+
+ DESCRIPTION
+
+ The shared cache is used so: One IO_CACHE is initialized with
+ init_io_cache(). This includes the allocation of a buffer. Then a
+ share is allocated and init_io_cache_share() is called with the io
+ cache and the share. Then the io cache is copied for each thread. So
+ every thread has its own copy of IO_CACHE. But the allocated buffer
+ is shared because cache->buffer is the same for all caches.
+
+ One thread reads data from the file into the buffer. All threads
+ read from the buffer, but every thread maintains its own set of
+ pointers into the buffer. When all threads have used up the buffer
+ contents, one of the threads reads the next block of data into the
+ buffer. To accomplish this, each thread enters the cache lock before
+ accessing the buffer. They wait in lock_io_cache() until all threads
+ joined the lock. The last thread entering the lock is in charge of
+ reading from file to buffer. It wakes all threads when done.
+
+ Synchronizing a write cache to the read caches works so: Whenever
+ the write buffer needs a flush, the write thread enters the lock and
+ waits for all other threads to enter the lock too. They do this when
+ they have used up the read buffer. When all threads are in the lock,
+ the write thread copies the write buffer to the read buffer and
+ wakes all threads.
+
+ share->running_threads is the number of threads not being in the
+ cache lock. When entering lock_io_cache() the number is decreased.
+ When the thread that fills the buffer enters unlock_io_cache() the
+ number is reset to the number of threads. The condition
+ running_threads == 0 means that all threads are in the lock. Bumping
+ up the number to the full count is non-intuitive. But increasing the
+ number by one for each thread that leaves the lock could lead to a
+ solo run of one thread. The last thread to join a lock reads from
+ file to buffer, wakes the other threads, processes the data in the
+ cache and enters the lock again. If no other thread left the lock
+ meanwhile, it would think it's the last one again and read the next
+ block...
+
+ The share has copies of 'error', 'buffer', 'read_end', and
+ 'pos_in_file' from the thread that filled the buffer. We may not be
+ able to access this information directly from its cache because the
+ thread may be removed from the share before the variables could be
+ copied by all other threads. Or, if a write buffer is synchronized,
+ it would change its 'pos_in_file' after waking the other threads,
+ possibly before they could copy its value.
+
+ However, the 'buffer' variable in the share is for a synchronized
+ write cache. It needs to know where to put the data. Otherwise it
+ would need access to the read cache of one of the threads that is
+ not yet removed from the share.
+
+ RETURN
+ void
+*/
+
+void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
+ IO_CACHE *write_cache, uint num_threads)
{
- DBUG_ASSERT(info->type == READ_CACHE);
- pthread_mutex_init(&s->mutex, MY_MUTEX_INIT_FAST);
- pthread_cond_init (&s->cond, 0);
- s->total=s->count=num_threads-1;
- s->active=0;
- info->share=s;
- info->read_function=_my_b_read_r;
- info->current_pos= info->current_end= 0;
+ DBUG_ENTER("init_io_cache_share");
+ DBUG_PRINT("io_cache_share", ("read_cache: 0x%lx share: 0x%lx "
+ "write_cache: 0x%lx threads: %u",
+ read_cache, cshare, write_cache, num_threads));
+
+ DBUG_ASSERT(num_threads > 1);
+ DBUG_ASSERT(read_cache->type == READ_CACHE);
+ DBUG_ASSERT(!write_cache || (write_cache->type == WRITE_CACHE));
+
+ pthread_mutex_init(&cshare->mutex, MY_MUTEX_INIT_FAST);
+ pthread_cond_init(&cshare->cond, 0);
+ pthread_cond_init(&cshare->cond_writer, 0);
+
+ cshare->running_threads= num_threads;
+ cshare->total_threads= num_threads;
+ cshare->error= 0; /* Initialize. */
+ cshare->buffer= read_cache->buffer;
+ cshare->read_end= NULL; /* See function comment of lock_io_cache(). */
+ cshare->pos_in_file= 0; /* See function comment of lock_io_cache(). */
+ cshare->source_cache= write_cache; /* Can be NULL. */
+
+ read_cache->share= cshare;
+ read_cache->read_function= _my_b_read_r;
+ read_cache->current_pos= NULL;
+ read_cache->current_end= NULL;
+
+ if (write_cache)
+ write_cache->share= cshare;
+
+ DBUG_VOID_RETURN;
}
+
/*
- Remove a thread from shared access to IO_CACHE
- Every thread should do that on exit for not
- to deadlock other threads
+ Remove a thread from shared access to IO_CACHE.
+
+ SYNOPSIS
+ remove_io_thread()
+ cache The IO_CACHE to be removed from the share.
+
+ NOTE
+
+ Every thread must do that on exit for not to deadlock other threads.
+
+ The last thread destroys the pthread resources.
+
+ A writer flushes its cache first.
+
+ RETURN
+ void
*/
-void remove_io_thread(IO_CACHE *info)
+
+void remove_io_thread(IO_CACHE *cache)
{
- IO_CACHE_SHARE *s=info->share;
+ IO_CACHE_SHARE *cshare= cache->share;
+ uint total;
+ DBUG_ENTER("remove_io_thread");
+
+ /* If the writer goes, it needs to flush the write cache. */
+ if (cache == cshare->source_cache)
+ flush_io_cache(cache);
- pthread_mutex_lock(&s->mutex);
- s->total--;
- if (! s->count--)
- pthread_cond_signal(&s->cond);
- pthread_mutex_unlock(&s->mutex);
+ pthread_mutex_lock(&cshare->mutex);
+ DBUG_PRINT("io_cache_share", ("%s: 0x%lx",
+ (cache == cshare->source_cache) ?
+ "writer" : "reader", cache));
+
+ /* Remove from share. */
+ total= --cshare->total_threads;
+ DBUG_PRINT("io_cache_share", ("remaining threads: %u", total));
+
+ /* Detach from share. */
+ cache->share= NULL;
+
+ /* If the writer goes, let the readers know. */
+ if (cache == cshare->source_cache)
+ {
+ DBUG_PRINT("io_cache_share", ("writer leaves"));
+ cshare->source_cache= NULL;
+ }
+
+ /* If all threads are waiting for me to join the lock, wake them. */
+ if (!--cshare->running_threads)
+ {
+ DBUG_PRINT("io_cache_share", ("the last running thread leaves, wake all"));
+ pthread_cond_signal(&cshare->cond_writer);
+ pthread_cond_broadcast(&cshare->cond);
+ }
+
+ pthread_mutex_unlock(&cshare->mutex);
+
+ if (!total)
+ {
+ DBUG_PRINT("io_cache_share", ("last thread removed, destroy share"));
+ pthread_cond_destroy (&cshare->cond_writer);
+ pthread_cond_destroy (&cshare->cond);
+ pthread_mutex_destroy(&cshare->mutex);
+ }
+
+ DBUG_VOID_RETURN;
}
-static int lock_io_cache(IO_CACHE *info, my_off_t pos)
-{
- int total;
- IO_CACHE_SHARE *s=info->share;
- pthread_mutex_lock(&s->mutex);
- if (!s->count)
+/*
+ Lock IO cache and wait for all other threads to join.
+
+ SYNOPSIS
+ lock_io_cache()
+ cache The cache of the thread entering the lock.
+ pos File position of the block to read.
+ Unused for the write thread.
+
+ DESCRIPTION
+
+ Wait for all threads to finish with the current buffer. We want
+ all threads to proceed in concert. The last thread to join
+ lock_io_cache() will read the block from file and all threads start
+ to use it. Then they will join again for reading the next block.
+
+ The waiting threads detect a fresh buffer by comparing
+ cshare->pos_in_file with the position they want to process next.
+ Since the first block may start at position 0, we take
+ cshare->read_end as an additional condition. This variable is
+ initialized to NULL and will be set after a block of data is written
+ to the buffer.
+
+ RETURN
+ 1 OK, lock in place, go ahead and read.
+ 0 OK, unlocked, another thread did the read.
+*/
+
+static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
+{
+ IO_CACHE_SHARE *cshare= cache->share;
+ DBUG_ENTER("lock_io_cache");
+
+ /* Enter the lock. */
+ pthread_mutex_lock(&cshare->mutex);
+ cshare->running_threads--;
+ DBUG_PRINT("io_cache_share", ("%s: 0x%lx pos: %lu running: %u",
+ (cache == cshare->source_cache) ?
+ "writer" : "reader", cache, (ulong) pos,
+ cshare->running_threads));
+
+ if (cshare->source_cache)
{
- s->count=s->total;
- return 1;
+ /* A write cache is synchronized to the read caches. */
+
+ if (cache == cshare->source_cache)
+ {
+ /* The writer waits until all readers are here. */
+ while (cshare->running_threads)
+ {
+ DBUG_PRINT("io_cache_share", ("writer waits in lock"));
+ pthread_cond_wait(&cshare->cond_writer, &cshare->mutex);
+ }
+ DBUG_PRINT("io_cache_share", ("writer awoke, going to copy"));
+
+ /* Stay locked. Leave the lock later by unlock_io_cache(). */
+ DBUG_RETURN(1);
+ }
+
+ /* The last thread wakes the writer. */
+ if (!cshare->running_threads)
+ {
+ DBUG_PRINT("io_cache_share", ("waking writer"));
+ pthread_cond_signal(&cshare->cond_writer);
+ }
+
+ /*
+ Readers wait until the data is copied from the writer. Another
+ reason to stop waiting is the removal of the write thread. If this
+ happens, we leave the lock with old data in the buffer.
+ */
+ while ((!cshare->read_end || (cshare->pos_in_file < pos)) &&
+ cshare->source_cache)
+ {
+ DBUG_PRINT("io_cache_share", ("reader waits in lock"));
+ pthread_cond_wait(&cshare->cond, &cshare->mutex);
+ }
+
+ /*
+ If the writer was removed from the share while this thread was
+ asleep, we need to simulate an EOF condition. The writer cannot
+ reset the share variables as they might still be in use by readers
+ of the last block. When we awake here then because the last
+ joining thread signalled us. If the writer is not the last, it
+ will not signal. So it is safe to clear the buffer here.
+ */
+ if (!cshare->read_end || (cshare->pos_in_file < pos))
+ {
+ DBUG_PRINT("io_cache_share", ("reader found writer removed. EOF"));
+ cshare->read_end= cshare->buffer; /* Empty buffer. */
+ cshare->error= 0; /* EOF is not an error. */
+ }
}
+ else
+ {
+ /*
+ There are read caches only. The last thread arriving in
+ lock_io_cache() continues with a locked cache and reads the block.
+ */
+ if (!cshare->running_threads)
+ {
+ DBUG_PRINT("io_cache_share", ("last thread joined, going to read"));
+ /* Stay locked. Leave the lock later by unlock_io_cache(). */
+ DBUG_RETURN(1);
+ }
- total=s->total;
- s->count--;
- while (!s->active || s->active->pos_in_file < pos)
- pthread_cond_wait(&s->cond, &s->mutex);
+ /*
+ All other threads wait until the requested block is read by the
+ last thread arriving. Another reason to stop waiting is the
+ removal of a thread. If this leads to all threads being in the
+ lock, we have to continue also. The first of the awaken threads
+ will then do the read.
+ */
+ while ((!cshare->read_end || (cshare->pos_in_file < pos)) &&
+ cshare->running_threads)
+ {
+ DBUG_PRINT("io_cache_share", ("reader waits in lock"));
+ pthread_cond_wait(&cshare->cond, &cshare->mutex);
+ }
- if (s->total < total &&
- (!s->active || s->active->pos_in_file < pos))
- return 1;
+ /* If the block is not yet read, continue with a locked cache and read. */
+ if (!cshare->read_end || (cshare->pos_in_file < pos))
+ {
+ DBUG_PRINT("io_cache_share", ("reader awoke, going to read"));
+ /* Stay locked. Leave the lock later by unlock_io_cache(). */
+ DBUG_RETURN(1);
+ }
- pthread_mutex_unlock(&s->mutex);
- return 0;
+ /* Another thread did read the block already. */
+ }
+ DBUG_PRINT("io_cache_share", ("reader awoke, going to process %u bytes",
+ cshare->read_end ? (uint)
+ (cshare->read_end - cshare->buffer) : 0));
+
+ /*
+ Leave the lock. Do not call unlock_io_cache() later. The thread that
+ filled the buffer did this and marked all threads as running.
+ */
+ pthread_mutex_unlock(&cshare->mutex);
+ DBUG_RETURN(0);
}
-static void unlock_io_cache(IO_CACHE *info)
+
+/*
+ Unlock IO cache.
+
+ SYNOPSIS
+ unlock_io_cache()
+ cache The cache of the thread leaving the lock.
+
+ NOTE
+ This is called by the thread that filled the buffer. It marks all
+ threads as running and awakes them. This must not be done by any
+ other thread.
+
+ Do not signal cond_writer. Either there is no writer or the writer
+ is the only one who can call this function.
+
+ The reason for resetting running_threads to total_threads before
+ waking all other threads is that it could be possible that this
+ thread is so fast with processing the buffer that it enters the lock
+ before even one other thread has left it. If every awoken thread
+ would increase running_threads by one, this thread could think that
+ he is again the last to join and would not wait for the other
+ threads to process the data.
+
+ RETURN
+ void
+*/
+
+static void unlock_io_cache(IO_CACHE *cache)
{
- pthread_cond_broadcast(&info->share->cond);
- pthread_mutex_unlock(&info->share->mutex);
+ IO_CACHE_SHARE *cshare= cache->share;
+ DBUG_ENTER("unlock_io_cache");
+ DBUG_PRINT("io_cache_share", ("%s: 0x%lx pos: %lu running: %u",
+ (cache == cshare->source_cache) ?
+ "writer" : "reader",
+ cache, (ulong) cshare->pos_in_file,
+ cshare->total_threads));
+
+ cshare->running_threads= cshare->total_threads;
+ pthread_cond_broadcast(&cshare->cond);
+ pthread_mutex_unlock(&cshare->mutex);
+ DBUG_VOID_RETURN;
}
@@ -569,7 +869,7 @@ static void unlock_io_cache(IO_CACHE *info)
SYNOPSIS
_my_b_read_r()
- info IO_CACHE pointer
+ cache IO_CACHE pointer
Buffer Buffer to retrieve count bytes from file
Count Number of bytes to read into Buffer
@@ -581,7 +881,7 @@ static void unlock_io_cache(IO_CACHE *info)
It works as follows: when a thread tries to read from a file (that
is, after using all the data from the (shared) buffer), it just
- hangs on lock_io_cache(), wating for other threads. When the very
+ hangs on lock_io_cache(), waiting for other threads. When the very
last thread attempts a read, lock_io_cache() returns 1, the thread
does actual IO and unlock_io_cache(), which signals all the waiting
threads that data is in the buffer.
@@ -601,16 +901,17 @@ static void unlock_io_cache(IO_CACHE *info)
1 Error: can't read requested characters
*/
-int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
+int _my_b_read_r(register IO_CACHE *cache, byte *Buffer, uint Count)
{
my_off_t pos_in_file;
uint length, diff_length, left_length;
+ IO_CACHE_SHARE *cshare= cache->share;
DBUG_ENTER("_my_b_read_r");
- if ((left_length= (uint) (info->read_end - info->read_pos)))
+ if ((left_length= (uint) (cache->read_end - cache->read_pos)))
{
DBUG_ASSERT(Count >= left_length); /* User is not using my_b_read() */
- memcpy(Buffer, info->read_pos, (size_t) (left_length));
+ memcpy(Buffer, cache->read_pos, (size_t) (left_length));
Buffer+= left_length;
Count-= left_length;
}
@@ -618,55 +919,133 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
{
int cnt, len;
- pos_in_file= info->pos_in_file + (info->read_end - info->buffer);
+ pos_in_file= cache->pos_in_file + (cache->read_end - cache->buffer);
diff_length= (uint) (pos_in_file & (IO_SIZE-1));
length=IO_ROUND_UP(Count+diff_length)-diff_length;
- length=(length <= info->read_length) ?
- length + IO_ROUND_DN(info->read_length - length) :
- length - IO_ROUND_UP(length - info->read_length) ;
- if (info->type != READ_FIFO &&
- (length > (info->end_of_file - pos_in_file)))
- length= (uint) (info->end_of_file - pos_in_file);
+ length= ((length <= cache->read_length) ?
+ length + IO_ROUND_DN(cache->read_length - length) :
+ length - IO_ROUND_UP(length - cache->read_length));
+ if (cache->type != READ_FIFO &&
+ (length > (cache->end_of_file - pos_in_file)))
+ length= (uint) (cache->end_of_file - pos_in_file);
if (length == 0)
{
- info->error= (int) left_length;
+ cache->error= (int) left_length;
DBUG_RETURN(1);
}
- if (lock_io_cache(info, pos_in_file))
+ if (lock_io_cache(cache, pos_in_file))
{
- info->share->active=info;
- if (info->seek_not_done) /* File touched, do seek */
- VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
- len=(int)my_read(info->file,info->buffer, length, info->myflags);
- info->read_end=info->buffer + (len == -1 ? 0 : len);
- info->error=(len == (int)length ? 0 : len);
- info->pos_in_file=pos_in_file;
- unlock_io_cache(info);
+ /* With a synchronized write/read cache we won't come here... */
+ DBUG_ASSERT(!cshare->source_cache);
+ /*
+ ... unless the writer has gone before this thread entered the
+ lock. Simulate EOF in this case. It can be distinguished by
+ cache->file.
+ */
+ if (cache->file < 0)
+ len= 0;
+ else
+ {
+ if (cache->seek_not_done) /* File touched, do seek */
+ VOID(my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0)));
+ len= (int) my_read(cache->file, cache->buffer, length, cache->myflags);
+ }
+ DBUG_PRINT("io_cache_share", ("read %d bytes", len));
+
+ cache->read_end= cache->buffer + (len == -1 ? 0 : len);
+ cache->error= (len == (int)length ? 0 : len);
+ cache->pos_in_file= pos_in_file;
+
+ /* Copy important values to the share. */
+ cshare->error= cache->error;
+ cshare->read_end= cache->read_end;
+ cshare->pos_in_file= pos_in_file;
+
+ /* Mark all threads as running and wake them. */
+ unlock_io_cache(cache);
}
else
{
- info->error= info->share->active->error;
- info->read_end= info->share->active->read_end;
- info->pos_in_file= info->share->active->pos_in_file;
- len= (int) (info->error == -1 ? -1 : info->read_end-info->buffer);
+ /*
+ With a synchronized write/read cache readers always come here.
+ Copy important values from the share.
+ */
+ cache->error= cshare->error;
+ cache->read_end= cshare->read_end;
+ cache->pos_in_file= cshare->pos_in_file;
+
+ len= (int) ((cache->error == -1) ? -1 : cache->read_end - cache->buffer);
}
- info->read_pos=info->buffer;
- info->seek_not_done=0;
+ cache->read_pos= cache->buffer;
+ cache->seek_not_done= 0;
if (len <= 0)
{
- info->error= (int) left_length;
+ DBUG_PRINT("io_cache_share", ("reader error. len %d left %u",
+ len, left_length));
+ cache->error= (int) left_length;
DBUG_RETURN(1);
}
cnt= ((uint) len > Count) ? (int) Count : len;
- memcpy(Buffer, info->read_pos, (size_t) cnt);
+ memcpy(Buffer, cache->read_pos, (size_t) cnt);
Count -= cnt;
Buffer+= cnt;
left_length+= cnt;
- info->read_pos+= cnt;
+ cache->read_pos+= cnt;
}
DBUG_RETURN(0);
}
-#endif
+
+
+/*
+ Copy data from write cache to read cache.
+
+ SYNOPSIS
+ copy_to_read_buffer()
+ write_cache The write cache.
+ write_buffer The source of data, mostly the cache buffer.
+ write_length The number of bytes to copy.
+
+ NOTE
+ The write thread will wait for all read threads to join the cache
+ lock. Then it copies the data over and wakes the read threads.
+
+ RETURN
+ void
+*/
+
+static void copy_to_read_buffer(IO_CACHE *write_cache,
+ const byte *write_buffer, uint write_length)
+{
+ IO_CACHE_SHARE *cshare= write_cache->share;
+
+ DBUG_ASSERT(cshare->source_cache == write_cache);
+ /*
+ write_length is usually less or equal to buffer_length.
+ It can be bigger if _my_b_write() is called with a big length.
+ */
+ while (write_length)
+ {
+ uint copy_length= min(write_length, write_cache->buffer_length);
+ int __attribute__((unused)) rc;
+
+ rc= lock_io_cache(write_cache, write_cache->pos_in_file);
+ /* The writing thread does always have the lock when it awakes. */
+ DBUG_ASSERT(rc);
+
+ memcpy(cshare->buffer, write_buffer, copy_length);
+
+ cshare->error= 0;
+ cshare->read_end= cshare->buffer + copy_length;
+ cshare->pos_in_file= write_cache->pos_in_file;
+
+ /* Mark all threads as running and wake them. */
+ unlock_io_cache(write_cache);
+
+ write_buffer+= copy_length;
+ write_length-= copy_length;
+ }
+}
+#endif /*THREAD*/
/*
@@ -1018,6 +1397,7 @@ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count)
Buffer+=rest_length;
Count-=rest_length;
info->write_pos+=rest_length;
+
if (my_b_flush_io_cache(info,1))
return 1;
if (Count >= IO_SIZE)
@@ -1030,6 +1410,23 @@ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count)
}
if (my_write(info->file,Buffer,(uint) length,info->myflags | MY_NABP))
return info->error= -1;
+
+#ifdef THREAD
+ /*
+ In case of a shared I/O cache with a writer we normally do direct
+ write cache to read cache copy. Simulate this here by direct
+ caller buffer to read cache copy. Do it after the write so that
+ the cache readers actions on the flushed part can go in parallel
+ with the write of the extra stuff. copy_to_read_buffer()
+ synchronizes writer and readers so that after this call the
+ readers can act on the extra stuff while the writer can go ahead
+ and prepare the next output. copy_to_read_buffer() relies on
+ info->pos_in_file.
+ */
+ if (info->share)
+ copy_to_read_buffer(info, Buffer, length);
+#endif
+
Count-=length;
Buffer+=length;
info->pos_in_file+=length;
@@ -1050,6 +1447,14 @@ int my_b_append(register IO_CACHE *info, const byte *Buffer, uint Count)
{
uint rest_length,length;
+#ifdef THREAD
+ /*
+ Assert that we cannot come here with a shared cache. If we do one
+ day, we might need to add a call to copy_to_read_buffer().
+ */
+ DBUG_ASSERT(!info->share);
+#endif
+
lock_append_buffer(info);
rest_length=(uint) (info->write_end - info->write_pos);
if (Count <= rest_length)
@@ -1110,6 +1515,14 @@ int my_block_write(register IO_CACHE *info, const byte *Buffer, uint Count,
uint length;
int error=0;
+#ifdef THREAD
+ /*
+ Assert that we cannot come here with a shared cache. If we do one
+ day, we might need to add a call to copy_to_read_buffer().
+ */
+ DBUG_ASSERT(!info->share);
+#endif
+
if (pos < info->pos_in_file)
{
/* Of no overlap, write everything without buffering */
@@ -1186,6 +1599,17 @@ int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock)
if ((length=(uint) (info->write_pos - info->write_buffer)))
{
+#ifdef THREAD
+ /*
+ In case of a shared I/O cache with a writer we do direct write
+ cache to read cache copy. Do it before the write here so that
+ the readers can work in parallel with the write.
+ copy_to_read_buffer() relies on info->pos_in_file.
+ */
+ if (info->share)
+ copy_to_read_buffer(info, info->write_buffer, length);
+#endif
+
pos_in_file=info->pos_in_file;
/*
If we have append cache, we always open the file with
@@ -1265,16 +1689,10 @@ int end_io_cache(IO_CACHE *info)
#ifdef THREAD
/*
- if IO_CACHE is shared between several threads, only one
- thread needs to call end_io_cache() - just as init_io_cache()
- should be called only once and then memcopy'ed
+ Every thread must call remove_io_thread(). The last one destroys
+ the share elements.
*/
- if (info->share)
- {
- pthread_cond_destroy(&info->share->cond);
- pthread_mutex_destroy(&info->share->mutex);
- info->share=0;
- }
+ DBUG_ASSERT(!info->share || !info->share->total_threads);
#endif
if ((pre_close=info->pre_close))
diff --git a/mysys/my_libwrap.c b/mysys/my_libwrap.c
index be8adbab0a1..80fca127716 100644
--- a/mysys/my_libwrap.c
+++ b/mysys/my_libwrap.c
@@ -31,12 +31,12 @@ void my_fromhost(struct request_info *req)
int my_hosts_access(struct request_info *req)
{
- hosts_access(req);
+ return hosts_access(req);
}
char *my_eval_client(struct request_info *req)
{
- eval_client(req);
+ return eval_client(req);
}
#endif /* HAVE_LIBWRAP */
diff --git a/mysys/queues.c b/mysys/queues.c
index ecf1058af41..6a285ce7417 100644
--- a/mysys/queues.c
+++ b/mysys/queues.c
@@ -164,28 +164,22 @@ void delete_queue(QUEUE *queue)
void queue_insert(register QUEUE *queue, byte *element)
{
- reg2 uint idx,next;
+ reg2 uint idx, next;
int cmp;
-
-#ifndef DBUG_OFF
- if (queue->elements < queue->max_elements)
-#endif
+ DBUG_ASSERT(queue->elements < queue->max_elements);
+ queue->root[0]= element;
+ idx= ++queue->elements;
+ /* max_at_top swaps the comparison if we want to order by desc */
+ while ((cmp= queue->compare(queue->first_cmp_arg,
+ element + queue->offset_to_key,
+ queue->root[(next= idx >> 1)] +
+ queue->offset_to_key)) &&
+ (cmp ^ queue->max_at_top) < 0)
{
- queue->root[0]=element;
- idx= ++queue->elements;
-
- /* max_at_top swaps the comparison if we want to order by desc */
- while ((cmp=queue->compare(queue->first_cmp_arg,
- element+queue->offset_to_key,
- queue->root[(next=idx >> 1)] +
- queue->offset_to_key)) &&
- (cmp ^ queue->max_at_top) < 0)
- {
- queue->root[idx]=queue->root[next];
- idx=next;
- }
- queue->root[idx]=element;
+ queue->root[idx]= queue->root[next];
+ idx= next;
}
+ queue->root[idx]= element;
}
/* Remove item from queue */
@@ -193,16 +187,12 @@ void queue_insert(register QUEUE *queue, byte *element)
byte *queue_remove(register QUEUE *queue, uint idx)
{
-#ifndef DBUG_OFF
- if (idx >= queue->max_elements)
- return 0;
-#endif
- {
- byte *element=queue->root[++idx]; /* Intern index starts from 1 */
- queue->root[idx]=queue->root[queue->elements--];
- _downheap(queue,idx);
- return element;
- }
+ byte *element;
+ DBUG_ASSERT(idx < queue->max_elements);
+ element= queue->root[++idx]; /* Intern index starts from 1 */
+ queue->root[idx]= queue->root[queue->elements--];
+ _downheap(queue, idx);
+ return element;
}
/* Fix when element on top has been replaced */
diff --git a/netware/BUILD/mwccnlm b/netware/BUILD/mwccnlm
index e6840e781f8..030d87288f2 100755
--- a/netware/BUILD/mwccnlm
+++ b/netware/BUILD/mwccnlm
@@ -3,9 +3,12 @@
# stop on errors
set -e
-# mwccnlm is having a hard time understanding "-I./../include"
-# convert it to "-I../include"
-args=" "`echo $* | sed -e 's/-I.\/../-I../g'`
+# mwccnlm is having a hard time understanding:
+# * "-I./../include", convert it to "-I../include"
+# * "-I.../..", convert it to "-I../../"
+args=" "`echo $* | sed \
+-e 's/-I.\/../-I../g' \
+-e 's/\(-I[.\/]*.\) /\1\/ /g'`
# NOTE: Option 'pipefail' is not standard sh
set -o pipefail
diff --git a/netware/BUILD/mwenv b/netware/BUILD/mwenv
index fa52568fcd6..d8d53293b2c 100755
--- a/netware/BUILD/mwenv
+++ b/netware/BUILD/mwenv
@@ -1,19 +1,39 @@
#! /bin/sh
-# F:/mydev, /home/kp/mydev, and 4.0.21 must be correct before compiling
-# This values are normally changed by the nwbootstrap script
+if test ! -r ./sql/mysqld.cc
+then
+ echo "you must start from the top source directory"
+ exit 1
+fi
-# the default is "F:/mydev"
-export MYDEV="F:/mydev"
+# The base path(in wineformat) where compilers, includes and
+# libraries are installed
+if test -z $MYDEV
+then
+ # the default is "F:/mydev"
+ export MYDEV="F:/mydev"
+fi
+echo "MYDEV: $MYDEV"
-export MWCNWx86Includes="$MYDEV/libc/include;$MYDEV/fs64/headers;$MYDEV/zlib-1.1.4;$MYDEV/mysql-VERSION/include;$MYDEV"
-export MWNWx86Libraries="$MYDEV/libc/imports;$MYDEV/mw/lib;$MYDEV/fs64/imports;$MYDEV/zlib-1.1.4;$MYDEV/openssl;$MYDEV/mysql-VERSION/netware/BUILD"
+# Get current dir
+BUILD_DIR=`pwd`
+echo "BUILD_DIR: $BUILD_DIR"
+
+# Get current dir in wine format
+base=`echo $MYDEV |sed 's/\/.*//'`
+base_unix_part=`winepath -- -u $base/`
+WINE_BUILD_DIR=`echo "$BUILD_DIR" | sed 's_'$base_unix_part'/__'`
+WINE_BUILD_DIR="$base/$WINE_BUILD_DIR"
+echo "WINE_BUILD_DIR: $WINE_BUILD_DIR"
+
+export MWCNWx86Includes="$MYDEV/libc/include;$MYDEV/fs64/headers;$MYDEV/zlib-1.2.3;$WINE_BUILD_DIR/include;$MYDEV"
+export MWNWx86Libraries="$MYDEV/libc/imports;$MYDEV/mw/lib;$MYDEV/fs64/imports;$MYDEV/zlib-1.2.3;$MYDEV/openssl;$WINE_BUILD_DIR/netware/BUILD"
export MWNWx86LibraryFiles="libcpre.o;libc.imp;netware.imp;mwcrtl.lib;mwcpp.lib;libz.a;neb.imp;zPublics.imp;knetware.imp"
export WINEPATH="$MYDEV/mw/bin"
-# the default added path is "$HOME/mydev/mysql-x.x-x/netware/BUILD"
-export PATH="$PATH:BUILD_DIR/mysql-VERSION/netware/BUILD"
+# the default added path is "$BUILD_DIR/netware/BUILD"
+export PATH="$PATH:$BUILD_DIR/netware/BUILD"
export AR='mwldnlm'
export AR_FLAGS='-type library -o'
diff --git a/netware/Makefile.am b/netware/Makefile.am
index 2d34283c4b3..648ce79c484 100644
--- a/netware/Makefile.am
+++ b/netware/Makefile.am
@@ -23,7 +23,8 @@ mysqld_safe_SOURCES= mysqld_safe.c my_manage.c
mysql_install_db_SOURCES= mysql_install_db.c my_manage.c
mysql_test_run_SOURCES= mysql_test_run.c my_manage.c
libmysql_SOURCES= libmysqlmain.c
-libmysql_LDADD = ../libmysql/.libs/libmysqlclient.a @openssl_libs@
+libmysql_LDADD = ../libmysql/.libs/libmysqlclient.a \
+ @openssl_libs@ @yassl_libs@
netware_build_files = client/mysql.def client/mysqladmin.def \
client/mysqlbinlog.def client/mysqlcheck.def \
@@ -45,8 +46,20 @@ link_sources:
@LN_CP_F@ $(srcdir)/$$org ../$$f; \
done
else
-EXTRA_DIST= comp_err.def init_db.sql install_test_db.ncf \
- libmysql.def libmysql.imp \
+
+BUILT_SOURCES = libmysql.imp
+DISTCLEANFILES = $(BUILT_SOURCES)
+
+# Create the libmysql.imp from libmysql/libmysql.def
+libmysql.imp: $(top_srcdir)/libmysql/libmysql.def
+ awk 'BEGIN{x=0;} \
+ END{printf("\n");} \
+ x==1 {printf(" %s",$$1); x++; next} \
+ x>1 {printf(",\n %s", $$1); next} \
+ /EXPORTS/{x=1}' $(top_srcdir)/libmysql/libmysql.def > libmysql.imp
+
+EXTRA_DIST= $(BUILT_SOURCES) comp_err.def init_db.sql install_test_db.ncf \
+ libmysql.def \
libmysqlmain.c my_manage.c my_manage.h \
my_print_defaults.def myisam_ftdump.def myisamchk.def \
myisamlog.def myisampack.def mysql.def mysql.xdc \
diff --git a/netware/libmysql.imp b/netware/libmysql.imp
deleted file mode 100644
index 977fb1b0b1f..00000000000
--- a/netware/libmysql.imp
+++ /dev/null
@@ -1,85 +0,0 @@
-myodbc_remove_escape,
-mysql_add_slave,
-mysql_affected_rows,
-mysql_change_user,
-mysql_character_set_name,
-mysql_close,
-mysql_data_seek,
-mysql_debug,
-mysql_disable_reads_from_master,
-mysql_disable_rpl_parse,
-mysql_dump_debug_info,
-mysql_enable_reads_from_master,
-mysql_enable_rpl_parse,
-mysql_eof,
-mysql_errno,
-mysql_error,
-mysql_escape_string,
-mysql_fetch_field,
-mysql_fetch_field_direct,
-mysql_fetch_fields,
-mysql_fetch_lengths,
-mysql_fetch_row,
-mysql_field_count,
-mysql_field_seek,
-mysql_field_tell,
-mysql_free_result,
-mysql_get_client_info,
-mysql_get_host_info,
-mysql_get_proto_info,
-mysql_get_server_info,
-mysql_info,
-mysql_init,
-mysql_insert_id,
-mysql_kill,
-mysql_list_dbs,
-mysql_list_fields,
-mysql_list_processes,
-mysql_list_tables,
-mysql_manager_close,
-mysql_manager_command,
-mysql_manager_connect,
-mysql_manager_fetch_line,
-mysql_manager_init,
-mysql_master_query,
-mysql_master_send_query,
-mysql_num_fields,
-mysql_num_rows,
-mysql_odbc_escape_string,
-mysql_options,
-mysql_ping,
-mysql_query,
-mysql_read_query_result,
-mysql_reads_from_master_enabled,
-mysql_real_connect,
-mysql_real_escape_string,
-mysql_real_query,
-mysql_refresh,
-mysql_row_seek,
-mysql_row_tell,
-mysql_rpl_parse_enabled,
-mysql_rpl_probe,
-mysql_rpl_query_type,
-mysql_select_db,
-mysql_send_query,
-mysql_server_end,
-mysql_server_init,
-mysql_set_master,
-mysql_shutdown,
-mysql_slave_query,
-mysql_slave_send_query,
-mysql_ssl_set,
-mysql_stat,
-mysql_store_result,
-mysql_thread_end,
-mysql_thread_id,
-mysql_thread_init,
-mysql_thread_safe,
-mysql_use_result,
-net_safe_read,
-#simple_command,
-mysql_connect,
-mysql_create_db,
-mysql_drop_db,
-
-
diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh
index bf53aa78e15..61cd59457d1 100644
--- a/scripts/mysqlhotcopy.sh
+++ b/scripts/mysqlhotcopy.sh
@@ -263,6 +263,7 @@ my $hc_locks = "";
my $hc_tables = "";
my $num_tables = 0;
my $num_files = 0;
+my $raid_dir_regex = '[A-Za-z0-9]{2}';
foreach my $rdb ( @db_desc ) {
my $db = $rdb->{src};
@@ -294,7 +295,7 @@ foreach my $rdb ( @db_desc ) {
my @raid_dir = ();
while ( defined( my $name = readdir DBDIR ) ) {
- if ( $name =~ /^\d\d$/ && -d "$db_dir/$name" ) {
+ if ( $name =~ /^$raid_dir_regex$/ && -d "$db_dir/$name" ) {
push @raid_dir, $name;
}
else {
@@ -602,7 +603,7 @@ sub copy_files {
# add recursive option for scp
$cp.= " -r" if $^O =~ /m^(solaris|linux|freebsd|darwin)$/ && $method =~ /^scp\b/;
- my @non_raid = map { "'$_'" } grep { ! m:/\d{2}/[^/]+$: } @$files;
+ my @non_raid = map { "'$_'" } grep { ! m:/$raid_dir_regex/[^/]+$: } @$files;
# add files to copy and the destination directory
safe_system( $cp, @non_raid, "'$target'" ) if (@non_raid);
@@ -810,7 +811,7 @@ sub get_raid_dirs {
my %dirs = ();
foreach my $f ( @$r_files ) {
- if ( $f =~ m:^(\d\d)/: ) {
+ if ( $f =~ m:^($raid_dir_regex)/: ) {
$dirs{$1} = 1;
}
}
diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc
index 24844e05776..e2142c97f33 100644
--- a/server-tools/instance-manager/guardian.cc
+++ b/server-tools/instance-manager/guardian.cc
@@ -110,20 +110,35 @@ void Guardian_thread::process_instance(Instance *instance,
if (instance->is_running())
{
- /* clear status fields */
- current_node->restart_counter= 0;
- current_node->crash_moment= 0;
- current_node->state= STARTED;
+ /* The instance can be contacted on it's port */
+
+ /* If STARTING also check that pidfile has been created */
+ if (current_node->state == STARTING &&
+ current_node->instance->options.get_pid() == 0)
+ {
+ /* Pid file not created yet, don't go to STARTED state yet */
+ }
+ else
+ {
+ /* clear status fields */
+ log_info("guardian: instance %s is running, set state to STARTED",
+ instance->options.instance_name);
+ current_node->restart_counter= 0;
+ current_node->crash_moment= 0;
+ current_node->state= STARTED;
+ }
}
else
{
switch (current_node->state) {
case NOT_STARTED:
- instance->start();
- current_node->last_checked= current_time;
log_info("guardian: starting instance %s",
instance->options.instance_name);
+
+ /* NOTE, set state to STARTING _before_ start() is called */
current_node->state= STARTING;
+ instance->start();
+ current_node->last_checked= current_time;
break;
case STARTED: /* fallthrough */
case STARTING: /* let the instance start or crash */
diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc
index 2ed369ba245..b792d132da0 100644
--- a/server-tools/instance-manager/instance.cc
+++ b/server-tools/instance-manager/instance.cc
@@ -572,18 +572,19 @@ void Instance::kill_instance(int signum)
/* if there are no pid, everything seems to be fine */
if ((pid= options.get_pid()) != 0) /* get pid from pidfile */
{
- /*
- If we cannot kill mysqld, then it has propably crashed.
- Let us try to remove staled pidfile and return successfully
- as mysqld is probably stopped.
- */
- if (!kill(pid, signum))
- options.unlink_pidfile();
- else if (signum == SIGKILL) /* really killed instance with SIGKILL */
- log_error("The instance %s is being stopped forsibly. Normally \
- it should not happed. Probably the instance has been \
- hanging. You should also check your IM setup",
- options.instance_name);
+ if (kill(pid, signum) == 0)
+ {
+ /* Kill suceeded */
+ if (signum == SIGKILL) /* really killed instance with SIGKILL */
+ {
+ log_error("The instance %s is being stopped forcibly. Normally" \
+ "it should not happen. Probably the instance has been" \
+ "hanging. You should also check your IM setup",
+ options.instance_name);
+ /* After sucessful hard kill the pidfile need to be removed */
+ options.unlink_pidfile();
+ }
+ }
}
return;
}
diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc
index 72621ed1662..f86f359959b 100644
--- a/server-tools/instance-manager/instance_options.cc
+++ b/server-tools/instance-manager/instance_options.cc
@@ -377,7 +377,8 @@ pid_t Instance_options::get_pid()
{
pid_t pid;
- fscanf(pid_file_stream, "%i", &pid);
+ if (fscanf(pid_file_stream, "%i", &pid) != 1)
+ pid= -1;
my_fclose(pid_file_stream, MYF(0));
return pid;
}
diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc
index 500b25bec03..58a4093dd05 100644
--- a/server-tools/instance-manager/listener.cc
+++ b/server-tools/instance-manager/listener.cc
@@ -36,6 +36,27 @@
#include "portability.h"
+static void set_non_blocking(int socket)
+{
+#ifndef __WIN__
+ int flags= fcntl(socket, F_GETFL, 0);
+ fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+#else
+ u_long arg= 1;
+ ioctlsocket(socket, FIONBIO, &arg);
+#endif
+}
+
+
+static void set_no_inherit(int socket)
+{
+#ifndef __WIN__
+ int flags= fcntl(socket, F_GETFD, 0);
+ fcntl(socket, F_SETFD, flags | FD_CLOEXEC);
+#endif
+}
+
+
/*
Listener_thread - incapsulates listening functionality
*/
@@ -157,6 +178,8 @@ void Listener_thread::run()
/* accept may return -1 (failure or spurious wakeup) */
if (client_fd >= 0) // connection established
{
+ set_no_inherit(client_fd);
+
Vio *vio= vio_new(client_fd, socket_index == 0 ?
VIO_TYPE_SOCKET : VIO_TYPE_TCPIP,
socket_index == 0 ? 1 : 0);
@@ -198,25 +221,6 @@ err:
return;
}
-void set_non_blocking(int socket)
-{
-#ifndef __WIN__
- int flags= fcntl(socket, F_GETFL, 0);
- fcntl(socket, F_SETFL, flags | O_NONBLOCK);
-#else
- u_long arg= 1;
- ioctlsocket(socket, FIONBIO, &arg);
-#endif
-}
-
-void set_no_inherit(int socket)
-{
-#ifndef __WIN__
- int flags= fcntl(socket, F_GETFD, 0);
- fcntl(socket, F_SETFD, flags | FD_CLOEXEC);
-#endif
-}
-
int Listener_thread::create_tcp_socket()
{
/* value to be set by setsockopt */
diff --git a/sql/Makefile.am b/sql/Makefile.am
index e837e10472c..d9cea960915 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -27,7 +27,7 @@ INCLUDES = @ZLIB_INCLUDES@ \
WRAPLIBS= @WRAPLIBS@
SUBDIRS = share
libexec_PROGRAMS = mysqld
-noinst_PROGRAMS = gen_lex_hash
+EXTRA_PROGRAMS = gen_lex_hash
bin_PROGRAMS = mysql_tzinfo_to_sql
gen_lex_hash_LDFLAGS = @NOINST_LDFLAGS@
LDADD = $(top_builddir)/myisam/libmyisam.a \
@@ -153,7 +153,11 @@ sql_yacc.o: sql_yacc.cc sql_yacc.h $(HEADERS)
@echo "If it fails, re-run configure with --with-low-memory"
$(CXXCOMPILE) $(LM_CFLAGS) -c $<
-lex_hash.h: gen_lex_hash$(EXEEXT)
+# This generates lex_hash.h
+# NOTE Built sources should depend on their sources not the tool
+# this avoid the rebuild of the built files in a source dist
+lex_hash.h: gen_lex_hash.cc lex.h
+ $(MAKE) $(AM_MAKEFLAGS) gen_lex_hash$(EXEEXT)
./gen_lex_hash$(EXEEXT) > $@
# For testing of udf_example.so
diff --git a/sql/field.cc b/sql/field.cc
index 4860f6ea3da..b05398afe75 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2316,11 +2316,16 @@ int Field_new_decimal::store(const char *from, uint length,
from, length, charset, &decimal_value)) &&
table->in_use->abort_on_warning)
{
+ /* Because "from" is not NUL-terminated and we use %s in the ER() */
+ String from_as_str;
+ from_as_str.copy(from, length, &my_charset_bin);
+
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
- "decimal", from, field_name,
+ "decimal", from_as_str.c_ptr(), field_name,
(ulong) table->in_use->row_count);
+
DBUG_RETURN(err);
}
@@ -2333,13 +2338,20 @@ int Field_new_decimal::store(const char *from, uint length,
set_value_on_overflow(&decimal_value, decimal_value.sign());
break;
case E_DEC_BAD_NUM:
+ {
+ /* Because "from" is not NUL-terminated and we use %s in the ER() */
+ String from_as_str;
+ from_as_str.copy(from, length, &my_charset_bin);
+
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
- "decimal", from, field_name,
+ "decimal", from_as_str.c_ptr(), field_name,
(ulong) table->in_use->row_count);
my_decimal_set_zero(&decimal_value);
+
break;
+ }
}
#ifndef DBUG_OFF
@@ -2413,6 +2425,13 @@ int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
}
+int Field_new_decimal::store_time(TIME *ltime, timestamp_type t_type)
+{
+ my_decimal decimal_value;
+ return store_value(date2my_decimal(ltime, &decimal_value));
+}
+
+
double Field_new_decimal::val_real(void)
{
double dbl;
@@ -2482,30 +2501,27 @@ void Field_new_decimal::sql_type(String &str) const
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{
- int not_used; // We can ignore result from str2int
char *end;
- long tmp= my_strntol(cs, from, len, 10, &end, &not_used);
- int error= 0;
+ int error;
if (unsigned_flag)
{
- if (tmp < 0)
+ ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
+ if (error == MY_ERRNO_ERANGE || tmp > 255)
{
- tmp=0; /* purecov: inspected */
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > 255)
- {
- tmp= 255;
+ set_if_smaller(tmp, 255);
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
+ else
+ error= 0;
+ ptr[0]= (char) tmp;
}
else
{
+ longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
if (tmp < -128)
{
tmp= -128;
@@ -2520,8 +2536,10 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
+ else
+ error= 0;
+ ptr[0]= (char) tmp;
}
- ptr[0]= (char) tmp;
return error;
}
@@ -2686,30 +2704,34 @@ void Field_tiny::sql_type(String &res) const
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{
- int not_used; // We can ignore result from str2int
char *end;
- long tmp= my_strntol(cs, from, len, 10, &end, &not_used);
- int error= 0;
+ int error;
if (unsigned_flag)
{
- if (tmp < 0)
+ ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
+ if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX16)
{
- tmp=0;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > UINT_MAX16)
- {
- tmp=UINT_MAX16;
+ set_if_smaller(tmp, UINT_MAX16);
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
+ else
+ error= 0;
+#ifdef WORDS_BIGENDIAN
+ if (table->s->db_low_byte_first)
+ {
+ int2store(ptr,tmp);
+ }
+ else
+#endif
+ shortstore(ptr,(short) tmp);
}
else
{
+ longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
if (tmp < INT_MIN16)
{
tmp= INT_MIN16;
@@ -2724,15 +2746,17 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
- }
+ else
+ error= 0;
#ifdef WORDS_BIGENDIAN
- if (table->s->db_low_byte_first)
- {
- int2store(ptr,tmp);
- }
- else
+ if (table->s->db_low_byte_first)
+ {
+ int2store(ptr,tmp);
+ }
+ else
#endif
- shortstore(ptr,(short) tmp);
+ shortstore(ptr,(short) tmp);
+ }
return error;
}
@@ -2960,30 +2984,27 @@ void Field_short::sql_type(String &res) const
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{
- int not_used; // We can ignore result from str2int
char *end;
- long tmp= my_strntol(cs, from, len, 10, &end, &not_used);
- int error= 0;
+ int error;
if (unsigned_flag)
{
- if (tmp < 0)
+ ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
+ if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX24)
{
- tmp=0;
- 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_if_smaller(tmp, UINT_MAX24);
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
+ else
+ error= 0;
+ int3store(ptr,tmp);
}
else
{
+ longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
if (tmp < INT_MIN24)
{
tmp= INT_MIN24;
@@ -2998,9 +3019,10 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
}
else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
error= 1;
+ else
+ error= 0;
+ int3store(ptr,tmp);
}
-
- int3store(ptr,tmp);
return error;
}
@@ -3196,64 +3218,47 @@ static bool test_if_minus(CHARSET_INFO *cs,
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
{
- ulong tmp_scan;
- longlong tmp;
long store_tmp;
int error;
char *end;
- tmp_scan= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES);
- len-= tmp_scan;
- from+= tmp_scan;
-
- end= (char*) from+len;
- tmp= cs->cset->strtoll10(cs, from, &end, &error);
-
- if (error != MY_ERRNO_EDOM)
+ if (unsigned_flag)
{
- if (unsigned_flag)
+ ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
+ if (error == MY_ERRNO_ERANGE || tmp > (ulonglong) UINT_MAX32)
{
- if (error < 0)
- {
- error= 1;
- tmp= 0;
- }
- else if ((ulonglong) tmp > (ulonglong) UINT_MAX32)
- {
- tmp= UINT_MAX32;
- error= 1;
- }
- else
- error= 0;
+ set_if_smaller(tmp, (ulonglong) UINT_MAX32);
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ error= 1;
}
+ else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ error= 1;
else
- {
- if (error < 0)
- {
- error= 0;
- if (tmp < INT_MIN32)
- {
- tmp= INT_MIN32;
- error= 1;
- }
- }
- else if (tmp > INT_MAX32)
- {
- tmp= INT_MAX32;
- error= 1;
- }
- }
+ error= 0;
+ store_tmp= (long) tmp;
}
- if (error)
+ else
{
- error= error != MY_ERRNO_EDOM ? 1 : 2;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
+ if (tmp < INT_MIN32)
+ {
+ tmp= INT_MIN32;
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ error= 1;
+ }
+ else if (tmp > INT_MAX32)
+ {
+ tmp=INT_MAX32;
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ error= 1;
+ }
+ else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ error= 1;
+ else
+ error= 0;
+ store_tmp= (long) tmp;
}
- else if (from+len != end && table->in_use->count_cuted_fields &&
- check_int(from,len,end,cs))
- error= 2;
- store_tmp= (long) tmp;
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
@@ -3489,33 +3494,20 @@ void Field_long::sql_type(String &res) const
int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
{
- longlong tmp;
- int error= 0;
+ int error;
char *end;
+ ulonglong tmp;
- tmp= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES);
- len-= (uint)tmp;
- from+= tmp;
- if (unsigned_flag)
- {
- if (!len || test_if_minus(cs, from, from + len))
- {
- tmp=0; // Set negative to 0
- error= 1;
- }
- else
- tmp=(longlong) my_strntoull(cs,from,len,10,&end,&error);
- }
- else
- tmp=my_strntoll(cs,from,len,10,&end,&error);
- if (error)
+ tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
+ if (error == MY_ERRNO_ERANGE)
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
- else if (from+len != end && table->in_use->count_cuted_fields &&
- check_int(from,len,end,cs))
- error= 2;
+ else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ error= 1;
+ else
+ error= 0;
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
@@ -7921,7 +7913,7 @@ int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs)
(delta == -1 && (uchar) *from > ((1 << bit_len) - 1)) ||
(!bit_len && delta < 0))
{
- set_rec_bits(0xff, bit_ptr, bit_ofs, bit_len);
+ set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len);
memset(ptr, 0xff, bytes_in_rec);
if (table->in_use->really_abort_on_warning())
set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
@@ -8877,7 +8869,7 @@ create_field::create_field(Field *old_field,Field *orig_field)
case 3: sql_type= FIELD_TYPE_MEDIUM_BLOB; break;
default: sql_type= FIELD_TYPE_LONG_BLOB; break;
}
- length=(length+charset->mbmaxlen-1) / charset->mbmaxlen;
+ length/= charset->mbmaxlen;
key_length/= charset->mbmaxlen;
break;
case MYSQL_TYPE_STRING:
diff --git a/sql/field.h b/sql/field.h
index b79c2bf77a8..8b22424265d 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -489,6 +489,7 @@ public:
int store(const char *to, uint length, CHARSET_INFO *charset);
int store(double nr);
int store(longlong nr, bool unsigned_val);
+ int store_time(TIME *ltime, timestamp_type t_type);
int store_decimal(const my_decimal *);
double val_real(void);
longlong val_int(void);
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 3200f2ca9b2..95ff985376d 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -428,6 +428,21 @@ static void do_varstring2(Copy_field *copy)
length);
}
+
+static void do_varstring2_mb(Copy_field *copy)
+{
+ int well_formed_error;
+ CHARSET_INFO *cs= copy->from_field->charset();
+ uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
+ uint from_length= uint2korr(copy->from_ptr);
+ const char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
+ uint length= cs->cset->well_formed_len(cs, from_beg, from_beg + from_length,
+ char_length, &well_formed_error);
+ int2store(copy->to_ptr, length);
+ memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
+}
+
+
/***************************************************************************
** The different functions that fills in a Copy_field class
***************************************************************************/
@@ -587,7 +602,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
return do_field_string;
if (to_length != from_length)
return (((Field_varstring*) to)->length_bytes == 1 ?
- do_varstring1 : do_varstring2);
+ do_varstring1 : (from->charset()->mbmaxlen == 1 ?
+ do_varstring2 : do_varstring2_mb));
}
else if (to_length < from_length)
return (from->charset()->mbmaxlen == 1 ?
diff --git a/sql/filesort.cc b/sql/filesort.cc
index f13354d5c72..12b17846fe4 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -109,6 +109,8 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
DBUG_PUSH(""); /* No DBUG here */
#endif
FILESORT_INFO table_sort;
+ TABLE_LIST *tab= table->pos_in_table_list;
+ Item_subselect *subselect= tab ? tab->containing_subselect() : 0;
/*
Don't use table->sort in filesort as it is also used by
QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end
@@ -121,7 +123,6 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
my_b_clear(&tempfile);
my_b_clear(&buffpek_pointers);
buffpek=0;
- sort_keys= (uchar **) NULL;
error= 1;
bzero((char*) &param,sizeof(param));
param.sort_length= sortlength(thd, sortorder, s_length, &multi_byte_charset);
@@ -202,13 +203,15 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
ulong old_memavl;
ulong keys= memavl/(param.rec_length+sizeof(char*));
param.keys=(uint) min(records+1, keys);
- if ((sort_keys= (uchar **) make_char_array(param.keys, param.rec_length,
- MYF(0))))
+ if (table_sort.sort_keys ||
+ (table_sort.sort_keys= (uchar **) make_char_array(param.keys, param.rec_length,
+ MYF(0))))
break;
old_memavl=memavl;
if ((memavl=memavl/4*3) < min_sort_memory && old_memavl > min_sort_memory)
memavl= min_sort_memory;
}
+ sort_keys= table_sort.sort_keys;
if (memavl < min_sort_memory)
{
my_error(ER_OUTOFMEMORY,MYF(ME_ERROR+ME_WAITTANG),
@@ -235,8 +238,12 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
}
else
{
- if (!(buffpek=read_buffpek_from_file(&buffpek_pointers, maxbuffer)))
+ if (!table_sort.buffpek && table_sort.buffpek_len < maxbuffer &&
+ !(table_sort.buffpek=
+ (byte *) read_buffpek_from_file(&buffpek_pointers, maxbuffer)))
goto err;
+ buffpek= (BUFFPEK *) table_sort.buffpek;
+ table_sort.buffpek_len= maxbuffer;
close_cached_file(&buffpek_pointers);
/* Open cached file if it isn't open */
if (! my_b_inited(outfile) &&
@@ -269,8 +276,14 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
err:
if (param.tmp_buffer)
x_free(param.tmp_buffer);
- x_free((gptr) sort_keys);
- x_free((gptr) buffpek);
+ if (!subselect || !subselect->is_uncacheable())
+ {
+ x_free((gptr) sort_keys);
+ table_sort.sort_keys= 0;
+ x_free((gptr) buffpek);
+ table_sort.buffpek= 0;
+ table_sort.buffpek_len= 0;
+ }
close_cached_file(&tempfile);
close_cached_file(&buffpek_pointers);
if (my_b_inited(outfile))
@@ -301,13 +314,27 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
} /* filesort */
-void filesort_free_buffers(TABLE *table)
+void filesort_free_buffers(TABLE *table, bool full)
{
if (table->sort.record_pointers)
{
my_free((gptr) table->sort.record_pointers,MYF(0));
table->sort.record_pointers=0;
}
+ if (full)
+ {
+ if (table->sort.sort_keys )
+ {
+ x_free((gptr) table->sort.sort_keys);
+ table->sort.sort_keys= 0;
+ }
+ if (table->sort.buffpek)
+ {
+ x_free((gptr) table->sort.buffpek);
+ table->sort.buffpek= 0;
+ table->sort.buffpek_len= 0;
+ }
+ }
if (table->sort.addon_buf)
{
my_free((char *) table->sort.addon_buf, MYF(0));
@@ -601,6 +628,7 @@ static inline void store_length(uchar *to, uint length, uint pack_length)
break;
case 3:
mi_int3store(to, length);
+ break;
default:
mi_int4store(to, length);
break;
diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc
index bb94a99e700..bc3c819c4ed 100644
--- a/sql/ha_archive.cc
+++ b/sql/ha_archive.cc
@@ -120,6 +120,8 @@ static bool archive_inited= FALSE;
/* Variables for archive share methods */
pthread_mutex_t archive_mutex;
static HASH archive_open_tables;
+static z_off_t max_zfile_size;
+static int zoffset_size;
/* The file extension */
#define ARZ ".ARZ" // The data file
@@ -203,6 +205,18 @@ bool archive_db_init()
}
else
{
+ zoffset_size= 2 << ((zlibCompileFlags() >> 6) & 3);
+ switch (sizeof(z_off_t)) {
+ case 2:
+ max_zfile_size= INT_MAX16;
+ break;
+ case 8:
+ max_zfile_size= LONGLONG_MAX;
+ break;
+ case 4:
+ default:
+ max_zfile_size= INT_MAX32;
+ }
archive_inited= TRUE;
DBUG_RETURN(FALSE);
}
@@ -240,7 +254,7 @@ ha_archive::ha_archive(TABLE *table_arg)
buffer.set((char *)byte_buffer, IO_SIZE, system_charset_info);
/* The size of the offset value we will use for position() */
- ref_length = 2 << ((zlibCompileFlags() >> 6) & 3);
+ ref_length = zoffset_size;
DBUG_ASSERT(ref_length <= sizeof(z_off_t));
}
@@ -480,7 +494,8 @@ int ha_archive::init_archive_writer()
DBUG_RETURN(1);
}
share->archive_write_open= TRUE;
-
+ info(HA_STATUS_TIME);
+ share->approx_file_size= data_file_length;
DBUG_RETURN(0);
}
@@ -651,10 +666,21 @@ error:
*/
int ha_archive::real_write_row(byte *buf, gzFile writer)
{
- z_off_t written;
+ z_off_t written, total_row_length;
uint *ptr, *end;
DBUG_ENTER("ha_archive::real_write_row");
-
+ total_row_length= table->s->reclength;
+ for (ptr= table->s->blob_field, end= ptr + table->s->blob_fields;
+ ptr != end; ptr++)
+ total_row_length+= ((Field_blob*) table->field[*ptr])->get_length();
+ if (share->approx_file_size > max_zfile_size - total_row_length)
+ {
+ info(HA_STATUS_TIME);
+ share->approx_file_size= data_file_length;
+ if (share->approx_file_size > max_zfile_size - total_row_length)
+ DBUG_RETURN(HA_ERR_RECORD_FILE_FULL);
+ }
+ share->approx_file_size+= total_row_length;
written= gzwrite(writer, buf, table->s->reclength);
DBUG_PRINT("ha_archive::real_write_row", ("Wrote %d bytes expected %d", written, table->s->reclength));
if (!delayed_insert || !bulk_insert)
diff --git a/sql/ha_archive.h b/sql/ha_archive.h
index 2bac9fa605e..564b9f03bf5 100644
--- a/sql/ha_archive.h
+++ b/sql/ha_archive.h
@@ -38,6 +38,7 @@ typedef struct st_archive_share {
bool dirty; /* Flag for if a flush should occur */
bool crashed; /* Meta file is crashed */
ha_rows rows_recorded; /* Number of rows in tables */
+ z_off_t approx_file_size; /* Approximate archive data file size */
} ARCHIVE_SHARE;
/*
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 4e73d4fb285..e99d93784c9 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -5970,19 +5970,6 @@ ha_innobase::start_stmt(
prebuilt->select_lock_type =
prebuilt->stored_select_lock_type;
}
-
- if (prebuilt->stored_select_lock_type != LOCK_S
- && prebuilt->stored_select_lock_type != LOCK_X) {
- sql_print_error("stored_select_lock_type is %lu inside "
- "::start_stmt()!",
- prebuilt->stored_select_lock_type);
-
- /* Set the value to LOCK_X: this is just fault
- tolerance, we do not know what the correct value
- should be! */
-
- prebuilt->select_lock_type = LOCK_X;
- }
}
trx->detailed_error[0] = '\0';
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index cb11d9b0452..a4f23cd3cf0 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -326,9 +326,22 @@ void ha_myisammrg::info(uint flag)
if (flag & HA_STATUS_CONST)
{
if (table->s->key_parts && info.rec_per_key)
+ {
+#ifdef HAVE_purify
+ /*
+ valgrind may be unhappy about it, because optimizer may access values
+ between file->keys and table->key_parts, that will be uninitialized.
+ It's safe though, because even if opimizer will decide to use a key
+ with such a number, it'll be an error later anyway.
+ */
+ bzero((char*) table->key_info[0].rec_per_key,
+ sizeof(table->key_info[0].rec_per_key) * table->s->key_parts);
+#endif
memcpy((char*) table->key_info[0].rec_per_key,
(char*) info.rec_per_key,
- sizeof(table->key_info[0].rec_per_key)*table->s->key_parts);
+ sizeof(table->key_info[0].rec_per_key) *
+ min(file->keys, table->s->key_parts));
+ }
}
}
diff --git a/sql/item.cc b/sql/item.cc
index a0eef7a19e9..b26f65ead69 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -272,6 +272,34 @@ my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
}
+my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
+{
+ DBUG_ASSERT(fixed == 1);
+ TIME ltime;
+ longlong date;
+ if (get_date(&ltime, TIME_FUZZY_DATE))
+ {
+ my_decimal_set_zero(decimal_value);
+ return 0;
+ }
+ return date2my_decimal(&ltime, decimal_value);
+}
+
+
+my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
+{
+ DBUG_ASSERT(fixed == 1);
+ TIME ltime;
+ longlong date;
+ if (get_time(&ltime))
+ {
+ my_decimal_set_zero(decimal_value);
+ return 0;
+ }
+ return date2my_decimal(&ltime, decimal_value);
+}
+
+
double Item::val_real_from_decimal()
{
/* Note that fix_fields may not be called for Item_avg_field items */
@@ -295,6 +323,25 @@ longlong Item::val_int_from_decimal()
return result;
}
+int Item::save_time_in_field(Field *field)
+{
+ TIME ltime;
+ if (get_time(&ltime))
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
+}
+
+
+int Item::save_date_in_field(Field *field)
+{
+ TIME ltime;
+ if (get_date(&ltime, TIME_FUZZY_DATE))
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
+}
+
Item::Item():
rsize(0), name(0), orig_name(0), name_length(0), fixed(0),
@@ -1148,6 +1195,28 @@ void Item_name_const::print(String *str)
/*
+ need a special class to adjust printing : references to aggregate functions
+ must not be printed as refs because the aggregate functions that are added to
+ the front of select list are not printed as well.
+*/
+class Item_aggregate_ref : public Item_ref
+{
+public:
+ Item_aggregate_ref(Name_resolution_context *context_arg, Item **item,
+ const char *table_name_arg, const char *field_name_arg)
+ :Item_ref(context_arg, item, table_name_arg, field_name_arg) {}
+
+ void print (String *str)
+ {
+ if (ref)
+ (*ref)->print(str);
+ else
+ Item_ident::print(str);
+ }
+};
+
+
+/*
Move SUM items out from item tree and replace with reference
SYNOPSIS
@@ -1200,8 +1269,8 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
Item *new_item, *real_itm= real_item();
ref_pointer_array[el]= real_itm;
- if (!(new_item= new Item_ref(&thd->lex->current_select->context,
- ref_pointer_array + el, 0, name)))
+ if (!(new_item= new Item_aggregate_ref(&thd->lex->current_select->context,
+ ref_pointer_array + el, 0, name)))
return; // fatal_error is set
fields.push_front(real_itm);
thd->change_item_tree(ref, new_item);
@@ -3745,6 +3814,7 @@ void Item_field::cleanup()
I.e. we can drop 'field'.
*/
field= result_field= 0;
+ null_value= FALSE;
DBUG_VOID_RETURN;
}
diff --git a/sql/item.h b/sql/item.h
index 0cfb0b01fd8..c1a04e4281d 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -617,9 +617,14 @@ public:
my_decimal *val_decimal_from_real(my_decimal *decimal_value);
my_decimal *val_decimal_from_int(my_decimal *decimal_value);
my_decimal *val_decimal_from_string(my_decimal *decimal_value);
+ my_decimal *val_decimal_from_date(my_decimal *decimal_value);
+ my_decimal *val_decimal_from_time(my_decimal *decimal_value);
longlong val_int_from_decimal();
double val_real_from_decimal();
+ int save_time_in_field(Field *field);
+ int save_date_in_field(Field *field);
+
virtual Field *get_tmp_table_field() { return 0; }
/* This is also used to create fields in CREATE ... SELECT: */
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
@@ -1959,6 +1964,16 @@ public:
class Item_in_subselect;
+
+/*
+ An object of this class:
+ - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
+ - Sets owner->was_null=TRUE if it has returned a NULL value from any
+ val_XXX() function. This allows to inject an Item_ref_null_helper
+ object into subquery and then check if the subquery has produced a row
+ with NULL value.
+*/
+
class Item_ref_null_helper: public Item_ref
{
protected:
diff --git a/sql/item_buff.cc b/sql/item_buff.cc
index 1661f04a4ae..37f9ca7ce6c 100644
--- a/sql/item_buff.cc
+++ b/sql/item_buff.cc
@@ -132,11 +132,17 @@ bool Cached_item_decimal::cmp()
{
my_decimal tmp;
my_decimal *ptmp= item->val_decimal(&tmp);
- if (null_value != item->null_value || my_decimal_cmp(&value, ptmp))
+ if (null_value != item->null_value ||
+ (!item->null_value && my_decimal_cmp(&value, ptmp)))
{
null_value= item->null_value;
- my_decimal2decimal(ptmp, &value);
- return TRUE;
+ /* Save only not null values */
+ if (!null_value)
+ {
+ my_decimal2decimal(ptmp, &value);
+ return TRUE;
+ }
+ return FALSE;
}
return FALSE;
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 780d70d51dc..540f67ba0ee 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -786,9 +786,41 @@ longlong Item_in_optimizer::val_int()
{
DBUG_ASSERT(fixed == 1);
cache->store(args[0]);
+
if (cache->null_value)
{
- null_value= 1;
+ if (((Item_in_subselect*)args[1])->is_top_level_item())
+ {
+ /*
+ We're evaluating "NULL IN (SELECT ...)". The result can be NULL or
+ FALSE, and we can return one instead of another. Just return NULL.
+ */
+ null_value= 1;
+ }
+ else
+ {
+ if (!((Item_in_subselect*)args[1])->is_correlated &&
+ result_for_null_param != UNKNOWN)
+ {
+ /* Use cached value from previous execution */
+ null_value= result_for_null_param;
+ }
+ else
+ {
+ /*
+ We're evaluating "NULL IN (SELECT ...)". The result is:
+ FALSE if SELECT produces an empty set, or
+ NULL otherwise.
+ We disable the predicates we've pushed down into subselect, run the
+ subselect and see if it has produced any rows.
+ */
+ ((Item_in_subselect*)args[1])->enable_pushed_conds= FALSE;
+ longlong tmp= args[1]->val_bool_result();
+ result_for_null_param= null_value=
+ !((Item_in_subselect*)args[1])->engine->no_rows();
+ ((Item_in_subselect*)args[1])->enable_pushed_conds= TRUE;
+ }
+ }
return 0;
}
bool tmp= args[1]->val_bool_result();
@@ -1078,6 +1110,8 @@ bool Item_func_between::fix_fields(THD *thd, Item **ref)
if (Item_func_opt_neg::fix_fields(thd, ref))
return 1;
+ thd->lex->current_select->between_count++;
+
/* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
if (pred_level && !negated)
return 0;
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index f2c43833bd9..acad1e51bc9 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -100,25 +100,44 @@ public:
};
class Item_cache;
+#define UNKNOWN ((my_bool)-1)
+
+
+/*
+ Item_in_optimizer(left_expr, Item_in_subselect(...))
+
+ Item_in_optimizer is used to wrap an instance of Item_in_subselect. This
+ class does the following:
+ - Evaluate the left expression and store it in Item_cache_* object (to
+ avoid re-evaluating it many times during subquery execution)
+ - Shortcut the evaluation of "NULL IN (...)" to NULL in the cases where we
+ don't care if the result is NULL or FALSE.
+
+ NOTE
+ It is not quite clear why the above listed functionality should be
+ placed into a separate class called 'Item_in_optimizer'.
+*/
+
class Item_in_optimizer: public Item_bool_func
{
protected:
Item_cache *cache;
bool save_cache;
+ /*
+ Stores the value of "NULL IN (SELECT ...)" for uncorrelated subqueries:
+ UNKNOWN - "NULL in (SELECT ...)" has not yet been evaluated
+ FALSE - result is FALSE
+ TRUE - result is NULL
+ */
+ my_bool result_for_null_param;
public:
Item_in_optimizer(Item *a, Item_in_subselect *b):
- Item_bool_func(a, my_reinterpret_cast(Item *)(b)), cache(0), save_cache(0)
+ Item_bool_func(a, my_reinterpret_cast(Item *)(b)), cache(0),
+ save_cache(0), result_for_null_param(UNKNOWN)
{}
bool fix_fields(THD *, Item **);
bool fix_left(THD *thd, Item **ref);
bool is_null();
- /*
- Item_in_optimizer item is special boolean function. On value request
- (one of val, val_int or val_str methods) it evaluate left expression
- of IN by storing it value in cache item (one of Item_cache* items),
- then it test cache is it NULL. If left expression (cache) is NULL then
- Item_in_optimizer return NULL, else it evaluate Item_in_subselect.
- */
longlong val_int();
void cleanup();
const char *func_name() const { return "<in_optimizer>"; }
@@ -256,9 +275,11 @@ public:
class Item_maxmin_subselect;
/*
+ trigcond<param>(arg) ::= param? arg : TRUE
+
The class Item_func_trig_cond is used for guarded predicates
which are employed only for internal purposes.
- A guarded predicates is an object consisting of an a regular or
+ A guarded predicate is an object consisting of an a regular or
a guarded predicate P and a pointer to a boolean guard variable g.
A guarded predicate P/g is evaluated to true if the value of the
guard g is false, otherwise it is evaluated to the same value that
@@ -276,6 +297,10 @@ class Item_maxmin_subselect;
Objects of this class are built only for query execution after
the execution plan has been already selected. That's why this
class needs only val_int out of generic methods.
+
+ Current uses of Item_func_trig_cond objects:
+ - To wrap selection conditions when executing outer joins
+ - To wrap condition that is pushed down into subquery
*/
class Item_func_trig_cond: public Item_bool_func
@@ -446,6 +471,7 @@ public:
negated= !negated;
return this;
}
+ bool subst_argument_checker(byte **arg) { return TRUE; }
};
@@ -1018,6 +1044,11 @@ public:
/* Functions used by HAVING for rewriting IN subquery */
class Item_in_subselect;
+
+/*
+ This is like IS NOT NULL but it also remembers if it ever has
+ encountered a NULL.
+*/
class Item_is_not_null_test :public Item_func_isnull
{
Item_in_subselect* owner;
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 2e594c74031..e9f75a507a4 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2869,6 +2869,20 @@ void Item_udf_func::cleanup()
}
+void Item_udf_func::print(String *str)
+{
+ str->append(func_name());
+ str->append('(');
+ for (uint i=0 ; i < arg_count ; i++)
+ {
+ if (i != 0)
+ str->append(',');
+ args[i]->print_item_w_name(str);
+ }
+ str->append(')');
+}
+
+
double Item_func_udf_float::val_real()
{
DBUG_ASSERT(fixed == 1);
@@ -3345,6 +3359,35 @@ longlong Item_func_release_lock::val_int()
}
+bool Item_func_last_insert_id::fix_fields(THD *thd, Item **ref)
+{
+ DBUG_ASSERT(fixed == 0);
+
+ if (Item_int_func::fix_fields(thd, ref))
+ return TRUE;
+
+ if (arg_count == 0)
+ {
+ if (!thd->last_insert_id_used)
+ {
+ /*
+ As this statement calls LAST_INSERT_ID(), set
+ THD::last_insert_id_used and remember first generated insert
+ id of the previous statement in THD::current_insert_id.
+ */
+ thd->last_insert_id_used= TRUE;
+ thd->last_insert_id_used_bin_log= TRUE;
+ thd->current_insert_id= thd->last_insert_id;
+ }
+ null_value= FALSE;
+ }
+
+ thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
+
+ return FALSE;
+}
+
+
longlong Item_func_last_insert_id::val_int()
{
THD *thd= current_thd;
@@ -3354,12 +3397,13 @@ longlong Item_func_last_insert_id::val_int()
longlong value= args[0]->val_int();
thd->insert_id(value);
null_value= args[0]->null_value;
- return value; // Avoid side effect of insert_id()
+ return value;
}
- thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
- return thd->last_insert_id_used ? thd->current_insert_id : thd->insert_id();
+
+ return thd->current_insert_id;
}
+
/* This function is just used to test speed of different functions */
longlong Item_func_benchmark::val_int()
diff --git a/sql/item_func.h b/sql/item_func.h
index 177daf0311f..99f7d16855e 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -891,6 +891,7 @@ public:
if (arg_count)
max_length= args[0]->max_length;
}
+ bool fix_fields(THD *thd, Item **ref);
};
@@ -951,6 +952,7 @@ public:
Item_result result_type () const { return udf.result_type(); }
table_map not_null_tables() const { return 0; }
bool is_expensive() { return 1; }
+ void print(String *str);
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 46a96c28d88..31c2f44fc3e 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1149,12 +1149,13 @@ void Item_func_substr::fix_length_and_dec()
}
if (arg_count == 3 && args[2]->const_item())
{
- int32 length= (int32) args[2]->val_int() * collation.collation->mbmaxlen;
+ int32 length= (int32) args[2]->val_int();
if (length <= 0)
max_length=0; /* purecov: inspected */
else
set_if_smaller(max_length,(uint) length);
}
+ max_length*= collation.collation->mbmaxlen;
}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 0ad517609c9..432a8882f5f 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -37,7 +37,7 @@ inline Item * and_items(Item* cond, Item *item)
Item_subselect::Item_subselect():
Item_result_field(), value_assigned(0), thd(0), substitution(0),
engine(0), old_engine(0), used_tables_cache(0), have_to_be_excluded(0),
- const_item_cache(1), engine_changed(0), changed(0)
+ const_item_cache(1), engine_changed(0), changed(0), is_correlated(FALSE)
{
with_subselect= 1;
reset();
@@ -192,16 +192,16 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
return res;
}
-bool Item_subselect::exec()
+bool Item_subselect::exec(bool full_scan)
{
int res;
- res= engine->exec();
+ res= engine->exec(full_scan);
if (engine_changed)
{
engine_changed= 0;
- return exec();
+ return exec(full_scan);
}
return (res);
}
@@ -441,13 +441,13 @@ bool Item_singlerow_subselect::null_inside()
void Item_singlerow_subselect::bring_value()
{
- exec();
+ exec(FALSE);
}
double Item_singlerow_subselect::val_real()
{
DBUG_ASSERT(fixed == 1);
- if (!exec() && !value->null_value)
+ if (!exec(FALSE) && !value->null_value)
{
null_value= 0;
return value->val_real();
@@ -462,7 +462,7 @@ double Item_singlerow_subselect::val_real()
longlong Item_singlerow_subselect::val_int()
{
DBUG_ASSERT(fixed == 1);
- if (!exec() && !value->null_value)
+ if (!exec(FALSE) && !value->null_value)
{
null_value= 0;
return value->val_int();
@@ -476,7 +476,7 @@ longlong Item_singlerow_subselect::val_int()
String *Item_singlerow_subselect::val_str(String *str)
{
- if (!exec() && !value->null_value)
+ if (!exec(FALSE) && !value->null_value)
{
null_value= 0;
return value->val_str(str);
@@ -491,7 +491,7 @@ String *Item_singlerow_subselect::val_str(String *str)
my_decimal *Item_singlerow_subselect::val_decimal(my_decimal *decimal_value)
{
- if (!exec() && !value->null_value)
+ if (!exec(FALSE) && !value->null_value)
{
null_value= 0;
return value->val_decimal(decimal_value);
@@ -506,7 +506,7 @@ my_decimal *Item_singlerow_subselect::val_decimal(my_decimal *decimal_value)
bool Item_singlerow_subselect::val_bool()
{
- if (!exec() && !value->null_value)
+ if (!exec(FALSE) && !value->null_value)
{
null_value= 0;
return value->val_bool();
@@ -557,7 +557,8 @@ bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit)
Item_in_subselect::Item_in_subselect(Item * left_exp,
st_select_lex *select_lex):
- Item_exists_subselect(), optimizer(0), transformed(0), upper_item(0)
+ Item_exists_subselect(), optimizer(0), transformed(0),
+ enable_pushed_conds(TRUE), upper_item(0)
{
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
left_expr= left_exp;
@@ -602,7 +603,7 @@ void Item_exists_subselect::fix_length_and_dec()
double Item_exists_subselect::val_real()
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(FALSE))
{
reset();
return 0;
@@ -613,7 +614,7 @@ double Item_exists_subselect::val_real()
longlong Item_exists_subselect::val_int()
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(FALSE))
{
reset();
return 0;
@@ -624,7 +625,7 @@ longlong Item_exists_subselect::val_int()
String *Item_exists_subselect::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(FALSE))
{
reset();
return 0;
@@ -637,7 +638,7 @@ String *Item_exists_subselect::val_str(String *str)
my_decimal *Item_exists_subselect::val_decimal(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(FALSE))
{
reset();
return 0;
@@ -650,7 +651,7 @@ my_decimal *Item_exists_subselect::val_decimal(my_decimal *decimal_value)
bool Item_exists_subselect::val_bool()
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(FALSE))
{
reset();
return 0;
@@ -667,7 +668,8 @@ double Item_in_subselect::val_real()
*/
DBUG_ASSERT(0);
DBUG_ASSERT(fixed == 1);
- if (exec())
+ null_value= 0;
+ if (exec(!enable_pushed_conds))
{
reset();
null_value= 1;
@@ -687,7 +689,8 @@ longlong Item_in_subselect::val_int()
*/
DBUG_ASSERT(0);
DBUG_ASSERT(fixed == 1);
- if (exec())
+ null_value= 0;
+ if (exec(!enable_pushed_conds))
{
reset();
null_value= 1;
@@ -707,7 +710,8 @@ String *Item_in_subselect::val_str(String *str)
*/
DBUG_ASSERT(0);
DBUG_ASSERT(fixed == 1);
- if (exec())
+ null_value= 0;
+ if (exec(!enable_pushed_conds))
{
reset();
null_value= 1;
@@ -726,7 +730,8 @@ String *Item_in_subselect::val_str(String *str)
bool Item_in_subselect::val_bool()
{
DBUG_ASSERT(fixed == 1);
- if (exec())
+ null_value= 0;
+ if (exec(!enable_pushed_conds))
{
reset();
null_value= 1;
@@ -744,8 +749,9 @@ my_decimal *Item_in_subselect::val_decimal(my_decimal *decimal_value)
method should not be used
*/
DBUG_ASSERT(0);
+ null_value= 0;
DBUG_ASSERT(fixed == 1);
- if (exec())
+ if (exec(!enable_pushed_conds))
{
reset();
null_value= 1;
@@ -758,7 +764,55 @@ my_decimal *Item_in_subselect::val_decimal(my_decimal *decimal_value)
}
-/* Rewrite a single-column IN/ALL/ANY subselect. */
+/*
+ Rewrite a single-column IN/ALL/ANY subselect
+
+ SYNOPSIS
+ Item_in_subselect::single_value_transformer()
+ join Join object of the subquery (i.e. 'child' join).
+ func Subquery comparison creator
+
+ DESCRIPTION
+ Rewrite a single-column subquery using rule-based approach. The subquery
+
+ oe $cmp$ (SELECT ie FROM ... WHERE subq_where ... HAVING subq_having)
+
+ First, try to convert the subquery to scalar-result subquery in one of
+ the forms:
+
+ - oe $cmp$ (SELECT MAX(...) ) // handled by Item_singlerow_subselect
+ - oe $cmp$ <max>(SELECT ...) // handled by Item_maxmin_subselect
+
+ If that fails, the subquery will be handled with class Item_in_optimizer,
+ Inject the predicates into subquery, i.e. convert it to:
+
+ - If the subquery has aggregates, GROUP BY, or HAVING, convert to
+
+ SELECT ie FROM ... HAVING subq_having AND
+ trigcond(oe $cmp$ ref_or_null_helper<ie>)
+
+ the addition is wrapped into trigger only when we want to distinguish
+ between NULL and FALSE results.
+
+ - Otherwise (no aggregates/GROUP BY/HAVING) convert it to one of the
+ following:
+
+ = If we don't need to distinguish between NULL and FALSE subquery:
+
+ SELECT 1 FROM ... WHERE (oe $cmp$ ie) AND subq_where
+
+ = If we need to distinguish between those:
+
+ SELECT 1 FROM ...
+ WHERE subq_where AND trigcond((oe $cmp$ ie) OR (ie IS NULL))
+ HAVING trigcond(<is_not_null_test>(ie))
+
+ RETURN
+ RES_OK - OK, either subquery was transformed, or appopriate
+ predicates where injected into it.
+ RES_REDUCE - The subquery was reduced to non-subquery
+ RES_ERROR - Error
+*/
Item_subselect::trans_res
Item_in_subselect::single_value_transformer(JOIN *join,
@@ -891,8 +945,12 @@ Item_in_subselect::single_value_transformer(JOIN *join,
select_lex->uncacheable|= UNCACHEABLE_DEPENDENT;
/*
Add the left part of a subselect to a WHERE or HAVING clause of
- the right part, e.g. SELECT 1 IN (SELECT a FROM t1) =>
- SELECT Item_in_optimizer(1, SELECT a FROM t1 WHERE a=1)
+ the right part, e.g.
+
+ SELECT 1 IN (SELECT a FROM t1) =>
+
+ SELECT Item_in_optimizer(1, SELECT a FROM t1 WHERE a=1)
+
HAVING is used only if the right part contains a SUM function, a GROUP
BY or a HAVING clause.
*/
@@ -907,10 +965,15 @@ Item_in_subselect::single_value_transformer(JOIN *join,
ref_pointer_array,
(char *)"<ref>",
this->full_name()));
-#ifdef CORRECT_BUT_TOO_SLOW_TO_BE_USABLE
- if (!abort_on_null && left_expr->maybe_null)
- item= new Item_cond_or(new Item_func_isnull(left_expr), item);
-#endif
+ if (!abort_on_null && ((Item*)select_lex->item_list.head())->maybe_null)
+ {
+ /*
+ We can encounter "NULL IN (SELECT ...)". Wrap the added condition
+ within a trigger.
+ */
+ item= new Item_func_trig_cond(item, &enable_pushed_conds);
+ }
+
/*
AND and comparison functions can't be changed during fix_fields()
we can assign select_lex->having here, and pass 0 as last
@@ -939,19 +1002,19 @@ Item_in_subselect::single_value_transformer(JOIN *join,
select_lex->item_list.push_back(new Item_int("Not_used",
(longlong) 1, 21));
select_lex->ref_pointer_array[0]= select_lex->item_list.head();
+
item= func->create(expr, item);
if (!abort_on_null && orig_item->maybe_null)
{
- having= new Item_is_not_null_test(this, having);
+ having=
+ new Item_func_trig_cond(new Item_is_not_null_test(this, having),
+ &enable_pushed_conds);
/*
Item_is_not_null_test can't be changed during fix_fields()
we can assign select_lex->having here, and pass 0 as last
argument (reference) to fix_fields()
*/
- select_lex->having=
- join->having= (join->having ?
- new Item_cond_and(having, join->having) :
- having);
+ select_lex->having= join->having= having;
select_lex->having_fix_field= 1;
/*
we do not check join->having->fixed, because Item_and (from
@@ -962,12 +1025,15 @@ Item_in_subselect::single_value_transformer(JOIN *join,
select_lex->having_fix_field= 0;
if (tmp)
DBUG_RETURN(RES_ERROR);
+ /*
+ NOTE: It is important that we add this "IS NULL" here, even when
+ orig_item can't be NULL. This is needed so that this predicate is
+ only used by ref[_or_null] analyzer (and, e.g. is not used by const
+ propagation).
+ */
item= new Item_cond_or(item,
new Item_func_isnull(orig_item));
-#ifdef CORRECT_BUT_TOO_SLOW_TO_BE_USABLE
- if (left_expr->maybe_null)
- item= new Item_cond_or(new Item_func_isnull(left_expr), item);
-#endif
+ item= new Item_func_trig_cond(item, &enable_pushed_conds);
}
item->name= (char *)in_additional_cond;
/*
@@ -994,13 +1060,14 @@ Item_in_subselect::single_value_transformer(JOIN *join,
we can assign select_lex->having here, and pass 0 as last
argument (reference) to fix_fields()
*/
- select_lex->having=
- join->having=
- func->create(expr,
+ Item *new_having=
+ func->create(expr,
new Item_ref_null_helper(&select_lex->context, this,
select_lex->ref_pointer_array,
(char *)"<no matter>",
(char *)"<result>"));
+ new_having= new Item_func_trig_cond(new_having, &enable_pushed_conds);
+ select_lex->having= join->having= new_having;
select_lex->having_fix_field= 1;
/*
@@ -1205,6 +1272,8 @@ Item_in_subselect::row_value_transformer(JOIN *join)
where_item= and_items(where_item, item);
}
+ if (where_item)
+ where_item= new Item_func_trig_cond(where_item, &enable_pushed_conds);
/*
AND can't be changed during fix_fields()
we can assign select_lex->where here, and pass 0 as last
@@ -1218,6 +1287,8 @@ Item_in_subselect::row_value_transformer(JOIN *join)
if (having_item)
{
bool res;
+ having_item= new Item_func_trig_cond(having_item, &enable_pushed_conds);
+
select_lex->having= join->having= and_items(join->having, having_item);
select_lex->having->top_level_item();
/*
@@ -1434,6 +1505,27 @@ bool subselect_union_engine::is_executed() const
}
+/*
+ Check if last execution of the subquery engine produced any rows
+
+ SYNOPSIS
+ subselect_union_engine::no_rows()
+
+ DESCRIPTION
+ Check if last execution of the subquery engine produced any rows. The
+ return value is undefined if last execution ended in an error.
+
+ RETURN
+ TRUE - Last subselect execution has produced no rows
+ FALSE - Otherwise
+*/
+
+bool subselect_union_engine::no_rows()
+{
+ /* Check if we got any rows when reading UNION result from temp. table: */
+ return test(!unit->fake_select_lex->join->send_records);
+}
+
void subselect_uniquesubquery_engine::cleanup()
{
DBUG_ENTER("subselect_uniquesubquery_engine::cleanup");
@@ -1499,6 +1591,28 @@ int subselect_uniquesubquery_engine::prepare()
return 1;
}
+
+/*
+ Check if last execution of the subquery engine produced any rows
+
+ SYNOPSIS
+ subselect_single_select_engine::no_rows()
+
+ DESCRIPTION
+ Check if last execution of the subquery engine produced any rows. The
+ return value is undefined if last execution ended in an error.
+
+ RETURN
+ TRUE - Last subselect execution has produced no rows
+ FALSE - Otherwise
+*/
+
+bool subselect_single_select_engine::no_rows()
+{
+ return !item->assigned();
+}
+
+
static Item_result set_row(List<Item> &item_list, Item *item,
Item_cache **row, bool *maybe_null)
{
@@ -1552,7 +1666,11 @@ void subselect_uniquesubquery_engine::fix_length_and_dec(Item_cache **row)
DBUG_ASSERT(0);
}
-int subselect_single_select_engine::exec()
+int init_read_record_seq(JOIN_TAB *tab);
+int join_read_always_key_or_null(JOIN_TAB *tab);
+int join_read_next_same_or_null(READ_RECORD *info);
+
+int subselect_single_select_engine::exec(bool full_scan)
{
DBUG_ENTER("subselect_single_select_engine::exec");
char const *save_where= thd->where;
@@ -1590,7 +1708,43 @@ int subselect_single_select_engine::exec()
if (!executed)
{
item->reset_value_registration();
+ if (full_scan)
+ {
+ /*
+ We should not apply optimizations based on the condition that was
+ pushed down into the subquery. Those optimizations are ref[_or_null]
+ acceses. Change them to be full table scans.
+ */
+ for (uint i=join->const_tables ; i < join->tables ; i++)
+ {
+ JOIN_TAB *tab=join->join_tab+i;
+ if (tab->keyuse && tab->keyuse->outer_ref)
+ {
+ tab->read_first_record= init_read_record_seq;
+ tab->read_record.record= tab->table->record[0];
+ tab->read_record.thd= join->thd;
+ tab->read_record.ref_length= tab->table->file->ref_length;
+ }
+ }
+ }
+
join->exec();
+
+ if (full_scan)
+ {
+ /* Enable the optimizations back */
+ for (uint i=join->const_tables ; i < join->tables ; i++)
+ {
+ JOIN_TAB *tab=join->join_tab+i;
+ if (tab->keyuse && tab->keyuse->outer_ref)
+ {
+ tab->read_record.record= 0;
+ tab->read_record.ref_length= 0;
+ tab->read_first_record= join_read_always_key_or_null;
+ tab->read_record.read_record= join_read_next_same_or_null;
+ }
+ }
+ }
executed= 1;
thd->where= save_where;
thd->lex->current_select= save_select;
@@ -1601,29 +1755,159 @@ int subselect_single_select_engine::exec()
DBUG_RETURN(0);
}
-int subselect_union_engine::exec()
+int subselect_union_engine::exec(bool full_scan)
{
char const *save_where= thd->where;
+ /*
+ Ignore the full_scan parameter: the pushed down predicates are only used
+ for filtering, and the caller has disabled them if necessary.
+ */
int res= unit->exec();
thd->where= save_where;
return res;
}
-int subselect_uniquesubquery_engine::exec()
+/*
+ Search for at least on row satisfying select condition
+
+ SYNOPSIS
+ subselect_uniquesubquery_engine::scan_table()
+
+ DESCRIPTION
+ Scan the table using sequential access until we find at least one row
+ satisfying select condition.
+
+ The result of this function (info about whether a row was found) is
+ stored in this->empty_result_set.
+
+ RETURN
+ FALSE - OK
+ TRUE - Error
+*/
+
+int subselect_uniquesubquery_engine::scan_table()
{
- DBUG_ENTER("subselect_uniquesubquery_engine::exec");
int error;
TABLE *table= tab->table;
- for (store_key **copy=tab->ref.key_copy ; *copy ; copy++)
+ DBUG_ENTER("subselect_uniquesubquery_engine::scan_table");
+ empty_result_set= TRUE;
+
+ if (table->file->inited)
+ table->file->ha_index_end();
+
+ table->file->ha_rnd_init(1);
+ table->file->extra_opt(HA_EXTRA_CACHE,
+ current_thd->variables.read_buff_size);
+ table->null_row= 0;
+ for (;;)
+ {
+ error=table->file->rnd_next(table->record[0]);
+ if (error && error != HA_ERR_END_OF_FILE)
+ {
+ error= report_error(table, error);
+ break;
+ }
+ /* No more rows */
+ if (table->status)
+ break;
+
+ if (!cond || cond->val_int())
+ {
+ empty_result_set= FALSE;
+ break;
+ }
+ }
+
+ table->file->ha_rnd_end();
+ DBUG_RETURN(error != 0);
+}
+
+
+/*
+ Copy ref key and check for null parts in it
+
+ SYNOPSIS
+ subselect_uniquesubquery_engine::copy_ref_key()
+
+ DESCRIPTION
+ Copy ref key and check for null parts in it.
+
+ RETURN
+ FALSE - ok, index lookup key without keys copied.
+ TRUE - an error occured while copying the key
+*/
+
+bool subselect_uniquesubquery_engine::copy_ref_key()
+{
+ DBUG_ENTER("subselect_uniquesubquery_engine::copy_ref_key");
+
+ for (store_key **copy= tab->ref.key_copy ; *copy ; copy++)
{
- if ((tab->ref.key_err= (*copy)->copy()) & 1)
+ tab->ref.key_err= (*copy)->copy();
+
+ /*
+ When there is a NULL part in the key we don't need to make index
+ lookup for such key thus we don't need to copy whole key.
+ If we later should do a sequential scan return OK. Fail otherwise.
+
+ See also the comment for the subselect_uniquesubquery_engine::exec()
+ function.
+ */
+ null_keypart= (*copy)->null_key;
+ bool top_level= ((Item_in_subselect *) item)->is_top_level_item();
+ if (null_keypart && !top_level)
+ break;
+ if ((tab->ref.key_err) & 1 || (null_keypart && top_level))
{
- table->status= STATUS_NOT_FOUND;
+ tab->table->status= STATUS_NOT_FOUND;
DBUG_RETURN(1);
}
}
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Execute subselect
+
+ SYNOPSIS
+ subselect_uniquesubquery_engine::exec()
+
+ DESCRIPTION
+ Find rows corresponding to the ref key using index access.
+ If some part of the lookup key is NULL, then we're evaluating
+ NULL IN (SELECT ... )
+ This is a special case, we don't need to search for NULL in the table,
+ instead, the result value is
+ - NULL if select produces empty row set
+ - FALSE otherwise.
+
+ In some cases (IN subselect is a top level item, i.e. abort_on_null==TRUE)
+ the caller doesn't distinguish between NULL and FALSE result and we just
+ return FALSE.
+ Otherwise we make a full table scan to see if there is at least one matching row.
+
+ NOTE
+
+ RETURN
+ FALSE - ok
+ TRUE - an error occured while scanning
+*/
+int subselect_uniquesubquery_engine::exec(bool full_scan)
+{
+ DBUG_ENTER("subselect_uniquesubquery_engine::exec");
+ int error;
+ TABLE *table= tab->table;
+
+ /* TODO: change to use of 'full_scan' here? */
+ if (copy_ref_key())
+ DBUG_RETURN(1);
+
+ if (null_keypart)
+ DBUG_RETURN(scan_table());
+
if (!table->file->inited)
table->file->ha_index_init(tab->ref.key);
error= table->file->index_read(table->record[0],
@@ -1652,14 +1936,68 @@ subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine()
}
-int subselect_indexsubquery_engine::exec()
+/*
+ Index-lookup subselect 'engine' - run the subquery
+
+ SYNOPSIS
+ subselect_uniquesubquery_engine:exec()
+ full_scan
+
+ DESCRIPTION
+ The engine is used to resolve subqueries in form
+
+ oe IN (SELECT key FROM tbl WHERE subq_where)
+
+ The value of the predicate is calculated as follows:
+ 1. If oe IS NULL, this is a special case, do a full table scan on
+ table tbl and search for row that satisfies subq_where. If such
+ row is found, return NULL, otherwise return FALSE.
+ 2. Make an index lookup via key=oe, search for a row that satisfies
+ subq_where. If found, return TRUE.
+ 3. If check_null==TRUE, make another lookup via key=NULL, search for a
+ row that satisfies subq_where. If found, return NULL, otherwise
+ return FALSE.
+
+ TODO
+ The step #1 can be optimized further when the index has several key
+ parts. Consider a subquery:
+
+ (oe1, oe2) IN (SELECT keypart1, keypart2 FROM tbl WHERE subq_where)
+
+ and suppose we need to evaluate it for {oe1, oe2}=={const1, NULL}.
+ Current code will do a full table scan and obtain correct result. There
+ is a better option: instead of evaluating
+
+ SELECT keypart1, keypart2 FROM tbl WHERE subq_where (1)
+
+ and checking if it has produced any matching rows, evaluate
+
+ SELECT keypart2 FROM tbl WHERE subq_where AND keypart1=const1 (2)
+
+ If this query produces a row, the result is NULL (as we're evaluating
+ "(const1, NULL) IN { (const1, X), ... }", which has a value of UNKNOWN,
+ i.e. NULL). If the query produces no rows, the result is FALSE.
+
+ We currently evaluate (1) by doing a full table scan. (2) can be
+ evaluated by doing a "ref" scan on "keypart1=const1", which can be much
+ cheaper. We can use index statistics to quickly check whether "ref" scan
+ will be cheaper than full table scan.
+
+ RETURN
+ 0
+ 1
+*/
+
+int subselect_indexsubquery_engine::exec(bool full_scan)
{
- DBUG_ENTER("subselect_indexsubselect_engine::exec");
+ DBUG_ENTER("subselect_indexsubquery_engine::exec");
int error;
bool null_finding= 0;
TABLE *table= tab->table;
((Item_in_subselect *) item)->value= 0;
+ empty_result_set= TRUE;
+ null_keypart= 0;
if (check_null)
{
@@ -1668,14 +2006,12 @@ int subselect_indexsubquery_engine::exec()
((Item_in_subselect *) item)->was_null= 0;
}
- for (store_key **copy=tab->ref.key_copy ; *copy ; copy++)
- {
- if ((tab->ref.key_err= (*copy)->copy()) & 1)
- {
- table->status= STATUS_NOT_FOUND;
- DBUG_RETURN(1);
- }
- }
+ /* Copy the ref key and check for nulls... */
+ if (copy_ref_key())
+ DBUG_RETURN(1);
+
+ if (null_keypart)
+ DBUG_RETURN(scan_table());
if (!table->file->inited)
table->file->ha_index_init(tab->ref.key);
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 45df4f3880d..0c6ba055096 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -60,6 +60,9 @@ public:
/* subquery is transformed */
bool changed;
+ /* TRUE <=> The underlying SELECT is correlated w.r.t some ancestor select */
+ bool is_correlated;
+
enum trans_res {RES_OK, RES_REDUCE, RES_ERROR};
enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS,
EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS};
@@ -92,7 +95,7 @@ public:
return null_value;
}
bool fix_fields(THD *thd, Item **ref);
- virtual bool exec();
+ virtual bool exec(bool full_scan);
virtual void fix_length_and_dec();
table_map used_tables() const;
table_map not_null_tables() const { return 0; }
@@ -114,6 +117,7 @@ public:
single select and union subqueries only.
*/
bool is_evaluated() const;
+ bool is_uncacheable() const;
/*
Used by max/min subquery to initialize value presence registration
@@ -215,7 +219,20 @@ public:
friend class subselect_indexsubquery_engine;
};
-/* IN subselect */
+
+/*
+ IN subselect: this represents "left_exr IN (SELECT ...)"
+
+ This class has:
+ - (as a descendant of Item_subselect) a "subquery execution engine" which
+ allows it to evaluate subqueries. (and this class participates in
+ execution by having was_null variable where part of execution result
+ is stored.
+ - Transformation methods (todo: more on this).
+
+ This class is not used directly, it is "wrapped" into Item_in_optimizer
+ which provides some small bits of subquery evaluation.
+*/
class Item_in_subselect :public Item_exists_subselect
{
@@ -231,12 +248,14 @@ protected:
bool abort_on_null;
bool transformed;
public:
+ /* Used to trigger on/off conditions that were pushed down to subselect */
+ bool enable_pushed_conds;
Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
Item_in_subselect()
:Item_exists_subselect(), optimizer(0), abort_on_null(0), transformed(0),
- upper_item(0)
+ enable_pushed_conds(TRUE), upper_item(0)
{}
subs_type substype() { return IN_SUBS; }
@@ -256,6 +275,7 @@ public:
my_decimal *val_decimal(my_decimal *);
bool val_bool();
void top_level_item() { abort_on_null=1; }
+ inline bool is_top_level_item() { return abort_on_null; }
bool test_limit(st_select_lex_unit *unit);
void print(String *str);
bool fix_fields(THD *thd, Item **ref);
@@ -313,7 +333,28 @@ public:
THD * get_thd() { return thd; }
virtual int prepare()= 0;
virtual void fix_length_and_dec(Item_cache** row)= 0;
- virtual int exec()= 0;
+ /*
+ Execute the engine
+
+ SYNOPSIS
+ exec()
+ full_scan TRUE - Pushed-down predicates are disabled, the engine
+ must disable made based on those predicates.
+ FALSE - Pushed-down predicates are in effect.
+ DESCRIPTION
+ Execute the engine. The result of execution is subquery value that is
+ either captured by previously set up select_result-based 'sink' or
+ stored somewhere by the exec() method itself.
+
+ A required side effect: if full_scan==TRUE, subselect_engine->no_rows()
+ should return correct result.
+
+ RETURN
+ 0 - OK
+ 1 - Either an execution error, or the engine was be "changed", and
+ caller should call exec() again for the new engine.
+ */
+ virtual int exec(bool full_scan)= 0;
virtual uint cols()= 0; /* return number of columns in select */
virtual uint8 uncacheable()= 0; /* query is uncacheable */
enum Item_result type() { return res_type; }
@@ -325,6 +366,8 @@ public:
virtual bool change_result(Item_subselect *si, select_subselect *result)= 0;
virtual bool no_tables()= 0;
virtual bool is_executed() const { return FALSE; }
+ /* Check if subquery produced any rows during last query execution */
+ virtual bool no_rows() = 0;
};
@@ -342,7 +385,7 @@ public:
void cleanup();
int prepare();
void fix_length_and_dec(Item_cache** row);
- int exec();
+ int exec(bool full_scan);
uint cols();
uint8 uncacheable();
void exclude();
@@ -351,6 +394,7 @@ public:
bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
bool is_executed() const { return executed; }
+ bool no_rows();
};
@@ -364,7 +408,7 @@ public:
void cleanup();
int prepare();
void fix_length_and_dec(Item_cache** row);
- int exec();
+ int exec(bool full_scan);
uint cols();
uint8 uncacheable();
void exclude();
@@ -373,6 +417,7 @@ public:
bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
bool is_executed() const;
+ bool no_rows();
};
@@ -382,6 +427,12 @@ class subselect_uniquesubquery_engine: public subselect_engine
protected:
st_join_table *tab;
Item *cond;
+ /*
+ TRUE<=> last execution produced empty set. Valid only when left
+ expression is NULL.
+ */
+ bool empty_result_set;
+ bool null_keypart; /* TRUE <=> constructed search tuple has a NULL */
public:
// constructor can assign THD because it will be called after JOIN::prepare
@@ -395,7 +446,7 @@ public:
void cleanup();
int prepare();
void fix_length_and_dec(Item_cache** row);
- int exec();
+ int exec(bool full_scan);
uint cols() { return 1; }
uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
void exclude();
@@ -403,11 +454,15 @@ public:
void print (String *str);
bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
+ int scan_table();
+ bool copy_ref_key();
+ bool no_rows() { return empty_result_set; }
};
class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine
{
+ /* FALSE for 'ref', TRUE for 'ref-or-null'. */
bool check_null;
public:
@@ -418,7 +473,7 @@ public:
:subselect_uniquesubquery_engine(thd, tab_arg, subs, where),
check_null(chk_null)
{}
- int exec();
+ int exec(bool full_scan);
void print (String *str);
};
@@ -428,3 +483,9 @@ inline bool Item_subselect::is_evaluated() const
return engine->is_executed();
}
+inline bool Item_subselect::is_uncacheable() const
+{
+ return engine->uncacheable();
+}
+
+
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 5ca1dbba94b..fccbdfa7925 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -893,6 +893,7 @@ bool Item_sum_distinct::setup(THD *thd)
tree= new Unique(simple_raw_key_cmp, &tree_key_length, tree_key_length,
thd->variables.max_heap_table_size);
+ is_evaluated= FALSE;
DBUG_RETURN(tree == 0);
}
@@ -900,6 +901,7 @@ bool Item_sum_distinct::setup(THD *thd)
bool Item_sum_distinct::add()
{
args[0]->save_in_field(table->field[0], FALSE);
+ is_evaluated= FALSE;
if (!table->field[0]->is_null())
{
DBUG_ASSERT(tree);
@@ -929,6 +931,7 @@ void Item_sum_distinct::clear()
DBUG_ASSERT(tree != 0); /* we always have a tree */
null_value= 1;
tree->reset();
+ is_evaluated= FALSE;
DBUG_VOID_RETURN;
}
@@ -938,6 +941,7 @@ void Item_sum_distinct::cleanup()
delete tree;
tree= 0;
table= 0;
+ is_evaluated= FALSE;
}
Item_sum_distinct::~Item_sum_distinct()
@@ -949,16 +953,20 @@ Item_sum_distinct::~Item_sum_distinct()
void Item_sum_distinct::calculate_val_and_count()
{
- count= 0;
- val.traits->set_zero(&val);
- /*
- We don't have a tree only if 'setup()' hasn't been called;
- this is the case of sql_select.cc:return_zero_rows.
- */
- if (tree)
+ if (!is_evaluated)
{
- table->field[0]->set_notnull();
- tree->walk(item_sum_distinct_walk, (void*) this);
+ count= 0;
+ val.traits->set_zero(&val);
+ /*
+ We don't have a tree only if 'setup()' hasn't been called;
+ this is the case of sql_select.cc:return_zero_rows.
+ */
+ if (tree)
+ {
+ table->field[0]->set_notnull();
+ tree->walk(item_sum_distinct_walk, (void*) this);
+ }
+ is_evaluated= TRUE;
}
}
@@ -1014,9 +1022,13 @@ Item_sum_avg_distinct::fix_length_and_dec()
void
Item_sum_avg_distinct::calculate_val_and_count()
{
- Item_sum_distinct::calculate_val_and_count();
- if (count)
- val.traits->div(&val, count);
+ if (!is_evaluated)
+ {
+ Item_sum_distinct::calculate_val_and_count();
+ if (count)
+ val.traits->div(&val, count);
+ is_evaluated= TRUE;
+ }
}
@@ -2477,6 +2489,7 @@ void Item_sum_count_distinct::cleanup()
*/
delete tree;
tree= 0;
+ is_evaluated= FALSE;
if (table)
{
free_tmp_table(table->in_use, table);
@@ -2498,6 +2511,7 @@ void Item_sum_count_distinct::make_unique()
original= 0;
force_copy_fields= 1;
tree= 0;
+ is_evaluated= FALSE;
tmp_table_param= 0;
always_null= FALSE;
}
@@ -2617,6 +2631,7 @@ bool Item_sum_count_distinct::setup(THD *thd)
but this has to be handled - otherwise someone can crash
the server with a DoS attack
*/
+ is_evaluated= FALSE;
if (! tree)
return TRUE;
}
@@ -2633,8 +2648,11 @@ Item *Item_sum_count_distinct::copy_or_same(THD* thd)
void Item_sum_count_distinct::clear()
{
/* tree and table can be both null only if always_null */
+ is_evaluated= FALSE;
if (tree)
+ {
tree->reset();
+ }
else if (table)
{
table->file->extra(HA_EXTRA_NO_CACHE);
@@ -2655,6 +2673,7 @@ bool Item_sum_count_distinct::add()
if ((*field)->is_real_null(0))
return 0; // Don't count NULL
+ is_evaluated= FALSE;
if (tree)
{
/*
@@ -2680,12 +2699,14 @@ longlong Item_sum_count_distinct::val_int()
return LL(0);
if (tree)
{
- ulonglong count;
+ if (is_evaluated)
+ return count;
if (tree->elements == 0)
return (longlong) tree->elements_in_tree(); // everything fits in memory
count= 0;
tree->walk(count_distinct_walk, (void*) &count);
+ is_evaluated= TRUE;
return (longlong) count;
}
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
diff --git a/sql/item_sum.h b/sql/item_sum.h
index f1ea95214de..a2b2f7cab92 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -321,12 +321,23 @@ public:
class Item_sum_num :public Item_sum
{
+protected:
+ /*
+ val_xxx() functions may be called several times during the execution of a
+ query. Derived classes that require extensive calculation in val_xxx()
+ maintain cache of aggregate value. This variable governs the validity of
+ that cache.
+ */
+ bool is_evaluated;
public:
- Item_sum_num() :Item_sum() {}
- Item_sum_num(Item *item_par) :Item_sum(item_par) {}
- Item_sum_num(Item *a, Item* b) :Item_sum(a,b) {}
- Item_sum_num(List<Item> &list) :Item_sum(list) {}
- Item_sum_num(THD *thd, Item_sum_num *item) :Item_sum(thd, item) {}
+ Item_sum_num() :Item_sum(),is_evaluated(FALSE) {}
+ Item_sum_num(Item *item_par)
+ :Item_sum(item_par), is_evaluated(FALSE) {}
+ Item_sum_num(Item *a, Item* b) :Item_sum(a,b),is_evaluated(FALSE) {}
+ Item_sum_num(List<Item> &list)
+ :Item_sum(list), is_evaluated(FALSE) {}
+ Item_sum_num(THD *thd, Item_sum_num *item)
+ :Item_sum(thd, item),is_evaluated(item->is_evaluated) {}
bool fix_fields(THD *, Item **);
longlong val_int()
{
@@ -509,6 +520,12 @@ class Item_sum_count_distinct :public Item_sum_int
*/
Unique *tree;
/*
+ Storage for the value of count between calls to val_int() so val_int()
+ will not recalculate on each call. Validitiy of the value is stored in
+ is_evaluated.
+ */
+ longlong count;
+ /*
Following is 0 normal object and pointer to original one for copy
(to correctly free resources)
*/
@@ -525,14 +542,15 @@ class Item_sum_count_distinct :public Item_sum_int
public:
Item_sum_count_distinct(List<Item> &list)
:Item_sum_int(list), table(0), field_lengths(0), tmp_table_param(0),
- force_copy_fields(0), tree(0), original(0), always_null(FALSE)
+ force_copy_fields(0), tree(0), count(0),
+ original(0), always_null(FALSE)
{ quick_group= 0; }
Item_sum_count_distinct(THD *thd, Item_sum_count_distinct *item)
:Item_sum_int(thd, item), table(item->table),
field_lengths(item->field_lengths),
tmp_table_param(item->tmp_table_param),
- force_copy_fields(0), tree(item->tree), original(item),
- tree_key_length(item->tree_key_length),
+ force_copy_fields(0), tree(item->tree), count(item->count),
+ original(item), tree_key_length(item->tree_key_length),
always_null(item->always_null)
{}
~Item_sum_count_distinct();
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 30230005f6e..1aa93b9ba8e 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -65,7 +65,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
ltime->hour, ltime->minute, ltime->second);
break;
case TIME_MICROSECOND:
- length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06d",
+ length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06ld",
ltime->neg ? "-" : "",
ltime->hour, ltime->minute, ltime->second,
ltime->second_part);
@@ -82,7 +82,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
break;
case DATE_TIME_MICROSECOND:
length= cs->cset->snprintf(cs, buff, length,
- "%04d-%02d-%02d %02d:%02d:%02d.%06d",
+ "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
ltime->year, ltime->month, ltime->day,
ltime->hour, ltime->minute, ltime->second,
ltime->second_part);
@@ -1294,17 +1294,6 @@ String *Item_date::val_str(String *str)
}
-int Item_date::save_in_field(Field *field, bool no_conversions)
-{
- TIME ltime;
- if (get_date(&ltime, TIME_FUZZY_DATE))
- return set_field_to_null(field);
- field->set_notnull();
- field->store_time(&ltime, MYSQL_TIMESTAMP_DATE);
- return 0;
-}
-
-
longlong Item_date::val_int()
{
DBUG_ASSERT(fixed == 1);
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index d5d3efeeab4..29978cf60a3 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -339,12 +339,20 @@ public:
decimals=0;
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
- int save_in_field(Field *to, bool no_conversions);
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
}
bool result_as_longlong() { return TRUE; }
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_date(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_date_in_field(field);
+ }
};
@@ -361,21 +369,57 @@ public:
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
}
bool result_as_longlong() { return TRUE; }
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_date(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_date_in_field(field);
+ }
+};
+
+
+class Item_str_timefunc :public Item_str_func
+{
+public:
+ Item_str_timefunc() :Item_str_func() {}
+ Item_str_timefunc(Item *a) :Item_str_func(a) {}
+ Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
+ Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
+ enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
+ void fix_length_and_dec()
+ {
+ decimals=0;
+ max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+ }
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
+ }
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_time(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_time_in_field(field);
+ }
};
/* Abstract CURTIME function. Children should define what time zone is used */
-class Item_func_curtime :public Item_func
+class Item_func_curtime :public Item_str_timefunc
{
longlong value;
char buff[9*2+32];
uint buff_length;
public:
- Item_func_curtime() :Item_func() {}
- Item_func_curtime(Item *a) :Item_func(a) {}
- enum Item_result result_type () const { return STRING_RESULT; }
- enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
+ Item_func_curtime() :Item_str_timefunc() {}
+ Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
String *val_str(String *str);
@@ -602,10 +646,10 @@ class Item_func_convert_tz :public Item_date_func
};
-class Item_func_sec_to_time :public Item_str_func
+class Item_func_sec_to_time :public Item_str_timefunc
{
public:
- Item_func_sec_to_time(Item *item) :Item_str_func(item) {}
+ Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
double val_real()
{
DBUG_ASSERT(fixed == 1);
@@ -615,17 +659,12 @@ public:
String *val_str(String *);
void fix_length_and_dec()
{
+ Item_str_timefunc::fix_length_and_dec();
collation.set(&my_charset_bin);
maybe_null=1;
decimals= DATETIME_DEC;
- max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
- enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
const char *func_name() const { return "sec_to_time"; }
- Field *tmp_table_field(TABLE *t_arg)
- {
- return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
- }
bool result_as_longlong() { return TRUE; }
};
@@ -759,6 +798,15 @@ public:
}
bool result_as_longlong() { return TRUE; }
longlong val_int();
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_date(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_date_in_field(field);
+ }
};
@@ -777,6 +825,15 @@ public:
}
bool result_as_longlong() { return TRUE; }
longlong val_int();
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_time(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_time_in_field(field);
+ }
};
@@ -794,12 +851,21 @@ public:
}
bool result_as_longlong() { return TRUE; }
longlong val_int();
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_date(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_date_in_field(field);
+ }
};
-class Item_func_makedate :public Item_str_func
+class Item_func_makedate :public Item_date_func
{
public:
- Item_func_makedate(Item *a,Item *b) :Item_str_func(a,b) {}
+ Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
String *val_str(String *str);
const char *func_name() const { return "makedate"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
@@ -812,8 +878,16 @@ public:
{
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
}
- bool result_as_longlong() { return TRUE; }
longlong val_int();
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return val_decimal_from_date(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_date_in_field(field);
+ }
};
@@ -845,45 +919,46 @@ public:
}
void print(String *str);
const char *func_name() const { return "add_time"; }
+ my_decimal *val_decimal(my_decimal *decimal_value)
+ {
+ DBUG_ASSERT(fixed == 1);
+ if (cached_field_type == MYSQL_TYPE_TIME)
+ return val_decimal_from_time(decimal_value);
+ if (cached_field_type == MYSQL_TYPE_DATETIME)
+ return val_decimal_from_date(decimal_value);
+ return Item_str_func::val_decimal(decimal_value);
+ }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ if (cached_field_type == MYSQL_TYPE_TIME)
+ return save_time_in_field(field);
+ if (cached_field_type == MYSQL_TYPE_DATETIME)
+ return save_date_in_field(field);
+ return Item_str_func::save_in_field(field, no_conversions);
+ }
};
-class Item_func_timediff :public Item_str_func
+class Item_func_timediff :public Item_str_timefunc
{
public:
Item_func_timediff(Item *a, Item *b)
- :Item_str_func(a, b) {}
+ :Item_str_timefunc(a, b) {}
String *val_str(String *str);
const char *func_name() const { return "timediff"; }
- enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
void fix_length_and_dec()
{
- decimals=0;
- max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+ Item_str_timefunc::fix_length_and_dec();
maybe_null= 1;
}
- Field *tmp_table_field(TABLE *t_arg)
- {
- return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
- }
};
-class Item_func_maketime :public Item_str_func
+class Item_func_maketime :public Item_str_timefunc
{
public:
Item_func_maketime(Item *a, Item *b, Item *c)
- :Item_str_func(a, b ,c) {}
+ :Item_str_timefunc(a, b ,c) {}
String *val_str(String *str);
const char *func_name() const { return "maketime"; }
- enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
- void fix_length_and_dec()
- {
- decimals=0;
- max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
- }
- Field *tmp_table_field(TABLE *t_arg)
- {
- return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
- }
};
class Item_func_microsecond :public Item_int_func
diff --git a/sql/key.cc b/sql/key.cc
index 75161e4f616..5e658312352 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -18,6 +18,7 @@
/* Functions to handle keys and fields in forms */
#include "mysql_priv.h"
+#include "sql_trigger.h"
/*
** Search after with key field is. If no key starts with field test
@@ -342,12 +343,24 @@ void key_unpack(String *to,TABLE *table,uint idx)
/*
- Return 1 if any field in a list is part of key or the key uses a field
- that is automaticly updated (like a timestamp)
+ Check if key uses field that is listed in passed field list or is
+ automatically updated (like a timestamp) or can be updated by before
+ update trigger defined on the table.
+
+ SYNOPSIS
+ is_key_used()
+ table TABLE object with which keys and fields are associated.
+ idx Key to be checked.
+ fields List of fields to be checked.
+
+ RETURN VALUE
+ TRUE Key uses field which meets one the above conditions
+ FALSE Otherwise
*/
-bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields)
+bool is_key_used(TABLE *table, uint idx, List<Item> &fields)
{
+ Table_triggers_list *triggers= table->triggers;
List_iterator_fast<Item> f(fields);
KEY_PART_INFO *key_part,*key_part_end;
for (key_part=table->key_info[idx].key_part,key_part_end=key_part+
@@ -366,6 +379,9 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields)
if (key_part->field->eq(field->field))
return 1;
}
+ if (triggers &&
+ triggers->is_updated_in_before_update_triggers(key_part->field))
+ return 1;
}
/*
@@ -374,7 +390,7 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields)
*/
if (idx != table->s->primary_key && table->s->primary_key < MAX_KEY &&
(table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
- return check_if_key_used(table, table->s->primary_key, fields);
+ return is_key_used(table, table->s->primary_key, fields);
return 0;
}
diff --git a/sql/log.cc b/sql/log.cc
index 1cd01865f9f..960fc4f60c2 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -566,15 +566,18 @@ bool MYSQL_LOG::open(const char *log_name,
case LOG_NORMAL:
{
char *end;
- int len=my_snprintf(buff, sizeof(buff), "%s, Version: %s. "
+ int len=my_snprintf(buff, sizeof(buff), "%s, Version: %s (%s). "
#ifdef EMBEDDED_LIBRARY
- "embedded library\n", my_progname, server_version
+ "embedded library\n",
+ my_progname, server_version, MYSQL_COMPILATION_COMMENT
#elif __NT__
"started with:\nTCP Port: %d, Named Pipe: %s\n",
- my_progname, server_version, mysqld_port, mysqld_unix_port
+ my_progname, server_version, MYSQL_COMPILATION_COMMENT,
+ mysqld_port, mysqld_unix_port
#else
"started with:\nTcp port: %d Unix socket: %s\n",
- my_progname,server_version,mysqld_port,mysqld_unix_port
+ my_progname, server_version, MYSQL_COMPILATION_COMMENT,
+ mysqld_port, mysqld_unix_port
#endif
);
end=strnmov(buff+len,"Time Id Command Argument\n",
@@ -1702,7 +1705,7 @@ bool MYSQL_LOG::write(Log_event *event_info)
if (thd)
{
- if (thd->last_insert_id_used)
+ if (thd->last_insert_id_used_bin_log)
{
Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
thd->current_insert_id);
@@ -1994,7 +1997,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
tmp_errno=errno;
strmov(db,thd->db);
}
- if (thd->last_insert_id_used)
+ if (thd->last_insert_id_used_bin_log)
{
end=strmov(end,",last_insert_id=");
end=longlong10_to_str((longlong) thd->current_insert_id,end,-10);
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 219434ab218..271658d8054 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -3365,7 +3365,6 @@ int Intvar_log_event::exec_event(struct st_relay_log_info* rli)
{
switch (type) {
case LAST_INSERT_ID_EVENT:
- thd->last_insert_id_used = 1;
thd->last_insert_id = val;
break;
case INSERT_ID_EVENT:
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 1bd16940b47..f33609e0168 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -15,6 +15,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysql_priv.h"
+#include <time.h>
+
#ifndef MYSQL_CLIENT
/*
@@ -190,6 +192,23 @@ int str2my_decimal(uint mask, const char *from, uint length,
}
+my_decimal *date2my_decimal(TIME *ltime, my_decimal *dec)
+{
+ longlong date;
+ date = (ltime->year*100L + ltime->month)*100L + ltime->day;
+ if (ltime->time_type > MYSQL_TIMESTAMP_DATE)
+ date= ((date*100L + ltime->hour)*100L+ ltime->minute)*100L + ltime->second;
+ if (int2my_decimal(E_DEC_FATAL_ERROR, date, FALSE, dec))
+ return dec;
+ if (ltime->second_part)
+ {
+ dec->buf[(dec->intg-1) / 9 + 1]= ltime->second_part * 1000;
+ dec->frac= 6;
+ }
+ return dec;
+}
+
+
#ifndef DBUG_OFF
/* routines for debugging print */
diff --git a/sql/my_decimal.h b/sql/my_decimal.h
index b02abacf0a3..af3edade8d6 100644
--- a/sql/my_decimal.h
+++ b/sql/my_decimal.h
@@ -295,7 +295,12 @@ int string2my_decimal(uint mask, const String *str, my_decimal *d)
{
return str2my_decimal(mask, str->ptr(), str->length(), str->charset(), d);
}
-#endif
+
+
+my_decimal *date2my_decimal(TIME *ltime, my_decimal *dec);
+
+
+#endif /*defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) */
inline
int double2my_decimal(uint mask, double val, my_decimal *d)
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index ff04022b110..a556f190fdf 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -131,7 +131,18 @@ MY_LOCALE *my_locale_by_name(const char *name);
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
#define MAX_FIELDS_BEFORE_HASH 32
#define USER_VARS_HASH_SIZE 16
-#define STACK_MIN_SIZE 8192 // Abort if less stack during eval.
+
+/*
+ Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
+ Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
+ 100 bytes as reasonable buffer against growth and other environments'
+ requirements.)
+
+ Feel free to raise this by the smallest amount you can to get the
+ "execution_constants" test to pass.
+ */
+#define STACK_MIN_SIZE 10788 // Abort if less stack during eval.
+
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
#define STACK_BUFF_ALLOC 256 // For stack overrun checks
#ifndef MYSQLD_NET_RETRY_COUNT
@@ -648,6 +659,9 @@ int quick_rm_table(enum db_type base,const char *db,
const char *table_name);
void close_cached_table(THD *thd, TABLE *table);
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list);
+bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
+ char *new_table_name, char *new_table_alias,
+ bool skip_error);
bool mysql_change_db(THD *thd,const char *name,bool no_access_check);
void mysql_parse(THD *thd,char *inBuf,uint length);
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
@@ -711,7 +725,8 @@ bool mysql_xa_recover(THD *thd);
bool check_simple_select();
-SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length);
+SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
+ SORT_FIELD *sortorder);
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List <Item> &all_fields, ORDER *order);
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
@@ -1114,17 +1129,17 @@ void key_restore(byte *to_record, byte *from_key, KEY *key_info,
uint key_length);
bool key_cmp_if_same(TABLE *form,const byte *key,uint index,uint key_length);
void key_unpack(String *to,TABLE *form,uint index);
-bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields);
+bool is_key_used(TABLE *table, uint idx, List<Item> &fields);
int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length);
bool init_errmessage(void);
void sql_perror(const char *message);
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
-void sql_print_error(const char *format, ...);
-void sql_print_warning(const char *format, ...);
-void sql_print_information(const char *format, ...);
-
+void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
+void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
+void sql_print_information(const char *format, ...)
+ ATTRIBUTE_FORMAT(printf, 1, 2);
bool fn_format_relative_to_data_home(my_string to, const char *name,
@@ -1229,7 +1244,6 @@ extern my_bool opt_log_queries_not_using_indexes;
extern bool opt_disable_networking, opt_skip_show_db;
extern my_bool opt_character_set_client_handshake;
extern bool volatile abort_loop, shutdown_in_progress, grant_option;
-extern bool mysql_proc_table_exists;
extern uint volatile thread_count, thread_running, global_read_lock;
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
extern my_bool opt_safe_show_db, opt_local_infile;
@@ -1461,7 +1475,7 @@ void end_read_record(READ_RECORD *info);
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
uint s_length, SQL_SELECT *select,
ha_rows max_rows, ha_rows *examined_rows);
-void filesort_free_buffers(TABLE *table);
+void filesort_free_buffers(TABLE *table, bool full);
void change_double_for_sort(double nr,byte *to);
double my_double_round(double value, int dec, bool truncate);
int get_quick_record(SQL_SELECT *select);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 8a4f212340d..1dd15398cd1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1025,8 +1025,8 @@ extern "C" sig_handler print_signal_warning(int sig)
if (!DBUG_IN_USE)
{
if (global_system_variables.log_warnings)
- sql_print_warning("Got signal %d from thread %d",
- sig,my_thread_id());
+ sql_print_warning("Got signal %d from thread %ld",
+ sig, my_thread_id());
}
#ifdef DONT_REMEMBER_SIGNAL
my_sigset(sig,print_signal_warning); /* int. thread system calls */
@@ -1531,8 +1531,8 @@ static void network_init(void)
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);
+ sql_print_error("The socket file path is too long (> %lu): %s",
+ sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
unireg_abort(1);
}
if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
@@ -2912,7 +2912,7 @@ static void openssl_lock(int mode, openssl_lock_t *lock, const char *file,
}
if (err)
{
- sql_print_error("Fatal: can't %s OpenSSL %s lock", what);
+ sql_print_error("Fatal: can't %s OpenSSL lock", what);
abort();
}
}
@@ -7042,14 +7042,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
exit(1);
}
switch (method-1) {
- case 0:
- method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
+ case 2:
+ method_conv= MI_STATS_METHOD_IGNORE_NULLS;
break;
case 1:
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
break;
- case 2:
- method_conv= MI_STATS_METHOD_IGNORE_NULLS;
+ case 0:
+ default:
+ method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
break;
}
global_system_variables.myisam_stats_method= method_conv;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 79cfbc72fe7..d68ea0abfe7 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -5559,8 +5559,9 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
ulong count=count_key_part_usage(root,pos->next_key_part);
if (count > pos->next_key_part->use_count)
{
- sql_print_information("Use_count: Wrong count for key at 0x%lx, %lu should be %lu",
- pos,pos->next_key_part->use_count,count);
+ sql_print_information("Use_count: Wrong count for key at 0x%lx, %lu "
+ "should be %lu", (long unsigned int)pos,
+ pos->next_key_part->use_count, count);
return;
}
pos->next_key_part->test_use_count(root);
@@ -5568,7 +5569,7 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
}
if (e_count != elements)
sql_print_warning("Wrong use count: %u (should be %u) for tree at 0x%lx",
- e_count, elements, (gptr) this);
+ e_count, elements, (long unsigned int) this);
}
#endif
@@ -6127,42 +6128,42 @@ static bool null_part_in_key(KEY_PART *key_part, const char *key, uint length)
}
-bool QUICK_SELECT_I::check_if_keys_used(List<Item> *fields)
+bool QUICK_SELECT_I::is_keys_used(List<Item> *fields)
{
- return check_if_key_used(head, index, *fields);
+ return is_key_used(head, index, *fields);
}
-bool QUICK_INDEX_MERGE_SELECT::check_if_keys_used(List<Item> *fields)
+bool QUICK_INDEX_MERGE_SELECT::is_keys_used(List<Item> *fields)
{
QUICK_RANGE_SELECT *quick;
List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
while ((quick= it++))
{
- if (check_if_key_used(head, quick->index, *fields))
+ if (is_key_used(head, quick->index, *fields))
return 1;
}
return 0;
}
-bool QUICK_ROR_INTERSECT_SELECT::check_if_keys_used(List<Item> *fields)
+bool QUICK_ROR_INTERSECT_SELECT::is_keys_used(List<Item> *fields)
{
QUICK_RANGE_SELECT *quick;
List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
while ((quick= it++))
{
- if (check_if_key_used(head, quick->index, *fields))
+ if (is_key_used(head, quick->index, *fields))
return 1;
}
return 0;
}
-bool QUICK_ROR_UNION_SELECT::check_if_keys_used(List<Item> *fields)
+bool QUICK_ROR_UNION_SELECT::is_keys_used(List<Item> *fields)
{
QUICK_SELECT_I *quick;
List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
while ((quick= it++))
{
- if (quick->check_if_keys_used(fields))
+ if (quick->is_keys_used(fields))
return 1;
}
return 0;
@@ -8371,6 +8372,7 @@ TRP_GROUP_MIN_MAX::make_quick(PARAM *param, bool retrieve_full_rows,
quick->quick_prefix_select= NULL;
quick->update_key_stat();
+ quick->adjust_prefix_ranges();
DBUG_RETURN(quick);
}
@@ -8601,6 +8603,42 @@ bool QUICK_GROUP_MIN_MAX_SELECT::add_range(SEL_ARG *sel_range)
/*
+ Opens the ranges if there are more conditions in quick_prefix_select than
+ the ones used for jumping through the prefixes.
+
+ SYNOPSIS
+ QUICK_GROUP_MIN_MAX_SELECT::adjust_prefix_ranges()
+
+ NOTES
+ quick_prefix_select is made over the conditions on the whole key.
+ It defines a number of ranges of length x.
+ However when jumping through the prefixes we use only the the first
+ few most significant keyparts in the range key. However if there
+ are more keyparts to follow the ones we are using we must make the
+ condition on the key inclusive (because x < "ab" means
+ x[0] < 'a' OR (x[0] == 'a' AND x[1] < 'b').
+ To achive the above we must turn off the NEAR_MIN/NEAR_MAX
+*/
+void QUICK_GROUP_MIN_MAX_SELECT::adjust_prefix_ranges ()
+{
+ if (quick_prefix_select &&
+ group_prefix_len < quick_prefix_select->max_used_key_length)
+ {
+ DYNAMIC_ARRAY *arr;
+ uint inx;
+
+ for (inx= 0, arr= &quick_prefix_select->ranges; inx < arr->elements; inx++)
+ {
+ QUICK_RANGE *range;
+
+ get_dynamic(arr, (gptr)&range, inx);
+ range->flag &= ~(NEAR_MIN | NEAR_MAX);
+ }
+ }
+}
+
+
+/*
Determine the total number and length of the keys that will be used for
index lookup.
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 9474f2d469f..ddc959f1cdf 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -225,8 +225,9 @@ public:
Return 1 if any index used by this quick select
a) uses field that is listed in passed field list or
b) is automatically updated (like a timestamp)
+ c) can be updated by one of before update triggers defined on table
*/
- virtual bool check_if_keys_used(List<Item> *fields);
+ virtual bool is_keys_used(List<Item> *fields);
/*
rowid of last row retrieved by this quick select. This is used only when
@@ -294,6 +295,7 @@ protected:
friend class QUICK_SELECT_DESC;
friend class QUICK_INDEX_MERGE_SELECT;
friend class QUICK_ROR_INTERSECT_SELECT;
+ friend class QUICK_GROUP_MIN_MAX_SELECT;
DYNAMIC_ARRAY ranges; /* ordered array of range ptrs */
QUICK_RANGE **cur_range; /* current element in ranges */
@@ -423,7 +425,7 @@ public:
int get_type() { return QS_TYPE_INDEX_MERGE; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
- bool check_if_keys_used(List<Item> *fields);
+ bool is_keys_used(List<Item> *fields);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
@@ -482,7 +484,7 @@ public:
int get_type() { return QS_TYPE_ROR_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
- bool check_if_keys_used(List<Item> *fields);
+ bool is_keys_used(List<Item> *fields);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
@@ -536,7 +538,7 @@ public:
int get_type() { return QS_TYPE_ROR_UNION; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void add_info_string(String *str);
- bool check_if_keys_used(List<Item> *fields);
+ bool is_keys_used(List<Item> *fields);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
@@ -642,6 +644,7 @@ public:
~QUICK_GROUP_MIN_MAX_SELECT();
bool add_range(SEL_ARG *sel_range);
void update_key_stat();
+ void adjust_prefix_ranges();
bool alloc_buffers();
int init();
int reset();
diff --git a/sql/records.cc b/sql/records.cc
index b352f9f395a..78473659b22 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -20,7 +20,7 @@
#include "mysql_priv.h"
static int rr_quick(READ_RECORD *info);
-static int rr_sequential(READ_RECORD *info);
+int rr_sequential(READ_RECORD *info);
static int rr_from_tempfile(READ_RECORD *info);
static int rr_unpack_from_tempfile(READ_RECORD *info);
static int rr_unpack_from_buffer(READ_RECORD *info);
@@ -184,6 +184,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
} /* init_read_record */
+
void end_read_record(READ_RECORD *info)
{ /* free cache if used */
if (info->cache)
@@ -193,7 +194,7 @@ void end_read_record(READ_RECORD *info)
}
if (info->table)
{
- filesort_free_buffers(info->table);
+ filesort_free_buffers(info->table,0);
(void) info->file->extra(HA_EXTRA_NO_CACHE);
if (info->read_record != rr_quick) // otherwise quick_range does it
(void) info->file->ha_index_or_rnd_end();
@@ -289,7 +290,7 @@ static int rr_index(READ_RECORD *info)
}
-static int rr_sequential(READ_RECORD *info)
+int rr_sequential(READ_RECORD *info)
{
int tmp;
while ((tmp=info->file->rnd_next(info->record)))
diff --git a/sql/set_var.cc b/sql/set_var.cc
index c667e2f2bcc..d0268d7017b 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -1255,8 +1255,8 @@ static void fix_tx_isolation(THD *thd, enum_var_type type)
thd->variables.tx_isolation);
}
-static void fix_completion_type(THD *thd __attribute__(unused),
- enum_var_type type __attribute__(unused)) {}
+static void fix_completion_type(THD *thd __attribute__((unused)),
+ enum_var_type type __attribute__((unused))) {}
static int check_completion_type(THD *thd, set_var *var)
{
@@ -1295,14 +1295,14 @@ static void fix_net_retry_count(THD *thd, enum_var_type type)
thd->net.retry_count=thd->variables.net_retry_count;
}
#else /* HAVE_REPLICATION */
-static void fix_net_read_timeout(THD *thd __attribute__(unused),
- enum_var_type type __attribute__(unused))
+static void fix_net_read_timeout(THD *thd __attribute__((unused)),
+ enum_var_type type __attribute__((unused)))
{}
-static void fix_net_write_timeout(THD *thd __attribute__(unused),
- enum_var_type type __attribute__(unused))
+static void fix_net_write_timeout(THD *thd __attribute__((unused)),
+ enum_var_type type __attribute__((unused)))
{}
-static void fix_net_retry_count(THD *thd __attribute__(unused),
- enum_var_type type __attribute__(unused))
+static void fix_net_retry_count(THD *thd __attribute__((unused)),
+ enum_var_type type __attribute__((unused)))
{}
#endif /* HAVE_REPLICATION */
@@ -2571,8 +2571,18 @@ bool sys_var_last_insert_id::update(THD *thd, set_var *var)
byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type,
LEX_STRING *base)
{
- thd->sys_var_tmp.long_value= (long) thd->insert_id();
- return (byte*) &thd->last_insert_id;
+ if (!thd->last_insert_id_used)
+ {
+ /*
+ As this statement reads @@LAST_INSERT_ID, set
+ THD::last_insert_id_used and remember first generated insert id
+ of the previous statement in THD::current_insert_id.
+ */
+ thd->last_insert_id_used= TRUE;
+ thd->last_insert_id_used_bin_log= TRUE;
+ thd->current_insert_id= thd->last_insert_id;
+ }
+ return (byte*) &thd->current_insert_id;
}
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index c3657e8246d..2b6d2b18f88 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -3813,7 +3813,7 @@ ER_WRONG_MRG_TABLE
cze "V-B¹echny tabulky v MERGE tabulce nejsou definovány stejnì"
dan "Tabellerne i MERGE er ikke defineret ens"
nla "Niet alle tabellen in de MERGE tabel hebben identieke gedefinities"
- eng "All tables in the MERGE table are not identically defined"
+ eng "Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist"
est "Kõik tabelid MERGE tabeli määratluses ei ole identsed"
fre "Toutes les tables de la table de type MERGE n'ont pas la même définition"
ger "Nicht alle Tabellen in der MERGE-Tabelle sind gleich definiert"
diff --git a/sql/slave.cc b/sql/slave.cc
index 55cff94a179..28bb7f12008 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -4613,7 +4613,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
suppress_warnings= 0;
sql_print_error("Slave I/O thread: error %s to master \
'%s@%s:%d': \
-Error: '%s' errno: %d retry-time: %d retries: %d",
+Error: '%s' errno: %d retry-time: %d retries: %lu",
(reconnect ? "reconnecting" : "connecting"),
mi->user,mi->host,mi->port,
mysql_error(mysql), last_errno,
diff --git a/sql/slave.h b/sql/slave.h
index c355f7172a9..65adb4564cc 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -553,7 +553,8 @@ void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
const char *print_slave_db_safe(const char *db);
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
void skip_load_data_infile(NET* net);
-void slave_print_error(RELAY_LOG_INFO* rli, int err_code, const char* msg, ...);
+void slave_print_error(RELAY_LOG_INFO *rli, int err_code, const char *msg, ...)
+ ATTRIBUTE_FORMAT(printf, 3, 4);
void end_slave(); /* clean up */
void init_master_info_with_options(MASTER_INFO* mi);
diff --git a/sql/sp.cc b/sql/sp.cc
index fc72822c15e..49dbed79fe5 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -66,8 +66,6 @@ enum
MYSQL_PROC_FIELD_COUNT
};
-bool mysql_proc_table_exists= 1;
-
/* Tells what SP_DEFAULT_ACCESS should be mapped to */
#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
@@ -119,13 +117,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
bool not_used;
DBUG_ENTER("open_proc_table");
- /*
- Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists
- is set when we create or read stored procedure or on flush privileges.
- */
- if (!mysql_proc_table_exists)
- DBUG_RETURN(0);
-
thd->reset_n_backup_open_tables_state(backup);
bzero((char*) &tables, sizeof(tables));
@@ -135,7 +126,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
MYSQL_LOCK_IGNORE_FLUSH)))
{
thd->restore_backup_open_tables_state(backup);
- mysql_proc_table_exists= 0;
DBUG_RETURN(0);
}
@@ -184,15 +174,6 @@ static TABLE *open_proc_table_for_update(THD *thd)
table= open_ltable(thd, &tables, TL_WRITE);
- /*
- Under explicit LOCK TABLES or in prelocked mode we should not
- say that mysql.proc table does not exist if we are unable to
- open and lock it for writing since this condition may be
- transient.
- */
- if (!(thd->locked_tables || thd->prelocked_mode) || table)
- mysql_proc_table_exists= test(table);
-
DBUG_RETURN(table);
}
@@ -1610,14 +1591,6 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
case SP_KEY_NOT_FOUND:
ret= SP_OK;
break;
- case SP_OPEN_TABLE_FAILED:
- /*
- Force it to attempt opening it again on subsequent calls;
- otherwise we will get one error message the first time, and
- then ER_SP_PROC_TABLE_CORRUPT (below) on subsequent tries.
- */
- mysql_proc_table_exists= 1;
- /* Fall through */
default:
/*
Any error when loading an existing routine is either some problem
@@ -1633,7 +1606,17 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
*/
if (!thd->net.report_error)
{
- char n[NAME_LEN*2+2];
+ /*
+ SP allows full NAME_LEN chars thus he have to allocate enough
+ size in bytes. Otherwise there is stack overrun could happen
+ if multibyte sequence is `name`. `db` is still safe because the
+ rest of the server checks agains NAME_LEN bytes and not chars.
+ Hence, the overrun happens only if the name is in length > 32 and
+ uses multibyte (cyrillic, greek, etc.)
+
+ !! Change 3 with SYSTEM_CHARSET_MBMAXLEN when it's defined.
+ */
+ char n[NAME_LEN*3*2+2];
/* m_qname.str is not always \0 terminated */
memcpy(n, name.m_qname.str, name.m_qname.length);
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index e6170cae994..50cee6eeca4 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -202,7 +202,6 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
DBUG_ENTER("acl_load");
grant_version++; /* Privileges updated */
- mysql_proc_table_exists= 1; // Assume mysql.proc exists
acl_cache->clear(1); // Clear locked hostname cache
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index af9246c673a..62b6d4f7920 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -807,9 +807,9 @@ void field_str::get_opt_type(String *answer, ha_rows total_rows)
else if (num_info.decimals) // DOUBLE(%d,%d) sometime
{
if (num_info.dval > -FLT_MAX && num_info.dval < FLT_MAX)
- sprintf(buff, "FLOAT(%d,%d)", num_info.integers, num_info.decimals);
+ sprintf(buff, "FLOAT(%d,%d)", (num_info.integers + num_info.decimals), num_info.decimals);
else
- sprintf(buff, "DOUBLE(%d,%d)", num_info.integers, num_info.decimals);
+ sprintf(buff, "DOUBLE(%d,%d)", (num_info.integers + num_info.decimals), num_info.decimals);
}
else if (ev_num_info.llval >= -128 &&
ev_num_info.ullval <=
@@ -916,10 +916,10 @@ void field_real::get_opt_type(String *answer,
else
{
if (min_arg >= -FLT_MAX && max_arg <= FLT_MAX)
- sprintf(buff, "FLOAT(%d,%d)", (int) max_length - (item->decimals + 1),
+ sprintf(buff, "FLOAT(%d,%d)", (int) max_length - (item->decimals + 1) + max_notzero_dec_len,
max_notzero_dec_len);
else
- sprintf(buff, "DOUBLE(%d,%d)", (int) max_length - (item->decimals + 1),
+ sprintf(buff, "DOUBLE(%d,%d)", (int) max_length - (item->decimals + 1) + max_notzero_dec_len,
max_notzero_dec_len);
answer->append(buff, (uint) strlen(buff));
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 85be84d1270..3984ceac6a9 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1478,6 +1478,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->file->ft_handler= 0;
if (table->timestamp_field)
table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
+ table->pos_in_table_list= table_list;
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
DBUG_ASSERT(table->key_read == 0);
DBUG_RETURN(table);
@@ -2762,6 +2763,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
if (thd->slave_thread)
slave_open_temp_tables++;
}
+ tmp_table->pos_in_table_list= 0;
DBUG_RETURN(tmp_table);
}
@@ -3450,13 +3452,20 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
const char *field_name=0;
const char *table_name=0;
bool found_unaliased_non_uniq= 0;
+ /*
+ true if the item that we search for is a valid name reference
+ (and not an item that happens to have a name).
+ */
+ bool is_ref_by_name= 0;
uint unaliased_counter;
LINT_INIT(unaliased_counter); // Dependent on found_unaliased
*unaliased= FALSE;
- if (find->type() == Item::FIELD_ITEM || find->type() == Item::REF_ITEM)
+ is_ref_by_name= (find->type() == Item::FIELD_ITEM ||
+ find->type() == Item::REF_ITEM);
+ if (is_ref_by_name)
{
field_name= ((Item_ident*) find)->field_name;
table_name= ((Item_ident*) find)->table_name;
@@ -3568,7 +3577,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
}
}
else if (!table_name && (find->eq(item,0) ||
- find->name && item->name &&
+ is_ref_by_name && find->name && item->name &&
!my_strcasecmp(system_charset_info,
item->name,find->name)))
{
@@ -4899,6 +4908,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
thd->set_query_id=1;
select_lex->cond_count= 0;
+ select_lex->between_count= 0;
for (table= tables; table; table= table->next_local)
{
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 093173ab949..645ac6e28f3 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -179,9 +179,9 @@ THD::THD()
lock_id(&main_lock_id),
user_time(0), in_sub_stmt(0), global_read_lock(0), is_fatal_error(0),
rand_used(0), time_zone_used(0),
- last_insert_id_used(0), insert_id_used(0), clear_next_insert_id(0),
- in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE),
- spcont(NULL)
+ last_insert_id_used(0), last_insert_id_used_bin_log(0), insert_id_used(0),
+ clear_next_insert_id(0), in_lock_tables(0), bootstrap(0),
+ derived_tables_processing(FALSE), spcont(NULL)
{
stmt_arena= this;
thread_stack= 0;
@@ -553,10 +553,25 @@ bool THD::store_globals()
}
-/* Cleanup after a query */
+/*
+ Cleanup after query.
+
+ SYNOPSIS
+ THD::cleanup_after_query()
+
+ DESCRIPTION
+ This function is used to reset thread data to its default state.
+
+ NOTE
+ This function is not suitable for setting thread data to some
+ non-default values, as there is only one replication thread, so
+ different master threads may overwrite data of each other on
+ slave.
+*/
void THD::cleanup_after_query()
{
+ last_insert_id_used= FALSE;
if (clear_next_insert_id)
{
clear_next_insert_id= 0;
@@ -568,6 +583,7 @@ void THD::cleanup_after_query()
where= THD::DEFAULT_WHERE;
}
+
/*
Convert a string to another character set
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 039c133e885..804c887f05a 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -306,7 +306,7 @@ public:
const char *log_name);
void new_file(bool need_lock);
bool write(THD *thd, enum enum_server_command command,
- const char *format,...);
+ const char *format, ...) ATTRIBUTE_FORMAT(printf, 4, 5);
bool write(THD *thd, const char *query, uint query_length,
time_t query_start=0);
bool write(Log_event* event_info); // binary log write
@@ -1097,6 +1097,12 @@ public:
struct st_mysql_data **data_tail;
void clear_data_list();
struct st_mysql_data *alloc_new_dataset();
+ /*
+ In embedded server it points to the statement that is processed
+ in the current query. We store some results directly in statement
+ fields then.
+ */
+ struct st_mysql_stmt *current_stmt;
#endif
NET net; // client connection descriptor
MEM_ROOT warn_root; // For warnings and errors
@@ -1252,17 +1258,29 @@ public:
ulonglong next_insert_id;
/* Remember last next_insert_id to reset it if something went wrong */
ulonglong prev_insert_id;
+
/*
- The insert_id used for the last statement or set by SET LAST_INSERT_ID=#
- or SELECT LAST_INSERT_ID(#). Used for binary log and returned by
- LAST_INSERT_ID()
+ At the beginning of the statement last_insert_id holds the first
+ generated value of the previous statement. During statement
+ execution it is updated to the value just generated, but then
+ restored to the value that was generated first, so for the next
+ statement it will again be "the first generated value of the
+ previous statement".
+
+ It may also be set with "LAST_INSERT_ID(expr)" or
+ "@@LAST_INSERT_ID= expr", but the effect of such setting will be
+ seen only in the next statement.
*/
ulonglong last_insert_id;
+
/*
- Set to the first value that LAST_INSERT_ID() returned for the last
- statement. When this is set, last_insert_id_used is set to true.
+ current_insert_id remembers the first generated value of the
+ previous statement, and does not change during statement
+ execution. Its value returned from LAST_INSERT_ID() and
+ @@LAST_INSERT_ID.
*/
ulonglong current_insert_id;
+
ulonglong limit_found_rows;
ulonglong options; /* Bitmap of states */
longlong row_count_func; /* For the ROW_COUNT() function */
@@ -1325,7 +1343,31 @@ public:
bool last_cuted_field;
bool no_errors, password, is_fatal_error;
bool query_start_used, rand_used, time_zone_used;
- bool last_insert_id_used,insert_id_used, clear_next_insert_id;
+
+ /*
+ last_insert_id_used is set when current statement calls
+ LAST_INSERT_ID() or reads @@LAST_INSERT_ID.
+ */
+ bool last_insert_id_used;
+
+ /*
+ last_insert_id_used is set when current statement or any stored
+ function called from this statement calls LAST_INSERT_ID() or
+ reads @@LAST_INSERT_ID, so that binary log LAST_INSERT_ID_EVENT be
+ generated. Required for statement-based binary log for issuing
+ "SET LAST_INSERT_ID= #" before "SELECT func()", if func() reads
+ LAST_INSERT_ID.
+ */
+ bool last_insert_id_used_bin_log;
+
+ /*
+ insert_id_used is set when current statement updates
+ THD::last_insert_id, so that binary log INSERT_ID_EVENT be
+ generated.
+ */
+ bool insert_id_used;
+
+ bool clear_next_insert_id;
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
bool substitute_null_with_insert_id;
bool in_lock_tables;
@@ -1461,15 +1503,6 @@ public:
insert_id_used=1;
substitute_null_with_insert_id= TRUE;
}
- inline ulonglong insert_id(void)
- {
- if (!last_insert_id_used)
- {
- last_insert_id_used=1;
- current_insert_id=last_insert_id;
- }
- return last_insert_id;
- }
inline ulonglong found_rows(void)
{
return limit_found_rows;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index c95fb5d5973..3e3378542aa 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -167,7 +167,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
MYF(MY_FAE | MY_ZEROFILL));
if (!(sortorder= make_unireg_sortorder((ORDER*) order->first,
- &length)) ||
+ &length, NULL)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length,
select, HA_POS_ERROR,
&examined_rows))
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 3db6eae8695..2ce83caa369 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -590,10 +590,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
#endif
error=write_record(thd, table ,&info);
/*
- If auto_increment values are used, save the first one
- for LAST_INSERT_ID() and for the update log.
- We can't use insert_id() as we don't want to touch the
- last_insert_id_used flag.
+ If auto_increment values are used, save the first one for
+ LAST_INSERT_ID() and for the update log.
*/
if (! id && thd->insert_id_used)
{ // Get auto increment value
@@ -1303,6 +1301,9 @@ public:
time_t start_time;
bool query_start_used,last_insert_id_used,insert_id_used, ignore, log_query;
ulonglong last_insert_id;
+ ulonglong next_insert_id;
+ ulong auto_increment_increment;
+ ulong auto_increment_offset;
timestamp_auto_set_type timestamp_field_type;
uint query_length;
@@ -1684,6 +1685,22 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, bool igno
row->last_insert_id= thd->last_insert_id;
row->timestamp_field_type= table->timestamp_field_type;
+ /* The session variable settings can always be copied. */
+ row->auto_increment_increment= thd->variables.auto_increment_increment;
+ row->auto_increment_offset= thd->variables.auto_increment_offset;
+ /*
+ Next insert id must be set for the first value in a multi-row insert
+ only. So clear it after the first use. Assume a multi-row insert.
+ Since the user thread doesn't really execute the insert,
+ thd->next_insert_id is left untouched between the rows. If we copy
+ the same insert id to every row of the multi-row insert, the delayed
+ insert thread would copy this before inserting every row. Thus it
+ tries to insert all rows with the same insert id. This fails on the
+ unique constraint. So just the first row would be really inserted.
+ */
+ row->next_insert_id= thd->next_insert_id;
+ thd->next_insert_id= 0;
+
di->rows.push_back(row);
di->stacked_inserts++;
di->status=1;
@@ -2055,6 +2072,14 @@ bool delayed_insert::handle_inserts(void)
thd.insert_id_used=row->insert_id_used;
table->timestamp_field_type= row->timestamp_field_type;
+ /* The session variable settings can always be copied. */
+ thd.variables.auto_increment_increment= row->auto_increment_increment;
+ thd.variables.auto_increment_offset= row->auto_increment_offset;
+ /* Next insert id must be used only if non-zero. */
+ if (row->next_insert_id)
+ thd.next_insert_id= row->next_insert_id;
+ DBUG_PRINT("loop", ("next_insert_id: %lu", (ulong) thd.next_insert_id));
+
info.ignore= row->ignore;
info.handle_duplicates= row->dup;
if (info.ignore ||
@@ -2076,6 +2101,20 @@ bool delayed_insert::handle_inserts(void)
info.error_count++; // Ignore errors
thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
row->log_query = 0;
+ /*
+ We must reset next_insert_id. Otherwise all following rows may
+ become duplicates. If write_record() failed on a duplicate and
+ next_insert_id would be left unchanged, the next rows would also
+ be tried with the same insert id and would fail. Since the end
+ of a multi-row statement is unknown here, all following rows in
+ the queue would be dropped, regardless which thread added them.
+ After the queue is used up, next_insert_id is cleared and the
+ next run will succeed. This could even happen if these come from
+ the same multi-row statement as the current queue contents. That
+ way it would look somewhat random which rows are rejected after
+ a duplicate.
+ */
+ thd.next_insert_id= 0;
}
if (using_ignore)
{
@@ -2121,6 +2160,7 @@ bool delayed_insert::handle_inserts(void)
/* This should never happen */
table->file->print_error(error,MYF(0));
sql_print_error("%s",thd.net.last_error);
+ DBUG_PRINT("error", ("HA_EXTRA_NO_CACHE failed in loop"));
goto err;
}
query_cache_invalidate3(&thd, table, 1);
@@ -2146,6 +2186,7 @@ bool delayed_insert::handle_inserts(void)
{ // This shouldn't happen
table->file->print_error(error,MYF(0));
sql_print_error("%s",thd.net.last_error);
+ DBUG_PRINT("error", ("HA_EXTRA_NO_CACHE failed after loop"));
goto err;
}
query_cache_invalidate3(&thd, table, 1);
@@ -2153,13 +2194,16 @@ bool delayed_insert::handle_inserts(void)
DBUG_RETURN(0);
err:
+ DBUG_EXECUTE("error", max_rows= 0;);
/* Remove all not used rows */
while ((row=rows.get()))
{
delete row;
thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
stacked_inserts--;
+ DBUG_EXECUTE("error", max_rows++;);
}
+ DBUG_PRINT("error", ("dropped %lu rows after an error", max_rows));
thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
pthread_mutex_lock(&mutex);
DBUG_RETURN(1);
@@ -2447,7 +2491,7 @@ bool select_insert::send_data(List<Item> &values)
*/
table->next_number_field->reset();
if (!last_insert_id && thd->insert_id_used)
- last_insert_id= thd->insert_id();
+ last_insert_id= thd->last_insert_id;
}
}
DBUG_RETURN(error);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 788276ac654..dee198d14bc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -163,6 +163,7 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
lex->select_lex.group_list.empty();
lex->select_lex.order_list.empty();
+ lex->select_lex.udf_list.empty();
lex->current_select= &lex->select_lex;
lex->yacc_yyss=lex->yacc_yyvs=0;
lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
@@ -1138,7 +1139,7 @@ void st_select_lex::init_query()
initialization is checked for failure.
*/
parent_lex->push_context(&context);
- cond_count= with_wild= 0;
+ cond_count= between_count= with_wild= 0;
conds_processed_with_permanent_arena= 0;
ref_pointer_array= 0;
select_n_having_items= 0;
@@ -1166,6 +1167,7 @@ void st_select_lex::init_select()
braces= 0;
when_list.empty();
expr_list.empty();
+ udf_list.empty();
interval_list.empty();
use_index.empty();
ftfunc_list_alloc.empty();
@@ -1179,7 +1181,7 @@ void st_select_lex::init_select()
select_limit= 0; /* denotes the default limit = HA_POS_ERROR */
offset_limit= 0; /* denotes the default offset = 0 */
with_sum_func= 0;
-
+ is_correlated= 0;
}
/*
@@ -1373,6 +1375,8 @@ void st_select_lex::mark_as_dependent(SELECT_LEX *last)
SELECT_LEX_UNIT *munit= s->master_unit();
munit->uncacheable|= UNCACHEABLE_DEPENDENT;
}
+ is_correlated= TRUE;
+ this->master_unit()->item->is_correlated= TRUE;
}
bool st_select_lex_node::set_braces(bool value) { return 1; }
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index fdf14c691e9..1d6f344cb1c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -470,7 +470,7 @@ public:
void set_thd(THD *thd_arg) { thd= thd_arg; }
friend void lex_start(THD *thd, uchar *buf, uint length);
- friend int subselect_union_engine::exec();
+ friend int subselect_union_engine::exec(bool);
List<Item> *get_unit_column_types();
};
@@ -530,7 +530,8 @@ public:
list during split_sum_func
*/
uint select_n_having_items;
- uint cond_count; /* number of arguments of and/or/xor in where/having */
+ uint cond_count; /* number of arguments of and/or/xor in where/having/on */
+ uint between_count; /* number of between predicates in where/having/on */
enum_parsing_place parsing_place; /* where we are parsing expression */
bool with_sum_func; /* sum function indicator */
/*
@@ -561,6 +562,8 @@ public:
query processing end even if we use temporary table
*/
bool subquery_in_having;
+ /* TRUE <=> this SELECT is correlated w.r.t. some ancestor select */
+ bool is_correlated;
/*
This variable is required to ensure proper work of subqueries and
stored procedures. Generally, one should use the states of
@@ -580,6 +583,8 @@ public:
/* exclude this select from check of unique_table() */
bool exclude_from_table_unique_test;
+ List<udf_func> udf_list; /* udf function calls stack */
+
void init_query();
void init_select();
st_select_lex_unit* master_unit();
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index d5faf6ee7e9..bdc08b7bd2d 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -616,10 +616,8 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
thd->no_trans_update= no_trans_update;
/*
- If auto_increment values are used, save the first one
- for LAST_INSERT_ID() and for the binary/update log.
- We can't use insert_id() as we don't want to touch the
- last_insert_id_used flag.
+ If auto_increment values are used, save the first one for
+ LAST_INSERT_ID() and for the binary/update log.
*/
if (!id && thd->insert_id_used)
id= thd->last_insert_id;
@@ -784,10 +782,8 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
if (write_record(thd, table, &info))
DBUG_RETURN(1);
/*
- If auto_increment values are used, save the first one
- for LAST_INSERT_ID() and for the binary/update log.
- We can't use insert_id() as we don't want to touch the
- last_insert_id_used flag.
+ If auto_increment values are used, save the first one for
+ LAST_INSERT_ID() and for the binary/update log.
*/
if (!id && thd->insert_id_used)
id= thd->last_insert_id;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 18d048df393..c62c286cfdb 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2422,6 +2422,20 @@ mysql_execute_command(THD *thd)
thd->net.no_send_error= 0;
/*
+ Remember first generated insert id value of the previous
+ statement. We remember it here at the beginning of the statement,
+ and also in Item_func_last_insert_id::fix_fields() and
+ sys_var_last_insert_id::value_ptr(). Last two places are required
+ because LAST_INSERT_ID() and @@LAST_INSERT_ID may also be used in
+ expression that is not executed with mysql_execute_command().
+
+ And we remember it here because some statements read
+ @@LAST_INSERT_ID indirectly, like "SELECT * FROM t1 WHERE id IS
+ NULL", that may replace "id IS NULL" with "id = <LAST_INSERT_ID>".
+ */
+ thd->current_insert_id= thd->last_insert_id;
+
+ /*
In many cases first table of main SELECT_LEX have special meaning =>
check that it is first table in global list and relink it first in
queries_tables list if it is necessary (we need such relinking only
@@ -5636,7 +5650,8 @@ void mysql_reset_thd_for_next_command(THD *thd)
DBUG_ENTER("mysql_reset_thd_for_next_command");
thd->free_list= 0;
thd->select_number= 1;
- thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0;
+ thd->query_start_used= thd->insert_id_used=0;
+ thd->last_insert_id_used_bin_log= FALSE;
thd->is_fatal_error= thd->time_zone_used= 0;
thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
SERVER_QUERY_NO_INDEX_USED |
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 74951029de9..c87a8696bbc 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -126,94 +126,146 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list)
/*
- Rename all tables in list; Return pointer to wrong entry if something goes
- wrong. Note that the table_list may be empty!
+ Rename a single table or a view
+
+ SYNPOSIS
+ do_rename()
+ thd Thread handle
+ ren_table A table/view to be renamed
+ new_db The database to which the table to be moved to
+ new_table_name The new table/view name
+ new_table_alias The new table/view alias
+ skip_error Whether to skip error
+
+ DESCRIPTION
+ Rename a single table or a view.
+
+ RETURN
+ false Ok
+ true rename failed
*/
-static TABLE_LIST *
-rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
+bool
+do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
+ char *new_table_alias, bool skip_error)
{
- TABLE_LIST *ren_table,*new_table;
+ int rc= 1;
+ char name[FN_REFLEN];
+ const char *new_alias, *old_alias;
frm_type_enum frm_type;
db_type table_type;
- DBUG_ENTER("rename_tables");
+ DBUG_ENTER("do_rename");
- for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
+ if (lower_case_table_names == 2)
{
- int rc= 1;
- char name[FN_REFLEN];
- const char *new_alias, *old_alias;
-
- new_table= ren_table->next_local;
- if (lower_case_table_names == 2)
- {
- old_alias= ren_table->alias;
- new_alias= new_table->alias;
- }
- else
- {
- old_alias= ren_table->table_name;
- new_alias= new_table->table_name;
- }
- sprintf(name,"%s/%s/%s%s",mysql_data_home,
- new_table->db, new_alias, reg_ext);
- unpack_filename(name, name);
- if (!access(name,F_OK))
- {
- my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
- DBUG_RETURN(ren_table); // This can't be skipped
- }
- sprintf(name,"%s/%s/%s%s",mysql_data_home,
- ren_table->db, old_alias,
- reg_ext);
- unpack_filename(name, name);
+ old_alias= ren_table->alias;
+ new_alias= new_table_alias;
+ }
+ else
+ {
+ old_alias= ren_table->table_name;
+ new_alias= new_table_name;
+ }
+ sprintf(name,"%s/%s/%s%s",mysql_data_home,
+ new_db, new_alias, reg_ext);
+ unpack_filename(name, name);
+ if (!access(name,F_OK))
+ {
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
+ DBUG_RETURN(1); // This can't be skipped
+ }
+ sprintf(name,"%s/%s/%s%s",mysql_data_home,
+ ren_table->db, old_alias,
+ reg_ext);
+ unpack_filename(name, name);
- frm_type= mysql_frm_type(thd, name, &table_type);
- switch (frm_type)
+ frm_type= mysql_frm_type(thd, name, &table_type);
+ switch (frm_type)
+ {
+ case FRMTYPE_TABLE:
{
- case FRMTYPE_TABLE:
+ if (table_type == DB_TYPE_UNKNOWN)
+ my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+ else
{
- if (table_type == DB_TYPE_UNKNOWN)
- my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
- else
+ if (!(rc= mysql_rename_table(table_type, ren_table->db, old_alias,
+ new_db, new_alias)))
{
- if (!(rc= mysql_rename_table(table_type, ren_table->db, old_alias,
- new_table->db, new_alias)))
+ if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
+ old_alias,
+ new_db,
+ new_alias)))
{
- if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
- old_alias,
- new_table->db,
- new_alias)))
- {
- /*
- We've succeeded in renaming table's .frm and in updating
- corresponding handler data, but have failed to update table's
- triggers appropriately. So let us revert operations on .frm
- and handler's data and report about failure to rename table.
- */
- (void) mysql_rename_table(table_type, new_table->db, new_alias,
- ren_table->db, old_alias);
- }
+ /*
+ We've succeeded in renaming table's .frm and in updating
+ corresponding handler data, but have failed to update table's
+ triggers appropriately. So let us revert operations on .frm
+ and handler's data and report about failure to rename table.
+ */
+ (void) mysql_rename_table(table_type, new_db, new_alias,
+ ren_table->db, old_alias);
}
}
- break;
}
- case FRMTYPE_VIEW:
- /* change of schema is not allowed */
- if (strcmp(ren_table->db, new_table->db))
- my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
- new_table->db);
- else
- rc= mysql_rename_view(thd, new_alias, ren_table);
- break;
- default:
- DBUG_ASSERT(0); // should never happen
- case FRMTYPE_ERROR:
- my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
- break;
+ break;
}
- if (rc && !skip_error)
+ case FRMTYPE_VIEW:
+ /* change of schema is not allowed */
+ if (strcmp(ren_table->db, new_db))
+ my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
+ new_db);
+ else
+ rc= mysql_rename_view(thd, new_alias, ren_table);
+ break;
+ default:
+ DBUG_ASSERT(0); // should never happen
+ case FRMTYPE_ERROR:
+ my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+ break;
+ }
+ if (rc && !skip_error)
+ DBUG_RETURN(1);
+
+ DBUG_RETURN(0);
+
+}
+/*
+ Rename all tables in list; Return pointer to wrong entry if something goes
+ wrong. Note that the table_list may be empty!
+*/
+
+/*
+ Rename tables/views in the list
+
+ SYNPOSIS
+ rename_tables()
+ thd Thread handle
+ table_list List of tables to rename
+ skip_error Whether to skip errors
+
+ DESCRIPTION
+ Take a table/view name from and odd list element and rename it to a
+ the name taken from list element+1. Note that the table_list may be
+ empty.
+
+ RETURN
+ false Ok
+ true rename failed
+*/
+
+static TABLE_LIST *
+rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
+{
+ TABLE_LIST *ren_table,*new_table, *tmp_table;
+
+ DBUG_ENTER("rename_tables");
+
+ for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
+ {
+ new_table= ren_table->next_local;
+ if (do_rename(thd, ren_table, new_table->db, new_table->table_name,
+ new_table->alias, skip_error))
DBUG_RETURN(ren_table);
}
DBUG_RETURN(0);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index b328d9162d5..f92217302f8 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -35,14 +35,17 @@ const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
"index_merge"
};
+struct st_sargable_param;
+
static void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
static bool make_join_statistics(JOIN *join, TABLE_LIST *leaves, COND *conds,
DYNAMIC_ARRAY *keyuse);
static bool update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,
- JOIN_TAB *join_tab,
+ JOIN_TAB *join_tab,
uint tables, COND *conds,
COND_EQUAL *cond_equal,
- table_map table_map, SELECT_LEX *select_lex);
+ table_map table_map, SELECT_LEX *select_lex,
+ st_sargable_param **sargables);
static int sort_keyuse(KEYUSE *a,KEYUSE *b);
static void set_position(JOIN *join,uint index,JOIN_TAB *table,KEYUSE *key);
static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
@@ -155,8 +158,8 @@ static int join_read_prev_same(READ_RECORD *info);
static int join_read_prev(READ_RECORD *info);
static int join_ft_read_first(JOIN_TAB *tab);
static int join_ft_read_next(READ_RECORD *info);
-static int join_read_always_key_or_null(JOIN_TAB *tab);
-static int join_read_next_same_or_null(READ_RECORD *info);
+int join_read_always_key_or_null(JOIN_TAB *tab);
+int join_read_next_same_or_null(READ_RECORD *info);
static COND *make_cond_for_table(COND *cond,table_map table,
table_map used_table);
static Item* part_of_refkey(TABLE *form,Field *field);
@@ -509,11 +512,12 @@ err:
DBUG_RETURN(-1); /* purecov: inspected */
}
+
/*
test if it is known for optimisation IN subquery
- SYNOPSYS
- JOIN::test_in_subselect
+ SYNOPSIS
+ JOIN::test_in_subselect()
where - pointer for variable in which conditions should be
stored if subquery is known
@@ -548,6 +552,35 @@ bool JOIN::test_in_subselect(Item **where)
/*
+ Check if the passed HAVING clause is a clause added by subquery optimizer
+
+ SYNOPSIS
+ is_having_subq_predicates()
+ having Having clause
+
+ RETURN
+ TRUE The passed HAVING clause was added by the subquery optimizer
+ FALSE Otherwise
+*/
+
+bool is_having_subq_predicates(Item *having)
+{
+ if (having->type() == Item::FUNC_ITEM)
+ {
+ if (((Item_func *) having)->functype() == Item_func::ISNOTNULLTEST_FUNC)
+ return TRUE;
+ if (((Item_func *) having)->functype() == Item_func::TRIG_COND_FUNC)
+ {
+ having= ((Item_func*)having)->arguments()[0];
+ if (((Item_func *) having)->functype() == Item_func::ISNOTNULLTEST_FUNC)
+ return TRUE;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*
global select optimisation.
return 0 - success
1 - error
@@ -1013,9 +1046,7 @@ JOIN::optimize()
}
} else if (join_tab[0].type == JT_REF_OR_NULL &&
join_tab[0].ref.items[0]->name == in_left_expr_name &&
- having->type() == Item::FUNC_ITEM &&
- ((Item_func *) having)->functype() ==
- Item_func::ISNOTNULLTEST_FUNC)
+ is_having_subq_predicates(having))
{
join_tab[0].type= JT_INDEX_SUBQUERY;
error= 0;
@@ -1134,17 +1165,28 @@ JOIN::optimize()
tmp_table_param.hidden_field_count= (all_fields.elements -
fields_list.elements);
+ ORDER *tmp_group= ((!simple_group && !procedure &&
+ !(test_flags & TEST_NO_KEY_GROUP)) ? group_list :
+ (ORDER*) 0);
+ /*
+ Pushing LIMIT to the temporary table creation is not applicable
+ when there is ORDER BY or GROUP BY or there is no GROUP BY, but
+ there are aggregate functions, because in all these cases we need
+ all result rows.
+ */
+ ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order ||
+ test(select_options & OPTION_BUFFER_RESULT)) &&
+ !tmp_group &&
+ !thd->lex->current_select->with_sum_func) ?
+ select_limit : HA_POS_ERROR;
+
if (!(exec_tmp_table1 =
create_tmp_table(thd, &tmp_table_param, all_fields,
- ((!simple_group && !procedure &&
- !(test_flags & TEST_NO_KEY_GROUP)) ?
- group_list : (ORDER*) 0),
+ tmp_group,
group_list ? 0 : select_distinct,
group_list && simple_group,
select_options,
- (order == 0 || skip_sort_order ||
- test(select_options & OPTION_BUFFER_RESULT)) ?
- select_limit : HA_POS_ERROR,
+ tmp_rows_limit,
(char *) "")))
DBUG_RETURN(1);
@@ -1257,14 +1299,14 @@ JOIN::reinit()
exec_tmp_table1->file->extra(HA_EXTRA_RESET_STATE);
exec_tmp_table1->file->delete_all_rows();
free_io_cache(exec_tmp_table1);
- filesort_free_buffers(exec_tmp_table1);
+ filesort_free_buffers(exec_tmp_table1,0);
}
if (exec_tmp_table2)
{
exec_tmp_table2->file->extra(HA_EXTRA_RESET_STATE);
exec_tmp_table2->file->delete_all_rows();
free_io_cache(exec_tmp_table2);
- filesort_free_buffers(exec_tmp_table2);
+ filesort_free_buffers(exec_tmp_table2,0);
}
if (items0)
set_items_ref_array(items0);
@@ -1364,12 +1406,13 @@ JOIN::exec()
thd->examined_row_count= 0;
DBUG_VOID_RETURN;
}
- /*
- don't reset the found rows count if there're no tables
- as FOUND_ROWS() may be called.
- */
+ /*
+ Don't reset the found rows count if there're no tables as
+ FOUND_ROWS() may be called. Never reset the examined row count here.
+ It must be accumulated from all join iterations of all join parts.
+ */
if (tables)
- thd->limit_found_rows= thd->examined_row_count= 0;
+ thd->limit_found_rows= 0;
if (zero_result_cause)
{
@@ -1399,7 +1442,8 @@ JOIN::exec()
simple_order= simple_group;
skip_sort_order= 0;
}
- if (order &&
+ if (order &&
+ (order != group_list || !(select_options & SELECT_BIG_RESULT)) &&
(const_tables == tables ||
((simple_order || skip_sort_order) &&
test_if_skip_sort_order(&join_tab[const_tables], order,
@@ -1417,6 +1461,12 @@ JOIN::exec()
List<Item> *curr_all_fields= &all_fields;
List<Item> *curr_fields_list= &fields_list;
TABLE *curr_tmp_table= 0;
+ /*
+ Initialize examined rows here because the values from all join parts
+ must be accumulated in examined_row_count. Hence every join
+ iteration must count from zero.
+ */
+ curr_join->examined_rows= 0;
if ((curr_join->select_lex->options & OPTION_SCHEMA_TABLE) &&
get_schema_tables_result(curr_join))
@@ -1574,6 +1624,7 @@ JOIN::exec()
{
DBUG_VOID_RETURN;
}
+ sortorder= curr_join->sortorder;
}
thd->proc_info="Copying to group table";
@@ -1783,6 +1834,7 @@ JOIN::exec()
(select_options & OPTION_FOUND_ROWS ?
HA_POS_ERROR : unit->select_limit_cnt)))
DBUG_VOID_RETURN;
+ sortorder= curr_join->sortorder;
}
}
/* XXX: When can we have here thd->net.report_error not zero? */
@@ -1823,9 +1875,12 @@ JOIN::exec()
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
error= do_select(curr_join, curr_fields_list, NULL, procedure);
thd->limit_found_rows= curr_join->send_records;
- thd->examined_row_count= curr_join->examined_rows;
}
+ /* Accumulate the counts from all join iterations of all join parts. */
+ thd->examined_row_count+= curr_join->examined_rows;
+ DBUG_PRINT("counts", ("thd->examined_row_count: %lu",
+ (ulong) thd->examined_row_count));
DBUG_VOID_RETURN;
}
@@ -2041,6 +2096,19 @@ static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select,
DBUG_RETURN(HA_POS_ERROR); /* This shouldn't happend */
}
+/*
+ This structure is used to collect info on potentially sargable
+ predicates in order to check whether they become sargable after
+ reading const tables.
+ We form a bitmap of indexes that can be used for sargable predicates.
+ Only such indexes are involved in range analysis.
+*/
+typedef struct st_sargable_param
+{
+ Field *field; /* field against which to check sargability */
+ Item **arg_value; /* values of potential keys for lookups */
+ uint num_values; /* number of values in the above array */
+} SARGABLE_PARAM;
/*
Calculate the best possible join and initialize the join structure
@@ -2063,6 +2131,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
JOIN_TAB *stat,*stat_end,*s,**stat_ref;
KEYUSE *keyuse,*start_keyuse;
table_map outer_join=0;
+ SARGABLE_PARAM *sargables= 0;
JOIN_TAB *stat_vector[MAX_TABLES+1];
DBUG_ENTER("make_join_statistics");
@@ -2184,7 +2253,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
if (conds || outer_join)
if (update_ref_and_keys(join->thd, keyuse_array, stat, join->tables,
conds, join->cond_equal,
- ~outer_join, join->select_lex))
+ ~outer_join, join->select_lex, &sargables))
DBUG_RETURN(1);
/* Read tables with 0 or 1 rows (system tables) */
@@ -2334,6 +2403,26 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
}
} while (join->const_table_map & found_ref && ref_changed);
+ /*
+ Update info on indexes that can be used for search lookups as
+ reading const tables may has added new sargable predicates.
+ */
+ if (const_count && sargables)
+ {
+ for( ; sargables->field ; sargables++)
+ {
+ Field *field= sargables->field;
+ JOIN_TAB *stat= field->table->reginfo.join_tab;
+ key_map possible_keys= field->key_start;
+ possible_keys.intersect(field->table->keys_in_use_for_query);
+ bool is_const= 1;
+ for (uint i=0; i< sargables->num_values; i++)
+ is_const&= sargables->arg_value[i]->const_item();
+ if (is_const)
+ stat[0].const_keys.merge(possible_keys);
+ }
+ }
+
/* Calc how many (possible) matched records in each table */
for (s=stat ; s < stat_end ; s++)
@@ -2451,6 +2540,9 @@ typedef struct key_field_t { // Used when finding key fields
when val IS NULL.
*/
bool null_rejecting;
+
+ /* TRUE<=> This ref access is an outer subquery reference access */
+ bool outer_ref;
} KEY_FIELD;
/* Values in optimize */
@@ -2593,6 +2685,7 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
eq_func True if we used =, <=> or IS NULL
value Value used for comparison with field
usable_tables Tables which can be used for key optimization
+ sargables IN/OUT Array of found sargable candidates
NOTES
If we are doing a NOT NULL comparison on a NOT NULL field in a outer join
@@ -2604,8 +2697,8 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
static void
add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
- Field *field, bool eq_func, Item **value, uint num_values,
- table_map usable_tables)
+ Field *field, bool eq_func, Item **value, uint num_values,
+ table_map usable_tables, SARGABLE_PARAM **sargables)
{
uint exists_optimize= 0;
if (!(field->flags & PART_KEY_FLAG))
@@ -2661,6 +2754,19 @@ add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
is_const&= value[i]->const_item();
if (is_const)
stat[0].const_keys.merge(possible_keys);
+ else if (!eq_func)
+ {
+ /*
+ Save info to be able check whether this predicate can be
+ considered as sargable for range analisis after reading const tables.
+ We do not save info about equalities as update_const_equal_items
+ will take care of updating info on keys from sargable equalities.
+ */
+ (*sargables)--;
+ (*sargables)->field= field;
+ (*sargables)->arg_value= value;
+ (*sargables)->num_values= num_values;
+ }
/*
We can't always use indexes when comparing a string index to a
number. cmp_type() is checked to allow compare of dates to numbers.
@@ -2735,6 +2841,7 @@ add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
cond->functype() == Item_func::MULT_EQUAL_FUNC) &&
((*value)->type() == Item::FIELD_ITEM) &&
((Item_field*)*value)->field->maybe_null());
+ (*key_fields)->outer_ref= FALSE;
(*key_fields)++;
}
@@ -2751,6 +2858,7 @@ add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
value Value used for comparison with field
Is NULL for BETWEEN and IN
usable_tables Tables which can be used for key optimization
+ sargables IN/OUT Array of found sargable candidates
NOTES
If field items f1 and f2 belong to the same multiple equality and
@@ -2764,11 +2872,12 @@ static void
add_key_equal_fields(KEY_FIELD **key_fields, uint and_level,
Item_func *cond, Item_field *field_item,
bool eq_func, Item **val,
- uint num_values, table_map usable_tables)
+ uint num_values, table_map usable_tables,
+ SARGABLE_PARAM **sargables)
{
Field *field= field_item->field;
add_key_field(key_fields, and_level, cond, field,
- eq_func, val, num_values, usable_tables);
+ eq_func, val, num_values, usable_tables, sargables);
Item_equal *item_equal= field_item->item_equal;
if (item_equal)
{
@@ -2783,15 +2892,17 @@ add_key_equal_fields(KEY_FIELD **key_fields, uint and_level,
if (!field->eq(item->field))
{
add_key_field(key_fields, and_level, cond, item->field,
- eq_func, val, num_values, usable_tables);
+ eq_func, val, num_values, usable_tables,
+ sargables);
}
}
}
}
static void
-add_key_fields(KEY_FIELD **key_fields,uint *and_level,
- COND *cond, table_map usable_tables)
+add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level,
+ COND *cond, table_map usable_tables,
+ SARGABLE_PARAM **sargables)
{
if (cond->type() == Item_func::COND_ITEM)
{
@@ -2802,28 +2913,54 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
{
Item *item;
while ((item=li++))
- add_key_fields(key_fields,and_level,item,usable_tables);
+ add_key_fields(join, key_fields, and_level, item, usable_tables,
+ sargables);
for (; org_key_fields != *key_fields ; org_key_fields++)
org_key_fields->level= *and_level;
}
else
{
(*and_level)++;
- add_key_fields(key_fields,and_level,li++,usable_tables);
+ add_key_fields(join, key_fields, and_level, li++, usable_tables,
+ sargables);
Item *item;
while ((item=li++))
{
KEY_FIELD *start_key_fields= *key_fields;
(*and_level)++;
- add_key_fields(key_fields,and_level,item,usable_tables);
+ add_key_fields(join, key_fields, and_level, item, usable_tables,
+ sargables);
*key_fields=merge_key_fields(org_key_fields,start_key_fields,
*key_fields,++(*and_level));
}
}
return;
}
- /* If item is of type 'field op field/constant' add it to key_fields */
+ /*
+ Subquery optimization: check if the encountered condition is one
+ added by condition push down into subquery.
+ */
+ {
+ if (cond->type() == Item::FUNC_ITEM &&
+ ((Item_func*)cond)->functype() == Item_func::TRIG_COND_FUNC)
+ {
+ cond= ((Item_func*)cond)->arguments()[0];
+ if (!join->group_list && !join->order &&
+ join->unit->item &&
+ join->unit->item->substype() == Item_subselect::IN_SUBS &&
+ !join->unit->first_select()->next_select())
+ {
+ add_key_fields(join, key_fields, and_level, cond, usable_tables,
+ sargables);
+ // Indicate that this ref access candidate is for subquery lookup:
+ (*key_fields)[-1].outer_ref= TRUE;
+ }
+ return;
+ }
+ }
+
+ /* If item is of type 'field op field/constant' add it to key_fields */
if (cond->type() != Item::FUNC_ITEM)
return;
Item_func *cond_func= (Item_func*) cond;
@@ -2846,9 +2983,9 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
cond_func->argument_count() != 2);
add_key_equal_fields(key_fields, *and_level, cond_func,
(Item_field*) (cond_func->key_item()->real_item()),
- 0, values,
+ 0, values,
cond_func->argument_count()-1,
- usable_tables);
+ usable_tables, sargables);
}
if (cond_func->functype() == Item_func::BETWEEN)
{
@@ -2862,7 +2999,8 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
{
field_item= (Item_field *) (cond_func->arguments()[i]->real_item());
add_key_equal_fields(key_fields, *and_level, cond_func,
- field_item, 0, values, 1, usable_tables);
+ field_item, 0, values, 1, usable_tables,
+ sargables);
}
}
}
@@ -2879,7 +3017,8 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
add_key_equal_fields(key_fields, *and_level, cond_func,
(Item_field*) (cond_func->arguments()[0])->real_item(),
equal_func,
- cond_func->arguments()+1, 1, usable_tables);
+ cond_func->arguments()+1, 1, usable_tables,
+ sargables);
}
if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM &&
cond_func->functype() != Item_func::LIKE_FUNC &&
@@ -2888,7 +3027,8 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
add_key_equal_fields(key_fields, *and_level, cond_func,
(Item_field*) (cond_func->arguments()[1])->real_item(),
equal_func,
- cond_func->arguments(),1,usable_tables);
+ cond_func->arguments(),1,usable_tables,
+ sargables);
}
break;
}
@@ -2903,7 +3043,7 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
add_key_equal_fields(key_fields, *and_level, cond_func,
(Item_field*) (cond_func->arguments()[0])->real_item(),
cond_func->functype() == Item_func::ISNULL_FUNC,
- &tmp, 1, usable_tables);
+ &tmp, 1, usable_tables, sargables);
}
break;
case Item_func::OPTIMIZE_EQUAL:
@@ -2921,7 +3061,7 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
while ((item= it++))
{
add_key_field(key_fields, *and_level, cond_func, item->field,
- TRUE, &const_item, 1, usable_tables);
+ TRUE, &const_item, 1, usable_tables, sargables);
}
}
else
@@ -2941,7 +3081,8 @@ add_key_fields(KEY_FIELD **key_fields,uint *and_level,
if (!field->eq(item->field))
{
add_key_field(key_fields, *and_level, cond_func, field,
- TRUE, (Item **) &item, 1, usable_tables);
+ TRUE, (Item **) &item, 1, usable_tables,
+ sargables);
}
}
it.rewind();
@@ -2993,6 +3134,7 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field)
keyuse.used_tables=key_field->val->used_tables();
keyuse.optimize= key_field->optimize & KEY_OPTIMIZE_REF_OR_NULL;
keyuse.null_rejecting= key_field->null_rejecting;
+ keyuse.outer_ref= key_field->outer_ref;
VOID(insert_dynamic(keyuse_array,(gptr) &keyuse));
}
}
@@ -3092,6 +3234,7 @@ sort_keyuse(KEYUSE *a,KEYUSE *b)
nested_join_table IN Nested join pseudo-table to process
end INOUT End of the key field array
and_level INOUT And-level
+ sargables IN/OUT Array of found sargable candidates
DESCRIPTION
This function populates KEY_FIELD array with entries generated from the
@@ -3114,8 +3257,9 @@ sort_keyuse(KEYUSE *a,KEYUSE *b)
Here we can add 'ref' access candidates for t1 and t2, but not for t3.
*/
-static void add_key_fields_for_nj(TABLE_LIST *nested_join_table,
- KEY_FIELD **end, uint *and_level)
+static void add_key_fields_for_nj(JOIN *join, TABLE_LIST *nested_join_table,
+ KEY_FIELD **end, uint *and_level,
+ SARGABLE_PARAM **sargables)
{
List_iterator<TABLE_LIST> li(nested_join_table->nested_join->join_list);
table_map tables= 0;
@@ -3125,12 +3269,13 @@ static void add_key_fields_for_nj(TABLE_LIST *nested_join_table,
while ((table= li++))
{
if (table->nested_join)
- add_key_fields_for_nj(table, end, and_level);
+ add_key_fields_for_nj(join, table, end, and_level, sargables);
else
if (!table->on_expr)
tables |= table->table->map;
}
- add_key_fields(end, and_level, nested_join_table->on_expr, tables);
+ add_key_fields(join, end, and_level, nested_join_table->on_expr, tables,
+ sargables);
}
@@ -3145,9 +3290,10 @@ static void add_key_fields_for_nj(TABLE_LIST *nested_join_table,
tables Number of tables in join
cond WHERE condition (note that the function analyzes
join_tab[i]->on_expr too)
- normal_tables tables not inner w.r.t some outer join (ones for which
+ normal_tables Tables not inner w.r.t some outer join (ones for which
we can make ref access based the WHERE clause)
select_lex current SELECT
+ sargables OUT Array of found sargable candidates
RETURN
0 - OK
@@ -3156,27 +3302,56 @@ static void add_key_fields_for_nj(TABLE_LIST *nested_join_table,
static bool
update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
- uint tables, COND *cond, COND_EQUAL *cond_equal,
- table_map normal_tables, SELECT_LEX *select_lex)
+ uint tables, COND *cond, COND_EQUAL *cond_equal,
+ table_map normal_tables, SELECT_LEX *select_lex,
+ SARGABLE_PARAM **sargables)
{
uint and_level,i,found_eq_constant;
KEY_FIELD *key_fields, *end, *field;
+ uint sz;
uint m= 1;
if (cond_equal && cond_equal->max_members)
m= cond_equal->max_members;
-
- if (!(key_fields=(KEY_FIELD*)
- thd->alloc(sizeof(key_fields[0])*
- (thd->lex->current_select->cond_count+1)*2*m)))
+
+ /*
+ We use the same piece of memory to store both KEY_FIELD
+ and SARGABLE_PARAM structure.
+ KEY_FIELD values are placed at the beginning this memory
+ while SARGABLE_PARAM values are put at the end.
+ All predicates that are used to fill arrays of KEY_FIELD
+ and SARGABLE_PARAM structures have at most 2 arguments
+ except BETWEEN predicates that have 3 arguments and
+ IN predicates.
+ This any predicate if it's not BETWEEN/IN can be used
+ directly to fill at most 2 array elements, either of KEY_FIELD
+ or SARGABLE_PARAM type. For a BETWEEN predicate 3 elements
+ can be filled as this predicate is considered as
+ saragable with respect to each of its argument.
+ An IN predicate can require at most 1 element as currently
+ it is considered as sargable only for its first argument.
+ Multiple equality can add elements that are filled after
+ substitution of field arguments by equal fields. There
+ can be not more than cond_equal->max_members such substitutions.
+ */
+ sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
+ (((thd->lex->current_select->cond_count+1)*2 +
+ thd->lex->current_select->between_count)*m+1);
+ if (!(key_fields=(KEY_FIELD*) thd->alloc(sz)))
return TRUE; /* purecov: inspected */
and_level= 0;
field= end= key_fields;
+ *sargables= (SARGABLE_PARAM *) key_fields +
+ (sz - sizeof((*sargables)[0].field))/sizeof(SARGABLE_PARAM);
+ /* set a barrier for the array of SARGABLE_PARAM */
+ (*sargables)[0].field= 0;
+
if (my_init_dynamic_array(keyuse,sizeof(KEYUSE),20,64))
return TRUE;
if (cond)
{
- add_key_fields(&end,&and_level,cond,normal_tables);
+ add_key_fields(join_tab->join, &end, &and_level, cond, normal_tables,
+ sargables);
for (; field != end ; field++)
{
add_key_part(keyuse,field);
@@ -3198,8 +3373,9 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
into account as well.
*/
if (*join_tab[i].on_expr_ref)
- add_key_fields(&end,&and_level,*join_tab[i].on_expr_ref,
- join_tab[i].table->map);
+ add_key_fields(join_tab->join, &end, &and_level,
+ *join_tab[i].on_expr_ref,
+ join_tab[i].table->map, sargables);
}
/* Process ON conditions for the nested joins */
@@ -3209,7 +3385,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
while ((table= li++))
{
if (table->nested_join)
- add_key_fields_for_nj(table, &end, &and_level);
+ add_key_fields_for_nj(join_tab->join, table, &end, &and_level,
+ sargables);
}
}
@@ -4949,9 +5126,28 @@ make_simple_join(JOIN *join,TABLE *tmp_table)
JOIN_TAB *join_tab;
DBUG_ENTER("make_simple_join");
- if (!(tableptr=(TABLE**) join->thd->alloc(sizeof(TABLE*))) ||
- !(join_tab=(JOIN_TAB*) join->thd->alloc(sizeof(JOIN_TAB))))
- DBUG_RETURN(TRUE);
+ /*
+ Reuse TABLE * and JOIN_TAB if already allocated by a previous call
+ to this function through JOIN::exec (may happen for sub-queries).
+ */
+ if (!join->table_reexec)
+ {
+ if (!(join->table_reexec= (TABLE**) join->thd->alloc(sizeof(TABLE*))))
+ DBUG_RETURN(TRUE); /* purecov: inspected */
+ if (join->tmp_join)
+ join->tmp_join->table_reexec= join->table_reexec;
+ }
+ if (!join->join_tab_reexec)
+ {
+ if (!(join->join_tab_reexec=
+ (JOIN_TAB*) join->thd->alloc(sizeof(JOIN_TAB))))
+ DBUG_RETURN(TRUE); /* purecov: inspected */
+ if (join->tmp_join)
+ join->tmp_join->join_tab_reexec= join->join_tab_reexec;
+ }
+ tableptr= join->table_reexec;
+ join_tab= join->join_tab_reexec;
+
join->join_tab=join_tab;
join->table=tableptr; tableptr[0]=tmp_table;
join->tables=1;
@@ -5954,7 +6150,7 @@ void JOIN::cleanup(bool full)
if (tables > const_tables) // Test for not-const tables
{
free_io_cache(table[const_tables]);
- filesort_free_buffers(table[const_tables]);
+ filesort_free_buffers(table[const_tables],full);
}
if (full)
@@ -7333,7 +7529,22 @@ static void update_const_equal_items(COND *cond, JOIN_TAB *tab)
((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC)
{
Item_equal *item_equal= (Item_equal *) cond;
+ bool contained_const= item_equal->get_const() != NULL;
item_equal->update_const();
+ if (!contained_const && item_equal->get_const())
+ {
+ /* Update keys for range analysis */
+ Item_equal_iterator it(*item_equal);
+ Item_field *item_field;
+ while ((item_field= it++))
+ {
+ Field *field= item_field->field;
+ JOIN_TAB *stat= field->table->reginfo.join_tab;
+ key_map possible_keys= field->key_start;
+ possible_keys.intersect(field->table->keys_in_use_for_query);
+ stat[0].const_keys.merge(possible_keys);
+ }
+ }
}
}
@@ -8142,7 +8353,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
Field *field=((Item_field*) args[0])->field;
if (field->flags & AUTO_INCREMENT_FLAG && !field->table->maybe_null &&
(thd->options & OPTION_AUTO_IS_NULL) &&
- thd->insert_id() && thd->substitute_null_with_insert_id)
+ thd->current_insert_id && thd->substitute_null_with_insert_id)
{
#ifdef HAVE_QUERY_CACHE
query_cache_abort(&thd->net);
@@ -8150,9 +8361,16 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
COND *new_cond;
if ((new_cond= new Item_func_eq(args[0],
new Item_int("last_insert_id()",
- thd->insert_id(),
+ thd->current_insert_id,
21))))
{
+ /*
+ Set THD::last_insert_id_used_bin_log manually, as this
+ statement uses LAST_INSERT_ID() in a sense, and should
+ issue LAST_INSERT_ID_EVENT.
+ */
+ thd->last_insert_id_used_bin_log= TRUE;
+
cond=new_cond;
/*
Item_func_eq can't be fixed after creation so we do not check
@@ -9097,6 +9315,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
thd->variables.max_heap_table_size) :
thd->variables.tmp_table_size)/ table->s->reclength);
set_if_bigger(table->s->max_rows,1); // For dummy start options
+ /*
+ Push the LIMIT clause to the temporary table creation, so that we
+ materialize only up to 'rows_limit' records instead of all result records.
+ */
+ set_if_smaller(table->s->max_rows, rows_limit);
+ param->end_write_records= rows_limit;
+
keyinfo= param->keyinfo;
if (group)
@@ -9226,19 +9451,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
}
- /*
- Push the LIMIT clause to the temporary table creation, so that we
- materialize only up to 'rows_limit' records instead of all result records.
- This optimization is not applicable when there is GROUP BY or there is
- no GROUP BY, but there are aggregate functions, because both must be
- computed for all result rows.
- */
- if (!group && !thd->lex->current_select->with_sum_func)
- {
- set_if_smaller(table->s->max_rows, rows_limit);
- param->end_write_records= rows_limit;
- }
-
if (thd->is_fatal_error) // If end of memory
goto err; /* purecov: inspected */
table->s->db_record_offset= 1;
@@ -10129,6 +10341,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
*/
join->examined_rows++;
join->thd->row_count++;
+ DBUG_PRINT("counts", ("join->examined_rows++: %lu",
+ (ulong) join->examined_rows));
if (found)
{
@@ -10633,6 +10847,13 @@ join_init_quick_read_record(JOIN_TAB *tab)
}
+int rr_sequential(READ_RECORD *info);
+int init_read_record_seq(JOIN_TAB *tab)
+{
+ tab->read_record.read_record= rr_sequential;
+ return tab->read_record.file->ha_rnd_init(1);
+}
+
static int
test_if_quick_select(JOIN_TAB *tab)
{
@@ -10761,7 +10982,7 @@ join_ft_read_next(READ_RECORD *info)
Reading of key with key reference and one part that may be NULL
*/
-static int
+int
join_read_always_key_or_null(JOIN_TAB *tab)
{
int res;
@@ -10777,7 +10998,7 @@ join_read_always_key_or_null(JOIN_TAB *tab)
}
-static int
+int
join_read_next_same_or_null(READ_RECORD *info)
{
int error;
@@ -11981,7 +12202,6 @@ static int
create_sort_index(THD *thd, JOIN *join, ORDER *order,
ha_rows filesort_limit, ha_rows select_limit)
{
- SORT_FIELD *sortorder;
uint length;
ha_rows examined_rows;
TABLE *table;
@@ -11995,11 +12215,18 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
table= tab->table;
select= tab->select;
- if (test_if_skip_sort_order(tab,order,select_limit,0))
+ /*
+ When there is SQL_BIG_RESULT do not sort using index for GROUP BY,
+ and thus force sorting on disk.
+ */
+ if ((order != join->group_list ||
+ !(join->select_options & SELECT_BIG_RESULT)) &&
+ test_if_skip_sort_order(tab,order,select_limit,0))
DBUG_RETURN(0);
- if (!(sortorder=make_unireg_sortorder(order,&length)))
+ if (!(join->sortorder=
+ make_unireg_sortorder(order,&length,join->sortorder)))
goto err; /* purecov: inspected */
- /* It's not fatal if the following alloc fails */
+
table->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
MYF(MY_WME | MY_ZEROFILL));
table->status=0; // May be wrong if quick_select
@@ -12044,7 +12271,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
if (table->s->tmp_table)
table->file->info(HA_STATUS_VARIABLE); // Get record count
- table->sort.found_records=filesort(thd, table,sortorder, length,
+ table->sort.found_records=filesort(thd, table,join->sortorder, length,
select, filesort_limit, &examined_rows);
tab->records= table->sort.found_records; // For SQL_CALC_ROWS
if (select)
@@ -12391,7 +12618,8 @@ err:
}
-SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length)
+SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length,
+ SORT_FIELD *sortorder)
{
uint count;
SORT_FIELD *sort,*pos;
@@ -12400,7 +12628,9 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length)
count=0;
for (ORDER *tmp = order; tmp; tmp=tmp->next)
count++;
- pos=sort=(SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD)*(count+1));
+ if (!sortorder)
+ sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD)*(count+1));
+ pos=sort=sortorder;
if (!pos)
return 0;
@@ -13513,7 +13743,19 @@ bool JOIN::alloc_func_list()
disctinct->group_by optimization
*/
if (select_distinct)
+ {
group_parts+= fields_list.elements;
+ /*
+ If the ORDER clause is specified then it's possible that
+ it also will be optimized, so reserve space for it too
+ */
+ if (order)
+ {
+ ORDER *ord;
+ for (ord= order; ord; ord= ord->next)
+ group_parts++;
+ }
+ }
/* This must use calloc() as rollup_make_fields depends on this */
sum_funcs= (Item_sum**) thd->calloc(sizeof(Item_sum**) * (func_count+1) +
@@ -13996,12 +14238,17 @@ bool JOIN::rollup_init()
while ((item= it++))
{
ORDER *group_tmp;
+ bool found_in_group= 0;
+
for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next)
{
if (*group_tmp->item == item)
+ {
item->maybe_null= 1;
+ found_in_group= 1;
+ }
}
- if (item->type() == Item::FUNC_ITEM)
+ if (item->type() == Item::FUNC_ITEM && !found_in_group)
{
bool changed= FALSE;
if (change_group_ref(thd, (Item_func *) item, group_list, &changed))
diff --git a/sql/sql_select.h b/sql/sql_select.h
index d5a1bf82bc8..629b44538d8 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -36,6 +36,8 @@ typedef struct keyuse_t {
satisfied if val has NULL 'value'.
*/
bool null_rejecting;
+ /* TRUE<=> This ref access is an outer subquery reference access */
+ bool outer_ref;
} KEYUSE;
class store_key;
@@ -282,6 +284,18 @@ public:
bool union_part; // this subselect is part of union
bool optimized; // flag to avoid double optimization in EXPLAIN
+ /*
+ storage for caching buffers allocated during query execution.
+ These buffers allocations need to be cached as the thread memory pool is
+ cleared only at the end of the execution of the whole query and not caching
+ allocations that occur in repetition at execution time will result in
+ excessive memory usage.
+ */
+ SORT_FIELD *sortorder; // make_unireg_sortorder()
+ TABLE **table_reexec; // make_simple_join()
+ JOIN_TAB *join_tab_reexec; // make_simple_join()
+ /* end of allocation caching storage */
+
JOIN(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg,
select_result *result_arg)
:fields_list(fields_arg)
@@ -307,6 +321,9 @@ public:
examined_rows= 0;
exec_tmp_table1= 0;
exec_tmp_table2= 0;
+ sortorder= 0;
+ table_reexec= 0;
+ join_tab_reexec= 0;
thd= thd_arg;
sum_funcs= sum_funcs2= 0;
procedure= 0;
@@ -440,10 +457,11 @@ class store_key :public Sql_alloc
Field *to_field; // Store data here
char *null_ptr;
char err;
- public:
+public:
+ bool null_key; /* TRUE <=> the value of the key has a null part */
enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length)
- :null_ptr(null),err(0)
+ :null_ptr(null), err(0), null_key(0)
{
if (field_arg->type() == FIELD_TYPE_BLOB)
{
@@ -481,6 +499,7 @@ class store_key_field: public store_key
enum store_key_result copy()
{
copy_field.do_copy(&copy_field);
+ null_key= to_field->is_null();
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
}
const char *name() const { return field_name; }
@@ -501,8 +520,8 @@ public:
enum store_key_result copy()
{
int res= item->save_in_field(to_field, 1);
+ null_key= to_field->is_null() || item->null_value;
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
-
}
const char *name() const { return "func"; }
};
@@ -532,6 +551,7 @@ public:
err= res;
}
}
+ null_key= to_field->is_null() || item->null_value;
return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
}
const char *name() const { return "const"; }
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index eb78f4fbdae..d859db03437 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3977,7 +3977,7 @@ bool get_schema_tables_result(JOIN *join)
table_list->table->file->extra(HA_EXTRA_RESET_STATE);
table_list->table->file->delete_all_rows();
free_io_cache(table_list->table);
- filesort_free_buffers(table_list->table);
+ filesort_free_buffers(table_list->table,1);
table_list->table->null_row= 0;
}
else
@@ -4277,7 +4277,7 @@ ST_FIELD_INFO triggers_fields_info[]=
ST_FIELD_INFO variables_fields_info[]=
{
{"Variable_name", 80, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
- {"Value", 255, MYSQL_TYPE_STRING, 0, 0, "Value"},
+ {"Value", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, "Value"},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
};
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a340c5ffc98..3fc74ad1371 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -224,7 +224,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
DBUG_ENTER("mysql_rm_table_part2");
- if (lock_table_names(thd, tables))
+ if (!drop_temporary && lock_table_names(thd, tables))
DBUG_RETURN(1);
/* Don't give warnings for not found errors, as we already generate notes */
@@ -334,7 +334,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
}
}
- unlock_table_names(thd, tables, (TABLE_LIST*) 0);
+ if (!drop_temporary)
+ unlock_table_names(thd, tables, (TABLE_LIST*) 0);
thd->no_warnings_for_error= 0;
DBUG_RETURN(error);
}
@@ -2266,7 +2267,6 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
goto send_result;
}
- table->table->pos_in_table_list= table;
if ((table->table->db_stat & HA_READ_ONLY) && open_for_modify)
{
char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE];
@@ -3154,9 +3154,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
ha_rows copied,deleted;
ulonglong next_insert_id;
uint db_create_options, used_fields;
- enum db_type old_db_type,new_db_type;
+ enum db_type old_db_type, new_db_type, table_type;
bool need_copy_table;
bool no_table_reopen= FALSE, varchar= FALSE;
+ frm_type_enum frm_type;
DBUG_ENTER("mysql_alter_table");
thd->proc_info="init";
@@ -3174,6 +3175,51 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (alter_info->tablespace_op != NO_TABLESPACE_OP)
DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
alter_info->tablespace_op));
+ sprintf(new_name_buff,"%s/%s/%s%s",mysql_data_home, db, table_name, reg_ext);
+ unpack_filename(new_name_buff, new_name_buff);
+ if (lower_case_table_names != 2)
+ my_casedn_str(files_charset_info, new_name_buff);
+ frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
+ /* Rename a view */
+ if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))
+ {
+ /*
+ Avoid problems with a rename on a table that we have locked or
+ if the user is trying to to do this in a transcation context
+ */
+
+ if (thd->locked_tables || thd->active_transaction())
+ {
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
+ DBUG_RETURN(1);
+ }
+
+ if (wait_if_global_read_lock(thd,0,1))
+ DBUG_RETURN(1);
+ VOID(pthread_mutex_lock(&LOCK_open));
+ if (lock_table_names(thd, table_list))
+ goto view_err;
+
+ error=0;
+ if (!do_rename(thd, table_list, new_db, new_name, new_name, 1))
+ {
+ if (mysql_bin_log.is_open())
+ {
+ thd->clear_error();
+ Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
+ mysql_bin_log.write(&qinfo);
+ }
+ send_ok(thd);
+ }
+
+ unlock_table_names(thd, table_list, (TABLE_LIST*) 0);
+
+view_err:
+ pthread_mutex_unlock(&LOCK_open);
+ start_waiting_global_read_lock(thd);
+ DBUG_RETURN(error);
+ }
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
DBUG_RETURN(TRUE);
@@ -4049,7 +4095,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
if (thd->lex->select_lex.setup_ref_array(thd, order_num) ||
setup_order(thd, thd->lex->select_lex.ref_pointer_array,
&tables, fields, all_fields, order) ||
- !(sortorder=make_unireg_sortorder(order, &length)) ||
+ !(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
(from->sort.found_records = filesort(thd, from, sortorder, length,
(SQL_SELECT *) 0, HA_POS_ERROR,
&examined_rows)) ==
@@ -4210,8 +4256,6 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
}
else
{
- t->pos_in_table_list= table;
-
if (t->file->table_flags() & HA_HAS_CHECKSUM &&
!(check_opt->flags & T_EXTEND))
protocol->store((ulonglong)t->file->checksum());
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 6bb50d602c3..c0c9c34cbeb 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -1548,6 +1548,38 @@ void Table_triggers_list::mark_fields_used(THD *thd, trg_event_type event)
/*
+ Check if field of subject table can be changed in before update trigger.
+
+ SYNOPSIS
+ is_updated_in_before_update_triggers()
+ field Field object for field to be checked
+
+ NOTE
+ Field passed to this function should be bound to the same
+ TABLE object as Table_triggers_list.
+
+ RETURN VALUE
+ TRUE Field is changed
+ FALSE Otherwise
+*/
+
+bool Table_triggers_list::is_updated_in_before_update_triggers(Field *fld)
+{
+ Item_trigger_field *trg_fld;
+ for (trg_fld= trigger_fields[TRG_EVENT_UPDATE][TRG_ACTION_BEFORE];
+ trg_fld != 0;
+ trg_fld= trg_fld->next_trg_field)
+ {
+ if (trg_fld->get_settable_routine_parameter() &&
+ trg_fld->field_idx != (uint)-1 &&
+ table->field[trg_fld->field_idx]->eq(fld))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+/*
Trigger BUG#14090 compatibility hook
SYNOPSIS
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h
index 521905a2c56..7e0fadfa677 100644
--- a/sql/sql_trigger.h
+++ b/sql/sql_trigger.h
@@ -116,15 +116,12 @@ public:
bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]);
}
- bool has_before_update_triggers()
- {
- return test(bodies[TRG_EVENT_UPDATE][TRG_ACTION_BEFORE]);
- }
-
void set_table(TABLE *new_table);
void mark_fields_used(THD *thd, trg_event_type event);
+ bool is_updated_in_before_update_triggers(Field *fld);
+
friend class Item_trigger_field;
friend int sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex,
TABLE_LIST *table);
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a5a767b6ebc..d431b671f18 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -274,7 +274,7 @@ int mysql_update(THD *thd,
{
used_index= select->quick->index;
used_key_is_modified= (!select->quick->unique_key_range() &&
- select->quick->check_if_keys_used(&fields));
+ select->quick->is_keys_used(&fields));
}
else
{
@@ -282,7 +282,7 @@ int mysql_update(THD *thd,
if (used_index == MAX_KEY) // no index for sort order
used_index= table->file->key_used_on_scan;
if (used_index != MAX_KEY)
- used_key_is_modified= check_if_key_used(table, used_index, fields);
+ used_key_is_modified= is_key_used(table, used_index, fields);
}
if (used_key_is_modified || order)
@@ -311,7 +311,7 @@ int mysql_update(THD *thd,
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
- if (!(sortorder=make_unireg_sortorder(order, &length)) ||
+ if (!(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length,
select, limit,
&examined_rows))
@@ -568,7 +568,7 @@ int mysql_update(THD *thd,
thd->row_count_func=
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
send_ok(thd, (ulong) thd->row_count_func,
- thd->insert_id_used ? thd->insert_id() : 0L,buff);
+ thd->insert_id_used ? thd->last_insert_id : 0L,buff);
DBUG_PRINT("info",("%d records updated",updated));
}
thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */
@@ -1095,6 +1095,8 @@ multi_update::initialize_tables(JOIN *join)
List<Item> temp_fields= *fields_for_table[cnt];
ORDER group;
+ if (ignore)
+ table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
if (table == main_table) // First table in join
{
if (safe_update_on_fly(join->join_tab, &temp_fields))
@@ -1189,21 +1191,15 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List<Item> *fields)
return TRUE; // At most one matching row
case JT_REF:
case JT_REF_OR_NULL:
- return !check_if_key_used(table, join_tab->ref.key, *fields) &&
- !(table->triggers &&
- table->triggers->has_before_update_triggers());
+ return !is_key_used(table, join_tab->ref.key, *fields);
case JT_ALL:
/* If range search on index */
if (join_tab->quick)
- return !join_tab->quick->check_if_keys_used(fields) &&
- !(table->triggers &&
- table->triggers->has_before_update_triggers());
+ return !join_tab->quick->is_keys_used(fields);
/* If scanning in clustered key */
if ((table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
table->s->primary_key < MAX_KEY)
- return !check_if_key_used(table, table->s->primary_key, *fields) &&
- !(table->triggers &&
- table->triggers->has_before_update_triggers());
+ return !is_key_used(table, table->s->primary_key, *fields);
return TRUE;
default:
break; // Avoid compler warning
@@ -1216,7 +1212,11 @@ multi_update::~multi_update()
{
TABLE_LIST *table;
for (table= update_tables ; table; table= table->next_local)
+ {
table->table->no_keyread= table->table->no_cache= 0;
+ if (ignore)
+ table->table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ }
if (tmp_tables)
{
@@ -1567,6 +1567,6 @@ bool multi_update::send_eof()
thd->row_count_func=
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
::send_ok(thd, (ulong) thd->row_count_func,
- thd->insert_id_used ? thd->insert_id() : 0L,buff);
+ thd->insert_id_used ? thd->last_insert_id : 0L,buff);
return FALSE;
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index cb105d05332..e5c11f6d437 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -650,11 +650,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token UNIX_TIMESTAMP
%token UNKNOWN_SYM
%token UNLOCK_SYM
-%token UNLOCK_SYM
%token UNSIGNED
%token UNTIL_SYM
-%token UNTIL_SYM
-%token UPDATE_SYM
%token UPDATE_SYM
%token UPGRADE_SYM
%token USAGE
@@ -764,7 +761,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <item_list>
expr_list udf_expr_list udf_expr_list2 when_list
- ident_list ident_list_arg
+ ident_list ident_list_arg opt_expr_list
%type <var_type>
option_type opt_var_type opt_var_ident_type
@@ -4724,7 +4721,7 @@ simple_expr:
{ $$= new Item_func_trim($5,$3); }
| TRUNCATE_SYM '(' expr ',' expr ')'
{ $$= new Item_func_round($3,$5,1); }
- | ident '.' ident '(' udf_expr_list ')'
+ | ident '.' ident '(' opt_expr_list ')'
{
LEX *lex= Lex;
sp_name *name= new sp_name($1, $3);
@@ -4741,27 +4738,27 @@ simple_expr:
{
#ifdef HAVE_DLOPEN
udf_func *udf= 0;
+ LEX *lex= Lex;
if (using_udf_functions &&
(udf= find_udf($1.str, $1.length)) &&
udf->type == UDFTYPE_AGGREGATE)
{
- LEX *lex= Lex;
if (lex->current_select->inc_in_sum_expr())
{
yyerror(ER(ER_SYNTAX_ERROR));
YYABORT;
}
}
- $<udf>$= udf;
+ lex->current_select->udf_list.push_front(udf);
#endif
}
udf_expr_list ')'
{
#ifdef HAVE_DLOPEN
- udf_func *udf= $<udf>3;
- SELECT_LEX *sel= Select;
+ udf_func *udf;
+ LEX *lex= Lex;
- if (udf)
+ if (NULL != (udf= lex->current_select->udf_list.pop()))
{
if (udf->type == UDFTYPE_AGGREGATE)
Select->in_sum_expr--;
@@ -4988,12 +4985,29 @@ udf_expr_list3:
udf_expr:
remember_name expr remember_end select_alias
{
+ udf_func *udf= Select->udf_list.head();
+ /*
+ Use Item::name as a storage for the attribute value of user
+ defined function argument. It is safe to use Item::name
+ because the syntax will not allow having an explicit name here.
+ See WL#1017 re. udf attributes.
+ */
if ($4.str)
{
+ if (!udf)
+ {
+ /*
+ Disallow using AS to specify explicit names for the arguments
+ of stored routine calls
+ */
+ yyerror(ER(ER_SYNTAX_ERROR));
+ YYABORT;
+ }
+
$2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info);
}
- else
+ else if (udf)
$2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
$$= $2;
}
@@ -5114,6 +5128,11 @@ cast_type:
| DECIMAL_SYM float_options { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
;
+opt_expr_list:
+ /* empty */ { $$= NULL; }
+ | expr_list { $$= $1;}
+ ;
+
expr_list:
{ Select->expr_list.push_front(new List<Item>); }
expr_list2
diff --git a/sql/stacktrace.c b/sql/stacktrace.c
index 43f35c452f7..a2fe2ab88f1 100644
--- a/sql/stacktrace.c
+++ b/sql/stacktrace.c
@@ -222,7 +222,7 @@ terribly wrong...\n");
fprintf(stderr, "Stack trace seems successful - bottom reached\n");
end:
- fprintf(stderr, "Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved\n\
+ fprintf(stderr, "Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Resolved\n\
stack trace is much more helpful in diagnosing the problem, so please do \n\
resolve it\n");
}
diff --git a/sql/table.cc b/sql/table.cc
index 1886fdb0b82..9aecf28ab8c 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -468,7 +468,21 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
count)))
goto err;
for (count= 0; count < interval->count; count++)
- interval->type_lengths[count]= strlen(interval->type_names[count]);
+ {
+ char *val= (char*) interval->type_names[count];
+ interval->type_lengths[count]= strlen(val);
+ /*
+ Replace all ',' symbols with NAMES_SEP_CHAR.
+ See the comment in unireg.cc, pack_fields() function
+ for details.
+ */
+ for (uint cnt= 0 ; cnt < interval->type_lengths[count] ; cnt++)
+ {
+ char c= val[cnt];
+ if (c == ',')
+ val[cnt]= NAMES_SEP_CHAR;
+ }
+ }
interval->type_lengths[count]= 0;
}
}
@@ -1963,12 +1977,13 @@ bool st_table_list::prep_where(THD *thd, Item **conds,
this expression will not be moved to WHERE condition (i.e. will
be clean correctly for PS/SP)
*/
- tbl->on_expr= and_conds(tbl->on_expr, where);
+ tbl->on_expr= and_conds(tbl->on_expr,
+ where->copy_andor_structure(thd));
break;
}
}
if (tbl == 0)
- *conds= and_conds(*conds, where);
+ *conds= and_conds(*conds, where->copy_andor_structure(thd));
if (arena)
thd->restore_active_arena(arena, &backup);
where_processed= TRUE;
@@ -3017,6 +3032,23 @@ void st_table_list::reinit_before_use(THD *thd)
embedding->nested_join->join_list.head() == embedded);
}
+/*
+ Return subselect that contains the FROM list this table is taken from
+
+ SYNOPSIS
+ st_table_list::containing_subselect()
+
+ RETURN
+ Subselect item for the subquery that contains the FROM list
+ this table is taken from if there is any
+ 0 - otherwise
+
+*/
+
+Item_subselect *st_table_list::containing_subselect()
+{
+ return (select_lex ? select_lex->master_unit()->item : 0);
+}
/*****************************************************************************
** Instansiate templates
diff --git a/sql/table.h b/sql/table.h
index 5136ac2c4db..f0190353328 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -18,6 +18,7 @@
/* Structs that defines the TABLE */
class Item; /* Needed by ORDER */
+class Item_subselect;
class GRANT_TABLE;
class st_select_lex_unit;
class st_select_lex;
@@ -68,6 +69,9 @@ enum frm_type_enum
typedef struct st_filesort_info
{
IO_CACHE *io_cache; /* If sorted through filebyte */
+ uchar **sort_keys; /* Buffer for sorting keys */
+ byte *buffpek; /* Buffer for buffpek structures */
+ uint buffpek_len; /* Max number of buffpeks in the buffer */
byte *addon_buf; /* Pointer to a buffer if sorted with fields */
uint addon_length; /* Length of the buffer */
struct st_sort_addon_field *addon_field; /* Pointer to the fields info */
@@ -678,6 +682,7 @@ typedef struct st_table_list
procedure.
*/
void reinit_before_use(THD *thd);
+ Item_subselect *containing_subselect();
private:
bool prep_check_option(THD *thd, uint8 check_opt_type);
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 93afd9c9e4e..768a288ca19 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -718,6 +718,21 @@ static bool pack_fields(File file, List<create_field> &create_fields,
tmp.append(NAMES_SEP_CHAR);
for (const char **pos=field->interval->type_names ; *pos ; pos++)
{
+ char *val= (char*) *pos;
+ uint str_len= strlen(val);
+ /*
+ Note, hack: in old frm NAMES_SEP_CHAR is used to separate
+ names in the interval (ENUM/SET). To allow names to contain
+ NAMES_SEP_CHAR, we replace it with a comma before writing frm.
+ Backward conversion is done during frm file opening,
+ See table.cc, openfrm() function
+ */
+ for (uint cnt= 0 ; cnt < str_len ; cnt++)
+ {
+ char c= val[cnt];
+ if (c == NAMES_SEP_CHAR)
+ val[cnt]= ',';
+ }
tmp.append(*pos);
tmp.append(NAMES_SEP_CHAR);
}
diff --git a/strings/CHARSET_INFO.txt b/strings/CHARSET_INFO.txt
index f7a10f95880..3fd262c6f12 100644
--- a/strings/CHARSET_INFO.txt
+++ b/strings/CHARSET_INFO.txt
@@ -33,7 +33,7 @@ typedef struct charset_info_st
uint strxfrm_multiply;
uint mbminlen;
uint mbmaxlen;
- char max_sort_char; /* For LIKE optimization */
+ uint16 max_sort_char; /* For LIKE optimization */
MY_CHARSET_HANDLER *cset;
MY_COLLATION_HANDLER *coll;
@@ -134,7 +134,15 @@ Misc fields
mbmaxlen - maximum multibyte sequence length.
1 for 8bit charsets. Can be also 2 or 3.
-
+ max_sort_char - for LIKE range
+ in case of 8bit character sets - native code
+ of maximum character (max_str pad byte);
+ in case of UTF8 and UCS2 - Unicode code of the maximum
+ possible character (usually U+FFFF). This code is
+ converted to multibyte representation (usually 0xEFBFBF)
+ and then used as a pad sequence for max_str.
+ in case of other multibyte character sets -
+ max_str pad byte (usually 0xFF).
MY_CHARSET_HANDLER
==================
diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c
index 0ca1cf21129..479fb789816 100644
--- a/strings/ctype-big5.c
+++ b/strings/ctype-big5.c
@@ -6370,6 +6370,7 @@ static MY_CHARSET_HANDLER my_charset_big5_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
index 54c35c82652..0bd5a1fda76 100644
--- a/strings/ctype-bin.c
+++ b/strings/ctype-bin.c
@@ -517,6 +517,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-cp932.c b/strings/ctype-cp932.c
index 5f8a93b1c2b..b4e9ba16d92 100644
--- a/strings/ctype-cp932.c
+++ b/strings/ctype-cp932.c
@@ -5492,6 +5492,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-euc_kr.c b/strings/ctype-euc_kr.c
index d6df46f7e05..40e0f4e3d2d 100644
--- a/strings/ctype-euc_kr.c
+++ b/strings/ctype-euc_kr.c
@@ -8711,6 +8711,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-eucjpms.c b/strings/ctype-eucjpms.c
index 348eb2f6e87..65fef2dfc4c 100644
--- a/strings/ctype-eucjpms.c
+++ b/strings/ctype-eucjpms.c
@@ -8677,6 +8677,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-gb2312.c b/strings/ctype-gb2312.c
index 29ecafc3527..c2fc1e2c190 100644
--- a/strings/ctype-gb2312.c
+++ b/strings/ctype-gb2312.c
@@ -5762,6 +5762,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c
index ef1b33fd82c..c4d06d67eb9 100644
--- a/strings/ctype-gbk.c
+++ b/strings/ctype-gbk.c
@@ -10015,6 +10015,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-latin1.c b/strings/ctype-latin1.c
index a3f5aec9605..1298b66bb7e 100644
--- a/strings/ctype-latin1.c
+++ b/strings/ctype-latin1.c
@@ -411,6 +411,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c
index 0f95a688d85..394111be3bc 100644
--- a/strings/ctype-mb.c
+++ b/strings/ctype-mb.c
@@ -474,15 +474,35 @@ static void my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
/*
- Write max key: create a buffer with multibyte
- representation of the max_sort_char character,
- and copy it into max_str in a loop.
+ Fill the given buffer with 'maximum character' for given charset
+ SYNOPSIS
+ pad_max_char()
+ cs Character set
+ str Start of buffer to fill
+ end End of buffer to fill
+
+ DESCRIPTION
+ Write max key:
+ - for non-Unicode character sets:
+ just set to 255.
+ - for Unicode character set (utf-8):
+ create a buffer with multibyte representation of the max_sort_char
+ character, and copy it into max_str in a loop.
*/
static void pad_max_char(CHARSET_INFO *cs, char *str, char *end)
{
char buf[10];
- char buflen= cs->cset->wc_mb(cs, cs->max_sort_char, (uchar*) buf,
- (uchar*) buf + sizeof(buf));
+ char buflen;
+
+ if (!(cs->state & MY_CS_UNICODE))
+ {
+ bfill(str, end - str, 255);
+ return;
+ }
+
+ buflen= cs->cset->wc_mb(cs, cs->max_sort_char, (uchar*) buf,
+ (uchar*) buf + sizeof(buf));
+
DBUG_ASSERT(buflen > 0);
do
{
@@ -927,7 +947,7 @@ MY_COLLATION_HANDLER my_collation_mb_bin_handler =
my_strnncollsp_mb_bin,
my_strnxfrm_mb_bin,
my_strnxfrmlen_simple,
- my_like_range_simple,
+ my_like_range_mb,
my_wildcmp_mb_bin,
my_strcasecmp_mb_bin,
my_instr_mb,
diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c
index 12ef77c59b1..e40a1948dcf 100644
--- a/strings/ctype-simple.c
+++ b/strings/ctype-simple.c
@@ -17,6 +17,7 @@
#include <my_global.h>
#include "m_string.h"
#include "m_ctype.h"
+#include "my_sys.h" /* Needed for MY_ERRNO_ERANGE */
#include <errno.h>
#include "stdarg.h"
@@ -1354,6 +1355,341 @@ longlong my_strtoll10_8bit(CHARSET_INFO *cs __attribute__((unused)),
}
+#undef ULONGLONG_MAX
+/*
+ Needed under MetroWerks Compiler, since MetroWerks compiler does not
+ properly handle a constant expression containing a mod operator
+*/
+#if defined(__NETWARE__) && defined(__MWERKS__)
+static ulonglong ulonglong_max= ~(ulonglong) 0;
+#define ULONGLONG_MAX ulonglong_max
+#else
+#define ULONGLONG_MAX (~(ulonglong) 0)
+#endif /* __NETWARE__ && __MWERKS__ */
+
+
+#define CUTOFF (ULONGLONG_MAX / 10)
+#define CUTLIM (ULONGLONG_MAX % 10)
+#define DIGITS_IN_ULONGLONG 20
+
+static ulonglong d10[DIGITS_IN_ULONGLONG]=
+{
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000,
+ 1000000,
+ 10000000,
+ 100000000,
+ 1000000000,
+ 10000000000ULL,
+ 100000000000ULL,
+ 1000000000000ULL,
+ 10000000000000ULL,
+ 100000000000000ULL,
+ 1000000000000000ULL,
+ 10000000000000000ULL,
+ 100000000000000000ULL,
+ 1000000000000000000ULL,
+ 10000000000000000000ULL
+};
+
+
+/*
+
+ Convert a string to unsigned long long integer value
+ with rounding.
+
+ SYNOPSYS
+ my_strntoull10_8bit()
+ cs in pointer to character set
+ str in pointer to the string to be converted
+ length in string length
+ unsigned_flag in whether the number is unsigned
+ endptr out pointer to the stop character
+ error out returned error code
+
+ DESCRIPTION
+ This function takes the decimal representation of integer number
+ from string str and converts it to an signed or unsigned
+ long long integer value.
+ Space characters and tab are ignored.
+ A sign character might precede the digit characters.
+ The number may have any number of pre-zero digits.
+ The number may have decimal point and exponent.
+ Rounding is always done in "away from zero" style:
+ 0.5 -> 1
+ -0.5 -> -1
+
+ The function stops reading the string str after "length" bytes
+ or at the first character that is not a part of correct number syntax:
+
+ <signed numeric literal> ::=
+ [ <sign> ] <exact numeric literal> [ E [ <sign> ] <unsigned integer> ]
+
+ <exact numeric literal> ::=
+ <unsigned integer> [ <period> [ <unsigned integer> ] ]
+ | <period> <unsigned integer>
+ <unsigned integer> ::= <digit>...
+
+ RETURN VALUES
+ Value of string as a signed/unsigned longlong integer
+
+ endptr cannot be NULL. The function will store the end pointer
+ to the stop character here.
+
+ The error parameter contains information how things went:
+ 0 ok
+ ERANGE If the the value of the converted number is out of range
+ In this case the return value is:
+ - ULONGLONG_MAX if unsigned_flag and the number was too big
+ - 0 if unsigned_flag and the number was negative
+ - LONGLONG_MAX if no unsigned_flag and the number is too big
+ - LONGLONG_MIN if no unsigned_flag and the number it too big negative
+
+ EDOM If the string didn't contain any digits.
+ In this case the return value is 0.
+*/
+
+ulonglong
+my_strntoull10rnd_8bit(CHARSET_INFO *cs __attribute__((unused)),
+ const char *str, uint length, int unsigned_flag,
+ char **endptr, int *error)
+{
+ const char *dot, *end9, *beg, *end= str + length;
+ ulonglong ull;
+ ulong ul;
+ unsigned char ch;
+ int shift= 0, digits= 0, negative, addon;
+
+ /* Skip leading spaces and tabs */
+ for ( ; str < end && (*str == ' ' || *str == '\t') ; str++);
+
+ if (str >= end)
+ goto ret_edom;
+
+ if ((negative= (*str == '-')) || *str=='+') /* optional sign */
+ {
+ if (++str == end)
+ goto ret_edom;
+ }
+
+ beg= str;
+ end9= (str + 9) > end ? end : (str + 9);
+ /* Accumulate small number into ulong, for performance purposes */
+ for (ul= 0 ; str < end9 && (ch= (unsigned char) (*str - '0')) < 10; str++)
+ {
+ ul= ul * 10 + ch;
+ }
+
+ if (str >= end) /* Small number without dots and expanents */
+ {
+ *endptr= (char*) str;
+ if (negative)
+ {
+ if (unsigned_flag)
+ {
+ *error= ul ? MY_ERRNO_ERANGE : 0;
+ return 0;
+ }
+ else
+ {
+ *error= 0;
+ return (ulonglong) (longlong) (long) -ul;
+ }
+ }
+ else
+ {
+ *error=0;
+ return (ulonglong) ul;
+ }
+ }
+
+ digits= str - beg;
+
+ /* Continue to accumulate into ulonglong */
+ for (dot= NULL, ull= ul; str < end; str++)
+ {
+ if ((ch= (unsigned char) (*str - '0')) < 10)
+ {
+ if (ull < CUTOFF || (ull == CUTOFF && ch <= CUTLIM))
+ {
+ ull= ull * 10 + ch;
+ digits++;
+ continue;
+ }
+ /*
+ Adding the next digit would overflow.
+ Remember the next digit in "addon", for rounding.
+ Scan all digits with an optional single dot.
+ */
+ if (ull == CUTOFF)
+ {
+ ull= ULONGLONG_MAX;
+ addon= 1;
+ str++;
+ }
+ else
+ addon= (*str >= '5');
+ for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; str++)
+ {
+ if (!dot)
+ shift++;
+ }
+ if (str < end && *str == '.' && !dot)
+ {
+ str++;
+ for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; str++);
+ }
+ goto exp;
+ }
+
+ if (*str == '.')
+ {
+ if (dot)
+ {
+ /* The second dot character */
+ addon= 0;
+ goto exp;
+ }
+ else
+ {
+ dot= str + 1;
+ }
+ continue;
+ }
+
+ /* Unknown character, exit the loop */
+ break;
+ }
+ shift= dot ? dot - str : 0; /* Right shift */
+ addon= 0;
+
+exp: /* [ E [ <sign> ] <unsigned integer> ] */
+
+ if (!digits)
+ {
+ str= beg;
+ goto ret_edom;
+ }
+
+ if (str < end && (*str == 'e' || *str == 'E'))
+ {
+ str++;
+ if (str < end)
+ {
+ int negative_exp, exp;
+ if ((negative_exp= (*str == '-')) || *str=='+')
+ {
+ if (++str == end)
+ goto ret_sign;
+ }
+ for (exp= 0 ;
+ str < end && (ch= (unsigned char) (*str - '0')) < 10;
+ str++)
+ {
+ exp= exp * 10 + ch;
+ }
+ shift+= negative_exp ? -exp : exp;
+ }
+ }
+
+ if (shift == 0) /* No shift, check addon digit */
+ {
+ if (addon)
+ {
+ if (ull == ULONGLONG_MAX)
+ goto ret_too_big;
+ ull++;
+ }
+ goto ret_sign;
+ }
+
+ if (shift < 0) /* Right shift */
+ {
+ ulonglong d, r;
+
+ if (-shift >= DIGITS_IN_ULONGLONG)
+ goto ret_zero; /* Exponent is a big negative number, return 0 */
+
+ d= d10[-shift];
+ r= (ull % d) * 2;
+ ull /= d;
+ if (r >= d)
+ ull++;
+ goto ret_sign;
+ }
+
+ if (shift > DIGITS_IN_ULONGLONG) /* Huge left shift */
+ {
+ if (!ull)
+ goto ret_sign;
+ goto ret_too_big;
+ }
+
+ for ( ; shift > 0; shift--, ull*= 10) /* Left shift */
+ {
+ if (ull > CUTOFF)
+ goto ret_too_big; /* Overflow, number too big */
+ }
+
+ret_sign:
+ *endptr= (char*) str;
+
+ if (!unsigned_flag)
+ {
+ if (negative)
+ {
+ if (ull > (ulonglong) LONGLONG_MIN)
+ {
+ *error= MY_ERRNO_ERANGE;
+ return (ulonglong) LONGLONG_MIN;
+ }
+ *error= 0;
+ return (ulonglong) -ull;
+ }
+ else
+ {
+ if (ull > (ulonglong) LONGLONG_MAX)
+ {
+ *error= MY_ERRNO_ERANGE;
+ return (ulonglong) LONGLONG_MAX;
+ }
+ *error= 0;
+ return ull;
+ }
+ }
+
+ /* Unsigned number */
+ if (negative && ull)
+ {
+ *error= MY_ERRNO_ERANGE;
+ return 0;
+ }
+ *error= 0;
+ return ull;
+
+ret_zero:
+ *endptr= (char*) str;
+ *error= 0;
+ return 0;
+
+ret_edom:
+ *endptr= (char*) str;
+ *error= MY_ERRNO_EDOM;
+ return 0;
+
+ret_too_big:
+ *endptr= (char*) str;
+ *error= MY_ERRNO_ERANGE;
+ return unsigned_flag ?
+ ULONGLONG_MAX :
+ negative ? (ulonglong) LONGLONG_MIN : (ulonglong) LONGLONG_MAX;
+}
+
+
/*
Check if a constant can be propagated
@@ -1434,6 +1770,7 @@ MY_CHARSET_HANDLER my_charset_8bit_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-sjis.c b/strings/ctype-sjis.c
index 57d6d8bae2b..3854837e09a 100644
--- a/strings/ctype-sjis.c
+++ b/strings/ctype-sjis.c
@@ -4663,6 +4663,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c
index dc4f18b516b..85ebbe82731 100644
--- a/strings/ctype-tis620.c
+++ b/strings/ctype-tis620.c
@@ -891,6 +891,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c
index 97dca79e84b..4a60220f73e 100644
--- a/strings/ctype-ucs2.c
+++ b/strings/ctype-ucs2.c
@@ -974,6 +974,35 @@ double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)),
}
+ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs __attribute__((unused)),
+ const char *nptr, uint length, int unsign_fl,
+ char **endptr, int *err)
+{
+ char buf[256], *b= buf;
+ ulonglong res;
+ const uchar *end, *s= (const uchar*) nptr;
+ my_wc_t wc;
+ int cnv;
+
+ /* Cut too long strings */
+ if (length >= sizeof(buf))
+ length= sizeof(buf)-1;
+ end= s + length;
+
+ while ((cnv= cs->cset->mb_wc(cs,&wc,s,end)) > 0)
+ {
+ s+= cnv;
+ if (wc > (int) (uchar) 'e' || !wc)
+ break; /* Can't be a number part */
+ *b++= (char) wc;
+ }
+
+ res= my_strntoull10rnd_8bit(cs, buf, b - buf, unsign_fl, endptr, err);
+ *endptr= (char*) nptr + 2 * (uint) (*endptr- buf);
+ return res;
+}
+
+
/*
This is a fast version optimized for the case of radix 10 / -10
*/
@@ -1629,6 +1658,7 @@ MY_CHARSET_HANDLER my_charset_ucs2_handler=
my_strntoull_ucs2,
my_strntod_ucs2,
my_strtoll10_ucs2,
+ my_strntoull10rnd_ucs2,
my_scan_ucs2
};
diff --git a/strings/ctype-ujis.c b/strings/ctype-ujis.c
index ca27b4bef6b..675ac918e2c 100644
--- a/strings/ctype-ujis.c
+++ b/strings/ctype-ujis.c
@@ -8545,6 +8545,7 @@ static MY_CHARSET_HANDLER my_charset_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c
index 3594ab954c6..ae2c04fb068 100644
--- a/strings/ctype-utf8.c
+++ b/strings/ctype-utf8.c
@@ -2548,6 +2548,7 @@ MY_CHARSET_HANDLER my_charset_utf8_handler=
my_strntoull_8bit,
my_strntod_8bit,
my_strtoll10_8bit,
+ my_strntoull10rnd_8bit,
my_scan_8bit
};
@@ -2611,7 +2612,7 @@ CHARSET_INFO my_charset_utf8_bin=
1, /* mbminlen */
3, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_utf8_handler,
diff --git a/strings/strtod.c b/strings/strtod.c
index 7171a6e0801..ddb570718a0 100644
--- a/strings/strtod.c
+++ b/strings/strtod.c
@@ -30,7 +30,8 @@
#include "m_ctype.h"
#define MAX_DBL_EXP 308
-#define MAX_RESULT_FOR_MAX_EXP 1.79769313486232
+#define MAX_RESULT_FOR_MAX_EXP 1.7976931348623157
+#define MIN_RESULT_FOR_MIN_EXP 2.225073858507202
static double scaler10[] = {
1.0, 1e10, 1e20, 1e30, 1e40, 1e50, 1e60, 1e70, 1e80, 1e90
};
@@ -57,10 +58,11 @@ double my_strtod(const char *str, char **end_ptr, int *error)
{
double result= 0.0;
uint negative= 0, ndigits, dec_digits= 0, neg_exp= 0;
- int exp= 0, digits_after_dec_point= 0;
+ int exp= 0, digits_after_dec_point= 0, tmp_exp;
const char *old_str, *end= *end_ptr, *start_of_number;
char next_char;
my_bool overflow=0;
+ double scaler= 1.0;
*error= 0;
if (str >= end)
@@ -91,6 +93,7 @@ double my_strtod(const char *str, char **end_ptr, int *error)
while ((next_char= *str) >= '0' && next_char <= '9')
{
result= result*10.0 + (next_char - '0');
+ scaler= scaler*10.0;
if (++str == end)
{
next_char= 0; /* Found end of string */
@@ -114,6 +117,7 @@ double my_strtod(const char *str, char **end_ptr, int *error)
{
result= result*10.0 + (next_char - '0');
digits_after_dec_point++;
+ scaler= scaler*10.0;
if (++str == end)
{
next_char= 0;
@@ -144,39 +148,54 @@ double my_strtod(const char *str, char **end_ptr, int *error)
} while (str < end && my_isdigit(&my_charset_latin1, *str));
}
}
- if ((exp= (neg_exp ? exp + digits_after_dec_point :
- exp - digits_after_dec_point)))
+ tmp_exp= neg_exp ? exp + digits_after_dec_point : exp - digits_after_dec_point;
+ if (tmp_exp)
{
- double scaler;
- if (exp < 0)
- {
- exp= -exp;
- neg_exp= 1; /* neg_exp was 0 before */
- }
- if (exp + ndigits >= MAX_DBL_EXP + 1 && result)
+ int order;
+ /*
+ Check for underflow/overflow.
+ order is such an integer number that f = C * 10 ^ order,
+ where f is the resulting floating point number and 1 <= C < 10.
+ Here we compute the modulus
+ */
+ order= exp + (neg_exp ? -1 : 1) * (ndigits - 1);
+ if (order < 0)
+ order= -order;
+ if (order >= MAX_DBL_EXP && result)
{
- /*
- This is not 100 % as we actually will give an owerflow for
- 17E307 but not for 1.7E308 but lets cut some corners to make life
- simpler
- */
- if (exp + ndigits > MAX_DBL_EXP + 1 ||
- result >= MAX_RESULT_FOR_MAX_EXP)
+ double c;
+ /* Compute modulus of C (see comment above) */
+ c= result / scaler * 10.0;
+ if (neg_exp)
{
- if (neg_exp)
+ if (order > MAX_DBL_EXP || c < MIN_RESULT_FOR_MIN_EXP)
+ {
result= 0.0;
- else
+ goto done;
+ }
+ }
+ else
+ {
+ if (order > MAX_DBL_EXP || c > MAX_RESULT_FOR_MAX_EXP)
+ {
overflow= 1;
- goto done;
+ goto done;
+ }
}
}
- scaler= 1.0;
+
+ exp= tmp_exp;
+ if (exp < 0)
+ {
+ exp= -exp;
+ neg_exp= 1; /* neg_exp was 0 before */
+ }
while (exp >= 100)
{
- scaler*= 1.0e100;
+ result= neg_exp ? result/1.0e100 : result*1.0e100;
exp-= 100;
}
- scaler*= scaler10[exp/10]*scaler1[exp%10];
+ scaler= scaler10[exp/10]*scaler1[exp%10];
if (neg_exp)
result/= scaler;
else
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 8a444590301..d3f39296445 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -15237,6 +15237,43 @@ static void test_bug21206()
DBUG_VOID_RETURN;
}
+/*
+ Bug#21726: Incorrect result with multiple invocations of
+ LAST_INSERT_ID
+
+ Test that client gets updated value of insert_id on UPDATE that uses
+ LAST_INSERT_ID(expr).
+*/
+static void test_bug21726()
+{
+ const char *create_table[]=
+ {
+ "DROP TABLE IF EXISTS t1",
+ "CREATE TABLE t1 (i INT)",
+ "INSERT INTO t1 VALUES (1)",
+ };
+ const char *update_query= "UPDATE t1 SET i= LAST_INSERT_ID(i + 1)";
+ int rc;
+ my_ulonglong insert_id;
+
+ DBUG_ENTER("test_bug21726");
+ myheader("test_bug21726");
+
+ fill_tables(create_table, sizeof(create_table) / sizeof(*create_table));
+
+ rc= mysql_query(mysql, update_query);
+ myquery(rc);
+ insert_id= mysql_insert_id(mysql);
+ DIE_UNLESS(insert_id == 2);
+
+ rc= mysql_query(mysql, update_query);
+ myquery(rc);
+ insert_id= mysql_insert_id(mysql);
+ DIE_UNLESS(insert_id == 3);
+
+ DBUG_VOID_RETURN;
+}
+
/*
Read and parse arguments and MySQL options from my.cnf
@@ -15511,7 +15548,8 @@ static struct my_tests_st my_tests[]= {
{ "test_bug17667", test_bug17667 },
{ "test_bug19671", test_bug19671 },
{ "test_bug15752", test_bug15752 },
- { "test_bug21206", test_bug21206},
+ { "test_bug21206", test_bug21206 },
+ { "test_bug21726", test_bug21726 },
{ 0, 0 }
};
diff --git a/zlib/Makefile.am b/zlib/Makefile.am
index 0081c93a2ae..af7d60d8568 100644
--- a/zlib/Makefile.am
+++ b/zlib/Makefile.am
@@ -18,6 +18,8 @@
INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include
+LIBS= $(NON_THREADED_LIBS)
+
pkglib_LTLIBRARIES=libz.la
libz_la_LDFLAGS= -version-info 3:3:2