From e1418b14ecc1d6c2c2ec28246be0a4a30751ba6f Mon Sep 17 00:00:00 2001 From: Ingo Struewing Date: Mon, 26 Apr 2010 15:44:10 +0200 Subject: [PATCH 01/44] Bug#46339 - crash on REPAIR TABLE merge table USE_FRM REPAIR TABLE ... USE_FRM crashed debug servers. A wrong assert assumed that this operation would not be executed for MERGE tables. Removed the assert. mysql-test/r/merge.result: Bug#46339 - crash on REPAIR TABLE merge table USE_FRM Added test result. mysql-test/t/merge.test: Bug#46339 - crash on REPAIR TABLE merge table USE_FRM Added test. sql/sql_table.cc: Bug#46339 - crash on REPAIR TABLE merge table USE_FRM Removed false assert. --- mysql-test/r/merge.result | 41 ++++++++++++++++++++ mysql-test/t/merge.test | 78 +++++++++++++++++++++++++++++++++++++++ sql/sql_table.cc | 3 -- 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index dbffbba1b8b..1fb074d38bf 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -2298,4 +2298,45 @@ t2 WHERE b SOUNDS LIKE e AND d = 1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables DROP TABLE t2, t1; +# +# Bug#46339 - crash on REPAIR TABLE merge table USE_FRM +# +DROP TABLE IF EXISTS m1, t1; +CREATE TABLE t1 (c1 INT) ENGINE=MYISAM; +CREATE TABLE m1 (c1 INT) ENGINE=MRG_MyISAM UNION=(t1) INSERT_METHOD=LAST; +LOCK TABLE m1 READ; +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +test.m1 repair note The storage engine for the table doesn't support repair +UNLOCK TABLES; +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +test.m1 repair note The storage engine for the table doesn't support repair +DROP TABLE m1,t1; +CREATE TABLE m1 (f1 BIGINT) ENGINE=MRG_MyISAM UNION(t1); +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +test.m1 repair Error Can't open table +test.m1 repair error Corrupt +CREATE TABLE t1 (f1 BIGINT) ENGINE = MyISAM; +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +test.m1 repair note The storage engine for the table doesn't support repair +REPAIR TABLE m1; +Table Op Msg_type Msg_text +test.m1 repair note The storage engine for the table doesn't support repair +DROP TABLE m1, t1; +CREATE TEMPORARY TABLE m1 (f1 BIGINT) ENGINE=MRG_MyISAM UNION(t1); +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +test.m1 repair Error Table 'test.m1' doesn't exist +test.m1 repair error Corrupt +CREATE TEMPORARY TABLE t1 (f1 BIGINT) ENGINE=MyISAM; +REPAIR TABLE m1 USE_FRM; +Table Op Msg_type Msg_text +m1 repair error Cannot repair temporary table from .frm file +REPAIR TABLE m1; +Table Op Msg_type Msg_text +test.m1 repair note The storage engine for the table doesn't support repair +DROP TABLE m1, t1; End of 5.1 tests diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 44b202fab97..f290803bbd2 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -1705,4 +1705,82 @@ t2 WHERE b SOUNDS LIKE e AND d = 1; DROP TABLE t2, t1; +--echo # +--echo # Bug#46339 - crash on REPAIR TABLE merge table USE_FRM +--echo # +--disable_warnings +DROP TABLE IF EXISTS m1, t1; +--enable_warnings +# +# Test derived from a proposal of Shane Bester. +# +CREATE TABLE t1 (c1 INT) ENGINE=MYISAM; +CREATE TABLE m1 (c1 INT) ENGINE=MRG_MyISAM UNION=(t1) INSERT_METHOD=LAST; +# +# REPAIR ... USE_FRM with LOCK TABLES. +# +LOCK TABLE m1 READ; +REPAIR TABLE m1 USE_FRM; +UNLOCK TABLES; +# +# REPAIR ... USE_FRM without LOCK TABLES. +# +# This statement crashed the server (Bug#46339). +# +REPAIR TABLE m1 USE_FRM; +# +DROP TABLE m1,t1; +# +# Test derived from a proposal of Matthias Leich. +# +# Base table is missing. +# +CREATE TABLE m1 (f1 BIGINT) ENGINE=MRG_MyISAM UNION(t1); +# +# This statement crashed the server (Bug#46339). +# +REPAIR TABLE m1 USE_FRM; +# +# Create base table. +# +CREATE TABLE t1 (f1 BIGINT) ENGINE = MyISAM; +# +# This statement crashed the server (Bug#46339). +# +REPAIR TABLE m1 USE_FRM; +# +# Normal repair as reference. +# +REPAIR TABLE m1; +# +# Cleanup. +# +DROP TABLE m1, t1; +# +# Same with temporary tables. +# +# Base table is missing. +# +CREATE TEMPORARY TABLE m1 (f1 BIGINT) ENGINE=MRG_MyISAM UNION(t1); +# +# This statement crashed the server (Bug#46339). +# +REPAIR TABLE m1 USE_FRM; +# +# Create base table. +# +CREATE TEMPORARY TABLE t1 (f1 BIGINT) ENGINE=MyISAM; +# +# This statement crashed the server (Bug#46339). +# +REPAIR TABLE m1 USE_FRM; +# +# Normal repair as reference. +# +REPAIR TABLE m1; +# +# Cleanup. +# +DROP TABLE m1, t1; + --echo End of 5.1 tests diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ad72cab664e..78128fae576 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4384,9 +4384,6 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, pthread_mutex_unlock(&LOCK_open); } - /* A MERGE table must not come here. */ - DBUG_ASSERT(!table->child_l); - /* REPAIR TABLE ... USE_FRM for temporary tables makes little sense. */ From 190ec75c3540b5e9578472f637ff03b904b24042 Mon Sep 17 00:00:00 2001 From: Jimmy Yang Date: Sun, 1 Aug 2010 22:25:57 -0700 Subject: [PATCH 02/44] Fix Bug #55382 Assignment with SELECT expressions takes unexpected S locks in READ COMMITTED rb://410 Approved by Sunny Bains --- storage/innobase/handler/ha_innodb.cc | 9 +++++---- storage/innodb_plugin/ChangeLog | 7 +++++++ storage/innodb_plugin/handler/ha_innodb.cc | 9 +++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index d10fcb8d31e..f29dd3be990 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -7814,16 +7814,17 @@ ha_innobase::store_lock( && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT) && (sql_command == SQLCOM_INSERT_SELECT || sql_command == SQLCOM_UPDATE - || sql_command == SQLCOM_CREATE_TABLE)) { + || sql_command == SQLCOM_CREATE_TABLE + || sql_command == SQLCOM_SET_OPTION)) { /* If we either have innobase_locks_unsafe_for_binlog option set or this session is using READ COMMITTED isolation level and isolation level of the transaction is not set to serializable and MySQL is doing INSERT INTO...SELECT or UPDATE ... = (SELECT ...) or - CREATE ... SELECT... without FOR UPDATE or - IN SHARE MODE in select, then we use consistent - read for select. */ + CREATE ... SELECT... or SET ... = (SELECT ...) + without FOR UPDATE or IN SHARE MODE in select, + then we use consistent read for select. */ prebuilt->select_lock_type = LOCK_NONE; prebuilt->stored_select_lock_type = LOCK_NONE; diff --git a/storage/innodb_plugin/ChangeLog b/storage/innodb_plugin/ChangeLog index 3e802360d23..1f8491baa51 100644 --- a/storage/innodb_plugin/ChangeLog +++ b/storage/innodb_plugin/ChangeLog @@ -1,3 +1,10 @@ +2010-08-01 The InnoDB Team + + * handler/ha_innodb.cc + Fix Bug #55382 Assignment with SELECT expressions takes unexpected + S locks in READ COMMITTED + + 2010-07-27 The InnoDB Team * include/mem0pool.h, mem/mem0mem.c, mem/mem0pool.c, srv/srv0start.c: diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index e0a62ed3ac5..a70921806b4 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -9235,7 +9235,8 @@ ha_innobase::store_lock( && (sql_command == SQLCOM_INSERT_SELECT || sql_command == SQLCOM_REPLACE_SELECT || sql_command == SQLCOM_UPDATE - || sql_command == SQLCOM_CREATE_TABLE)) { + || sql_command == SQLCOM_CREATE_TABLE + || sql_command == SQLCOM_SET_OPTION)) { /* If we either have innobase_locks_unsafe_for_binlog option set or this session is using READ COMMITTED @@ -9243,9 +9244,9 @@ ha_innobase::store_lock( is not set to serializable and MySQL is doing INSERT INTO...SELECT or REPLACE INTO...SELECT or UPDATE ... = (SELECT ...) or CREATE ... - SELECT... without FOR UPDATE or IN SHARE - MODE in select, then we use consistent read - for select. */ + SELECT... or SET ... = (SELECT ...) without + FOR UPDATE or IN SHARE MODE in select, + then we use consistent read for select. */ prebuilt->select_lock_type = LOCK_NONE; prebuilt->stored_select_lock_type = LOCK_NONE; From 666dfaf090c801db93ff6d583c22203291bc2030 Mon Sep 17 00:00:00 2001 From: Jimmy Yang Date: Tue, 3 Aug 2010 20:20:55 -0700 Subject: [PATCH 03/44] Backport "NULL pointer check for ut_free()" from mysql-trunk-innodb to mysql-5.1-innodb plugin to fix bug #55627 segv in ut_free pars_lexer_close innobase_shutdown innodb-use-sys-malloc=0. --- storage/innodb_plugin/ChangeLog | 7 ++++++- storage/innodb_plugin/include/ut0mem.h | 3 ++- storage/innodb_plugin/ut/ut0mem.c | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/storage/innodb_plugin/ChangeLog b/storage/innodb_plugin/ChangeLog index 1f8491baa51..9fe5c1e7ee6 100644 --- a/storage/innodb_plugin/ChangeLog +++ b/storage/innodb_plugin/ChangeLog @@ -1,10 +1,15 @@ +2010-08-03 The InnoDB Team + + * include/ut0mem.h, ut/ut0mem.c: + Fix Bug #55627 segv in ut_free pars_lexer_close innobase_shutdown + innodb-use-sys-malloc=0 + 2010-08-01 The InnoDB Team * handler/ha_innodb.cc Fix Bug #55382 Assignment with SELECT expressions takes unexpected S locks in READ COMMITTED - 2010-07-27 The InnoDB Team * include/mem0pool.h, mem/mem0mem.c, mem/mem0pool.c, srv/srv0start.c: diff --git a/storage/innodb_plugin/include/ut0mem.h b/storage/innodb_plugin/include/ut0mem.h index cf41cba4643..f14606be966 100644 --- a/storage/innodb_plugin/include/ut0mem.h +++ b/storage/innodb_plugin/include/ut0mem.h @@ -113,7 +113,8 @@ ut_test_malloc( ulint n); /*!< in: try to allocate this many bytes */ #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** -Frees a memory block allocated with ut_malloc. */ +Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is +a nop. */ UNIV_INTERN void ut_free( diff --git a/storage/innodb_plugin/ut/ut0mem.c b/storage/innodb_plugin/ut/ut0mem.c index 35a325b9ccd..bf55e4273b6 100644 --- a/storage/innodb_plugin/ut/ut0mem.c +++ b/storage/innodb_plugin/ut/ut0mem.c @@ -290,7 +290,8 @@ ut_test_malloc( #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** -Frees a memory block allocated with ut_malloc. */ +Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is +a nop. */ UNIV_INTERN void ut_free( @@ -300,7 +301,9 @@ ut_free( #ifndef UNIV_HOTBACKUP ut_mem_block_t* block; - if (UNIV_LIKELY(srv_use_sys_malloc)) { + if (ptr == NULL) { + return; + } else if (UNIV_LIKELY(srv_use_sys_malloc)) { free(ptr); return; } From 0812058d023a5261d40b31e8427669b5b5e8db20 Mon Sep 17 00:00:00 2001 From: Inaam Rana Date: Thu, 5 Aug 2010 11:34:44 -0400 Subject: [PATCH 04/44] Backport of revno 3148 mysql-innodb-trunk Currently we do a full validation of AHI whenever check tables is called on any table. This patch fixes this by only doing this full check in debug versions. bug#55716 rb://423 approved by: Marko --- storage/innodb_plugin/btr/btr0sea.c | 2 ++ storage/innodb_plugin/ha/ha0ha.c | 2 ++ storage/innodb_plugin/include/btr0sea.h | 4 ++++ storage/innodb_plugin/include/ha0ha.h | 2 ++ 4 files changed, 10 insertions(+) diff --git a/storage/innodb_plugin/btr/btr0sea.c b/storage/innodb_plugin/btr/btr0sea.c index ac7248fef20..f3ffe07a951 100644 --- a/storage/innodb_plugin/btr/btr0sea.c +++ b/storage/innodb_plugin/btr/btr0sea.c @@ -1734,6 +1734,7 @@ function_exit: } } +#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /********************************************************************//** Validates the search system. @return TRUE if ok */ @@ -1897,3 +1898,4 @@ btr_search_validate(void) return(ok); } +#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */ diff --git a/storage/innodb_plugin/ha/ha0ha.c b/storage/innodb_plugin/ha/ha0ha.c index f9e798012f8..7f11917de0a 100644 --- a/storage/innodb_plugin/ha/ha0ha.c +++ b/storage/innodb_plugin/ha/ha0ha.c @@ -354,6 +354,7 @@ ha_remove_all_nodes_to_page( #endif } +#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /*************************************************************//** Validates a given range of the cells in hash table. @return TRUE if ok */ @@ -400,6 +401,7 @@ ha_validate( return(ok); } +#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */ /*************************************************************//** Prints info of a hash table. */ diff --git a/storage/innodb_plugin/include/btr0sea.h b/storage/innodb_plugin/include/btr0sea.h index 20a2be7f877..6493689a969 100644 --- a/storage/innodb_plugin/include/btr0sea.h +++ b/storage/innodb_plugin/include/btr0sea.h @@ -180,6 +180,7 @@ btr_search_update_hash_on_delete( btr_cur_t* cursor);/*!< in: cursor which was positioned on the record to delete using btr_cur_search_..., the record is not yet deleted */ +#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /********************************************************************//** Validates the search system. @return TRUE if ok */ @@ -187,6 +188,9 @@ UNIV_INTERN ibool btr_search_validate(void); /*======================*/ +#else +# define btr_search_validate() TRUE +#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */ /** Flag: has the search system been enabled? Protected by btr_search_latch and btr_search_enabled_mutex. */ diff --git a/storage/innodb_plugin/include/ha0ha.h b/storage/innodb_plugin/include/ha0ha.h index 1ffbd3440aa..3299000bf3c 100644 --- a/storage/innodb_plugin/include/ha0ha.h +++ b/storage/innodb_plugin/include/ha0ha.h @@ -186,6 +186,7 @@ ha_remove_all_nodes_to_page( hash_table_t* table, /*!< in: hash table */ ulint fold, /*!< in: fold value */ const page_t* page); /*!< in: buffer page */ +#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /*************************************************************//** Validates a given range of the cells in hash table. @return TRUE if ok */ @@ -196,6 +197,7 @@ ha_validate( hash_table_t* table, /*!< in: hash table */ ulint start_index, /*!< in: start index */ ulint end_index); /*!< in: end index */ +#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */ /*************************************************************//** Prints info of a hash table. */ UNIV_INTERN From 531c0eee52bf96ffc3f10ed408ce1fb143b9fd0a Mon Sep 17 00:00:00 2001 From: Jimmy Yang Date: Fri, 6 Aug 2010 02:49:22 -0700 Subject: [PATCH 05/44] Address bug #55465 ERROR 1280 (42000): Incorrect index name '', adding a couple FK related messages. rb://409 approved by Sunny Bains --- storage/innobase/dict/dict0dict.c | 4 ++-- storage/innobase/handler/ha_innodb.cc | 26 ++++++++++++++++++++++++-- storage/innobase/include/db0err.h | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index d2b59469cdc..9f9c4da46f4 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -2140,7 +2140,7 @@ dict_foreign_add_to_cache( mem_heap_free(foreign->heap); } - return(DB_CANNOT_ADD_CONSTRAINT); + return(DB_FOREIGN_NO_INDEX); } for_in_cache->referenced_table = ref_table; @@ -2184,7 +2184,7 @@ dict_foreign_add_to_cache( mem_heap_free(foreign->heap); } - return(DB_CANNOT_ADD_CONSTRAINT); + return(DB_REFERENCING_NO_INDEX); } for_in_cache->foreign_table = for_table; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index f29dd3be990..991b3a394d7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -707,7 +707,9 @@ convert_error_code_to_mysql( return(HA_ERR_ROW_IS_REFERENCED); - } else if (error == (int) DB_CANNOT_ADD_CONSTRAINT) { + } else if (error == (int) DB_CANNOT_ADD_CONSTRAINT + || error == (int) DB_FOREIGN_NO_INDEX + || error == (int) DB_REFERENCING_NO_INDEX) { return(HA_ERR_CANNOT_ADD_FOREIGN); @@ -6099,6 +6101,8 @@ ha_innobase::rename_table( innobase_commit_low(trx); trx_free_for_mysql(trx); + switch (error) { + case DB_DUPLICATE_KEY: /* Add a special case to handle the Duplicated Key error and return DB_ERROR instead. This is to avoid a possible SIGSEGV error from mysql error @@ -6111,10 +6115,28 @@ ha_innobase::rename_table( the dup key error here is due to an existing table whose name is the one we are trying to rename to) and return the generic error code. */ - if (error == (int) DB_DUPLICATE_KEY) { my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to); error = DB_ERROR; + break; + case DB_FOREIGN_NO_INDEX: + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + HA_ERR_CANNOT_ADD_FOREIGN, + "Alter or rename of table '%s' failed" + " because the new table is a child table" + " in a FK relationship and it does not" + " have an index that contains foreign" + " keys as its prefix columns.", norm_to); + break; + case DB_REFERENCING_NO_INDEX: + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + HA_ERR_CANNOT_ADD_FOREIGN, + "Alter or rename of table '%s' failed" + " because the new table is a parent table" + " in a FK relationship and it does not" + " have an index that contains foreign" + " keys as its prefix columns.", norm_to); + break; } error = convert_error_code_to_mysql(error, NULL); diff --git a/storage/innobase/include/db0err.h b/storage/innobase/include/db0err.h index 2be6005622d..cc6b0745b97 100644 --- a/storage/innobase/include/db0err.h +++ b/storage/innobase/include/db0err.h @@ -73,6 +73,12 @@ Created 5/24/1996 Heikki Tuuri a later version of the engine. */ #define DB_INTERRUPTED 49 /* the query has been interrupted with "KILL QUERY N;" */ +#define DB_FOREIGN_NO_INDEX 50 /* the child (foreign) table does not + have an index that contains the + foreign keys as its prefix columns */ +#define DB_REFERENCING_NO_INDEX 51 /* the parent (referencing) table does + not have an index that contains the + foreign keys as its prefix columns */ /* The following are partial failure codes */ #define DB_FAIL 1000 From b409fad8cc0812cc1da44bb6b893e95be46049ca Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 10 Aug 2010 10:43:12 +0200 Subject: [PATCH 06/44] Bug#55458: Partitioned MyISAM table gets crashed by multi-table update Problem was that the handler call ::extra(HA_EXTRA_CACHE) was cached but the ::extra(HA_EXTRA_PREPARE_FOR_UPDATE) was not. Solution was to also cache the other call and forward it when moving to a new partition to scan. mysql-test/r/partition.result: test result mysql-test/t/partition.test: New test from bug report. sql/ha_partition.cc: cache the HA_EXTRA_PREPARE_FOR_UPDATE just like HA_EXTRA_CACHE. sql/ha_partition.h: Added cache flag for HA_EXTRA_PREPARE_FOR_UPDATE --- mysql-test/r/partition.result | 25 +++++++++++++++++++++++++ mysql-test/t/partition.test | 27 +++++++++++++++++++++++++++ sql/ha_partition.cc | 27 ++++++++++++++++++++++++--- sql/ha_partition.h | 2 ++ 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 23a485dc5ed..bb1635b8621 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1,4 +1,29 @@ drop table if exists t1, t2; +# +# Bug#55458: Partitioned MyISAM table gets crashed by multi-table update +# +CREATE TABLE t1 ( +`id` int NOT NULL, +`user_num` int DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1,8601); +INSERT INTO t1 VALUES (2,8601); +INSERT INTO t1 VALUES (3,8601); +INSERT INTO t1 VALUES (4,8601); +CREATE TABLE t2 ( +`id` int(11) NOT NULL, +`user_num` int DEFAULT NULL, +`name` varchar(64) NOT NULL, +PRIMARY KEY (`id`) +) ENGINE=MyISAM CHARSET=latin1 +PARTITION BY HASH (id) +PARTITIONS 2; +INSERT INTO t2 VALUES (1,8601,'John'); +INSERT INTO t2 VALUES (2,8601,'JS'); +INSERT INTO t2 VALUES (3,8601,'John S'); +UPDATE t1, t2 SET t2.name = 'John Smith' WHERE t1.user_num = t2.user_num; +DROP TABLE t1, t2; CREATE TABLE t1 (a INT, b INT) PARTITION BY LIST (a) SUBPARTITION BY HASH (b) diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 22124cc1847..95d702ee6b8 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -14,6 +14,33 @@ drop table if exists t1, t2; --enable_warnings +--echo # +--echo # Bug#55458: Partitioned MyISAM table gets crashed by multi-table update +--echo # +CREATE TABLE t1 ( + `id` int NOT NULL, + `user_num` int DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1,8601); +INSERT INTO t1 VALUES (2,8601); +INSERT INTO t1 VALUES (3,8601); +INSERT INTO t1 VALUES (4,8601); +CREATE TABLE t2 ( + `id` int(11) NOT NULL, + `user_num` int DEFAULT NULL, + `name` varchar(64) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM CHARSET=latin1 +PARTITION BY HASH (id) +PARTITIONS 2; +INSERT INTO t2 VALUES (1,8601,'John'); +INSERT INTO t2 VALUES (2,8601,'JS'); +INSERT INTO t2 VALUES (3,8601,'John S'); + +UPDATE t1, t2 SET t2.name = 'John Smith' WHERE t1.user_num = t2.user_num; + +DROP TABLE t1, t2; # # Bug#48276: can't add column if subpartition exists CREATE TABLE t1 (a INT, b INT) diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index a87c7fbf7b8..3d3ae33be4b 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -232,6 +232,7 @@ void ha_partition::init_handler_variables() m_innodb= FALSE; m_extra_cache= FALSE; m_extra_cache_size= 0; + m_extra_prepare_for_update= FALSE; m_handler_status= handler_not_initialized; m_low_byte_first= 1; m_part_field_array= NULL; @@ -5549,9 +5550,20 @@ int ha_partition::extra(enum ha_extra_function operation) case HA_EXTRA_PREPARE_FOR_RENAME: DBUG_RETURN(prepare_for_rename()); break; + case HA_EXTRA_PREPARE_FOR_UPDATE: + DBUG_ASSERT(m_extra_cache); + /* + Needs to be run on the first partition in the range now, and + later in late_extra_cache, when switching to a new partition to scan. + */ + m_extra_prepare_for_update= TRUE; + if (m_part_spec.start_part != NO_CURRENT_PART_ID) + { + VOID(m_file[m_part_spec.start_part]->extra(HA_EXTRA_PREPARE_FOR_UPDATE)); + } + break; case HA_EXTRA_NORMAL: case HA_EXTRA_QUICK: - case HA_EXTRA_PREPARE_FOR_UPDATE: case HA_EXTRA_FORCE_REOPEN: case HA_EXTRA_PREPARE_FOR_DROP: case HA_EXTRA_FLUSH_CACHE: @@ -5578,6 +5590,7 @@ int ha_partition::extra(enum ha_extra_function operation) { m_extra_cache= FALSE; m_extra_cache_size= 0; + m_extra_prepare_for_update= FALSE; DBUG_RETURN(loop_extra(operation)); } case HA_EXTRA_IGNORE_NO_KEY: @@ -5705,6 +5718,7 @@ int ha_partition::extra_opt(enum ha_extra_function operation, ulong cachesize) void ha_partition::prepare_extra_cache(uint cachesize) { DBUG_ENTER("ha_partition::prepare_extra_cache()"); + DBUG_PRINT("info", ("cachesize %u", cachesize)); m_extra_cache= TRUE; m_extra_cache_size= cachesize; @@ -5793,14 +5807,21 @@ void ha_partition::late_extra_cache(uint partition_id) { handler *file; DBUG_ENTER("ha_partition::late_extra_cache"); + DBUG_PRINT("info", ("extra_cache %u partid %u size %u", m_extra_cache, + partition_id, m_extra_cache_size)); - if (!m_extra_cache) + if (!m_extra_cache && !m_extra_prepare_for_update) DBUG_VOID_RETURN; file= m_file[partition_id]; if (m_extra_cache_size == 0) VOID(file->extra(HA_EXTRA_CACHE)); else VOID(file->extra_opt(HA_EXTRA_CACHE, m_extra_cache_size)); + if (m_extra_prepare_for_update) + { + DBUG_ASSERT(m_extra_cache); + VOID(file->extra(HA_EXTRA_PREPARE_FOR_UPDATE)); + } DBUG_VOID_RETURN; } @@ -5821,7 +5842,7 @@ void ha_partition::late_extra_no_cache(uint partition_id) handler *file; DBUG_ENTER("ha_partition::late_extra_no_cache"); - if (!m_extra_cache) + if (!m_extra_cache && !m_extra_prepare_for_update) DBUG_VOID_RETURN; file= m_file[partition_id]; VOID(file->extra(HA_EXTRA_NO_CACHE)); diff --git a/sql/ha_partition.h b/sql/ha_partition.h index e3dc7d17c6d..013341e4df3 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -154,6 +154,8 @@ private: */ bool m_extra_cache; uint m_extra_cache_size; + /* The same goes for HA_EXTRA_PREPARE_FOR_UPDATE */ + bool m_extra_prepare_for_update; void init_handler_variables(); /* From 788b4e404bbd97ff6b215ae55633e0971f8d19d6 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 10 Aug 2010 12:13:58 +0200 Subject: [PATCH 07/44] Bug #55413 mysqltest gives parse error for lines matching "^let.*\\.*;$" Allow escaped quotes also in statements not starting with -- But will not support single unescaped ' or ` --- client/mysqltest.cc | 10 ++++++++-- mysql-test/r/mysqltest.result | 3 +++ mysql-test/t/mysqltest.test | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index d7a302912b4..d8c921e8f18 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5507,6 +5507,8 @@ int read_line(char *buf, int size) char c, UNINIT_VAR(last_quote); char *p= buf, *buf_end= buf + size - 1; int skip_char= 0; + my_bool have_slash= FALSE; + enum {R_NORMAL, R_Q, R_SLASH_IN_Q, R_COMMENT, R_LINE_START} state= R_LINE_START; DBUG_ENTER("read_line"); @@ -5578,9 +5580,13 @@ int read_line(char *buf, int size) } else if (c == '\'' || c == '"' || c == '`') { - last_quote= c; - state= R_Q; + if (! have_slash) + { + last_quote= c; + state= R_Q; + } } + have_slash= (c == '\\'); break; case R_COMMENT: diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index e4f68d68c3f..1044127b06e 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -262,6 +262,9 @@ a long \$where variable content banana = banana Not a banana: ba\$cat\$cat +with\`some"escaped\'quotes +with\`some"escaped\'quotes +single'tick`backtick mysqltest: At line 1: Missing arguments to let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Missing assignment operator in let diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 031c51a0720..9da19ec00e0 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -701,6 +701,16 @@ echo banana = $cat; let $cat=ba\\\$cat\\\$cat; echo Not a banana: $cat; +# Bug #55413 would cause this to fail +let $escape= with\`some\"escaped\'quotes; +echo $escape; + +--let $escape= with\`some\"escaped\'quotes +echo $escape; + +# This only works with "--let" syntax +--let $tick= single'tick`backtick +echo $tick; # Test illegal uses of let From 61f842444cc4ef8caa7342ae5e93706819c851c7 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Tue, 17 Aug 2010 22:37:18 +0300 Subject: [PATCH 08/44] Disable all innodb_plugin tests on Solaris until the problem is resolved. Track this via: Bug#56063 InnoDB Plugin mysql-tests fail on Solaris --- mysql-test/collections/default.experimental | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/collections/default.experimental b/mysql-test/collections/default.experimental index f84337660ea..6d29134316d 100644 --- a/mysql-test/collections/default.experimental +++ b/mysql-test/collections/default.experimental @@ -12,6 +12,8 @@ funcs_1.ndb* # joro : NDB tests marked as experiment funcs_2.ndb_charset # joro : NDB tests marked as experimental as agreed with bochklin +innodb_plugin.* @solaris # Bug#56063 InnoDB Plugin mysql-tests fail on Solaris + main.ctype_gbk_binlog @solaris # Bug#46010: main.ctype_gbk_binlog fails sporadically : Table 't2' already exists main.func_str @solaris # joro: Bug#40928 main.plugin_load @solaris # Bug#42144 From 5a296bb07c2d335f7826e3aad91e6070817996c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 18 Aug 2010 14:01:10 +0300 Subject: [PATCH 09/44] Bug#55626: MIN and MAX reading a delete-marked record from secondary index Remove a bogus debug assertion that triggered the bug. Add assertions precisely where records must not be delete-marked. And a comment to clarify when the record is allowed to be delete-marked. --- storage/innodb_plugin/row/row0sel.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/storage/innodb_plugin/row/row0sel.c b/storage/innodb_plugin/row/row0sel.c index 76c144e5a8c..aff36b65124 100644 --- a/storage/innodb_plugin/row/row0sel.c +++ b/storage/innodb_plugin/row/row0sel.c @@ -2690,7 +2690,6 @@ row_sel_store_mysql_rec( ut_ad(prebuilt->mysql_template); ut_ad(prebuilt->default_rec); ut_ad(rec_offs_validate(rec, NULL, offsets)); - ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets))); if (UNIV_LIKELY_NULL(prebuilt->blob_heap)) { mem_heap_free(prebuilt->blob_heap); @@ -3611,6 +3610,7 @@ row_search_for_mysql( row_sel_try_search_shortcut_for_mysql(). The latch will not be released until mtr_commit(&mtr). */ + ut_ad(!rec_get_deleted_flag(rec, comp)); if (!row_sel_store_mysql_rec(buf, prebuilt, rec, offsets)) { @@ -4238,7 +4238,7 @@ no_gap_lock: rec = old_vers; } - } else if (!lock_sec_rec_cons_read_sees(rec, trx->read_view)) { + } else { /* We are looking into a non-clustered index, and to get the right version of the record we have to look also into the clustered index: this @@ -4246,8 +4246,12 @@ no_gap_lock: information via the clustered index record. */ ut_ad(index != clust_index); + ut_ad(!dict_index_is_clust(index)); - goto requires_clust_rec; + if (!lock_sec_rec_cons_read_sees( + rec, trx->read_view)) { + goto requires_clust_rec; + } } } @@ -4370,8 +4374,13 @@ requires_clust_rec: ULINT_UNDEFINED, &heap); result_rec = rec; } + + /* result_rec can legitimately be delete-marked + now that it has been established that it points to a + clustered index record that exists in the read view. */ } else { result_rec = rec; + ut_ad(!rec_get_deleted_flag(rec, comp)); } /* We found a qualifying record 'result_rec'. At this point, From b6c5f4537be428578e55b7c73fa6b624046c3089 Mon Sep 17 00:00:00 2001 From: Sunny Bains Date: Fri, 20 Aug 2010 12:55:52 +1000 Subject: [PATCH 10/44] Fix bug#55699 - Assertion failure in innodb plugin with large number of threads Fix a debug assertion that was missed in svnrev:2380 (fix for Bug# 35352). Approved by Marko on IRC --- storage/innodb_plugin/trx/trx0undo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/innodb_plugin/trx/trx0undo.c b/storage/innodb_plugin/trx/trx0undo.c index 3bb1b1cdf6c..eb5112c4d31 100644 --- a/storage/innodb_plugin/trx/trx0undo.c +++ b/storage/innodb_plugin/trx/trx0undo.c @@ -1938,7 +1938,8 @@ trx_undo_update_cleanup( UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo); } else { - ut_ad(undo->state == TRX_UNDO_TO_PURGE); + ut_ad(undo->state == TRX_UNDO_TO_PURGE + || undo->state == TRX_UNDO_TO_FREE); trx_undo_mem_free(undo); } From 3daf6d3d73168971dfba30f7a248a6a48fca5691 Mon Sep 17 00:00:00 2001 From: Sunny Bains Date: Fri, 20 Aug 2010 12:57:04 +1000 Subject: [PATCH 11/44] Fix Bug #55027: assertion: mutex_own(&dict_sys->mutex) in dict_table_get_on_id() The callers should indicate that the dictionary is locked or not using the trx->dict_operation_lock_mode == RW_X_LATCH mode. Checking explicitly for system tables is unnecessary. Approved by Marko on IRC. --- storage/innobase/dict/dict0dict.c | 3 +-- storage/innodb_plugin/dict/dict0dict.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index 9f9c4da46f4..0e323d2bf24 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -616,8 +616,7 @@ dict_table_get_on_id( { dict_table_t* table; - if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0 - || trx->dict_operation_lock_mode == RW_X_LATCH) { + if (trx->dict_operation_lock_mode == RW_X_LATCH) { /* Note: An X latch implies that the transaction already owns the dictionary mutex. */ diff --git a/storage/innodb_plugin/dict/dict0dict.c b/storage/innodb_plugin/dict/dict0dict.c index fe4e058e122..a79f084e327 100644 --- a/storage/innodb_plugin/dict/dict0dict.c +++ b/storage/innodb_plugin/dict/dict0dict.c @@ -568,8 +568,7 @@ dict_table_get_on_id( { dict_table_t* table; - if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0 - || trx->dict_operation_lock_mode == RW_X_LATCH) { + if (trx->dict_operation_lock_mode == RW_X_LATCH) { /* Note: An X latch implies that the transaction already owns the dictionary mutex. */ From 81da9b3d72a6d971f686613129679661524e2dd4 Mon Sep 17 00:00:00 2001 From: Sunny Bains Date: Fri, 20 Aug 2010 17:49:43 +1000 Subject: [PATCH 12/44] Fix Bug #54538 - use of exclusive innodb dictionary lock limits performance. This patch doesn't get rid of the need to acquire the dict_sys->mutex but reduces the need to keep the mutex locked for the duration of the query to fsp_get_available_space_in_free_extents() from ha_innobase::info(). rb://390. --- storage/innobase/fil/fil0fil.c | 104 +++++++++++++++++++++----- storage/innobase/fsp/fsp0fsp.c | 49 ++++++++++++ storage/innobase/handler/ha_innodb.cc | 20 ++--- storage/innobase/include/fil0fil.h | 14 +++- storage/innobase/include/univ.i | 6 ++ 5 files changed, 160 insertions(+), 33 deletions(-) diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index 3810fefd3cb..6ca8381ebdf 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -966,6 +966,8 @@ try_again: HASH_SEARCH(name_hash, system->name_hash, ut_fold_string(name), space, 0 == strcmp(name, space->name)); if (space != NULL) { + ibool success; + ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Warning: trying to init to the" @@ -1002,9 +1004,10 @@ try_again: namesake_id = space->id; - mutex_exit(&(system->mutex)); + success = fil_space_free(namesake_id, FALSE); + ut_a(success); - fil_space_free(namesake_id); + mutex_exit(&(system->mutex)); goto try_again; } @@ -1127,6 +1130,33 @@ fil_assign_new_space_id(void) return(id); } +/*********************************************************************** +Check if the space id exists in the cache, complain to stderr if the +space id cannot be found. */ +static +fil_space_t* +fil_space_search( +/*=============*/ + /* out: file space instance*/ + ulint id) /* in: space id */ +{ + fil_space_t* space; + + ut_ad(mutex_own(&fil_system->mutex)); + + HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id); + + if (space == NULL) { + ut_print_timestamp(stderr); + fprintf(stderr, + " InnoDB: Error: trying to remove tablespace %lu" + " from the cache but\n" + "InnoDB: it is not there.\n", (ulong) id); + } + + return(space); +} + /*********************************************************************** Frees a space object from the tablespace memory cache. Closes the files in the chain but does not delete them. There must not be any pending i/o's or @@ -1135,27 +1165,21 @@ flushes on the files. */ ibool fil_space_free( /*===========*/ - /* out: TRUE if success */ - ulint id) /* in: space id */ + /* out: TRUE if success */ + ulint id, /* in: space id */ + ibool x_latched) /* in: TRUE if caller has space->latch + in X mode */ { fil_system_t* system = fil_system; fil_space_t* space; fil_space_t* namespace; fil_node_t* fil_node; - mutex_enter(&(system->mutex)); + ut_ad(mutex_own(&fil_system->mutex)); - HASH_SEARCH(hash, system->spaces, id, space, space->id == id); - - if (!space) { - ut_print_timestamp(stderr); - fprintf(stderr, - " InnoDB: Error: trying to remove tablespace %lu" - " from the cache but\n" - "InnoDB: it is not there.\n", (ulong) id); - - mutex_exit(&(system->mutex)); + space = fil_space_search(id); + if (space == NULL) { return(FALSE); } @@ -1191,7 +1215,9 @@ fil_space_free( ut_a(0 == UT_LIST_GET_LEN(space->chain)); - mutex_exit(&(system->mutex)); + if (x_latched) { + rw_lock_x_unlock(&space->latch); + } rw_lock_free(&(space->latch)); @@ -2048,6 +2074,19 @@ try_again: path = mem_strdup(space->name); mutex_exit(&(system->mutex)); + + /* Important: We rely on the data dictionary mutex to ensure + that a race is not possible here. It should serialize the tablespace + drop/free. We acquire an X latch only to avoid a race condition + when accessing the tablespace instance via: + + fsp_get_available_space_in_free_extents(). + + There our main motivation is to reduce the contention on the + dictionary mutex and not correctness. */ + + rw_lock_x_lock(&space->latch); + #ifndef UNIV_HOTBACKUP /* Invalidate in the buffer pool all pages belonging to the tablespace. Since we have set space->is_being_deleted = TRUE, readahead @@ -2060,7 +2099,11 @@ try_again: #endif /* printf("Deleting tablespace %s id %lu\n", space->name, id); */ - success = fil_space_free(id); + mutex_enter(&system->mutex); + + success = fil_space_free(id, TRUE); + + mutex_exit(&system->mutex); if (success) { success = os_file_delete(path); @@ -2068,6 +2111,8 @@ try_again: if (!success) { success = os_file_delete_if_exists(path); } + } else { + rw_lock_x_unlock(&space->latch); } if (success) { @@ -4569,3 +4614,28 @@ fil_page_get_type( return(mach_read_from_2(page + FIL_PAGE_TYPE)); } + +/*********************************************************************** +Returns TRUE if a single-table tablespace is being deleted. */ + +ibool +fil_tablespace_is_being_deleted( +/*============================*/ + /* out: TRUE if space is being deleted */ + ulint id) /* in: space id */ +{ + fil_space_t* space; + ibool is_being_deleted; + + mutex_enter(&fil_system->mutex); + + HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id); + + ut_a(space != NULL); + + is_being_deleted = space->is_being_deleted; + + mutex_exit(&fil_system->mutex); + + return(is_being_deleted); +} diff --git a/storage/innobase/fsp/fsp0fsp.c b/storage/innobase/fsp/fsp0fsp.c index 1ec1c262a52..1f033c4b140 100644 --- a/storage/innobase/fsp/fsp0fsp.c +++ b/storage/innobase/fsp/fsp0fsp.c @@ -2842,12 +2842,61 @@ fsp_get_available_space_in_free_extents( ut_ad(!mutex_own(&kernel_mutex)); + /* The convoluted mutex acquire is to overcome latching order + issues: The problem is that the fil_mutex is at a lower level + than the tablespace latch and the buffer pool mutex. We have to + first prevent any operations on the file system by acquiring the + dictionary mutex. Then acquire the tablespace latch to obey the + latching order and then release the dictionary mutex. That way we + ensure that the tablespace instance can't be freed while we are + examining its contents (see fil_space_free()). + + However, there is one further complication, we release the fil_mutex + when we need to invalidate the the pages in the buffer pool and we + reacquire the fil_mutex when deleting and freeing the tablespace + instance in fil0fil.c. Here we need to account for that situation + too. */ + + dict_mutex_enter_for_mysql(); + + /* At this stage there is no guarantee that the tablespace even + exists in the cache. */ + + if (fil_tablespace_deleted_or_being_deleted_in_mem(space, -1)) { + + dict_mutex_exit_for_mysql(); + + return(ULLINT_UNDEFINED); + } + mtr_start(&mtr); latch = fil_space_get_latch(space); + /* This should ensure that the tablespace instance can't be freed + by another thread. However, the tablespace pages can still be freed + from the buffer pool. We need to check for that again. */ + mtr_x_lock(latch, &mtr); + dict_mutex_exit_for_mysql(); + + /* At this point it is possible for the tablespace to be deleted and + its pages removed from the buffer pool. We need to check for that + situation. However, the tablespace instance can't be deleted because + our latching above should ensure that. */ + + if (fil_tablespace_is_being_deleted(space)) { + + mtr_commit(&mtr); + + return(ULLINT_UNDEFINED); + } + + /* From here on even if the user has dropped the tablespace, the + pages _must_ still exist in the buffer pool and the tablespace + instance _must be in the file system hash table. */ + space_header = fsp_get_space_header(space, &mtr); size = mtr_read_ulint(space_header + FSP_SIZE, MLOG_4BYTES, &mtr); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 991b3a394d7..38394544c87 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6485,20 +6485,12 @@ ha_innobase::info( so the "old" value can remain. delete_length is initialized to 0 in the ha_statistics' constructor. */ if (!(flag & HA_STATUS_NO_LOCK)) { + ullint avail_space; - /* lock the data dictionary to avoid races with - ibd_file_missing and tablespace_discarded */ - row_mysql_lock_data_dictionary(prebuilt->trx); - - /* ib_table->space must be an existent tablespace */ - if (!ib_table->ibd_file_missing - && !ib_table->tablespace_discarded) { - - stats.delete_length = - fsp_get_available_space_in_free_extents( - ib_table->space) * 1024; - } else { + avail_space = fsp_get_available_space_in_free_extents( + ib_table->space); + if (avail_space == ULLINT_UNDEFINED) { THD* thd; thd = ha_thd(); @@ -6515,9 +6507,9 @@ ha_innobase::info( ib_table->name); stats.delete_length = 0; + } else { + stats.delete_length = avail_space * 1024; } - - row_mysql_unlock_data_dictionary(prebuilt->trx); } stats.check_time = 0; diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 251d6c22547..7e85a0b412b 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -202,8 +202,10 @@ the chain but does not delete them. */ ibool fil_space_free( /*===========*/ - /* out: TRUE if success */ - ulint id); /* in: space id */ + /* out: TRUE if success */ + ulint id, /* in: space id */ + ibool x_latched); /* in: TRUE if caller has space->latch + in X mode */ /*********************************************************************** Returns the size of the space in pages. The tablespace must be cached in the memory cache. */ @@ -710,6 +712,14 @@ fil_page_get_type( written to page, the return value not defined */ byte* page); /* in: file page */ +/*********************************************************************** +Returns TRUE if a single-table tablespace is being deleted. */ + +ibool +fil_tablespace_is_being_deleted( +/*============================*/ + /* out: TRUE if space is being deleted */ + ulint id); /* in: space id */ typedef struct fil_space_struct fil_space_t; diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index 97d022d284e..ce5d8a092bf 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -234,6 +234,12 @@ typedef unsigned long long int ullint; /* Maximum value for a ulint */ #define ULINT_MAX ((ulint)(-2)) +/* THe 'undefined' value for ullint */ +#define ULLINT_UNDEFINED ((ullint)(-1)) + +/* Maximum value for a ullint */ +#define ULLINT_MAX ((ullint)(-2)) + /* This 'ibool' type is used within Innobase. Remember that different included headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */ #define ibool ulint From 634af8f446c473b46fcdcf49957a1c595e363fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 23 Aug 2010 13:28:54 +0300 Subject: [PATCH 13/44] Bug#55832: selects crash too easily when innodb_force_recovery>3 dict_update_statistics_low(): Create bogus statistics for those indexes that cannot be accessed because of the innodb_force_recovery setting. ha_innobase::info(): Calculate statistics for each index, even if innodb_force_recovery is set. Fill in bogus data for those indexes that are not accessed because of the innodb_force_recovery setting. --- storage/innobase/dict/dict0dict.c | 57 ++++++++++++++++----------- storage/innobase/handler/ha_innodb.cc | 38 ++++++++++-------- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index 0e323d2bf24..b52a94c3348 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -3753,7 +3753,6 @@ dict_update_statistics_low( dictionary mutex */ { dict_index_t* index; - ulint size; ulint sum_of_index_sizes = 0; if (table->ibd_file_missing) { @@ -3769,14 +3768,6 @@ dict_update_statistics_low( return; } - /* If we have set a high innodb_force_recovery level, do not calculate - statistics, as a badly corrupted index can cause a crash in it. */ - - if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - - return; - } - /* Find out the sizes of the indexes and how many different values for the key they approximately have */ @@ -3788,26 +3779,48 @@ dict_update_statistics_low( return; } - while (index) { - size = btr_get_size(index, BTR_TOTAL_SIZE); - index->stat_index_size = size; + do { + if (UNIV_LIKELY + (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE + || (srv_force_recovery < SRV_FORCE_NO_LOG_REDO + && (index->type & DICT_CLUSTERED)))) { + ulint size; + size = btr_get_size(index, BTR_TOTAL_SIZE); - sum_of_index_sizes += size; + index->stat_index_size = size; - size = btr_get_size(index, BTR_N_LEAF_PAGES); + sum_of_index_sizes += size; - if (size == 0) { - /* The root node of the tree is a leaf */ - size = 1; + size = btr_get_size(index, BTR_N_LEAF_PAGES); + + if (size == 0) { + /* The root node of the tree is a leaf */ + size = 1; + } + + index->stat_n_leaf_pages = size; + + btr_estimate_number_of_different_key_vals(index); + } else { + /* If we have set a high innodb_force_recovery + level, do not calculate statistics, as a badly + corrupted index can cause a crash in it. + Initialize some bogus index cardinality + statistics, so that the data can be queried in + various means, also via secondary indexes. */ + ulint i; + + sum_of_index_sizes++; + index->stat_index_size = index->stat_n_leaf_pages = 1; + + for (i = dict_index_get_n_unique(index); i; ) { + index->stat_n_diff_key_vals[i--] = 1; + } } - index->stat_n_leaf_pages = size; - - btr_estimate_number_of_different_key_vals(index); - index = dict_table_get_next_index(index); - } + } while (index); index = dict_table_get_first_index(table); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 38394544c87..4688b5fd16c 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6365,8 +6365,6 @@ ha_innobase::info( dict_index_t* index; ha_rows rec_per_key; ib_longlong n_rows; - ulong j; - ulong i; char path[FN_REFLEN]; os_file_stat_t stat_info; @@ -6376,16 +6374,6 @@ ha_innobase::info( statistics calculation on tables, because that may crash the server if an index is badly corrupted. */ - if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - - /* We return success (0) instead of HA_ERR_CRASHED, - because we want MySQL to process this query and not - stop, like it would do if it received the error code - HA_ERR_CRASHED. */ - - DBUG_RETURN(0); - } - /* We do not know if MySQL can call this function before calling external_lock(). To be safe, update the thd of the current table handle. */ @@ -6480,11 +6468,18 @@ ha_innobase::info( acquiring latches inside InnoDB, we do not call it if we are asked by MySQL to avoid locking. Another reason to avoid the call is that it uses quite a lot of CPU. - See Bug#38185. - We do not update delete_length if no locking is requested - so the "old" value can remain. delete_length is initialized - to 0 in the ha_statistics' constructor. */ - if (!(flag & HA_STATUS_NO_LOCK)) { + See Bug#38185. */ + if (flag & HA_STATUS_NO_LOCK) { + /* We do not update delete_length if no + locking is requested so the "old" value can + remain. delete_length is initialized to 0 in + the ha_statistics' constructor. */ + } else if (UNIV_UNLIKELY + (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) { + /* Avoid accessing the tablespace if + innodb_crash_recovery is set to a high value. */ + stats.delete_length = 0; + } else { ullint avail_space; avail_space = fsp_get_available_space_in_free_extents( @@ -6522,6 +6517,7 @@ ha_innobase::info( } if (flag & HA_STATUS_CONST) { + ulong i = 0; index = dict_table_get_first_index_noninline(ib_table); if (prebuilt->clust_index_was_generated) { @@ -6529,6 +6525,8 @@ ha_innobase::info( } for (i = 0; i < table->s->keys; i++) { + ulong j; + if (index == NULL) { sql_print_error("Table %s contains fewer " "indexes inside InnoDB than " @@ -6585,6 +6583,11 @@ ha_innobase::info( } } + if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { + + goto func_exit; + } + if (flag & HA_STATUS_ERRKEY) { ut_a(prebuilt->trx); ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N); @@ -6597,6 +6600,7 @@ ha_innobase::info( stats.auto_increment_value = innobase_peek_autoinc(); } +func_exit: prebuilt->trx->op_info = (char*)""; DBUG_RETURN(0); From fed2531f02d9bd9def3ce75dbfa9f3a41411109a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 24 Aug 2010 11:10:03 +0300 Subject: [PATCH 14/44] Bug#55832: selects crash too easily when innodb_force_recovery>3 dict_update_statistics_low(): Create bogus statistics for those indexes that cannot be accessed because of the innodb_force_recovery setting. ha_innobase::info(): Calculate statistics for each index, even if innodb_force_recovery is set. Fill in bogus data for those indexes that are not accessed because of the innodb_force_recovery setting. --- storage/innodb_plugin/ChangeLog | 5 ++ storage/innodb_plugin/dict/dict0dict.c | 57 +++++++++++++--------- storage/innodb_plugin/handler/ha_innodb.cc | 39 +++++++-------- 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/storage/innodb_plugin/ChangeLog b/storage/innodb_plugin/ChangeLog index 9fe5c1e7ee6..538cd40dd5b 100644 --- a/storage/innodb_plugin/ChangeLog +++ b/storage/innodb_plugin/ChangeLog @@ -1,3 +1,8 @@ +2010-08-24 The InnoDB Team + + * handler/ha_innodb.c, dict/dict0dict.c: + Fix Bug #55832 selects crash too easily when innodb_force_recovery>3 + 2010-08-03 The InnoDB Team * include/ut0mem.h, ut/ut0mem.c: diff --git a/storage/innodb_plugin/dict/dict0dict.c b/storage/innodb_plugin/dict/dict0dict.c index a79f084e327..560534345f9 100644 --- a/storage/innodb_plugin/dict/dict0dict.c +++ b/storage/innodb_plugin/dict/dict0dict.c @@ -4191,7 +4191,6 @@ dict_update_statistics_low( dictionary mutex */ { dict_index_t* index; - ulint size; ulint sum_of_index_sizes = 0; if (table->ibd_file_missing) { @@ -4206,14 +4205,6 @@ dict_update_statistics_low( return; } - /* If we have set a high innodb_force_recovery level, do not calculate - statistics, as a badly corrupted index can cause a crash in it. */ - - if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - - return; - } - /* Find out the sizes of the indexes and how many different values for the key they approximately have */ @@ -4225,26 +4216,48 @@ dict_update_statistics_low( return; } - while (index) { - size = btr_get_size(index, BTR_TOTAL_SIZE); - index->stat_index_size = size; + do { + if (UNIV_LIKELY + (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE + || (srv_force_recovery < SRV_FORCE_NO_LOG_REDO + && dict_index_is_clust(index)))) { + ulint size; + size = btr_get_size(index, BTR_TOTAL_SIZE); - sum_of_index_sizes += size; + index->stat_index_size = size; - size = btr_get_size(index, BTR_N_LEAF_PAGES); + sum_of_index_sizes += size; - if (size == 0) { - /* The root node of the tree is a leaf */ - size = 1; + size = btr_get_size(index, BTR_N_LEAF_PAGES); + + if (size == 0) { + /* The root node of the tree is a leaf */ + size = 1; + } + + index->stat_n_leaf_pages = size; + + btr_estimate_number_of_different_key_vals(index); + } else { + /* If we have set a high innodb_force_recovery + level, do not calculate statistics, as a badly + corrupted index can cause a crash in it. + Initialize some bogus index cardinality + statistics, so that the data can be queried in + various means, also via secondary indexes. */ + ulint i; + + sum_of_index_sizes++; + index->stat_index_size = index->stat_n_leaf_pages = 1; + + for (i = dict_index_get_n_unique(index); i; ) { + index->stat_n_diff_key_vals[i--] = 1; + } } - index->stat_n_leaf_pages = size; - - btr_estimate_number_of_different_key_vals(index); - index = dict_table_get_next_index(index); - } + } while (index); index = dict_table_get_first_index(table); diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index a70921806b4..c7474109d4f 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -7511,28 +7511,15 @@ ha_innobase::info( dict_index_t* index; ha_rows rec_per_key; ib_int64_t n_rows; - ulong j; - ulong i; char path[FN_REFLEN]; os_file_stat_t stat_info; - DBUG_ENTER("info"); /* If we are forcing recovery at a high level, we will suppress statistics calculation on tables, because that may crash the server if an index is badly corrupted. */ - if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - - /* We return success (0) instead of HA_ERR_CRASHED, - because we want MySQL to process this query and not - stop, like it would do if it received the error code - HA_ERR_CRASHED. */ - - DBUG_RETURN(0); - } - /* We do not know if MySQL can call this function before calling external_lock(). To be safe, update the thd of the current table handle. */ @@ -7627,12 +7614,18 @@ ha_innobase::info( acquiring latches inside InnoDB, we do not call it if we are asked by MySQL to avoid locking. Another reason to avoid the call is that it uses quite a lot of CPU. - See Bug#38185. - We do not update delete_length if no locking is requested - so the "old" value can remain. delete_length is initialized - to 0 in the ha_statistics' constructor. */ - if (!(flag & HA_STATUS_NO_LOCK)) { - + See Bug#38185. */ + if (flag & HA_STATUS_NO_LOCK) { + /* We do not update delete_length if no + locking is requested so the "old" value can + remain. delete_length is initialized to 0 in + the ha_statistics' constructor. */ + } else if (UNIV_UNLIKELY + (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) { + /* Avoid accessing the tablespace if + innodb_crash_recovery is set to a high value. */ + stats.delete_length = 0; + } else { /* lock the data dictionary to avoid races with ibd_file_missing and tablespace_discarded */ row_mysql_lock_data_dictionary(prebuilt->trx); @@ -7677,6 +7670,7 @@ ha_innobase::info( } if (flag & HA_STATUS_CONST) { + ulong i; /* Verify the number of index in InnoDB and MySQL matches up. If prebuilt->clust_index_was_generated holds, InnoDB defines GEN_CLUST_INDEX internally */ @@ -7693,6 +7687,7 @@ ha_innobase::info( } for (i = 0; i < table->s->keys; i++) { + ulong j; /* We could get index quickly through internal index mapping with the index translation table. The identity of index (match up index name with @@ -7758,6 +7753,11 @@ ha_innobase::info( } } + if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { + + goto func_exit; + } + if (flag & HA_STATUS_ERRKEY) { const dict_index_t* err_index; @@ -7778,6 +7778,7 @@ ha_innobase::info( stats.auto_increment_value = innobase_peek_autoinc(); } +func_exit: prebuilt->trx->op_info = (char*)""; DBUG_RETURN(0); From 8822ecff2dea2e83fdad84d7a9307e8aa5905bce Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Tue, 24 Aug 2010 10:48:45 -0300 Subject: [PATCH 15/44] Bug#55846: Link tests fail on Windows - my_compiler.h missing Make the my_compiler.h header, like my_attribute.h, part of the distribution. This is required due to the dependency of the former on the latter (which can undefine __attribute__). --- include/Makefile.am | 5 +++-- scripts/make_win_bin_dist | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/Makefile.am b/include/Makefile.am index 182011c25a3..08532db1731 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -26,7 +26,8 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ decimal.h errmsg.h my_global.h my_net.h \ my_getopt.h sslopt-longopts.h my_dir.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ - m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \ + m_ctype.h my_attribute.h my_compiler.h \ + $(HEADERS_GEN_CONFIGURE) \ $(HEADERS_GEN_MAKE) noinst_HEADERS = config-win.h config-netware.h my_bit.h \ @@ -37,7 +38,7 @@ noinst_HEADERS = config-win.h config-netware.h my_bit.h \ my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \ thr_lock.h t_ctype.h violite.h my_md5.h base64.h \ my_handler.h my_time.h my_vle.h my_user.h \ - my_libwrap.h my_stacktrace.h my_compiler.h + my_libwrap.h my_stacktrace.h EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp diff --git a/scripts/make_win_bin_dist b/scripts/make_win_bin_dist index a08a41bb283..22970c95ddd 100755 --- a/scripts/make_win_bin_dist +++ b/scripts/make_win_bin_dist @@ -263,6 +263,7 @@ cp include/mysql.h \ include/keycache.h \ include/m_ctype.h \ include/my_attribute.h \ + include/my_compiler.h \ include/mysqld_error.h \ include/sql_state.h \ include/mysqld_ername.h \ From 6b246aaf8d61d3cf6822401cada37970e8f2467a Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 26 Aug 2010 18:06:07 +0300 Subject: [PATCH 16/44] Increment InnoDB Plugin version to 1.0.12. InnoDB Plugin 1.0.11 has been released with MySQL 5.1.50. --- storage/innodb_plugin/include/univ.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innodb_plugin/include/univ.i b/storage/innodb_plugin/include/univ.i index aa56c18e44e..66b712a0355 100644 --- a/storage/innodb_plugin/include/univ.i +++ b/storage/innodb_plugin/include/univ.i @@ -46,7 +46,7 @@ Created 1/20/1994 Heikki Tuuri #define INNODB_VERSION_MAJOR 1 #define INNODB_VERSION_MINOR 0 -#define INNODB_VERSION_BUGFIX 11 +#define INNODB_VERSION_BUGFIX 12 /* The following is the InnoDB version as shown in SELECT plugin_version FROM information_schema.plugins; From e5bab33a2a4a97261b70ac7c5ef4f4f694896109 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Thu, 26 Aug 2010 17:14:18 +0200 Subject: [PATCH 17/44] Bug#53806: Wrong estimates for range query in partitioned MyISAM table Bug#46754: 'rows' field doesn't reflect partition pruning The EXPLAIN's result in 'rows' field was evaluated to number of rows when the table was opened (not from the table cache) and only the partitions left after pruning was updated with its correct number of rows. The evaluation of the 'rows' field was using handler::records() which is a potentially expensive call, and ignores the partitioning pruning. The fix was to use the handlers stats.records after updating it with ::info(HA_STATUS_VARIABLE) instead. mysql-test/r/partition_pruning.result: updated result mysql-test/t/partition_pruning.test: Added test. sql/sql_select.cc: Use ::info + stats.records instead of ::records(). --- mysql-test/r/partition_pruning.result | 508 ++++++++++++++------------ mysql-test/t/partition_pruning.test | 24 ++ sql/sql_select.cc | 10 +- 3 files changed, 299 insertions(+), 243 deletions(-) diff --git a/mysql-test/r/partition_pruning.result b/mysql-test/r/partition_pruning.result index 568c21b27be..01ae3876fd0 100644 --- a/mysql-test/r/partition_pruning.result +++ b/mysql-test/r/partition_pruning.result @@ -1,5 +1,29 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; # +# Bug#53806: Wrong estimates for range query in partitioned MyISAM table +# Bug#46754: 'rows' field doesn't reflect partition pruning +# +CREATE TABLE t1 (a INT PRIMARY KEY) +PARTITION BY RANGE (a) ( +PARTITION p0 VALUES LESS THAN (1), +PARTITION p1 VALUES LESS THAN (2), +PARTITION p2 VALUES LESS THAN (3), +PARTITION p3 VALUES LESS THAN (4), +PARTITION p4 VALUES LESS THAN (5), +PARTITION p5 VALUES LESS THAN (6), +PARTITION max VALUES LESS THAN MAXVALUE); +INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; +id select_type table partitions type possible_keys key key_len ref rows Extra +# # # # # # # # # 3 # +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7; +id select_type table partitions type possible_keys key key_len ref rows Extra +# # # # # # # # # 9 # +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; +id select_type table partitions type possible_keys key key_len ref rows Extra +# # # # # # # # # 3 # +DROP TABLE t1; +# # Bug#49742: Partition Pruning not working correctly for RANGE # CREATE TABLE t1 (a INT PRIMARY KEY) @@ -89,7 +113,7 @@ a 1 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1 index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p0,p1 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a <= 2; a -1 @@ -98,7 +122,7 @@ a 2 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2 index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p0,p1,p2 index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a <= 3; a -1 @@ -108,7 +132,7 @@ a 3 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2,p3 index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p0,p1,p2,p3 index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a <= 4; a -1 @@ -119,7 +143,7 @@ a 4 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2,p3,p4 index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p0,p1,p2,p3,p4 index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a <= 5; a -1 @@ -131,7 +155,7 @@ a 5 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2,p3,p4,p5 index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p0,p1,p2,p3,p4,p5 index PRIMARY PRIMARY 4 NULL 7 Using where; Using index SELECT * FROM t1 WHERE a <= 6; a -1 @@ -213,7 +237,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 8 Using where; Using index SELECT * FROM t1 WHERE a >= 2; a 2 @@ -225,7 +249,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 7 Using where; Using index SELECT * FROM t1 WHERE a >= 3; a 3 @@ -236,7 +260,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a >= 4; a 4 @@ -246,7 +270,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p4,p5,max index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a >= 5; a 5 @@ -255,7 +279,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p5,max index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a >= 6; a 6 @@ -263,14 +287,14 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a >= 7; a 7 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 7; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 1; a 2 @@ -282,7 +306,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 7 Using where; Using index SELECT * FROM t1 WHERE a > 2; a 3 @@ -293,7 +317,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a > 3; a 4 @@ -303,7 +327,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p4,p5,max index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a > 4; a 5 @@ -312,7 +336,7 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 p5,max index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a > 5; a 6 @@ -320,20 +344,20 @@ a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 6; a 7 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 7; a 8 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 7; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY) PARTITION BY RANGE (a) ( @@ -408,7 +432,7 @@ a 1 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1 index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p0,p1 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a <= 2; a -1 @@ -417,7 +441,7 @@ a 2 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2 index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p0,p1,p2 index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a <= 3; a -1 @@ -427,7 +451,7 @@ a 3 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2,p3 index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p0,p1,p2,p3 index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a <= 4; a -1 @@ -438,7 +462,7 @@ a 4 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1,p2,p3,p4 index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p0,p1,p2,p3,p4 index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a <= 5; a -1 @@ -511,7 +535,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p1,p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 7 Using where; Using index SELECT * FROM t1 WHERE a >= 2; a 2 @@ -522,7 +546,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a >= 3; a 3 @@ -532,7 +556,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p3,p4,max index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a >= 4; a 4 @@ -541,7 +565,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p4,max index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a >= 5; a 5 @@ -549,14 +573,14 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a >= 6; a 6 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 1; a 2 @@ -567,7 +591,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 6 Using where; Using index SELECT * FROM t1 WHERE a > 2; a 3 @@ -577,7 +601,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p3,p4,max index PRIMARY PRIMARY 4 NULL 5 Using where; Using index SELECT * FROM t1 WHERE a > 3; a 4 @@ -586,7 +610,7 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 p4,max index PRIMARY PRIMARY 4 NULL 4 Using where; Using index SELECT * FROM t1 WHERE a > 4; a 5 @@ -594,20 +618,20 @@ a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 5; a 6 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index SELECT * FROM t1 WHERE a > 6; a 7 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index +1 SIMPLE t1 max index PRIMARY PRIMARY 4 NULL 3 Using where; Using index DROP TABLE t1; # test of RANGE and index CREATE TABLE t1 (a DATE, KEY(a)) @@ -757,10 +781,10 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01,p2001-01-01 range a a 4 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p2001-01-01 index a a 4 NULL 7 Using where; Using index +1 SIMPLE t1 pNULL,p2001-01-01 index a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p2001-01-01 index a a 4 NULL 7 Using where; Using index +1 SIMPLE t1 pNULL,p2001-01-01 index a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pNULL ref a a 4 const 1 Using where; Using index @@ -880,34 +904,34 @@ a 1001-01-01 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1001-01-01 system NULL NULL NULL NULL 1 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 3 Using where # Disabling warnings for the invalid date EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra @@ -917,25 +941,25 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p2001-01-01 ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p1001-01-01,p2001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p0001-01-01,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where DROP TABLE t1; # test of LIST and index CREATE TABLE t1 (a DATE, KEY(a)) @@ -1086,10 +1110,10 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 range a a 4 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL index a a 4 NULL 7 Using where; Using index +1 SIMPLE t1 p2001-01-01,pNULL index a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL index a a 4 NULL 7 Using where; Using index +1 SIMPLE t1 p2001-01-01,pNULL index a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pNULL ref a a 4 const 1 Using where; Using index @@ -1101,7 +1125,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 range a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01 index a a 4 NULL 7 Using where; Using index +1 SIMPLE t1 pNULL,p1001-01-01 index a a 4 NULL 4 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0001-01-01,pNULL,p1001-01-01 range a a 4 NULL 3 Using where; Using index @@ -1209,62 +1233,62 @@ a 1001-01-01 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1001-01-01 system NULL NULL NULL NULL 1 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 3 Using where # Disabling warnings for the invalid date EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p2001-01-01,pNULL ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p0000-01-02,p1001-01-01 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pNULL,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 pNULL,p1001-01-01 ALL NULL NULL NULL NULL 4 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p0001-01-01,pNULL,p1001-01-01 ALL NULL NULL NULL NULL 5 Using where DROP TABLE t1; # Test with DATETIME column NOT NULL CREATE TABLE t1 ( @@ -1289,25 +1313,25 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 3 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1315,99 +1339,99 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 3 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 12 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 12 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 12 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 12 NULL 6 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 13 Using where; Using index +1 SIMPLE t1 p20090402 index NULL PRIMARY 12 NULL 3 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1440,21 +1464,21 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1462,79 +1486,79 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090403 index NULL PRIMARY 7 NULL 2 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402,p20090403 index NULL PRIMARY 7 NULL 7 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1542,19 +1566,19 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090404,p20090405 index NULL PRIMARY 7 NULL 8 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090402 index NULL PRIMARY 7 NULL 5 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1562,11 +1586,11 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 12 Using where; Using index +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 index NULL PRIMARY 7 NULL 10 Using where; Using index DROP TABLE t1; # Test with DATETIME column NULL CREATE TABLE t1 ( @@ -1590,25 +1614,25 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 8 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1616,99 +1640,99 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 6 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 13 Using where +1 SIMPLE t1 p20090402 ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1740,21 +1764,21 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1762,79 +1786,79 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090403 ALL NULL NULL NULL NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402,p20090403 ALL NULL NULL NULL NULL 7 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1842,19 +1866,19 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090404,p20090405 ALL NULL NULL NULL NULL 8 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090402 ALL NULL NULL NULL NULL 5 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra @@ -1862,11 +1886,11 @@ id select_type table partitions type possible_keys key key_len ref rows Extra EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t1 p20090401,p20090403,p20090404,p20090405 ALL NULL NULL NULL NULL 10 Using where DROP TABLE t1; # For better code coverage of the patch CREATE TABLE t1 ( @@ -1930,7 +1954,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1 ALL NULL NULL NULL NULL 3 Using where explain partitions select * from t2 where a=1 and b=1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 2 Using where create table t3 ( a int ) @@ -1988,25 +2012,25 @@ id select_type table partitions type possible_keys key key_len ref rows Extra explain partitions select * from t5 where (a=10 and b=1) or (a=10 and b=2) or (a=10 and b = 3); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (a=10 and b=2) or (a=10 and b=3) or (a=10 and b = 4); id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t5 where (c=1 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_p0sp0,p1_p1sp0 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp0,p1_p1sp0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or (c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 3 Using where explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or (b=2 and c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 3 Using where create table t6 (a int not null) partition by LIST(a) ( partition p1 values in (1), partition p3 values in (3), @@ -2044,7 +2068,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t6 p5,p7,p9 system NULL NULL NULL NULL 1 explain partitions select * from t6 where a >= 3 and a <= 8; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t6 p3,p5,p7 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t6 p3,p5,p7 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t6 where a > 3 and a < 5; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables @@ -2086,7 +2110,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t6 p5,p7,p9 system NULL NULL NULL NULL 1 explain partitions select * from t6 where a >= 3 and a <= 8; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t6 p3,p5,p7 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t6 p3,p5,p7 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t6 where a > 3 and a < 5; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables @@ -2325,7 +2349,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra explain partitions select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE X p1,p2 ALL a NULL NULL NULL 4 Using where +1 SIMPLE X p1,p2 ALL a NULL NULL NULL 2 Using where 1 SIMPLE Y p1,p2 ref a a 4 test.X.a 2 drop table t1; create table t1 (a int) partition by hash(a) partitions 20; @@ -2338,7 +2362,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a > 1 and a <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 p2,p3 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a >= 1 and a <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2,p3 ALL NULL NULL NULL NULL 3 Using where @@ -2428,22 +2452,22 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL NULL NULL NULL NULL 1010 explain partitions select * from t2 where a < 801 and a > 200; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p1,p2,p3,p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p1,p2,p3,p4 ALL NULL NULL NULL NULL 800 Using where explain partitions select * from t2 where a < 801 and a > 800; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p4 ALL NULL NULL NULL NULL 200 Using where explain partitions select * from t2 where a > 600; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 400 Using where explain partitions select * from t2 where a > 600 and b = 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 400 Using where explain partitions select * from t2 where a > 600 and b = 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 400 Using where explain partitions select * from t2 where a > 600 and b = 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 1010 Using where +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 400 Using where explain partitions select * from t2 where b = 5; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL NULL NULL NULL NULL 1010 Using where @@ -2498,19 +2522,19 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL NULL NULL NULL NULL 910 explain partitions select * from t2 where a = 101; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 910 Using where +1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 110 Using where explain partitions select * from t2 where a = 550; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 910 Using where +1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 200 Using where explain partitions select * from t2 where a = 833; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p4 ALL NULL NULL NULL NULL 910 Using where +1 SIMPLE t2 p4 ALL NULL NULL NULL NULL 200 Using where explain partitions select * from t2 where (a = 100 OR a = 900); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0,p4 ALL NULL NULL NULL NULL 910 Using where +1 SIMPLE t2 p0,p4 ALL NULL NULL NULL NULL 310 Using where explain partitions select * from t2 where (a > 100 AND a < 600); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0,p1,p2 ALL NULL NULL NULL NULL 910 Using where +1 SIMPLE t2 p0,p1,p2 ALL NULL NULL NULL NULL 510 Using where explain partitions select * from t2 where b = 4; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ref b b 5 const 76 Using where @@ -2796,17 +2820,17 @@ id select_type table partitions type possible_keys key key_len ref rows Extra explain partitions select * from t1 where a >= 18446744073709551000-1 and a <= 18446744073709551000+1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p3,p4 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p3,p4 ALL NULL NULL NULL NULL 3 Using where explain partitions select * from t1 where a between 18446744073709551001 and 18446744073709551002; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a = 18446744073709551000; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a = 18446744073709551613; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a = 18446744073709551614; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables @@ -2833,10 +2857,10 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a=0xFE; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p2 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t2 where a=0xFE; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a > 0xFE AND a <= 0xFF; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables @@ -2845,22 +2869,22 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables explain partitions select * from t1 where a >= 0xFE AND a <= 0xFF; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p2 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t2 where a >= 0xFE AND a <= 0xFF; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t2 p2 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a < 64 AND a >= 63; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t2 where a < 64 AND a >= 63; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t2 p0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a <= 64 AND a >= 63; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t2 where a <= 64 AND a >= 63; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0,p1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t2 p0,p1 ALL NULL NULL NULL NULL 4 Using where drop table t1; drop table t2; create table t1(a bigint unsigned not null) partition by range(a+0) ( diff --git a/mysql-test/t/partition_pruning.test b/mysql-test/t/partition_pruning.test index 358832496e5..db544d4643f 100644 --- a/mysql-test/t/partition_pruning.test +++ b/mysql-test/t/partition_pruning.test @@ -8,6 +8,30 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; --enable_warnings +--echo # +--echo # Bug#53806: Wrong estimates for range query in partitioned MyISAM table +--echo # Bug#46754: 'rows' field doesn't reflect partition pruning +--echo # +CREATE TABLE t1 (a INT PRIMARY KEY) +PARTITION BY RANGE (a) ( +PARTITION p0 VALUES LESS THAN (1), +PARTITION p1 VALUES LESS THAN (2), +PARTITION p2 VALUES LESS THAN (3), +PARTITION p3 VALUES LESS THAN (4), +PARTITION p4 VALUES LESS THAN (5), +PARTITION p5 VALUES LESS THAN (6), +PARTITION max VALUES LESS THAN MAXVALUE); + +INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); + +--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; +--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7; +--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; +DROP TABLE t1; + --echo # --echo # Bug#49742: Partition Pruning not working correctly for RANGE --echo # diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7ee1762295f..9a824b0810a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16640,7 +16640,15 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, if (tab->select && tab->select->quick) examined_rows= tab->select->quick->records; else if (tab->type == JT_NEXT || tab->type == JT_ALL) - examined_rows= tab->limit ? tab->limit : tab->table->file->records(); + { + if (tab->limit) + examined_rows= tab->limit; + else + { + tab->table->file->info(HA_STATUS_VARIABLE); + examined_rows= tab->table->file->stats.records; + } + } else examined_rows=(ha_rows)join->best_positions[i].records_read; From 0ec8312f72aaede3972ba1bdf38cd6d5b0289bdf Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Aug 2010 10:43:51 +0200 Subject: [PATCH 18/44] Bug#53806: Wrong estimates for range query in partitioned MyISAM table Bug#46754: 'rows' field doesn't reflect partition pruning Update of test results after fixing the above bugs. (fix in separate commit). mysql-test/r/partition.result: Updated test result after fixing bugs 46754 and 53806 mysql-test/r/partition_hash.result: Updated test result after fixing bugs 46754 and 53806 mysql-test/r/partition_innodb.result: Updated test result after fixing bugs 46754 and 53806 mysql-test/r/partition_range.result: Updated test result after fixing bugs 46754 and 53806 mysql-test/suite/parts/r/partition_alter3_innodb.result: Updated test result after fixing bugs 46754 and 53806 mysql-test/suite/parts/r/partition_alter3_myisam.result: Updated test result after fixing bugs 46754 and 53806 --- mysql-test/r/partition.result | 2 +- mysql-test/r/partition_hash.result | 12 +++---- mysql-test/r/partition_innodb.result | 18 +++++----- mysql-test/r/partition_range.result | 12 +++---- .../parts/r/partition_alter3_innodb.result | 36 +++++++++---------- .../parts/r/partition_alter3_myisam.result | 36 +++++++++---------- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 23a485dc5ed..90b4bf92af5 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1382,7 +1382,7 @@ NULL 2 explain partitions select * from t1 where a is null or a < 0 or a > 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pn,p2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 pn,p2 ALL NULL NULL NULL NULL 2 Using where drop table t1; CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, name VARCHAR(20)) ENGINE=MyISAM DEFAULT CHARSET=latin1 diff --git a/mysql-test/r/partition_hash.result b/mysql-test/r/partition_hash.result index 19da70db5a0..94fefe77a77 100644 --- a/mysql-test/r/partition_hash.result +++ b/mysql-test/r/partition_hash.result @@ -69,25 +69,25 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,p1,p2,p3 ALL NULL NULL NULL NULL 9 Using where explain partitions select * from t1 where a is null or (a >= 5 and a <= 7); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p2,p3 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p0,p2,p3 ALL NULL NULL NULL NULL 7 Using where explain partitions select * from t1 where a is null; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 3 Using where explain partitions select * from t1 where a is not null; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,p1,p2,p3 ALL NULL NULL NULL NULL 9 Using where explain partitions select * from t1 where a >= 1 and a < 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 5 Using where explain partitions select * from t1 where a >= 3 and a <= 5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p1,p2 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t1 where a > 2 and a < 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a > 3 and a <= 6; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p2,p3 ALL NULL NULL NULL NULL 9 Using where +1 SIMPLE t1 p2,p3 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t1 where a > 5; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,p1,p2,p3 ALL NULL NULL NULL NULL 9 Using where diff --git a/mysql-test/r/partition_innodb.result b/mysql-test/r/partition_innodb.result index 2a04aafe554..238fbf4662c 100644 --- a/mysql-test/r/partition_innodb.result +++ b/mysql-test/r/partition_innodb.result @@ -22,31 +22,31 @@ insert INTO t1 VALUES (110); ERROR HY000: Table has no partition for value 110 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 90; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 90; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 90; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 89; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p90 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p90 ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 89; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p90 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 p90 ALL NULL NULL NULL NULL 3 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 89; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 100; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 100; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 100; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where DROP TABLE t1; # # Bug#50104: Partitioned table with just 1 partion works with fk diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result index 7a3ff4861cc..58945b563dc 100644 --- a/mysql-test/r/partition_range.result +++ b/mysql-test/r/partition_range.result @@ -73,13 +73,13 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pnull system NULL NULL NULL NULL 1 explain partitions select * from t1 where a >= 0; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a < 0; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables explain partitions select * from t1 where a <= 0; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pnull,p0 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 pnull,p0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a > 1; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables @@ -112,16 +112,16 @@ select * from t1 where a > 1; a b explain partitions select * from t1 where a is null; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a >= 0; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t1 where a < 0; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t1 where a <= 0; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t1 where a > 1; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables diff --git a/mysql-test/suite/parts/r/partition_alter3_innodb.result b/mysql-test/suite/parts/r/partition_alter3_innodb.result index cb104d4be54..7825a2350b0 100644 --- a/mysql-test/suite/parts/r/partition_alter3_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter3_innodb.result @@ -141,7 +141,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -165,7 +165,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -190,7 +190,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -226,7 +226,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -248,7 +248,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -269,7 +269,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -289,7 +289,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -308,7 +308,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -326,7 +326,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -452,7 +452,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -476,7 +476,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -504,7 +504,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -538,7 +538,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -563,7 +563,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -587,7 +587,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 23 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -610,7 +610,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -632,7 +632,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -653,7 +653,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 diff --git a/mysql-test/suite/parts/r/partition_alter3_myisam.result b/mysql-test/suite/parts/r/partition_alter3_myisam.result index 374b108b57e..a5dec48e85c 100644 --- a/mysql-test/suite/parts/r/partition_alter3_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter3_myisam.result @@ -155,7 +155,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -187,7 +187,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -228,7 +228,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -278,7 +278,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -312,7 +312,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -343,7 +343,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -371,7 +371,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -396,7 +396,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part1 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -418,7 +418,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -552,7 +552,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -584,7 +584,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -628,7 +628,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p6 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -676,7 +676,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -713,7 +713,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 3 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -747,7 +747,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p4 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -778,7 +778,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 5 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -806,7 +806,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 part7 ALL NULL NULL NULL NULL 7 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 @@ -831,7 +831,7 @@ t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where # check read single success: 1 # check read all success: 1 # check read row by row success: 1 From 6a113b215abde05ffe602111f54c2aef8e78bbd1 Mon Sep 17 00:00:00 2001 From: Ramil Kalimullin Date: Mon, 30 Aug 2010 11:51:46 +0400 Subject: [PATCH 19/44] Fix for bug #51875: crash when loading data into geometry function polyfromwkb Check for number of line strings in the incoming polygon data (wkb) and for number of points in the incoming linestring wkb. mysql-test/r/gis.result: Fix for bug #51875: crash when loading data into geometry function polyfromwkb - test result. mysql-test/t/gis.test: Fix for bug #51875: crash when loading data into geometry function polyfromwkb - test case. sql/spatial.cc: Fix for bug #51875: crash when loading data into geometry function polyfromwkb - creating a polygon from wkb check for number of line strings, - creating a linestring from wkb check for number of line points. --- mysql-test/r/gis.result | 7 +++++++ mysql-test/t/gis.test | 10 ++++++++++ sql/spatial.cc | 6 ++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index 3e28227d542..d39afa6f315 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -1057,4 +1057,11 @@ NULL SELECT Polygon(12345123,''); Polygon(12345123,'') NULL +# +# BUG#51875: crash when loading data into geometry function polyfromwkb +# +SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); +SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); End of 5.1 tests diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index bc0695aaa93..236b31efb79 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -722,4 +722,14 @@ SELECT Polygon(123451,''); SELECT Polygon(1234512,''); SELECT Polygon(12345123,''); + +--echo # +--echo # BUG#51875: crash when loading data into geometry function polyfromwkb +--echo # +SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); +SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); + + --echo End of 5.1 tests diff --git a/sql/spatial.cc b/sql/spatial.cc index 2305a8eb97d..8b869a5b1ca 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -528,7 +528,7 @@ uint Gis_line_string::init_from_wkb(const char *wkb, uint len, n_points= wkb_get_uint(wkb, bo); proper_length= 4 + n_points * POINT_DATA_SIZE; - if (len < proper_length || res->reserve(proper_length)) + if (!n_points || len < proper_length || res->reserve(proper_length)) return 0; res->q_append(n_points); @@ -746,7 +746,9 @@ uint Gis_polygon::init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, if (len < 4) return 0; - n_linear_rings= wkb_get_uint(wkb, bo); + if (!(n_linear_rings= wkb_get_uint(wkb, bo))) + return 0; + if (res->reserve(4, 512)) return 0; wkb+= 4; From 93b8156365630192ede711f4b5a33b8adf9cddd4 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Mon, 30 Aug 2010 11:25:10 +0200 Subject: [PATCH 20/44] Bug #55178 Set timeout on test-to-test-basis Allow --testcase-timeout= to be set in .opt file for test --- mysql-test/lib/mtr_cases.pm | 7 +++++++ mysql-test/mysql-test-run.pl | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index 07a26a1cdf4..7d25a72212a 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -684,6 +684,13 @@ sub process_opts_file { next; } + $value= mtr_match_prefix($opt, "--testcase-timeout="); + if ( defined $value ) { + # Overrides test case timeout for this test + $tinfo->{'case-timeout'}= $value; + next; + } + # Ok, this was a real option, add it push(@{$tinfo->{$opt_name}}, $opt); } diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 28665918e49..5e6d4206d4a 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -212,7 +212,6 @@ my $opt_suite_timeout = $ENV{MTR_SUITE_TIMEOUT} || 300; # minutes my $opt_shutdown_timeout= $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds my $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds -sub testcase_timeout { return $opt_testcase_timeout * 60; }; sub suite_timeout { return $opt_suite_timeout * 60; }; sub check_timeout { return $opt_testcase_timeout * 6; }; @@ -241,6 +240,17 @@ my $opt_callgrind; my %mysqld_logs; my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions. +sub testcase_timeout ($) { + my ($tinfo)= @_; + if (exists $tinfo->{'case-timeout'}) { + # Return test specific timeout if *longer* that the general timeout + my $test_to= $tinfo->{'case-timeout'}; + $test_to*= 10 if $opt_valgrind; + return $test_to * 60 if $test_to > $opt_testcase_timeout; + } + return $opt_testcase_timeout * 60; +} + our $opt_warnings= 1; our $opt_skip_ndbcluster= 0; @@ -3469,7 +3479,7 @@ sub run_testcase ($) { } } - my $test_timeout= start_timer(testcase_timeout()); + my $test_timeout= start_timer(testcase_timeout($tinfo)); do_before_run_mysqltest($tinfo); @@ -3669,7 +3679,7 @@ sub run_testcase ($) { { my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log"; $tinfo->{comment}= - "Test case timeout after ".testcase_timeout(). + "Test case timeout after ".testcase_timeout($tinfo). " seconds\n\n"; # Add 20 last executed commands from test case log file if (-e $log_file_name) @@ -3678,7 +3688,7 @@ sub run_testcase ($) { "== $log_file_name == \n". mtr_lastlinesfromfile($log_file_name, 20)."\n"; } - $tinfo->{'timeout'}= testcase_timeout(); # Mark as timeout + $tinfo->{'timeout'}= testcase_timeout($tinfo); # Mark as timeout run_on_all($tinfo, 'analyze-timeout'); report_failure_and_restart($tinfo); From 7749cd8fd807683e2466b257d48f3850a6fb48c5 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 31 Aug 2010 11:27:57 +0200 Subject: [PATCH 21/44] Bug #56383 provide option to restart mysqld after each mtr test Added --force-restart --- mysql-test/mysql-test-run.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 5e6d4206d4a..82c62ebfcf1 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -225,6 +225,7 @@ my $opt_repeat= 1; my $opt_retry= 3; my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2); my $opt_reorder= 1; +my $opt_force_restart= 0; my $opt_strace_client; @@ -924,6 +925,7 @@ sub command_line_setup { 'report-features' => \$opt_report_features, 'comment=s' => \$opt_comment, 'fast' => \$opt_fast, + 'force-restart' => \$opt_force_restart, 'reorder!' => \$opt_reorder, 'enable-disabled' => \&collect_option, 'verbose+' => \$opt_verbose, @@ -4512,6 +4514,11 @@ sub server_need_restart { return 1; } + if ( $opt_force_restart ) { + mtr_verbose_restart($server, "forced restart turned on"); + return 1; + } + if ( $tinfo->{template_path} ne $current_config_name) { mtr_verbose_restart($server, "using different config file"); @@ -5541,6 +5548,7 @@ Misc options servers to exit before finishing the process fast Run as fast as possible, dont't wait for servers to shutdown etc. + force-restart Always restart servers between tests parallel=N Run tests in N parallel threads (default=1) Use parallel=auto for auto-setting of N repeat=N Run each test N number of times From 8a04f73d3c2a16c78f7e350480fa9d6aff3312fe Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Tue, 31 Aug 2010 11:28:22 -0300 Subject: [PATCH 22/44] Bug#55846: Link tests fail on Windows - my_compiler.h missing Make the my_compiler.h header, like my_attribute.h, part of the distribution. This is required due to the dependency of the former on the latter (which can undefine __attribute__). --- include/CMakeLists.txt | 1 + include/Makefile.am | 7 ++++--- scripts/make_win_bin_dist | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index aee7561d242..5334fc0f5ae 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -54,6 +54,7 @@ SET(HEADERS keycache.h m_ctype.h my_attribute.h + my_compiler.h ${HEADERS_GEN_CONFIGURE} ) diff --git a/include/Makefile.am b/include/Makefile.am index e30588de065..b0e2402d46c 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -30,8 +30,9 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ decimal.h errmsg.h my_global.h my_net.h \ my_getopt.h sslopt-longopts.h my_dir.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ - m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \ - $(HEADERS_GEN_MAKE) probes_mysql.h probes_mysql_nodtrace.h + m_ctype.h my_attribute.h my_compiler.h \ + $(HEADERS_GEN_CONFIGURE) $(HEADERS_GEN_MAKE) \ + probes_mysql.h probes_mysql_nodtrace.h noinst_HEADERS = lf.h my_bit.h \ heap.h my_bitmap.h my_uctype.h password.h \ @@ -45,7 +46,7 @@ noinst_HEADERS = lf.h my_bit.h \ my_user.h my_atomic.h atomic/nolock.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ - atomic/solaris.h mysql/innodb_priv.h my_compiler.h + atomic/solaris.h mysql/innodb_priv.h pkgpsiinclude_HEADERS = mysql/psi/psi.h mysql/psi/mysql_thread.h \ mysql/psi/mysql_file.h diff --git a/scripts/make_win_bin_dist b/scripts/make_win_bin_dist index 4fb57b06d71..aa106a3dfc4 100755 --- a/scripts/make_win_bin_dist +++ b/scripts/make_win_bin_dist @@ -260,6 +260,7 @@ cp include/mysql.h \ include/keycache.h \ include/m_ctype.h \ include/my_attribute.h \ + include/my_compiler.h \ include/mysqld_error.h \ include/sql_state.h \ include/mysqld_ername.h \ From 64b639260ca83c27a7ffaa0f4d12dcf167c580cf Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 1 Sep 2010 19:38:34 +0200 Subject: [PATCH 23/44] Bug#39932 "create table fails if column for FK is in different case than in corr index". Server was unable to find existing or explicitly created supporting index for foreign key if corresponding statement clause used field names in case different than one used in key specification and created yet another supporting index. In cases when name of constraint (and thus name of generated index) was the same as name of existing/explicitly created index this led to duplicate key name error. The problem was that unlike all other code Key_part_spec::operator==() compared field names in case sensitive fashion. As result routines responsible for getting rid of redundant generated supporting indexes for foreign key were not working properly for versions of field names using different cases. (backported from mysql-trunk) sql/sql_class.cc: Make field name comparison case-insensitive like it is in the rest of server. --- mysql-test/suite/innodb/r/innodb_mysql.result | 20 +++++++++++++++++++ mysql-test/suite/innodb/t/innodb_mysql.test | 18 +++++++++++++++++ sql/sql_class.cc | 4 +++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/innodb_mysql.result b/mysql-test/suite/innodb/r/innodb_mysql.result index ba8ac0ba86c..0a76a1fbcec 100644 --- a/mysql-test/suite/innodb/r/innodb_mysql.result +++ b/mysql-test/suite/innodb/r/innodb_mysql.result @@ -2588,3 +2588,23 @@ Extra Using index DROP TABLE t1; # End of 5.1 tests +# +# Test for bug #39932 "create table fails if column for FK is in different +# case than in corr index". +# +drop tables if exists t1, t2; +create table t1 (pk int primary key) engine=InnoDB; +# Even although the below statement uses uppercased field names in +# foreign key definition it still should be able to find explicitly +# created supporting index. So it should succeed and should not +# create any additional supporting indexes. +create table t2 (fk int, key x (fk), +constraint x foreign key (FK) references t1 (PK)) engine=InnoDB; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `fk` int(11) DEFAULT NULL, + KEY `x` (`fk`), + CONSTRAINT `x` FOREIGN KEY (`fk`) REFERENCES `t1` (`pk`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop table t2, t1; diff --git a/mysql-test/suite/innodb/t/innodb_mysql.test b/mysql-test/suite/innodb/t/innodb_mysql.test index ae03bebfbe3..cb534068c6e 100644 --- a/mysql-test/suite/innodb/t/innodb_mysql.test +++ b/mysql-test/suite/innodb/t/innodb_mysql.test @@ -813,3 +813,21 @@ DROP TABLE t1; --echo End of 5.1 tests + + +--echo # +--echo # Test for bug #39932 "create table fails if column for FK is in different +--echo # case than in corr index". +--echo # +--disable_warnings +drop tables if exists t1, t2; +--enable_warnings +create table t1 (pk int primary key) engine=InnoDB; +--echo # Even although the below statement uses uppercased field names in +--echo # foreign key definition it still should be able to find explicitly +--echo # created supporting index. So it should succeed and should not +--echo # create any additional supporting indexes. +create table t2 (fk int, key x (fk), + constraint x foreign key (FK) references t1 (PK)) engine=InnoDB; +show create table t2; +drop table t2, t1; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7c52e6957cc..44bb6d51c6c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -91,7 +91,9 @@ extern "C" void free_user_var(user_var_entry *entry) bool Key_part_spec::operator==(const Key_part_spec& other) const { - return length == other.length && !strcmp(field_name, other.field_name); + return length == other.length && + !my_strcasecmp(system_charset_info, field_name, + other.field_name); } /** From afff01687bbad18f62ee30609c7b9500bbb4aede Mon Sep 17 00:00:00 2001 From: Alfranio Correia Date: Thu, 2 Sep 2010 14:05:06 +0100 Subject: [PATCH 24/44] BUG#55961 Savepoint Identifier should be enclosed with backticks Added backticks to the savepoint identifier. --- .../suite/binlog/r/binlog_row_mix_innodb_myisam.result | 8 ++++---- .../suite/binlog/r/binlog_stm_mix_innodb_myisam.result | 8 ++++---- mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result | 8 ++++---- mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result | 2 +- sql/log.cc | 8 ++++++-- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result index 8b42cadf6cb..8ee531c6ce2 100644 --- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result @@ -48,12 +48,12 @@ Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # SAVEPOINT my_savepoint +master-bin.000001 # Query # # SAVEPOINT `my_savepoint` master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # ROLLBACK TO my_savepoint +master-bin.000001 # Query # # ROLLBACK TO `my_savepoint` master-bin.000001 # Xid # # COMMIT /* XID */ delete from t1; delete from t2; @@ -77,12 +77,12 @@ Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # SAVEPOINT my_savepoint +master-bin.000001 # Query # # SAVEPOINT `my_savepoint` master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # ROLLBACK TO my_savepoint +master-bin.000001 # Query # # ROLLBACK TO `my_savepoint` master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ diff --git a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result index a26fcc1dc1a..d2f47e56c61 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result @@ -44,10 +44,10 @@ show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # use `test`; insert into t1 values(3) -master-bin.000001 # Query # # SAVEPOINT my_savepoint +master-bin.000001 # Query # # SAVEPOINT `my_savepoint` master-bin.000001 # Query # # use `test`; insert into t1 values(4) master-bin.000001 # Query # # use `test`; insert into t2 select * from t1 -master-bin.000001 # Query # # ROLLBACK TO my_savepoint +master-bin.000001 # Query # # ROLLBACK TO `my_savepoint` master-bin.000001 # Xid # # COMMIT /* XID */ delete from t1; delete from t2; @@ -70,10 +70,10 @@ show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # use `test`; insert into t1 values(5) -master-bin.000001 # Query # # SAVEPOINT my_savepoint +master-bin.000001 # Query # # SAVEPOINT `my_savepoint` master-bin.000001 # Query # # use `test`; insert into t1 values(6) master-bin.000001 # Query # # use `test`; insert into t2 select * from t1 -master-bin.000001 # Query # # ROLLBACK TO my_savepoint +master-bin.000001 # Query # # ROLLBACK TO `my_savepoint` master-bin.000001 # Query # # use `test`; insert into t1 values(7) master-bin.000001 # Xid # # COMMIT /* XID */ delete from t1; diff --git a/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result b/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result index 3bf33044d75..f826136e81e 100644 --- a/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result +++ b/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result @@ -139,14 +139,14 @@ show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # use `test`; INSERT INTO db1.t1 VALUES(20) -master-bin.000001 # Query # # SAVEPOINT has_comment +master-bin.000001 # Query # # SAVEPOINT `has_comment` master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(30) master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("in savepoint has_comment") -master-bin.000001 # Query # # SAVEPOINT mixed_cases +master-bin.000001 # Query # # SAVEPOINT `mixed_cases` master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("in savepoint mixed_cases") master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(40) -master-bin.000001 # Query # # ROLLBACK TO mixed_cases -master-bin.000001 # Query # # ROLLBACK TO has_comment +master-bin.000001 # Query # # ROLLBACK TO `mixed_cases` +master-bin.000001 # Query # # ROLLBACK TO `has_comment` master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("after rollback to") master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(50) master-bin.000001 # Xid # # COMMIT /* XID */ diff --git a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result index 7fc940f25e0..d076a24e1f0 100644 --- a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result +++ b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result @@ -997,7 +997,7 @@ master-bin.000001 # Query # # use `test_rpl`; INSERT INTO t1 VALUES (3, 'before master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # use `test_rpl`; INSERT INTO t1 VALUES (5, 'before savepoint s2') -master-bin.000001 # Query # # SAVEPOINT s2 +master-bin.000001 # Query # # SAVEPOINT `s2` master-bin.000001 # Query # # use `test_rpl`; INSERT INTO t1 VALUES (6, 'after savepoint s2') master-bin.000001 # Table_map # # table_id: # (test_rpl.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F diff --git a/sql/log.cc b/sql/log.cc index 156c293e3aa..503b3bb5cff 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1712,7 +1712,9 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv) String log_query; if (log_query.append(STRING_WITH_LEN("SAVEPOINT ")) || - log_query.append(thd->lex->ident.str, thd->lex->ident.length)) + log_query.append("`") || + log_query.append(thd->lex->ident.str, thd->lex->ident.length) || + log_query.append("`")) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(), @@ -1734,7 +1736,9 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) { String log_query; if (log_query.append(STRING_WITH_LEN("ROLLBACK TO ")) || - log_query.append(thd->lex->ident.str, thd->lex->ident.length)) + log_query.append("`") || + log_query.append(thd->lex->ident.str, thd->lex->ident.length) || + log_query.append("`")) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(), From d2d4fdb23f6b38ff6718a35120043627582ee836 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Tue, 7 Sep 2010 14:18:01 +0700 Subject: [PATCH 25/44] Fixed bug #47485 - mysql_store_result returns a not NULL result set for a prepared statement. include/mysql.h: enumerator MYSQL_STATUS_STATEMENT_GET_RESULT was added into mysql_status enum. include/mysql.h.pp: enumerator MYSQL_STATUS_STATEMENT_GET_RESULT was added into mysql_status enum. libmysql/libmysql.c: Introduce a separate mysql state to distinguish the situation when we have a binary result set pending on the server from the situation when the result set is in text protocol. execute() modified: if mysql->status == MYSQL_STATUS_GET_RESULT before return then set it to value MYSQL_STATUS_STATEMENT_GET_RESULT. stmt_read_row_unbuffered() and mysql_stmt_store_result() were modified: added checking for mysql->status against MYSQL_STATUS_STATEMENT_GET_RESULT value instead of MYSQL_STATUS_GET_RESULT. tests/mysql_client_test.c: added test_bug47485() --- include/mysql.h | 3 +- include/mysql.h.pp | 3 +- libmysql/libmysql.c | 6 ++- tests/mysql_client_test.c | 102 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index dcf3e167e6a..699bd1f1b7f 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -224,7 +224,8 @@ struct st_mysql_options { enum mysql_status { - MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT + MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT, + MYSQL_STATUS_STATEMENT_GET_RESULT }; enum mysql_protocol_type diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 0a397863022..ceb4b2d591c 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -293,7 +293,8 @@ struct st_mysql_options { }; enum mysql_status { - MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT + MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT, + MYSQL_STATUS_STATEMENT_GET_RESULT }; enum mysql_protocol_type { diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 362ad5de6c4..8c612b6894e 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2503,6 +2503,8 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) set_stmt_errmsg(stmt, net); DBUG_RETURN(1); } + else if (mysql->status == MYSQL_STATUS_GET_RESULT) + stmt->mysql->status= MYSQL_STATUS_STATEMENT_GET_RESULT; DBUG_RETURN(0); } @@ -2641,7 +2643,7 @@ static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row) set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL); return 1; } - if (mysql->status != MYSQL_STATUS_GET_RESULT) + if (mysql->status != MYSQL_STATUS_STATEMENT_GET_RESULT) { set_stmt_error(stmt, stmt->unbuffered_fetch_cancelled ? CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC, @@ -4847,7 +4849,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) DBUG_RETURN(1); } } - else if (mysql->status != MYSQL_STATUS_GET_RESULT) + else if (mysql->status != MYSQL_STATUS_STATEMENT_GET_RESULT) { set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL); DBUG_RETURN(1); diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 87c35666ac6..3bfcf3ee233 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -18297,6 +18297,107 @@ static void test_bug54041() } +/** + Bug#47485: mysql_store_result returns a result set for a prepared statement +*/ +static void test_bug47485() +{ + MYSQL_STMT *stmt; + MYSQL_RES *res; + MYSQL_BIND bind[2]; + int rc; + const char* sql_select = "SELECT 1, 'a'"; + int int_data; + char str_data[16]; + my_bool is_null[2]; + my_bool error[2]; + unsigned long length[2]; + + DBUG_ENTER("test_bug47485"); + myheader("test_bug47485"); + + stmt= mysql_stmt_init(mysql); + check_stmt(stmt); + rc= mysql_stmt_prepare(stmt, sql_select, strlen(sql_select)); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + res = mysql_store_result(mysql); + DIE_UNLESS(res == NULL); + + mysql_stmt_reset(stmt); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + res = mysql_use_result(mysql); + DIE_UNLESS(res == NULL); + + mysql_stmt_reset(stmt); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + bind[0].error= &error[0]; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].buffer_length= sizeof(str_data); + bind[1].is_null= &is_null[1]; + bind[1].length= &length[1]; + bind[1].error= &error[1]; + + rc= mysql_stmt_bind_result(stmt, bind); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_store_result(stmt); + check_execute(stmt, rc); + + while (!(rc= mysql_stmt_fetch(stmt))) + ; + + DIE_UNLESS(rc == MYSQL_NO_DATA); + + mysql_stmt_reset(stmt); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + bind[0].error= &error[0]; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].buffer_length= sizeof(str_data); + bind[1].is_null= &is_null[1]; + bind[1].length= &length[1]; + bind[1].error= &error[1]; + + rc= mysql_stmt_bind_result(stmt, bind); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + while (!(rc= mysql_stmt_fetch(stmt))) + ; + + DIE_UNLESS(rc == MYSQL_NO_DATA); + + mysql_stmt_close(stmt); + + DBUG_VOID_RETURN; +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -18622,6 +18723,7 @@ static struct my_tests_st my_tests[]= { { "test_bug44495", test_bug44495 }, { "test_bug42373", test_bug42373 }, { "test_bug54041", test_bug54041 }, + { "test_bug47485", test_bug47485 }, { 0, 0 } }; From 446cc653c0ab13a6fec8ab54de9f5596389b08bc Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Tue, 7 Sep 2010 09:58:05 +0200 Subject: [PATCH 26/44] Bug#54543: update ignore with incorrect subquery leads to assertion failure: inited==INDEX When an error occurs while sending the data in a temporary table there was no cleanup performed. This caused a failed assertion in the case when different access methods were used for populating the table vs. retrieving the data from the table if IGNORE was specified and sql_safe_updates = 0. In this case execution continues, but the handler expects to continue with the access method used for row retrieval. Fixed by doing the cleanup even if errors occur. --- mysql-test/r/multi_update.result | 20 ++++++++++++++++++++ mysql-test/t/multi_update.test | 21 +++++++++++++++++++++ sql/sql_select.cc | 18 ++++++++---------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index ae72f416c79..d77ad1d2953 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -639,4 +639,24 @@ SET SESSION sql_safe_updates = 1; UPDATE IGNORE t1, t1 t1a SET t1.a = 1 WHERE t1a.a = 1; ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column DROP TABLE t1; +# +# Bug#54543: update ignore with incorrect subquery leads to assertion +# failure: inited==INDEX +# +SET SESSION sql_safe_updates = 0; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1), (2); +CREATE TABLE t2 ( a INT ); +INSERT INTO t2 VALUES (1), (2); +CREATE TABLE t3 ( a INT ); +INSERT INTO t3 VALUES (1), (2); +# Should not crash +UPDATE IGNORE +( SELECT ( SELECT COUNT(*) FROM t1 GROUP BY a, @v ) a FROM t2 ) x, t3 +SET t3.a = 0; +Warnings: +Error 1242 Subquery returns more than 1 row +Error 1242 Subquery returns more than 1 row +DROP TABLE t1, t2, t3; +SET SESSION sql_safe_updates = DEFAULT; end of tests diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 559408eb90e..85d2ed19fda 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -651,5 +651,26 @@ SET SESSION sql_safe_updates = 1; UPDATE IGNORE t1, t1 t1a SET t1.a = 1 WHERE t1a.a = 1; DROP TABLE t1; +--echo # +--echo # Bug#54543: update ignore with incorrect subquery leads to assertion +--echo # failure: inited==INDEX +--echo # +SET SESSION sql_safe_updates = 0; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1), (2); + +CREATE TABLE t2 ( a INT ); +INSERT INTO t2 VALUES (1), (2); + +CREATE TABLE t3 ( a INT ); +INSERT INTO t3 VALUES (1), (2); + +--echo # Should not crash +UPDATE IGNORE + ( SELECT ( SELECT COUNT(*) FROM t1 GROUP BY a, @v ) a FROM t2 ) x, t3 +SET t3.a = 0; + +DROP TABLE t1, t2, t3; +SET SESSION sql_safe_updates = DEFAULT; --echo end of tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4a32ca34790..f550f75c8b8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -11157,22 +11157,20 @@ do_select(JOIN *join,List *fields,TABLE *table,Procedure *procedure) if (error == NESTED_LOOP_NO_MORE_ROWS) error= NESTED_LOOP_OK; + if (table == NULL) // If sending data to client + /* + The following will unlock all cursors if the command wasn't an + update command + */ + join->join_free(); // Unlock all cursors if (error == NESTED_LOOP_OK) { /* Sic: this branch works even if rc != 0, e.g. when send_data above returns an error. */ - if (!table) // If sending data to client - { - /* - The following will unlock all cursors if the command wasn't an - update command - */ - join->join_free(); // Unlock all cursors - if (join->result->send_eof()) - rc= 1; // Don't send error - } + if (table == NULL && join->result->send_eof()) // If sending data to client + rc= 1; // Don't send error DBUG_PRINT("info",("%ld records output", (long) join->send_records)); } else From d6f6db6f4cb02fb5a4c6225747af0673bd91ea94 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Tue, 7 Sep 2010 15:53:46 +0700 Subject: [PATCH 27/44] Fixed bug #55421 - Protocol::end_statement(): Assertion `0' on multi-table UPDATE IGNORE. The problem was that if there was an active SELECT statement during trigger execution, an error risen during the execution may cause a crash. The fix is to temporary reset LEX::current_select before trigger execution and restore it afterwards. This way errors risen during the trigger execution are processed as if there was no active SELECT. mysql-test/r/trigger_notembedded.result: added test case result for bug #55421. mysql-test/t/trigger_notembedded.test: added test case for bug #55421. sql/sql_trigger.cc: Reset thd->lex->current_select before start trigger execution and restore its original value after execution is finished. This is neccessery in order to set error status in diagnostic_area in case of trigger execution failure. --- mysql-test/r/trigger_notembedded.result | 21 +++++++++++ mysql-test/t/trigger_notembedded.test | 48 +++++++++++++++++++++++++ sql/sql_trigger.cc | 9 +++++ 3 files changed, 78 insertions(+) diff --git a/mysql-test/r/trigger_notembedded.result b/mysql-test/r/trigger_notembedded.result index d66308a9bd7..cba41660ced 100644 --- a/mysql-test/r/trigger_notembedded.result +++ b/mysql-test/r/trigger_notembedded.result @@ -474,4 +474,25 @@ SHOW CREATE TRIGGER db1.trg; ERROR 42000: Access denied; you need the TRIGGER privilege for this operation DROP USER 'no_rights'@'localhost'; DROP DATABASE db1; +DROP DATABASE IF EXISTS mysqltest_db1; +CREATE DATABASE mysqltest_db1; +USE mysqltest_db1; +GRANT ALL ON mysqltest_db1.* TO mysqltest_u1@localhost; +CREATE TABLE t1 ( +a1 int, +a2 int +); +INSERT INTO t1 VALUES (1, 20); +CREATE TRIGGER mysqltest_db1.upd_t1 +BEFORE UPDATE ON t1 FOR EACH ROW SET new.a2 = 200; +CREATE TABLE t2 ( +a1 int +); +INSERT INTO t2 VALUES (2); +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost; +UPDATE IGNORE t1, t2 SET t1.a1 = 2, t2.a1 = 3 WHERE t1.a1 = 1 AND t2.a1 = 2; +ERROR 42000: TRIGGER command denied to user 'mysqltest_u1'@'localhost' for table 't1' +DROP DATABASE mysqltest_db1; +DROP USER mysqltest_u1@localhost; +USE test; End of 5.1 tests. diff --git a/mysql-test/t/trigger_notembedded.test b/mysql-test/t/trigger_notembedded.test index 7a7e6c6bc85..387944ffb47 100644 --- a/mysql-test/t/trigger_notembedded.test +++ b/mysql-test/t/trigger_notembedded.test @@ -932,4 +932,52 @@ disconnect con1; DROP USER 'no_rights'@'localhost'; DROP DATABASE db1; +# +# Bug#55421 Protocol::end_statement(): Assertion `0' on multi-table UPDATE IGNORE +# To reproduce a crash we need to provoke a trigger execution with +# the following conditions: +# - active SELECT statement during trigger execution +# (i.e. LEX::current_select != NULL); +# - IGNORE option (i.e. LEX::current_select->no_error == TRUE); +--disable_warnings +DROP DATABASE IF EXISTS mysqltest_db1; +--enable_warnings + +CREATE DATABASE mysqltest_db1; +USE mysqltest_db1; + +GRANT ALL ON mysqltest_db1.* TO mysqltest_u1@localhost; + +--connect(con1,localhost,mysqltest_u1,,mysqltest_db1) + +CREATE TABLE t1 ( + a1 int, + a2 int +); +INSERT INTO t1 VALUES (1, 20); + +CREATE TRIGGER mysqltest_db1.upd_t1 +BEFORE UPDATE ON t1 FOR EACH ROW SET new.a2 = 200; + +CREATE TABLE t2 ( + a1 int +); + +INSERT INTO t2 VALUES (2); + +--connection default + +REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost; + +--error ER_TABLEACCESS_DENIED_ERROR +UPDATE IGNORE t1, t2 SET t1.a1 = 2, t2.a1 = 3 WHERE t1.a1 = 1 AND t2.a1 = 2; +# Cleanup + +DROP DATABASE mysqltest_db1; +DROP USER mysqltest_u1@localhost; + +--disconnect con1 +--connection default +USE test; + --echo End of 5.1 tests. diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index bf4a46a4c67..9348feaa22a 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1989,6 +1989,7 @@ bool Table_triggers_list::process_triggers(THD *thd, bool err_status; Sub_statement_state statement_state; sp_head *sp_trigger= bodies[event][time_type]; + SELECT_LEX *save_current_select; if (sp_trigger == NULL) return FALSE; @@ -2012,11 +2013,19 @@ bool Table_triggers_list::process_triggers(THD *thd, thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER); + /* + Reset current_select before call execute_trigger() and + restore it after return from one. This way error is set + in case of failure during trigger execution. + */ + save_current_select= thd->lex->current_select; + thd->lex->current_select= NULL; err_status= sp_trigger->execute_trigger(thd, &trigger_table->s->db, &trigger_table->s->table_name, &subject_table_grants[event][time_type]); + thd->lex->current_select= save_current_select; thd->restore_sub_statement_state(&statement_state); From 4f4d03a416f2a440d946bcdbc59cfaa99dd97aa4 Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Tue, 7 Sep 2010 11:21:09 +0200 Subject: [PATCH 28/44] Bug#51070: Query with a NOT IN subquery predicate returns a wrong result set The EXISTS transformation has additional switches to catch the known corner cases that appear when transforming an IN predicate into EXISTS. Guarded conditions are used which are deactivated when a NULL value is seen in the outer expression's row. When the inner query block supplies NULL values, however, they are filtered out because no distinction is made between the guarded conditions; guarded NOT x IS NULL conditions in the HAVING clause that filter out NULL values cannot be de-activated in isolation from those that match values or from the outer expression or NULL's. The above problem is handled by making the guarded conditions remember whether they have rejected a NULL value or not, and index access methods are taking this into account as well. The bug consisted of 1) Not resetting the property for every nested loop iteration on the inner query's result. 2) Not propagating the NULL result properly from inner query to IN optimizer. 3) A hack that may or may not have been needed at some point. According to a comment it was aimed to fix #2 by returning NULL when FALSE was actually the result. This caused failures when #2 was properly fixed. The hack is now removed. The fix resolves all three points. --- mysql-test/r/subselect4.result | 86 ++++++++++++++++++++++++++++++++++ mysql-test/t/subselect4.test | 62 ++++++++++++++++++++++++ sql/item_cmpfunc.cc | 79 +++++++++++++++++++++++++++++-- sql/item_subselect.cc | 48 ++++++++----------- 4 files changed, 243 insertions(+), 32 deletions(-) diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index fad65d3f000..63265970c4b 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -77,6 +77,92 @@ Note 1249 Select 2 was reduced during optimization CREATE VIEW v1 AS SELECT 1 LIKE ( 1 IN ( SELECT 1 ) ); CREATE VIEW v2 AS SELECT 1 LIKE '%' ESCAPE ( 1 IN ( SELECT 1 ) ); DROP VIEW v1, v2; +# +# Bug#51070: Query with a NOT IN subquery predicate returns a wrong +# result set +# +CREATE TABLE t1 ( a INT, b INT ); +INSERT INTO t1 VALUES ( 1, NULL ), ( 2, NULL ); +CREATE TABLE t2 ( c INT, d INT ); +INSERT INTO t2 VALUES ( NULL, 3 ), ( NULL, 4 ); +CREATE TABLE t3 ( e INT, f INT ); +INSERT INTO t3 VALUES ( NULL, NULL ), ( NULL, NULL ); +CREATE TABLE t4 ( a INT ); +INSERT INTO t4 VALUES (1), (2), (3); +CREATE TABLE t5 ( a INT ); +INSERT INTO t5 VALUES (NULL), (2); +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +x PRIMARY x x x x x x x x +x DEPENDENT SUBQUERY x x x x x x x x +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ); +a b +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL; +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE ( a, b ) IN ( SELECT c, d FROM t2 ) IS NULL; +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS UNKNOWN; +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE (( a, b ) NOT IN ( SELECT c, d FROM t2 )) IS UNKNOWN; +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE 1 = 1 AND ( a, b ) NOT IN ( SELECT c, d FROM t2 ); +a b +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 ); +id select_type table type possible_keys key key_len ref rows Extra +x PRIMARY x x x x x x x x +x DEPENDENT SUBQUERY x x x x x x x x +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 ); +a b +EXPLAIN +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +x PRIMARY x x x x x x x x +x DEPENDENT SUBQUERY x x x x x x x x +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 ); +c d +EXPLAIN +SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 ); +id select_type table type possible_keys key key_len ref rows Extra +x PRIMARY x x x x x x x x +x DEPENDENT SUBQUERY x x x x x x x x +SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 ); +e f +EXPLAIN +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 ); +id select_type table type possible_keys key key_len ref rows Extra +x PRIMARY x x x x x x x x +x DEPENDENT SUBQUERY x x x x x x x x +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 ); +c d +SELECT * FROM t1 WHERE ( a, b ) NOT IN +( SELECT c, d FROM t2 WHERE c = 1 AND c <> 1 ); +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE b NOT IN ( SELECT c FROM t2 WHERE c = 1 ); +a b +1 NULL +2 NULL +SELECT * FROM t1 WHERE NULL NOT IN ( SELECT c FROM t2 WHERE c = 1 AND c <> 1 ); +a b +1 NULL +2 NULL +DROP TABLE t1, t2, t3, t4, t5; # # End of 5.1 tests. # diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test index 2c6efdbaac2..eb8baf9bac8 100644 --- a/mysql-test/t/subselect4.test +++ b/mysql-test/t/subselect4.test @@ -74,6 +74,68 @@ CREATE VIEW v1 AS SELECT 1 LIKE ( 1 IN ( SELECT 1 ) ); CREATE VIEW v2 AS SELECT 1 LIKE '%' ESCAPE ( 1 IN ( SELECT 1 ) ); DROP VIEW v1, v2; +--echo # +--echo # Bug#51070: Query with a NOT IN subquery predicate returns a wrong +--echo # result set +--echo # +CREATE TABLE t1 ( a INT, b INT ); +INSERT INTO t1 VALUES ( 1, NULL ), ( 2, NULL ); + +CREATE TABLE t2 ( c INT, d INT ); +INSERT INTO t2 VALUES ( NULL, 3 ), ( NULL, 4 ); + +CREATE TABLE t3 ( e INT, f INT ); +INSERT INTO t3 VALUES ( NULL, NULL ), ( NULL, NULL ); + +CREATE TABLE t4 ( a INT ); +INSERT INTO t4 VALUES (1), (2), (3); + +CREATE TABLE t5 ( a INT ); +INSERT INTO t5 VALUES (NULL), (2); + +--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ); +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ); + +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL; +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS NULL; +SELECT * FROM t1 WHERE ( a, b ) IN ( SELECT c, d FROM t2 ) IS NULL; +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT c, d FROM t2 ) IS UNKNOWN; +SELECT * FROM t1 WHERE (( a, b ) NOT IN ( SELECT c, d FROM t2 )) IS UNKNOWN; + +SELECT * FROM t1 WHERE 1 = 1 AND ( a, b ) NOT IN ( SELECT c, d FROM t2 ); + +--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x +EXPLAIN +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 ); +SELECT * FROM t1 WHERE ( a, b ) NOT IN ( SELECT e, f FROM t3 ); + +--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x +EXPLAIN +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 ); +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT a, b FROM t1 ); + +--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x +EXPLAIN +SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 ); +SELECT * FROM t3 WHERE ( e, f ) NOT IN ( SELECT c, d FROM t2 ); + +--replace_column 1 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x +EXPLAIN +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 ); +SELECT * FROM t2 WHERE ( c, d ) NOT IN ( SELECT e, f FROM t3 ); + +SELECT * FROM t1 WHERE ( a, b ) NOT IN + ( SELECT c, d FROM t2 WHERE c = 1 AND c <> 1 ); + +SELECT * FROM t1 WHERE b NOT IN ( SELECT c FROM t2 WHERE c = 1 ); + +SELECT * FROM t1 WHERE NULL NOT IN ( SELECT c FROM t2 WHERE c = 1 AND c <> 1 ); + +DROP TABLE t1, t2, t3, t4, t5; + --echo # --echo # End of 5.1 tests. diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fe4616f64d7..605d12742f8 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1751,6 +1751,76 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) } +/** + The implementation of optimized \ [NOT] IN \ + predicates. The implementation works as follows. + + For the current value of the outer expression + + - If it contains only NULL values, the original (before rewrite by the + Item_in_subselect rewrite methods) inner subquery is non-correlated and + was previously executed, there is no need to re-execute it, and the + previous return value is returned. + + - If it contains NULL values, check if there is a partial match for the + inner query block by evaluating it. For clarity we repeat here the + transformation previously performed on the sub-query. The expression + + + ( oc_1, ..., oc_n ) + \ + ( SELECT ic_1, ..., ic_n + FROM \ + WHERE \ + ) + + + was transformed into + + + ( oc_1, ..., oc_n ) + \ + ( SELECT ic_1, ..., ic_n + FROM \ + WHERE \ AND ... ( ic_k = oc_k OR ic_k IS NULL ) + HAVING ... NOT ic_k IS NULL + ) + + + The evaluation will now proceed according to special rules set up + elsewhere. These rules include: + + - The HAVING NOT \ IS NULL conditions added by the + aforementioned rewrite methods will detect whether they evaluated (and + rejected) a NULL value and if so, will cause the subquery to evaluate + to NULL. + + - The added WHERE and HAVING conditions are present only for those inner + columns that correspond to outer column that are not NULL at the moment. + + - If there is an eligible index for executing the subquery, the special + access method "Full scan on NULL key" is employed which ensures that + the inner query will detect if there are NULL values resulting from the + inner query. This access method will quietly resort to table scan if it + needs to find NULL values as well. + + - Under these conditions, the sub-query need only be evaluated in order to + find out whether it produced any rows. + + - If it did, we know that there was a partial match since there are + NULL values in the outer row expression. + + - If it did not, the result is FALSE or UNKNOWN. If at least one of the + HAVING sub-predicates rejected a NULL value corresponding to an outer + non-NULL, and hence the inner query block returns UNKNOWN upon + evaluation, there was a partial match and the result is UNKNOWN. + + - If it contains no NULL values, the call is forwarded to the inner query + block. + + @see Item_in_subselect::val_bool() + @see Item_is_not_null_test::val_int() + */ longlong Item_in_optimizer::val_int() { bool tmp; @@ -1804,7 +1874,7 @@ longlong Item_in_optimizer::val_int() all_left_cols_null= false; } - if (!((Item_in_subselect*)args[1])->is_correlated && + if (!item_subs->is_correlated && all_left_cols_null && result_for_null_param != UNKNOWN) { /* @@ -1818,8 +1888,11 @@ longlong Item_in_optimizer::val_int() else { /* The subquery has to be evaluated */ - (void) args[1]->val_bool_result(); - null_value= !item_subs->engine->no_rows(); + (void) item_subs->val_bool_result(); + if (item_subs->engine->no_rows()) + null_value= item_subs->null_value; + else + null_value= TRUE; if (all_left_cols_null) result_for_null_param= null_value; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index b93ea6f241b..d0c933df845 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -47,7 +47,7 @@ Item_subselect::Item_subselect(): item value is NULL if select_subselect not changed this value (i.e. some rows will be found returned) */ - null_value= 1; + null_value= TRUE; } @@ -427,9 +427,9 @@ void Item_maxmin_subselect::print(String *str, enum_query_type query_type) void Item_singlerow_subselect::reset() { - null_value= 1; + null_value= TRUE; if (value) - value->null_value= 1; + value->null_value= TRUE; } @@ -574,7 +574,7 @@ double Item_singlerow_subselect::val_real() DBUG_ASSERT(fixed == 1); if (!exec() && !value->null_value) { - null_value= 0; + null_value= FALSE; return value->val_real(); } else @@ -589,7 +589,7 @@ longlong Item_singlerow_subselect::val_int() DBUG_ASSERT(fixed == 1); if (!exec() && !value->null_value) { - null_value= 0; + null_value= FALSE; return value->val_int(); } else @@ -603,7 +603,7 @@ String *Item_singlerow_subselect::val_str(String *str) { if (!exec() && !value->null_value) { - null_value= 0; + null_value= FALSE; return value->val_str(str); } else @@ -618,7 +618,7 @@ my_decimal *Item_singlerow_subselect::val_decimal(my_decimal *decimal_value) { if (!exec() && !value->null_value) { - null_value= 0; + null_value= FALSE; return value->val_decimal(decimal_value); } else @@ -633,7 +633,7 @@ bool Item_singlerow_subselect::val_bool() { if (!exec() && !value->null_value) { - null_value= 0; + null_value= FALSE; return value->val_bool(); } else @@ -651,7 +651,7 @@ Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): bool val_bool(); init(select_lex, new select_exists_subselect(this)); max_columns= UINT_MAX; - null_value= 0; //can't be NULL + null_value= FALSE; //can't be NULL maybe_null= 0; //can't be NULL value= 0; DBUG_VOID_RETURN; @@ -814,15 +814,14 @@ double Item_in_subselect::val_real() */ DBUG_ASSERT(0); DBUG_ASSERT(fixed == 1); - null_value= 0; + null_value= was_null= FALSE; if (exec()) { reset(); - null_value= 1; return 0; } if (was_null && !value) - null_value= 1; + null_value= TRUE; return (double) value; } @@ -835,15 +834,14 @@ longlong Item_in_subselect::val_int() */ DBUG_ASSERT(0); DBUG_ASSERT(fixed == 1); - null_value= 0; + null_value= was_null= FALSE; if (exec()) { reset(); - null_value= 1; return 0; } if (was_null && !value) - null_value= 1; + null_value= TRUE; return value; } @@ -856,16 +854,15 @@ String *Item_in_subselect::val_str(String *str) */ DBUG_ASSERT(0); DBUG_ASSERT(fixed == 1); - null_value= 0; + null_value= was_null= FALSE; if (exec()) { reset(); - null_value= 1; return 0; } if (was_null && !value) { - null_value= 1; + null_value= TRUE; return 0; } str->set((ulonglong)value, &my_charset_bin); @@ -876,20 +873,14 @@ String *Item_in_subselect::val_str(String *str) bool Item_in_subselect::val_bool() { DBUG_ASSERT(fixed == 1); - null_value= 0; + null_value= was_null= FALSE; if (exec()) { reset(); - /* - Must mark the IN predicate as NULL so as to make sure an enclosing NOT - predicate will return FALSE. See the comments in - subselect_uniquesubquery_engine::copy_ref_key for further details. - */ - null_value= 1; return 0; } if (was_null && !value) - null_value= 1; + null_value= TRUE; return value; } @@ -900,16 +891,15 @@ my_decimal *Item_in_subselect::val_decimal(my_decimal *decimal_value) method should not be used */ DBUG_ASSERT(0); - null_value= 0; + null_value= was_null= FALSE; DBUG_ASSERT(fixed == 1); if (exec()) { reset(); - null_value= 1; return 0; } if (was_null && !value) - null_value= 1; + null_value= TRUE; int2my_decimal(E_DEC_FATAL_ERROR, value, 0, decimal_value); return decimal_value; } From af951a6c368a234d9521cb1afc347fd53fae141e Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 7 Sep 2010 17:56:43 +0200 Subject: [PATCH 29/44] Bug#55458: Partitioned MyISAM table gets crashed by multi-table update Updated according to reviewers comments. --- sql/ha_partition.cc | 40 ++++++++++++++++++++++++++++------------ sql/ha_partition.h | 2 ++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 3d3ae33be4b..4fff6cc703c 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -233,6 +233,7 @@ void ha_partition::init_handler_variables() m_extra_cache= FALSE; m_extra_cache_size= 0; m_extra_prepare_for_update= FALSE; + m_extra_cache_part_id= NO_CURRENT_PART_ID; m_handler_status= handler_not_initialized; m_low_byte_first= 1; m_part_field_array= NULL; @@ -5376,9 +5377,6 @@ void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info, when performing the sequential scan we will check this recorded value and call extra_opt whenever we start scanning a new partition. - monty: Neads to be fixed so that it's passed to all handlers when we - move to another partition during table scan. - HA_EXTRA_NO_CACHE: When performing a UNION SELECT HA_EXTRA_NO_CACHE is called from the flush method in the select_union class. @@ -5390,7 +5388,7 @@ void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info, for. If no cache is in use they will quickly return after finding this out. And we also ensure that all caches are disabled and no one is left by mistake. - In the future this call will probably be deleted an we will instead call + In the future this call will probably be deleted and we will instead call ::reset(); HA_EXTRA_WRITE_CACHE: @@ -5402,8 +5400,9 @@ void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info, This is called as part of a multi-table update. When the table to be updated is also scanned then this informs MyISAM handler to drop any caches if dynamic records are used (fixed size records do not care - about this call). We pass this along to all underlying MyISAM handlers - and ignore it for the rest. + about this call). We pass this along to the first partition to scan, and + flag that it is to be called after HA_EXTRA_CACHE when moving to the next + partition to scan. HA_EXTRA_PREPARE_FOR_DROP: Only used by MyISAM, called in preparation for a DROP TABLE. @@ -5559,6 +5558,7 @@ int ha_partition::extra(enum ha_extra_function operation) m_extra_prepare_for_update= TRUE; if (m_part_spec.start_part != NO_CURRENT_PART_ID) { + DBUG_ASSERT(m_extra_cache_part_id == m_part_spec.start_part); VOID(m_file[m_part_spec.start_part]->extra(HA_EXTRA_PREPARE_FOR_UPDATE)); } break; @@ -5586,11 +5586,22 @@ int ha_partition::extra(enum ha_extra_function operation) break; } case HA_EXTRA_NO_CACHE: + { + int ret= 0; + if (m_extra_cache_part_id != NO_CURRENT_PART_ID) + ret= m_file[m_extra_cache_part_id]->extra(HA_EXTRA_NO_CACHE); + m_extra_cache= FALSE; + m_extra_cache_size= 0; + m_extra_prepare_for_update= FALSE; + m_extra_cache_part_id= NO_CURRENT_PART_ID; + DBUG_RETURN(ret); + } case HA_EXTRA_WRITE_CACHE: { m_extra_cache= FALSE; m_extra_cache_size= 0; m_extra_prepare_for_update= FALSE; + m_extra_cache_part_id= NO_CURRENT_PART_ID; DBUG_RETURN(loop_extra(operation)); } case HA_EXTRA_IGNORE_NO_KEY: @@ -5777,16 +5788,18 @@ int ha_partition::loop_extra(enum ha_extra_function operation) { int result= 0, tmp; handler **file; + bool is_select; DBUG_ENTER("ha_partition::loop_extra()"); - /* - TODO, 5.2: this is where you could possibly add optimisations to add the bitmap - _if_ a SELECT. - */ + is_select= (thd_sql_command(ha_thd()) == SQLCOM_SELECT); for (file= m_file; *file; file++) { - if ((tmp= (*file)->extra(operation))) - result= tmp; + if (!is_select || + bitmap_is_set(&(m_part_info->used_partitions), file - m_file)) + { + if ((tmp= (*file)->extra(operation))) + result= tmp; + } } DBUG_RETURN(result); } @@ -5822,6 +5835,7 @@ void ha_partition::late_extra_cache(uint partition_id) DBUG_ASSERT(m_extra_cache); VOID(file->extra(HA_EXTRA_PREPARE_FOR_UPDATE)); } + m_extra_cache_part_id= partition_id; DBUG_VOID_RETURN; } @@ -5846,6 +5860,8 @@ void ha_partition::late_extra_no_cache(uint partition_id) DBUG_VOID_RETURN; file= m_file[partition_id]; VOID(file->extra(HA_EXTRA_NO_CACHE)); + DBUG_ASSERT(partition_id == m_extra_cache_part_id); + m_extra_cache_part_id= NO_CURRENT_PART_ID; DBUG_VOID_RETURN; } diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 013341e4df3..feb2ddb9cfc 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -156,6 +156,8 @@ private: uint m_extra_cache_size; /* The same goes for HA_EXTRA_PREPARE_FOR_UPDATE */ bool m_extra_prepare_for_update; + /* Which partition has active cache */ + uint m_extra_cache_part_id; void init_handler_variables(); /* From 95362e0da87951f921e0700cd1237d00e52405fc Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 9 Sep 2010 19:36:57 +0700 Subject: [PATCH 30/44] Fix mysql_client_test failure introduced by a patch for Bug#47485. The problem was that mysql_stmt_next_result() (new to 5.5) was not properly updated. libmysql/libmysql.c: mysql_stmt_next_result() modified: set mysql->status= MYSQL_STATUS_STATEMENT_GET_RESULT before return if there is a result set. --- libmysql/libmysql.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 231b6e2ef76..a44395578c6 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4874,6 +4874,9 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) DBUG_RETURN(rc); } + if (mysql->status == MYSQL_STATUS_GET_RESULT) + mysql->status= MYSQL_STATUS_STATEMENT_GET_RESULT; + stmt->state= MYSQL_STMT_EXECUTE_DONE; stmt->bind_result_done= FALSE; From 453107bc561338e0764443561a11d05dbe6486ee Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Thu, 9 Sep 2010 16:46:13 +0400 Subject: [PATCH 31/44] Bug #54190: Comparison to row subquery produces incorrect result Row subqueries producing no rows were not handled as UNKNOWN values in row comparison expressions. That was a result of the following two problems: 1. Item_singlerow_subselect did not mark the resulting row value as NULL/UNKNOWN when no rows were produced. 2. Arg_comparator::compare_row() did not take into account that a whole argument may be NULL rather than just individual scalar values. Before bug#34384 was fixed, the above problems were hidden because an uninitialized (i.e. without any stored value) cached object would appear as NULL for scalar values in a row subquery returning an empty result. After the fix Arg_comparator::compare_row() would try to evaluate uninitialized cached objects. Fixed by removing the aforementioned problems. mysql-test/r/row.result: Added a test case for bug #54190. mysql-test/r/subselect.result: Updated the result for a test relying on wrong behavior. mysql-test/t/row.test: Added a test case for bug #54190. sql/item_cmpfunc.cc: If either of the argument rows is NULL, return NULL as the result of comparison. sql/item_subselect.cc: Adjust null_value for Item_singlerow_subselect depending on whether a row has been produced by the row subquery. --- mysql-test/r/row.result | 23 +++++++++++++++++++++++ mysql-test/r/subselect.result | 4 ++-- mysql-test/t/row.test | 19 +++++++++++++++++++ sql/item_cmpfunc.cc | 7 +++++++ sql/item_subselect.cc | 5 ++++- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/row.result b/mysql-test/r/row.result index 2962123fcb2..789b9c4f383 100644 --- a/mysql-test/r/row.result +++ b/mysql-test/r/row.result @@ -466,3 +466,26 @@ SELECT 1 FROM t1 WHERE ROW(a, b) >= ROW('1', (SELECT 1 FROM t1 WHERE a > 1234)); 1 DROP TABLE t1; +# +# Bug #54190: Comparison to row subquery produces incorrect result +# +SELECT ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0); +ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0) +NULL +SELECT ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0); +ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0) +NULL +CREATE TABLE t1 (i INT); +INSERT INTO t1 () VALUES (1), (2), (3); +SELECT ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0); +ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0) +NULL +SELECT ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0); +ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0) +NULL +SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0); +i +SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0); +i +DROP TABLE t1; +End of 5.1 tests diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 47a89897daf..dc40e42275b 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -922,7 +922,7 @@ select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a) 1 1 a 2 0 b -NULL 0 NULL +NULL NULL NULL select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2; a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a) 1 0 a @@ -932,7 +932,7 @@ select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a) 1 0 a 2 0 b -NULL 0 NULL +NULL NULL NULL drop table t1,t2; create table t1 (a int, b real, c varchar(10)); insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b'); diff --git a/mysql-test/t/row.test b/mysql-test/t/row.test index cec44078279..fb49ce23644 100644 --- a/mysql-test/t/row.test +++ b/mysql-test/t/row.test @@ -266,3 +266,22 @@ SELECT 1 FROM t1 WHERE ROW(a, b) >= ROW('1', (SELECT 1 FROM t1 WHERE a > 1234)); --enable_warnings DROP TABLE t1; + +--echo # +--echo # Bug #54190: Comparison to row subquery produces incorrect result +--echo # + +SELECT ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0); +SELECT ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0); + +CREATE TABLE t1 (i INT); +INSERT INTO t1 () VALUES (1), (2), (3); + +SELECT ROW(1,2) = (SELECT 1,2 FROM t1 WHERE 1 = 0); +SELECT ROW(1,2) = (SELECT 1,3 FROM t1 WHERE 1 = 0); +SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,2 FROM DUAL WHERE 1 = 0); +SELECT i FROM t1 WHERE ROW(1,2) = (SELECT 1,3 FROM DUAL WHERE 1 = 0); + +DROP TABLE t1; + +--echo End of 5.1 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fe4616f64d7..b2ed2df0f45 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1583,6 +1583,13 @@ int Arg_comparator::compare_row() bool was_null= 0; (*a)->bring_value(); (*b)->bring_value(); + + if ((*a)->null_value || (*b)->null_value) + { + owner->null_value= 1; + return -1; + } + uint n= (*a)->cols(); for (uint i= 0; i Date: Thu, 9 Sep 2010 18:44:53 +0400 Subject: [PATCH 32/44] Addendum patch for bug #54190. The patch caused some test failures when merged to 5.5 because, unlike 5.1, it utilizes Item_cache_row to actually cache row values. The problem was that Item_cache_row::bring_value() essentially did nothing. In particular, it did not update its null_value, so all Item_cache_row objects were always having their null_values set to TRUE. This went unnoticed previously, but now when Arg_comparator::compare_row() actually depends on the row's null_value to evaluate the comparison, the problem has surfaced. Fixed by calling the underlying item's bring_value() and updating null_value in Item_cache_row::bring_value(). Since the problem also exists in 5.1 code (albeit hidden, since the relevant code is not used anywhere), the addendum patch is against 5.1. --- sql/item.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sql/item.cc b/sql/item.cc index 66c5314c16e..29529abe7b9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7404,9 +7404,12 @@ bool Item_cache_row::null_inside() void Item_cache_row::bring_value() { + if (!example) + return; + example->bring_value(); + null_value= example->null_value; for (uint i= 0; i < item_count; i++) values[i]->bring_value(); - return; } From daa6d1f4f322b1ceaa2fbbdeef76bbbd0b30dab1 Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Mon, 13 Sep 2010 11:18:35 +0400 Subject: [PATCH 33/44] Bug #55779: select does not work properly in mysql server Version "5.1.42 SUSE MySQL RPM" When a query was using a DATE or DATETIME value formatted using different formatting than "yyyy-mm-dd HH:MM:SS", a query with a greater-or-equal '>=' condition matched only greater values in an indexed TIMESTAMP column. The problem was introduced by the fix for the bug 46362 and partially solved (for DATE and DATETIME columns only) by the fix for the bug 47925. The stored_field_cmp_to_item function has been modified to take into account TIMESTAMP columns like we do for DATE and DATETIME columns. mysql-test/r/type_timestamp.result: Test case for bug #55779. mysql-test/t/type_timestamp.test: Test case for bug #55779. sql/item.cc: Bug #55779: select does not work properly in mysql server Version "5.1.42 SUSE MySQL RPM" The stored_field_cmp_to_item function has been modified to take into account TIMESTAMP columns like we do for DATE and DATETIME. --- mysql-test/r/type_timestamp.result | 21 +++++++++++++++++++++ mysql-test/t/type_timestamp.test | 17 +++++++++++++++++ sql/item.cc | 6 ++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index e26c2e68775..e88d3462466 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -527,3 +527,24 @@ f1 f2-f3 5 0 DROP TABLE t1; End of 5.0 tests +# +# Bug #55779: select does not work properly in mysql server +# Version "5.1.42 SUSE MySQL RPM" +# +CREATE TABLE t1 (a TIMESTAMP, KEY (a)); +INSERT INTO t1 VALUES ('2000-01-01 00:00:00'), ('2000-01-01 00:00:00'), +('2000-01-01 00:00:01'), ('2000-01-01 00:00:01'); +SELECT a FROM t1 WHERE a >= 20000101000000; +a +2000-01-01 00:00:00 +2000-01-01 00:00:00 +2000-01-01 00:00:01 +2000-01-01 00:00:01 +SELECT a FROM t1 WHERE a >= '20000101000000'; +a +2000-01-01 00:00:00 +2000-01-01 00:00:00 +2000-01-01 00:00:01 +2000-01-01 00:00:01 +DROP TABLE t1; +End of 5.1 tests diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index e8374e0ebfc..602f6f089c2 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -357,3 +357,20 @@ SELECT f1,f2-f3 FROM t1; DROP TABLE t1; --echo End of 5.0 tests + +--echo # +--echo # Bug #55779: select does not work properly in mysql server +--echo # Version "5.1.42 SUSE MySQL RPM" +--echo # + +CREATE TABLE t1 (a TIMESTAMP, KEY (a)); + +INSERT INTO t1 VALUES ('2000-01-01 00:00:00'), ('2000-01-01 00:00:00'), + ('2000-01-01 00:00:01'), ('2000-01-01 00:00:01'); + +SELECT a FROM t1 WHERE a >= 20000101000000; +SELECT a FROM t1 WHERE a >= '20000101000000'; + +DROP TABLE t1; + +--echo End of 5.1 tests diff --git a/sql/item.cc b/sql/item.cc index 29529abe7b9..61dd8a97dcb 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6970,14 +6970,16 @@ int stored_field_cmp_to_item(THD *thd, Field *field, Item *item) enum_field_types field_type= field->type(); - if (field_type == MYSQL_TYPE_DATE || field_type == MYSQL_TYPE_DATETIME) + if (field_type == MYSQL_TYPE_DATE || field_type == MYSQL_TYPE_DATETIME || + field_type == MYSQL_TYPE_TIMESTAMP) { enum_mysql_timestamp_type type= MYSQL_TIMESTAMP_ERROR; if (field_type == MYSQL_TYPE_DATE) type= MYSQL_TIMESTAMP_DATE; - if (field_type == MYSQL_TYPE_DATETIME) + if (field_type == MYSQL_TYPE_DATETIME || + field_type == MYSQL_TYPE_TIMESTAMP) type= MYSQL_TIMESTAMP_DATETIME; const char *field_name= field->field_name; From 3beeb5d045241afb9d3733fba8dd4ec6e5b9dd86 Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Mon, 13 Sep 2010 13:33:19 +0200 Subject: [PATCH 34/44] Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and ORDER BY computed col GROUP BY implies ORDER BY in the MySQL dialect of SQL. Therefore, when an index on the first table in the query is used, and that index satisfies ordering according to the GROUP BY clause, the query optimizer estimates the number of tuples that need to be read from this index. If there is a LIMIT clause, table statistics on tables following this 'sort table' are employed. There may be a separate ORDER BY clause however, which mandates reading the whole 'sort table' anyway. But the previous estimate was left untouched. Fixed by removing the estimate from EXPLAIN output if GROUP BY is used in conjunction with an ORDER BY clause that mandates using a temporary table. --- mysql-test/r/order_by.result | 21 +++++++++++++++++++++ mysql-test/t/order_by.test | 25 +++++++++++++++++++++++++ sql/sql_select.cc | 9 +++++++++ 3 files changed, 55 insertions(+) diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 6827fd0bc76..ba639fa9763 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -1617,4 +1617,25 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 5 NULL 2 Using where; Using temporary; Using filesort 1 SIMPLE t2 ALL NULL NULL NULL NULL 10 Using join buffer DROP TABLE t1, t2; +# +# Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and +# ORDER BY computed col +# +CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, KEY( a, b ) ); +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +INSERT INTO t1 SELECT a + 5, b + 5 FROM t1; +CREATE TABLE t2( a INT PRIMARY KEY, b INT ); +INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +INSERT INTO t2 SELECT a + 5, b + 5 FROM t2; +EXPLAIN +SELECT count(*) AS c, t1.a +FROM t1 JOIN t2 ON t1.b = t2.a +WHERE t2.b = 1 +GROUP BY t1.a +ORDER by c +LIMIT 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL a 8 NULL 10 Using index; Using temporary; Using filesort +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 Using where +DROP TABLE t1, t2; End of 5.1 tests diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 36b6015c5d8..a8a6ad00648 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -1467,4 +1467,29 @@ SELECT * FROM t1 FORCE INDEX FOR JOIN (a), t2 WHERE t1.a < 2 ORDER BY t1.a; DROP TABLE t1, t2; +--echo # +--echo # Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and +--echo # ORDER BY computed col +--echo # +CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, KEY( a, b ) ); + +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +INSERT INTO t1 SELECT a + 5, b + 5 FROM t1; + +CREATE TABLE t2( a INT PRIMARY KEY, b INT ); + +INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +INSERT INTO t2 SELECT a + 5, b + 5 FROM t2; + +EXPLAIN +SELECT count(*) AS c, t1.a +FROM t1 JOIN t2 ON t1.b = t2.a +WHERE t2.b = 1 +GROUP BY t1.a +ORDER by c +LIMIT 2; + +DROP TABLE t1, t2; + + --echo End of 5.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f550f75c8b8..605819a1646 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1486,6 +1486,15 @@ JOIN::optimize() } if (order) { + /* + Do we need a temporary table due to the ORDER BY not being equal to + the GROUP BY? The call to test_if_skip_sort_order above tests for the + GROUP BY clause only and hence is not valid in this case. So the + estimated number of rows to be read from the first table is not valid. + We clear it here so that it doesn't show up in EXPLAIN. + */ + if (need_tmp && (select_options & SELECT_DESCRIBE) != 0) + join_tab[const_tables].limit= 0; /* Force using of tmp table if sorting by a SP or UDF function due to their expensive and probably non-deterministic nature. From 0876ef05131461c4fcaad9e656dfcb4a3626e33b Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Thu, 16 Sep 2010 08:53:58 +0200 Subject: [PATCH 35/44] Updated build_mccge.sh and added support for more cpu's in check-cpu --- BUILD/build_mccge.sh | 633 ++++++++++++++++++++++++++++++++----------- BUILD/check-cpu | 58 +++- 2 files changed, 523 insertions(+), 168 deletions(-) diff --git a/BUILD/build_mccge.sh b/BUILD/build_mccge.sh index eb37323c570..e5e0d5da01b 100755 --- a/BUILD/build_mccge.sh +++ b/BUILD/build_mccge.sh @@ -63,41 +63,50 @@ sysadmin_usage() cat < ./build_mccge.sh + shell> BUILD/build_mccge.sh This performs the following operations: 1) Detects the operating system. Currently, Linux, FreeBSD, Solaris - 10/11, and Mac OS X are supported by this script. + 8/9/10/11, and Mac OS X are supported by this script. 2) Detect the type of CPU being used. Currently supported processors are: x86 for all supported operating systems, Itanium for Linux - with GCC, and SPARC for Solaris using the Forte compiler. + with GCC, and x86 + SPARC for Solaris using the Forte compiler and + finally x86 on Linux using the Intel compiler. 3) Invokes the GCC compiler. - 4) Builds a set of MySQL Cluster Carrier Grade Edition binaries; for + 4) Builds a set of MySQL/MySQL Cluster binaries; for more information about these, see --extended-help. + 5) Default compiler is always gcc. The default version assumes that you have a source code tarball from which you are building, and thus autoconf and automake do not need to be run. If you have downloaded a BitKeeper tree then you should read --developer-help. - If you are building MySQL Cluster Carrier Grade Edition for commercial + If you are building MySQL/MySQL Cluster for commercial use then you need to set the --commercial flag to ensure that the commercial libraries are compiled in, rather than the GPL-only libraries. The default is to build a GPL version of MySQL Cluster Carrier Grade Edition. - If your building on a Solaris SPARC machine you must set + If your building on a Solaris SPARC machine and you want to compile + using SunStudio you must set --compiler=forte; if you want to build using the Intel compiler on Linux, you need to set --compiler=icc. + A synonym for forte is SunStudio, so one can also use + --compiler=SunStudio. + If you want to make sure that a 64-bit version is built then you should add the flag --64. This is always set on Solaris machines and when check-cpu is able to discover that a 64-bit CPU is being used. If @@ -120,7 +129,7 @@ cat < 32-bit binary - x86_64 => 64 bit binary unless Mac OS X + --compiler=[gcc|icc|forte|SunStudio] Select compiler + --cpu=[x86|x86_64|sparc|itanium] Select CPU type + x86 => x86 and 32-bit binary + x86_64 => x86 and 64 bit binary --warning-mode=[extra|pedantic|normal|no] Set warning mode level --warnings Set warning mode to normal --32 Build a 32-bit binary even if CPU is 64-bit @@ -170,8 +186,9 @@ Usage: $0 [options] --error-inject Enable error injection into MySQL Server and data nodes --valgrind Build with valgrind - --fast Optimise for CPU architecture buildt on + --fast Optimise for CPU architecture built on --static-linking Statically link system libraries into binaries + --use-tcmalloc Link with tcmalloc instead of standard malloc (Linux only) --with-flags * Pass extra --with-xxx options to configure EOF if test "x$1" != "x" ; then @@ -186,13 +203,14 @@ extended_usage() Extended help text for this script: ----------------------------------- This script is intended to make it easier for customers using MySQL - Cluster Carrier Grade Edition to build the product from source on - these platforms/compilers: Linux/x86 (32-bit and 64-bit), - Solaris 10 and 11/x86/gcc, Solaris 9/Sparc/Forte, and MacOSX/x86/gcc. - The script automatically detects CPU type and operating system; in - most cases this also determines which compiler to use, the exception - being Linux/x86 where you can choose between gcc and icc (gcc is the - default). + Cluster Carrier Grade Edition, customers using performance-optimised + MySQL versions and developers to build the product from source on + these platforms/compilers: Linux/x86 (32-bit and 64-bit) (either using + gcc or icc), Linux Itanium, Solaris 8,9,10 and 11 x86 and SPARC using + gcc or SunStudio and MacOSX/x86/gcc. + + The script automatically detects CPU type and operating system; The + default compiler is always gcc. To build on other platforms you can use the --print-only option on a supported platform and edit the output for a proper set of commands on @@ -213,7 +231,7 @@ extended_usage() --package=cge storage engines: - ARCHIVE, BLACKHOLE, CSV, EXAMPLE, FEDERATED, MYISAM, NDB + ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, NDB (All storage engines except InnoDB) comment: MySQL Cluster Carrier Grade Edition GPL/Commercial version built from source @@ -221,7 +239,7 @@ extended_usage() --package=extended storage engines: - ARCHIVE, BLACKHOLE, CSV, EXAMPLE, FEDERATED, MYISAM, INNODB, NDB + ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, INNODB, NDB (All storage engines) comment: MySQL Cluster Carrier Grade Extended Edition GPL/Commercial version built from source @@ -229,7 +247,7 @@ extended_usage() --package=pro storage engines: - ARCHIVE, BLACKHOLE, CSV, EXAMPLE, FEDERATED, INNODB, MYISAM + ARCHIVE, BLACKHOLE, CSV, FEDERATED, INNODB, MYISAM (All storage engines except NDB) comment: MySQL Pro GPL/Commercial version built from source @@ -291,11 +309,16 @@ extended_usage() by MySQL (cannot be overridden). --with-ssl: Enable use of yaSSL library included in the MySQL source + if possible (GCC and same CC and CXX). (cannot be overridden). --with-pic: Build all binaries using position independent assembler to avoid problems with dynamic linkers (cannot be overridden). + --without-example-engine: Ensure that the example engine isn't built, + it cannot do any useful things, it's merely intended as documentation. + (cannot be overridden) + --with-csv-storage-engine: Ensure that the CSV storage engine is included in all builds. Since CSV is required for log tables in MySQL 5.1, this option cannot be overridden. @@ -314,10 +337,6 @@ extended_usage() In addition there are some configure options that are specific to Linux operating systems: - --with-fast-mutexes - Include an alternative implementation of mutexes that is faster on - Linux systems - --enable-assembler Include assembler code optimisations for a number of mostly string methods. Used for x86 processors only. @@ -364,17 +383,24 @@ extended_usage() --with-mysqld-libs=-lmtmalloc Used on Solaris to ensure that the proper malloc library is used. + Investigations have shown mtmalloc to be the best choice on Solaris, + also umem has good performance on Solaris but better debugging + capabilities. Compiler options: ----------------- - This section describes the compiler options for each of the different - platforms supported by thisscript. + This section describes the compiler options for each of the different + platforms supported by this script. - The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides - support for Nocona, K8, and other processors). + The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides + support for Nocona, K8, and other processors). - Use of the --debug option adds -g to the C/C++ flags. + Use of the --debug option adds -g to the C/C++ flags. + + In all cases it is possible to override the definition of CC and CXX + by calling the script as follows: + CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh FreeBSD/x86/gcc --------------- @@ -383,8 +409,7 @@ extended_usage() Linux/x86+Itanium/gcc ------------- - No flags are used. Instead the configure script determines the - proper flags to use for both normal and debug builds. Discovery of a + For debug builds -O is used and otherwise -O3 is used.Discovery of a Nocona or Core 2 Duo CPU causes a 64-bit binary to be built; otherwise, the binary is 32-bit. To build a 64-bit binary, -m64 is added to the C/C++ flags. (To build a 32-bit binary on a 64-bit CPU, @@ -393,48 +418,105 @@ extended_usage() Linux/x86+Itanium/icc ------------- Flags used: - CC = icc -static-libgcc -static-libcxa -i-static - C++ = icpc -static-libgcc -static-libcxa -i-static + CC = icc -static-libgcc -static-intel + C++ = icpc -static-libgcc -static-intel C/C++ flags = -mp -restrict - On Itanium we also add -no-ftz and -no-prefetch to CC and C++ flags. + On Itanium we also add -no-ftz and to CC and C++ flags. - The non-debug versions also add the following: - C/C++ flags += -O3 unroll2 -ip + Note that if the user of this script sets CC or CXX explicitly then + also -static-libgcc and -static-intel needs to be set in the CC and + CXX. - The fast version adds: - C/C++ flags += -ipo + The non-debug versions also add the following: + C/C++ flags += -O3 unroll2 -ip - On discovery of a Core 2 Duo architecture while using icc, -xT is also - added to the C/C++ flags; this provides optimisations specific to Core - 2 Duo. This is added only when the --fast flag is set. + The fast version adds (if --with-link-time-optimizer is used): + C/C++ flags += -ipo + + On discovery of a Core 2 Duo architecture while using icc, -xT is also + added to the C/C++ flags; this provides optimisations specific to Core + 2 Duo. This is added only when the --fast flag is set. Solaris/x86/gcc --------------- - All builds on Solaris are 64-bit, so -m64 is always used in the - C/C++ flags. LDFLAGS is set to -m64 -static-libgcc -O/-O2. + All builds on Solaris are by default 64-bit, so -m64 is always used in + the C/C++ flags. LDFLAGS is set to -m64 -O/-O2/-O3. If for + some reason a 32-bit Solaris is used it is necessary to add the flag + --32 to the script invocation. Due to bugs in compiling with -O3 on + Solaris only -O2 is used by default, when --fast flag is used -O3 will + be used instead. + + Sets -m64 (default) or -m32 (if specifically set) in LDFLAGS and + C/C++ flags. Solaris/Sparc/Forte ------------------- - Uses cc-5.0 as CC - Sets ASFLAGS=LDFLAGS=xarch=v9, so that we compile Sparc v9 binaries - C flags = -Xa -strconst -xc99=none + Uses cc as CC and CC as CXX + Note that SunStudio uses different binaries for C and C++ compilers. + + Set -m64 (default) or -m32 (if specifically set) in ASFLAGS, + LDFLAGS and C/C++ flags. + + Sets ASFLAGS=LDFLAGS=compiler flags=xarch=sparc, so that we compile + Sparc v9 binaries, also -mt is set in all those since we're always + building a multithreaded program. + + C flags = -xstrconst This flag is set only on SPARC C++ flags = -noex - C/C++ flags = -mt -D_FORTEC -xarch=v9 - For non-debug builds, the following flags are also used: + Set the following C/C++ flags: + -fsimple=1 + -ftrap=%none + -nofstore This flag is set only on x86 + -xbuiltin=%all + -xlibmil + -xlibmopt - C/C++ flags = -xO3 + Set the C++ flag: + -noex + -features=no%except This flag is set only on x86 + + When compiling with fast we set (-ipo only used if we have + set --with-link-time-optimizer): + C/C++ flags: -xtarget=native -xunroll=3 -xipo + LDFLAGS: -xipo + + When not compiling with fast we always set -xtarget=generic + + When compiling with fast on SPARC we also set: + C/C++ flags: -xbinopt=prepare + LDFLAGS: -xbinopt=prepare + + When compiling with fast on x86 we also set: + C/C++ flags: -xregs=frameptr + When not compiling with fast we set on x86 + C/C++ flags: -xregs=no%frameptr + + On SPARC we set + ASFLAGS = LDFLAGS = C/C++ flags = -xarch=sparc + + The optimisation level is + -xO Debug builds + -xO2 Production build on SPARC + -xO3 Production build on x86 + -xO4 Fast builds on SPARC/x86 MacOSX/x86/gcc -------------- - C/C++ flags include -fno-common -arch i386. + C/C++ flags include -fno-common -arch i386. + When 64-bits builds then i386 is replaced by x86_64. - Non-debug versions also add -Os -felide-constructors, where "-Os" - means the build is space-optimised as long as the space optimisations - do not negatively affect performance. Debug versions use -O. + Non-debug versions also add -Os -felide-constructors, where "-Os" + means the build is space-optimised as long as the space optimisations + do not negatively affect performance. Debug versions use -O. + + Mac OS X builds will always be 32-bit by default, when --64 is added + the build will be 64 bit instead. Thus the flag --m64 is added only + when specifically given as an option. EOF } + with_usage() { cat < /dev/null 2>&1 && test "$USING_GCOV" != "1" @@ -994,7 +1095,7 @@ set_with_debug_flags() if test "x$with_debug_flag" = "xyes" ; then if test "x$developer_flag" = "xyes" ; then loc_debug_flags="-DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS " - loc_debug_flags="$loc_debug_cflags -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC" + loc_debug_flags="$loc_debug_flags -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC" compiler_flags="$compiler_flags $loc_debug_flags" fi fi @@ -1023,6 +1124,18 @@ set_debug_flag() fi } +# +# We compile in SSL support if we can, this isn't possible if CXX +# and CC aren't the same and we're not using GCC. +# +set_ssl() +{ + if test "x$compiler" = "xgcc" && \ + test "x$CC" = "x$CXX" ; then + base_configs="$base_configs --with-ssl" + fi +} + # # Base options used by all packages # @@ -1048,9 +1161,12 @@ set_base_configs() base_configs="$base_configs --enable-thread-safe-client" base_configs="$base_configs --with-big-tables" base_configs="$base_configs --with-extra-charsets=all" - base_configs="$base_configs --with-ssl" + if test "x$with_fast_mutexes" = "xyes" ; then + base_configs="$base_configs --with-fast-mutexes" + fi base_configs="$base_configs --with-pic" base_configs="$base_configs --with-csv-storage-engine" + base_configs="$base_configs --with-perfschema" } # @@ -1060,18 +1176,30 @@ set_base_configs() # set_base_engines() { - engine_configs="$engine_configs --with-archive-storage-engine" + engine_configs="--with-archive-storage-engine" engine_configs="$engine_configs --with-blackhole-storage-engine" - engine_configs="$engine_configs --with-example-storage-engine" + engine_configs="$engine_configs --without-example-storage-engine" engine_configs="$engine_configs --with-federated-storage-engine" engine_configs="$engine_configs --with-partition" + base_configs="$base_configs $engine_configs" +} + +set_innodb_engine() +{ + base_configs="$base_configs --with-innodb" +} + +set_ndb_engine() +{ + base_configs="$base_configs --with-ndbcluster" + base_configs="$base_configs --without-ndb-debug" } set_pro_package() { - base_configs="$base_configs $engine_configs" - base_configs="$base_configs --with-innodb" - base_configs="$base_configs --with-comment=\"MySQL Pro $version_text built from source\"" + if test "x$without_comment" != "xyes" ; then + base_configs="$base_configs --with-comment=\"MySQL Enterprise Pro $version_text built from source\"" + fi if test "x$with_debug_flag" = "xyes" ; then base_configs="$base_configs --with-server-suffix=\"-debug\"" fi @@ -1079,40 +1207,37 @@ set_pro_package() set_cge_extended_package() { - if test "x$gpl" = "xno" ; then - echo "Cannot build Extended Carrier Grade Edition as Commercial version" + if test "x$without_comment" != "xyes" ; then + base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Extended Edition $version_text built from source\"" fi - base_configs="$base_configs --with-ndbcluster" - base_configs="$base_configs --without-ndb-debug" - base_configs="$base_configs $engine_configs" - base_configs="$base_configs --with-innodb" - base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Extended Edition $version_text built from source\"" if test "x$with_debug_flag" = "xyes" ; then base_configs="$base_configs --with-server-suffix=\"-cge-extended-debug\"" else - base_configs="$base_configs --with-server-suffix=\"-cge-extended"\" + base_configs="$base_configs --with-server-suffix=\"-cge-extended\"" fi } set_cge_package() { - base_configs="$base_configs --with-ndbcluster" - base_configs="$base_configs --without-ndb-debug" - base_configs="$base_configs $engine_configs" - base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Edition $version_text built from source\"" + if test "x$without_comment" != "xyes" ; then + base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Edition $version_text built from source\"" + fi if test "x$with_debug_flag" = "xyes" ; then base_configs="$base_configs --with-server-suffix=\"-cge-debug\"" else - base_configs="$base_configs --with-server-suffix=\"-cge"\" + base_configs="$base_configs --with-server-suffix=\"-cge\"" fi } set_classic_package() { - base_configs="$base_configs --with-comment=\"MySQL Classic $version_text built from source\"" + if test "x$without_comment" != "xyes" ; then + base_configs="$base_configs --with-comment=\"MySQL Classic $version_text built from source\"" + fi if test "x$with_debug_flag" = "xyes" ; then base_configs="$base_configs --with-server-suffix=\"-debug\"" fi + base_configs="$base_configs --without-example-storage-engine" } # @@ -1140,6 +1265,36 @@ set_gcc_special_options() fi } +set_cc_and_cxx_for_gcc() +{ + if test "x$CC" = "x" ; then + CC="gcc -static-libgcc -fno-exceptions" + fi + if test "x$CXX" = "x" ; then + CXX="gcc -static-libgcc -fno-exceptions" + fi +} + +set_cc_and_cxx_for_icc() +{ + if test "x$CC" = "x" ; then + CC="icc -static-intel -static-libgcc" + fi + if test "x$CXX" = "x" ; then + CXX="icpc -static-intel -static-libgcc" + fi +} + +set_cc_and_cxx_for_forte() +{ + if test "x$CC" = "x" ; then + CC="cc" + fi + if test "x$CXX" = "x" ; then + CXX="CC" + fi +} + # # If we discover a Core 2 Duo architecture and we have enabled the fast # flag, we enable a compile especially optimised for Core 2 Duo. This @@ -1167,10 +1322,69 @@ set_bsd_configs() exit 1 fi base_configs="$base_configs --enable-assembler" - CC="gcc" - CXX="gcc" + if test "x$fast_flag" != "xno" ; then + compiler_flags="$compiler_flags -O3" + else + compiler_flags="$compiler_flags -O0" + fi + set_cc_and_cxx_for_gcc } +check_64_bits() +{ + echo "Checking for 32/64-bits compilation" + echo "int main() { return 0; }" > temp_test.c + if test "x$m64" = "xyes" ; then + cmd="$CC $compile_flags -m64 temp_test.c" + if ! $cmd 2>1 ; then + m64="no" + echo "Changing to 32-bits since 64-bits didn't work" + else + echo "Will use 64-bits" + fi + else + cmd="$CC $compile_flags -m32 temp_test.c" + if ! $cmd 2>1 ; then + m64="yes" + echo "Changing to 64-bits since 32-bits didn't work" + else + echo "Will use 32-bits" + fi + fi + rm temp_test.c +} + +# +# Get GCC version +# +get_gcc_version() +{ + # check if compiler is gcc and dump its version + cc_verno=`$cc -dumpversion 2>/dev/null` + if test "x$?" = "x0" ; then + set -- `echo $cc_verno | tr '.' ' '` + cc_ver="GCC" + cc_major=$1 + cc_minor=$2 + cc_patch=$3 + gcc_version=`expr $cc_major '*' 100 '+' $cc_minor` + fi +} + +# +# Link Time Optimizer in GCC (LTO) uses a parameter -flto +# which was added to GCC 4.5, if --with-link-time-optimizer +# is set then use this feature +# +check_for_link_time_optimizer() +{ + get_gcc_version + if test "$gcc_version" -ge 405 && \ + test "x$with_link_time_optimizer" = "xyes" ; then + compiler_flags="$compiler_flags -flto" + LDFLAGS="$LDFLAGS -flto" + fi +} # # Linux Section # @@ -1178,31 +1392,46 @@ set_linux_configs() { if test "x$cpu_base_type" != "xx86" && \ test "x$cpu_base_type" != "xitanium" ; then - usage "Only x86 and Itanium CPUs supported for 32-bit Linux" + usage "Only x86 and Itanium CPUs supported for Linux" exit 1 fi - base_configs="$base_configs --with-fast-mutexes" + if test "x$use_tcmalloc" = "xyes" ; then + base_configs="$base_configs --with-mysqld-libs=-ltcmalloc_minimal" + fi if test "x$cpu_base_type" = "xx86" ; then base_configs="$base_configs --enable-assembler" fi if test "x$compiler" = "xgcc" ; then - CC="gcc" - CXX="gcc" + set_cc_and_cxx_for_gcc + if test "x$fast_flag" != "xno" ; then + if test "x$fast_flag" = "xyes" ; then + compiler_flags="$compiler_flags -O3" + check_for_link_time_optimizer + else + compiler_flags="$compiler_flags -O2" + fi + else + compiler_flags="$compiler_flags -O0" + fi + check_64_bits if test "x$m64" = "xyes" ; then compiler_flags="$compiler_flags -m64" + else + compiler_flags="$compiler_flags -m32" fi # configure will set proper compiler flags for gcc on Linux elif test "x$compiler" = "xicc" ; then compiler_flags="$compiler_flags -mp -restrict" - CC="icc -static-intel" - CXX="icpc -static-intel" + set_cc_and_cxx_for_icc if test "x$cpu_base_type" = "xitanium" ; then compiler_flags="$compiler_flags -no-ftz" fi if test "x$fast_flag" != "xno" ; then compiler_flags="$compiler_flags -O3 -unroll2 -ip" - if test "x$fast_flag" = "xyes" ; then + if test "x$fast_flag" = "xyes" && \ + test "x$with_link_time_optimizer" = "xyes" ; then compiler_flags="$compiler_flags -ipo" + LDFLAGS="$LDFLAGS -ipo" fi fi else @@ -1216,54 +1445,112 @@ set_linux_configs() # set_solaris_configs() { - base_configs="$base_configs --with-mysqld-libs=-lmtmalloc" +# Use mtmalloc as malloc, see Tim Cook blog +# For information on optimal compiler settings, see article at +# http://developers.sun.com/solaris/articles/mysql_perf_tune.html +# by Luojia Chen at Sun. + base_configs="$base_configs --with-named-curses=-lcurses" case "`uname -a`" in - *5.10*|*5.11*) + *5.8* | *5.9* ) + ;; + + *5.10* | *5.11*) + base_configs="$base_configs --with-mysqld-libs=-lmtmalloc" ;; *) - die "Only versions 10 and 11 supported for Solaris" + usage "Only versions 8,9, 10 and 11 supported for Solaris" + exit 1 esac if test "x$cpu_base_type" != "xx86" && \ test "x$cpu_base_type" != "xsparc" ; then usage "Only x86 and Sparc CPUs supported for Solaris" exit 1 fi - if test "x$compiler" = "xgcc" ; then - CC="gcc" - CXX="gcc" - if test "x$cpu_base_type" != "xx86" ; then - usage "Only gcc supported for Solaris 10/11 on SPARC" - fi - compiler_flags="$compiler_flags -m64 -DMY_ATOMIC_MODE_RWLOCKS" - LDFLAGS="-m64 -static-libgcc" - if test "x$fast_flag" != "xno" ; then - LDFLAGS="$LDFLAGS -O2" - compiler_flags="$compiler_flags -O2" - else - LDFLAGS="$LDFLAGS -O" - compiler_flags="$compiler_flags -O" - fi - elif test "x$compiler" = "xforte" ; then - if test "x$cpu_base_type" = "xx86" ; then - usage "Only gcc supported for Solaris/x86" - fi - if test "x$cpu_base_type" != "xsparc" ; then - usage "Forte compiler supported for Solaris 9/SPARC only" - fi - CC="cc-5.0" - CXX=CC - ASFLAGS="xarch=v9" - LDFLAGS="xarch=v9" - base_cflags="$base_cflags -Xa -xstrconst -xc99=none" - base_cxxflags="$base_cxxflags -noex" - compiler_flags="$compiler_flags -mt -D_FORTEC -xarch=v9" - if test "x$fast_flag" != "xno" ; then - compiler_flags="$compiler_flags -xO3" - fi - else + if test "x$compiler" != "xgcc" && \ + test "x$compiler" != "xforte" ; then usage "Only gcc and Forte compilers supported for Solaris" exit 1 fi + if test "x$m64" = "xyes" ; then + compiler_flags="$compiler_flags -m64" + LDFLAGS="-m64" + ASFLAGS="$ASFLAGS -m64" + else + compiler_flags="$compiler_flags -m32" + LDFLAGS="-m32" + ASFLAGS="$ASFLAGS -m32" + fi + if test "x$compiler" = "xgcc" ; then + set_cc_and_cxx_for_gcc + if test "x$cpu_base_type" != "xx86" ; then + usage "gcc currently not supported for Solaris on SPARC" + exit 1 + fi + if test "x$fast_flag" = "xyes" ; then + LDFLAGS="$LDFLAGS -O3" + compiler_flags="$compiler_flags -O3" + check_for_link_time_optimizer + else + if test "x$fast_flag" = "xgeneric" ; then + LDFLAGS="$LDFLAGS -O2" + compiler_flags="$compiler_flags -O2" + else + LDFLAGS="$LDFLAGS -O0" + compiler_flags="$compiler_flags -O0" + fi + fi + else +#Using Forte compiler (SunStudio) + set_cc_and_cxx_for_forte + compiler_flags="$compiler_flags -mt" + LDFLAGS="$LDFLAGS -mt" + compiler_flags="$compiler_flags -fsimple=1" + compiler_flags="$compiler_flags -ftrap=%none" + compiler_flags="$compiler_flags -xbuiltin=%all" + compiler_flags="$compiler_flags -xlibmil" + compiler_flags="$compiler_flags -xlibmopt" + if test "x$fast_flag" = "xyes" ; then + compiler_flags="$compiler_flags -xtarget=native" + compiler_flags="$compiler_flags -xunroll=3" + if test "x$with_link_time_optimizer" = "xyes" ; then + compiler_flags="$compiler_flags -xipo" + LDFLAGS="$LDFLAGS -xipo" + fi + else + compiler_flags="$compiler_flags -xtarget=generic" + fi + if test "x$cpu_base_type" = "xx86" ; then + compiler_flags="$compiler_flags -nofstore" + base_cxx_flags="$base_cxx_flags -features=no%except" + if test "x$fast_flag" = "xyes" ; then + compiler_flags="$compiler_flags -xregs=frameptr" + compiler_flags="$compiler_flags -xO4" + else + compiler_flags="$compiler_flags -xregs=no%frameptr" + if test "x$fast_flag" = "xgeneric" ; then + compiler_flags="$compiler_flags -xO2" + else + compiler_flags="$compiler_flags -xO0" + fi + fi + else +#Using SPARC cpu with SunStudio (Forte) compiler + ASFLAGS="$ASFLAGS -xarch=sparc" + LDFLAGS="$LDFLAGS -xarch=sparc" + base_cxxflags="$base_cxxflags -noex" + base_cflags="$base_cflags -xstrconst" + compiler_flags="$compiler_flags -xarch=sparc" + if test "x$fast_flag" = "xyes" ; then + compiler_flags="$compiler_flags -xbinopt=prepare" + LDFLAGS="$LDFLAGS -xbinopt=prepare" + compiler_flags="$compiler_flags -xO4" + elif test "x$fast_flag" = "xgeneric" ; then + compiler_flags="$compiler_flags -xO3" + else + compiler_flags="$compiler_flags -xO0" + fi + fi + fi } # @@ -1271,10 +1558,7 @@ set_solaris_configs() # set_macosx_configs() { - base_cxxflags="$base_cxxflags -fno-common" - if test "x$cpu_base_type" = "xx86" && test "x$compiler" = "xgcc" ; then - compiler_flags="$compiler_flags -arch i386" - else + if test "x$cpu_base_type" != "xx86" || test "x$compiler" != "xgcc" ; then usage "Only gcc/x86 supported for Mac OS X" exit 1 fi @@ -1282,14 +1566,21 @@ set_macosx_configs() # Optimize for space as long as it doesn't affect performance, use some # optimisations also when not in fast mode. # + base_cxxflags="$base_cxxflags -felide-constructors" + compiler_flags="$compiler_flags -fno-common" + if test "x$m64" = "xyes" ; then + compiler_flags="$compiler_flags -m64" + compiler_flags="$compiler_flags -arch x86_64" + else + compiler_flags="$compiler_flags -m32" + compiler_flags="$compiler_flags -arch i386" + fi if test "x$fast_flag" != "xno" ; then compiler_flags="$compiler_flags -Os" - base_cxxflags="$base_cxxflags -felide-constructors" else - compiler_flags="$compiler_flags -O" + compiler_flags="$compiler_flags -O0" fi - CC="gcc" - CXX="gcc" + set_cc_and_cxx_for_gcc } # @@ -1370,7 +1661,7 @@ fi cpu_type= package= prefix="/usr/local/mysql" -parallelism="4" +parallelism="8" fast_flag="generic" compiler="gcc" gpl="yes" @@ -1398,11 +1689,19 @@ base_cxxflags= base_configs= debug_flags= cxxflags= -m32= m64= +explicit_size_set= datadir= commands= use_autotools= +engine_configs= +ASFLAGS= +LDFLAGS= +use_tcmalloc= +without_comment="yes" +with_fast_mutexes= +with_link_time_optimizer= +gcc_version="0" set_defaults_based_on_environment @@ -1419,7 +1718,14 @@ set -e # This call sets the cpu_arg and check_cpu_args parameters # path=`dirname $0` +if test "x$compiler" = "xgcc" ; then + compiler= +fi . "$path/check-cpu" +if test "x$compiler" = "x" ; then + compiler="gcc" +fi +check_os set_cpu_base if test "x$?" = "x1" ; then exit 1 @@ -1447,17 +1753,23 @@ set_icc_special_options # including all storage engines except InnoDB, and to use GPL libraries. # set_base_configs -set_base_engines if test "x$gpl" = "xyes" ; then version_text="GPL version" else version_text="Commercial version" fi if test "x$package" = "xpro" ; then + set_base_engines + set_innodb_engine set_pro_package elif test "x$package" = "xextended" ; then + set_base_engines + set_ndb_engine + set_innodb_engine set_cge_extended_package elif test "x$package" = "xcge" ; then + set_base_engines + set_ndb_engine set_cge_package elif test "x$package" = "xclassic" ; then set_classic_package @@ -1473,7 +1785,6 @@ set_error_inject_configs # operating systems, and processors. # -check_os if test "x$os" = "xlinux" ; then set_linux_configs elif test "x$os" = "xSolaris" ; then @@ -1485,13 +1796,13 @@ elif test "x$os" = "xbsd" ; then else die "Operating system not supported by this script" fi - +set_ssl # # Final step before setting up commands is to set up proper make and # proper libtoolize versions, and to determine whether to use ccache. # set_make_version -set_up_ccache +set_ccache_usage # # Set up commands variable from variables prepared for base diff --git a/BUILD/check-cpu b/BUILD/check-cpu index 390ba545405..90f42ef67cc 100755 --- a/BUILD/check-cpu +++ b/BUILD/check-cpu @@ -16,12 +16,14 @@ check_cpu () { # on Linux (and others?) we can get detailed CPU information out of /proc cpuinfo="cat $CPUINFO" + # detect CPU architecture + cpu_arch=`$cpuinfo | grep 'arch' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1` + # detect CPU family cpu_family=`$cpuinfo | grep 'family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1` if test -z "$cpu_family" ; then cpu_family=`$cpuinfo | grep 'cpu' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1` fi - # detect CPU vendor and model cpu_vendor=`$cpuinfo | grep 'vendor_id' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1` model_name=`$cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -1` @@ -56,8 +58,8 @@ check_cpu () { fi ;; *) - cpu_family=`uname -m`; - model_name=`uname -p`; + cpu_family=`uname -p`; + model_name=`uname -m`; ;; esac fi @@ -65,9 +67,10 @@ check_cpu () { # detect CPU shortname as used by gcc options # this list is not complete, feel free to add further entries cpu_arg="" - case "$cpu_family--$model_name" in + low_cpu_arg="" + case "$cpu_vendor--$cpu_family--$model_name--$cpu_arch" in # DEC Alpha - Alpha*EV6*) + *Alpha*EV6*) cpu_arg="ev6"; ;; #Core 2 Duo @@ -96,6 +99,13 @@ check_cpu () { *Pentium*4*Mobile*) cpu_arg="pentium4m" ;; + *Pentium\(R\)*\ M*) + cpu_arg="pentium-m" + low_cpu_arg="pentium3" + ;; + *Pentium\(R\)*\ D*) + cpu_arg="prescott" + ;; *Pentium*4*) cpu_arg="pentium4" ;; @@ -120,6 +130,12 @@ check_cpu () { *Celeron*) cpu_arg="pentium2" ;; + *Atom*) + cpu_arg="prescott" + ;; + *GenuineIntel*) + cpu_arg="pentium" + ;; *Turion*) cpu_arg="athlon64" ;; @@ -129,9 +145,30 @@ check_cpu () { *Athlon*) cpu_arg="athlon" ;; + *AMD-K7*) + cpu_arg="athlon" + ;; + *Athlon*XP\ *) + cpu_arg="athlon-xp" + ;; + *AMD*Sempron\(tm\)*) + cpu_arg="athlon-mp" + ;; + *AMD*Athlon\(tm\)\ 64*) + cpu_arg="k8" + ;; *Opteron*) cpu_arg="opteron" ;; + *Phenom*) + cpu_arg="k8" + ;; + *AuthenticAMD*) + cpu_arg="k6" + ;; + *VIA\ *) + cpu_arg="i686" + ;; # MacOSX / Intel *i386*i486*) cpu_arg="pentium-m" @@ -143,8 +180,11 @@ check_cpu () { *Itanium*) cpu_arg="itanium" ;; + *IA-64*) + cpu_arg="itanium" + ;; # Solaris Sparc - *sparc*sun4u*) + *sparc*sun4[uv]*) cpu_arg="sparc" ;; # Power PC @@ -160,6 +200,10 @@ check_cpu () { ;; esac + if test "x$low_cpu_arg" = "x" ; then + low_cpu_arg="$cpu_arg" + fi + if test -z "$cpu_arg" ; then if test "$CPUINFO" != " " ; then # fallback to uname if necessary @@ -198,7 +242,7 @@ check_cpu () { case `gcc -dumpmachine` in i?86-* | x86_64-*) if test "$cc_comp" -lt 304 ; then - check_cpu_cflags="-mcpu=${cpu_arg}" + check_cpu_cflags="-mcpu=${low_cpu_arg}" elif test "$cc_comp" -ge 402 ; then check_cpu_cflags="-mtune=native" else From 0c91b53d10ad74fd26a2e3ba565d117539d8983c Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 16 Sep 2010 17:24:27 +0700 Subject: [PATCH 36/44] Fixed bug#42503 - "Lost connection" errors when using compression protocol. The loss of connection was caused by a malformed packet sent by the server in case when query cache was in use. When storing data in the query cache, the query cache memory allocation algorithm had a tendency to reduce the amount of memory block necessary to store a result set, up to finally storing the entire result set in a single block. With a significant result set, this memory block could turn out to be quite large - 30, 40 MB and on. When such a result set was sent to the client, the entire memory block was compressed and written to network as a single network packet. However, the length of the network packet is limited by 0xFFFFFF (16MB), since the packet format only allows 3 bytes for packet length. As a result, a malformed, overly large packet with truncated length would be sent to the client and break the client/server protocol. The solution is, when sending result sets from the query cache, to ensure that the data is chopped into network packets of size <= 16MB, so that there is no corruption of packet length. This solution, however, has a shortcoming: since the result set is still stored in the query cache as a single block, at the time of sending, we've lost boundaries of individual logical packets (one logical packet = one row of the result set) and thus can end up sending a truncated logical packet in a compressed network packet. As a result, on the client we may require more memory than max_allowed_packet to keep, both, the truncated last logical packet, and the compressed next packet. This never (or in practice never) happens without compression, since without compression it's very unlikely that a) a truncated logical packet would remain on the client when it's time to read the next packet b) a subsequent logical packet that is being read would be so large that size-of-new-packet + size-of-old-packet-tail > max_allowed_packet. To remedy this issue, we send data in 1MB sized packets, that's below the current client default of 16MB for max_allowed_packet, but large enough to ensure there is no unnecessary overhead from too many syscalls per result set. sql/net_serv.cc: net_realloc() modified: consider already used memory when compare packet buffer length sql/sql_cache.cc: modified Query_cache::send_result_to_client: send result to client in chunks limited by 1 megabyte. --- sql/net_serv.cc | 12 +++++++++- sql/sql_cache.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 38ab3a70136..f3f6f1bd9a0 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -170,7 +170,17 @@ my_bool net_realloc(NET *net, size_t length) DBUG_ENTER("net_realloc"); DBUG_PRINT("enter",("length: %lu", (ulong) length)); - if (length >= net->max_packet_size) + /* + When compression is off, net->where_b is always 0. + With compression turned on, net->where_b may indicate + that we still have a piece of the previous logical + packet in the buffer, unprocessed. Take it into account + when checking that max_allowed_packet is not exceeded. + This ensures that the client treats max_allowed_packet + limit identically, regardless of compression being on + or off. + */ + if (length >= (net->max_packet_size + net->where_b)) { DBUG_PRINT("error", ("Packet too large. Max size: %lu", net->max_packet_size)); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index fcf4edbdc22..22bdb24fb16 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1330,6 +1330,55 @@ end: } +/** + Send a single memory block from the query cache. + + Respects the client/server protocol limits for the + size of the network packet, and splits a large block + in pieces to ensure that individual piece doesn't exceed + the maximal allowed size of the network packet (16M). + + @param[in] net NET handler + @param[in] packet packet to send + @param[in] len packet length + + @return Operation status + @retval FALSE On success + @retval TRUE On error +*/ +static bool +send_data_in_chunks(NET *net, const uchar *packet, ulong len) +{ + /* + On the client we may require more memory than max_allowed_packet + to keep, both, the truncated last logical packet, and the + compressed next packet. This never (or in practice never) + happens without compression, since without compression it's very + unlikely that a) a truncated logical packet would remain on the + client when it's time to read the next packet b) a subsequent + logical packet that is being read would be so large that + size-of-new-packet + size-of-old-packet-tail > + max_allowed_packet. To remedy this issue, we send data in 1MB + sized packets, that's below the current client default of 16MB + for max_allowed_packet, but large enough to ensure there is no + unnecessary overhead from too many syscalls per result set. + */ + static const ulong MAX_CHUNK_LENGTH= 1024*1024; + + while (len > MAX_CHUNK_LENGTH) + { + if (net_real_write(net, packet, MAX_CHUNK_LENGTH)) + return TRUE; + packet+= MAX_CHUNK_LENGTH; + len-= MAX_CHUNK_LENGTH; + } + if (len && net_real_write(net, packet, len)) + return TRUE; + + return FALSE; +} + + /* Check if the query is in the cache. If it was cached, send it to the user. @@ -1635,11 +1684,11 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", ALIGN_SIZE(sizeof(Query_cache_result))))); Query_cache_result *result = result_block->result(); - if (net_real_write(&thd->net, result->data(), - result_block->used - - result_block->headers_len() - - ALIGN_SIZE(sizeof(Query_cache_result)))) - break; // Client aborted + if (send_data_in_chunks(&thd->net, result->data(), + result_block->used - + result_block->headers_len() - + ALIGN_SIZE(sizeof(Query_cache_result)))) + break; // Client aborted result_block = result_block->next; thd->net.pkt_nr= query->last_pkt_nr; // Keep packet number updated } while (result_block != first_result_block); From ebd207baa84278759675bd97d8864d4cac94c6ed Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Thu, 16 Sep 2010 12:51:08 +0200 Subject: [PATCH 37/44] Bug #54606 innodb fast alter table + pack_keys=0 prevents adding new indexes A fast alter table requires that the existing (old) table and indices are unchanged (i.e only new indices can be added). To verify this, the layout and flags of the old table/indices are compared for equality with the new. The PACK_KEYS option is a no-op in InnoDB, but the flag exists, and is used in the table compare. We need to check this (table) option flag before deciding whether an index should be packed or not. If the table has explicitly set PACK_KEYS to 0, the created indices should not be marked as packed/packable. --- .../suite/innodb_plugin/r/innodb_mysql.result | 10 ++++++++++ mysql-test/suite/innodb_plugin/t/innodb_mysql.test | 14 ++++++++++++++ sql/sql_table.cc | 1 + 3 files changed, 25 insertions(+) diff --git a/mysql-test/suite/innodb_plugin/r/innodb_mysql.result b/mysql-test/suite/innodb_plugin/r/innodb_mysql.result index b4ac88fc1c3..54a8854ecaf 100644 --- a/mysql-test/suite/innodb_plugin/r/innodb_mysql.result +++ b/mysql-test/suite/innodb_plugin/r/innodb_mysql.result @@ -2390,4 +2390,14 @@ a 2 UPDATE t1,t2 SET t1.a = t1.a + 100 WHERE t1.a = 1; DROP TABLE t1,t2; +# +# Bug#54606 innodb fast alter table + pack_keys=0 +# prevents adding new indexes +# +CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b)) +ENGINE=InnoDB +PACK_KEYS=0; +CREATE INDEX a ON t1 (a); +CREATE INDEX c on t1 (c); +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/suite/innodb_plugin/t/innodb_mysql.test b/mysql-test/suite/innodb_plugin/t/innodb_mysql.test index 3f6d9d96bb8..3d078062d43 100644 --- a/mysql-test/suite/innodb_plugin/t/innodb_mysql.test +++ b/mysql-test/suite/innodb_plugin/t/innodb_mysql.test @@ -632,4 +632,18 @@ UPDATE t1,t2 SET t1.a = t1.a + 100 WHERE t1.a = 1; DROP TABLE t1,t2; +--echo # +--echo # Bug#54606 innodb fast alter table + pack_keys=0 +--echo # prevents adding new indexes +--echo # + +CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b)) + ENGINE=InnoDB + PACK_KEYS=0; +CREATE INDEX a ON t1 (a); +CREATE INDEX c on t1 (c); + +DROP TABLE t1; + + --echo End of 5.1 tests diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d3ac2bf0f95..7a7446c7f79 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3325,6 +3325,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, key_part_info->length=(uint16) length; /* Use packed keys for long strings on the first column */ if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) && + !((create_info->table_options & HA_OPTION_NO_PACK_KEYS)) && (length >= KEY_DEFAULT_PACK_LENGTH && (sql_field->sql_type == MYSQL_TYPE_STRING || sql_field->sql_type == MYSQL_TYPE_VARCHAR || From 31a38c0fc5de01055183f642ce171b2f47d377f0 Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 16 Sep 2010 16:13:53 +0400 Subject: [PATCH 38/44] Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB Subselect executes twice, at JOIN::optimize stage and at JOIN::execute stage. At optimize stage Innodb prebuilt struct which is used for the retrieval of column values is initialized in. ha_innobase::index_read(), prebuilt->sql_stat_start is true. After QUICK_ROR_INTERSECT_SELECT finished his job it restores read_set/write_set bitmaps with initial values and deactivates one of the handlers used by QUICK_ROR_INTERSECT_SELECT in JOIN::cleanup (it's the case when we reuse original handler as one of handlers required by QUICK_ROR_INTERSECT_SELECT object). On second subselect execution inactive handler is activated in QUICK_RANGE_SELECT::reset, file->ha_index_init(). In ha_index_init Innodb prebuilt struct is reinitialized with inappropriate read_set/write_set bitmaps. Further reinitialization in ha_innobase::index_read() does not happen as prebuilt->sql_stat_start is false. It leads to partial retrieval of required field values and we get a mix of field values from different records in the record buffer. The fix is to reset read_set/write_set bitmaps as these values are required for proper intialization of internal InnoDB struct which is used for the retrieval of column values (see build_template(), ha_innodb.cc) mysql-test/include/index_merge_ror_cpk.inc: test case mysql-test/r/index_merge_innodb.result: test case mysql-test/r/index_merge_myisam.result: test case sql/opt_range.cc: if ROR merge scan is used we need to reset read_set/write_set bitmaps as these values are required for proper intialization of internal InnoDB struct which is used for the retrieval of column values (see build_template(), ha_innodb.cc) --- mysql-test/include/index_merge_ror_cpk.inc | 16 ++++++++++++++++ mysql-test/r/index_merge_innodb.result | 18 ++++++++++++++++++ mysql-test/r/index_merge_myisam.result | 18 ++++++++++++++++++ sql/opt_range.cc | 11 ++++++++--- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/mysql-test/include/index_merge_ror_cpk.inc b/mysql-test/include/index_merge_ror_cpk.inc index cfc2ed3885e..3912aa34026 100644 --- a/mysql-test/include/index_merge_ror_cpk.inc +++ b/mysql-test/include/index_merge_ror_cpk.inc @@ -126,3 +126,19 @@ WHERE drop table t1; +--echo # +--echo # Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB +--echo # +CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1)); +INSERT INTO t1 VALUES (2); +CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1), + PRIMARY KEY (f1), KEY (f2), KEY (f3) ); +INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, ''); + +SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; + +EXPLAIN SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; + +DROP TABLE t1,t2; diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result index 588de70e6e5..58ed99b1e67 100644 --- a/mysql-test/r/index_merge_innodb.result +++ b/mysql-test/r/index_merge_innodb.result @@ -581,3 +581,21 @@ WHERE `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND `TESTID`='' AND `UCCHECK`=''; drop table t1; +# +# Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB +# +CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1)); +INSERT INTO t1 VALUES (2); +CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1), +PRIMARY KEY (f1), KEY (f2), KEY (f3) ); +INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, ''); +SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; +f1 +2 +EXPLAIN SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index +2 DEPENDENT SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index +DROP TABLE t1,t2; diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index c639b20de91..6bfec69fad9 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -1416,6 +1416,24 @@ WHERE `TESTID`='' AND `UCCHECK`=''; drop table t1; # +# Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB +# +CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1)); +INSERT INTO t1 VALUES (2); +CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1), +PRIMARY KEY (f1), KEY (f2), KEY (f3) ); +INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, ''); +SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; +f1 +2 +EXPLAIN SELECT t1.f1 FROM t1 +WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 +2 DEPENDENT SUBQUERY t2 ref f2,f3 f2 5 1 Using where +DROP TABLE t1,t2; +# # Generic @@optimizer_switch tests (move those into a separate file if # we get another @@optimizer_switch user) # diff --git a/sql/opt_range.cc b/sql/opt_range.cc index eae79e63c19..d4a2bc3b138 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -8451,9 +8451,14 @@ int QUICK_RANGE_SELECT::reset() in_range= FALSE; cur_range= (QUICK_RANGE**) ranges.buffer; - if (file->inited == handler::NONE && (error= file->ha_index_init(index,1))) - DBUG_RETURN(error); - + if (file->inited == handler::NONE) + { + if (in_ror_merged_scan) + head->column_bitmaps_set_no_signal(&column_bitmap, &column_bitmap); + if ((error= file->ha_index_init(index,1))) + DBUG_RETURN(error); + } + /* Do not allocate the buffers twice. */ if (multi_range_length) { From 9516e824e01d99165a37966fc5fc4f03acbd4c4e Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Wed, 22 Sep 2010 19:53:06 +0700 Subject: [PATCH 39/44] Fixed bug#56821 - failure to start the MySQL Service. sql/log.cc: reopen_fstreams modified: fixed error in processing of stdout/stderr when run mysqld as Windows service. --- sql/log.cc | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 503b3bb5cff..56f151fe2ab 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5072,10 +5072,32 @@ extern "C" my_bool reopen_fstreams(const char *filename, FILE *outstream, FILE *errstream) { int handle_fd; - int stream_fd; + int err_fd, out_fd; HANDLE osfh; - DBUG_ASSERT(filename && (outstream || errstream)); + DBUG_ASSERT(filename && errstream); + + // Services don't have stdout/stderr on Windows, so _fileno returns -1. + err_fd= _fileno(errstream); + if (err_fd < 0) + { + if (!freopen(filename, "a+", errstream)) + return TRUE; + + setbuf(errstream, NULL); + err_fd= _fileno(errstream); + } + + if (outstream) + { + out_fd= _fileno(outstream); + if (out_fd < 0) + { + if (!freopen(filename, "a+", outstream)) + return TRUE; + out_fd= _fileno(outstream); + } + } if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | @@ -5091,24 +5113,16 @@ extern "C" my_bool reopen_fstreams(const char *filename, return TRUE; } - if (outstream) + if (_dup2(handle_fd, err_fd) < 0) { - stream_fd= _fileno(outstream); - if (_dup2(handle_fd, stream_fd) < 0) - { - CloseHandle(osfh); - return TRUE; - } + CloseHandle(osfh); + return TRUE; } - if (errstream) + if (outstream && _dup2(handle_fd, out_fd) < 0) { - stream_fd= _fileno(errstream); - if (_dup2(handle_fd, stream_fd) < 0) - { - CloseHandle(osfh); - return TRUE; - } + CloseHandle(osfh); + return TRUE; } _close(handle_fd); From 7461d92d4570c2d243bd6c9cadb5506ee4ed2fac Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Fri, 24 Sep 2010 19:03:28 +0700 Subject: [PATCH 40/44] Follow-up for Bug#42503: fix a compilation warning. sql/sql_cache.cc: Added include of send_data_in_chunks() definiton when macros EMBEDDED_LIBRARY is on. --- sql/sql_cache.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 22bdb24fb16..befeecb1902 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1330,6 +1330,7 @@ end: } +#ifndef EMBEDDED_LIBRARY /** Send a single memory block from the query cache. @@ -1377,6 +1378,7 @@ send_data_in_chunks(NET *net, const uchar *packet, ulong len) return FALSE; } +#endif /* From 930a50f9d3709fb18c30a1c4d4f1b9908d53ed1f Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 24 Sep 2010 09:36:31 -0300 Subject: [PATCH 41/44] Bug#45288: pb2 returns a lot of compilation warnings on linux Temporarily disable strict aliasing warnings in order to get wider coverage for optimized builds. Once the violations are fixed and false-positives silenced, this flag should be removed. --- config/ac-macros/maintainer.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ac-macros/maintainer.m4 b/config/ac-macros/maintainer.m4 index 1b7df75d6f7..24be31395f2 100644 --- a/config/ac-macros/maintainer.m4 +++ b/config/ac-macros/maintainer.m4 @@ -16,7 +16,7 @@ AC_DEFUN([MY_MAINTAINER_MODE], [ AC_DEFUN([MY_MAINTAINER_MODE_WARNINGS], [ # Setup GCC warning options. AS_IF([test "$GCC" = "yes"], [ - C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Werror" + C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror" CXX_WARNINGS="${C_WARNINGS} -Wno-unused-parameter" ]) From 48de6a60d254da87d9289d76333322d4b4266805 Mon Sep 17 00:00:00 2001 From: Dmitry Lenev Date: Fri, 24 Sep 2010 20:26:24 +0400 Subject: [PATCH 42/44] Fix compile warning about passing NULL to non-pointer argument of inline_mysql_mutex_init in sql_base.cc. When initializing LOCK_dd_owns_lock_open mutex pass correct PSI key instead of NULL value. mysql-test/suite/perfschema/r/dml_setup_instruments.result: Updated test results after adding P_S instrumentation for LOCK_dd_owns_lock_open. sql/sql_base.cc: When initializing LOCK_dd_owns_lock_open mutex pass correct PSI key instead of NULL value. --- .../suite/perfschema/r/dml_setup_instruments.result | 2 +- sql/sql_base.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/perfschema/r/dml_setup_instruments.result b/mysql-test/suite/perfschema/r/dml_setup_instruments.result index 2338252976c..7f203118346 100644 --- a/mysql-test/suite/perfschema/r/dml_setup_instruments.result +++ b/mysql-test/suite/perfschema/r/dml_setup_instruments.result @@ -13,7 +13,7 @@ wait/synch/mutex/sql/LOCK_active_mi YES YES wait/synch/mutex/sql/LOCK_audit_mask YES YES wait/synch/mutex/sql/LOCK_connection_count YES YES wait/synch/mutex/sql/LOCK_crypt YES YES -wait/synch/mutex/sql/LOCK_delayed_create YES YES +wait/synch/mutex/sql/LOCK_dd_owns_lock_open YES YES select * from performance_schema.SETUP_INSTRUMENTS where name like 'Wait/Synch/Rwlock/sql/%' and name not in ('wait/synch/rwlock/sql/CRYPTO_dynlock_value::lock') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b168f561954..c0ea60cac3b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -104,9 +104,10 @@ mysql_mutex_t LOCK_dd_owns_lock_open; uint dd_owns_lock_open= 0; #ifdef HAVE_PSI_INTERFACE -static PSI_mutex_key key_LOCK_open; +static PSI_mutex_key key_LOCK_open, key_LOCK_dd_owns_lock_open; static PSI_mutex_info all_tdc_mutexes[]= { - { &key_LOCK_open, "LOCK_open", PSI_FLAG_GLOBAL } + { &key_LOCK_open, "LOCK_open", PSI_FLAG_GLOBAL }, + { &key_LOCK_dd_owns_lock_open, "LOCK_dd_owns_lock_open", PSI_FLAG_GLOBAL } }; /** @@ -300,7 +301,8 @@ bool table_def_init(void) init_tdc_psi_keys(); #endif mysql_mutex_init(key_LOCK_open, &LOCK_open, MY_MUTEX_INIT_FAST); - mysql_mutex_init(NULL, &LOCK_dd_owns_lock_open, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_dd_owns_lock_open, &LOCK_dd_owns_lock_open, + MY_MUTEX_INIT_FAST); oldest_unused_share= &end_of_unused_share; end_of_unused_share.prev= &oldest_unused_share; From 060289e9ce2f5f41ba200cb91ca2d693b5d4a56a Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 24 Sep 2010 17:04:36 -0300 Subject: [PATCH 43/44] Bug#45288: pb2 returns a lot of compilation warnings on linux Use UNINIT_VAR workaround instead of LINT_INIT. The former is also used in non-debug builds as it doesn't cause changes. --- mysys/my_getopt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 4faaadb3f70..2ea39080cff 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -153,7 +153,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option) { - uint opt_found, argvpos= 0, length; + uint UNINIT_VAR(opt_found), argvpos= 0, length; my_bool end_of_options= 0, must_be_var, set_maximum_value, option_is_loose; char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN]; @@ -163,7 +163,6 @@ int handle_options(int *argc, char ***argv, int error, i; my_bool is_cmdline_arg= 1; - LINT_INIT(opt_found); /* handle_options() assumes arg0 (program name) always exists */ DBUG_ASSERT(argc && *argc >= 1); DBUG_ASSERT(argv && *argv); From 58dfba2899474553592479be24ef73947775eeaf Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 24 Sep 2010 19:13:51 -0300 Subject: [PATCH 44/44] Bug#45288: pb2 returns a lot of compilation warnings on linux Use UNINIT_VAR workaround instead of LINT_INIT. The former can also be used to silence false-positives in non-debug builds as it actually does not cause new code to be generated. --- mysys/my_getopt.c | 3 +-- storage/myisam/mi_range.c | 3 +-- storage/myisam/mi_search.c | 10 +++------- storage/myisam/rt_index.c | 8 ++------ storage/myisam/rt_split.c | 11 +++-------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 0327db33e98..069626ba004 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -112,7 +112,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option) { - uint opt_found, argvpos= 0, length; + uint UNINIT_VAR(opt_found), argvpos= 0, length; my_bool end_of_options= 0, must_be_var, set_maximum_value, option_is_loose; char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN]; @@ -121,7 +121,6 @@ int handle_options(int *argc, char ***argv, void *value; int error, i; - LINT_INIT(opt_found); /* handle_options() assumes arg0 (program name) always exists */ DBUG_ASSERT(argc && *argc >= 1); DBUG_ASSERT(argv && *argv); diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index dc6dc9d62b7..e4205f36557 100644 --- a/storage/myisam/mi_range.c +++ b/storage/myisam/mi_range.c @@ -193,12 +193,11 @@ static double _mi_search_pos(register MI_INFO *info, register my_off_t pos) { int flag; - uint nod_flag,keynr,max_keynr; + uint nod_flag,keynr,UNINIT_VAR(max_keynr); my_bool after_key; uchar *keypos,*buff; double offset; DBUG_ENTER("_mi_search_pos"); - LINT_INIT(max_keynr); if (pos == HA_OFFSET_ERROR) DBUG_RETURN(0.5); diff --git a/storage/myisam/mi_search.c b/storage/myisam/mi_search.c index 9c842fba544..66ea82b7643 100644 --- a/storage/myisam/mi_search.c +++ b/storage/myisam/mi_search.c @@ -296,9 +296,9 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, flag is the value returned by ha_key_cmp and as treated as final */ int flag=0, my_flag=-1; - uint nod_flag, length, len, matched, cmplen, kseg_len; - uint prefix_len,suffix_len; - int key_len_skip, seg_len_pack, key_len_left; + uint nod_flag, UNINIT_VAR(length), len, matched, cmplen, kseg_len; + uint UNINIT_VAR(prefix_len), suffix_len; + int key_len_skip, UNINIT_VAR(seg_len_pack), key_len_left; uchar *end, *kseg, *vseg; uchar *sort_order=keyinfo->seg->charset->sort_order; uchar tt_buff[MI_MAX_KEY_BUFF+2], *t_buff=tt_buff+2; @@ -308,10 +308,6 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, uint length_pack; DBUG_ENTER("_mi_prefix_search"); - LINT_INIT(length); - LINT_INIT(prefix_len); - LINT_INIT(seg_len_pack); - t_buff[0]=0; /* Avoid bugs */ end= page+mi_getint(page); nod_flag=mi_test_if_nod(page); diff --git a/storage/myisam/rt_index.c b/storage/myisam/rt_index.c index 410badd3145..3f712c2dd06 100644 --- a/storage/myisam/rt_index.c +++ b/storage/myisam/rt_index.c @@ -481,17 +481,13 @@ static uchar *rtree_pick_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, uint key_length, uchar *page_buf, uint nod_flag) { double increase; - double best_incr; + double UNINIT_VAR(best_incr); double area; - double best_area; + double UNINIT_VAR(best_area); uchar *best_key= NULL; uchar *k = rt_PAGE_FIRST_KEY(page_buf, nod_flag); uchar *last = rt_PAGE_END(page_buf); - LINT_INIT(best_area); - LINT_INIT(best_key); - LINT_INIT(best_incr); - for (; k < last; k = rt_PAGE_NEXT_KEY(k, key_length, nod_flag)) { /* The following is safe as -1.0 is an exact number */ diff --git a/storage/myisam/rt_split.c b/storage/myisam/rt_split.c index 03d22de68fa..0b7cc43e062 100644 --- a/storage/myisam/rt_split.c +++ b/storage/myisam/rt_split.c @@ -178,18 +178,13 @@ static int split_rtree_node(SplitStruct *node, int n_entries, double **d_buffer, int n_dim) { SplitStruct *cur; - SplitStruct *a; - SplitStruct *b; + SplitStruct *UNINIT_VAR(a), *UNINIT_VAR(b); double *g1 = reserve_coords(d_buffer, n_dim); double *g2 = reserve_coords(d_buffer, n_dim); - SplitStruct *next; - int next_node; + SplitStruct *UNINIT_VAR(next); + int UNINIT_VAR(next_node); int i; SplitStruct *end = node + n_entries; - LINT_INIT(a); - LINT_INIT(b); - LINT_INIT(next); - LINT_INIT(next_node); if (all_size < min_size * 2) {