1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

automatic merge with 5.5

This commit is contained in:
Michael Widenius
2012-06-27 17:22:23 +03:00
266 changed files with 7531 additions and 2398 deletions

View File

@ -1,6 +1,7 @@
Copyright (c) 2009, 2010 Sun Microsystems, Inc. Copyright (c) 2009, 2010 Sun Microsystems, Inc.
Copyright (c) 2012 Monty Program Ab
How to Build MySQL server with CMake How to Build MariaDB server with CMake
WHAT YOU NEED WHAT YOU NEED
--------------------------------------------------------------- ---------------------------------------------------------------
@ -11,7 +12,7 @@ HOW TO INSTALL:
Linux distributions: Linux distributions:
shell> sudo apt-get install cmake shell> sudo apt-get install cmake
The above works on do Debian/Ubuntu based distributions.On others, command The above works on Debian/Ubuntu based distributions. On others, the command
line needs to be modified to e.g "yum install" on Fedora or "zypper install" line needs to be modified to e.g "yum install" on Fedora or "zypper install"
on OpenSUSE. on OpenSUSE.
@ -20,8 +21,9 @@ shell> pfexec pkgadd install SUNWcmake
Windows and Mac OSX: Windows and Mac OSX:
Download and install the latest distribution from Download and install the latest distribution from
http://www.cmake.org/cmake/resources/software.html.On Windows, download http://www.cmake.org/cmake/resources/software.html
installer exe file and run it. On Mac, download the .dmg image and open it. On Windows, download installer exe file and run it. On MacOS, download
the .dmg image and open it.
Other Unixes: Other Unixes:
Precompiled packages for other Unix flavors (HPUX, AIX) are available from Precompiled packages for other Unix flavors (HPUX, AIX) are available from
@ -243,3 +245,4 @@ later corrected, the cached result is still used. If you encounter this
situation, which should be a rare occation, you need either to remove the situation, which should be a rare occation, you need either to remove the
offending entry from CMakeCache.txt (if test was for HAVE_FOO, remove lines offending entry from CMakeCache.txt (if test was for HAVE_FOO, remove lines
containing HAVE_FOO from CMakeCache.txt) or just remove the cache file. containing HAVE_FOO from CMakeCache.txt) or just remove the cache file.

View File

@ -131,6 +131,10 @@ IF (NOT CPACK_GENERATOR)
ENDIF(WIN32) ENDIF(WIN32)
ENDIF(NOT CPACK_GENERATOR) ENDIF(NOT CPACK_GENERATOR)
IF(DEB)
SET(INSTALL_LAYOUT "DEB")
ENDIF(DEB)
INCLUDE(mysql_version) INCLUDE(mysql_version)
INCLUDE(cpack_rpm) INCLUDE(cpack_rpm)
INCLUDE(cpack_source_ignore_files) INCLUDE(cpack_source_ignore_files)

View File

@ -31,7 +31,7 @@ also applies.
first. first.
If you run into problems and need to file a bug report, If you run into problems and need to file a bug report,
please report them to: http://bugs.launchpad.net/maria please report them to: http://mariadb.org/jira
See the instructions in Section 1.6, "How to Report Bugs or Problems." See the instructions in Section 1.6, "How to Report Bugs or Problems."

View File

@ -1,10 +1,11 @@
MariaDB is in most aspects identical to MySQL. MariaDB is in most aspects identical to MySQL.
Differences between MySQL and MariaDB can be found at: Differences between MySQL and MariaDB can be found at:
http://askmonty.org/wiki/index.php/MariaDB_versus_MySQL http://kb.askmonty.org/en/mariadb-versus-mysql-features/
http://kb.askmonty.org/en/mariadb-versus-mysql-compatibility/
The MariaDB references manual can be found at: The MariaDB manual can be found at:
http://askmonty.org/wiki/index.php/Manual http://kb.askmonty.org/
The MySQL Reference Manual is available in various formats on The MySQL Reference Manual is available in various formats on
http://dev.mysql.com/doc; if you're interested in the DocBook XML http://dev.mysql.com/doc; if you're interested in the DocBook XML

View File

@ -1,3 +1,14 @@
Installing and Upgrading MariaDB
This file contains chapter two of the MySQL manual and describes how
to obtain and install MySQL. The instructions below are generally
applicable to both MySQL and MariaDB, but differ in some particulars
(like, for example, the GPG signing key we use is different).
Detailed, MariaDB-specific instructions are available at:
http://kb.askmonty.org/en/getting-installing-and-upgrading-mariadb/
- - - -
Chapter 2. Installing and Upgrading MySQL Chapter 2. Installing and Upgrading MySQL

View File

@ -1,2 +1,3 @@
Up-to-date instructions on MariaDB building on Windows can be found in http://kb.askmonty.org/en/building-mariadb-on-windows. Up-to-date instructions about building MariaDB on Windows can be found
at: http://kb.askmonty.org/en/building-mariadb-on-windows

View File

@ -1,35 +1,35 @@
This file should contain all know fatal bugs in the Mariadb and the This file should contain all known fatal bugs in Mariadb and the Aria
Maria storage engine for the last source or binary release. Minor storage engine for the last source or binary release. Minor bugs,
bugs, extensions and feature request and bugs found since this release extensions and feature requests, and bugs found since this release can
can be find in the MariaDB bugs database at: be found in the MariaDB bugs database at: http://mariadb.org/jira and
https://bugs.launchpad.net/maria and in the MySQL bugs databases at: in the MySQL bugs databases at: http://bugs.mysql.com/ (category
http://bugs.mysql.com/ (category "Maria storage engine"). "Maria storage engine").
There shouldn't normally be any bugs that affects normal operations in There should not normally be any bugs which affect normal operations
any MariaDB release. Still, there are always exceptions and edge cases in any MariaDB release. Still, there are always exceptions and edge
and that's what this file is for. cases and that is what this file is for.
If you have found a bug that is not listed here, please add it to If you have found a bug that is not listed here, please add it to
http://bugs.launchpad.net/maria so that we can either fix it for next http://mariadb.org/jira so we can either fix it for next release or in
release or in the worst case add it here for others to know! the worst case add it here for others to know!
IMPORTANT: IMPORTANT:
If you have been using the Maria storage engine with If you have been using the Maria (now Aria) storage engine with the
MySQL-5.1-Maria-alpha build and upgrading to a newer MariaDB you MUST MySQL-5.1-Maria-alpha build and are upgrading to a newer MariaDB you
run maria_chk --recover on all your Maria tables. This is because we MUST run [m]aria_chk --recover on all your Aria tables. This is because
made an incompatible change of how transaction id is stored and old we made an incompatible change with how the transaction id is stored
transaction id's must be reset! and old transaction id's must be reset!
cd mysql-data-directory cd mysql-data-directory
maria_chk --recover */*.MAI aria_chk --recover */*.MAI
As the Maria storage engine is now in beta we will do our best to not Going forward, we will do our best to not introduce any incompatible
introduce any incompatible changes in the data format for the Maria changes in the data format for Aria tables. If this would be ever be
tables; If this would be ever be needed, we will, if possible, support needed, we will, if possible, support both the old and the new version
both the old and the new version to make upgrades as easy as possible. to make upgrades as easy as possible.
Note that for the MariaDB 5.1 release the Maria storage engine is Note that for the MariaDB 5.1 release the Aria storage engine is
classified as 'beta'; It should work, but use it with caution. Please classified as 'beta'; It should work, but use it with caution. Please
report all bugs to https://bugs.launchpad.net/maria so that we can fix report all bugs to http://mariadb.org/jira so we can fix them!
them!

8
README
View File

@ -13,9 +13,9 @@ see the Credits appendix. You can also do 'SHOW authors' to get a
list of active contributors. list of active contributors.
A description of the MariaDB project and a manual can be found at: A description of the MariaDB project and a manual can be found at:
http://askmonty.org/wiki/index.php/MariaDB http://kb.askmonty.org/
http://askmonty.org/wiki/index.php/MariaDB_versus_MySQL http://kb.askmonty.org/en/mariadb-versus-mysql-features/
http://askmonty.org/wiki/index.php/Manual:Contents http://kb.askmonty.org/en/mariadb-versus-mysql-compatibility/
As MariaDB is a full replacement of MySQL, the MySQL manual at As MariaDB is a full replacement of MySQL, the MySQL manual at
http://dev.mysql.com/doc is generally applicable. http://dev.mysql.com/doc is generally applicable.
@ -41,7 +41,7 @@ EXCEPTIONS-CLIENT file.
IMPORTANT: IMPORTANT:
Bug and/or error reports regarding MariaDB should be submitted at Bug and/or error reports regarding MariaDB should be submitted at
https://bugs.launchpad.net/maria http://mariadb.org/jira
Bugs in the MySQL code can also be submitted at http://bugs.mysql.com Bugs in the MySQL code can also be submitted at http://bugs.mysql.com

View File

@ -2916,7 +2916,7 @@ com_help(String *buffer __attribute__((unused)),
} }
put_info("\nGeneral information about MariaDB can be found at\n" put_info("\nGeneral information about MariaDB can be found at\n"
"http://askmonty.org/wiki/index.php/Manual:Contents\n", INFO_INFO); "http://mariadb.org\n", INFO_INFO);
put_info("List of all MySQL commands:", INFO_INFO); put_info("List of all MySQL commands:", INFO_INFO);
if (!named_cmds) if (!named_cmds)
put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO); put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO);

View File

@ -86,6 +86,15 @@
/* Chars needed to store LONGLONG, excluding trailing '\0'. */ /* Chars needed to store LONGLONG, excluding trailing '\0'. */
#define LONGLONG_LEN 20 #define LONGLONG_LEN 20
/* general_log or slow_log tables under mysql database */
static inline my_bool general_log_or_slow_log_tables(const char *db,
const char *table)
{
return (strcmp(db, "mysql") == 0) &&
((strcmp(table, "general_log") == 0) ||
(strcmp(table, "slow_log") == 0));
}
static void add_load_option(DYNAMIC_STRING *str, const char *option, static void add_load_option(DYNAMIC_STRING *str, const char *option,
const char *option_value); const char *option_value);
static ulong find_set(TYPELIB *lib, const char *x, uint length, static ulong find_set(TYPELIB *lib, const char *x, uint length,
@ -2503,6 +2512,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
"TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'"; "TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
FILE *sql_file= md_result_file; FILE *sql_file= md_result_file;
int len; int len;
my_bool is_log_table;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
DBUG_ENTER("get_table_structure"); DBUG_ENTER("get_table_structure");
@ -2587,9 +2597,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
/* /*
Even if the "table" is a view, we do a DROP TABLE here. The Even if the "table" is a view, we do a DROP TABLE here. The
view-specific code below fills in the DROP VIEW. view-specific code below fills in the DROP VIEW.
We will skip the DROP TABLE for general_log and slow_log, since
those stmts will fail, in case we apply dump by enabling logging.
*/ */
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", if (!general_log_or_slow_log_tables(db, table))
opt_quoted_table); fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
opt_quoted_table);
check_io(sql_file); check_io(sql_file);
} }
@ -2701,12 +2714,25 @@ static uint get_table_structure(char *table, char *db, char *table_type,
row= mysql_fetch_row(result); row= mysql_fetch_row(result);
fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" : is_log_table= general_log_or_slow_log_tables(db, table);
"/*!40101 SET @saved_cs_client = @@character_set_client */;\n" if (is_log_table)
"/*!40101 SET character_set_client = utf8 */;\n" row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */
"%s;\n" if (opt_compatible_mode & 3)
"/*!40101 SET character_set_client = @saved_cs_client */;\n", {
row[1]); fprintf(sql_file,
is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n",
row[1]);
}
else
{
fprintf(sql_file,
"/*!40101 SET @saved_cs_client = @@character_set_client */;\n"
"/*!40101 SET character_set_client = utf8 */;\n"
"%s%s;\n"
"/*!40101 SET character_set_client = @saved_cs_client */;\n",
is_log_table ? "CREATE TABLE IF NOT EXISTS " : "",
row[1]);
}
check_io(sql_file); check_io(sql_file);
mysql_free_result(result); mysql_free_result(result);
@ -4315,6 +4341,22 @@ static int dump_all_tables_in_db(char *database)
if (opt_xml) if (opt_xml)
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
if (strcmp(database, "mysql") == 0)
{
char table_type[NAME_LEN];
char ignore_flag;
uint num_fields;
num_fields= get_table_structure((char *) "general_log",
database, table_type, &ignore_flag);
if (num_fields == 0)
verbose_msg("-- Warning: get_table_structure() failed with some internal "
"error for 'general_log' table\n");
num_fields= get_table_structure((char *) "slow_log",
database, table_type, &ignore_flag);
if (num_fields == 0)
verbose_msg("-- Warning: get_table_structure() failed with some internal "
"error for 'slow_log' table\n");
}
if (lock_tables) if (lock_tables)
{ {
DYNAMIC_STRING query; DYNAMIC_STRING query;
@ -4775,7 +4817,7 @@ static int do_show_slave_status(MYSQL *mysql_con)
if (row[1]) if (row[1])
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]); fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
if (row[3]) if (row[3])
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]); fprintf(md_result_file, "MASTER_PORT=%s, ", row[3]);
} }
fprintf(md_result_file, fprintf(md_result_file,
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]); "MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);

View File

@ -9012,8 +9012,12 @@ int main(int argc, char **argv)
command->abort_on_error= (command->expected_errors.count == 0 && command->abort_on_error= (command->expected_errors.count == 0 &&
abort_on_error); abort_on_error);
/* delimiter needs to be executed so we can continue to parse */ /*
ok_to_do= cur_block->ok || command->type == Q_DELIMITER; some commmands need to be executed or at least parsed unconditionally,
because they change the grammar.
*/
ok_to_do= cur_block->ok || command->type == Q_DELIMITER
|| command->type == Q_PERL;
/* /*
Some commands need to be "done" the first time if they may get Some commands need to be "done" the first time if they may get
re-iterated over in a true context. This can only happen if there's re-iterated over in a true context. This can only happen if there's
@ -9024,8 +9028,7 @@ int main(int argc, char **argv)
if (command->type == Q_SOURCE || if (command->type == Q_SOURCE ||
command->type == Q_ERROR || command->type == Q_ERROR ||
command->type == Q_WRITE_FILE || command->type == Q_WRITE_FILE ||
command->type == Q_APPEND_FILE || command->type == Q_APPEND_FILE)
command->type == Q_PERL)
{ {
for (struct st_block *stb= cur_block-1; stb >= block_stack; stb--) for (struct st_block *stb= cur_block-1; stb >= block_stack; stb--)
{ {

View File

@ -94,8 +94,19 @@ IF(FEATURE_SET)
ENDIF() ENDIF()
OPTION(ENABLED_LOCAL_INFILE "" ON) OPTION(ENABLED_LOCAL_INFILE "" ON)
SET(WITH_SSL bundled CACHE STRING "") IF(RPM)
SET(WITH_ZLIB bundled CACHE STRING "") SET(WITH_SSL system CACHE STRING "")
SET(WITH_ZLIB system CACHE STRING "")
ELSEIF(DEB)
SET(WITH_SSL system CACHE STRING "")
SET(WITH_ZLIB system CACHE STRING "")
SET(WITH_LIBWRAP ON)
SET(WITH_MAX ON)
SET(HAVE_EMBEDDED_PRIVILEGE_CONTROL ON)
ELSE()
SET(WITH_SSL bundled CACHE STRING "")
SET(WITH_ZLIB bundled CACHE STRING "")
ENDIF()
IF(NOT COMPILATION_COMMENT) IF(NOT COMPILATION_COMMENT)
SET(COMPILATION_COMMENT "MariaDB Server") SET(COMPILATION_COMMENT "MariaDB Server")

View File

@ -3,7 +3,7 @@
[client] [client]
# Default is Latin1, if you need UTF-8 set this (also in server section) # Default is Latin1, if you need UTF-8 set this (also in server section)
#character-set-server = utf8 #default-character-set = utf8
[mysqld] [mysqld]
# #

View File

@ -124,8 +124,9 @@ Provides: virtual-mysql-client, mysql-client,
mysql-client-4.1, mysql-client-5.1, mysql-client-5.5 mysql-client-4.1, mysql-client-5.1, mysql-client-5.5
Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1,
mariadb-client (<< ${source:Version}), mariadb-client (<< ${source:Version}),
mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3, mysql-client-5.5
Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1,
mysql-client-5.5,
mariadb-client (<< ${source:Version}), mariadb-client (<< ${source:Version}),
mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3
Description: MariaDB database client binaries Description: MariaDB database client binaries
@ -185,10 +186,10 @@ Pre-Depends: mariadb-common, adduser (>= 3.40), debconf
Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version}) Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version})
Provides: mariadb-server, mysql-server, virtual-mysql-server Provides: mariadb-server, mysql-server, virtual-mysql-server
Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}),
mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5,
mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3 mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3
Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}),
mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5,
mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3,
libmariadbclient16 (<< 5.3.4), libmariadbclient16 (<< 5.3.4),
libmariadbclient-dev (<< 5.5.0) libmariadbclient-dev (<< 5.5.0)

View File

@ -70,30 +70,11 @@ endif
CXX=$${MYSQL_BUILD_CXX:-g++} \ CXX=$${MYSQL_BUILD_CXX:-g++} \
CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \ CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \
cmake .. \ cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DINSTALL_SBINDIR=sbin \
-DMYSQL_DATADIR=/var/lib/mysql \
-DINSTALL_INCLUDEDIR=include/mysql \
-DINSTALL_INFODIR=share/info \
-DINSTALL_MANDIR=share/man \
\
-DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \ -DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \
-DBUILD_CONFIG=mysql_release \
-DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DCOMPILATION_COMMENT="mariadb.org binary distribution" \
-DSYSTEM_TYPE="debian-linux-gnu" \ -DSYSTEM_TYPE="debian-linux-gnu" \
-DINSTALL_LAYOUT=DEB \ -DDEB=debian'
\
-DENABLED_LOCAL_INFILE=1 \
-DWITH_FAST_MUTEXES=1 \
\
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
\
-DEXTRA_CHARSETS=all \
-DWITH_LIBWRAP=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DHAVE_EMBEDDED_PRIVILEGE_CONTROL=ON \
-DWITH_MAX=1'
touch $@ touch $@

View File

@ -124,8 +124,9 @@ Provides: virtual-mysql-client, mysql-client,
mysql-client-4.1, mysql-client-5.1, mysql-client-5.5 mysql-client-4.1, mysql-client-5.1, mysql-client-5.5
Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, Conflicts: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1,
mariadb-client (<< ${source:Version}), mariadb-client (<< ${source:Version}),
mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3, mysql-client-5.5
Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1, Replaces: mysql-client (<< 5.0.51), mysql-client-5.0, mysql-client-5.1,
mysql-client-5.5,
mariadb-client (<< ${source:Version}), mariadb-client (<< ${source:Version}),
mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3 mariadb-client-5.1, mariadb-client-5.2, mariadb-client-5.3
Description: MariaDB database client binaries Description: MariaDB database client binaries
@ -179,10 +180,10 @@ Pre-Depends: mariadb-common, adduser (>= 3.40), debconf
Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version}) Depends: mariadb-client-5.5 (>= ${source:Version}), libdbi-perl, perl (>= 5.6), ${shlibs:Depends}, ${misc:Depends}, psmisc, passwd, lsb-base (>= 3.0-10), mariadb-server-core-5.5 (>= ${binary:Version})
Provides: mariadb-server, mysql-server, virtual-mysql-server Provides: mariadb-server, mysql-server, virtual-mysql-server
Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), Conflicts: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}),
mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5,
mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3 mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3
Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}), Replaces: mariadb-server (<< ${source:Version}), mysql-server (<< ${source:Version}),
mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-4.1, mysql-server-5.0, mysql-server-5.1, mysql-server-5.5,
mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3, mariadb-server-5.1, mariadb-server-5.2, mariadb-server-5.3,
libmariadbclient16 (<< 5.3.4), libmariadbclient16 (<< 5.3.4),
libmariadbclient-dev (<< 5.5.0) libmariadbclient-dev (<< 5.5.0)

View File

@ -70,30 +70,11 @@ endif
CXX=$${MYSQL_BUILD_CXX:-g++} \ CXX=$${MYSQL_BUILD_CXX:-g++} \
CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \ CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wno-uninitialized"} \
cmake .. \ cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DINSTALL_SBINDIR=sbin \
-DMYSQL_DATADIR=/var/lib/mysql \
-DINSTALL_INCLUDEDIR=include/mysql \
-DINSTALL_INFODIR=share/info \
-DINSTALL_MANDIR=share/man \
\
-DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \ -DMYSQL_SERVER_SUFFIX="-$(DEBVERSION)" \
-DBUILD_CONFIG=mysql_release \
-DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DCOMPILATION_COMMENT="mariadb.org binary distribution" \
-DSYSTEM_TYPE="debian-linux-gnu" \ -DSYSTEM_TYPE="debian-linux-gnu" \
-DINSTALL_LAYOUT=DEB \ -DDEB=ubuntu'
\
-DENABLED_LOCAL_INFILE=1 \
-DWITH_FAST_MUTEXES=1 \
\
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
\
-DEXTRA_CHARSETS=all \
-DWITH_LIBWRAP=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DHAVE_EMBEDDED_PRIVILEGE_CONTROL=ON \
-DWITH_MAX=1'
touch $@ touch $@

View File

@ -148,9 +148,10 @@ typedef struct st_key_cache
ulonglong param_partitions; /* number of the key cache partitions */ ulonglong param_partitions; /* number of the key cache partitions */
my_bool key_cache_inited; /* <=> key cache has been created */ my_bool key_cache_inited; /* <=> key cache has been created */
my_bool can_be_used; /* usage of cache for read/write is allowed */ my_bool can_be_used; /* usage of cache for read/write is allowed */
my_bool in_init; /* Set to 1 in MySQL during init/resize */ my_bool in_init; /* set to 1 in MySQL during init/resize */
uint partitions; /* actual number of partitions */ uint partitions; /* actual number of partitions */
size_t key_cache_mem_size; /* specified size of the cache memory */ size_t key_cache_mem_size; /* specified size of the cache memory */
pthread_mutex_t op_lock; /* to serialize operations like 'resize' */
} KEY_CACHE; } KEY_CACHE;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -10,8 +10,8 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software Foundation, Inc.,
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
/* /*
* Vio Lite. * Vio Lite.

View File

@ -69,10 +69,10 @@ extension. For example:
If you want to submit your test case you can send it If you want to submit your test case you can send it
to maria-developers@lists.launchpad.com or attach it to a bug report on to maria-developers@lists.launchpad.com or attach it to a bug report on
https://bugs.launchpad.net/maria/. http://mariadb.org/jira/.
If the test case is really big or if it contains 'not public' data, If the test case is really big or if it contains 'not public' data,
then put your .test file and .result file(s) into a tar.gz archive, then put your .test file and .result file(s) into a tar.gz archive,
add a README that explains the problem, ftp the archive to add a README that explains the problem, ftp the archive to
ftp://ftp.askmonty.org/private and send a mail to ftp://ftp.askmonty.org/private and submit a report to
https://bugs.launchpad.net/maria/ about it. http://mariadb.org/jira about it.

View File

@ -1518,7 +1518,7 @@ sub command_line_setup {
# We make the path absolute, as the server will do a chdir() before usage # We make the path absolute, as the server will do a chdir() before usage
unless ( $opt_vardir =~ m,^/, or unless ( $opt_vardir =~ m,^/, or
(IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) ) (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:[/\\],i) )
{ {
# Make absolute path, relative test dir # Make absolute path, relative test dir
$opt_vardir= "$glob_mysql_test_dir/$opt_vardir"; $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
@ -2717,6 +2717,7 @@ sub setup_vardir() {
# hm, what paths work for debs and for rpms ? # hm, what paths work for debs and for rpms ?
for (<$bindir/lib64/mysql/plugin/*.so>, for (<$bindir/lib64/mysql/plugin/*.so>,
<$bindir/lib/mysql/plugin/*.so>, <$bindir/lib/mysql/plugin/*.so>,
<$bindir/lib/plugin/*.so>, # bintar
<$bindir/lib/plugin/*.dll>) <$bindir/lib/plugin/*.dll>)
{ {
my $pname=basename($_); my $pname=basename($_);
@ -3463,12 +3464,6 @@ sub mysql_install_db {
mtr_add_arg($args, "--lc-messages-dir=%s", $install_lang); mtr_add_arg($args, "--lc-messages-dir=%s", $install_lang);
mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir); mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir);
# On some old linux kernels, aio on tmpfs is not supported
# Remove this if/when Bug #58421 fixes this in the server
if ($^O eq "linux" && $opt_mem) {
mtr_add_arg($args, "--loose-skip-innodb-use-native-aio");
}
# InnoDB arguments that affect file location and sizes may # InnoDB arguments that affect file location and sizes may
# need to be given to the bootstrap process as well as the # need to be given to the bootstrap process as well as the
# server process. # server process.
@ -4743,6 +4738,7 @@ sub extract_warning_lines ($$) {
qr|Access denied for user|, qr|Access denied for user|,
qr|Aborted connection|, qr|Aborted connection|,
qr|table.*is full|, qr|table.*is full|,
qr|Linux Native AIO|, # warning that aio does not work on /dev/shm
); );
my $matched_lines= []; my $matched_lines= [];
@ -5246,13 +5242,6 @@ sub mysqld_arguments ($$$) {
mtr_add_arg($args, "--user=root"); mtr_add_arg($args, "--user=root");
} }
# On some old linux kernels, aio on tmpfs is not supported
# Remove this if/when Bug #58421 fixes this in the server
if ($^O eq "linux" && $opt_mem)
{
mtr_add_arg($args, "--loose-skip-innodb-use-native-aio");
}
if (!using_extern() and !$opt_user_args) if (!using_extern() and !$opt_user_args)
{ {
# Turn on logging to file # Turn on logging to file
@ -5293,6 +5282,7 @@ sub mysqld_arguments ($$$) {
} }
elsif ($plugin = mtr_match_prefix($arg, "--plugin-load=")) elsif ($plugin = mtr_match_prefix($arg, "--plugin-load="))
{ {
next if $plugin =~ /=$/;
push @plugins, $plugin unless $seen{$plugin}; push @plugins, $plugin unless $seen{$plugin};
$seen{$plugin} = 1; $seen{$plugin} = 1;
} }

View File

@ -0,0 +1,56 @@
#
# Bug#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE.
#
create database show_table_lw_db;
use show_table_lw_db;
create table t1 (c1 int);
create table t2 (c1 int);
create table t3 (c1 int);
create table t4 (c1 int);
create table t5 (c1 int);
create table t6 (c1 int);
create table t7 (c1 int);
create table t8 (c1 int);
create table t9 (c1 int);
create table t10 (c1 int);
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_before;
show tables;
Tables_in_show_table_lw_db
t1
t10
t2
t3
t4
t5
t6
t7
t8
t9
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_after;
select @count_read_after-@count_read_before;
@count_read_after-@count_read_before
0.000000000000000000000000000000
show full tables;
Tables_in_show_table_lw_db Table_type
t1 BASE TABLE
t10 BASE TABLE
t2 BASE TABLE
t3 BASE TABLE
t4 BASE TABLE
t5 BASE TABLE
t6 BASE TABLE
t7 BASE TABLE
t8 BASE TABLE
t9 BASE TABLE
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_after;
select @count_read_after-@count_read_before;
@count_read_after-@count_read_before
10.000000000000000000000000000000
drop table t1;
drop database show_table_lw_db;

View File

@ -161,24 +161,24 @@ prepare stmt1 from @stmt ;
execute stmt1 ; execute stmt1 ;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
execute stmt1 ; execute stmt1 ;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25; explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
deallocate prepare stmt1; deallocate prepare stmt1;
drop tables t1,t2; drop tables t1,t2;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;

View File

@ -1682,7 +1682,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and `test`.`t2`.`b`) Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`b` <> 0))
SELECT t.b, t.c, t1.a SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b AND t.c = t1.a; WHERE t.b AND t.c = t1.a;
@ -1713,7 +1713,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on((`test`.`t3`.`b` = `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and `test`.`t2`.`b`) Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on((`test`.`t3`.`b` = `test`.`t2`.`a`)) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`b` <> 0))
SELECT t.b, t.c, t1.a SELECT t.b, t.c, t1.a
FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t FROM t1, (SELECT t2.b, t2.c FROM t3 RIGHT JOIN t2 ON t2.a = t3.b) AS t
WHERE t.b AND t.c = t1.a; WHERE t.b AND t.c = t1.a;

View File

@ -225,10 +225,10 @@ INSERT INTO t2 VALUES (NULL), (0);
EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1; EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
Note 1003 select <expr_cache><NULL>((select 1 from `test`.`t2` where (`test`.`t2`.`d` = NULL))) AS `(SELECT 1 FROM t2 WHERE d = c)` from dual Note 1003 select (select 1 from `test`.`t2` where (`test`.`t2`.`d` = NULL)) AS `(SELECT 1 FROM t2 WHERE d = c)` from dual
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# Bug#30302: Tables that were optimized away are printed in the # Bug#30302: Tables that were optimized away are printed in the
@ -260,7 +260,7 @@ FLUSH TABLES;
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT 1 FROM t1 t JOIN t2 WHERE b <= 1 AND t.a); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT 1 FROM t1 t JOIN t2 WHERE b <= 1 AND t.a);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# Bug #48573: difference of index selection between rpm binary and # Bug #48573: difference of index selection between rpm binary and
@ -287,7 +287,7 @@ WHERE t1.f1 GROUP BY t1.f1));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where 2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1
PREPARE stmt FROM PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1 'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a
@ -297,12 +297,12 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where 2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where 2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
PREPARE stmt FROM PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1 'EXPLAIN SELECT 1 FROM t1
@ -313,12 +313,12 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where 2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where 2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
DROP TABLE t1; DROP TABLE t1;
End of 5.1 tests. End of 5.1 tests.

View File

@ -204,4 +204,30 @@ SELECT BIT_XOR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
BIT_XOR(t1.b) BIT_XOR(t1.b)
0 0
DROP TABLE t1, t2; DROP TABLE t1, t2;
#
# Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY
# COUNT(*) LIMIT.
#
CREATE TABLE t1 (
id BIGINT(20) ,
member_id_to INT(11) ,
r_date DATE ,
PRIMARY KEY (id,r_date),
KEY r_date_idx (r_date),
KEY t1_idx01 (member_id_to)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES
(107924526,518491,'2011-05-01'),
(107924527,518491,'2011-05-01'),
(107924534,518491,'2011-06-21'),
(107924535,518491,'2011-06-21'),
(107924542,1601319,'2011-06-21'),
(107924543,1601319,'2011-06-21'),
(107924544,1601319,'2011-06-21'),
(107924545,1601319,'2011-06-21');
SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
'2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
member_id_to COUNT(*)
518491 2
DROP TABLE t1;
End of 5.5 tests End of 5.5 tests

View File

@ -789,3 +789,26 @@ DROP TABLE t1;
# End of test BUG#13012483 # End of test BUG#13012483
# #
End of 5.1 tests End of 5.1 tests
create table t1 (a bigint, b int);
insert t1 values (1,1),(2,2),(3,3);
select * from t1 where a in ('2.1');
a b
select * from t1 where b in ('2.1');
a b
select * from t1 where a='2.1';
a b
select * from t1 where b='2.1';
a b
select * from t1 where IF(1,a,a)='2.1';
a b
drop table t1;
#
# LP bug#992380 Crash when creating PS for a query with
# subquery in WHERE (see also mysql bug#13012483)
#
CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;
1
DROP TABLE t1;
# End of 5.3 tests

View File

@ -279,3 +279,44 @@ NULL
SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL;
GREATEST(1.5E+2,1.3E+2,NULL) GREATEST(1.5E+2,1.3E+2,NULL)
NULL NULL
create table t1 (a int);
insert into t1 values (1), (100), (0), (NULL);
select not a from t1;
not a
0
0
1
NULL
explain extended select not a from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00
Warnings:
Note 1003 select (`test`.`t1`.`a` = 0) AS `not a` from `test`.`t1`
select * from t1 where not a;
a
0
explain extended select * from t1 where not a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0)
select not (a+0) from t1;
not (a+0)
0
0
1
NULL
explain extended select not (a+0) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00
Warnings:
Note 1003 select (not((`test`.`t1`.`a` + 0))) AS `not (a+0)` from `test`.`t1`
select * from t1 where not (a+0);
a
0
explain extended select * from t1 where not (a+0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not((`test`.`t1`.`a` + 0)))
drop table t1;

View File

@ -2398,12 +2398,12 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index 1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index
2 SUBQUERY t1 index NULL a 10 NULL 1 Using index 2 SUBQUERY t1 index NULL a 10 NULL 15 Using index
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by 2 SUBQUERY t1 index NULL a 10 NULL 15 Using index
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -2419,9 +2419,9 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2
ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2)
AND t1_outer1.b = t1_outer2.b; AND t1_outer1.b = t1_outer2.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer1 ref a a 5 const 2 Using where; Using index 1 PRIMARY t1_outer1 ref a a 5 const 1 Using where; Using index
1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join) 1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by 2 SUBQUERY t1 index NULL a 10 NULL 15 Using index
EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x
FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2; FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -2756,8 +2756,8 @@ NULL
EXPLAIN EXPLAIN
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
x x x x x x x x x Using where; Using index x x x x x x x x x Impossible WHERE noticed after reading const tables
x x x x x x x x x Using where; Using index x x x x x x x x x Using index
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
MIN( a ) MIN( a )
NULL NULL
@ -2828,8 +2828,8 @@ NULL
EXPLAIN EXPLAIN
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
x x x x x x x x x Using where; Using index x x x x x x x x x Impossible WHERE noticed after reading const tables
x x x x x x x x x Using where; Using index x x x x x x x x x Using index
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
MIN( a ) MIN( a )
NULL NULL
@ -2907,8 +2907,8 @@ NULL
EXPLAIN EXPLAIN
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
x x x x x x x x x Using where; Using index x x x x x x x x x Impossible WHERE noticed after reading const tables
x x x x x x x x x Using where; Using index x x x x x x x x x Using index
SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0); SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
MIN( a ) MIN( a )
NULL NULL

View File

@ -654,7 +654,7 @@ EXPLAIN SELECT t1.f1 FROM t1
WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; 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 id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index
2 DEPENDENT SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index 2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
# BUG#56862/640419: Wrong result with sort_union index merge when one # BUG#56862/640419: Wrong result with sort_union index merge when one

View File

@ -1487,7 +1487,7 @@ EXPLAIN SELECT t1.f1 FROM t1
WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; 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 id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
2 DEPENDENT SUBQUERY t2 ref f2,f3 f2 5 const 1 Using where 2 SUBQUERY t2 ref f2,f3 f2 5 const 1 Using where
DROP TABLE t1,t2; DROP TABLE t1,t2;
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

View File

@ -1895,10 +1895,10 @@ EXPLAIN EXTENDED
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where 1 Note 1003 select NULL AS `a` from `test`.`t2` where 1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
# #
# LP bug #817384 Wrong result with outer join + subquery in ON # LP bug #817384 Wrong result with outer join + subquery in ON

View File

@ -1906,10 +1906,10 @@ EXPLAIN EXTENDED
SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3); SELECT t2.a FROM t1 LEFT JOIN t2 ON (6) IN (SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where 1 Note 1003 select NULL AS `a` from `test`.`t2` where 1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
# #
# LP bug #817384 Wrong result with outer join + subquery in ON # LP bug #817384 Wrong result with outer join + subquery in ON

View File

@ -598,8 +598,8 @@ VALUES
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t1 range NULL a 5 NULL 8 Using index for group-by 2 SUBQUERY t1 index NULL a 10 NULL 15 Using index
SELECT 1 as RES FROM t1 AS t1_outer WHERE SELECT 1 as RES FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
RES RES

View File

@ -679,7 +679,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 Using temporary 1 PRIMARY t1 system NULL NULL NULL NULL 1 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Distinct 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Distinct
2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 2 SUBQUERY t3 ALL NULL NULL NULL NULL 3
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t2 ALL NULL NULL NULL NULL 3
SELECT DISTINCT a AS field1 FROM t1, t2 SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;

View File

@ -0,0 +1,22 @@
set names swe7;
select '' in ('',convert(0,time));
'' in ('',convert(0,time))
1
select case '' when '' then 1 when convert(0,time) then 2 end;
case '' when '' then 1 when convert(0,time) then 2 end
1
select convert(0x0030 using ucs2) div 1, concat(convert(0x0030 using ucs2)) div 1;
convert(0x0030 using ucs2) div 1 concat(convert(0x0030 using ucs2)) div 1
0 0
select cast(convert(0x0030 using ucs2) as double), cast(concat(convert(0x0030 using ucs2)) as double);
cast(convert(0x0030 using ucs2) as double) cast(concat(convert(0x0030 using ucs2)) as double)
0 0
select cast(convert(0x0030 using ucs2) as decimal(5.2)), cast(concat(convert(0x0030 using ucs2)) as decimal(5.2));
cast(convert(0x0030 using ucs2) as decimal(5.2)) cast(concat(convert(0x0030 using ucs2)) as decimal(5.2))
0 0
select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date);
cast(convert(_ucs2 0x0030 using latin1) as date) cast(concat(convert(_ucs2 0x0030 using latin1)) as date)
NULL NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'

View File

@ -349,10 +349,10 @@ WHERE t2.int_key IS NULL
GROUP BY t2.pk GROUP BY t2.pk
); );
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 ref int_key int_key 5 const 1 100.00 Using index condition 2 SUBQUERY t2 ref int_key int_key 5 const 1 100.00 Using index condition
Warnings: Warnings:
Note 1003 select min(1) AS `MIN(t1.pk)` from dual where exists(select `test`.`t2`.`pk` from `test`.`t2` where isnull(`test`.`t2`.`int_key`)) Note 1003 select min(`test`.`t1`.`pk`) AS `MIN(t1.pk)` from `test`.`t1` where 0
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# BUG#42048 Discrepancy between MyISAM and Maria's ICP implementation # BUG#42048 Discrepancy between MyISAM and Maria's ICP implementation

View File

@ -159,6 +159,10 @@ The following options may be given as the first argument:
Enable the event scheduler. Possible values are ON, OFF, Enable the event scheduler. Possible values are ON, OFF,
and DISABLED (keep the event scheduler completely and DISABLED (keep the event scheduler completely
deactivated, it cannot be activated run-time) deactivated, it cannot be activated run-time)
--expensive-subquery-limit=#
The maximum number of rows a subquery may examine in
order to be executed during optimization and used for
constant optimization
--expire-logs-days=# --expire-logs-days=#
If non-zero, binary logs will be purged after If non-zero, binary logs will be purged after
expire_logs_days days; possible purges happen at startup expire_logs_days days; possible purges happen at startup
@ -885,6 +889,7 @@ delayed-queue-size 1000
div-precision-increment 4 div-precision-increment 4
engine-condition-pushdown FALSE engine-condition-pushdown FALSE
event-scheduler OFF event-scheduler OFF
expensive-subquery-limit 100
expire-logs-days 0 expire-logs-days 0
external-locking FALSE external-locking FALSE
extra-max-connections 1 extra-max-connections 1

View File

@ -5222,3 +5222,48 @@ DROP DATABASE b12809202_db;
# Delete all existing binary logs. # Delete all existing binary logs.
# #
RESET MASTER; RESET MASTER;
#
# Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM
#
SET @old_log_output_state= @@global.log_output;
SET @old_general_log_state= @@global.general_log;
SET @old_slow_query_log_state= @@global.slow_query_log;
call mtr.add_suppression("Failed to write to mysql.general_log");
SET @@global.log_output="TABLE";
SET @@global.general_log='OFF';
SET @@global.slow_query_log='OFF';
DROP DATABASE mysql;
Warnings:
Error 1146 Table 'mysql.proc' doesn't exist
Error 1146 Table 'mysql.event' doesn't exist
SHOW CREATE TABLE mysql.general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`command_type` varchar(64) NOT NULL,
`argument` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'
SHOW CREATE TABLE mysql.slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
`rows_sent` int(11) NOT NULL,
`rows_examined` int(11) NOT NULL,
`db` varchar(512) NOT NULL,
`last_insert_id` int(11) NOT NULL,
`insert_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
SET @@global.log_output= @old_log_output_state;
SET @@global.slow_query_log= @old_slow_query_log_state;
SET @@global.general_log= @old_general_log_state;
#
# End of 5.1 tests
#

View File

@ -0,0 +1 @@
# Done

View File

@ -321,7 +321,7 @@ select * from t1 where not(NULL or a);
a a
explain select * from t1 where not(NULL and a); explain select * from t1 where not(NULL and a);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL a 5 NULL 21 Using where; Using index 1 SIMPLE t1 ref a a 5 const 1 Using index
select * from t1 where not(NULL and a); select * from t1 where not(NULL and a);
a a
0 0
@ -502,5 +502,5 @@ explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index 1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or `test`.`t1`.`a`) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or (`test`.`t1`.`a` <> 0)) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0)
drop table t1; drop table t1;

View File

@ -2461,3 +2461,15 @@ SELECT 1 FROM t1 JOIN t1 AS t2 USING (a);
1 1
1 1
drop table t1; drop table t1;
#
# LP BUG#1001117 Crash on a simple select that uses a temptable view
# MySQL Bug #12330344 Crash and/or valgrind errors in free_io_cache with join, view,
# partitioned table
#
CREATE TABLE t1(a INT PRIMARY KEY) PARTITION BY LINEAR KEY (a);
CREATE ALGORITHM=TEMPTABLE VIEW vtmp AS
SELECT 1 FROM t1 AS t1_0 JOIN t1 ON t1_0.a LIKE (SELECT 1 FROM t1);
SELECT * FROM vtmp;
1
DROP VIEW vtmp;
DROP TABLE t1;

View File

@ -160,26 +160,26 @@ execute stmt1 ;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
execute stmt1 ; execute stmt1 ;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25; explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table 6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
5 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 4 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
deallocate prepare stmt1; deallocate prepare stmt1;
set optimizer_switch=@tmp_optimizer_switch; set optimizer_switch=@tmp_optimizer_switch;
drop tables t1,t2; drop tables t1,t2;
@ -255,15 +255,15 @@ deallocate prepare StMt1;
deallocate prepare Stmt1; deallocate prepare Stmt1;
ERROR HY000: Unknown prepared statement handler (Stmt1) given to DEALLOCATE PREPARE ERROR HY000: Unknown prepared statement handler (Stmt1) given to DEALLOCATE PREPARE
set names utf8; set names utf8;
prepare `ü` from 'select 1234'; prepare `ü` from 'select 1234';
execute `ü` ; execute `ü` ;
1234 1234
1234 1234
set names latin1; set names latin1;
execute `<EFBFBD>`; execute `ü`;
1234 1234
1234 1234
deallocate prepare `<EFBFBD>`; deallocate prepare `ü`;
set names default; set names default;
create table t1 (a varchar(10)) charset=utf8; create table t1 (a varchar(10)) charset=utf8;
insert into t1 (a) values ('yahoo'); insert into t1 (a) values ('yahoo');
@ -3055,6 +3055,62 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1; DROP TABLE t1;
End of 5.1 tests. End of 5.1 tests.
#
# LP bug#1001500 Crash on the second execution of the PS for
# a query with degenerated conjunctive condition
# (see also mysql bug#12582849)
#
CREATE TABLE t1 (
pk INTEGER AUTO_INCREMENT,
col_int_nokey INTEGER,
col_int_key INTEGER,
col_varchar_key VARCHAR(1),
col_varchar_nokey VARCHAR(1),
PRIMARY KEY (pk),
KEY (col_int_key),
KEY (col_varchar_key, col_int_key)
);
INSERT INTO t1 (
col_int_key, col_int_nokey,
col_varchar_key, col_varchar_nokey
) VALUES
(4, 2, 'v', 'v'),
(62, 150, 'v', 'v');
CREATE TABLE t2 (
pk INTEGER AUTO_INCREMENT,
col_int_nokey INTEGER,
col_int_key INTEGER,
col_varchar_key VARCHAR(1),
col_varchar_nokey VARCHAR(1),
PRIMARY KEY (pk),
KEY (col_int_key),
KEY (col_varchar_key, col_int_key)
);
INSERT INTO t2 (
col_int_key, col_int_nokey,
col_varchar_key, col_varchar_nokey
) VALUES
(8, NULL, 'x', 'x'),
(7, 8, 'd', 'd');
PREPARE stmt FROM '
SELECT
( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1
FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2
ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey )
)
WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk
) AS field1
FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk )
GROUP BY field1
';
EXECUTE stmt;
field1
150
EXECUTE stmt;
field1
150
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2;
# #
# WL#4435: Support OUT-parameters in prepared statements. # WL#4435: Support OUT-parameters in prepared statements.
@ -4044,3 +4100,4 @@ c1 c2 count(c3)
2012-03-01 01:00:00 3 1 2012-03-01 01:00:00 3 1
2012-03-01 02:00:00 3 1 2012-03-01 02:00:00 3 1
DEALLOCATE PREPARE s1; DEALLOCATE PREPARE s1;
# End of 5.3 tests

View File

@ -9,6 +9,6 @@ STOP SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START;
START SLAVE; START SLAVE;
STOP SLAVE; STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT='MASTER_MYPORT', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START;
START SLAVE; START SLAVE;
include/rpl_end.inc include/rpl_end.inc

View File

@ -7849,3 +7849,36 @@ c1 c2 count(c3)
2012-03-01 01:00:00 3 1 2012-03-01 01:00:00 3 1
2012-03-01 02:00:00 3 1 2012-03-01 02:00:00 3 1
DROP PROCEDURE p1; DROP PROCEDURE p1;
#
# LP bug#1002157 : testing stored function
# bug#62125 result for null incorrectly yields 1292 warning.
#
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
DROP FUNCTION IF EXISTS f3;
DROP FUNCTION IF EXISTS f4;
CREATE FUNCTION f1() RETURNS VARCHAR(1)
BEGIN RETURN 'X'; END;/
CREATE FUNCTION f2() RETURNS CHAR(1)
BEGIN RETURN 'X'; END;/
CREATE FUNCTION f3() RETURNS VARCHAR(1)
BEGIN RETURN NULL; END;/
CREATE FUNCTION f4() RETURNS CHAR(1)
BEGIN RETURN NULL; END;/
SELECT f1() IS NULL;
f1() IS NULL
0
SELECT f2() IS NULL;
f2() IS NULL
0
SELECT f3() IS NULL;
f3() IS NULL
1
SELECT f4() IS NULL;
f4() IS NULL
1
DROP FUNCTION f1;
DROP FUNCTION f2;
DROP FUNCTION f3;
DROP FUNCTION f4;
# End of 5.5 test

View File

@ -51,12 +51,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list)
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1003 select 1 AS `1` from dual having (<expr_cache><1>((select 1)) = 1) Note 1003 select 1 AS `1` from dual having ((select 1) = 1)
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 1
1 1
@ -371,12 +371,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
@ -517,6 +517,7 @@ ERROR 21000: Subquery returns more than 1 row
show warnings; show warnings;
Level Code Message Level Code Message
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
Error 1028 Sort aborted: Subquery returns more than 1 row
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
@ -547,11 +548,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows filtered Extra ERROR 21000: Subquery returns more than 1 row
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index
2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1'))))
SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
@ -907,7 +904,7 @@ a t1.a in (select t2.a from t2)
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index 2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
CREATE TABLE t3 (a int(11) default '0'); CREATE TABLE t3 (a int(11) default '0');
@ -1608,25 +1605,25 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
drop table t1,t2; drop table t1,t2;
@ -1675,34 +1672,34 @@ select * from t3 where NULL >= any (select b from t2);
a a
explain extended select * from t3 where NULL >= any (select b from t2); explain extended select * from t3 where NULL >= any (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= any (select b from t2 group by 1); select * from t3 where NULL >= any (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2); select * from t3 where NULL >= some (select b from t2);
a a
explain extended select * from t3 where NULL >= some (select b from t2); explain extended select * from t3 where NULL >= some (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2 group by 1); select * from t3 where NULL >= some (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
insert into t2 values (2,2), (2,1), (3,3), (3,1); insert into t2 values (2,2), (2,1), (3,3), (3,1);
select * from t3 where a > all (select max(b) from t2 group by a); select * from t3 where a > all (select max(b) from t2 group by a);
a a
@ -1764,7 +1761,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 UNION t1 system NULL NULL NULL NULL 1 100.00 3 UNION t1 system NULL NULL NULL NULL 1 100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 select 'e' AS `s1` from dual where <nop>(<in_optimizer>('f',(<min>(select 'e' from dual union select 'e' from dual) < 'f'))) Note 1003 select 'e' AS `s1` from dual where 1
drop table t1; drop table t1;
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
@ -3099,8 +3096,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where 2 SUBQUERY t2 range b b 40 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@ -3111,8 +3108,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition 2 SUBQUERY t2 range b b 40 NULL 2 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@ -3163,7 +3160,7 @@ INSERT INTO t2 VALUES (1),(2),(3);
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key 2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
SELECT a, a IN (SELECT a FROM t1) FROM t2; SELECT a, a IN (SELECT a FROM t1) FROM t2;
a a IN (SELECT a FROM t1) a a IN (SELECT a FROM t1)
1 1 1 1
@ -3699,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index 2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t = (SELECT t1.t FROM t1
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
@ -3726,9 +3723,9 @@ from t1' at line 1
explain select * from t1 where not exists explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12)); ((select t11.i from t1 t11) union (select t12.i from t1 t12));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3 UNION t12 system NULL NULL NULL NULL 0 const row not found 3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1); INSERT INTO t1 VALUES (1,1),(2,1);
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 const 0 Using where; Using index 1 PRIMARY t1 ref a a 5 const 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
@ -4580,7 +4577,7 @@ FROM t1
WHERE a = 230; WHERE a = 230;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
FROM t1 FROM t1
WHERE a = 230; WHERE a = 230;
@ -4626,7 +4623,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1 1
1 1
@ -5969,7 +5966,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
@ -6130,7 +6127,7 @@ set optimizer_switch=@tmp_optimizer_switch;
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
@ -6542,7 +6539,7 @@ EXPLAIN
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 NULL 0 NULL
@ -6550,7 +6547,7 @@ EXPLAIN
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 0 0 0
@ -6589,5 +6586,187 @@ NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
f1 f2 f1 f2
drop table t1,t2; drop table t1,t2;
#
# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible
# WHERE and UNION in HAVING
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
min_a a
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
min_a a
drop table t1;
#
# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not
# precomputed and thus not part of optimization
#
CREATE TABLE t1 ( a VARCHAR(16), KEY (a) );
INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'),
('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade');
EXPLAIN
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
field
EXPLAIN
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index
1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index
1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
MAX( alias2.a )
Arden-Arcade
drop table t1;
#
# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows
# with semijoin+materialization, IN and = subqueries
#
CREATE TABLE t1 (a1 INT);
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (b1 INT);
INSERT INTO t2 VALUES (1),(7);
EXPLAIN
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
a1
drop table t1, t2;
#
# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS,
# inner joins takes hundreds times longer
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(5);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (8),(3);
set @@expensive_subquery_limit= 0;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 6
Subquery_cache_miss 2
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 8
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 22
set @@expensive_subquery_limit= default;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
drop table t1, t2, t3;
#
# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(8);
CREATE TABLE t2 (b INT PRIMARY KEY);
INSERT INTO t2 VALUES (1),(2);
EXPLAIN
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
a
drop table t1,t2;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;

View File

@ -1479,7 +1479,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(<expr_cache><(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9))>(<in_optimizer>((select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)),(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)) in ( <materialize> (select `test`.`t3`.`b` from `test`.`t3` ), <primary_index_lookup>(9 in <temporary table> on distinct_key where ((9 = `<subquery3>`.`b`)))))))) Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1
SELECT * FROM t1 SELECT * FROM t1
WHERE ( WHERE (
( SELECT a FROM t2 WHERE a = 9 ), ( SELECT a FROM t2 WHERE a = 9 ),

View File

@ -1489,7 +1489,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(<expr_cache><(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9))>(<in_optimizer>((select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)),(select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = 9)) in ( <materialize> (select `test`.`t3`.`b` from `test`.`t3` ), <primary_index_lookup>(9 in <temporary table> on distinct_key where ((9 = `<subquery3>`.`b`)))))))) Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1
SELECT * FROM t1 SELECT * FROM t1
WHERE ( WHERE (
( SELECT a FROM t2 WHERE a = 9 ), ( SELECT a FROM t2 WHERE a = 9 ),

View File

@ -226,10 +226,10 @@ NULL
EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 ; EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 ;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
Note 1003 select <expr_cache><>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual
first equivalent variant first equivalent variant
SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c ; SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c ;
RESULT RESULT
@ -237,10 +237,10 @@ NULL
EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c; EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
Note 1003 select <expr_cache><>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual group by NULL Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual group by NULL
second equivalent variant second equivalent variant
SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ; SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ;
RESULT RESULT
@ -248,10 +248,10 @@ NULL
EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ; EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
Note 1003 select <expr_cache><>((select 1 from `test`.`t2` where 0)) AS `RESULT` from dual group by NULL Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from dual group by NULL
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
# BUG#45928 "Differing query results depending on MRR and # BUG#45928 "Differing query results depending on MRR and
@ -562,7 +562,7 @@ WHERE f3 = (
SELECT t1.f3 FROM t1 SELECT t1.f3 FROM t1
WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 )); WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref f3 f3 5 const 0 Using where 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
@ -577,7 +577,7 @@ WHERE f3 = (
SELECT f3 FROM t1 SELECT f3 FROM t1
WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 )); WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref f3 f3 5 const 0 Using where 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 8 func,func 1 2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 8 func,func 1
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
@ -1220,6 +1220,13 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary 3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary
3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) 3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE
(SELECT f2 FROM t2
WHERE f4 <= ALL
(SELECT max(SQ1_t1.f4)
FROM t3 AS SQ1_t1 JOIN t3 AS SQ1_t3 ON SQ1_t3.f4
GROUP BY SQ1_t1.f4));
ERROR 21000: Subquery returns more than 1 row
drop table t1, t2, t3; drop table t1, t2, t3;
# #
# BUG#52317: Assertion failing in Field_varstring::store() # BUG#52317: Assertion failing in Field_varstring::store()
@ -1250,10 +1257,9 @@ FROM t2 JOIN t1 ON t1.f3
WHERE ('v') IN (SELECT f4 FROM t2) WHERE ('v') IN (SELECT f4 FROM t2)
GROUP BY f9; GROUP BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
(SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9
FROM t2 JOIN t1 ON t1.f3 FROM t2 JOIN t1 ON t1.f3
@ -1267,17 +1273,16 @@ FROM t2 JOIN t1 ON t1.f3
WHERE ('v') IN (SELECT f4 FROM t2) WHERE ('v') IN (SELECT f4 FROM t2)
ORDER BY f9; ORDER BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
(SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9
FROM t2 JOIN t1 ON t1.f3 FROM t2 JOIN t1 ON t1.f3
WHERE ('v') IN (SELECT f4 FROM t2) WHERE ('v') IN (SELECT f4 FROM t2)
ORDER BY f9; ORDER BY f9;
COUNT(t2.f3) f9 COUNT(t2.f3) f9
0 2 0 NULL
EXPLAIN EXPLAIN
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
(SELECT t2.f1 FROM t1 limit 1) AS f9 (SELECT t2.f1 FROM t1 limit 1) AS f9
@ -1285,8 +1290,7 @@ FROM t2 JOIN t1
WHERE ('v') IN (SELECT f4 FROM t2) WHERE ('v') IN (SELECT f4 FROM t2)
GROUP BY f9; GROUP BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
@ -1302,8 +1306,7 @@ FROM t2 JOIN t1
WHERE ('v') IN (SELECT f4 FROM t2) WHERE ('v') IN (SELECT f4 FROM t2)
ORDER BY f9; ORDER BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
@ -1325,7 +1328,7 @@ EXPLAIN
SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1; SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2
2 SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1; SELECT (SELECT f1 FROM t1) AS field1 FROM t2 GROUP BY field1;
field1 field1
NULL NULL
@ -1333,7 +1336,7 @@ EXPLAIN
SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1; SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2
2 SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1; SELECT (SELECT f1 FROM t1) AS field1 FROM t2 ORDER BY field1;
field1 field1
NULL NULL
@ -1631,7 +1634,7 @@ SET SESSION optimizer_switch='in_to_exists=on,materialization=off';
EXPLAIN EXPLAIN
SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t3 system NULL NULL NULL NULL 1 2 SUBQUERY t3 system NULL NULL NULL NULL 1
2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index 2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index
SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10);
@ -1852,8 +1855,8 @@ GROUP BY 1, 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 Using temporary; Using filesort 1 PRIMARY t3 system NULL NULL NULL NULL 1 Using temporary; Using filesort
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 MATERIALIZED t1 system NULL NULL NULL NULL 0 const row not found 3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
PREPARE st1 FROM " PREPARE st1 FROM "
SELECT t2.f1, (SELECT f2 FROM t1 WHERE (7) IN (SELECT f1 FROM t1)) SELECT t2.f1, (SELECT f2 FROM t1 WHERE (7) IN (SELECT f1 FROM t1))
FROM t2 JOIN t3 ON t3.f4 = t2.f4 FROM t2 JOIN t3 ON t3.f4 = t2.f4
@ -2029,6 +2032,61 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 10 Using where
2 SUBQUERY five ALL NULL NULL NULL NULL 5 Using where 2 SUBQUERY five ALL NULL NULL NULL NULL 5 Using where
drop table ten, t1, five; drop table ten, t1, five;
#
# LP BUG#1008773 Wrong result (NULL instead of a value) with no matching rows, subquery in FROM and HAVING
#
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1);
EXPLAIN
SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t2 system NULL NULL NULL NULL 1
SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1;
MAX(a) bb
NULL 1
EXPLAIN
SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t2 system NULL NULL NULL NULL 1
SELECT MAX(a), 1 in ( SELECT b FROM t2 ) AS bb FROM t1;
MAX(a) bb
NULL 1
EXPLAIN
SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(a), 1 >= ALL ( SELECT b FROM t2 ) AS bb FROM t1;
MAX(a) bb
NULL 1
EXPLAIN
SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(a), ( SELECT 1 FROM t2 where b = a) AS bb FROM t1;
MAX(a) bb
NULL NULL
EXPLAIN
SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1
SELECT MAX(a), a in ( SELECT b FROM t2 ) AS bb FROM t1;
MAX(a) bb
NULL NULL
EXPLAIN
SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1
SELECT MAX(a), a >= ALL ( SELECT b FROM t2 ) AS bb FROM t1;
MAX(a) bb
NULL NULL
drop table t1, t2;
set optimizer_switch=@subselect4_tmp; set optimizer_switch=@subselect4_tmp;
SET optimizer_switch= @@global.optimizer_switch; SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size; set @@tmp_table_size= @@global.tmp_table_size;

View File

@ -486,9 +486,9 @@ Handler_read_key 7
Handler_read_last 0 Handler_read_last 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
Handler_read_rnd 10 Handler_read_rnd 0
Handler_read_rnd_deleted 0 Handler_read_rnd_deleted 0
Handler_read_rnd_next 42 Handler_read_rnd_next 31
set optimizer_switch='subquery_cache=off'; set optimizer_switch='subquery_cache=off';
flush status; flush status;
select a from t1 ORDER BY (select d from t2 where b=c); select a from t1 ORDER BY (select d from t2 where b=c);
@ -514,9 +514,9 @@ Handler_read_key 0
Handler_read_last 0 Handler_read_last 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
Handler_read_rnd 10 Handler_read_rnd 0
Handler_read_rnd_deleted 0 Handler_read_rnd_deleted 0
Handler_read_rnd_next 72 Handler_read_rnd_next 61
set optimizer_switch='subquery_cache=on'; set optimizer_switch='subquery_cache=on';
#single value subquery test (distinct ORDER BY) #single value subquery test (distinct ORDER BY)
flush status; flush status;

View File

@ -46,7 +46,7 @@ select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null)); where id in (select id from t1 as x1 where (t1.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select 1 AS `id`,'2007-04-25 18:30:22' AS `cur_date` from dual where <expr_cache><1>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where 0))) Note 1003 select 1 AS `id`,'2007-04-25 18:30:22' AS `cur_date` from dual where <expr_cache><1>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where 0)))
@ -58,7 +58,7 @@ select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null)); where id in (select id from t2 as x1 where (t2.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select 1 AS `id`,'2007-04-25' AS `cur_date` from dual where <expr_cache><1>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where 0))) Note 1003 select 1 AS `id`,'2007-04-25' AS `cur_date` from dual where <expr_cache><1>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where 0)))

View File

@ -332,8 +332,8 @@ FROM t2
WHERE (SELECT DISTINCT b FROM t3) > 0); WHERE (SELECT DISTINCT b FROM t3) > 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using where; Using index 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using where; Using index
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using temporary 3 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 0 Using temporary
SELECT * SELECT *
FROM t1 FROM t1
WHERE t1.a = ( WHERE t1.a = (
@ -361,7 +361,7 @@ GROUP BY 1
); );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 1 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 SUBQUERY t3 ALL NULL NULL NULL NULL 1 3 SUBQUERY t3 ALL NULL NULL NULL NULL 1
SELECT MAX( f1 ) FROM t2 SELECT MAX( f1 ) FROM t2
WHERE f2 >= ( WHERE f2 >= (
@ -386,7 +386,7 @@ select 1 from t1 where 1 like (select 1 from t1 where 1 <=> (select 1 from t1 gr
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 1 PRIMARY t1 ALL NULL NULL NULL NULL 1
2 SUBQUERY t1 ALL NULL NULL NULL NULL 1 2 SUBQUERY t1 ALL NULL NULL NULL NULL 1
3 SUBQUERY t1 ALL NULL NULL NULL NULL 1 Using temporary; Using filesort 3 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
select 1 from t1 where 1 like (select 1 from t1 where 1 <=> (select 1 from t1 group by a1)); select 1 from t1 where 1 like (select 1 from t1 where 1 <=> (select 1 from t1 group by a1));
1 1
1 1

View File

@ -1152,8 +1152,8 @@ create table t2 (b1 int);
insert into t1 values (5); insert into t1 values (5);
explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED t2 system NULL NULL NULL NULL 0 const row not found 2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
min(a1) min(a1)
NULL NULL
@ -1162,8 +1162,8 @@ set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on'; set @@optimizer_switch='materialization=off,in_to_exists=on';
explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
min(a1) min(a1)
NULL NULL
@ -1171,8 +1171,8 @@ set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off'; set @@optimizer_switch='semijoin=off';
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED t2 system NULL NULL NULL NULL 0 const row not found 2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
NULL NULL
@ -1181,16 +1181,16 @@ set @@optimizer_switch='materialization=off,in_to_exists=on';
# with MariaDB and MWL#90, this particular case is solved: # with MariaDB and MWL#90, this particular case is solved:
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
NULL NULL
# but when we go around MWL#90 code, the problem still shows up: # but when we go around MWL#90 code, the problem still shows up:
explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
min(a1) min(a1)
NULL NULL
@ -1932,7 +1932,7 @@ WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index 1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index
2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index 2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index
2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
SELECT a, c FROM t1, t2 SELECT a, c FROM t1, t2
@ -1951,8 +1951,8 @@ WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index 1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index
2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index 2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index
2 MATERIALIZED s1 hash_ALL NULL #hash#$hj 5 test.s2.d 8 Using where; Using join buffer (flat, BNLH join) 2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
SELECT a, c FROM t1, t2 SELECT a, c FROM t1, t2
WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2
@ -2166,7 +2166,7 @@ set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_
EXPLAIN EXPLAIN
SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
@ -2175,7 +2175,7 @@ EXPLAIN
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1) (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1)
@ -2192,7 +2192,7 @@ EXPLAIN
SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1);
(SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1) (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1)
@ -2235,10 +2235,10 @@ NULL
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL b 5 NULL 2 100.00 Using index 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where <expr_cache><9>(<in_optimizer>(9,9 in ( <materialize> (select `test`.`t2`.`a` from `test`.`t2` ), <primary_index_lookup>(9 in <temporary table> on distinct_key where ((9 = `<subquery2>`.`a`)))))) Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0
set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off'; set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off';
SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2);
max_res max_res
@ -2246,10 +2246,10 @@ NULL
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL b 5 NULL 2 100.00 Using index 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where <expr_cache><9>(<in_optimizer>(9,<exists>(select `test`.`t2`.`a` from `test`.`t2` where (9 = `test`.`t2`.`a`)))) Note 1003 select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
# LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions # LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions

View File

@ -496,7 +496,7 @@ from City
where City.population > 10000000; where City.population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY City range Population Population 5 NULL 4 Using index condition; Rowid-ordered scan 1 PRIMARY City range Population Population 5 NULL 4 Using index condition; Rowid-ordered scan
2 DEPENDENT SUBQUERY Country index_subquery CountryCapital CountryCapital 5 func 2 Using index; Using where 2 SUBQUERY Country index_subquery CountryCapital CountryCapital 5 func 2 Using index; Using where
select Name, City.id in (select capital from Country where capital is not null) as is_capital select Name, City.id in (select capital from Country where capital is not null) as is_capital
from City from City
where City.population > 10000000; where City.population > 10000000;

View File

@ -124,7 +124,7 @@ FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1
WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT t1.* SELECT t1.*
FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1
WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 );
@ -148,7 +148,7 @@ FROM t2 GROUP BY f1
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 system NULL NULL NULL NULL 1 2 SUBQUERY t1 system NULL NULL NULL NULL 1
3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 3 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
drop table t1, t2, t3; drop table t1, t2, t3;
# #
# LP BUG#715034 Item_sum_distinct::clear(): Assertion `tree != 0' failed # LP BUG#715034 Item_sum_distinct::clear(): Assertion `tree != 0' failed
@ -209,8 +209,8 @@ WHERE t1.f1 AND alias2.f10
ORDER BY field1 ; ORDER BY field1 ;
field1 field1
Warnings: Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'f' Warning 1292 Truncated incorrect DOUBLE value: 'f'
Warning 1292 Truncated incorrect INTEGER value: 'd' Warning 1292 Truncated incorrect DOUBLE value: 'd'
set optimizer_switch=@tmp_optimizer_switch; set optimizer_switch=@tmp_optimizer_switch;
drop table t1,t2; drop table t1,t2;
# #

View File

@ -58,12 +58,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list)
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1003 select 1 AS `1` from dual having (<expr_cache><1>((select 1)) = 1) Note 1003 select 1 AS `1` from dual having ((select 1) = 1)
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 1
1 1
@ -378,12 +378,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
@ -524,6 +524,7 @@ ERROR 21000: Subquery returns more than 1 row
show warnings; show warnings;
Level Code Message Level Code Message
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
Error 1028 Sort aborted: Subquery returns more than 1 row
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
@ -554,11 +555,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows filtered Extra ERROR 21000: Subquery returns more than 1 row
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index
2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1'))))
SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
@ -914,7 +911,7 @@ a t1.a in (select t2.a from t2)
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index 2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
CREATE TABLE t3 (a int(11) default '0'); CREATE TABLE t3 (a int(11) default '0');
@ -1615,25 +1612,25 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
drop table t1,t2; drop table t1,t2;
@ -1682,34 +1679,34 @@ select * from t3 where NULL >= any (select b from t2);
a a
explain extended select * from t3 where NULL >= any (select b from t2); explain extended select * from t3 where NULL >= any (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= any (select b from t2 group by 1); select * from t3 where NULL >= any (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2); select * from t3 where NULL >= some (select b from t2);
a a
explain extended select * from t3 where NULL >= some (select b from t2); explain extended select * from t3 where NULL >= some (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2 group by 1); select * from t3 where NULL >= some (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
insert into t2 values (2,2), (2,1), (3,3), (3,1); insert into t2 values (2,2), (2,1), (3,3), (3,1);
select * from t3 where a > all (select max(b) from t2 group by a); select * from t3 where a > all (select max(b) from t2 group by a);
a a
@ -1771,7 +1768,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 UNION t1 system NULL NULL NULL NULL 1 100.00 3 UNION t1 system NULL NULL NULL NULL 1 100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 select 'e' AS `s1` from dual where <nop>(<in_optimizer>('f',(<min>(select 'e' from dual union select 'e' from dual) < 'f'))) Note 1003 select 'e' AS `s1` from dual where 1
drop table t1; drop table t1;
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
@ -3105,8 +3102,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where 2 SUBQUERY t2 range b b 40 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@ -3117,8 +3114,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition 2 SUBQUERY t2 range b b 40 NULL 2 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@ -3169,7 +3166,7 @@ INSERT INTO t2 VALUES (1),(2),(3);
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key 2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
SELECT a, a IN (SELECT a FROM t1) FROM t2; SELECT a, a IN (SELECT a FROM t1) FROM t2;
a a IN (SELECT a FROM t1) a a IN (SELECT a FROM t1)
1 1 1 1
@ -3703,7 +3700,7 @@ ORDER BY t1.t DESC LIMIT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index 2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t = (SELECT t1.t FROM t1
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
@ -3730,9 +3727,9 @@ from t1' at line 1
explain select * from t1 where not exists explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12)); ((select t11.i from t1 t11) union (select t12.i from t1 t12));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3 UNION t12 system NULL NULL NULL NULL 0 const row not found 3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
@ -4202,8 +4199,8 @@ CREATE TABLE t1 (a int, b int, KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1); INSERT INTO t1 VALUES (1,1),(2,1);
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 const 0 Using where; Using index 1 PRIMARY t1 ref a a 5 const 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
@ -4531,13 +4528,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(min(`test`.`t1`.`a`)))))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(min(`test`.`t1`.`a`)))))) Note 1003 select 1 AS `1` from `test`.`t1` where 0
SET join_cache_level=@save_join_cache_level; SET join_cache_level=@save_join_cache_level;
DROP TABLE t1; DROP TABLE t1;
# #
@ -4582,7 +4579,7 @@ FROM t1
WHERE a = 230; WHERE a = 230;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
FROM t1 FROM t1
WHERE a = 230; WHERE a = 230;
@ -4628,7 +4625,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1 1
1 1
@ -5970,7 +5967,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
@ -6129,7 +6126,7 @@ set optimizer_switch=@tmp_optimizer_switch;
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
@ -6541,7 +6538,7 @@ EXPLAIN
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 NULL 0 NULL
@ -6549,7 +6546,7 @@ EXPLAIN
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 0 0 0
@ -6588,6 +6585,187 @@ NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
f1 f2 f1 f2
drop table t1,t2; drop table t1,t2;
#
# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible
# WHERE and UNION in HAVING
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
min_a a
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
min_a a
drop table t1;
#
# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not
# precomputed and thus not part of optimization
#
CREATE TABLE t1 ( a VARCHAR(16), KEY (a) );
INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'),
('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade');
EXPLAIN
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
field
EXPLAIN
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index
1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index
1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
MAX( alias2.a )
Arden-Arcade
drop table t1;
#
# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows
# with semijoin+materialization, IN and = subqueries
#
CREATE TABLE t1 (a1 INT);
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (b1 INT);
INSERT INTO t2 VALUES (1),(7);
EXPLAIN
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; Start temporary; Using join buffer (flat, BNL join)
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 End temporary; Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
a1
drop table t1, t2;
#
# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS,
# inner joins takes hundreds times longer
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(5);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (8),(3);
set @@expensive_subquery_limit= 0;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 6
Subquery_cache_miss 2
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 8
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 22
set @@expensive_subquery_limit= default;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
drop table t1, t2, t3;
#
# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(8);
CREATE TABLE t2 (b INT PRIMARY KEY);
INSERT INTO t2 VALUES (1),(2);
EXPLAIN
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
a
drop table t1,t2;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set optimizer_switch=default; set optimizer_switch=default;

View File

@ -54,7 +54,7 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list)
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
@ -374,12 +374,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
@ -520,6 +520,7 @@ ERROR 21000: Subquery returns more than 1 row
show warnings; show warnings;
Level Code Message Level Code Message
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
Error 1028 Sort aborted: Subquery returns more than 1 row
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
@ -550,11 +551,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows filtered Extra ERROR 21000: Subquery returns more than 1 row
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index
2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1'))))
SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
@ -910,7 +907,7 @@ a t1.a in (select t2.a from t2)
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index 2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
CREATE TABLE t3 (a int(11) default '0'); CREATE TABLE t3 (a int(11) default '0');
@ -1611,25 +1608,25 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
drop table t1,t2; drop table t1,t2;
@ -1678,34 +1675,34 @@ select * from t3 where NULL >= any (select b from t2);
a a
explain extended select * from t3 where NULL >= any (select b from t2); explain extended select * from t3 where NULL >= any (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= any (select b from t2 group by 1); select * from t3 where NULL >= any (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2); select * from t3 where NULL >= some (select b from t2);
a a
explain extended select * from t3 where NULL >= some (select b from t2); explain extended select * from t3 where NULL >= some (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2 group by 1); select * from t3 where NULL >= some (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
insert into t2 values (2,2), (2,1), (3,3), (3,1); insert into t2 values (2,2), (2,1), (3,3), (3,1);
select * from t3 where a > all (select max(b) from t2 group by a); select * from t3 where a > all (select max(b) from t2 group by a);
a a
@ -1767,7 +1764,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 UNION t1 system NULL NULL NULL NULL 1 100.00 3 UNION t1 system NULL NULL NULL NULL 1 100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 select 'e' AS `s1` from dual where <nop>(<in_optimizer>('f',(<min>(select 'e' from dual union select 'e' from dual) < 'f'))) Note 1003 select 'e' AS `s1` from dual where 1
drop table t1; drop table t1;
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
@ -3101,8 +3098,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where 2 SUBQUERY t2 range b b 40 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@ -3113,8 +3110,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition 2 SUBQUERY t2 range b b 40 NULL 2 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@ -3165,7 +3162,7 @@ INSERT INTO t2 VALUES (1),(2),(3);
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key 2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
SELECT a, a IN (SELECT a FROM t1) FROM t2; SELECT a, a IN (SELECT a FROM t1) FROM t2;
a a IN (SELECT a FROM t1) a a IN (SELECT a FROM t1)
1 1 1 1
@ -3699,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index 2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t = (SELECT t1.t FROM t1
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
@ -3726,9 +3723,9 @@ from t1' at line 1
explain select * from t1 where not exists explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12)); ((select t11.i from t1 t11) union (select t12.i from t1 t12));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3 UNION t12 system NULL NULL NULL NULL 0 const row not found 3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1); INSERT INTO t1 VALUES (1,1),(2,1);
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 const 0 Using where; Using index 1 PRIMARY t1 ref a a 5 const 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
@ -4527,13 +4524,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(min(`test`.`t1`.`a`))))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(min(`test`.`t1`.`a`))))) Note 1003 select 1 AS `1` from `test`.`t1` where 0
SET join_cache_level=@save_join_cache_level; SET join_cache_level=@save_join_cache_level;
DROP TABLE t1; DROP TABLE t1;
# #
@ -4578,7 +4575,7 @@ FROM t1
WHERE a = 230; WHERE a = 230;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
FROM t1 FROM t1
WHERE a = 230; WHERE a = 230;
@ -4624,7 +4621,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1 1
1 1
@ -5966,7 +5963,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
@ -6125,7 +6122,7 @@ set optimizer_switch=@tmp_optimizer_switch;
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
@ -6537,7 +6534,7 @@ EXPLAIN
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 NULL 0 NULL
@ -6545,7 +6542,7 @@ EXPLAIN
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 0 0 0
@ -6584,6 +6581,188 @@ NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
f1 f2 f1 f2
drop table t1,t2; drop table t1,t2;
#
# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible
# WHERE and UNION in HAVING
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
min_a a
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
min_a a
drop table t1;
#
# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not
# precomputed and thus not part of optimization
#
CREATE TABLE t1 ( a VARCHAR(16), KEY (a) );
INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'),
('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade');
EXPLAIN
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
field
EXPLAIN
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index
1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index
1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
MAX( alias2.a )
Arden-Arcade
drop table t1;
#
# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows
# with semijoin+materialization, IN and = subqueries
#
CREATE TABLE t1 (a1 INT);
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (b1 INT);
INSERT INTO t2 VALUES (1),(7);
EXPLAIN
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
a1
drop table t1, t2;
#
# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS,
# inner joins takes hundreds times longer
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(5);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (8),(3);
set @@expensive_subquery_limit= 0;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 6
Subquery_cache_miss 2
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 8
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 22
set @@expensive_subquery_limit= default;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
drop table t1, t2, t3;
#
# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(8);
CREATE TABLE t2 (b INT PRIMARY KEY);
INSERT INTO t2 VALUES (1),(2);
EXPLAIN
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
a
drop table t1,t2;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;

View File

@ -57,7 +57,7 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list)
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
@ -377,12 +377,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
@ -523,6 +523,7 @@ ERROR 21000: Subquery returns more than 1 row
show warnings; show warnings;
Level Code Message Level Code Message
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
Error 1028 Sort aborted: Subquery returns more than 1 row
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
@ -553,11 +554,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows filtered Extra ERROR 21000: Subquery returns more than 1 row
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index
2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1'))))
SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
@ -913,7 +910,7 @@ a t1.a in (select t2.a from t2)
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index 2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
CREATE TABLE t3 (a int(11) default '0'); CREATE TABLE t3 (a int(11) default '0');
@ -1614,25 +1611,25 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key 2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
Warnings: Warnings:
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
drop table t1,t2; drop table t1,t2;
@ -1681,34 +1678,34 @@ select * from t3 where NULL >= any (select b from t2);
a a
explain extended select * from t3 where NULL >= any (select b from t2); explain extended select * from t3 where NULL >= any (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= any (select b from t2 group by 1); select * from t3 where NULL >= any (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2); select * from t3 where NULL >= some (select b from t2);
a a
explain extended select * from t3 where NULL >= some (select b from t2); explain extended select * from t3 where NULL >= some (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2 group by 1); select * from t3 where NULL >= some (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
insert into t2 values (2,2), (2,1), (3,3), (3,1); insert into t2 values (2,2), (2,1), (3,3), (3,1);
select * from t3 where a > all (select max(b) from t2 group by a); select * from t3 where a > all (select max(b) from t2 group by a);
a a
@ -1770,7 +1767,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 UNION t1 system NULL NULL NULL NULL 1 100.00 3 UNION t1 system NULL NULL NULL NULL 1 100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 select 'e' AS `s1` from dual where <nop>(<in_optimizer>('f',(<min>(select 'e' from dual union select 'e' from dual) < 'f'))) Note 1003 select 'e' AS `s1` from dual where 1
drop table t1; drop table t1;
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
@ -3105,8 +3102,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where 2 SUBQUERY t2 range b b 40 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@ -3117,8 +3114,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition 2 SUBQUERY t2 range b b 40 NULL 2 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@ -3169,7 +3166,7 @@ INSERT INTO t2 VALUES (1),(2),(3);
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key 2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
SELECT a, a IN (SELECT a FROM t1) FROM t2; SELECT a, a IN (SELECT a FROM t1) FROM t2;
a a IN (SELECT a FROM t1) a a IN (SELECT a FROM t1)
1 1 1 1
@ -3705,7 +3702,7 @@ ORDER BY t1.t DESC LIMIT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index 2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t = (SELECT t1.t FROM t1
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
@ -3732,9 +3729,9 @@ from t1' at line 1
explain select * from t1 where not exists explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12)); ((select t11.i from t1 t11) union (select t12.i from t1 t12));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3 UNION t12 system NULL NULL NULL NULL 0 const row not found 3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
@ -4204,8 +4201,8 @@ CREATE TABLE t1 (a int, b int, KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1); INSERT INTO t1 VALUES (1,1),(2,1);
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 const 0 Using where; Using index 1 PRIMARY t1 ref a a 5 const 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
@ -4586,7 +4583,7 @@ FROM t1
WHERE a = 230; WHERE a = 230;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
FROM t1 FROM t1
WHERE a = 230; WHERE a = 230;
@ -4632,7 +4629,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1 1
1 1
@ -5975,7 +5972,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
@ -6136,7 +6133,7 @@ set optimizer_switch=@tmp_optimizer_switch;
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
@ -6548,7 +6545,7 @@ EXPLAIN
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 NULL 0 NULL
@ -6556,7 +6553,7 @@ EXPLAIN
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 0 0 0
@ -6595,6 +6592,188 @@ NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
f1 f2 f1 f2
drop table t1,t2; drop table t1,t2;
#
# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible
# WHERE and UNION in HAVING
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
min_a a
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
min_a a
drop table t1;
#
# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not
# precomputed and thus not part of optimization
#
CREATE TABLE t1 ( a VARCHAR(16), KEY (a) );
INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'),
('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade');
EXPLAIN
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
field
EXPLAIN
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index
1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index
1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
MAX( alias2.a )
Arden-Arcade
drop table t1;
#
# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows
# with semijoin+materialization, IN and = subqueries
#
CREATE TABLE t1 (a1 INT);
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (b1 INT);
INSERT INTO t2 VALUES (1),(7);
EXPLAIN
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
a1
drop table t1, t2;
#
# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS,
# inner joins takes hundreds times longer
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(5);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (8),(3);
set @@expensive_subquery_limit= 0;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 58
set @@expensive_subquery_limit= default;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
drop table t1, t2, t3;
#
# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(8);
CREATE TABLE t2 (b INT PRIMARY KEY);
INSERT INTO t2 VALUES (1),(2);
EXPLAIN
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
a
drop table t1,t2;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set optimizer_switch=default; set optimizer_switch=default;

View File

@ -54,12 +54,12 @@ ERROR 42S22: Reference 'a' not supported (forward reference in item list)
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
Note 1003 select 1 AS `1` from dual having (<expr_cache><1>((select 1)) = 1) Note 1003 select 1 AS `1` from dual having ((select 1) = 1)
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 1
1 1
@ -374,12 +374,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select 'joce' from `test`.`t8` where 1)) Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
@ -520,6 +520,7 @@ ERROR 21000: Subquery returns more than 1 row
show warnings; show warnings;
Level Code Message Level Code Message
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
Error 1028 Sort aborted: Subquery returns more than 1 row
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
@ -550,11 +551,7 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
id select_type table type possible_keys key key_len ref rows filtered Extra ERROR 21000: Subquery returns more than 1 row
1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using where; Using index
2 SUBQUERY t1 ref PRIMARY PRIMARY 3 const 2 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`numreponse` AS `numreponse` from `test`.`t1` where ((`test`.`t1`.`numeropost` = '1') and (`test`.`t1`.`numreponse` = (select 1 from `test`.`t1` where (`test`.`t1`.`numeropost` = '1'))))
SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
ERROR 21000: Subquery returns more than 1 row ERROR 21000: Subquery returns more than 1 row
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
@ -1678,34 +1675,34 @@ select * from t3 where NULL >= any (select b from t2);
a a
explain extended select * from t3 where NULL >= any (select b from t2); explain extended select * from t3 where NULL >= any (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= any (select b from t2 group by 1); select * from t3 where NULL >= any (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2); select * from t3 where NULL >= some (select b from t2);
a a
explain extended select * from t3 where NULL >= some (select b from t2); explain extended select * from t3 where NULL >= some (select b from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
select * from t3 where NULL >= some (select b from t2 group by 1); select * from t3 where NULL >= some (select b from t2 group by 1);
a a
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings: Warnings:
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,((select min(NULL) from `test`.`t2`) <= NULL))) Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
insert into t2 values (2,2), (2,1), (3,3), (3,1); insert into t2 values (2,2), (2,1), (3,3), (3,1);
select * from t3 where a > all (select max(b) from t2 group by a); select * from t3 where a > all (select max(b) from t2 group by a);
a a
@ -1767,7 +1764,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 UNION t1 system NULL NULL NULL NULL 1 100.00 3 UNION t1 system NULL NULL NULL NULL 1 100.00
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 select 'e' AS `s1` from dual where <nop>(<in_optimizer>('f',(<min>(select 'e' from dual union select 'e' from dual) < 'f'))) Note 1003 select 'e' AS `s1` from dual where 1
drop table t1; drop table t1;
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
@ -3101,8 +3098,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where 2 SUBQUERY t2 range b b 40 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@ -3113,8 +3110,8 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r eq_ref PRIMARY PRIMARY 4 const 1 Using where 1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using index condition 2 SUBQUERY t2 range b b 40 NULL 2 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@ -3699,7 +3696,7 @@ ORDER BY t1.t DESC LIMIT 1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index 2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t = (SELECT t1.t FROM t1
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
@ -3726,9 +3723,9 @@ from t1' at line 1
explain select * from t1 where not exists explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12)); ((select t11.i from t1 t11) union (select t12.i from t1 t12));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
2 SUBQUERY t11 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3 UNION t12 system NULL NULL NULL NULL 0 const row not found 3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
@ -4198,8 +4195,8 @@ CREATE TABLE t1 (a int, b int, KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1); INSERT INTO t1 VALUES (1,1),(2,1);
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 const 0 Using where; Using index 1 PRIMARY t1 ref a a 5 const 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY internal_tmp_table ALL group_key NULL NULL NULL 1 Using temporary; Using filesort
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
@ -4525,15 +4522,15 @@ SET join_cache_level=0;
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,1 in ( <materialize> (select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a` ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery2>`.`min(a)`)))))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,1 in ( <materialize> (select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery2>`.`min(a)`)))))) Note 1003 select 1 AS `1` from `test`.`t1` where 0
SET join_cache_level=@save_join_cache_level; SET join_cache_level=@save_join_cache_level;
DROP TABLE t1; DROP TABLE t1;
# #
@ -4578,7 +4575,7 @@ FROM t1
WHERE a = 230; WHERE a = 230;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
FROM t1 FROM t1
WHERE a = 230; WHERE a = 230;
@ -4624,7 +4621,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
Warnings: Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1))) Note 1003 select 1 AS `1` from `test`.`t1` where 1
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1 1
1 1
@ -5966,7 +5963,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) # BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
@ -6125,7 +6122,7 @@ set optimizer_switch=@tmp_optimizer_switch;
EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
2 SUBQUERY t1 ref a a 5 const 1 Using index 2 SUBQUERY t1 ref a a 5 const 1
DROP TABLE t1; DROP TABLE t1;
# #
@ -6537,7 +6534,7 @@ EXPLAIN
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 NULL 0 NULL
@ -6545,7 +6542,7 @@ EXPLAIN
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3;
COUNT(f1) f4 COUNT(f1) f4
0 0 0 0
@ -6584,6 +6581,188 @@ NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7;
f1 f2 f1 f2
drop table t1,t2; drop table t1,t2;
#
# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible
# WHERE and UNION in HAVING
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1;
min_a a
EXPLAIN
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1;
min_a a
drop table t1;
#
# LP BUG#944706 Query with impossible or constant subquery in WHERE or HAVING is not
# precomputed and thus not part of optimization
#
CREATE TABLE t1 ( a VARCHAR(16), KEY (a) );
INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'),
('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade');
EXPLAIN
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a ) AS field
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR alias1.a = 'y'
HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 );
field
EXPLAIN
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index
1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index
1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join)
2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where
SELECT MAX( alias2.a )
FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 );
MAX( alias2.a )
Arden-Arcade
drop table t1;
#
# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows
# with semijoin+materialization, IN and = subqueries
#
CREATE TABLE t1 (a1 INT);
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (b1 INT);
INSERT INTO t2 VALUES (1),(7);
EXPLAIN
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2));
a1
drop table t1, t2;
#
# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS,
# inner joins takes hundreds times longer
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(7);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(5);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (8),(3);
set @@expensive_subquery_limit= 0;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 6
Subquery_cache_miss 2
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 8
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 22
set @@expensive_subquery_limit= default;
EXPLAIN
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2
flush status;
SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
FROM t2 alias1, t1 alias2, t1 alias3;
(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3)))
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
show status like "subquery_cache%";
Variable_name Value
Subquery_cache_hit 0
Subquery_cache_miss 0
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
drop table t1, t2, t3;
#
# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(8);
CREATE TABLE t2 (b INT PRIMARY KEY);
INSERT INTO t2 VALUES (1),(2);
EXPLAIN
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1));
a
drop table t1,t2;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;

View File

@ -1197,8 +1197,8 @@ set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on'; set @@optimizer_switch='materialization=off,in_to_exists=on';
explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1);
min(a1) min(a1)
NULL NULL
@ -1206,8 +1206,8 @@ set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off'; set @@optimizer_switch='semijoin=off';
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
NULL NULL
@ -1223,8 +1223,8 @@ NULL
# but when we go around MWL#90 code, the problem still shows up: # but when we go around MWL#90 code, the problem still shows up:
explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
min(a1) min(a1)
NULL NULL
@ -1971,7 +1971,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 index c c 5 NULL 8 Using index 1 PRIMARY t2 index c c 5 NULL 8 Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index 2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index
2 MATERIALIZED s1 ALL c NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 2 MATERIALIZED s1 ALL c NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
SELECT a, c FROM t1, t2 SELECT a, c FROM t1, t2
@ -1991,8 +1991,8 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 index c c 5 NULL 8 Using index 1 PRIMARY t2 index c c 5 NULL 8 Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
2 MATERIALIZED s2 ref d d 4 const 1 Using where; Using index 2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index
2 MATERIALIZED s1 hash_ALL c #hash#$hj 10 const,test.s2.d 8 Using where; Using join buffer (flat, BNLH join) 2 MATERIALIZED s1 hash_ALL c #hash#$hj 5 const 8 Using where; Using join buffer (flat, BNLH join)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
SELECT a, c FROM t1, t2 SELECT a, c FROM t1, t2
WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2

View File

@ -1845,3 +1845,20 @@ dev
SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev; SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
dev dev
1 1
#
# LP bug#1010729: Unexpected syntax error from UNION
# (bug #54382) with single-table join nest
#
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
CREATE TABLE t3 (c int);
SELECT a FROM t1 UNION SELECT b FROM t2 JOIN (t3) ON ( t2.b = t3.c );
a
DROP TABLE t1, t2, t3;
CREATE TABLE t1 (pk int NOT NULL);
CREATE TABLE t2 (pk int NOT NULL, fk int NOT NULL);
SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk)
UNION
SELECT t1.pk FROM t1 LEFT JOIN (t2) ON (t1.pk = t2.fk);
pk
DROP TABLE t1,t2;

View File

@ -454,6 +454,13 @@ SELECT (@v:=a) <> (@v:=1) FROM t1;
(@v:=a) <> (@v:=1) (@v:=a) <> (@v:=1)
1 1
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1(a int);
INSERT INTO t1 VALUES (1), (2);
SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2
GROUP BY @b:=(SELECT COUNT(*) > t2.a);
@a:=MIN(t1.a)
1
DROP TABLE t1;
End of 5.1 tests End of 5.1 tests
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
CREATE TABLE t1(f1 INT AUTO_INCREMENT, PRIMARY KEY(f1)); CREATE TABLE t1(f1 INT AUTO_INCREMENT, PRIMARY KEY(f1));

View File

@ -4324,13 +4324,13 @@ MM
ZZ ZZ
ZZ ZZ
Warnings: Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'VV' Warning 1292 Truncated incorrect DOUBLE value: 'VV'
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV';
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 1 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index
Warnings: Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'VV' Warning 1292 Truncated incorrect DOUBLE value: 'VV'
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 'JJ') Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 'JJ')
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;

View File

@ -22,3 +22,7 @@ ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) fo
**** Clean up **** **** Clean up ****
set global binlog_format = @saved_binlog_format; set global binlog_format = @saved_binlog_format;
drop user mysqltest_1@localhost; drop user mysqltest_1@localhost;
GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost';
SHOW MASTER LOGS;
SHOW BINARY LOGS;
DROP USER 'mysqltest_1'@'localhost';

View File

@ -0,0 +1,30 @@
SET GLOBAL max_binlog_size= 4096;
SET GLOBAL innodb_flush_log_at_trx_commit= 1;
RESET MASTER;
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
SET DEBUG_SYNC= "binlog_open_before_update_index SIGNAL con1_ready WAIT_FOR con1_cont";
SET SESSION debug_dbug="+d,crash_create_critical_before_update_index";
INSERT INTO t1 VALUES (1, REPEAT("x", 4100));
SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
SET DEBUG_SYNC= "ha_commit_trans_after_prepare SIGNAL con2_ready";
INSERT INTO t1 VALUES (2, NULL);
SET DEBUG_SYNC= "now WAIT_FOR con2_ready";
SET DEBUG_SYNC= "now SIGNAL con1_cont";
Got one of the listed errors
SELECT a FROM t1 ORDER BY a;
a
1
show binary logs;
Log_name File_size
master-bin.000001 #
master-bin.000002 #
show binlog events in 'master-bin.000001' from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Rotate # # master-bin.000002;pos=<binlog_start>
DROP TABLE t1;

View File

@ -54,3 +54,22 @@ disconnect root;
connection default; connection default;
set global binlog_format = @saved_binlog_format; set global binlog_format = @saved_binlog_format;
drop user mysqltest_1@localhost; drop user mysqltest_1@localhost;
# Testing if REPLICATION CLIENT privilege is enough to execute
# SHOW MASTER LOGS and SHOW BINARY.
GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost';
--connect(rpl,localhost,mysqltest_1,,)
--connection rpl
# We are only interested if the following commands succeed and not on
# their output.
--disable_result_log
SHOW MASTER LOGS;
SHOW BINARY LOGS;
--enable_result_log
# clean up
--disconnect rpl
connection default;
DROP USER 'mysqltest_1'@'localhost';

View File

@ -0,0 +1 @@
--skip-stack-trace --skip-core-file

View File

@ -0,0 +1,66 @@
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
--source include/have_binlog_format_row.inc
# Valgrind does not work well with test that crashes the server
--source include/not_valgrind.inc
# (We do not need to restore these settings, as we crash the server).
SET GLOBAL max_binlog_size= 4096;
SET GLOBAL innodb_flush_log_at_trx_commit= 1;
RESET MASTER;
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
# One connection does an insert that causes a binlog rotate.
# The rotate is paused after writing new file but before updating index.
connect(con1,localhost,root,,);
SET DEBUG_SYNC= "binlog_open_before_update_index SIGNAL con1_ready WAIT_FOR con1_cont";
SET SESSION debug_dbug="+d,crash_create_critical_before_update_index";
send INSERT INTO t1 VALUES (1, REPEAT("x", 4100));
connection default;
SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
# Another connection creates a prepared transaction.
# After the transaction is prepared, it will hang waiting for LOCK_log.
connect(con2,localhost,root,,);
SET DEBUG_SYNC= "ha_commit_trans_after_prepare SIGNAL con2_ready";
send INSERT INTO t1 VALUES (2, NULL);
connection default;
SET DEBUG_SYNC= "now WAIT_FOR con2_ready";
# Now crash the server in con1, with old binlog closed, new binlog not yet in
# index, and one transaction in prepared-but-not-committed state.
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait-binlog_mdev342.test
EOF
# If con1 manages to race ahead and crash, we can see the crash already in the
# SET DEBUG_SYNC statement, so need --error here also.
--error 0,2006,2013
SET DEBUG_SYNC= "now SIGNAL con1_cont";
connection con1;
--error 2006,2013
reap;
--remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart-binlog_mdev342.test
EOF
connection default;
--enable_reconnect
--source include/wait_until_connected_again.inc
# Check that all transactions are recovered.
SELECT a FROM t1 ORDER BY a;
--source include/show_binary_logs.inc
--let $binlog_file= master-bin.000001
--let $binlog_start= 4
--source include/show_binlog_events.inc
# Cleanup
connection default;
DROP TABLE t1;

View File

@ -0,0 +1,6 @@
create table t1 (f1 integer primary key) engine innodb;
alter table t1 add constraint c1 foreign key (f1) references t1(f1);
ERROR HY000: Error on rename of '#sql-temporary' to './test/t1' (errno: 150)
InnoDB: has or is referenced in foreign key constraints
InnoDB: which are not compatible with the new table definition.
drop table t1;

View File

@ -0,0 +1,56 @@
create table t1 (
rowid int,
f1 int,
f2 int,
key i1 (f1, f2),
key i2 (f2)) engine=innodb;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`rowid` int(11) DEFAULT NULL,
`f1` int(11) DEFAULT NULL,
`f2` int(11) DEFAULT NULL,
KEY `i1` (`f1`,`f2`),
KEY `i2` (`f2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
start transaction with consistent snapshot;
start transaction;
update t1 set f2 = 4 where f1 = 1 and f2 is null;
(b) Number of rows updated:
select row_count();
row_count()
1
insert into t1 values (3, 1, null);
(b) After update and insert query.
select rowid, f1, f2 from t1;
rowid f1 f2
1 1 10
2 1 4
3 1 NULL
commit;
(a) Before the update statement is executed.
select rowid, f1, f2 from t1;
rowid f1 f2
1 1 10
2 1 NULL
SET SESSION debug_dbug="+d,bug14007649";
update t1 set f2 = 6 where f1 = 1 and f2 is null;
(a) Number of rows updated:
select row_count();
row_count()
1
(a) After the update statement is executed.
select rowid, f1, f2 from t1;
rowid f1 f2
1 1 10
2 1 NULL
3 1 6
commit;
"The trx with consistent snapshot ended."
select rowid, f1, f2 from t1;
rowid f1 f2
1 1 10
2 1 4
3 1 6
drop table t1;

View File

@ -4,11 +4,6 @@
--source include/have_innodb.inc --source include/have_innodb.inc
if (`select plugin_auth_version <= "1.1.8-24.1" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in XtraDB 1.1.8-24.1 or earlier
}
# DEBUG_SYNC must be compiled in. # DEBUG_SYNC must be compiled in.
--source include/have_debug_sync.inc --source include/have_debug_sync.inc

View File

@ -1,10 +1,5 @@
-- source include/have_innodb.inc -- source include/have_innodb.inc
if (`select plugin_auth_version <= "1.0.17-13.0" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in XtraDB 1.0.17-13.0 or earlier
}
let $MYSQLD_DATADIR= `select @@datadir`; let $MYSQLD_DATADIR= `select @@datadir`;
let $per_table=`select @@innodb_file_per_table`; let $per_table=`select @@innodb_file_per_table`;

View File

@ -1,10 +1,5 @@
--source include/have_innodb.inc --source include/have_innodb.inc
if (`select plugin_auth_version <= "1.0.17-13.0" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in XtraDB 1.0.17-13.0 or earlier
}
# #
# Check and select innodb lock type # Check and select innodb lock type
# #

View File

@ -0,0 +1,30 @@
# Bug 12902967: Creating self referencing fk on same index unhandled,
# confusing error
#
# Creating a self referencing foreign key on the same
# column/index is an unhandled exception, it should throw a sensible
# error but instead implies that your data dictionary may now be out
# of sync:
--source include/have_innodb.inc
--source include/not_embedded.inc
let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err;
--source include/restart_mysqld.inc
create table t1 (f1 integer primary key) engine innodb;
# The below statement should produce error message in error log.
# This error message should mention problem with foreign keys
# rather than with data dictionary.
--replace_regex /'\.\/test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
--error ER_ERROR_ON_RENAME
alter table t1 add constraint c1 foreign key (f1) references t1(f1);
--source include/restart_mysqld.inc
perl;
$file = $ENV{error_log};
open (FILE, '<', $file) or die "can't open(< $file): $!\n";
print ((grep { /^InnoDB:/ and not /aio/i } <FILE>)[-2..-1]);
EOF
drop table t1;

View File

@ -2,11 +2,6 @@
--source include/have_debug_sync.inc --source include/have_debug_sync.inc
--source include/not_embedded.inc --source include/not_embedded.inc
if (`select plugin_auth_version <= "1.1.8-24.1" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in XtraDB 1.1.8-24.1 or earlier
}
SET DEBUG_SYNC='reset'; SET DEBUG_SYNC='reset';
# Save the initial number of concurrent sessions # Save the initial number of concurrent sessions

View File

@ -0,0 +1,63 @@
--source include/have_innodb.inc
--source include/have_debug.inc
if (`select plugin_auth_version <= "1.1.8-26.0" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in XtraDB 1.1.8-26.0 or earlier
}
create table t1 (
rowid int,
f1 int,
f2 int,
key i1 (f1, f2),
key i2 (f2)) engine=innodb;
show create table t1;
insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
connect (a,localhost,root,,);
connect (b,localhost,root,,);
connection a;
start transaction with consistent snapshot;
connection b;
start transaction;
update t1 set f2 = 4 where f1 = 1 and f2 is null;
-- echo (b) Number of rows updated:
select row_count();
insert into t1 values (3, 1, null);
-- echo (b) After update and insert query.
select rowid, f1, f2 from t1;
commit;
connection a;
-- echo (a) Before the update statement is executed.
select rowid, f1, f2 from t1;
SET SESSION debug_dbug="+d,bug14007649";
update t1 set f2 = 6 where f1 = 1 and f2 is null;
-- echo (a) Number of rows updated:
select row_count();
-- echo (a) After the update statement is executed.
select rowid, f1, f2 from t1;
commit;
--echo "The trx with consistent snapshot ended."
select rowid, f1, f2 from t1;
connection default;
disconnect a;
disconnect b;
drop table t1;

View File

@ -1,3 +1,5 @@
percona_sync_flush: removed from XtraDB-26.0
percona_suppress_log_warning_1592: Feature not merged into MariaDB percona_suppress_log_warning_1592: Feature not merged into MariaDB
percona_log_slow_slave_statements: Feature not merged into MariaDB percona_log_slow_slave_statements: Feature not merged into MariaDB
percona_log_slow_slave_statements-and-use_global_long_query_time: Feature not merged into MariaDB percona_log_slow_slave_statements-and-use_global_long_query_time: Feature not merged into MariaDB

View File

@ -0,0 +1,41 @@
include/master-slave.inc
[connection master]
call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam;
create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb;
ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key
create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb;
set @@binlog_format=statement;
*** autoincrement field is not the first in PK warning must be there: ***
insert into tm set b=null, a=1;
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
show warnings;
Level Code Message
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
*** no warning when autoincrement is the first in PK
insert into ti set b=null, a=1;
show warnings;
Level Code Message
create function multi_part_pk_with_autoinc (arg int)
returns int
begin
insert into tm set b=null, a=arg;
return arg;
end//
select multi_part_pk_with_autoinc (3);
multi_part_pk_with_autoinc (3)
3
Warnings:
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
*** autoincrement field is not the first in PK warning must be there: ***
show warnings;
Level Code Message
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
set @@binlog_format=mixed;
insert into tm set b=null, a=2;
drop table tm, ti;
drop function multi_part_pk_with_autoinc;
include/rpl_end.inc

View File

@ -114,4 +114,23 @@ id c
3 3 3 3
[on master] [on master]
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
CREATE TABLE test.t1 (a INT);
INSERT INTO test.t1 VALUES(1);
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW
INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c);
SET INSERT_ID=2;
SET @c=2;
SET @@rand_seed1=10000000, @@rand_seed2=1000000;
INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c);
SELECT b into @b FROM test.t5;
UPDATE test.t1 SET a=2;
SELECT a AS 'ONE' into @a FROM test.t_slave;
SELECT c AS 'NULL' into @c FROM test.t_slave;
SELECT b into @b FROM test.t_slave;
drop table test.t5;
drop table test.t1;
drop table test.t_slave;
include/rpl_end.inc include/rpl_end.inc

View File

@ -0,0 +1,13 @@
include/master-slave.inc
[connection master]
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master';
SET GLOBAL rpl_semi_sync_master_enabled = ON;
SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont";
INSERT INTO t1 SELECT * FROM t1;
SET DEBUG_SYNC= "now WAIT_FOR m1_ready";
SET GLOBAL rpl_semi_sync_master_enabled = OFF;
SET DEBUG_SYNC= "now SIGNAL m1_cont";
DROP TABLE t1;
UNINSTALL PLUGIN rpl_semi_sync_master;
include/rpl_end.inc

View File

@ -0,0 +1,13 @@
include/master-slave.inc
[connection master]
[connection slave]
SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end';
SHOW BINLOG EVENTS;
[connection slave1]
SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events';
FLUSH LOGS;
SET DEBUG_SYNC= 'now SIGNAL end';
SET DEBUG_SYNC= 'RESET';
[connection slave]
SET DEBUG_SYNC= 'RESET';
include/rpl_end.inc

View File

@ -3,8 +3,8 @@ include/master-slave.inc
include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000] include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000]
include/start_slave.inc include/start_slave.inc
[Slave restarted with the report-port set to some value] [Slave restarted with the report-port set to some value]
include/assert.inc [The value shown for the slave's port number is 9000 which is the value set for report-port.] include/assert.inc [The value shown for the slave's port number is user specified port number which is the value set for report-port.]
include/rpl_restart_server.inc [server_number=2 parameters: --report-port=] include/rpl_restart_server.inc [server_number=2]
include/start_slave.inc include/start_slave.inc
[Slave restarted with the report-port set to the value of slave's port number] [Slave restarted with the report-port set to the value of slave's port number]
include/assert.inc [The default value shown for the slave's port number is the actual port number of the slave.] include/assert.inc [The default value shown for the slave's port number is the actual port number of the slave.]

View File

@ -0,0 +1,62 @@
# Test of auto-increment.
#
# BUG#11754117-45670
# Multipart primary key with the autoincrement part not first in it
# is replication unsafe.
#
source include/master-slave.inc;
source include/have_binlog_format_mixed.inc;
source include/have_innodb.inc;
call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
--connection master
create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam;
--error ER_WRONG_AUTO_KEY
create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb;
create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb;
set @@binlog_format=statement;
--echo *** autoincrement field is not the first in PK warning must be there: ***
insert into tm set b=null, a=1;
show warnings;
--echo *** no warning when autoincrement is the first in PK
insert into ti set b=null, a=1;
show warnings;
delimiter //;
create function multi_part_pk_with_autoinc (arg int)
returns int
begin
insert into tm set b=null, a=arg;
return arg;
end//
delimiter ;//
select multi_part_pk_with_autoinc (3);
--echo *** autoincrement field is not the first in PK warning must be there: ***
show warnings;
set @@binlog_format=mixed;
insert into tm set b=null, a=2;
sync_slave_with_master;
if (`select count(*) <> 3 from tm`)
{
--echo Wrong result from SELECT on the slave side.
select * from tm;
--die
}
# cleanup
--connection master
drop table tm, ti;
drop function multi_part_pk_with_autoinc;
sync_slave_with_master;
--source include/rpl_end.inc

View File

@ -206,4 +206,64 @@ SELECT * FROM t3;
connection master; connection master;
echo [on master]; echo [on master];
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
--sync_slave_with_master
#
# BUG#11754117 - 45670: INTVAR_EVENTS FOR FILTERED-OUT QUERY_LOG_EVENTS ARE EXECUTED
# Int-, Rand- and User- var events accompaning a filtered out Query-log-event should
# be filtered as well.
#
connection master;
CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); # ignored on slave
CREATE TABLE test.t1 (a INT); # accepted on slave
INSERT INTO test.t1 VALUES(1);
--sync_slave_with_master
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW
INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c);
connection master;
SET INSERT_ID=2;
SET @c=2;
SET @@rand_seed1=10000000, @@rand_seed2=1000000;
INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); # to be ignored
SELECT b into @b FROM test.t5;
--let $b_master=`select @b`
UPDATE test.t1 SET a=2; # to run trigger on slave
--sync_slave_with_master
# The proof:
SELECT a AS 'ONE' into @a FROM test.t_slave;
SELECT c AS 'NULL' into @c FROM test.t_slave;
let $count= 1;
let $table= test.t_slave;
source include/wait_until_rows_count.inc;
if (`SELECT @a != 2 and @c != NULL`)
{
SELECT * FROM test.t_slave;
--die Intvar or user var from replication events unexpetedly escaped out to screw a following query applying context.
}
SELECT b into @b FROM test.t_slave;
--let $b_slave=`select @b`
if (`SELECT $b_slave = $b_master`)
{
--echo Might be pure coincidence of two randoms from master and slave table. Don not panic yet.
}
# cleanup BUG#11754117
connection master;
drop table test.t5;
drop table test.t1;
--sync_slave_with_master
drop table test.t_slave;
--source include/rpl_end.inc --source include/rpl_end.inc

View File

@ -0,0 +1,36 @@
--source include/have_semisync_plugin.inc
--source include/not_embedded.inc
--source include/have_debug_sync.inc
--source include/have_binlog_format_mixed_or_statement.inc
--source include/master-slave.inc
# MDEV-359: There was a server crash when the code first checks if semisync
# is enabled without lock, then if so takes the lock and tests again.
# If semisync was disabled in-between the first and the second test, an
# assert was incorrectly made that referenced a NULL pointer.
#
# This tests uses debug_sync to pause one thread at the critical point in
# the code, disable the semisync, and then continue the paused thread.
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master';
SET GLOBAL rpl_semi_sync_master_enabled = ON;
--connection master1
SET DEBUG_SYNC = "rpl_semisync_master_commit_trx_before_lock SIGNAL m1_ready WAIT_FOR m1_cont";
--send
INSERT INTO t1 SELECT * FROM t1;
--connection master
SET DEBUG_SYNC= "now WAIT_FOR m1_ready";
SET GLOBAL rpl_semi_sync_master_enabled = OFF;
SET DEBUG_SYNC= "now SIGNAL m1_cont";
--connection master1
--reap
connection master;
DROP TABLE t1;
disable_warnings;
UNINSTALL PLUGIN rpl_semi_sync_master;
enable_warnings;
--source include/rpl_end.inc

View File

@ -0,0 +1,35 @@
# BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER
#
# The function mysql_show_binlog_events has a local stack variable
# 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however
# this variable goes out of scope and is destroyed before clean
# thd->current_linfo.
#
# This test case runs SHOW BINLOG EVENTS and FLUSH LOGS to make sure
# that with the fix local variable linfo is valid along all
# mysql_show_binlog_events function scope.
#
--source include/have_debug_sync.inc
--source include/master-slave.inc
--echo [connection slave]
--connection slave
SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end';
--send SHOW BINLOG EVENTS
--connection slave1
--echo [connection slave1]
SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events';
FLUSH LOGS;
SET DEBUG_SYNC= 'now SIGNAL end';
SET DEBUG_SYNC= 'RESET';
--echo [connection slave]
--connection slave
--disable_result_log
--reap
--enable_result_log
SET DEBUG_SYNC= 'RESET';
--connection master
--source include/rpl_end.inc

View File

@ -38,21 +38,23 @@ connection master;
# 9000 is the value of the port we should get. # 9000 is the value of the port we should get.
--let $report_port= query_get_value(SHOW SLAVE HOSTS, Port, 1) --let $report_port= query_get_value(SHOW SLAVE HOSTS, Port, 1)
--let assert_text= The value shown for the slave's port number is 9000 which is the value set for report-port. --let assert_text= The value shown for the slave's port number is user specified port number which is the value set for report-port.
--let assert_cond= $report_port = "9000" --let assert_cond= $report_port = "9000"
--source include/assert.inc --source include/assert.inc
# Start the server with the report-port being passed with no value. So on SHOW SLAVE HOSTS # Start the server with the report-port being passed with no value. So on SHOW SLAVE HOSTS
# on the master the value of slave's port should be the actual value of the slave port. # on the master the value of slave's port should be the actual value of the slave port.
connection master;
--let $rpl_server_number= 2 --let $rpl_server_number= 2
--let $rpl_server_parameters= --report-port= --let $rpl_server_parameters=
--source include/rpl_restart_server.inc --source include/rpl_restart_server.inc
connection slave; connection slave;
--source include/start_slave.inc --source include/start_slave.inc
connection master;
sync_slave_with_master;
--echo [Slave restarted with the report-port set to the value of slave's port number] --echo [Slave restarted with the report-port set to the value of slave's port number]
connection master; connection master;

View File

@ -46,14 +46,17 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition 1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
drop table ts; drop table ts;
show status like "sphinx_%"; show status like "sphinx_error%";
Variable_name Value Variable_name Value
sphinx_error_commits 0 sphinx_error_commits 0
sphinx_error_group_commits 0 sphinx_error_group_commits 0
sphinx_error_snapshot_file sphinx_error_snapshot_file
sphinx_error_snapshot_position 0 sphinx_error_snapshot_position 0
sphinx_time 0 show status like "sphinx_total%";
Variable_name Value
sphinx_total 2 sphinx_total 2
sphinx_total_found 2 sphinx_total_found 2
show status like "sphinx_word%";
Variable_name Value
sphinx_word_count 0 sphinx_word_count 0
sphinx_words sphinx_words

View File

@ -26,4 +26,6 @@ explain select * from ts where q=';groupby=attr:gid';
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
drop table ts; drop table ts;
show status like "sphinx_%"; show status like "sphinx_error%";
show status like "sphinx_total%";
show status like "sphinx_word%";

View File

@ -11,4 +11,5 @@
############################################################################## ##############################################################################
innodb_trx_rseg_n_slots_debug_basic: variable innodb_trx_rseg_n_slots_debug is removed in MariaDB innodb_trx_rseg_n_slots_debug_basic: variable innodb_trx_rseg_n_slots_debug is removed in MariaDB
innodb_flush_checkpoint_debug_basic: removed from XtraDB-26.0

View File

@ -10,5 +10,6 @@ there should be *no* long test name listed below:
select distinct variable_name as `there should be *no* variables listed below:` from t2 select distinct variable_name as `there should be *no* variables listed below:` from t2
left join t1 on variable_name=test_name where test_name is null; left join t1 on variable_name=test_name where test_name is null;
there should be *no* variables listed below: there should be *no* variables listed below:
expensive_subquery_limit
drop table t1; drop table t1;
drop table t2; drop table t2;

View File

@ -1,11 +1,6 @@
--source include/have_innodb.inc --source include/have_innodb.inc
--source include/have_debug.inc --source include/have_debug.inc
if (`select plugin_auth_version <= "1.1.8-24.1" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not supported by XtraDB 1.1.8-24.1 or earlier
}
SET @start_global_value = @@global.innodb_trx_rseg_n_slots_debug; SET @start_global_value = @@global.innodb_trx_rseg_n_slots_debug;
SELECT @start_global_value; SELECT @start_global_value;

View File

@ -146,6 +146,42 @@ table_schema table_name column_name column_type extra
test t2 a int(11) test t2 a int(11)
test t2 b int(11) VIRTUAL test t2 b int(11) VIRTUAL
DROP TABLE t1,t2; DROP TABLE t1,t2;
create table t1 (
a int not null, b char(2) not null,
c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent
);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` char(2) NOT NULL,
`c` enum('Y','N') AS (case when b = 'aa' then 'Y' else 'N' end) PERSISTENT
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc');
select * from t1;
a b c
1 bb N
2 aa Y
3 cc N
create table t2 (
a int, b int,
c set("y","n")
as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent
);
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` set('y','n') AS (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) PERSISTENT
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t2(a,b) values (7,0), (2,3), (0,1);
select * from t2;
a b c
7 0 y,n
2 3 y
0 1 y,n
drop table t1,t2;
create table t1 (a int, b int); create table t1 (a int, b int);
insert into t1 values (3, 30), (4, 20), (1, 20); insert into t1 values (3, 30), (4, 20), (1, 20);
create table t2 (c int, d int, v int as (d+1), index idx(c)); create table t2 (c int, d int, v int as (d+1), index idx(c));

View File

@ -155,6 +155,29 @@ SELECT table_schema, table_name, column_name, column_type, extra
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug mdev-354: virtual columns of ENUM and SET types
#
create table t1 (
a int not null, b char(2) not null,
c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent
);
show create table t1;
insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc');
select * from t1;
create table t2 (
a int, b int,
c set("y","n")
as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent
);
show create table t2;
insert into t2(a,b) values (7,0), (2,3), (0,1);
select * from t2;
drop table t1,t2;
# #
# SELECT that uses a virtual column and executed with BKA # SELECT that uses a virtual column and executed with BKA
# #

View File

@ -0,0 +1,51 @@
--echo #
--echo # Bug#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE.
--echo #
--source include/not_embedded.inc
--source include/have_perfschema.inc
--disable_warnings
create database show_table_lw_db;
use show_table_lw_db;
create table t1 (c1 int);
create table t2 (c1 int);
create table t3 (c1 int);
create table t4 (c1 int);
create table t5 (c1 int);
create table t6 (c1 int);
create table t7 (c1 int);
create table t8 (c1 int);
create table t9 (c1 int);
create table t10 (c1 int);
--enable_warnings
# Query PS to know initial read count for frm file.
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_before;
show tables;
# Query PS to know read count for frm file after above query. It should
# not be changed as FRM file will not be opened for above query.
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_after;
select @count_read_after-@count_read_before;
show full tables;
# Query PS to know read count for frm file after above query. COUNT_READ
# will be incremented by 1 as FRM file will be opened for above query.
select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME
like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
into @count_read_after;
select @count_read_after-@count_read_before;
--disable_warnings
drop table t1;
drop database show_table_lw_db;
--enable_warnings

View File

@ -144,5 +144,33 @@ SELECT BIT_XOR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
--echo #
--echo # Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY
--echo # COUNT(*) LIMIT.
--echo #
CREATE TABLE t1 (
id BIGINT(20) ,
member_id_to INT(11) ,
r_date DATE ,
PRIMARY KEY (id,r_date),
KEY r_date_idx (r_date),
KEY t1_idx01 (member_id_to)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES
(107924526,518491,'2011-05-01'),
(107924527,518491,'2011-05-01'),
(107924534,518491,'2011-06-21'),
(107924535,518491,'2011-06-21'),
(107924542,1601319,'2011-06-21'),
(107924543,1601319,'2011-06-21'),
(107924544,1601319,'2011-06-21'),
(107924545,1601319,'2011-06-21');
SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
'2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
DROP TABLE t1;
--echo End of 5.5 tests --echo End of 5.5 tests

View File

@ -577,3 +577,32 @@ DROP TABLE t1;
--echo # --echo #
--echo End of 5.1 tests --echo End of 5.1 tests
#
# lp:817966 int_column IN (string_constant)
#
# rather illogically, when BIGINT field is compared to a string,
# the string is converted to an integer, not to a double.
# When some other integer field (not BIGINT) is compared to a string,
# or when the BIGINT is not a field, but an expression, both
# operands are compared as doubles. The latter behavior is correct,
# according to the manual.
#
create table t1 (a bigint, b int);
insert t1 values (1,1),(2,2),(3,3);
select * from t1 where a in ('2.1');
select * from t1 where b in ('2.1');
select * from t1 where a='2.1';
select * from t1 where b='2.1';
select * from t1 where IF(1,a,a)='2.1';
drop table t1;
--echo #
--echo # LP bug#992380 Crash when creating PS for a query with
--echo # subquery in WHERE (see also mysql bug#13012483)
--echo #
CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;
DROP TABLE t1;
--echo # End of 5.3 tests

View File

@ -160,3 +160,23 @@ SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL;
SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL;
# End of 4.1 tests # End of 4.1 tests
#
# test of replacing NOT <field>
#
create table t1 (a int);
insert into t1 values (1), (100), (0), (NULL);
select not a from t1;
explain extended select not a from t1;
select * from t1 where not a;
explain extended select * from t1 where not a;
select not (a+0) from t1;
explain extended select not (a+0) from t1;
select * from t1 where not (a+0);
explain extended select * from t1 where not (a+0);
drop table t1;

14
mysql-test/t/mdev316.test Normal file
View File

@ -0,0 +1,14 @@
#
# MDEV-316 lp:1009085 Assertion failed: warn_item, file item_cmpfunc.cc, line 3613
#
set names swe7;
select '' in ('',convert(0,time));
select case '' when '' then 1 when convert(0,time) then 2 end;
#
# Excessive optimization of Item_func_conv_charset:
#
select convert(0x0030 using ucs2) div 1, concat(convert(0x0030 using ucs2)) div 1;
select cast(convert(0x0030 using ucs2) as double), cast(concat(convert(0x0030 using ucs2)) as double);
select cast(convert(0x0030 using ucs2) as decimal(5.2)), cast(concat(convert(0x0030 using ucs2)) as decimal(5.2));
select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date);

View File

@ -2413,3 +2413,30 @@ RESET MASTER;
# Wait till we reached the initial number of concurrent sessions # Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc --source include/wait_until_count_sessions.inc
--echo #
--echo # Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM
--echo #
SET @old_log_output_state= @@global.log_output;
SET @old_general_log_state= @@global.general_log;
SET @old_slow_query_log_state= @@global.slow_query_log;
call mtr.add_suppression("Failed to write to mysql.general_log");
--exec $MYSQL_DUMP -uroot --all-databases > $MYSQLTEST_VARDIR/tmp/bug45740.sql
# Make log_output as table and disabling general_log and slow_log
SET @@global.log_output="TABLE";
SET @@global.general_log='OFF';
SET @@global.slow_query_log='OFF';
DROP DATABASE mysql;
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug45740.sql
SHOW CREATE TABLE mysql.general_log;
SHOW CREATE TABLE mysql.slow_log;
--remove_file $MYSQLTEST_VARDIR/tmp/bug45740.sql
SET @@global.log_output= @old_log_output_state;
SET @@global.slow_query_log= @old_slow_query_log_state;
SET @@global.general_log= @old_general_log_state;
--echo #
--echo # End of 5.1 tests
--echo #

Some files were not shown because too many files have changed in this diff Show More