developers
Threads by month
- ----- 2025 -----
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 8 participants
- 6853 discussions

[Maria-developers] FYI: @@optimizer_switch default changed to have semijoin switched ON.
by Sergei Petrunia 08 Nov '11
by Sergei Petrunia 08 Nov '11
08 Nov '11
Hi!
If you haven't noticed: last week I've pushed a change that enabled semi-join
optimization flags by default, i.e. now the default @@optimizer_swich value
has:
semijoin=on
firstmatch=on
loosescan=on
Philip: if you have any testing planned for "after semi-join optimizations are
enabled by default", now it's time to do them.
BR
Sergei
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
3
2
While working on MariaDB on HP-UX we noticed an inconsistency involving
the type of enum arguments.
In init_variables and init_one_value (mysys/my_getopt.c), ENUM options
are treated as unsigned longs but the enum arguments are actually
declared as uint instead of ulong. While this doesn't matter in 32 bit
mode when int's and longs's are the same size, it can cause problems in
64 bit mode when long's are 64 bits and int's 32 bits.
We found 4 variables that we think should be ulong instead of uint:
plugin_maturity
plugin_maturity_map
thread_handling
delay_key_write_options
We also changed the value field in the sys_var_enum class (sql/set_var.h)
from a uint pointer to a ulong pointer and changed the sys_var_enum and
sys_var_enum_const constructors to use a ulong pointer argument for value_arg
to make everything consistent.
I suppose init_variables and init_one_value could be changed to treat
ENUM's as uint instead of ulong but the use of ulong seemed to be
intentional so we didn't try making that change as an alternative fix.
Is this a change that should be made in the official MariaDB sources?
Steve Ellcey
sje(a)cup.hp.com
5
8

[Maria-developers] review: [Commits] Rev 3045: Fix gcc 4.6 warning after merge with 5.1 in file:///home/bell/maria/bzr/work-maria-5.2-merge/
by Michael Widenius 04 Nov '11
by Michael Widenius 04 Nov '11
04 Nov '11
Hi!
Review follows:
> Fix gcc 4.6 warning after merge with 5.1
> === modified file 'sql/table.cc'
> --- a/sql/table.cc 2011-09-01 18:18:29 +0000
> +++ b/sql/table.cc 2011-10-27 16:18:25 +0000
> @@ -5484,7 +5484,7 @@ int update_virtual_fields(THD *thd, TABL
> {
> DBUG_ENTER("update_virtual_fields");
> Field **vfield_ptr, *vfield;
> - int error= 0;
> + int error __attribute__ ((unused))= 0;
> if (!table || !table->vfield)
> DBUG_RETURN(0);
The above is wrong.
The bug is that we ignore the value of error later down:
error= vfield->vcol_info->expr_item->save_in_field(vfield, 0);
We should change the above code to be:
if (!ignore_errors && error < 0)
{
my_printf_error(ER_UNKNOWN_ERROR, "Got error when computing value
for virtual column %s", vfield->field_name, MYF(0));
DBUG_RETURN(1);
}
We also need to add 'ignore_errors' as a parameter and add the new
parameter to the calls. This can for now be '0' for all cases except
for the cases where we check the value for the function, like in
fill_record where we already handle the ignore_errors variable.
Regards,
Monty
1
0
Hi Daniel,
I believe I've fixed the issues for our .debs on Ubuntu 11.10.
I made buildbot create packages for MariaDB 5.2.9. They pass the tests.
Buildnumber: 1325
Location in archive: /archive/pack/5.2/build-1325/kvm-deb-oneiric-*
Maybe you can make them available alongside the existing 5.2.9 packages? It is
the exact code version as the other platforms, but the packaging scripts are
modified of course. There is no apparmor profile by default (this kept causing
new problems, and future packages on Ubuntu will have it disabled by default).
Maybe you can help test them as an extra check on top of the automatic ones in
buildbot?
I also tried getting 5.3 packages built, but Buildbot kept building the latest
revision rather than the 5.3.2 one. I can probably solve that somehow, but
unless it is urgent I would like to just wait for the next 5.3 release, which
will get Oneiric packages automatically.
Note that for 5.1, we currently have a problem, as Oneiric has MySQL 5.1.58
while the MariaDB version is 5.1.55. But for the next 5.1 release we will
presumably merge MySQL 5.1.58 anyway, so this will get solved and most people
will want to use 5.2 anyway I think.
I think that's it, let me know if you have questions or other suggestions.
- Kristian.
2
4

02 Nov '11
Marian Marinov <mm(a)yuhu.biz> writes:
> I'm trying to build MariaDB packages for CentOS.
> But the problem I have is that the Policy of the distro does not allow
> packages that are drop-in replacements of core packages.
> Meaning that I can not simply build MariaDB which will provide libmysqlclient
> and mysql binaries.
>
> Can you share with me what is the situation over in the Debian/Ubuntu camp ?
In Debian/Ubuntu, there are no "Official" MariaDB packages yet. The ones we
provide do replace the standard mysql packages, which is possible since there
are no policies enforced for 3rd-party repositories.
It will need to be fixed eventually, of course. The normal way I think in
Debian is to have MariaDB and MySQL as alternatives, just like Some versions
of Ubuntu/Debian have mysql-5.0 and mysql-5.1 as alternatives (can install one
or the other, but not both).
It is not 100% clear to me what your situation is (I'm not much familiar with
CentOS or RPM). Are you saying that the MariaDB packages you create *must* be
possible to install alongside the Official CentOS packages?
In that case I suppose you have little option but to run mariadb on a
different port, different data directory, different socket, different binary
names. It seems to be sub-optimal for users, as they would need to reconfigure
anything they want to use with MariaDB away from the standard port/names in
the MySQL world.
Still, this is perfectly possible to do. Configure a non-standard port in your
my.cnf, build and install mariadb with a different --prefix, /opt/mariadb or
whatever.
- Kristian.
3
2

Re: [Maria-developers] [Commits] Rev 3262: Fix bug lp:833702 in file:///home/tsk/mprog/src/5.3/
by Oleksandr Byelkin 01 Nov '11
by Oleksandr Byelkin 01 Nov '11
01 Nov '11
Hi!
01.11.2011 18:19, timour(a)askmonty.org пишет:
> At file:///home/tsk/mprog/src/5.3/
>
> ------------------------------------------------------------
> revno: 3262
> revision-id: timour(a)askmonty.org-20111101161919-hukh3tipjms3lfzf
> parent: sanja(a)askmonty.org-20111101112209-n4ghsy9hpliiassm
> fixes bug(s): https://launchpad.net/bugs/833702
> committer: timour(a)askmonty.org
> branch nick: 5.3
> timestamp: Tue 2011-11-01 18:19:19 +0200
> message:
> Fix bug lp:833702
>
> Analysis:
> Equality propagation propagated the constant '7' into
> args[0] of the Item_in_optimizer that stands for the
> "< ANY" predicate. At the same the min/max subquery
> rewrite swapped the order of the left and right operands
> of the "<" predicate, but used Item_in_subselect::left_expr.
>
> As a result, when the<ANY predicate is executed early in the
> execution phase as a contant condition, instead of a constant
> right (swapped) argument of the< predicate, there was a field
> (t3.a). This field had no data, since the whole predicate is
> considered constant, and it is evaluated before any tables are
> read. Having junk in the field row buffer produced wrong result
>
> Solution:
> Fix create_swap to pick the correct Item_in_optimizer left
> argument.
OK to push.
1
0
I have downloaded, built and tested MariaDB 5.3.2 Beta on HP-UX 11.31
and I get two test failures, I have a question about one of tests that
I was hoping someone could help me with.
The main.cast test fails and the problem is with this part of the test:
select cast(cast(20010203101112.1 as double) as datetime(1));
It is converting the string "20010203101112.1" to a double value and then
converting the double value to a date. The test expects "2001-02-03
10:11:12.1" to be output but I am getting "2001-02-03 10:11:12.0".
I think the problem is with the conversion into floating point. When I
use gdb to break sql at double_to_datetime, on HP-UX the value I have is
20010203101112.098, on Linux I see 20010203101112.102. Neither value
is completely correct because 20010203101112.1 cannot be represented
exactly as an IEEE floating point value.
So I have two questions. Where did the string get converted into a
floating point value? I couldn't find where this is happening, I assume
it is using strtod or something but breaking on that function didn't
do anything. Secondly, given that 20010203101112.1 cannot be represented
exactly as a double precision floating point value, is this a valid test?
FYI: The other failure I get is main.cast, this test is trying to check
for a stack overflow before it happens but IA64 HP-UX has two stacks, a
register stack and a user data stack. In this test case the recursion of
p_ere and p_ere_exp wind up using only the register stack because all the
local variables and arguments are stored in registers. The stack check
in check_stack_overrun is checking the user stack which doesn't overflow
(or even change) and so we eventually die with a register stack overflow.
There is a way to check the register stack on IA64 HP-UX, but it would
require using IA64 assembly language so it may not be worth doing.
Steve Ellcey
sje(a)cup.hp.com
3
4

Re: [Maria-developers] [Commits] Rev 3100: Fix gcc 4.6 warnings about assigned but not used variables. in file:///home/bell/maria/bzr/work-maria-5.1-applebuild/
by Michael Widenius 27 Oct '11
by Michael Widenius 27 Oct '11
27 Oct '11
Hi!
>>>>> "sanja" == sanja <sanja(a)askmonty.org> writes:
sanja> At file:///home/bell/maria/bzr/work-maria-5.1-applebuild/
sanja> ------------------------------------------------------------
sanja> revno: 3100
sanja> revision-id: sanja(a)askmonty.org-20111025142424-dntpnipgi5qxg2io
sanja> parent: wlad(a)montyprogram.com-20111019185101-fw3oxkpr2o060qk4
sanja> committer: sanja(a)askmonty.org
sanja> branch nick: work-maria-5.1-applebuild
sanja> timestamp: Tue 2011-10-25 17:24:24 +0300
sanja> message:
sanja> Fix gcc 4.6 warnings about assigned but not used variables.
sanja> Fixed my_gethwaddr.c to allow compilation on Mac OS X.
<cut>
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2011-05-12 11:56:08 +0000
+++ b/sql/sql_show.cc 2011-10-25 14:24:24 +0000
@@ -1215,7 +1215,7 @@ int store_create_info(THD *thd, TABLE_LI
handler *file= table->file;
TABLE_SHARE *share= table->s;
HA_CREATE_INFO create_info;
- bool show_table_options= FALSE;
+ bool show_table_options __attribute__ ((unused))= FALSE;
bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |
MODE_ORACLE |
MODE_MSSQL |
Add instead:
#ifdef WITH_PARTITION_STORAGE_ENGINE
around the this the definition of the variable.
@@ -1432,7 +1432,9 @@ int store_create_info(THD *thd, TABLE_LI
packet->append(STRING_WITH_LEN("\n)"));
if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
{
+#ifdef WITH_PARTITION_STORAGE_ENGINE
show_table_options= TRUE;
+#endif
The above is correct; Better to do it this way.
=== modified file 'storage/maria/ma_blockrec.c'
--- a/storage/maria/ma_blockrec.c 2011-07-24 08:25:28 +0000
+++ b/storage/maria/ma_blockrec.c 2011-10-25 14:24:24 +0000
@@ -4997,7 +4997,7 @@ static my_bool read_row_extent_info(MARI
MARIA_EXTENT_CURSOR extent;
MARIA_RECORD_POS *tail_pos;
uchar *data, *end_of_data;
- uint flag, row_extents, row_extents_size, field_lengths;
+ uint flag, row_extents, row_extents_size;
uchar *extents, *end;
DBUG_ENTER("read_row_extent_info");
@@ -5032,9 +5032,6 @@ static my_bool read_row_extent_info(MARI
}
info->cur_row.extents_count= row_extents;
- if (share->base.max_field_lengths)
- get_key_length(field_lengths, data);
-
The above is wrong. get_key_length will increment data, which is
required as data it's used later.
Better to leave field_lengths there for the future.
(Please fix this in 5.3 too !)
You can avoid the warning by doing:
get_key_length= get_key_length;
=== modified file 'storage/maria/ma_dynrec.c'
--- a/storage/maria/ma_dynrec.c 2011-02-25 12:55:40 +0000
+++ b/storage/maria/ma_dynrec.c 2011-10-25 14:24:24 +0000
@@ -1741,7 +1741,8 @@ int _ma_read_rnd_dynamic_record(MARIA_HA
MARIA_RECORD_POS filepos,
my_bool skip_deleted_blocks)
{
- int block_of_record, info_read;
+ int block_of_record;
+ int info_read;
Why the above?
=== modified file 'storage/maria/ma_ft_update.c'
--- a/storage/maria/ma_ft_update.c 2009-01-30 21:55:42 +0000
+++ b/storage/maria/ma_ft_update.c 2011-10-25 14:24:24 +0000
@@ -319,7 +319,6 @@ my_bool _ma_ft_convert_to_ft2(MARIA_HA *
uchar *key_ptr= (uchar*) dynamic_array_ptr(da, 0), *end;
uint length, key_length;
MARIA_PINNED_PAGE tmp_page_link, *page_link= &tmp_page_link;
- MARIA_KEY tmp_key;
MARIA_PAGE page;
DBUG_ENTER("_ma_ft_convert_to_ft2");
@@ -357,13 +356,8 @@ my_bool _ma_ft_convert_to_ft2(MARIA_HA *
/* inserting the rest of key values */
end= (uchar*) dynamic_array_ptr(da, da->elements);
- tmp_key.keyinfo= keyinfo;
- tmp_key.data_length= keyinfo->keylength;
- tmp_key.ref_length= 0;
- tmp_key.flag= 0;
for (key_ptr+=length; key_ptr < end; key_ptr+=keyinfo->keylength)
{
- tmp_key.data= key_ptr;
if (_ma_ck_real_write_btree(info, key, &root, SEARCH_SAME))
DBUG_RETURN(1);
}
Wrong. The correct fix is:
if (_ma_ck_real_write_btree(info, key, &root, SEARCH_SAME))
DBUG_RETURN(1);
->
if (_ma_ck_real_write_btree(info, &tmp_key, &root, SEARCH_SAME))
DBUG_RETURN(1);
Apparently free textsearch with Aria is not tested properly :(
<cut>
=== modified file 'storage/maria/ma_open.c'
--- a/storage/maria/ma_open.c 2011-07-24 08:25:28 +0000
+++ b/storage/maria/ma_open.c 2011-10-25 14:24:24 +0000
@@ -1802,7 +1802,6 @@ void _ma_set_index_pagecache_callbacks(P
int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share, const char *org_name,
File file_to_dup __attribute__((unused)))
{
- char *data_name= share->data_file_name.str;
char real_data_name[FN_REFLEN];
if (org_name)
@@ -1816,7 +1815,6 @@ int _ma_open_datafile(MARIA_HA *info, MA
my_errno= HA_WRONG_CREATE_OPTION;
return 1;
}
- data_name= real_data_name;
}
}
Wrong:
The correct fix is:
info->dfile.file= share->bitmap.file.file=
my_open(share->data_file_name.str, share->mode | O_SHARE,
MYF(MY_WME));
->
info->dfile.file= share->bitmap.file.file=
my_open(data_name, share->mode | O_SHARE, MYF(MY_WME));
The above means that symlinking didn't work on windows with Aria
files.
=== modified file 'storage/maria/ma_rt_split.c'
--- a/storage/maria/ma_rt_split.c 2010-09-05 23:25:44 +0000
+++ b/storage/maria/ma_rt_split.c 2011-10-25 14:24:24 +0000
@@ -380,7 +380,6 @@ int maria_rtree_split_page(const MARIA_K
SplitStruct *stop;
double *coord_buf;
double *next_coord;
- double *old_coord;
int n_dim;
uchar *source_cur, *cur1, *cur2;
uchar *new_page_buff, *log_internal_copy, *log_internal_copy_ptr,
@@ -426,7 +425,6 @@ int maria_rtree_split_page(const MARIA_K
maria_rtree_d_mbr(keyinfo->seg, key->data, key_data_length, cur->coords);
cur->key= key->data;
- old_coord= next_coord;
myisam/rt_split.c has the exact same code. You should do the same
change there.
=== modified file 'storage/myisam/mi_check.c'
--- a/storage/myisam/mi_check.c 2011-05-02 17:58:45 +0000
+++ b/storage/myisam/mi_check.c 2011-10-25 14:24:24 +0000
@@ -946,7 +946,6 @@ int chk_data_link(HA_CHECK *param, MI_IN
char llbuff[22],llbuff2[22],llbuff3[22];
ha_checksum intern_record_checksum;
ha_checksum key_checksum[HA_MAX_POSSIBLE_KEY];
- my_bool static_row_size;
MI_KEYDEF *keyinfo;
MI_BLOCK_INFO block_info;
DBUG_ENTER("chk_data_link");
@@ -971,7 +970,6 @@ int chk_data_link(HA_CHECK *param, MI_IN
empty=info->s->pack.header_length;
/* Check how to calculate checksum of rows */
- static_row_size=1;
if (info->s->data_file_type == COMPRESSED_RECORD)
{
for (field=0 ; field < info->s->base.fields ; field++)
@@ -979,7 +977,6 @@ int chk_data_link(HA_CHECK *param, MI_IN
if (info->s->rec[field].base_type == FIELD_BLOB ||
info->s->rec[field].base_type == FIELD_VARCHAR)
{
- static_row_size=0;
break;
}
}
Please remove also the if and the loop around the above code.
=== modified file 'storage/pbxt/src/ha_pbxt.cc'
--- a/storage/pbxt/src/ha_pbxt.cc 2010-11-26 22:37:34 +0000
+++ b/storage/pbxt/src/ha_pbxt.cc 2011-10-25 14:24:24 +0000
@@ -1559,7 +1559,7 @@ static int pbxt_rollback(handlerton *hto
if (!all)
self->st_stat_trans = FALSE;
}
- return 0;
+ return err;
}
#ifdef DRIZZLED
@@ -2863,7 +2863,7 @@ int ha_pbxt::update_row(const byte * old
* insert into t1 (val) values (1);
*/
if (table->found_next_number_field && new_data == table->record[0]) {
- MX_LONGLONG_T nr;
+ MX_LONGLONG_T nr __attribute__ ((unused));
my_bitmap_map *old_map;
old_map = mx_tmp_use_all_columns(table, table->read_set);
Better to remove the nr value totally (and the call that sets it).
This is safe as in the code:
nr = table->found_next_number_field->val_int();
ha_set_auto_increment(pb_open_tab, table->found_next_number_field);
The first thing ha_set_auto_increment() is doing is calling val_int() on
the second argument.
<cut>
=== modified file 'storage/pbxt/src/thread_xt.cc'
--- a/storage/pbxt/src/thread_xt.cc 2010-09-28 13:05:45 +0000
+++ b/storage/pbxt/src/thread_xt.cc 2011-10-25 14:24:24 +0000
@@ -485,7 +485,8 @@ static void thr_free_resources(XTThreadP
xtPublic void xt_bug(XTThreadPtr XT_UNUSED(self))
{
- static int *bug_ptr = NULL;
+ static int *bug_ptr __attribute__ ((unused));
+ bug_ptr= NULL;
bug_ptr = NULL;
}
No reason to set this to null twice.
Better to remove the variable altogether.
=== modified file 'storage/pbxt/src/xactlog_xt.cc'
--- a/storage/pbxt/src/xactlog_xt.cc 2010-05-05 10:59:57 +0000
+++ b/storage/pbxt/src/xactlog_xt.cc 2011-10-25 14:24:24 +0000
@@ -2117,7 +2117,7 @@ xtBool XTDatabaseLog::xlog_seq_next(XTXa
size_t rec_offset;
size_t max_rec_len;
size_t size;
- u_int check_size = 1;
+ u_int check_size __attribute__ ((unused))= 1;
Don't understand the above change.
We both set check_size and test it in the above function.
Are you sure that you get a warning about the above?
/* Go to the next record (xseq_record_len must be initialized
* to 0 for this to work.
@@ -2629,7 +2629,7 @@ static void *xlog_wr_run_thread(XTThread
{
XTDatabaseHPtr db = (XTDatabaseHPtr) self->t_data;
int count;
- void *mysql_thread;
+ void *mysql_thread __attribute__ ((unused));
mysql_thread = myxt_create_thread();
=== modified file 'storage/xtradb/btr/btr0cur.c'
--- a/storage/xtradb/btr/btr0cur.c 2011-04-29 14:16:42 +0000
+++ b/storage/xtradb/btr/btr0cur.c 2011-10-25 14:24:24 +0000
@@ -3301,7 +3301,7 @@ static
void
btr_record_not_null_field_in_rec(
/*=============================*/
- rec_t* rec, /*!< in: physical record */
+ rec_t* rec __attribute__ ((unused)),/*!< in: physical record */
ulint n_unique, /*!< in: dict_index_get_n_unique(index),
number of columns uniquely determine
an index entry */
@@ -3321,9 +3321,8 @@ btr_record_not_null_field_in_rec(
for (i = 0; i < n_unique; i++) {
ulint rec_len;
- byte* field;
- field = rec_get_nth_field(rec, offsets, i, &rec_len);
+ rec_get_nth_field_offs(offsets, i, &rec_len);
if (rec_len != UNIV_SQL_NULL) {
n_not_null[i]++;
=== modified file 'storage/xtradb/buf/buf0buf.c'
--- a/storage/xtradb/buf/buf0buf.c 2011-04-29 14:16:42 +0000
+++ b/storage/xtradb/buf/buf0buf.c 2011-10-25 14:24:24 +0000
@@ -3895,7 +3895,7 @@ buf_page_io_complete(
enum buf_io_fix io_type;
const ibool uncompressed = (buf_page_get_state(bpage)
== BUF_BLOCK_FILE_PAGE);
- enum buf_flush flush_type;
+ //enum buf_flush flush_type;
mutex_t* block_mutex;
ut_a(buf_page_in_file(bpage));
@@ -4051,7 +4051,7 @@ corrupt:
//buf_pool_mutex_enter();
if (io_type == BUF_IO_WRITE) {
- flush_type = buf_page_get_flush_type(bpage);
+ //flush_type = buf_page_get_flush_type(bpage);
/* to keep consistency at buf_LRU_insert_zip_clean() */
//if (flush_type == BUF_FLUSH_LRU) { /* optimistic! */
mutex_enter(&LRU_list_mutex);
Remove the variable from the start of the function and
enum buf_flush flush_type; to the if. That way, all the comments are
in one place.
Ok to push after the above changes.
Regards,
Monty
3
5

27 Oct '11
Hello!
JFYI I've just pushed the fix for table_elim.test into 5.5-main.
With this, I consider my involvement with 5.5 merge to be done, i.e.
I don't have anything on my todo that's related to 5.5.
BR
Sergei
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

Re: [Maria-developers] [Commits] Rev 3249: Fix of LP BUG#872775. in file:///home/bell/maria/bzr/work-maria-5.3-lpb872775/
by Sergei Petrunia 26 Oct '11
by Sergei Petrunia 26 Oct '11
26 Oct '11
Hi Sanja,
Please add a comment around the defitions of nest_level / nest_level_base that
nest_levels are local to the query or VIEW, and that view merge procedure does
not re-calculate them.
Ok to push after the above is addressed.
On Tue, Oct 25, 2011 at 11:59:37AM +0300, sanja(a)askmonty.org wrote:
> At file:///home/bell/maria/bzr/work-maria-5.3-lpb872775/
>
> ------------------------------------------------------------
> revno: 3249
> revision-id: sanja(a)askmonty.org-20111025085936-h0jyyxtbv3qhp4f4
> parent: igor(a)askmonty.org-20111023124603-sjv665ajk25b4dgi
> committer: sanja(a)askmonty.org
> branch nick: work-maria-5.3-lpb872775
> timestamp: Tue 2011-10-25 11:59:36 +0300
> message:
> Fix of LP BUG#872775.
>
> The problem was that merged views has its own nest_level numbering =>
> when we compare nest levels we should take into considiration basis (i.e. 0 level),
> if it is different then nest levels are not comparable.
> === modified file 'mysql-test/r/subselect_cache.result'
> --- a/mysql-test/r/subselect_cache.result 2011-07-19 20:19:10 +0000
> +++ b/mysql-test/r/subselect_cache.result 2011-10-25 08:59:36 +0000
> @@ -1,3 +1,5 @@
> +drop table if exists t1,t2,t3,t4,t5;
> +drop view if exists v1;
> set optimizer_switch='subquery_cache=on';
> create table t1 (a int, b int);
> insert into t1 values (1,2),(3,4),(1,2),(3,4),(3,4),(4,5),(4,5),(5,6),(5,6),(4,5);
> @@ -3354,5 +3356,31 @@ f1 f2 f3 f3
> 7 0 0 0
> 7 0 0 0
> drop tables t1, t2, t3;
> +#
> +# Test of LP BUG#872775 view with "outer references" bug
> +#
> +set @@optimizer_switch= default;
> +set optimizer_switch='subquery_cache=on';
> +CREATE TABLE t1 (a int) ;
> +CREATE TABLE t2 (b int, c varchar(1) NOT NULL ) ;
> +INSERT INTO t2 VALUES (1,'x'),(2,'y');
> +CREATE TABLE t3 (a int) ;
> +CREATE TABLE t4 ( pk int(11) NOT NULL , b int(11) NOT NULL ) ;
> +INSERT INTO t4 VALUES (26,9),(27,5),(28,0),(29,3);
> +CREATE OR REPLACE VIEW v1 AS
> +SELECT t2.b
> +FROM t1
> +JOIN t2
> +WHERE t2 .c > (
> +SELECT t2.c FROM t3
> +);
> +SELECT * FROM t4 WHERE b NOT IN ( SELECT * FROM v1 );
> +pk b
> +26 9
> +27 5
> +28 0
> +29 3
> +drop view v1;
> +drop table t1,t2,t3,t4;
> # restore default
> set @@optimizer_switch= default;
>
> === modified file 'mysql-test/t/subselect_cache.test'
> --- a/mysql-test/t/subselect_cache.test 2011-07-19 20:19:10 +0000
> +++ b/mysql-test/t/subselect_cache.test 2011-10-25 08:59:36 +0000
> @@ -1,4 +1,10 @@
>
> +--disable_warnings
> +drop table if exists t1,t2,t3,t4,t5;
> +drop view if exists v1;
> +--enable_warnings
> +
> +
> set optimizer_switch='subquery_cache=on';
>
> create table t1 (a int, b int);
> @@ -1664,5 +1670,33 @@ FROM t1
> WHERE t2.f1 OR t2.f3 );
> drop tables t1, t2, t3;
>
> +--echo #
> +--echo # Test of LP BUG#872775 view with "outer references" bug
> +--echo #
> +set @@optimizer_switch= default;
> +set optimizer_switch='subquery_cache=on';
> +CREATE TABLE t1 (a int) ;
> +
> +CREATE TABLE t2 (b int, c varchar(1) NOT NULL ) ;
> +INSERT INTO t2 VALUES (1,'x'),(2,'y');
> +
> +CREATE TABLE t3 (a int) ;
> +
> +CREATE TABLE t4 ( pk int(11) NOT NULL , b int(11) NOT NULL ) ;
> +INSERT INTO t4 VALUES (26,9),(27,5),(28,0),(29,3);
> +
> +CREATE OR REPLACE VIEW v1 AS
> +SELECT t2.b
> +FROM t1
> +JOIN t2
> +WHERE t2 .c > (
> + SELECT t2.c FROM t3
> + );
> +
> +SELECT * FROM t4 WHERE b NOT IN ( SELECT * FROM v1 );
> +
> +drop view v1;
> +drop table t1,t2,t3,t4;
> +
> --echo # restore default
> set @@optimizer_switch= default;
>
> === modified file 'sql/item.cc'
> --- a/sql/item.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/item.cc 2011-10-25 08:59:36 +0000
> @@ -755,7 +755,9 @@ bool Item_ident::remove_dependence_proce
> bool Item_ident::collect_outer_ref_processor(uchar *param)
> {
> Collect_deps_prm *prm= (Collect_deps_prm *)param;
> - if (depended_from && depended_from->nest_level < prm->nest_level)
> + if (depended_from &&
> + depended_from->nest_level_base == prm->nest_level_base &&
> + depended_from->nest_level < prm->nest_level)
> prm->parameters->add_unique(this, &cmp_items);
> return FALSE;
> }
>
> === modified file 'sql/item.h'
> --- a/sql/item.h 2011-10-22 07:14:27 +0000
> +++ b/sql/item.h 2011-10-25 08:59:36 +0000
> @@ -505,6 +505,7 @@ typedef void (*Cond_traverser) (const It
> class Item_equal;
> class COND_EQUAL;
>
> +class st_select_lex_unit;
>
> class Item {
> Item(const Item &); /* Prevent use of these */
> @@ -1159,8 +1160,10 @@ public:
> }
> struct Collect_deps_prm
> {
> - int nest_level;
> List<Item> *parameters;
> + /* unit from which we count nest_level */
> + st_select_lex_unit *nest_level_base;
> + int nest_level;
> };
> /**
> Collect outer references
>
> === modified file 'sql/item_subselect.cc'
> --- a/sql/item_subselect.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/item_subselect.cc 2011-10-25 08:59:36 +0000
> @@ -599,7 +599,9 @@ bool Item_subselect::exec()
>
> void Item_subselect::get_cache_parameters(List<Item> ¶meters)
> {
> - Collect_deps_prm prm= { unit->first_select()->nest_level, ¶meters };
> + Collect_deps_prm prm= {¶meters,
> + unit->first_select()->nest_level_base,
> + unit->first_select()->nest_level};
> walk(&Item::collect_outer_ref_processor, TRUE, (uchar*)&prm);
> }
>
>
> === modified file 'sql/item_sum.cc'
> --- a/sql/item_sum.cc 2011-07-19 20:19:10 +0000
> +++ b/sql/item_sum.cc 2011-10-25 08:59:36 +0000
> @@ -359,7 +359,9 @@ bool Item_sum::collect_outer_ref_process
> {
> Collect_deps_prm *prm= (Collect_deps_prm *)param;
> SELECT_LEX *ds;
> - if ((ds= depended_from()) && ds->nest_level < prm->nest_level)
> + if ((ds= depended_from()) &&
> + ds->nest_level_base == prm->nest_level_base &&
> + ds->nest_level < prm->nest_level)
> prm->parameters->add_unique(this, &cmp_items);
> return FALSE;
> }
>
> === modified file 'sql/sql_lex.cc'
> --- a/sql/sql_lex.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/sql_lex.cc 2011-10-25 08:59:36 +0000
> @@ -339,6 +339,7 @@ void lex_start(THD *thd)
> lex->event_parse_data= NULL;
> lex->profile_options= PROFILE_NONE;
> lex->nest_level=0 ;
> + lex->select_lex.nest_level_base= &lex->unit;
> lex->allow_sum_func= 0;
> lex->in_sum_func= NULL;
> lex->protect_against_global_read_lock= FALSE;
>
> === modified file 'sql/sql_lex.h'
> --- a/sql/sql_lex.h 2011-09-22 22:13:38 +0000
> +++ b/sql/sql_lex.h 2011-10-25 08:59:36 +0000
> @@ -684,6 +684,7 @@ public:
> ulong table_join_options;
> uint in_sum_expr;
> uint select_number; /* number of select (used for EXPLAIN) */
> + SELECT_LEX_UNIT *nest_level_base; /* unit from which we count nest_level */
> int nest_level; /* nesting level of select */
> Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
> uint with_wild; /* item list contain '*' */
>
> === modified file 'sql/sql_parse.cc'
> --- a/sql/sql_parse.cc 2011-10-11 10:55:42 +0000
> +++ b/sql/sql_parse.cc 2011-10-25 08:59:36 +0000
> @@ -5917,6 +5917,7 @@ mysql_new_select(LEX *lex, bool move_dow
> DBUG_RETURN(1);
> }
> select_lex->nest_level= lex->nest_level;
> + select_lex->nest_level_base= &thd->lex->unit;
> if (move_down)
> {
> SELECT_LEX_UNIT *unit;
>
> _______________________________________________
> commits mailing list
> commits(a)mariadb.org
> https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits
--
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

Re: [Maria-developers] [Commits] Rev 3249: Fix of LP BUG#872775. in file:///home/bell/maria/bzr/work-maria-5.3-lpb872775/
by Sergei Petrunia 25 Oct '11
by Sergei Petrunia 25 Oct '11
25 Oct '11
On Tue, Oct 25, 2011 at 11:59:37AM +0300, sanja(a)askmonty.org wrote:
> At file:///home/bell/maria/bzr/work-maria-5.3-lpb872775/
>
> ------------------------------------------------------------
> revno: 3249
> revision-id: sanja(a)askmonty.org-20111025085936-h0jyyxtbv3qhp4f4
> parent: igor(a)askmonty.org-20111023124603-sjv665ajk25b4dgi
> committer: sanja(a)askmonty.org
> branch nick: work-maria-5.3-lpb872775
> timestamp: Tue 2011-10-25 11:59:36 +0300
> message:
> Fix of LP BUG#872775.
>
> The problem was that merged views has its own nest_level numbering =>
> when we compare nest levels we should take into considiration basis (i.e. 0 level),
> if it is different then nest levels are not comparable.
:grep nest_level_base *.h *.c*
item.h|1165| st_select_lex_unit *nest_level_base;
sql_lex.h|687| SELECT_LEX_UNIT *nest_level_base; /* unit from which we count
nest_level */
item.cc|759| depended_from->nest_level_base == prm->nest_level_base &&
item_subselect.cc|603| unit->first_select()->nest_level_base,
item_sum.cc|363| ds->nest_level_base == prm->nest_level_base &&
sql_lex.cc|342| lex->select_lex.nest_level_base= &lex->unit;
sql_parse.cc|5920| select_lex->nest_level_base= &thd->lex->unit;
The only places where nest_level_base is assigned are:
sql_lex.cc|342| lex->select_lex.nest_level_base= &lex->unit;
sql_parse.cc|5920| select_lex->nest_level_base= &thd->lex->unit;
both of these initialize it to the top-level unit. So what is the point of
having nest_level_base in this case? Please clarify :)
> === modified file 'mysql-test/r/subselect_cache.result'
> --- a/mysql-test/r/subselect_cache.result 2011-07-19 20:19:10 +0000
> +++ b/mysql-test/r/subselect_cache.result 2011-10-25 08:59:36 +0000
> @@ -1,3 +1,5 @@
> +drop table if exists t1,t2,t3,t4,t5;
> +drop view if exists v1;
> set optimizer_switch='subquery_cache=on';
> create table t1 (a int, b int);
> insert into t1 values (1,2),(3,4),(1,2),(3,4),(3,4),(4,5),(4,5),(5,6),(5,6),(4,5);
> @@ -3354,5 +3356,31 @@ f1 f2 f3 f3
> 7 0 0 0
> 7 0 0 0
> drop tables t1, t2, t3;
> +#
> +# Test of LP BUG#872775 view with "outer references" bug
> +#
> +set @@optimizer_switch= default;
> +set optimizer_switch='subquery_cache=on';
> +CREATE TABLE t1 (a int) ;
> +CREATE TABLE t2 (b int, c varchar(1) NOT NULL ) ;
> +INSERT INTO t2 VALUES (1,'x'),(2,'y');
> +CREATE TABLE t3 (a int) ;
> +CREATE TABLE t4 ( pk int(11) NOT NULL , b int(11) NOT NULL ) ;
> +INSERT INTO t4 VALUES (26,9),(27,5),(28,0),(29,3);
> +CREATE OR REPLACE VIEW v1 AS
> +SELECT t2.b
> +FROM t1
> +JOIN t2
> +WHERE t2 .c > (
> +SELECT t2.c FROM t3
> +);
> +SELECT * FROM t4 WHERE b NOT IN ( SELECT * FROM v1 );
> +pk b
> +26 9
> +27 5
> +28 0
> +29 3
> +drop view v1;
> +drop table t1,t2,t3,t4;
> # restore default
> set @@optimizer_switch= default;
>
> === modified file 'mysql-test/t/subselect_cache.test'
> --- a/mysql-test/t/subselect_cache.test 2011-07-19 20:19:10 +0000
> +++ b/mysql-test/t/subselect_cache.test 2011-10-25 08:59:36 +0000
> @@ -1,4 +1,10 @@
>
> +--disable_warnings
> +drop table if exists t1,t2,t3,t4,t5;
> +drop view if exists v1;
> +--enable_warnings
> +
> +
> set optimizer_switch='subquery_cache=on';
>
> create table t1 (a int, b int);
> @@ -1664,5 +1670,33 @@ FROM t1
> WHERE t2.f1 OR t2.f3 );
> drop tables t1, t2, t3;
>
> +--echo #
> +--echo # Test of LP BUG#872775 view with "outer references" bug
> +--echo #
> +set @@optimizer_switch= default;
> +set optimizer_switch='subquery_cache=on';
> +CREATE TABLE t1 (a int) ;
> +
> +CREATE TABLE t2 (b int, c varchar(1) NOT NULL ) ;
> +INSERT INTO t2 VALUES (1,'x'),(2,'y');
> +
> +CREATE TABLE t3 (a int) ;
> +
> +CREATE TABLE t4 ( pk int(11) NOT NULL , b int(11) NOT NULL ) ;
> +INSERT INTO t4 VALUES (26,9),(27,5),(28,0),(29,3);
> +
> +CREATE OR REPLACE VIEW v1 AS
> +SELECT t2.b
> +FROM t1
> +JOIN t2
> +WHERE t2 .c > (
> + SELECT t2.c FROM t3
> + );
> +
> +SELECT * FROM t4 WHERE b NOT IN ( SELECT * FROM v1 );
> +
> +drop view v1;
> +drop table t1,t2,t3,t4;
> +
> --echo # restore default
> set @@optimizer_switch= default;
>
> === modified file 'sql/item.cc'
> --- a/sql/item.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/item.cc 2011-10-25 08:59:36 +0000
> @@ -755,7 +755,9 @@ bool Item_ident::remove_dependence_proce
> bool Item_ident::collect_outer_ref_processor(uchar *param)
> {
> Collect_deps_prm *prm= (Collect_deps_prm *)param;
> - if (depended_from && depended_from->nest_level < prm->nest_level)
> + if (depended_from &&
> + depended_from->nest_level_base == prm->nest_level_base &&
> + depended_from->nest_level < prm->nest_level)
> prm->parameters->add_unique(this, &cmp_items);
> return FALSE;
> }
>
> === modified file 'sql/item.h'
> --- a/sql/item.h 2011-10-22 07:14:27 +0000
> +++ b/sql/item.h 2011-10-25 08:59:36 +0000
> @@ -505,6 +505,7 @@ typedef void (*Cond_traverser) (const It
> class Item_equal;
> class COND_EQUAL;
>
> +class st_select_lex_unit;
>
> class Item {
> Item(const Item &); /* Prevent use of these */
> @@ -1159,8 +1160,10 @@ public:
> }
> struct Collect_deps_prm
> {
> - int nest_level;
> List<Item> *parameters;
> + /* unit from which we count nest_level */
> + st_select_lex_unit *nest_level_base;
> + int nest_level;
> };
> /**
> Collect outer references
>
> === modified file 'sql/item_subselect.cc'
> --- a/sql/item_subselect.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/item_subselect.cc 2011-10-25 08:59:36 +0000
> @@ -599,7 +599,9 @@ bool Item_subselect::exec()
>
> void Item_subselect::get_cache_parameters(List<Item> ¶meters)
> {
> - Collect_deps_prm prm= { unit->first_select()->nest_level, ¶meters };
> + Collect_deps_prm prm= {¶meters,
> + unit->first_select()->nest_level_base,
> + unit->first_select()->nest_level};
> walk(&Item::collect_outer_ref_processor, TRUE, (uchar*)&prm);
> }
>
>
> === modified file 'sql/item_sum.cc'
> --- a/sql/item_sum.cc 2011-07-19 20:19:10 +0000
> +++ b/sql/item_sum.cc 2011-10-25 08:59:36 +0000
> @@ -359,7 +359,9 @@ bool Item_sum::collect_outer_ref_process
> {
> Collect_deps_prm *prm= (Collect_deps_prm *)param;
> SELECT_LEX *ds;
> - if ((ds= depended_from()) && ds->nest_level < prm->nest_level)
> + if ((ds= depended_from()) &&
> + ds->nest_level_base == prm->nest_level_base &&
> + ds->nest_level < prm->nest_level)
> prm->parameters->add_unique(this, &cmp_items);
> return FALSE;
> }
>
> === modified file 'sql/sql_lex.cc'
> --- a/sql/sql_lex.cc 2011-10-22 07:14:27 +0000
> +++ b/sql/sql_lex.cc 2011-10-25 08:59:36 +0000
> @@ -339,6 +339,7 @@ void lex_start(THD *thd)
> lex->event_parse_data= NULL;
> lex->profile_options= PROFILE_NONE;
> lex->nest_level=0 ;
> + lex->select_lex.nest_level_base= &lex->unit;
> lex->allow_sum_func= 0;
> lex->in_sum_func= NULL;
> lex->protect_against_global_read_lock= FALSE;
>
> === modified file 'sql/sql_lex.h'
> --- a/sql/sql_lex.h 2011-09-22 22:13:38 +0000
> +++ b/sql/sql_lex.h 2011-10-25 08:59:36 +0000
> @@ -684,6 +684,7 @@ public:
> ulong table_join_options;
> uint in_sum_expr;
> uint select_number; /* number of select (used for EXPLAIN) */
> + SELECT_LEX_UNIT *nest_level_base; /* unit from which we count nest_level */
> int nest_level; /* nesting level of select */
> Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
> uint with_wild; /* item list contain '*' */
>
> === modified file 'sql/sql_parse.cc'
> --- a/sql/sql_parse.cc 2011-10-11 10:55:42 +0000
> +++ b/sql/sql_parse.cc 2011-10-25 08:59:36 +0000
> @@ -5917,6 +5917,7 @@ mysql_new_select(LEX *lex, bool move_dow
> DBUG_RETURN(1);
> }
> select_lex->nest_level= lex->nest_level;
> + select_lex->nest_level_base= &thd->lex->unit;
> if (move_down)
> {
> SELECT_LEX_UNIT *unit;
>
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

[Maria-developers] WL#243 New (by Psergey): Support >63 tables in a select
by worklog-noreply@askmonty.org 24 Oct '11
by worklog-noreply@askmonty.org 24 Oct '11
24 Oct '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Support >63 tables in a select
CREATION DATE..: Mon, 24 Oct 2011, 18:38
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 243 (http://askmonty.org/worklog/?tid=243)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Quote:
> Number of joins in a view >63
> MariaDB has a limit of 63 tables joined in a select statement. This
> needs to be extended in order to handle the many number of attributes
> that may be connected to an anchor. Preferably a much larger number than
> 63 in order to be 'future proof'.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#242 New (by Psergey): Parameterized VIEWs
by worklog-noreply@askmonty.org 24 Oct '11
by worklog-noreply@askmonty.org 24 Oct '11
24 Oct '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Parameterized VIEWs
CREATION DATE..: Mon, 24 Oct 2011, 16:57
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 242 (http://askmonty.org/worklog/?tid=242)
VERSION........: Benchmarks-3.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Quote:
> We need views which can take a specified number of parameters of a
> specified type. For example, the syntax could be something like:
>
> CREATE VIEW exampleView (@timepoint DATE) AS
> SELECT
FROM
WHERE colDate <= @timepoint;
>
> Implementation could be done as simple as doing a search and replace
> with the variable and the parameter given when the view is used, such
> as:
>
> SELECT * FROM exampleView('2001-01-01');
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

21 Oct '11
Hi, Timour!
On Oct 21, timour(a)askmonty.org wrote:
I don't understand, why do you need map_ptr_array (working memory
provided by the caller). Looks like unnecessary complication to me.
I'd do something like
for (j= 0; j < bitmap_count; j++)
DBUG_ASSERT(end_bit < bitmap_array[j]->n_bits);
start_idx= start_bit/8/sizeof(my_bitmap_map);
end_idx= end_bit/8/sizeof(my_bitmap_map);
for (i= start_idx; i < end_idx; i++)
{
cur_res= ~0;
for (j= 0; cur_res && j < bitmap_count; j++)
cur_res &= bitmap_array[j]->bitmap[i];
if (cur_res)
return TRUE;
}
cur_res= last_word_mask(end_bit);
for (j= 0; cur_res && j < bitmap_count; j++)
cur_res &= bitmap_array[j]->bitmap[end_idx+1];
return cur_res != 0;
}
and created last_word_mask() function by extracting the relevant part of
create_last_word_mask() to a separate inline function.
Besides, it may be that your implementation has a bug - you use a last
word mask from the shortest bitmap, while you should've built it from
end_bit. Now you risk taking more bits into account that end_bit
dictates.
> === modified file 'mysys/my_bitmap.c'
> --- a/mysys/my_bitmap.c 2011-05-02 17:58:45 +0000
> +++ b/mysys/my_bitmap.c 2011-10-21 09:44:36 +0000
> @@ -410,6 +410,88 @@ void bitmap_intersect(MY_BITMAP *map, co
> }
> }
>
> +
> +/*
> + Check if there is some bit index between start_bit and end_bit, such that
> + this is bit is set for all bitmaps in bitmap_list.
> +
> + SYNOPSIS
> + bitmap_exists_intersection()
> + bitmpap_array [in] a set of MY_BITMAPs
> + map_ptr_array [in] wokring memory provided by the caller, same size as
> + bitmpap_array
> + bitmap_count [in] number of elements in bitmpap_array
> + start_bit [in] beginning (inclusive) of the range of bits to search
> + end_bit [in] end (inclusive) of the range of bits to search, must be
> + no bigger than the bits of the shortest bitmap.
> +
> + NOTES
> + This function assumes that for at least one of the bitmaps in bitmap_array all
> + bits outside the range [start_bit, end_bit] are 0. As a result is not
> + necessary to take care of the bits outside the range [start_bit, end_bit].
> +
> + RETURN
> + TRUE if an intersecion exists
> + FALSE no intersection
> +*/
> +
> +my_bool bitmap_exists_intersection(const MY_BITMAP **bitmap_array,
> + const my_bitmap_map **map_ptr_array,
> + uint bitmap_count,
> + uint start_bit, uint end_bit)
> +{
> + const MY_BITMAP *cur_bitmap;
> + my_bitmap_map cur_res, last_word_mask_inverted= 0;
> + uint i, j, min_n_bits= UINT_MAX;
> + uint end_word_idx= end_bit / 32;
> +
> + DBUG_ASSERT(bitmap_count && end_bit >= start_bit);
> + for (j= 0; j < bitmap_count; j++)
> + {
> + cur_bitmap= bitmap_array[j];
> + DBUG_ASSERT(end_bit <= cur_bitmap->n_bits);
> + /*
> + Get the word that contains 'start_bit' so that intersection begins
> + from that word instead of the first word of the bitmap.
> + */
> + map_ptr_array[j]= cur_bitmap->bitmap + start_bit / 32;
> + /*
> + Find and save the last_word_mask of the shortest bitmap that
> + contains end_bit in its last word.
> + */
> + if (no_words_in_map(bitmap_array[j]) - 1 == end_word_idx &&
> + bitmap_array[j]->n_bits < min_n_bits)
> + {
> + min_n_bits= bitmap_array[j]->n_bits;
> + last_word_mask_inverted= ~bitmap_array[j]->last_word_mask;
> + }
> + }
> +
> + /* Find the first word where the intersection of all bits is non-empty. */
> + for (i= 0; i <= end_word_idx; i++)
> + {
> + cur_res= 0xFFFFFFFF;
> + for (j= 0; j < bitmap_count; j++)
> + {
> + cur_res &= *(map_ptr_array[j]);
> + ++map_ptr_array[j];
> + }
> + /* Clear not relevant bits using the longest last_word_mask. */
> + if (last_word_mask_inverted && i == end_word_idx)
> + cur_res&= last_word_mask_inverted;
> + /*
> + If there is at least one non-zero bit, there was at least one sub-row
> + with all bits set, that is one NULL-subrow.
> + */
> + if (cur_res)
> + return TRUE;
> + }
> +
> + /* No intersection was found. */
> + return FALSE;
> +}
Regards,
Sergei
1
0

19 Oct '11
Hi,
Written down notes from discussion about which flags should be enabled by
default in the next 5.3 release:
- Derived tables and keys in them should be enabled
- BKA should not be enabled (doesn't make sense for 'default' query loads)
- semi-joins should be enabled
- Materialization (base) should be enabled
- extra strategies for NULL-aware materialization - ???
- ICP should be enabled
- Hash join could be enabled but in the next minor release.
- Cost-based MRR should not be enabled as cost model is not tuned.
when some feature is considered stable enough, its owner should apply for
testing with {$current_optimizer_switch_default+new_feature}, and once that is
passed, change the default in the main branch.
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

Re: [Maria-developers] Compiler warning about assigned but not used variables fixed
by Sergei Golubchik 18 Oct '11
by Sergei Golubchik 18 Oct '11
18 Oct '11
Hi, Sanja!
On Oct 17, sanja(a)askmonty.org wrote:
> message:
> Compiler warning about assigned but not used variables fixed.
Pretty much ok.
But please change ifdef's to __attribute__((unused)), as discussed.
And see below about the commented out code, looks like you forgot to fix
or uncomment it.
> === modified file 'client/mysqltest.cc'
> --- a/client/mysqltest.cc 2011-05-28 02:11:32 +0000
> +++ b/client/mysqltest.cc 2011-10-17 19:38:32 +0000
> @@ -5238,7 +5238,10 @@ void do_connect(struct st_command *comma
> int con_port= opt_port;
> char *con_options;
> my_bool con_ssl= 0, con_compress= 0;
> - my_bool con_pipe= 0, con_shm= 0;
> + my_bool con_pipe= 0;
> +#ifdef HAVE_SMEM
> + my_bool con_shm= 0;
> +#endif
try not to overuse #ifdef's, (*)
prefer __attribute__((unused)) instead.
it is less error-prone and results in a more maintainable and readable
code.
> struct st_connection* con_slot;
>
> static DYNAMIC_STRING ds_connection_name;
> === modified file 'mysys/ma_dyncol.c'
> --- a/mysys/ma_dyncol.c 2011-09-22 09:04:00 +0000
> +++ b/mysys/ma_dyncol.c 2011-10-17 19:38:32 +0000
> @@ -1916,16 +1915,18 @@ dynamic_column_update_many(DYNAMIC_COLUM
> }
>
> /* if (new_offset_size != offset_size) then we have to rewrite header */
> + /*
> + Now we only copy. TODO: fix
> +
> header_delta_sign= new_offset_size - offset_size;
> data_delta_sign= 0;
> - copy= FALSE;
> for (i= 0; i < add_column_count; i++)
> {
> - /* This is the check for increasing/decreasing */
> + // This is the check for increasing/decreasing
> DELTA_CHECK(header_delta_sign, plan[i].hdelta, copy);
> DELTA_CHECK(data_delta_sign, plan[i].ddelta, copy);
> }
> -
> + */
why did you comment this out?
> calc_param(&new_entry_size, &new_header_size,
> new_offset_size, new_column_count);
>
> === modified file 'sql/sql_show.cc'
> --- a/sql/sql_show.cc 2011-10-11 10:55:42 +0000
> +++ b/sql/sql_show.cc 2011-10-17 19:38:32 +0000
> @@ -1274,7 +1274,9 @@ int store_create_info(THD *thd, TABLE_LI
> handler *file= table->file;
> TABLE_SHARE *share= table->s;
> HA_CREATE_INFO create_info;
> +#ifdef WITH_PARTITION_STORAGE_ENGINE
> bool show_table_options= FALSE;
> +#endif
same here, and below.
> bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |
> MODE_ORACLE |
> MODE_MSSQL |
> @@ -1507,7 +1509,9 @@ int store_create_info(THD *thd, TABLE_LI
> packet->append(STRING_WITH_LEN("\n)"));
> if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
> {
> +#ifdef WITH_PARTITION_STORAGE_ENGINE
> show_table_options= TRUE;
> +#endif
> /*
> Get possible table space definitions and append them
> to the CREATE TABLE statement
>
> === modified file 'sql/table.cc'
> --- a/sql/table.cc 2011-09-02 12:10:10 +0000
> +++ b/sql/table.cc 2011-10-17 19:38:32 +0000
> @@ -5689,7 +5689,8 @@ int update_virtual_fields(THD *thd, TABL
> {
> DBUG_ENTER("update_virtual_fields");
> Field **vfield_ptr, *vfield;
> - int error= 0;
> + int error __attribute__ ((unused));
> + error= 0;
FYI, you can still use initializer and __attribute__ together:
int error __attribute__ ((unused)) = 0;
there is no need to change the above, either way is ok.
> if (!table || !table->vfield)
> DBUG_RETURN(0);
>
> === modified file 'storage/xtradb/buf/buf0buf.c'
> --- a/storage/xtradb/buf/buf0buf.c 2011-05-10 15:17:43 +0000
> +++ b/storage/xtradb/buf/buf0buf.c 2011-10-17 19:38:32 +0000
> @@ -3895,7 +3895,7 @@ buf_page_io_complete(
> enum buf_io_fix io_type;
> const ibool uncompressed = (buf_page_get_state(bpage)
> == BUF_BLOCK_FILE_PAGE);
> - enum buf_flush flush_type;
> + //enum buf_flush flush_type;
please send all your XtraDB changes to Percona
> mutex_t* block_mutex;
>
Regards,
Sergei
(*) see for example http://www.google.com/search?q=ifdef+considered+harmful
2
2

14 Oct '11
On Thu, 13 Oct 2011 11:13:07 -0400
Daniel Bartholomew <dbart(a)montyprogram.com> wrote:
Daniel> I'm uploading the release to the primary mirror now. Is there
Daniel> anything in particular we should be sure to put into the
Daniel> Release Notes?
The MariaDB 5.3.2 files have been mirrored to all but one of the
mirrors, so I've activated the download, release notes, and changelog
pages.
http://kb.askmonty.org/en/mariadb-532-release-notes
http://kb.askmonty.org/en/mariadb-532-changelog
http://downloads.askmonty.org/mariadb/5.3.2
On the release notes page, I mentioned the Feedback plugin. Is there
anything else that should be mentioned? Please let me know ASAP, as I
will be sending out the announce email shortly.
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0

[Maria-developers] Feature request: Add support for a syntax check for SQL scripts
by Raphael Vullriede 14 Oct '11
by Raphael Vullriede 14 Oct '11
14 Oct '11
Hi,
we have a lot of developers writing a lot of SQL scripts against a lot
of different databases. These scripts usually consists of mixed DDL
(e.g. change a column definition) and DML (e.g. adding new master data).
Since our applications are constantly under development we'd like to add
these scripts to our continuous integration environment.
For that it would be great to have a feature that checks the script
against a given database without actually executing it. It should not
only check the SQL syntax but also if all mentioned tables, columns etc.
exists in the given database.
It is not possible to use transactions for that since DDL is (currently)
not transactional.
I'm thinking of something like this:
SET DISABLE_EXECUTION="TRUE";
-- here come the sql statements
SET DISABLE_EXECUTION="FALSE";
I've tried to write such a check with an external tool but as it turned
out this is virtually impossible and has a lot of loopholes.
Do you think it would be possible to implement something like this in
the server?
Thanks,
Raphael
5
7
----- Forwarded message from Sergei Petrunia <psergey(a)askmonty.org> -----
Date: Thu, 13 Oct 2011 12:55:36 +0400
From: Sergei Petrunia <psergey(a)askmonty.org>
To: maria-docs(a)lists.launchpad.net, maria-dev(a)lists.launchpad.net,
community(a)askmonty.org
Subject: MariaDB 5.3.2 beta is being released
Hello,
MariaDB 5.3.2 beta is being built. The tip changeset is:
revno: 3231
tags: mariadb-5.3.2-beta
revision-id: psergey(a)askmonty.org-20111012201551-t0nswetvvpp2a4sm
parent: psergey(a)askmonty.org-20111012174056-ov0wq91z6z4zrajd
committer: Sergey Petrunya <psergey(a)askmonty.org>
branch nick: 5.3-push19
timestamp: Thu 2011-10-13 00:15:51 +0400
message:
Remove garbage comment
The buildnumber is 255, tarbuildnum=1289.
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
----- End forwarded message -----
--
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

[Maria-developers] FW: [pstoev@askmonty.org: Re: MariaDB 5.3.2 beta is being released
by Sergei Petrunia 13 Oct '11
by Sergei Petrunia 13 Oct '11
13 Oct '11
(Forwarding as this was sent to wrong 'maria-dev' address):
----- Forwarded message from Philip Stoev <pstoev(a)askmonty.org> -----
From: Philip Stoev <pstoev(a)askmonty.org>
To: Sergei Petrunia <psergey(a)askmonty.org>
Cc: maria-docs(a)lists.launchpad.net, maria-dev(a)lists.launchpad.net,
community(a)askmonty.org
Subject: Re: MariaDB 5.3.2 beta is being released
Date: Thu, 13 Oct 2011 12:01:32 +0300
Organization: Monty Program AB
X-Mailer: Microsoft Outlook Express 6.00.2900.5931
Windows packages have been built and are available at a new location:
http://i7.askmonty.org/packages/
Philip Stoev
----- Original Message ----- From: "Sergei Petrunia" <psergey(a)askmonty.org>
To: <maria-docs(a)lists.launchpad.net>; <maria-dev(a)lists.launchpad.net>;
<community(a)askmonty.org>
Sent: Thursday, October 13, 2011 11:55 AM
Subject: MariaDB 5.3.2 beta is being released
> Hello,
>
> MariaDB 5.3.2 beta is being built. The tip changeset is:
>
> revno: 3231
> tags: mariadb-5.3.2-beta
> revision-id: psergey(a)askmonty.org-20111012201551-t0nswetvvpp2a4sm
> parent: psergey(a)askmonty.org-20111012174056-ov0wq91z6z4zrajd
> committer: Sergey Petrunya <psergey(a)askmonty.org>
> branch nick: 5.3-push19
> timestamp: Thu 2011-10-13 00:15:51 +0400
> message:
> Remove garbage comment
>
>
> The buildnumber is 255, tarbuildnum=1289.
>
> BR
> Sergey
> --
> Sergei Petrunia, Software Developer
> Monty Program AB, http://askmonty.org
> Blog: http://s.petrunia.net/blog
>
----- End forwarded message -----
--
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0
Hi Kristian,
I've got RQG replication tests fail as follows for 5.3:
http://buildbot.askmonty.org/buildbot/builders/rqg-perpush-replication/buil…
http://buildbot.askmonty.org/buildbot/builders/rqg-perpush-replication-chec…
111013 2:36:57 [ERROR]
/home/buildbot/buildbot_basedir/rqg-perpush-replication-checksum/build/sql/mysqld:
unknown option '--binlog-annotate-rows-events'
111013 3:30:24 [ERROR]
/home/buildbot/buildbot_basedir/rqg-perpush-replication/build/sql/mysqld:
unknown variable 'binlog_annotate_rows_events=1'
This seems like a trivial failure that was overlooked?
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

Re: [Maria-developers] open_binary_frm() decomposed an methods of TABLE_SHARE
by Sergei Golubchik 12 Oct '11
by Sergei Golubchik 12 Oct '11
12 Oct '11
Hi, Sanja!
On Oct 04, sanja(a)askmonty.org wrote:
> ------------------------------------------------------------
> revno: 3202
> revision-id: sanja(a)askmonty.org-20111004111459-1i44vpkdm1j3lisl
> parent: psergey(a)askmonty.org-20110929130743-yj0zl4hdvoydnmda
> committer: sanja(a)askmonty.org
> branch nick: work-maria-5.3-frm2
> timestamp: Tue 2011-10-04 14:14:59 +0300
> message:
> open_binary_frm() decomposed an methods of TABLE_SHARE to allow
> engine to create TABLE_SHARE.
>
> utype and geometry_type moved out of Field.
Thanks!
Here're my thoughts.
The summary is:
1. I'd like to have it simpler. It's going to be an external API for
engines to use, after all.
2. Don't try to support all optimizations that open_binary_frm() uses,
and old frm formats - keep that out of the API, open_binary_frm()
can modify TABLE_SHARE directly to achieve the necessary effect.
3. Try to create a usage example - it will show the unnecessary
complexity
See all the comments below:
> === modified file 'sql/handler.h'
> --- a/sql/handler.h 2011-07-14 13:44:37 +0000
> +++ b/sql/handler.h 2011-10-04 11:14:59 +0000
> @@ -298,6 +298,31 @@ enum legacy_db_type
> DB_TYPE_FIRST_DYNAMIC=42,
> DB_TYPE_DEFAULT=127 // Must be last
> };
> +
> +/*
> + We use three additional unireg types for TIMESTAMP to overcome limitation
> + of current binary format of .frm file. We'd like to be able to support
> + NOW() as default and on update value for such fields but unable to hold
> + this info anywhere except unireg_check field. This issue will be resolved
> + in more clean way with transition to new text based .frm format.
> + See also comment for Field_timestamp::Field_timestamp().
> +*/
> +enum utype
> +{
> + UT_NONE, UT_DATE, UT_SHIELD, UT_NOEMPTY, UT_CASEUP, UT_PNR,
> + UT_BGNR, UT_PGNR, UT_YES, UT_NO, UT_REL,
> + UT_CHECK, UT_EMPTY, UT_UNKNOWN_FIELD, UT_CASEDN,
> + UT_NEXT_NUMBER, UT_INTERVAL_FIELD,
> + UT_BIT_FIELD, UT_TIMESTAMP_OLD_FIELD, UT_CAPITALIZE,
> + UT_BLOB_FIELD, UT_TIMESTAMP_DN_FIELD, UT_TIMESTAMP_UN_FIELD,
> + UT_TIMESTAMP_DNUN_FIELD
> +};
Why wouldn't you remove all unused values from utype enum?
> +enum geometry_type
> +{
> + GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
> + GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
> + GEOM_GEOMETRYCOLLECTION = 7
> +};
> /*
> Better name for DB_TYPE_UNKNOWN. Should be used for engines that do not have
> a hard-coded type value here.
> === modified file 'sql/table.cc'
> --- a/sql/table.cc 2011-09-02 12:10:10 +0000
> +++ b/sql/table.cc 2011-10-04 11:14:59 +0000
> @@ -675,6 +684,797 @@ err_not_open:
> }
>
>
> +/**
> + Set some general table parameters (should be called first after the
> + TABLE SHARE initialization)
> +
> + @param frm_ver Version of the frm (FRM_VER_TRUE_VARCHAR)
no need to pass it as a parameter, set frm version always to the latest one.
if needed - overwrite it later from open_binary_frm().
don't add support for historical features into the API.
> + @param db_create_opt Flags of CREATE options
> + @param avg_row_len Average row length
> + @param transact CREATE option TRANSACTION
> + @param page_chcksum CREATE option PAGE_CHECK_SUM
> + @param rtype CREATE option ROW_TYPE (used by aria only)
> + @param charset default charset for the table.
> + @param null_fld_first Should be TRUE for modern frm
same as frm_version
> + @param mi_rows CREATE option MIN_ROWS
> + @param ma_rows CREATE option MAX_ROWS
> + @param reclen Record buffer length
> + @param extra_rec_buf_len Extra record buffer length (???)
> + @param key_blck_size CREATE option KEY_BLOCK_SIZE
> + @param new_fld_pck_flg Should be 2 for modern frm
same as frm_version
> + @param error Error code assigned here in case of error
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +bool TABLE_SHARE::set_init_parameters(uchar frm_ver, ulong mysql_ver,
> + uint db_create_opt,
> + ulong avg_row_len,
> + enum ha_choice transact,
> + enum ha_choice page_chcksum,
> + enum row_type rtype,
> + CHARSET_INFO *charset,
> + bool null_fld_first,
> + ha_rows mi_rows,
> + ha_rows ma_rows,
> + ulong reclen,
> + uint extra_rec_buf_len,
> + uint key_blck_size,
> + uint new_fld_pck_flg,
> + int &error)
use a pointer, not a reference. Or, better, just return the error code
> +{
> + frm_version= frm_ver;
> + mysql_version= mysql_ver;
> + db_options_in_use= db_create_options= db_create_opt;
> + if (db_create_options & HA_OPTION_LONG_BLOB_PTR)
> + blob_ptr_size= portable_sizeof_char_ptr;
> + avg_row_length= avg_row_len;
> + transactional= transact;
> + page_checksum= page_chcksum;
> + row_type= rtype;
> + table_charset= charset;
> + null_field_first= null_fld_first;
> + db_record_offset= 1;
> + min_rows= mi_rows;
> + max_rows= ma_rows;
> + stored_rec_length= reclength= reclen;
> + key_block_size= key_blck_size;
> + new_field_pack_flag= new_fld_pck_flg;
> + rec_buff_length= ALIGN_SIZE(reclength + 1 + extra_rec_buf_len);
> + if (!(default_values= (uchar *) alloc_root(&mem_root,
> + rec_buff_length)))
> + {
> + error= 4;
> + return TRUE;
> + }
> + /* Default values */
> + system= 0;
> + crypted= 0;
> +
> + return FALSE;
> +}
> +
> +
> +/**
> + Allocate space for indices and its parts
> +
> + @param nkeys Number of keys
> + @param nkey_parts Number of key parts of all keys
> + @param names_len Sum of lengths of all indices names (string ends
> + are not counted)
> + @param error Error code assigned here in case of error\
return the error code instead
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +bool TABLE_SHARE::allocate_indices_space(uint nkeys, uint nkey_parts,
> + uint names_len, int &error)
> +{
> + uint n_length= (nkeys * sizeof(KEY) +
> + nkey_parts * sizeof(KEY_PART_INFO));
> +
> + DBUG_ASSERT(key_info == NULL); // prevent reallocation
> + DBUG_ASSERT(nkeys <= nkey_parts);
> +
> + keys= nkeys;
> + key_parts= nkey_parts;
> + keys_for_keyread.init(0);
> + keys_in_use.init(keys);
> +
> +
> + if (!(rec_per_key= (ulong *) alloc_root(&mem_root,
> + sizeof(ulong) * key_parts +
> + n_length +
> + (names_len + nkeys + 1))))
> + {
> + error= 4;
> + return TRUE; /* purecov: inspected */
> + }
> + key= key_info=
> + my_reinterpret_cast(KEY*) (rec_per_key + key_parts);
> + bzero((char*) key_info, n_length);
> + first_key_part= key_part=
> + my_reinterpret_cast(KEY_PART_INFO*) (key_info + keys);
> + first_keyname= keyname=
> + my_reinterpret_cast(char *) (first_key_part + key_parts);
> + is_keys_allocated= TRUE;
> + if (key_parts == 0)
> + {
> + DBUG_ASSERT(keys == 0);
> + is_keynames_ready= is_keyparts_ready= TRUE;
> + if (is_fieldnames_ready)
> + parse_names();
> + if (is_fields_ready &&
> + connect_indexes_and_fields(error))
> + return TRUE;
> + }
> + if (is_fields_allocated && final_fields_keys_allocation())
> + {
> + error= 4;
> + return TRUE;
> + }
> + return FALSE;
> +}
> +
> +
> +/**
> + Add index header
> +
> + @param name Name of the index (could be NULL if it is
> + already copied by add_index_names_as_onestring())
> + @param name_len Length of the index name (used only if name passed)
> + @param flags Key flags
> + @param length Length of the key (in its buffer)
> + @param parts Number of parts in the index
> + @param alg Index algorithm
> + @param blk_size Index block size
> +
> + @retval pointer on the allocated index descriptor
> +*/
> +
> +KEY *TABLE_SHARE::add_index(char *name, uint name_len,
> + uint flags, uint length, uint parts,
> + enum ha_key_alg alg, uint blk_size)
> +{
> + DBUG_ASSERT(key < (key_info + keys));
> + DBUG_ASSERT(key->key_length == 0); // prevent redefinition
> + DBUG_ASSERT(is_keys_allocated);
> + key->flags= flags;
> + key->key_length= length;
isn't key_length equal to the sum of keypart lengths?
> + key->key_parts= parts;
> + key->algorithm= alg;
> + key->block_size= blk_size;
> + if (name)
> + {
> + /*
> + TODO: should be check bounds of the allocated string?
> +
> + Check for illegal separating characters
> + */
> + DBUG_ASSERT(memchr(name, '\0', name_len) == NULL);
> + DBUG_ASSERT(memchr(name, NAMES_SEP_CHAR, name_len) == NULL);
> +
> + if (key == key_info)
> + *(keyname++)= NAMES_SEP_CHAR;
why is that?
> +
> + memcpy(keyname, name, name_len);
> + keyname+= name_len;
> + *(keyname++)= NAMES_SEP_CHAR;
please, don't do that. Don't ask the caller for the total length of all
key names, and don't allocate them in one alloc_root.
just set the pointer here: key->name= name.
the caller can allocate them in one array, or independently, or whatever -
don't bother enforcing anything specific here.
> +
> + if (key == key_info + (keys - 1))
> + {
> + is_keynames_ready= TRUE;
> + if (is_fieldnames_ready)
> + parse_names();
> + }
> +
> + /* names should be all or none */
> + DBUG_ASSERT(key == key_info || (key - 1)->name != NULL);
> + }
> + else
> + {
> + /* names should be all or none */
> + DBUG_ASSERT(key == key_info || (key - 1)->name == NULL);
> + }
> + return key++;
> +}
> +
> +
> +/**
> + Add part description to the index
> +
> + @param keyinfo The index where to add part
> + @param fieldnr Number of the field used in the index
> + @param offset Offset of the part in the key biffer
do you need that? The keypart starts where the previous one ends, doesn't it?
> + @param keytype Key type
> + @param length Length of the part
> + @param flags Flags of the part
> + @param error Error code assigned here in case of error
return the error instead
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +bool TABLE_SHARE::add_index_part(KEY *keyinfo, uint16 fieldnr,
> + uint offset, uint16 keytype,
> + uint16 length, uint16 flags,
> + int &error)
> +{
> + if (!keyinfo->key_part)
> + {
> + // first key part for the key
> + keyinfo->key_part= key_part;
> + keyinfo->rec_per_key= rec_per_key;
this can be done as
key[i].rec_per_key=key[i-1].rec_per_key+key[i-1].key_parts
not in add_index_part() but later, in something like
finalize_share() - function that is called at the end. where you fix
all typelibs and stuff.
> + }
> + *rec_per_key++= 0;
> + key_part->fieldnr= fieldnr;
> + key_part->offset= offset;
> + key_part->key_type= keytype;
> + key_part->length= length;
> + key_part->key_part_flag= flags;
> + key_part->store_length= key_part->length; // will be fixed
> + key_part++;
> +
> + if (key_part == first_key_part + key_parts)
> + {
> + is_keyparts_ready= TRUE;
> + if (is_fields_ready &&
> + connect_indexes_and_fields(error))
> + return TRUE;
> + }
you don't need any is_fields_ready, etc
move all that code to finalize_share()
and let the caller to call it at the end, when all fields and keys
are parsed. No need to try to detect this moment automatically
with various cursors.
> + return FALSE;
> +}
> +
> +/**
> + Allocate space for field information
> +
> + @param fields_count Number of the fields
> + @param null_flds Number of the fields which could be NULL
> + @param enum_set_count Number of fields which are ENUM or SET
> + @param enum_set_values_count Sum of number of values of all fields which
> + are ENUM or SET
> + @param field_names_length Sum length of all fields names (string ends are not
> + counted)
don't ask for this (see above)
> + @param enum_set_names_length Sum length of all values of all fields which
> + are ENUM or SET (string ends are not counted)
> + @param com_length Sum ength of the all field comments
nor for this, nor enum_set_count, nor enum_set_values_count, nor
enum_set_names_length
> + @param handler_file handler - used to check fields/indices features
> + @param tbl_com_length Length of the table comment (if present) or 0
> + @param tbl_com reference on the table comment (if present)
move table comment related parameters somewhere
out of "allocate_fields_space" method.
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +bool TABLE_SHARE::allocate_fields_space(uint fields_count,
> + uint null_flds,
> + uint enum_set_count,
> + uint enum_set_values_count,
> + uint field_names_length,
> + uint enum_set_names_length,
> + uint com_length,
> + handler *handler_file,
> + size_t tbl_com_length,
> + char *tbl_com)
> +{
> + stored_fields= fields= fields_count;
> + vfields= 0;
> + tmp_handler_file= handler_file;
> + null_fields= null_flds;
> + enum_set_values= enum_set_values_count;
> + enums_sets= enum_set_count;
> + field_names_length+= fields_count + 1; //add space for separators
> + comments_length= com_length;
> + /* add space for separators between names and intervals */
> + enum_set_names_length+= enum_set_values_count + enum_set_count * 2;
> + if (!(field_ptr= field = (Field **)
> + alloc_root(&mem_root,
> + (uint) ((fields_count + 1) * sizeof(Field*) +
> + enum_set_count * sizeof(TYPELIB) +
> + field_names_length + enum_set_names_length +
> + comments_length))))
> + return TRUE; /* purecov: inspected */
> +
> + field_ptr[fields]= 0; // End marker
> + curr_interval= intervals= (TYPELIB*) (field + fields + 1);
> + names= (char *) (intervals + enum_set_count);
> + curr_interval_names= names + field_names_length;
> + first_comment= comment_pos=
> + (char *) (names + field_names_length + enum_set_names_length);
> + if (!enum_set_count)
> + intervals= 0; // For better debugging
> + is_fields_allocated= TRUE;
> + if (is_keys_allocated && final_fields_keys_allocation())
> + return TRUE;
> + comment.str= strmake_root(&mem_root, tbl_com,
> + (comment.length= tbl_com_length));
> + /* init counters */
> + null_bits_are_used= (null_fields != 0);
> + if (null_field_first)
> + {
> + null_flags= null_pos= (uchar*) default_values;
> + null_bit_pos= (db_create_options & HA_OPTION_PACK_RECORD) ? 0 : 1;
> + /*
> + null_bytes below is only correct under the condition that
> + there are no bit fields. Correct values is set below after the
> + table struct is initialized
> + */
> + null_bytes= (null_fields + null_bit_pos + 7) / 8;
> + }
> +#ifndef WE_WANT_TO_SUPPORT_VERY_OLD_FRM_FILES
> + else
> + {
> + null_bytes= (null_fields + 7) / 8;
> + null_flags= null_pos= (uchar*) (default_values + reclength - null_bytes);
> + null_bit_pos= 0;
> + }
> +#endif
we don't want to support anything but the latest frm version here.
all compatibility hacks belong to open_binary_frm directly.
> + use_hash= fields >= MAX_FIELDS_BEFORE_HASH;
> + if (use_hash)
> + use_hash= !hash_init(&name_hash,
> + system_charset_info,
> + fields, 0, 0,
> + (hash_get_key) get_field_name, 0, 0);
> +
> + return FALSE;
> +}
> +
> +bool TABLE_SHARE::final_fields_keys_allocation()
see above - move this and parse_names and the likes into
one function, that the caller will call at the end.
don't try to detect when "the end" is.
> +{
> + DBUG_ASSERT(is_fields_allocated && is_keys_allocated);
> + if (!(interval_array=
> + (const char **) alloc_root(&mem_root,
> + (uint) ((fields + enum_set_values +
> + keys + 3) * sizeof(char *)))))
> + return TRUE;
> + curr_interval_array= interval_array + fields + 1;
> + return FALSE;
> +}
> +
> +/**
> + Internal function triggeren when all names
> + (indices, fields, enum and set) are allocated and copied
> +
> +
> + @retval FALSE OK
> + @retval TRUE Error
> +*/
> +
> +bool TABLE_SHARE::parse_names()
> +{
> + TYPELIB *interval;
> + DBUG_ASSERT(is_keys_allocated && is_fields_allocated &&
> + is_keynames_ready);
> + fix_type_pointers(&interval_array, &fieldnames, 1, &names);
> + if (is_fieldnames_ready)
> + fix_type_pointers(&interval_array, intervals, enums_sets, &names);
> + else
> + {
> + /* Intervals were passed to the add_field without preparation */
> + names= curr_interval_names;
> + interval_array= curr_interval_array;
> + is_fieldnames_ready= TRUE;
> + }
> + if ((keyname= first_keyname))
> + fix_type_pointers(&interval_array, &keynames, 1, &keyname);
> + if (fieldnames.count != fields)
> + return TRUE;
> +
> + /* Set ENUM and SET lengths */
> + for (interval= intervals;
> + interval < intervals + enums_sets;
> + interval++)
> + {
> + uint count= (uint) (interval->count + 1) * sizeof(uint);
> + if (!(interval->type_lengths= (uint *) alloc_root(&mem_root, count)))
> + return TRUE;
> + for (count= 0; count < interval->count; count++)
> + {
> + char *val= (char*) interval->type_names[count];
> + interval->type_lengths[count]= strlen(val);
> + }
> + interval->type_lengths[count]= 0;
> + }
> +
> + return FALSE;
> +}
> +
> +/**
> + Add field description to the TABLE_SHARE
> +
> + @param name Field name
> + @param pos Field position in the record buffer
isn't it equal the end of the previous field?
(with special treatment for BIT)
> + @param field_length Length of the field
> + @param pack_flag Flags of the field
what's that?
I mean, I understand that it's some set of cryptic bits, but how would an
engine use that?
You know what, I think we're missing a usage example.
could you add it to the example engine (ha_example) support for discovery?
Something like that - a table with a fixed name, say, "example_discovered_table"
is created by discovery() on the example engine. That is, a fixed table name,
keep it as simple as possible. Fixed table structure.
Few fields, say, an int, primary key, and enum (Y,N) - or whatever.
because you haven't yet done the step 2 in our plan (extracting that part
of ALTER TABLE that converts TABLE_SHARE into Create_field), this
example discovery won't create frm files - it'll be completely in memory.
which is fine, for now.
> + @param field_type Field type
> + @param charset Caracter set infoemation of the field
> + @param geom_type Geometry data type (for geometry fields)
> + @param auto_increment Is the field auto increment
> + @param enum_set Definition of ENUM or SET (for appropriate type)
a complete typelib? probably it's an overkill. better to pass an array
of names, and you can build a typelib internally.
> + @param comm_pos Reference on the field commentary
> + @param comment_length Length of the field commentary
> + @param error Error code assigned here in case of error
as always, you can return the error code
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +Field **TABLE_SHARE::add_field(const char *name,
> + uchar *pos,
> + uint32 field_length,
> + uint pack_flag,
> + enum_field_types field_type,
> + CHARSET_INFO *charset,
> + geometry_type geom_type,
> + bool auto_increment,
> + TYPELIB* enum_set,
> + char *comm_pos,
> + uint comment_length,
> + int &error)
> +{
> + DBUG_ASSERT(is_fields_allocated);
> + utype unireg_type= get_unireg_type(auto_increment,
> + !f_no_default(pack_flag),
> + FALSE,
> + FALSE, f_maybe_null(pack_flag),
> + field_type);
> +
> + return add_field_int(name, pos, field_length,
> + pack_flag, field_type,
> + charset, geom_type, unireg_type,
> + enum_set, comm_pos, comment_length,
> + NULL, TRUE, error);
> +}
> +
> +
> +/**
> + Add field description to the TABLE_SHARE (internal)
> +
> + @param name Field name
> + @param pos Field position in the record buffer
> + @param field_length Length of the field
> + @param pack_flag Flags of the field
> + @param field_type Field type
> + @param charset Caracter set infoemation of the field
> + @param geom_type Geometry data type (for geometry fields)
> + @param unireg_type Unireg type (or check flags)
> + @param auto_increment Is the field auto increment
> + @param enum_set Definition of ENUM or SET (for appropriate type)
> + @param comm_pos Reference on the field commentary
> + @param comment_length Length of the field commentary
> + @param vcol_info Virtual column information
> + @param fld_stored_in_db TRUE for normal fields and persistent virtual fields
> + @param error Error code assigned here in case of error
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +Field **TABLE_SHARE::add_field_int(const char *name,
> + uchar *pos,
> + uint32 field_length,
> + uint pack_flag,
> + enum_field_types field_type,
> + CHARSET_INFO *charset,
> + geometry_type geom_type,
> + utype unireg_type,
> + TYPELIB* enum_set,
> + char *comm_pos,
> + uint comment_length,
> + Virtual_column_info *vcol_info,
> + bool fld_stored_in_db,
> + int &error)
> +{
> + Field* reg_field;
> + DBUG_ASSERT(is_fields_allocated);
> + if (!is_fieldnames_ready)
> + {
> + if (enum_set)
> + {
> + copy_typelib(curr_interval,
> + &curr_interval_array, enum_set,
> + &curr_interval_names, NAMES_SEP_CHAR);
See? it's better to get an array of names from the caller and build the
typelib here - as you won't use the typelib that caller provided anyway
> + enum_set= curr_interval++;
> + }
> + {
> + uchar *tmp= (uchar*) strmov((char*) *curr_field_names, name);
> + *tmp++= (uchar)NAMES_SEP_CHAR;
> + *tmp= 0;
> + name= curr_field_names;
> + curr_field_names= (char*)tmp;
> + }
just like with other names - let the caller handle the allocations,
you simply use the pointer that the caller provides.
> + }
> + reg_field = *field_ptr=
> + make_field(this, pos,
> + (uint32) field_length,
> + null_pos, null_bit_pos,
> + pack_flag,
> + field_type,
> + charset,
> + geom_type,
> + (utype) MTYP_TYPENR(unireg_type),
add the cast to MTYP_TYPENR definition and remove it here (and elsewhere)
> + enum_set,
> + name);
> +
> + if (!reg_field) // Not supported field type
> + {
> + error= 4;
> + return NULL;
> + }
> + reg_field->field_index= (field_ptr - field);
> + reg_field->vcol_info= vcol_info;
> + reg_field->stored_in_db= fld_stored_in_db;
> + DBUG_ASSERT(reg_field->field_index < fields);
> + if (comm_pos && comment_length)
> + {
> + memcpy(comment_pos, comm_pos, comment_length);
same here and everywhere. I'll stop repeating "just use the pointer,
let the caller handle the allocation"
alternatively (here and everywhere) do alloc_root() - that is
the caller gives you a pointer, and you call alloc_root() anc copy
the data. Yes, it means that every string will be allocated in its
own chunk. And in the _int version of the function you use the pointers.
I mean something like that:
TABLE_SHARE::add_field(char *name, ...)
{
...
return add_field_int(strdup_root(name), ... );
so, if one uses add_field, he does not need to think about memory
allocations, and does not need to calculate the sum of lengths,
and stuff like that.
while open_binary_frm() will use add_field_int() can will pass the pointers
directly into the big allocated chunk, as always.
The above applies to all strings, comments, enum/set, everything.
> + DBUG_ASSERT(!is_comments_ready);
> + }
> + else
> + DBUG_ASSERT(is_comments_ready || comment_length == 0);
> + if (comment_length)
> + {
> + reg_field->comment.str= comment_pos;
> + reg_field->comment.length= comment_length;
> + comment_pos+= comment_length;
right, that's what I mean by "use the pointer directly, let the caller
to handle the allocations".
> + }
> + else
> + {
> + reg_field->comment.str= (char *)"";
> + reg_field->comment.length= 0;
very minor stilistic details:
in these cases I prefer to use
reg_field->comment= empty_lex_string;
it was introduced for exactly this purpose.
> + }
> + if (f_no_default(pack_flag))
> + reg_field->flags|= NO_DEFAULT_VALUE_FLAG;
> +
> + if (reg_field->unireg_check == UT_NEXT_NUMBER)
> + found_next_number_field= field_ptr;
> + if (timestamp_field == reg_field)
> + timestamp_field_offset= reg_field->field_index;
> +
> + if (use_hash)
> + {
> + if (my_hash_insert(&name_hash,
> + (uchar*) field_ptr))
> + {
> + /*
> + Set return code 8 here to indicate that an error has
> + occurred but that the error message already has been
> + sent (OOM).
> + */
> + error= 8;
> + return NULL;
> + }
> + }
> +
> + /* move null bit/byte pointers */
> + if (field_type == MYSQL_TYPE_BIT && !f_bit_as_char(pack_flag))
> + {
> + null_bits_are_used= 1;
> + if ((null_bit_pos+= field_length & 7) > 7)
> + {
> + null_pos++;
> + null_bit_pos-= 8;
> + }
> + }
> + if (!(reg_field->flags & NOT_NULL_FLAG))
> + {
> + if (!(null_bit_pos= (null_bit_pos + 1) & 7))
> + null_pos++;
> + }
> +
> + if (reg_field->field_index == fields - 1)
> + {
> + if (!is_fieldnames_ready)
> +
> + is_fields_ready= TRUE;
> + if (is_keyparts_ready &&
> + connect_indexes_and_fields(error))
> + return NULL;
> + }
> + return field_ptr++;
> +}
> +
> +/**
> + Internal function which connect fields and indices (its parts) triggered
> + when fields and index parts are ready
> +
> + @param error Error code assigned here in case of error
> +
> + @retval FALSE OK
> + @retval TRUE Error (error assigned)
> +*/
> +
> +bool TABLE_SHARE::connect_indexes_and_fields(int &error)
> +{
> + KEY *keyinfo;
> + uint i;
> + /* Fix key->name and key_part->field */
> + if (key_parts)
> + {
> + KEY_PART_INFO *key_part= first_key_part;
> + uint prm_key=(uint) (find_type((char*) primary_key_name,
> + &keynames, 3) - 1);
> + longlong ha_option= tmp_handler_file->ha_table_flags();
> + keyinfo= key_info;
> +
> + for (uint key=0 ; key < keys ; key++, keyinfo++)
> + {
> + uint usable_parts= 0;
> + keyinfo->name=(char*) keynames.type_names[key];
> + keyinfo->name_length= strlen(keyinfo->name);
> + keyinfo->cache_name=
> + (uchar*) alloc_root(&mem_root,
> + table_cache_key.length+
> + keyinfo->name_length + 1);
> + if (keyinfo->cache_name) // If not out of memory
> + {
> + uchar *pos= keyinfo->cache_name;
> + memcpy(pos, table_cache_key.str, table_cache_key.length);
> + memcpy(pos + table_cache_key.length, keyinfo->name,
> + keyinfo->name_length+1);
> + }
> +
> + /* Fix fulltext keys for old .frm files */
> + if (key_info[key].flags & HA_FULLTEXT)
> + key_info[key].algorithm= HA_KEY_ALG_FULLTEXT;
> +
> + if (prm_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME))
> + {
> + /*
> + If the UNIQUE key doesn't have NULL columns and is not a part key
> + declare this as a primary key.
> + */
> + prm_key= key;
> + for (i= 0 ; i < keyinfo->key_parts; i++)
> + {
> + uint fieldnr= key_part[i].fieldnr;
> + if (!fieldnr ||
> + field[fieldnr-1]->null_ptr ||
> + field[fieldnr-1]->key_length() !=
> + key_part[i].length)
> + {
> + prm_key=MAX_KEY; // Can't be used
> + break;
> + }
> + }
> + }
> +
> + for (i=0 ; i < keyinfo->key_parts ; key_part++,i++)
> + {
> + Field *fld;
> + if (new_field_pack_flag <= 1)
> + key_part->fieldnr= (uint16) find_field(field,
> + default_values,
> + (uint) key_part->offset,
> + (uint) key_part->length);
> + if (!key_part->fieldnr)
> + {
> + error= 4; // Wrong file
> + return TRUE;
> + }
> + fld= key_part->field= field[key_part->fieldnr-1];
> + key_part->type= fld->key_type();
> + if (fld->null_ptr)
> + {
> + key_part->null_offset=(uint) ((uchar*) fld->null_ptr -
> + default_values);
> + key_part->null_bit= fld->null_bit;
> + key_part->store_length+=HA_KEY_NULL_LENGTH;
> + keyinfo->flags|=HA_NULL_PART_KEY;
> + keyinfo->key_length+= HA_KEY_NULL_LENGTH;
> + }
> + if (fld->type() == MYSQL_TYPE_BLOB ||
> + fld->real_type() == MYSQL_TYPE_VARCHAR ||
> + fld->type() == MYSQL_TYPE_GEOMETRY)
> + {
> + if (fld->type() == MYSQL_TYPE_BLOB ||
> + fld->type() == MYSQL_TYPE_GEOMETRY)
> + key_part->key_part_flag|= HA_BLOB_PART;
> + else
> + key_part->key_part_flag|= HA_VAR_LENGTH_PART;
> + key_part->store_length+=HA_KEY_BLOB_LENGTH;
> + keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
> + }
> + if (fld->type() == MYSQL_TYPE_BIT)
> + key_part->key_part_flag|= HA_BIT_PART;
> +
> + if (i == 0 && key != prm_key)
> + fld->flags |= (((keyinfo->flags & HA_NOSAME) &&
> + (keyinfo->key_parts == 1)) ?
> + UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
> + if (i == 0)
> + fld->key_start.set_bit(key);
> + if (fld->key_length() == key_part->length &&
> + !(fld->flags & BLOB_FLAG))
> + {
> + if (tmp_handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
> + {
> + keys_for_keyread.set_bit(key);
> + fld->part_of_key.set_bit(key);
> + fld->part_of_key_not_clustered.set_bit(key);
> + }
> + if (tmp_handler_file->index_flags(key, i, 1) & HA_READ_ORDER)
> + fld->part_of_sortkey.set_bit(key);
> + }
> + if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
> + usable_parts == i)
> + usable_parts++; // For FILESORT
> + fld->flags|= PART_KEY_FLAG;
> + if (key == prm_key)
> + {
> + fld->flags|= PRI_KEY_FLAG;
> + /*
> + If this field is part of the primary key and all keys contains
> + the primary key, then we can use any key to find this column
> + */
> + if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
> + {
> + if (fld->key_length() == key_part->length &&
> + !(fld->flags & BLOB_FLAG))
> + fld->part_of_key= keys_in_use;
> + if (fld->part_of_sortkey.is_set(key))
> + fld->part_of_sortkey= keys_in_use;
> + }
> + }
> + if (fld->key_length() != key_part->length)
> + {
> + key_part->key_part_flag|= HA_PART_KEY_SEG;
> + }
> + if (fld->real_maybe_null())
> + key_part->key_part_flag|= HA_NULL_PART;
> + /*
> + Sometimes we can compare key parts for equality with memcmp.
> + But not always.
> + */
> + if (!(key_part->key_part_flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART |
> + HA_BIT_PART)) &&
> + key_part->type != HA_KEYTYPE_FLOAT &&
> + key_part->type == HA_KEYTYPE_DOUBLE)
> + key_part->key_part_flag|= HA_CAN_MEMCMP;
> + }
> + keyinfo->usable_key_parts= usable_parts; // Filesort
> +
> + set_if_bigger(max_key_length,keyinfo->key_length+
> + keyinfo->key_parts);
> + total_key_length+= keyinfo->key_length;
> + /*
> + MERGE tables do not have unique indexes. But every key could be
> + an unique index on the underlying MyISAM table. (Bug #10400)
> + */
> + if ((keyinfo->flags & HA_NOSAME) ||
> + (ha_option & HA_ANY_INDEX_MAY_BE_UNIQUE))
> + set_if_bigger(max_unique_length,keyinfo->key_length);
> + }
> + if (prm_key < MAX_KEY &&
> + (keys_in_use.is_set(prm_key)))
> + {
> + primary_key= prm_key;
> + /*
> + If we are using an integer as the primary key then allow the user to
> + refer to it as '_rowid'
> + */
> + if (key_info[prm_key].key_parts == 1)
> + {
> + Field *fld= key_info[prm_key].key_part[0].field;
> + if (fld && fld->result_type() == INT_RESULT)
> + {
> + /* note that fieldnr here (and rowid_field_offset) starts from 1 */
> + rowid_field_offset= (key_info[prm_key].key_part[0].
> + fieldnr);
> + }
> + }
> + }
> + else
> + primary_key = MAX_KEY; // we do not have a primary key
> + }
> + else
> + primary_key= MAX_KEY;
> +
> + return FALSE;
> +}
> +
> /*
> Read data from a binary .frm file from MySQL 3.23 - 5.0 into TABLE_SHARE
> */
> @@ -747,38 +1544,53 @@ static int open_binary_frm(THD *thd, TAB
> legacy_db_type < DB_TYPE_FIRST_DYNAMIC)
> share->db_plugin= ha_lock_engine(NULL,
> ha_checktype(thd, legacy_db_type, 0, 0));
> - share->db_create_options= db_create_options= uint2korr(head+30);
> - share->db_options_in_use= share->db_create_options;
> - share->mysql_version= uint4korr(head+51);
> - share->null_field_first= 0;
> - if (!head[32]) // New frm file in 3.23
> - {
> - share->avg_row_length= uint4korr(head+34);
> - share->transactional= (ha_choice) (head[39] & 3);
> - share->page_checksum= (ha_choice) ((head[39] >> 2) & 3);
> - share->row_type= (row_type) head[40];
> - share->table_charset= get_charset((uint) head[38],MYF(0));
> - share->null_field_first= 1;
> - }
> - if (!share->table_charset)
> - {
> - /* unknown charset in head[38] or pre-3.23 frm */
> - if (use_mb(default_charset_info))
> - {
> - /* Warn that we may be changing the size of character columns */
> - sql_print_warning("'%s' had no or invalid character set, "
> - "and default character set is multi-byte, "
> - "so character column sizes may have changed",
> - share->path.str);
> - }
> - share->table_charset= default_charset_info;
> +
> +
> + {
> + enum ha_choice transact= HA_CHOICE_UNDEF;
> + enum ha_choice page_chcksum= HA_CHOICE_UNDEF;
> + enum row_type rtype= ROW_TYPE_DEFAULT;
> + CHARSET_INFO *charset= NULL;
> + bool null_fld_first= 0;
> + ulong avg_row_len= 0;
> + if (!head[32]) // New frm file in 3.23
> + {
> + avg_row_len= uint4korr(head+34);
> + transact= (ha_choice) (head[39] & 3);
> + page_chcksum= (ha_choice) ((head[39] >> 2) & 3);
> + rtype= (row_type) head[40];
> + charset= get_charset((uint) head[38],MYF(0));
> + null_fld_first= 1;
> + }
> + if (!charset)
> + {
> + /* unknown charset in head[38] or pre-3.23 frm */
> + if (use_mb(default_charset_info))
> + {
> + /* Warn that we may be changing the size of character columns */
> + sql_print_warning("'%s' had no or invalid character set, "
> + "and default character set is multi-byte, "
> + "so character column sizes may have changed",
> + share->path.str);
> + }
> + charset= default_charset_info;
> + }
> + if (share->
> + set_init_parameters(frm_ver,
> + uint4korr(head + 51), /*MySQL Version of the frm*/
> + uint2korr(head + 30), /*Create options (old)*/
> + avg_row_len, transact, page_chcksum,
> + rtype, charset, null_fld_first,
> + uint4korr(head+22), /*MIN_ROWS*/
> + uint4korr(head+18), /*MAX_ROWS*/
> + uint2korr(head+16), /*record length*/
> + uint2korr(head+59), /*extra_rec_buf_length*/
> + uint2korr(head+62), /*key block size*/
> + new_field_pack_flag,
> + error))
I'd say you can remove this method completely - it's just a set of
assignments, the caller can do them directly.
better try to provide reasonable defaults (in share->init()),
so that the caller would not need to assign most of those.
> + goto free_and_err;
> }
> - share->db_record_offset= 1;
> - if (db_create_options & HA_OPTION_LONG_BLOB_PTR)
> - share->blob_ptr_size= portable_sizeof_char_ptr;
> error=4;
> - share->max_rows= uint4korr(head+18);
> - share->min_rows= uint4korr(head+22);
>
> /* Read keyinformation */
> key_info_length= (uint) uint2korr(head+28);
> @@ -787,84 +1599,85 @@ static int open_binary_frm(THD *thd, TAB
> goto err; /* purecov: inspected */
> if (disk_buff[0] & 0x80)
> {
> - share->keys= keys= (disk_buff[1] << 7) | (disk_buff[0] & 0x7f);
> - share->key_parts= key_parts= uint2korr(disk_buff+2);
> + keys= (disk_buff[1] << 7) | (disk_buff[0] & 0x7f);
> + key_parts= uint2korr(disk_buff+2);
> }
> else
> {
> - share->keys= keys= disk_buff[0];
> - share->key_parts= key_parts= disk_buff[1];
> + keys= disk_buff[0];
> + key_parts= disk_buff[1];
> }
> - share->keys_for_keyread.init(0);
> - share->keys_in_use.init(keys);
> -
> - n_length=keys*sizeof(KEY)+key_parts*sizeof(KEY_PART_INFO);
> - if (!(keyinfo = (KEY*) alloc_root(&share->mem_root,
> - n_length + uint2korr(disk_buff+4))))
> - goto err; /* purecov: inspected */
> - bzero((char*) keyinfo,n_length);
> - share->key_info= keyinfo;
> - key_part= my_reinterpret_cast(KEY_PART_INFO*) (keyinfo+keys);
> - strpos=disk_buff+6;
> -
> - if (!(rec_per_key= (ulong*) alloc_root(&share->mem_root,
> - sizeof(ulong)*key_parts)))
> + if (share->allocate_indices_space(keys, key_parts,
> + uint2korr(disk_buff + 4) - keys - 1,
> + error))
> goto err;
> + strpos=disk_buff+6;
>
> - for (i=0 ; i < keys ; i++, keyinfo++)
> + for (i=0 ; i < keys ; i++)
> {
> if (new_frm_ver >= 3)
> {
> - keyinfo->flags= (uint) uint2korr(strpos) ^ HA_NOSAME;
> - keyinfo->key_length= (uint) uint2korr(strpos+2);
> - keyinfo->key_parts= (uint) strpos[4];
> - keyinfo->algorithm= (enum ha_key_alg) strpos[5];
> - keyinfo->block_size= uint2korr(strpos+6);
> + keyinfo= share->add_index(NULL, 0,
> + (uint) uint2korr(strpos) ^ HA_NOSAME,
> + (uint) uint2korr(strpos + 2),
> + (uint) strpos[4], (enum ha_key_alg) strpos[5],
> + uint2korr(strpos + 6));
make block_size an optional parameter, or let the caller set it directly
> strpos+=8;
> }
> else
> {
> - keyinfo->flags= ((uint) strpos[0]) ^ HA_NOSAME;
> - keyinfo->key_length= (uint) uint2korr(strpos+1);
> - keyinfo->key_parts= (uint) strpos[3];
> - keyinfo->algorithm= HA_KEY_ALG_UNDEF;
> + keyinfo= share->add_index(NULL, 0,
> + ((uint) strpos[0]) ^ HA_NOSAME,
> + (uint) uint2korr(strpos + 1),
> + (uint) strpos[3],
> + HA_KEY_ALG_UNDEF, 0);
> strpos+=4;
> }
>
> - keyinfo->key_part= key_part;
> - keyinfo->rec_per_key= rec_per_key;
> - for (j=keyinfo->key_parts ; j-- ; key_part++)
> + for (j=keyinfo->key_parts ; j-- ; )
> {
> - *rec_per_key++=0;
> - key_part->fieldnr= (uint16) (uint2korr(strpos) & FIELD_NR_MASK);
> - key_part->offset= (uint) uint2korr(strpos+2)-1;
> - key_part->key_type= (uint) uint2korr(strpos+5);
> - // key_part->field= (Field*) 0; // Will be fixed later
> if (new_frm_ver >= 1)
> {
> - key_part->key_part_flag= *(strpos+4);
> - key_part->length= (uint) uint2korr(strpos+7);
> + if (share->add_index_part(keyinfo,
> + (uint16)
> + (uint2korr(strpos) & FIELD_NR_MASK),
> + (uint) uint2korr(strpos + 2) - 1,
> + (uint) uint2korr(strpos + 5),
> + (uint) uint2korr(strpos + 7),
> + *(strpos + 4),
> + error))
> + {
> + DBUG_ASSERT(0); // it is not possible if keys defined first
> + }
> strpos+=9;
> }
> else
> {
> - key_part->length= *(strpos+4);
> - key_part->key_part_flag=0;
> - if (key_part->length > 128)
> + uint16 length= *(strpos+4);
> + uint16 flags= 0;
> + if (length > 128)
> {
> - key_part->length&=127; /* purecov: inspected */
> - key_part->key_part_flag=HA_REVERSE_SORT; /* purecov: inspected */
> + length&= 127; /* purecov: inspected */
> + flags= HA_REVERSE_SORT; /* purecov: inspected */
> }
> + if (share->add_index_part(keyinfo,
> + (uint16)
> + (uint2korr(strpos) & FIELD_NR_MASK),
> + (uint) uint2korr(strpos+2)-1,
> + (uint) uint2korr(strpos+5),
> + length, flags, error))
> + {
> + DBUG_ASSERT(0); // it is not possible if keys defined first
> + }
> strpos+=7;
> }
> - key_part->store_length=key_part->length;
> }
> }
> - keynames=(char*) key_part;
> - strpos+= (strmov(keynames, (char *) strpos) - keynames)+1;
>
> - share->reclength = uint2korr((head+16));
> - share->stored_rec_length= share->reclength;
> + if (share->add_index_names_as_onestring(strpos, i))
> + goto err;
No, please remove this method, let the caller do strmov as before.
it's a weird thing that open_binary_frm is doing, there's no need to
create an api for that, just keep it the old way.
To repeat: we want to have a reasonable and sane API for storage engines to
use, not an API that allows to do everything that frm format was
historically forcing us to do in openfrm().
> + strpos+= i;
> +
> if (*(head+26) == 1)
> share->system= 1; /* one-record-database */
> #ifdef HAVE_CRYPTED_FRM
> @@ -1034,17 +1847,10 @@ static int open_binary_frm(THD *thd, TAB
> }
> DBUG_ASSERT(next_chunk <= buff_end);
> }
> - share->key_block_size= uint2korr(head+62);
>
> error=4;
> - extra_rec_buf_length= uint2korr(head+59);
> - rec_buff_length= ALIGN_SIZE(share->reclength + 1 + extra_rec_buf_length);
> - share->rec_buff_length= rec_buff_length;
> - if (!(record= (uchar *) alloc_root(&share->mem_root,
> - rec_buff_length)))
> - goto free_and_err; /* purecov: inspected */
> - share->default_values= record;
> - if (my_pread(file, record, (size_t) share->reclength,
> + /* TODO: make copy function for handler */
what does this comment mean?
> + if (my_pread(file, share->default_values, (size_t) share->reclength,
> record_offset, MYF(MY_NABP)))
> goto free_and_err; /* purecov: inspected */
>
> @@ -2785,6 +3271,27 @@ fix_type_pointers(const char ***array, T
> } /* fix_type_pointers */
>
>
> +static void
> +copy_typelib(TYPELIB *type_copy,
> + const char ***array, TYPELIB *point_to_type,
> + char **names, char chr)
> +{
> + *((*names)++)= chr; // full compatibility, just to be safe
> + type_copy->name= 0;
> + type_copy->type_names= *array;
> + type_copy->count= point_to_type->count;
> + for (uint i= 0; i < point_to_type->count; i++)
> + {
> + *((*array)++) = *names;
> + uchar *tmp= (uchar*) strmov((char*) *names, type_copy->type_names[i]);
> + *tmp++= (uchar)0;
> + *names= (char *)tmp;
> + }
> + *((*array)++)= NullS; /* End of type */
> + *((*names)++)= 0;
> +}
> +
> +
> TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings)
> {
> TYPELIB *result= (TYPELIB*) alloc_root(mem_root, sizeof(TYPELIB));
I don't understand how you handle our new table/field/index options,
those that can be defined per storage engine
> === modified file 'sql/table.h'
> --- a/sql/table.h 2011-08-17 05:48:35 +0000
> +++ b/sql/table.h 2011-10-04 11:14:59 +0000
> @@ -484,6 +485,39 @@ typedef struct st_table_share
> void *ha_data;
> void (*ha_data_destroy)(void *); /* An optional destructor for ha_data. */
>
> + /*
> + Variables of building the TABLE_SHARE.
> +
> + TODO: it might have sense to make separate structure for this variables
> + and deallocate it after building
> + */
Agree!
It would be better to remove all this added functionality (all new methods
and variables) from the TABLE_SHARE and create a separate class
TABLE_SHARE_builder (or whatever), and have it allocated on the stack, like
int open_binary_frm( ... )
{
TABLE_SHARE_builder builder(share);
...
builder->add_field(...);
...
... etc ...
}
this looks like a cleaner approach - the builder and all its memory is
destroyed when the function returns. And the TABLE_SHARE itself
does not have the "building" methods - it always represents a complete
and frozen table structure.
> + KEY_PART_INFO *first_key_part; // pointer on parts array
> + KEY_PART_INFO *key_part; // current position during key parts adding
> + KEY *key; // current position during keys adding
> + ulong *rec_per_key;
> + const char **interval_array;
> + char *first_keyname; // pointer on the first index name string
> + char *keyname; // pointer on the current index name string during adding
> + char *names; // array of pointers to all names used in the definition
> + char *curr_interval_names;
> + TYPELIB *curr_interval;
> + const char **curr_interval_array;
> + char *first_comment, *comment_pos;
> + char *curr_field_names;
> + uchar *null_flags, *null_pos; //pointers to the NULL bits during field adding
> + /* Needed for fixing indices according to handler abilities and features */
> + handler *tmp_handler_file;
> + Field **field_ptr;
> + uint enum_set_values, enums_sets, comments_length;
> + uint new_field_pack_flag;
> + uchar null_bit_pos;
> + bool use_hash; /* use hash for field names */
> + bool null_bits_are_used;
> + /* Flags of the building progress (also used by triggers) */
> + bool is_keys_allocated, is_fields_allocated,
> + is_keynames_ready, is_fieldnames_ready, is_keyparts_ready,
> + is_comments_ready, is_fields_ready;
> + /* end of declaration of variables for building TABLE_SHARE*/
>
> /*
> Set share's table cache key and update its db and table name appropriately.
> @@ -652,6 +686,96 @@ typedef struct st_table_share
> return (tmp_table == SYSTEM_TMP_TABLE || is_view) ? 0 : table_map_id;
> }
>
> + /* Table_share building functions */
> + void init_metadata()
> + {
> + is_keys_allocated= is_fields_allocated=
> + is_keynames_ready= is_fieldnames_ready= is_comments_ready=
> + is_keyparts_ready= is_fields_ready= FALSE;
> + }
> + bool set_init_parameters(uchar frm_ver, ulong mysql_ver, uint db_create_opt,
> + ulong avg_row_len, enum ha_choice transact,
> + enum ha_choice page_chcksum, enum row_type rtype,
> + CHARSET_INFO *charset, bool null_fld_first,
> + ha_rows mi_rows, ha_rows ma_rows,
> + ulong reclen, uint extra_rec_buf_len,
> + uint key_blck_size, uint new_fld_pck_flg,
> + int &error);
> + bool allocate_indices_space(uint keys, uint parts, uint names_len,
> + int &error);
> + KEY *add_index(char *name, uint name_len,
> + uint flags, uint length, uint parts,
> + enum ha_key_alg alg, uint blk_size);
> + bool add_index_part(KEY *keyinfo, uint16 fieldnr,
> + uint offset, uint16 keytype,
> + uint16 length, uint16 flags, int &error);
> + inline bool add_index_names_as_onestring(uchar *pos, uint &len)
> + {
> + DBUG_ASSERT(is_keys_allocated);
> + DBUG_ASSERT(keyname == first_keyname); // add_key did not used names
> + len= (strmov(first_keyname, (char *) pos) - first_keyname) + 1;
> + is_keynames_ready= TRUE;
> + if (is_fieldnames_ready && parse_names())
> + return TRUE;
> + return FALSE;
> + }
> + inline bool add_field_enum_set_names_as_onestring(uchar *pos, uint len)
> + {
> + DBUG_ASSERT(is_fields_allocated);
> + memcpy((char*) names, pos, len);
> + is_fieldnames_ready= TRUE;
> + if (is_keynames_ready && parse_names())
> + return TRUE;
> + return FALSE;
> + }
> + inline void add_comments_as_one_string(const uchar *pos)
> + {
> + DBUG_ASSERT(is_fields_allocated);
> + memcpy(first_comment, pos, comments_length);
> + is_comments_ready= TRUE;
> + }
See above, I don't think that these *_onestring functions are necessary.
if you use the pointers are provided by the caller,
than open_binary_frm can parse these "one strings" as it wants
and pass pointers down. Thus keeping this trickery out of the api.
> +
> + bool allocate_fields_space(uint fields_count,
> + uint null_flds,
> + uint enum_set_count,
> + uint enum_set_values_count,
> + uint field_names_length,
> + uint enum_set_names_length,
> + uint com_length,
> + handler *handler_file,
> + size_t tbl_com_length= 0,
> + char *tbl_com= NULL);
> + Field **add_field(const char *name,
> + uchar *pos,
> + uint32 field_length,
> + uint pack_flag,
> + enum_field_types field_type,
> + CHARSET_INFO *charset,
> + geometry_type geom_type,
> + bool auto_increment,
> + TYPELIB* enum_set,
> + char *comm_pos,
> + uint comment_length,
> + int &error);
> + Field **add_field_int(const char *name,
> + uchar *pos,
> + uint32 field_length,
> + uint pack_flag,
> + enum_field_types field_type,
> + CHARSET_INFO *charset,
> + geometry_type geom_type,
> + utype unireg_type,
> + TYPELIB* enum_set,
> + char *comment_pos,
> + uint comment_length,
> + Virtual_column_info *vcol_info,
> + bool fld_stored_in_db,
> + int &error);
> +private:
> + bool final_fields_keys_allocation();
> + bool parse_names();
> + bool connect_indexes_and_fields(int &error);
> +
> } TABLE_SHARE;
>
Regards,
Sergei
1
0
Hi Serg,
Your latest push into 5.3 broke compilation on Windows:
http://buildbot.askmonty.org/buildbot/builders/win2008r2-vs2010-i386-packag…
http://buildbot.askmonty.org/buildbot/builders/win32-debug2/builds/734/step…
Could you please fix it? (If you don't have any idea what could be the cause,
maybe Wlad could help us?)
BR
Sergey
--
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
3
3
Hi!
As discussed on the yesterday's call, we're starting to prepare for the
next 5.3 release, 5.3.2 beta. The intent is to build it on this or on the
next weekend.
Before the release, we need to do
1. Bugs
2. optimizer_switch changes.
3. Merge from mariadb-5.1
We don't need to address:
1. Pushing Kristian's replication features. If I heard correctly, the
decision was that they won't be pushed into 5.3 (please correct me
if I am wrong)
== Bugs ==
Current situation with 5.3-targeted bugs is as follows:
Crashing bugs:
- SergeyP: 3 + 2 non-repeatable (#860535 #860553 #861147
#860561 (non-repeatable)
#860580 (non-repeatable))
- Timour: 2 (#824425 #858148)
- Nobody: 1 (#859375)
Wrong query result bugs:
- Timour: 8 (#858038 #817966 #833777 #825051 #826150 #747278 #833702 #856152)
- Igor : 2 (#823301 #791761)
- Sanja: 1 (#825075)
I have a slight excuse that all my crasing bugs were filed just yesterday.
I'll try to fix them before the release.
Another problem area is Timour's crashes + wrong query result bugs.
Also, we need to assign #859375.
== optimizer_switch changes ==
Some of the new optimizations are already sufficiently stable so that they can
be made enabled by default.
>From the code quality point of view, Philip's opinion is:
- subquery_cache can be turned ON.
- join_cache_level can be set to value higher than 1, and also
various variants of BKA/Hash join may be enabled.
- MRR can be enabled
- index_condition_pushdown can be enabled
- Materialization still has bugs, cannot be enabled.
- semi-joins+materialization cannot be enabled together, there are bugs.
- semi-joins without materialization cause non-repeatable crashes, so
cannot be enabled yet.
- FROM subqueries/derived tables optimization didn't recieve sufficient testing
yet, so cannot be enabled.
Note that the above is based only on the number of known crashes/wrong query
result problems, performance issues are not counted.
My opinion is that
- subquery_cache can be enabled.
- index_condition_pushdown can be enabled.
- I'm hesitant to enable MRR because it may cause slowdowns for small-dataset
sysbench-like tests.
- perhaps, some part of hash join could be enabled (as far as I understand, its
overhead is rather small, so it doesn't cause regressions?)
Anybody (and especially feature "owners") have any thoughts?
== Merge from MariaDB 5.1 ==
Monty mentioned we'll need to do it, but nobody took this task?
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
3
2

[Maria-developers] optimizer_switch default settings change for 5.3.2: status?
by Sergey Petrunya 09 Oct '11
by Sergey Petrunya 09 Oct '11
09 Oct '11
Hi Sanja,
I was wondering if you have any progress with optimizer_switch default
settings change that we decided to do for the 5.3.2 release?
Any ETA on when that will be pushed?
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0
Hi Serg,
Here is the status of my efforts to merge the rpl,binlog, and innodb suites.
These are the tests that still fail after my last pust to 5.5-serg:
binlog.binlog_innodb_row
This fails because of a problem in my merge of group commit, I will fix.
binlog.binlog_killed
I do not know yet, I can take a look next week.
binlog.binlog_index
This fails because of missing --test-expect-abort option which you said
you would re-add back.
rpl.rpl_create_if_not_exists
Something with CREATE IF NOT EXISTS, I believe you said you would look at
this (not related to replication).
rpl.rpl_variables_stm
This looks like microsecond related, maybe you can check.
innodb.innodb
innodb.innodb_no_mrricp
innodb.innodb_mysql
I think we should ask someone from optimiser to take a look at these.
- Kristian.
3
3

06 Oct '11
Hi Philip,
I've fixed/pushed all semi-join bugs. If I recall correctly, you intended to
do more semi-join testing, now everything is ready for it.
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
2
1

05 Oct '11
Cool, thank you!
As I'm not very familiar with the working process between MariaDB and MySQL
upstream, do you think this patch will go back upstream? My intention in my
original work on it was to get a fix into all distros that track MySQL.
Thanks again!
Jeremy Thomerson
On Wed, Oct 5, 2011 at 8:56 AM, Timour Katchaounov
<timour(a)montyprogram.com>wrote:
> Hello Jeremy,
>
> This is to inform you that I started working on
> MySQL Bug 59449. In order to track the bug progress
> I created a bug in Launchpad:
> https://bugs.launchpad.net/**maria/+bug/861763<https://bugs.launchpad.net/maria/+bug/861763>
>
> If you are interested in following the progress of
> this work, please subscribe to the Launchpad bug above.
>
> I will work on implementing the generic solution
> suggested by Monty.
>
> Timour
>
>
>
>> Hi!
>>
>> "Jeremy" == Jeremy Thomerson<jeremy(a)**thomersonfamily.com<jeremy(a)thomersonfamily.com>>
>>>>>>> writes:
>>>>>>>
>>>>>>
>> Jeremy> Monty, et al...
>> Jeremy> On Mon, Jun 13, 2011 at 9:36 AM, Michael Widenius<
>> monty(a)askmonty.org>**wrote:
>>
>>
>>>> Hi!
>>>>
>>>> "Sergei" == Sergei Golubchik<serg(a)askmonty.org> writes:
>>>>>>>>>
>>>>>>>>
>>>> Sergei> Hi, Jeremy!
>> Sergei> On Jun 10, Jeremy Thomerson wrote:
>>
>>> I just submitted a patch to a MySQL bug that I am also experiencing. I
>>>>>> would like to see it accepted into the wider community (MySQL,
>>>>>> MariaDB,
>>>>>> Percona, etc). Please let me know what I need to do so that this
>>>>>> patch
>>>>>> could also be accepted into your project.
>>>>>>
>>>>>> The bug is here: http://bugs.mysql.com/bug.php?**id=59449<http://bugs.mysql.com/bug.php?id=59449>
>>>>>> The "[11 Jun 3:16] Jeremy Thomerson" comment will be the most useful.
>>>>>>
>>>>>
>>>>
>>
>> Sergei> But if Oracle will refuse to fix this bug, we will look at your
>>
>>> patch,
>>>>
>>> Sergei> certainly.
>>
>>>
>>>> To ensure we don't forget about this, if you are not sure that Oracle
>>>> has fixed the bug within one month, ping us and we will look at
>>>> adding this into MariaDB at once.
>>>>
>>>>
>> Jeremy> Thanks a bunch! I was away a lot in July and August and didn't
>> get to
>> Jeremy> follow up on this. Looking at the original bug report, I have
>> seen
>> Jeremy> absolutely no activity. I'm not even sure why they have not
>> touched /
>> Jeremy> accepted it. If anyone here knows a way to get it into one (or
>> both)
>> Jeremy> projects, I'd appreciate any help you can offer.
>>
>> The patch you suggested was:
>>
>> === modified file 'sql/sql_base.cc'
>> --- sql/sql_base.cc 2011-04-12 10:59:59 +0000
>> +++ sql/sql_base.cc 2011-06-10 20:11:52 +0000
>> @@ -6975,6 +6975,28 @@
>> *counter= i;
>> *resolution= RESOLVED_IGNORING_ALIAS;
>> break;
>> + }
>> + else if (find->type() == Item::FUNC_ITEM&& ((Item_func*)
>> find)->functype() == Item_func::COLLATE_FUNC&& ((Item_func*)
>> find)->arg_count == 2)
>>
>> + {
>> + /*
>> + If someone uses "ORDER BY column_name COLLATE utf8_spanish_ci",
>> it is a function
>> + that we are trying to find, and not a real column. Bug #59449
>> exposes that this
>> + failed when column_name is actually referring to the name of an
>> alias, whether
>> + that alias is for a real column or for a function result (such
>> as coalesce). This
>> + block of code finds the real item, which is the "column"
>> referred to by the
>> + collation function for this scenario.
>> + */
>> + Item *collated_column = ((Item_func*) find)->arguments()[0];
>> + int is_alias = item->type() == Item::FUNC_ITEM ||
>> + ((item->type() == Item::FIELD_ITEM || item->type()
>> == Item::REF_ITEM)&&
>> + my_strcasecmp(system_charset_**info,
>> ((Item_ident*) item)->field_name, item->name));
>> + if (is_alias&& collated_column->name&& item->name&&
>> !my_strcasecmp(system_charset_**info, item->name,
>> collated_column->name))
>>
>> + {
>> + found =&collated_column;
>> + *counter = i;
>> + *resolution = RESOLVED_BEHIND_ALIAS;
>> + break;
>> + }
>> }
>> }
>> else if (table_name&& item->type() == Item::REF_ITEM&&
>>
>> What I don't like with the patch is that we make COLLATE a special
>> case. I think that all usage of alias names in ORDER BY should be
>> treated the same.
>>
>> In other words:
>>
>> ORDER BY LanguageName
>> ORDER BY LanguageName COLLATE utf8_spanish_ci
>> ORDER BY concat(LanguageName,"aa")
>>
>> should all use either the column or the alias in the same manner.
>>
>> As we normally prefer alias for a column name in the ORDER BY,
>> I think we should fix this so that we always prefer the alias name in
>> all ORDER BY context.
>>
>> The other option would be to give an error in this case as it's not
>> clear what the user wants. This is hower likely to break many old
>> applictions.
>>
>> After talking with Sergei, he concluded:
>>
>> "yes, I believe now that according to the SQL:2003 (ISO/IEC
>> 9075-2:2003, part 2 (foundations), 14.1<declare cursor>, Syntax
>> Rules, item 18) aliases from the select list take precedence over
>> column names from the table"
>>
>> The standard is very vague in the area, but it seams to support the
>> idea that alias'es should resolve first).
>>
>> This means that we should fix things to always first prefer alias.
>> The fix in this case needs to be done in item::fix_fields() and not in
>> sql_base.cc
>>
>> I will ask Timour to see if he can provide a fix for this.
>> (As he knows the fix_fields code quite well and he needs something to
>> bite into now when he is back from his vacation).
>>
>> Timour, can you handle this?
>>
>> Regards,
>> Monty
>>
>
1
0

[Maria-developers] WL#240 New (by Mdcallag): client-side compressed types
by worklog-noreply@askmonty.org 03 Oct '11
by worklog-noreply@askmonty.org 03 Oct '11
03 Oct '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: client-side compressed types
CREATION DATE..: Fri, 30 Sep 2011, 20:31
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Client-BackLog
TASK ID........: 240 (http://askmonty.org/worklog/?tid=240)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Is it possible to add a variant of the blob types that is compressed on the client
side? By this I mean that the client library handles compression and decompression
so that the client code does not have to deal with it.
The benefit from this is reduced load. There will be less network traffic between
client/server and master/slave. This uses less space in the binlog, relay log,
innodb transaction log and database files. The alternative is to use compression
between client/server and master/slave but that doesn't help with the size of the
binlog file nor with the innodb datafiles or log file.
We have too many cases where huge text/blob values store uncompressed JSON and the
bloat from that hurts performance.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
4
4

[Maria-developers] WL#239 New (by Jaequery): ability to have multiple TIMESTAMP columns with CURRENT_TIMESTAMP / on_update TIMESTAMP
by worklog-noreply@askmonty.org 28 Sep '11
by worklog-noreply@askmonty.org 28 Sep '11
28 Sep '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: ability to have multiple TIMESTAMP columns with CURRENT_TIMESTAMP /
on_update TIMESTAMP
CREATION DATE..: Wed, 28 Sep 2011, 19:37
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Client-BackLog
TASK ID........: 239 (http://askmonty.org/worklog/?tid=239)
VERSION........: Benchmarks-3.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Let's say I have two columns: 'created' and 'updated'
Currently I can only let 'created' use the CURRENT_TIMESTAMP attribute.
But ideally, I'd like 'updated' to also use CURRENT_TIMESTAMP as well as on_update
TIMESTAMP. This makes a lot more sense for operations like this when a developer
would have 'created', 'updated', or even 'deleted', columns. Only way we can do
this right now is via triggers or (shudder) setting them from the app server.
I understand there would be a underlying change and would really appreciate some
kind of change for this particular behavior.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

Re: [Maria-developers] Please review: [Commits] Rev 3199: Fix bug lp:858148. in file:///home/tsk/mprog/src/5.3/
by Igor Babaev 28 Sep '11
by Igor Babaev 28 Sep '11
28 Sep '11
OK to push.
Regards,
Igor.
On 09/28/2011 07:23 AM, Timour Katchaounov wrote:
> Hi Igor,
>
> Could you please review the following fix.
> It is very much related to a bug you fixed:
> https://bugs.launchpad.net/bugs/702301
>
> Thanks,
> Timour
>
> -------- Original Message --------
> Return-Path: <commits-bounces(a)mariadb.org>
> X-Original-To: timour(a)montyprogram.com
> Delivered-To: timour(a)montyprogram.com
> Received: from localhost (localhost.localdomain [127.0.0.1]) by
> hasky.askmonty.org (Postfix) with ESMTP id DFD38D0DCB; Wed, 28 Sep
> 2011 17:20:59 +0300 (EEST)
> X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
> Received: from hasky.askmonty.org ([127.0.0.1]) by localhost
> (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
> id lpHLfsC2eNw9; Wed, 28 Sep 2011 17:20:59 +0300 (EEST)
> Received: from hasky.askmonty.org (localhost.localdomain [127.0.0.1])
> by hasky.askmonty.org (Postfix) with ESMTP id BE79DC8236; Wed, 28 Sep
> 2011 17:20:59 +0300 (EEST)
> Received: by hasky.askmonty.org (Postfix) id 38FC0C8234; Wed, 28 Sep
> 2011 17:20:58 +0300 (EEST)
> Delivered-To: commits(a)mariadb.org
> Received: from localhost (localhost.localdomain [127.0.0.1]) by
> hasky.askmonty.org (Postfix) with ESMTP id 31622C8236 for
> <commits(a)mariadb.org>; Wed, 28 Sep 2011 17:20:58 +0300 (EEST)
> X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
> Received: from hasky.askmonty.org ([127.0.0.1]) by localhost
> (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
> id BvGNnoY8SHUx for <commits(a)mariadb.org>; Wed, 28 Sep 2011 17:20:52
> +0300 (EEST)
> Received: from localhost6.localdomain6 (unknown [212.91.171.126])
> (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No
> client certificate requested) by hasky.askmonty.org (Postfix) with
> ESMTPSA id 24886C8234 for <commits(a)mariadb.org>; Wed, 28 Sep 2011
> 17:20:52 +0300 (EEST)
> Content-Type: multipart/mixed;
> boundary="===============0198351398646356273=="
> MIME-Version: 1.0
> From: <timour(a)askmonty.org>
> User-Agent: bzr/2.3.4
> To: <commits(a)mariadb.org>
> Message-Id: <20110928142052.24886C8234(a)hasky.askmonty.org>
> Date: Wed, 28 Sep 2011 17:20:52 +0300 (EEST)
> Subject: [Commits] Rev 3199: Fix bug lp:858148. in
> file:///home/tsk/mprog/src/5.3/
> X-BeenThere: commits(a)mariadb.org
> X-Mailman-Version: 2.1.9
> Precedence: list
> Reply-To: maria-developers(a)lists.launchpad.net
> List-Id: MariaDB Commits List <commits.mariadb.org>
> List-Unsubscribe:
> <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>,
> <mailto:commits-request@mariadb.org?subject=unsubscribe>
> List-Archive: <http://lists.askmonty.org/pipermail/commits>
> List-Post: <mailto:commits@mariadb.org>
> List-Help: <mailto:commits-request@mariadb.org?subject=help>
> List-Subscribe:
> <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>,
> <mailto:commits-request@mariadb.org?subject=subscribe>
> Sender: commits-bounces(a)mariadb.org
> Errors-To: commits-bounces(a)mariadb.org
>
> At file:///home/tsk/mprog/src/5.3/
>
> ------------------------------------------------------------
> revno: 3199
> revision-id: timour(a)askmonty.org-20110928142043-b88ob3qytbroxdks
> parent: psergey(a)askmonty.org-20110928090147-izz3ebqbcrnakndu
> fixes bug(s): https://launchpad.net/bugs/858148
> committer: timour(a)askmonty.org
> branch nick: 5.3
> timestamp: Wed 2011-09-28 17:20:43 +0300
> message:
> Fix bug lp:858148.
>
> Analysis:
> The crash is a result of the same cause as all similar
> bugs (lp:827416, lp:718763, lp:778413, lp:806943,
> lp:611690). The general pattern is that some optimization
> requires the evaluation of some condition (e.g. the WHERE
> clause), and this condition contains a subquery, such that
> the subquery itself requires a temporary table for its
> execution. During the subquery execution the original
> tables in the FROM clause are replaced by the temporary
> table needed for the final GROUP or ORDER operation. All
> this happens during optimization of the outer query. Later
> when EXPLAIN is run for the subquery, explain attempts to
> print the name of the tables in the FROM clause, but it
> finds there a temporary table without a corresponding
> TABLE_LIST object. The attempt to print the name of a
> NULL table list results in a crash.
>
> Solution:
> This patch extends the fix to bug lp:702301, and dissalows
> constant substitution of aggregate functions if the filter
> condition used to check MIN/MAX keys is an expensive condition.
1
0

[Maria-developers] WL#238 New (by Snabb): Implement NOW() default value for DATETIME columns
by worklog-noreply@askmonty.org 27 Sep '11
by worklog-noreply@askmonty.org 27 Sep '11
27 Sep '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Implement NOW() default value for DATETIME columns
CREATION DATE..: Tue, 27 Sep 2011, 14:05
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 238 (http://askmonty.org/worklog/?tid=238)
VERSION........: Server-9.x
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Have a look at MySQL bug #27645: http://bugs.mysql.com/bug.php?id=27645
Currently it is possible to set the default value of a TIMESTAMP column to
CURRENT_TIME but this is not possible with DATETIME columns.
Looking at that bug report it looks like I am not the only one who wishes to use
DATETIME columns and have a way of setting their default value to the time when
the row was created.
Also TIMESTAMP DEFAULT CURRENT_TIME can occur only once in a table. It should be
possible to have several "DATETIME DEFAULT NOW()" columns (as this is useful for
having automatically initialized created_time and modified_time columns for a
row, for example).
Looks like MariaDB might gain some supporters by implementing this much-wanted
feature. Currently the only decent work-around is to create a trigger which
populates DATETIME columns before insert.
(I hope this is the proper way to file a feature request.)
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

Re: [Maria-developers] [Commits] Rev 3192: Added new options to KILL. New syntax is KILL [HARD|SOFT] [CONNECTION|QUERY] [ID | USER user_name] in lp:maria/5.3
by Sergei Golubchik 26 Sep '11
by Sergei Golubchik 26 Sep '11
26 Sep '11
Hi, Michael!
On Sep 23, Michael Widenius wrote:
> revno: 3192
> revision-id: monty(a)askmonty.org-20110922221338-wxnyyd5grsn689dy
> parent: sergii(a)pisem.net-20110922090400-jkxe2vagjakr4lbi
> committer: Michael Widenius <monty(a)askmonty.org>
> branch nick: maria-5.3
> timestamp: Fri 2011-09-23 01:13:38 +0300
> message:
> Added new options to KILL. New syntax is
> KILL [HARD|SOFT] [CONNECTION|QUERY] [ID | USER user_name]
> - If USER is given, all threads for that user is signaled
> - If SOFT is used then the KILL will not be sent to the handler.
Hm. So, this is the definition? "not sent to the handler"?
I liked the older version of it "not interrupt an operation that leaves
the table corrupted or unusable". This definition is easier to
understand for the user, who does not necessarily know or care
how every particular statement is split between the server and the
engine (especially, as this is different for different engines).
So, the point is - no matter how this SOFT is internally implemented (by
not sending to the handler or whatever), what is the official definition
of this feature? What should the manual say? Currently is says "will not
send the signal to storage engines" which - see above - is suboptimal,
in my opinion.
> This can be used to not interrupt critical things in the handler
> like 'REPAIR'.
>
> Internally added more kill signals. This gives us more information
> of why a query/connection was killed.
> - KILL_SERVER is used when server is going down. In this case the
> users gets ER_SHUTDOWN as the reason connection was killed.
> - Changed signals to number in correct order, which makes it easier
> to test how the signal should affect the code.
> - New error message ER_CONNECTION_KILLED if connection was killed by
> 'KILL CONNECTION'. Before we got error ER_SHUTDOWN.
>
> Changed names of not used parameters KILL_QUERY & KILL_CONNCTION to
> mysql_kill() to not conflict with defines in the server
> === modified file 'include/mysql.h.pp'
> --- a/include/mysql.h.pp 2011-07-21 12:50:25 +0000
> +++ b/include/mysql.h.pp 2011-09-22 22:13:38 +0000
> @@ -67,8 +67,8 @@ enum mysql_enum_shutdown_level {
> SHUTDOWN_WAIT_UPDATES= (unsigned char)(1 << 3),
> SHUTDOWN_WAIT_ALL_BUFFERS= ((unsigned char)(1 << 3) << 1),
> SHUTDOWN_WAIT_CRITICAL_BUFFERS= ((unsigned char)(1 << 3) << 1) + 1,
> - KILL_QUERY= 254,
> - KILL_CONNECTION= 255
> + SHUTDOWN_KILL_QUERY= 254,
> + SHUTDOWN_KILL_CONNECTION= 255
Why wouldn't you completely remove KILL_QUERY and KILL_CONNECTION from
this enum ?
Strictly speaking they are not "shutdown levels", they make no sense as
arguments to mysql_shutdown(). And, as you've noticed, shutdown levels
are completely ignored at the moment anyway - so nobody should miss
these constants if you remove them.
> };
> enum enum_cursor_type
> {
>
> === modified file 'mysql-test/t/kill.test'
> --- a/mysql-test/t/kill.test 2009-12-03 11:19:05 +0000
> +++ b/mysql-test/t/kill.test 2011-09-22 22:13:38 +0000
> @@ -337,5 +337,35 @@ SELECT 1;
>
> ###########################################################################
>
> +--echo #
> +--echo # Test kill USER
> +--echo #
> +
> +grant ALL on test.* to test@localhost;
> +grant ALL on test.* to test2@localhost;
> +connect (con3, localhost, test,,);
> +connect (con4, localhost, test2,,);
> +connection default;
> +--enable_info
> +kill hard query user test2@nohost;
> +kill soft query user test@localhost;
> +kill hard query user test@localhost;
> +kill soft connection user test2;
> +kill hard connection user test@localhost;
What about real tests? When you kill soft actually kills (and doesn't
kill) a statement. You can ask Philip to write them, I suppose.
> === modified file 'sql/sql_parse.cc'
> --- a/sql/sql_parse.cc 2011-09-10 15:01:27 +0000
> +++ b/sql/sql_parse.cc 2011-09-22 22:13:38 +0000
> @@ -7231,6 +7240,76 @@ uint kill_one_thread(THD *thd, ulong id,
> }
...
> +static uint kill_threads_for_user(THD *thd, LEX_USER *user,
> + killed_state kill_signal, ha_rows *rows)
> +{
> + THD *tmp;
> + List<THD> threads_to_kill;
> + DBUG_ENTER("kill_threads_for_user");
> +
> + *rows= 0;
> +
> + if (thd->is_fatal_error) // If we run out of memory
> + DBUG_RETURN(ER_OUT_OF_RESOURCES);
> +
> + DBUG_PRINT("enter", ("user: %s signal: %u", user->user.str,
> + (uint) kill_signal));
> +
> + VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
> + I_List_iterator<THD> it(threads);
> + while ((tmp=it++))
> + {
> + if (tmp->command == COM_DAEMON)
> + continue;
> + /*
> + Check that hostname (if given) and user name matches.
> +
> + host.str[0] == '%' means that host name was not given. See sql_yacc.yy
> + */
> + if (((user->host.str[0] == '%' && !user->host.str[1]) ||
> + !strcmp(tmp->security_ctx->host, user->host.str)) &&
> + !strcmp(tmp->security_ctx->user, user->user.str))
> + {
> + if (!(thd->security_ctx->master_access & SUPER_ACL) &&
> + !thd->security_ctx->user_matches(tmp->security_ctx))
So, without SUPER a user can only kill his own connections with
KILL USER.
A question.
Should "KILL USER my_name" also kill the current connection, or it
should only kill all other connections?
> + {
> + VOID(pthread_mutex_unlock(&LOCK_thread_count));
> + DBUG_RETURN(ER_KILL_DENIED_ERROR);
> + }
> + if (!threads_to_kill.push_back(tmp, tmp->mem_root))
> + pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete
> + }
> + }
> + VOID(pthread_mutex_unlock(&LOCK_thread_count));
> + if (!threads_to_kill.is_empty())
> + {
> + List_iterator_fast<THD> it(threads_to_kill);
> + THD *ptr;
> + while ((ptr= it++))
> + {
> + ptr->awake(kill_signal);
> + pthread_mutex_unlock(&ptr->LOCK_thd_data);
> + (*rows)++;
> + }
> + }
It may be a bit problematic. You lock thd->LOCK_thd_data for many
threads. This defines a specific locking order.
Which sounds quite fragile - I see no guarantee that this order cannot
be violated by another thread. It can be even violated by some other
feature that we'll implement in the future - and we won't notice it,
even your deadlock detector won't catch it, because you create the
dependency only during KILL USER, and only for specific THD's.
So, if we'll ever have this locking order violated, it will show up as
very random lockups in the undefined future :(
I would suggest to rewrite this code (if possible) to avoid locking all
thd->LOCK_thd_data's at once.
Note that this code doesn't have to be fast.
> + DBUG_RETURN(0);
> +}
> +
> @@ -7241,16 +7320,33 @@ uint kill_one_thread(THD *thd, ulong id,
> +void sql_kill_user(THD *thd, LEX_USER *user, killed_state state)
> +{
> + uint error;
> + ha_rows rows;
> + if (!(error= kill_threads_for_user(thd, user, state, &rows)))
I don't really understand why you've created a separate
kill_threads_for_user() instead of putting the code here.
But ok, as you like.
> + my_ok(thd, rows);
> + else
> + {
> + /*
> + This is probably ER_OUT_OF_RESOURCES, but in the future we may
> + want to write the name of the user we tried to kill
> + */
> + my_error(error, MYF(0), user->host.str, user->user.str);
> + }
> +}
> +
> === modified file 'storage/archive/ha_archive.cc'
> --- a/storage/archive/ha_archive.cc 2011-07-05 19:46:53 +0000
> +++ b/storage/archive/ha_archive.cc 2011-09-22 22:13:38 +0000
> @@ -17,6 +17,7 @@
> #pragma implementation // gcc: Class implementation
> #endif
>
> +#define MYSQL_SERVER 1
why?
> #include "mysql_priv.h"
> #include <myisam.h>
>
Regards,
Sergei
2
2
Hi!
>>>>> "Sergei" == Sergei Golubchik <serg(a)askmonty.org> writes:
Sergei> Hi, Michael!
Sergei> On Sep 23, Michael Widenius wrote:
>> === modified file 'mysql-test/r/user_limits.result'
>> --- mysql-test/r/user_limits.result 2005-05-02 18:45:06 +0000
>> +++ mysql-test/r/user_limits.result 2011-09-23 11:50:40 +0000
>> @@ -65,6 +65,16 @@ select * from t1;
>> connect(localhost,mysqltest_1,,test,MYSQL_PORT,MYSQL_SOCK);
>> ERROR 42000: User 'mysqltest_1' has exceeded the 'max_user_connections' resource (current value: 3)
>> +grant usage on *.* to mysqltest_1@localhost with max_user_connections -1;
Sergei> I still think that -1 (and 0 too) as special values look like a very
Sergei> unprofessional hack. I'd rather see keywords there like
Sergei> with max_user_connections UNLIMITED
Sergei> with max_user_connections NONE
That would be harder to document and understand when you take into
account how the global variable max_user_connections work.
I prefer to have these work identical.
Sergei> as for the SET, SHOW VARIABLES, and command-line options - we can easily
Sergei> support keywords if we declare max_user_connections to be a string
Sergei> variable, not numeric, and will parse it manually.
That I see would be an even great hack.
The 'proper' way for the future would be to change the default value
of 'max_user_connections' to MAX_INT and in the future threat 0 to
mean zero connections.
>> === modified file 'scripts/mysql_system_tables_fix.sql'
>> --- scripts/mysql_system_tables_fix.sql 2011-05-28 02:11:32 +0000
>> +++ scripts/mysql_system_tables_fix.sql 2011-09-22 21:41:45 +0000
>> @@ -326,8 +326,11 @@ UPDATE host SET Create_routine_priv=Crea
>>
>> #
>> # Add max_user_connections resource limit
>> +# this is signed in MariaDB so that if one sets it's to -1 then the user
>> +# can't connect anymore.
Sergei> You need one special value (-1) and to get it you cut the number of
Sergei> allowed values in half. Instead, you could've kept max_user_connections
Sergei> as unsigned and only reserve (uint)~0 as "cannot connect".
It's a maxint; No one will *ever* have 2~31 connections.
This is ok.
>> switch (var->show_type())
>> {
>> - case SHOW_INT: get_sys_var_safe (uint);
>> + case SHOW_INT: get_sys_var_safe (int);
>> case SHOW_LONG: get_sys_var_safe (ulong);
>> case SHOW_LONGLONG: get_sys_var_safe (ulonglong);
>> case SHOW_HA_ROWS: get_sys_var_safe (ha_rows);
Sergei> This is a bit inconsistent. INT is signed, but LONG/LONGLONG are
Sergei> unsigned. Do I understand correctly that there will be no way to create
Sergei> an unsigned INT variable after your patch?
If you want unsigned int, you just use 'long'
(Most of our variables are 'long' anyway; We have only a handful of
int variables and the range of MAX_INT is good enough for these).
When we ever need unsigned int, we will add a SHOW_UINT.
I wanted to keep the patch minimal and as no-intrusive as possible
and thats why I only fixed SHOW_INT and not SHOW_LONG and SHOW_LONGLONG.
It's actually a bug that SHOW_INT didn't take negative numbers before;
It's supposed to work the same way as GET_INT works in my_getopt.c,
which it didn't do.
>> === modified file 'sql/sql_acl.cc'
>> - /* Don't allow the user to connect if he has done too many queries */
>> - if ((acl_user->user_resource.questions || acl_user->user_resource.updates ||
>> - acl_user->user_resource.conn_per_hour ||
>> - acl_user->user_resource.user_conn || max_user_connections) &&
>> - get_or_create_user_conn(thd,
>> - (opt_old_style_user_limits ? sctx->user : sctx->priv_user),
>> - (opt_old_style_user_limits ? sctx->host_or_ip : sctx->priv_host),
>> - &acl_user->user_resource))
>> + /*
>> + Don't allow the user to connect if he has done too many queries
>> + We always have to allocated this as someone may change
>> + max_user_connections any time.
Sergei> What do you mean?
That the original code was wrong. We can *not* do the allocation based
on the original 'if' as it's assumed that max_user_connections would
never change.
My comments explain that the we have always to call
get_or_create_user_conn() because max_user_connections depends on this
structure to exists.
>> + */
>> + if (get_or_create_user_conn(thd,
>> + (opt_old_style_user_limits ? sctx->user :
>> + sctx->priv_user),
>> + (opt_old_style_user_limits ? sctx->host_or_ip
>> + : sctx->priv_host),
>> + &acl_user->user_resource))
>> DBUG_RETURN(1); // The error is set by get_or_create_user_conn()
>> }
>> else
>>
>> === modified file 'sql/sql_connect.cc'
>> --- sql/sql_connect.cc 2011-09-22 22:13:38 +0000
>> +++ sql/sql_connect.cc 2011-09-22 22:58:07 +0000
>> @@ -113,8 +113,11 @@ int check_for_max_user_connections(THD *
>> DBUG_ENTER("check_for_max_user_connections");
>>
>> (void) pthread_mutex_lock(&LOCK_user_conn);
>> +
>> + /* Root is not affected by the value of max_user_connections */
Sergei> It's an incompatible change. Why did you do it? If the point was to
Sergei> allow SUPER connections when max_user_connections==-1, then it would be
Sergei> enough to make only this value (-1) to be ignored by the SUPER user, and
Sergei> any other value limit should still apply.
root users should not be affected by the global variables
max_user_connections or max_connections.
Yes, it's incompatible, but ok and necessary in this case as otherwise
no one could login if we set global.max_user_connections=1 which would
not let you maintain the server at all.
Sergei> SUPER user typically ignores features that prevent him from connecting
Sergei> to the server. E.g incorrect init-connect option may do it. Or a normal
Sergei> user may use up all max_connections limit and prevent SUPER from
Sergei> connecting. That's why SUPER ignores init-connect and is allowed one
Sergei> connection above max_connections.
Sergei> But max_user_connections can not prevent SUPER from connecting (unless
Sergei> it is -1). If it is set to, for example, 5, SUPER can have five
Sergei> simultaneous connections and no normal user can prevent him from doing
Sergei> it. This is why SUPER does *not* ignore max_user_connections.
Sergei> So, by this logic, only the value max_user_connections==-1 should be
Sergei> ignored by SUPER, and not any other value.
I think it's better to not regard any value as special. It's easier
to document it the current way; Doing it your way would make it hard
to document and understand and that usually means it's a bad idea.
(For example, what happens if you set max_user_connections=-1 and then
later change it to 1; What limits apply to the root user that is now
logged in twice).
If you want to constrain the root user, you can do that with
GRANT root ... max_user_connections=#
Regards,
Monty
1
0
Whild building mariadb on HP-UX, I ran into a problem with a call to
accept(). The mariadb configure script uses MYSQL_TYPE_ACCEPT to
determine if the third argument to accept should be type socklen_t or
type int, and sets SOCKET_SIZE_TYPE accordingly, but in socket_accept
(plugin/handler_socket/libhsclient/socket.cpp), the third argument to
the accept call (addrlen_r) is hardcoded to be type socklen_t instead of
using SOCKET_SIZE_TYPE. I think that the addrlen_r argument to
socket_accept should be type SOCKET_SIZE_TYPE instead of socklent_t. I
think this also means that the addrlen field in the socket_args
structure (plugin/handler_socket/libhsclient/socket.hpp) should be
type SOCKET_SIZE_TYPE instead of socklen_t.
Does that sound right?
Steve Ellcey
sje(a)cup.hp.com
2
4

[Maria-developers] WL#237 New (by DonQuichote): more IF EXISTS clauses
by worklog-noreply@askmonty.org 23 Sep '11
by worklog-noreply@askmonty.org 23 Sep '11
23 Sep '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: more IF EXISTS clauses
CREATION DATE..: Fri, 23 Sep 2011, 14:10
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 237 (http://askmonty.org/worklog/?tid=237)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
It would be nice if more statements were repeatable for use in scripts (See
http://www.howtoforge.com/node/4833 for the use of this). I would like to see
the IF (NOT) EXISTS clauses added to the RENAME command and it would really be
nice if such a clause could be added to the various operations of the ALTER
TABLE command. For example:
RENAME TABLE IF EXISTS WrongName TO RightName;
-- when placed in an update script, it will rename the table if it still has the
wrong name, but it will not fail if it already has the right name.
ALTER TABLE SomeTable ADD COLUMN IF NOT EXISTS ExtraColumn VARCHAR(255) DEFAULT
NULL;
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0
All,
Monty asked me to prep the MariaDB 5.2.9 release. He said to use the
build of revision 3033 for the release:
http://buildbot.askmonty.org/buildbot/grid?branch=5.2&category=package
http://bazaar.launchpad.net/~maria-captains/maria/5.2/revision/3033
...and I've uploaded the files from that build to the primary mirror.
They should be mirrored worldwide by tomorrow.
But before I can finish the release and announce it I need a couple of
things:
First, I need one of the developers to tag the release in the source
tree:
http://bazaar.launchpad.net/~maria-captains/maria/5.2/changes
Second, I need to know if there is anything that I should be sure to
mention in the release notes. One thing I can think of which hasn't
been mentioned in the past few release notes is which version of MySQL
that this version of MariaDB has merged in. The current versions of
other things, like PBXT and XtraDB would also be helpful.
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
2
2
Hi, I have downloaded the MariaDB 3.1 Beta sources and am trying to
build MariaDB on HP-UX 11.31 using the HP compilers and ran into a few
problems that I wanted to ask about. The first problem I ran into was
with anonymous unions (and structs).
Anonymous unions are part of the C++ standard, but not C (though the
GNU C compiler allows them). The header file include/ma_dyncol.h has
a structure, st_dynamic_column_value, which includes both anonymous
unions and anonymous structures and this file is included in both C
files (mysys/ma_dyncol.c and unittest/mysys/ma_dyncol-t.c) and C++ files
(sql/item_strfunc.cc).
This is causing the HP C compiler problems since it doesn't allow
anonymous unions (or structs) by default. Now I can use a GNU
compatibility mode in the compiler (-Agcc) to allow this to compile,
but that creates other problems, specifically it causes the MariaDB
configure script to think I am using GCC (because __GNUC__ is defined
in this mode) and then it runs the ABI check which fails because the HP
compiler doesn't generate preprocessed source that exactly matches the
expected GNU compiler output due to minor changes in the output.
So I was wondering if this use of anonymous unions in C code was
intentional or unintentional? I was also wondering about the use of
the anonymous structs in the anonymous union as that is not part of the
C or C++ standards, though the GNU compilers only complain about this
when you use the -pedantic flag.
What solution to this issue would people recommend? We could use the
GNU compatibility mode with the HP compilers but would have to modify
the configure script to not run the ABI check. Or we could remove
the use of anonymous unions (and structs) from the C code in MariaDB.
I prefer the second option because it makes the C code more consistent
with the C99 standard.
Steve Ellcey
sje(a)cup.hp.com
2
3
I just submitted a patch to a MySQL bug that I am also experiencing. I
would like to see it accepted into the wider community (MySQL, MariaDB,
Percona, etc). Please let me know what I need to do so that this patch
could also be accepted into your project.
The bug is here: http://bugs.mysql.com/bug.php?id=59449
The "[11 Jun 3:16] Jeremy Thomerson" comment will be the most useful.
Please CC me on any replies to this thread because I am not subscribed to
this mailing list.
Best Regards,
Jeremy Thomerson
3
4
I noticed: http://askmonty.org/blog/the-2-year-old-mariadb/ "The support for
microseconds in TIMESTAMP, DATETIME, and TIME".
I fully agree the 'full seconds support only' has been a sever limitation in
MySQL. But I have two concerns with ths:
1)
'noisyness'. On not very fast systems the last digits of a TIME in
microseconds should not be considered too much important. It depends on
what else the system is doing at the time. I think for lots of users
milliseconds and not microseconds would be better/more relevant. It is not
always a lot of digits can be proven true. When we went to school we were
all taught not to present results in natural sciences more accurate than the
accuracy of data sources and measurements. Providing too many digits in a
resuslt actually caused a lower score in my highschool!
2)
Compability. There is a problem with UPDATES. A client/application written
for MySQL may assume 'full seconds support only' and may generate the
current MySQL format byte format in the WHERE clause (typically if the
client reserves a 14 byte buffer for TIMERSTAMPS etc). In SQL:
UPDATE table SET column = 'something' WHERE time_column = '01:01:01':
.. this update will fail if the currently stored value is
'01:01:01:010001'; and the rigth query in the context would be.
UPDATE table SET column = 'something' WHERE time_column =
'01:01:01:010001';
Ideally I think there should be a configuration parameter and a global
variable to SET time_accuracy = full_second|millisecond|microsecond.
Did somebody have considerations about same? I definitely think that lots of
applications using a TIME|TIMESTAMP|DATETIME column in the WHERE-clause of
an UPDATE statement will need some rewrite to be upgradable to MariaDB 5.3
-- Peter
4
5

Re: [Maria-developers] [Commits] Rev 3020: MWL#192: Non-blocking client API for libmysqlclient. in http://bazaar.launchpad.net/~maria-captains/maria/5.2
by Kristian Nielsen 20 Sep '11
by Kristian Nielsen 20 Sep '11
20 Sep '11
Hi Monty,
Please find included the patch for MWL#192, non-blocking client API, for
review.
This patch is against MariaDB 5.2.8, though I expect the feature will
eventually be merged and pushed to MariaDB 5.5.
One thing in particular I would like to ask for advice on is if there are ways
to improve the integration with libmysql/NET/Vio, as you know this code much
better than me.
- Kristian.
2
4

14 Sep '11
Hi.
At the end of test_if_skip_sort_order() you put (in 5.3):
17959 /*
17960 orig_cond is a part of pre_idx_push_cond,
17961 no need to restore it.
17962 */
17963 orig_cond= 0;
17964 orig_cond_saved= false;
17965 if (orig_cond_saved && !changed_key)
17966 tab->set_cond(orig_cond);
Besides incorrect indentation, you set orig_cond_saved to false, and in
the next line writes an if() statement that can only work if
orig_cond_saved is true. If orig_cond_saved=false is correct, then this
if() can be completely removed. Or, may be, orig_cond_saved should not
be set to false?
Regards,
Sergei
1
0
All,
The packages for MariaDB 5.3.1-beta were uploaded to the primary mirror
yesterday and all of the mirrors (except one) have the files now, so
I've gone ahead and activated the download page and the release notes
and changelog pages.
* http://kb.askmonty.org/en/mariadb-531-release-notes
* http://kb.askmonty.org/en/mariadb-531-changelog
* http://downloads.askmonty.org/mariadb/5.3.1/
I will be waiting until Monday to send out the announcement email so if
there is anything that should be added to the release notes, please let
me know as soon as possible.
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0

Re: [Maria-developers] [Commits] Rev 3182: BUG#833600: Wrong result with view + outer join + uncorrelated subquery (non-semijoin) in file:///home/psergey/dev2/5.3-push14/
by Oleksandr Byelkin 09 Sep '11
by Oleksandr Byelkin 09 Sep '11
09 Sep '11
Hi!
8 сент. 2011, в 22:24, Sergey Petrunya написал(а):
> At file:///home/psergey/dev2/5.3-push14/
>
> ------------------------------------------------------------
> revno: 3182
> revision-id: psergey(a)askmonty.org-20110908192447-h8rmi1gvivwh59eh
> parent: psergey(a)askmonty.org-20110908173810-mcq7fj9d14ynyckq
> committer: Sergey Petrunya <psergey(a)askmonty.org>
> branch nick: 5.3-push14
> timestamp: Thu 2011-09-08 23:24:47 +0400
> message:
> BUG#833600: Wrong result with view + outer join + uncorrelated subquery (non-semijoin)
> - The bug was caused by outer join being incorrectly converted into inner because of
> invalid return values of Item_direct_view_ref::not_null_tables().
> - Provided a correct Item_direct_view_ref::not_null_tables() function.
The patch is OK
[skip]
1
0

Re: [Maria-developers] [Question #169828]: MariaDB 5.3.0 7 crash in 4 minutes
by Kristian Nielsen 08 Sep '11
by Kristian Nielsen 08 Sep '11
08 Sep '11
"Philip Stoev" <pstoev(a)askmonty.org> writes:
> Bug https://bugs.launchpad.net/maria/+bug/824463, which is in state
> "Fix Committed", is still present. I assume it is waiting for a
> review. There may be others like it.
I think we are using "Fix committed" and "Fix released" somewhat
inconsistently. I see two different policies both being used:
1. "Fix committed" means the fix is pushed to a main tree. "Fix released"
is set when an official release is made containing the fix.
2. "Fix committed" means a patch has been made but not pushed to main tree yet
(eg. there is a commit mail or maybe pushed to a feature branch). "Fix
released" means the fix is in a main tree.
I prefer (2), since it simplifies the maintenance of bug states.
When a fix is pushed to the main tree, the developer can mark the bug "fix
released" with a comment noting in which release the bug will appear (just the
next release number in the appropriate main tree, eg. "Fix will appear in
5.3.1").
With (1), we need an extra manual step where "someone" goes through bugs after
release and figures out which should be set to "Fix released". I do not think
this extra work gives any tangible benefits.
So my suggestion is to adopt (2) as policy for MariaDB. However, the most
important thing is that we adopt a consistent policy, whatever it is.
- Kristian.
2
1

[Maria-developers] Will MariaDB eventually work with R1Soft CDP MySQL plugin?
by Daniel Bartholomew 06 Sep '11
by Daniel Bartholomew 06 Sep '11
06 Sep '11
A new question has been posted to the Knowledgebase:
http://kb.askmonty.org/en/will-mariadb-eventually-work-with-r1soft-cdp-mysq…
---------------------------------------------------------------------
According to R1Soft, their CDP MySQL plugin
http://www.r1soft.com/linux-cdp/cdp-30-enterprise-edition/mysql/ for
mysql backup isn't compatible with MariaDB
http://www.webhostingtalk.com/showthread.php?t=1079176 .
Would be nice if it did.
Any chance of MariaDB folks working with R1Soft to make MariaDB 5.x
compatible ?
---------------------------------------------------------------------
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0
Hi!
I checked the results according the link you gave me, also I thing the tests made compact enough.
1
0

[Maria-developers] Moving process names, directories, TCP port etc from MySQL to MariaDB?
by Daniel Bartholomew 31 Aug '11
by Daniel Bartholomew 31 Aug '11
31 Aug '11
I just came across a question in the Knowledgebase that I missed
because it was posted as an article, not a question. I've turned it
into a proper question.
http://kb.askmonty.org/en/moving-process-names-directories-tcp-port-etc-fro…
----------------------------------------------------------------------
Is there a time line for MariaDB to break away from using MySQL for
things like its default port, directory names, suggested user name,
lock directory, names of support programs, etc ?
I know most things can be set in ./configure or in the .cnf file but
isn't it time to make the move ?
----------------------------------------------------------------------
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0

[Maria-developers] Down/crossgrading MySQL 5.more to MariaDB 5.less
by Daniel Bartholomew 31 Aug '11
by Daniel Bartholomew 31 Aug '11
31 Aug '11
A new question has been posted to the Knowledgebase:
http://kb.askmonty.org/en/downcrossgrading-mysql-5more-to-mariadb-5less
-----------------------------------------------------------------------
Obsessed with dynamic columns, I'm considering moving our whole install
from MySQL 5.5/MyISAM (just upgraded from 5.1 a few months back when
this would have been a no-brainer) over/down to MariaDB/MyISAM 5.3.
I am wondering if there is any official word on engine/table
compatibility and what I would have to undo for this move.
-----------------------------------------------------------------------
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0
Hello:
I am beginning to work on a MEMORY/HEAP modification for the ARIA
engine. This should compete favorably with the ORACLE times-ten option
or SYBASE In-Memory DB.
The goal is to replace the native MySQL Table-Locked HEAP table with a
record-locked ARIA based HEAP table.
It is my belief that not only should ARIA be the default transactional
and non-transactional engine for Mysql, but it should be the default
disk-based AND memory-based engine as well.
Before I get too far down this road, is there an ARIA engine diagram
that someone has done
from the core ARIA team.
Here is an example from Percona on XtraDB.
http://www.mysqlperformanceblog.com/wp-content/uploads/2010/04/InnoDB_int.p…
Also, do the core ARIA developers have comments on modification of the
ARIA engine to include a ARIA HEAP setting so the ARIA engine operates
only on in-memory tables. Have you ideas on things that are already
available to achieve this functionality.
I currently have a working ARIA based MEMORY/HEAP alternative running
under MariaDB 2.8.x on Linux
if anybody wants to know how to make that work immediately.
Next week, when I get my server parts, I will run mysqlslap benchmark
tests on an 8 core server
that should push I/O past the point that my current Dual core testing
computer running HEAP vs ARIA HEAP.
I want to see if I can push the Native HEAP past the point of the table
locking limit and
see if I can SCALE the ARIA HEAP to performance way beyond Native HEAP.
I will publish more info after I get responses from the Maria DB
development community.
Mark Diener
(Note to self-Fixed table cache)
1
0

[Maria-developers] MWL#182: a problem select_type column, SIMPLE vs PRIMARY
by Sergey Petrunya 29 Aug '11
by Sergey Petrunya 29 Aug '11
29 Aug '11
Hello,
When coding MWL#182, I've found out that it is very difficult to print
the same value of select_type as EXPLAIN does.
Problem description
-------------------
Moreover, any attempt to unify EXPLAIN and SHOW EXPLAIN code cause numerous
test failures because of changed select_type.
http://dev.mysql.com/doc/refman/5.5/en/explain-output.html#explain_select_t…
defines:
- SIMPLE Simple SELECT (not using UNION or subqueries)
- PRIMARY Outermost SELECT
In practice, this is is not always true. As a most striking example, grep for
this query in subselect4.test:
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
FROM t1
WHERE EMPNUM IN
(SELECT EMPNUM
FROM t3
WHERE PNUM IN
(SELECT PNUM
FROM t2
WHERE PTYPE = 'Design'))";
The first execution will produce rows with select_type='PRIMARY', while the
second will produce the same rows with select_type='SIMPLE'. Apparently, one
of these is wrong.
If you do a plain select from a VIEW that has a subquery
create view V as select ... (subquery) ...;
explain select * from V;
you get EXPLAIN output which starts with a row that select_type='SIMPLE' and
continues with rows describing the subquery, which causes a self-contradiction.
Current solution
----------------
My approach to dealing with this is as follows:
- MWL#182 code should not make changes to output of regular EXPLAIN SELECT
queries.
- Outputs of SHOW EXPLAIN and EXPLAIN SELECT of the same query may be slightly
different
This causes some ugliness in the code though, because I had to keep two
ways to generate select_type values.
I think this should be ok (if you disagree, please let me know)
Future solution #1: get rid of SIMPLE
-------------------------------------
I don't see a value of having select_type=SIMPLE (other than term "simple"
being encouraging for novice users:) We could change SIMPLE to PRIMARY
everywhere and get rid of the problem
Future solution #2: use SIMPLE/PRIMARY approach of SHOW EXPLAIN
---------------------------------------------------------------
EXPLAIN SELECT produces incorrect values because it calls
st_select_lex::set_explain_type() before the query rewrites are done, so
it can't see that
- used VIEWs have subqueries
- used subqueries will be flattened
- etc.
SHOW EXPLAIN operates on a query that is being executed, and that alone
guarantees its output is closer to reality. This means, EXPLAIN SELECT output
must be changed to match SHOW EXPLAIN output. This is a lot of changes
across a number of .result files.
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
3
2
Hi,
I've been working on some improvements to the table and index
statistics in mariadb that allow tracking on the session and query
level. I've been pushing the changes to
lp:~provenscaling-eric/maria/tivo The long form version of where I'm
at in my hacking is at
http://ebergen.net/wordpress/2011/07/28/second-update-of-modifying-table-st…
I want to poll this list for ides on a few places I'm stuck and get
the review process started to hopefully get some of these changes
merged back into mainline mariadb. My first issue is around allocation
of query ids for both show profiles and show table_statistics; Table
statistics are enabled by userstat and profiles are controlled by
profiling. Enabling these options at different times makes some
confusing results:
mysql> use test;
Database changed
mysql> set query_statistics_history_size=5;
Query OK, 0 rows affected (0.00 sec)
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t limit 5;
+-------+--------+
| t | u |
+-------+--------+
| 14515 | 282874 |
| 14521 | 258653 |
| 14573 | 113276 |
| 14577 | 826475 |
| 14585 | 444645 |
+-------+--------+
5 rows in set (0.00 sec)
mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 7 | 0.00052300 | select * from t limit 5 |
+----------+------------+-------------------------+
1 row in set (0.00 sec)
mysql> set profiling=0;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t limit 10;
+-------+--------+
| t | u |
+-------+--------+
| 14515 | 282874 |
| 14521 | 258653 |
| 14573 | 113276 |
| 14577 | 826475 |
| 14585 | 444645 |
| 14612 | 792545 |
| 14626 | 483300 |
| 14842 | 447267 |
| 15325 | 38865 |
| 15340 | 744424 |
+-------+--------+
10 rows in set (0.00 sec)
mysql> show query table_statistics;
+----------+--------------+------------+-----------+--------------+-------------------------+
| Query_id | Table_schema | Table_name | Rows_read | Rows_changed |
Rows_changed_x_#indexes |
+----------+--------------+------------+-----------+--------------+-------------------------+
| 2 | #temp# | #temp# | 15 | 15 |
15 |
| 7 | test | t | 5 | 0 |
0 |
| 10 | test | t | 10 | 0 |
0 |
+----------+--------------+------------+-----------+--------------+-------------------------+
3 rows in set (0.00 sec)
mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 7 | 0.00052300 | select * from t limit 5 |
+----------+------------+-------------------------+
1 row in set (0.00 sec)
My current thought is to create a show query history command that
unifies both show profiles and user stats but only table stats or
profiles will be available for any given query depending on the flags
set when it ran. I can also create a separate show queries command
only for table statistics. Any ideas on how to unify the two different
profiling methods or split up the syntax?
--
Eric Bergen
eric.bergen(a)gmail.com
http://www.ebergen.net
3
4

Re: [Maria-developers] [Commits] Rev 3156: MWL#182: Explain running statements
by Sergei Golubchik 24 Aug '11
by Sergei Golubchik 24 Aug '11
24 Aug '11
Hi, Sergey!
On Aug 23, Sergey Petrunya wrote:
> MWL#182: Explain running statements
> First code
> - "Asynchronous procedure call" system
I would like to review that part (at least), could you please tell me
when it's ready for a review?
> - new THD::check_killed() that serves APC request is called from
> within most important loops
> - put THD::check_killed() call into every loop where we could spend
> significant amount of time
This shouldn't be necessary, by trying to keep all long operations
killable we've already put a "killed" check everywhere.
If some long time consuming code needs a "killed" check but doesn't have
it - it's a bug on itself (some code does not respond to KILL).
Regards,
Sergei
2
1

Re: [Maria-developers] [Commits] Rev 3165: Fix bug lp:825095 in file:///home/tsk/mprog/src/5.3/
by Sergey Petrunya 23 Aug '11
by Sergey Petrunya 23 Aug '11
23 Aug '11
Hi Timour,
ok to push.
On Tue, Aug 23, 2011 at 12:00:29AM +0300, timour(a)askmonty.org wrote:
> At file:///home/tsk/mprog/src/5.3/
>
> ------------------------------------------------------------
> revno: 3165
> revision-id: timour(a)askmonty.org-20110822210013-egubev0wgyi00wjt
> parent: igor(a)askmonty.org-20110820040205-1suikiokqfn8s81j
> fixes bug(s): https://launchpad.net/bugs/825095
> committer: timour(a)askmonty.org
> branch nick: 5.3
> timestamp: Tue 2011-08-23 00:00:13 +0300
> message:
> Fix bug lp:825095
>
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

Re: [Maria-developers] [Commits] Rev 3166: Fixed bug lp:825018 in file:///home/tsk/mprog/src/5.3/
by Sergey Petrunya 23 Aug '11
by Sergey Petrunya 23 Aug '11
23 Aug '11
Hi Timour,
Ok to push.
On Tue, Aug 23, 2011 at 03:41:55PM +0300, timour(a)askmonty.org wrote:
> At file:///home/tsk/mprog/src/5.3/
>
> ------------------------------------------------------------
> revno: 3166
> revision-id: timour(a)askmonty.org-20110823123915-jxf9hvxq2hy03rr7
> parent: timour(a)askmonty.org-20110822210013-egubev0wgyi00wjt
> fixes bug(s): https://launchpad.net/bugs/825018
> committer: timour(a)askmonty.org
> branch nick: 5.3
> timestamp: Tue 2011-08-23 15:39:15 +0300
> message:
> Fixed bug lp:825018
>
> Analysis:
> During the first execution of the query through the stored
> procedure, the optimization phase calls
> substitute_for_best_equal_field(), which calls
> Item_in_optimizer::transform(). The latter replaces
> Item_in_subselect::left_expr with args[0] via assignment.
> In this test case args[0] is an Item_outer_ref which is
> created/deallocated for each re-execution. As a result,
> during the second execution Item_in_subselect::left_expr
> pointed to freed memory, which resulted in a crash.
>
> Solution:
> The solution is to use change_item_tree(), so that the
> origianal left expression is restored after each execution.
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

18 Aug '11
All,
The files for MariaDB 5.2.8 were uploaded to the primary mirror last
night and at this time we are waiting on only a handful of mirrors
before we're ready to go live with this release.
The release notes and changelog for this release are here:
http://kb.askmonty.org/en/mariadb-528-release-notes
http://kb.askmonty.org/en/mariadb-528-changelog
If you have a minute, please review and suggest (or make) any necessary
additions/modifications/etc...
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0

[Maria-developers] WL#236 New (by Monty): Add MVCC to UPDATE in Aria, part 1
by worklog-noreply@askmonty.org 15 Aug '11
by worklog-noreply@askmonty.org 15 Aug '11
15 Aug '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Add MVCC to UPDATE in Aria, part 1
CREATION DATE..: Mon, 15 Aug 2011, 22:17
SUPERVISOR.....: Monty
IMPLEMENTOR....: Monty
COPIES TO......:
CATEGORY.......: Maria-RawIdeaBin
TASK ID........: 236 (http://askmonty.org/worklog/?tid=236)
VERSION........: Server-5.5
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 50 (hours remain)
ORIG. ESTIMATE.: 50
PROGRESS NOTES:
DESCRIPTION:
Add MVCC to UPDATE, part 1
Do a working proof-of-concept to better be able to estimate how long
the full WL#235 task will take and to be able to estimate the initial
performance of the first version of the work.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#235 New (by Monty): Add MVCC to UPDATE and DELETE
by worklog-noreply@askmonty.org 15 Aug '11
by worklog-noreply@askmonty.org 15 Aug '11
15 Aug '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Add MVCC to UPDATE and DELETE
CREATION DATE..: Mon, 15 Aug 2011, 22:11
SUPERVISOR.....: Monty
IMPLEMENTOR....: Monty
COPIES TO......:
CATEGORY.......: Maria-RawIdeaBin
TASK ID........: 235 (http://askmonty.org/worklog/?tid=235)
VERSION........: Server-5.5
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 600 (hours remain)
ORIG. ESTIMATE.: 600
PROGRESS NOTES:
DESCRIPTION:
Add MVCC to UPDATE and DELETE, which will allow concurrent SELECT, INSERT,
UPDATE and DELETE's to be done on an ARIA table.
This is sub task for making Aria fully transactional.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

Re: [Maria-developers] [Commits] Rev 3008: MWL#234: Support for marking binlog events ...
by Michael Widenius 12 Aug '11
by Michael Widenius 12 Aug '11
12 Aug '11
Hi!
>>>>> "knielsen" == knielsen <knielsen(a)knielsen-hq.org> writes:
<cut>
We agree to change the name of replicate-ignore-do-not-replicate
variable to just 'replicate' with a default value of 1.
(Double negatives are hard, especially if you test them with !
in the code..)
knielsen> MWL#234: Support for marking binlog events to not be replicated, and for telling slaves not to replicate events with such mark
knielsen> === modified file 'client/mysqlbinlog.cc'
knielsen> --- a/client/mysqlbinlog.cc 2011-05-03 16:10:10 +0000
knielsen> +++ b/client/mysqlbinlog.cc 2011-08-11 09:38:52 +0000
knielsen> @@ -671,6 +671,31 @@ print_use_stmt(PRINT_EVENT_INFO* pinfo,
knielsen> /**
knielsen> + Print "SET do_not_replicate=..." statement when needed.
knielsen> +
knielsen> + Not all servers support this (only MariaDB from some version on). So we
knielsen> + mark the SET to only execute from the version of MariaDB that supports it,
knielsen> + and also only output it if we actually see events with the flag set, to not
knielsen> + get spurious errors on MySQL@Oracle servers of higher version that do not
knielsen> + support the flag.
knielsen> +
knielsen> + So we start out assuming @@do_not_replicate is 0, and only output a SET
knielsen> + statement when it changes.
knielsen> +*/
I have now added to MariaDB 5.3 the following new comment syntax to allow one
to do MariaDB specific executable comments:
/* !M##### */
<cut>
knielsen> @@ -927,6 +958,7 @@ Exit_status process_event(PRINT_EVENT_IN
knielsen> if (!shall_skip_database(exlq->db))
knielsen> {
knielsen> print_use_stmt(print_event_info, exlq);
knielsen> + print_do_not_replicate_statement(print_event_info, ev);
knielsen> if (fname)
knielsen> {
Move the print_do_not_replicate_statement to just before
exlq->print(result_file, print_event_info, fname);
knielsen> convert_path_to_forward_slashes(fname);
knielsen> @@ -1030,6 +1062,12 @@ Exit_status process_event(PRINT_EVENT_IN
knielsen> }
knielsen> /* FALL THROUGH */
knielsen> }
knielsen> + case INTVAR_EVENT:
knielsen> + case RAND_EVENT:
knielsen> + case USER_VAR_EVENT:
knielsen> + case XID_EVENT:
knielsen> + print_do_not_replicate_statement(print_event_info, ev);
knielsen> + /* Fall through ... */
knielsen> default:
knielsen> ev->print(result_file, print_event_info);
knielsen> }
Would it not be safer to have
print_do_not_replicate_statement(print_event_info, ev);
after the default so that we don't miss anything.
(Having a few sporadic 'do_not_replicate=#' events is better than
missing something.
knielsen> === modified file 'configure.in'
knielsen> --- a/configure.in 2011-06-11 11:28:37 +0000
knielsen> +++ b/configure.in 2011-08-11 09:38:52 +0000
knielsen> @@ -13,7 +13,7 @@ dnl When changing the major version numb
knielsen> dnl statement in mysqlbinlog::check_master_version(). You may also need
knielsen> dnl to update version.c in ndb.
knielsen> -AC_INIT([MariaDB Server], [5.2.7-MariaDB], [], [mysql])
knielsen> +AC_INIT([MariaDB Server], [5.4.0-MariaDB], [], [mysql])
5.4, that was intersting ;)
(Should probably not be part of the patch you send the customer)
knielsen> --- a/sql/mysql_priv.h 2011-07-21 10:15:09 +0000
<cut>
knielsen> @@ -2064,6 +2065,7 @@ extern my_bool opt_old_style_user_limits
knielsen> extern uint opt_crash_binlog_innodb;
knielsen> extern char *shared_memory_base_name, *mysqld_unix_port;
knielsen> extern my_bool opt_enable_shared_memory;
knielsen> +extern my_bool opt_replicate_ignore_do_not_replicate;
Not a perfect name (as we both agree upon :)
<cut>
knielsen> +++ b/sql/mysqld.cc 2011-08-11 09:38:52 +0000
knielsen> @@ -553,6 +553,8 @@ uint opt_large_page_size= 0;
knielsen> uint opt_debug_sync_timeout= 0;
knielsen> #endif /* defined(ENABLED_DEBUG_SYNC) */
knielsen> my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
knielsen> +my_bool opt_replicate_ignore_do_not_replicate;
knielsen> +
knielsen> /*
knielsen> True if there is at least one per-hour limit for some user, so we should
knielsen> check them before each query (and possibly reset counters when hour is
knielsen> @@ -6085,7 +6087,8 @@ enum options_mysqld
knielsen> OPT_IGNORE_BUILTIN_INNODB,
knielsen> OPT_BINLOG_DIRECT_NON_TRANS_UPDATE,
knielsen> OPT_DEFAULT_CHARACTER_SET_OLD,
knielsen> - OPT_MAX_LONG_DATA_SIZE
knielsen> + OPT_MAX_LONG_DATA_SIZE,
knielsen> + OPT_REPLICATE_IGNORE_DO_NOT_REPLICATE
Add the option somewhere close to other replication options.
Benefits:
- Only one row changed
- Will not conflict if MySQL add more options or if we add more
options in later MariaDB versions.
knielsen> === modified file 'sql/slave.cc'
knielsen> --- a/sql/slave.cc 2011-05-03 16:10:10 +0000
knielsen> +++ b/sql/slave.cc 2011-08-11 09:38:52 +0000
knielsen> @@ -1176,6 +1176,38 @@ when it try to get the value of TIME_ZON
knielsen> }
knielsen> }
knielsen> + /*
knielsen> + Request the master to filter away events with the @@do_not_replicate flag
knielsen> + set, if we are running with --replicate-ignore-do_not_replicate=1.
knielsen> + */
knielsen> + if (opt_replicate_ignore_do_not_replicate)
knielsen> + {
knielsen> + if (!mysql_real_query(mysql, STRING_WITH_LEN("SET do_not_replicate=1")))
knielsen> + {
knielsen> + err_code= mysql_errno(mysql);
knielsen> + if (is_network_error(err_code))
knielsen> + {
knielsen> + mi->report(ERROR_LEVEL, err_code,
knielsen> + "Setting master-side filtering of @@do_not_replicate failed "
knielsen> + "with error: %s", mysql_error(mysql));
knielsen> + goto network_err;
knielsen> + }
knielsen> + else if (err_code == ER_UNKNOWN_SYSTEM_VARIABLE)
knielsen> + {
knielsen> + /*
knielsen> + The master is older than the slave and does not support the
knielsen> + @@do_not_replicate feature.
knielsen> + This is not a problem, as such master will not generate events with
knielsen> + the @@do_not_replicate flag set in the first place. We will still
knielsen> + do slave-side filtering of such events though, to handle the (rare)
knielsen> + case of downgrading a master and receiving old events generated from
knielsen> + before the downgrade with the @@do_not_replicate flag set.
knielsen> + */
knielsen> + DBUG_PRINT("info", ("Old master does not support master-side filtering "
knielsen> + "of @@do_not_replicate events."));
knielsen> + }
knielsen> + }
knielsen> + }
Wouldn't it be better to do:
if (err_code == ER_UNKNOWN_SYSTEM_VARIABLE)
...
else
...
Now you don't print an error if there was some other unknown problem
with setting the variable.
What other errors can we get other than ER_UNKNOWN_SYSTEM_VARIABLE
that would allow us to continue ?
knielsen> err:
knielsen> if (errmsg)
knielsen> {
knielsen> @@ -2114,6 +2146,8 @@ int apply_event_and_update_pos(Log_event
knielsen> thd->lex->current_select= 0;
knielsen> if (!ev->when)
knielsen> ev->when= my_time(0);
knielsen> + thd->options= (thd->options & ~OPTION_DO_NOT_REPLICATE) |
knielsen> + (ev->flags & LOG_EVENT_DO_NOT_REPLICATE_F ? OPTION_DO_NOT_REPLICATE : 0);
knielsen> ev->thd = thd; // because up to this point, ev->thd == 0
knielsen> int reason= ev->shall_skip(rli);
knielsen> @@ -3582,6 +3616,7 @@ static int queue_event(Master_info* mi,c
knielsen> {
knielsen> int error= 0;
knielsen> ulong inc_pos;
knielsen> + ulong event_pos;
knielsen> Relay_log_info *rli= &mi->rli;
knielsen> pthread_mutex_t *log_lock= rli->relay_log.get_log_lock();
knielsen> DBUG_ENTER("queue_event");
knielsen> @@ -3667,6 +3702,23 @@ static int queue_event(Master_info* mi,c
knielsen> }
knielsen> /*
knielsen> + If we filter events master-side (eg. @@do_not_replicate), we will see holes
knielsen> + in the event positions from the master. If we see such a hole, adjust
knielsen> + mi->master_log_pos accordingly so we maintain the correct position (for
knielsen> + reconnect, MASTER_POS_WAIT(), etc.)
knielsen> + */
knielsen> + if (inc_pos > 0 &&
knielsen> + event_len >= LOG_POS_OFFSET+4 &&
knielsen> + (event_pos= uint4korr(buf+LOG_POS_OFFSET)) > mi->master_log_pos + inc_pos)
knielsen> + {
knielsen> + inc_pos= event_pos - mi->master_log_pos;
knielsen> + DBUG_PRINT("info", ("Adjust master_log_pos %lu->%lu to account for "
knielsen> + "master-side filtering",
knielsen> + (unsigned long)(mi->master_log_pos + inc_pos),
knielsen> + event_pos));
knielsen> + }
<irc discussion about>
is 'inc_pos= event_pos - mi->master_log_pos' really secure and should
we add
DBUG_ASSERT(mi->master_log_pos == uint4korr(buf+LOG_POS_OFFSET) ||
inc_len == 0)
after
mi->master_log_pos+= inc_pos;
to ensure the correctness.
For the moment we decided to not do this.
<cut>
knielsen> +++ b/sql/sql_repl.cc 2011-08-11 09:38:52 +0000
knielsen> @@ -338,6 +338,41 @@ Increase max_allowed_packet on master";
knielsen> /*
knielsen> + Helper function for mysql_binlog_send() to write an event down the slave
knielsen> + connection.
knielsen> +
knielsen> + Returns NULL on success, error message string on error.
knielsen> +*/
knielsen> +static const char *
knielsen> +send_event_to_slave(THD *thd, NET *net, String* const packet)
knielsen> +{
knielsen> + thd_proc_info(thd, "Sending binlog event to slave");
knielsen> +
knielsen> + /*
knielsen> + Skip events with the @@do_not_replicate flag set, if slave requested
knielsen> + skipping of such events.
knielsen> + */
knielsen> + if (thd->options & OPTION_DO_NOT_REPLICATE)
knielsen> + {
knielsen> + uint16 flags= uint2korr(&((*packet)[FLAGS_OFFSET+1]));
Please add a comment to explain the +1 above
<cut>
Looks good!
Regards,
Monty
2
1
His attachment didn't make it thru, but here are some links:
Hello Colin,
you can download it from my server, that's the easiest way:
http://www.qa-navigation.com/Downloads/QANavBSmp.zip
and
http://www.qa-navigation.com/Downloads/QANavXDBTst.zip
it's less than 400 KB, all in all.
Begin forwarded message:
> From: Ronald Grindle <ronald(a)grindle.de>
> Date: 9 August 2011 17:07:25 GMT+08:00
> To: maria-developers(a)lists.launchpad.com, community(a)askmonty.org
> Subject: MariaDB contribution offer
>
> Dear Sir and Madam,
>
> I am writing you to make you an contribution offer to your Open Source Project MariaDB.
>
> I have developed a driver, that turns MySQL into an XML Database. Following this mail I am sending you the Java implementation of what I called XMLDB.
>
> XMLDB is a set of classes, that provides an interface to the user, that has the appearance of an XML dataset object, while providing him the advantages of a database, i.e. search-ability of data by key values, extraction of subsets of data, insertion of subsets of data etc. I used it in my own programs to create a generic database, where the data base scheme does not need to be changed every time a new data entity is added to the data set and, at the same time, takes advantage of the simplified transportation and handling of data that XML objects provide. It has proven its usability under the circumstances of industrial use.
>
> The appendix contains the zipped package QANavBSmp.zip that contains all Java classes, the built jar, the Java-Docs and the SQL scripts for setting up the DB scheme. The XMLDB requires a UID server to run, a small server, that generates universally unique ids. The UID server is part of the jar, the zipped package contains scripts to start the server.
>
> Along with the package QANavBSmp.zip comes a another package QANavXDBTst.zip. It contains a short test program that demonstrates the usage of XMLDB and some of its functions.
>
> I am willing to make all of this public domain, I just have not added the according statements to the packages yet. If you are interested in the package I am willing to migrate it to use MaraiDB.
>
> As already said, the packages will follow this mail, in case the mail is rejected by your firewall or your spam filter due to its content. The mail is labeled “MariaDB contribution offer – packages”.
>
> If the packages do not reach you please contact me, so we can find out how to make the transfer work.
>
> I hope you find this offer interesting, I am looking to hearing from you what you think about it.
>
> Yours sincerely
>
> Ronald D. Grindle
>
> E.Mail: ronald(a)grindle.de
> Tel: +49 (0)89-43573611
> Mobil: +49 (0)177-3775162
--
Colin Charles, http://bytebot.net/blog/ | twitter: @bytebot | skype: colincharles
MariaDB: Community developed. Feature enhanced. Backward compatible.
Download it at: http://www.mariadb.org/
Open MariaDB/MySQL documentation at the Knowledgebase: http://kb.askmonty.org/
1
0

[Maria-developers] Performance speed-up for DBT3 query set with MariaDB 5.3.0
by Igor Babaev 07 Aug '11
by Igor Babaev 07 Aug '11
07 Aug '11
Hi,
Here are the results for DBT3 query set I've got on my laptop with
MariaDB 5.3.0 installed.
[ Dell Latitude E6510: 4-cores with multithreading (8 threads in total)
Memory: 8GB, SSD,
SuSE 11.3 ]
DBT3 factor 10 (60M rows in lineitem) built for InnoDB.
Mysqld was launched with the following parameters:
--innodb-buffer-pool-size=1G
--innodb-additional-mem-pool-size=20M
--innodb-log-file-size=256M
--innodb-file-per-tab
--innodb_file_format=barracuda
Each query was executed
1. with default optimization options (as they are set in mysql-5.1/5.5)
2. with the best optimization options found for the query
I would like to attract your attention to the fact that hash join can
really compete with BKA join for some queries (see Q9, Q12, Q13).
Also: EXPLAIN for Q7, Q8, Q9 now is instantaneous.
Q18 practilly cannot be executed without optimizations.
My estimation tells me that it would take ~50 years to execute it unless
the in_to_exists transformation is optimized for group by queries (then
it will take only ~80 hours).
See how effectively optimize_join_buffer_size can be used for Q9.
(similar join buffer optimization could be applied for other queries,
I just did not do it).
Enjoy the numbers below.
Regards,
Igor.
====================================================
time in seconds time in seconds ratio
w/o optimizations with optimizations
Q1 172 - [172] 1.0
Q2 112 31 3.61
Q3 189 197 0.96
Q4 417 103 4.05
Q5 416 137 3.04
Q6 119 - [119] 1.0
Q7 558 221 2.52
Q8 1023 338 3.02
Q9 2399 218 (265) 11.00 (9.05)
Q10 542 139 3.90
Q11 33 25 1.32
Q12 308 247 1.25
Q13 446 133 3.35
Q14 302 92 3.28
Q15 1334 164 8.13
Q16 45 10 4.5
Q17 46 51 0.90
Q18 [*] 252 (218) -
Q19 76 63 1.21
Q20 463 337 1.37
Q21 297 304 0.98
Q22 11.02 10.72 1.03
====================================================
optimization settings used
Q1
[none]
Q2
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*64;
set join_cache_level=6;
Q3
set join_buffer_space_limit=1024*1024*256;
set join_buffer_size=1024*1024*32;
set optimizer_switch='mrr=on';
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q4
set optimizer_switch='mrr=on';
set mrr_buffer_size=1024*1024*8;
Q5
set optimizer_switch='mrr=on';
set mrr_buffer_size=1024*1024*8;
set join_buffer_space_limit=1024*1024*1024;
set join_buffer_size=1024*1024*32;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q6
[none]
Q7
set optimizer_switch='derived_merge=on';
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*1024;
set join_buffer_size=1024*1024*64;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q8
set optimizer_switch='derived_merge=on';
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*1024;
set join_buffer_size=1024*1024*128;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q9
set optimizer_switch='derived_merge=on';
set optimizer_switch='optimize_join_buffer_size=on';
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*128;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
(
set optimizer_switch='derived_merge=on';
set optimizer_switch='optimize_join_buffer_size=on';
set join_buffer_space_limit=1024*1024*32;
set join_buffer_size=1024*1024*24;
set join_cache_level=4;
)
Q10
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*128;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q11
set optimizer_switch='mrr=on';
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*8;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q12
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*512;
set join_cache_level=4;
Q13
set tmp_table_size=1024*1024*32;
set max_heap_table_size=1924*1024*32;
set optimizer_switch='outer_join_with_cache=on';
set join_buffer_space_limit=1024*1024*16;
set join_buffer_size=1024*1024*8;
set join_cache_level=4;
Q14
set optimizer_switch='mrr=on';
set mrr_buffer_size=1024*1024*8;
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*32;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q15
set tmp_table_size=1024*1024*32;
set max_heap_table_size=1924*1024*32;
set optimizer_switch='derived_with_keys=on';
set optimizer_switch='mrr=on';
set mrr_buffer_size=1024*1024*32;
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*16;
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q16
set optimizer_switch='materialization=on';
Q17
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*16;
set optimizer_switch='mrr=on';
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q18
set tmp_table_size=1024*1024*32;
set max_heap_table_size=1024*1024*32;
set optimizer_switch='materialization=on';
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*128;
set optimizer_switch='mrr=on';
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
(
set tmp_table_size=1024*1024*32;
set max_heap_table_size=1024*1024*32;
set optimizer_switch='materialization=on';
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*128;
set optimizer_switch='mrr=on';
set join_cache_level=4;
)
Q19
set join_buffer_space_limit=1024*1024*128;
set join_buffer_size=1024*1024*16;
set optimizer_switch='mrr=on';
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q20
set optimizer_switch='semijoin=on';
set optimizer_switch='materialization=on';
set optimizer_switch='in_to_exists=off';
Q21
set join_buffer_space_limit=1024*1024*512;
set join_buffer_size=1024*1024*64;
set optimizer_switch='mrr=on';
set optimizer_switch='mrr_sort_keys=on';
set join_cache_level=6;
Q22
set optimizer_switch='derived_merge=on';
1
0
When I try to start maria, Ubuntu 11.04, a local install mariadb 5.2.7
sudo /usr/bin/mysqld_safe I get
110801 22:40:54 mysqld_safe Logging to syslog.
110801 22:40:54 mysqld_safe Starting mysqld daemon with databases
from /var/lib/mysql
110801 22:40:54 mysqld_safe mysqld from pid
file /var/run/mysqld/mysqld.pid ended
If I try
sudo /etc/init.d/mysql start I get
* Starting MariaDB database server mysqld
[fail]
sudo /usr/bin/mysqld_safe -h localhost or 127.0.0.1 with the same
results as before.
I have been researching this problem and have found nothing definite
about the problem of how to solve it. I have tried a complete reinstall
from the repository and it has not helped.
I have verified my.conf appears to be correct based on information I
have found on the web.
I have enclosed the output from mysqlbug:
GNU nano 2.2.6 File: /tmp/mysqlbug-3129/mysqlbug
C++ compiler: g++-4.5.real (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
Environment:
System: Linux planas-pingy-1104 2.6.38-9-generic #43-Ubuntu SMP Thu Apr
28 15:2$
Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gcc /usr/bin/cc
GCC: Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/lto-wr$
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.2-8ub$
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
Compilation info (call): CC='gcc -static-libgcc' CFLAGS='-O2
-fno-omit-frame-p$
Compilation info (used): CC='gcc -static-libgcc' CFLAGS=' -O2
-fno-omit-frame-$
Configure command: ../configure '--build=x86_64-linux-gnu'
'--host=x86_64-linu$
--
Jay Lozier
jslozier(a)gmail.com
3
2

Re: [Maria-developers] [Commits] Rev 3138: Early check of subquery cache hit rate added to limit its performance impact in the worst case. in file:///home/bell/maria/bzr/work-maria-5.3-scache_impact/
by Oleksandr Byelkin 01 Aug '11
by Oleksandr Byelkin 01 Aug '11
01 Aug '11
Hi!
01.08.2011 10:12, Timour Katchaounov пишет:
> Sanja,
>
> Could you explain why these new constants are defines,
> and not declared const variables:
>
> === modified file 'sql/sql_expression_cache.cc'
> --- a/sql/sql_expression_cache.cc 2011-07-28 14:10:29 +0000
> +++ b/sql/sql_expression_cache.cc 2011-08-01 06:34:55 +0000
> @@ -26,6 +26,11 @@
> hit_rate = hit / (miss + hit);
> */
> #define EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE 0.2
> +/**
> + Number of cache miss to check hit ratio (maximum cache performance
> + impact in the case when the cache is not applicable)
> +*/
> +#define EXPCACHE_EARLY_CHECK 200
>
>
> All of these are potentially possible to tune, why make them
> compile-time defines?
Heh, that is what I wanted to discuss. On one hand too many parameters
is bad on other hand too simple is not good also...
[skip]
1
0

[Maria-developers] WL#234 New (by Knielsen): @@binlog_do_not_replicate filtering of binlog events
by worklog-noreply@askmonty.org 01 Aug '11
by worklog-noreply@askmonty.org 01 Aug '11
01 Aug '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: @@binlog_do_not_replicate filtering of binlog events
CREATION DATE..: Mon, 01 Aug 2011, 09:40
SUPERVISOR.....: Monty
IMPLEMENTOR....: Knielsen
COPIES TO......:
CATEGORY.......: Server-Sprint
TASK ID........: 234 (http://askmonty.org/worklog/?tid=234)
VERSION........: Server-9.x
STATUS.........: Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
This worklog is about introducing a new session variable
@@binlog_do_not_replicate.
When this variable is set, an associated flag bit is set in events logged into
the binlog.
The first stage of this worklog is to introduce an option
--slave-ignore-do-not-replicate-events. When this is set, the slave will skip
any events received with the binlog-do-not-replicate bit set.
The second stage is to do this filtering on the master. When
--slave-ignore-do-not-replicate-events is set on the slave, the master will
avoid sending these events to that slave at all, saving on bandwidth but
otherwise working the same way as stage 1.
The motivation for this worklog is to allow an application to do changes that
are replicated in a way external to the internal MySQL replication, but which
still keeps the events in the binlog for debugging/point-in-time recovery, or
for standard replication to other servers.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0
Hi Serg,
Can you review below patch? (sorry for no commit mail, I forgot to configure
outgoing mail on my new laptop before committing).
I was for a long time annoyed that mtr takes 20 seconds starting up before it
starts running the first test. So being bored one evening I ran a Perl
profiler on the code and fixed the culprit.
(BTW, I haven't forgotten your suggestion to change include/long_test.inc
information to be in a separate file instead; I just haven't gotten around to
it yet.)
- Kristian.
2
2

Re: [Maria-developers] [Commits] Rev 3135: Subquery cache going on disk management fix: Do not go on disk if hit rate is not good. in file:///home/bell/maria/bzr/work-maria-5.3-subquerycachedisk/
by Sergey Petrunya 28 Jul '11
by Sergey Petrunya 28 Jul '11
28 Jul '11
Hi Sanja,
Ok to push.
On Thu, Jul 28, 2011 at 05:10:29PM +0300, sanja(a)askmonty.org wrote:
> At file:///home/bell/maria/bzr/work-maria-5.3-subquerycachedisk/
>
> ------------------------------------------------------------
> revno: 3135
> revision-id: sanja(a)askmonty.org-20110728141029-adkbj1vedh86m3uc
> parent: igor(a)askmonty.org-20110723064728-j2sgq39rp528eaol
> committer: sanja(a)askmonty.org
> branch nick: work-maria-5.3-subquerycachedisk
> timestamp: Thu 2011-07-28 17:10:29 +0300
> message:
> Subquery cache going on disk management fix: Do not go on disk if hit rate is not good.
<skip>
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

[Maria-developers] Is it time to change 5.3 bugs status from Fix Committed to Fix Released?
by Sergey Petrunya 28 Jul '11
by Sergey Petrunya 28 Jul '11
28 Jul '11
Hello,
The bug database has 197 bugs with status="Fix committed" and
target_milestone=5.3.
Since we've released 5.3, is it time to change status on these bugs to "Fix
released"?
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

Re: [Maria-developers] [Commits] Rev 3135: Subquery cache going on disk management fix: Do not go on disk if hit/miss ration less than 2. in file:///home/bell/maria/bzr/work-maria-5.3-subquerycachedisk/
by Sergey Petrunya 28 Jul '11
by Sergey Petrunya 28 Jul '11
28 Jul '11
Hi Sanja
A summary of our discussion on irc/skype:
Please change EXPCACHE_DISK_HITMISS_RATIO to be a "hit ratio", i.e "fraction
of accesses that result in cache hits", as that's this is the most common
number people use when they think about cache performance.
Please change one limit into two:
1. A very poor hit ratio that will cause cache to stop working altogether
(like the below patch does)
2. A moderately poor ratio that will cause the in-memory table to be emptied
(instead of being converted to on-disk table).
Suggested names: EXPCACHE_MIN_HIT_RATIO_FOR_DISK_TABLE,
EXPCACHE_MIN_HIT_RATIO_FOR_MEM_TABLE. Please supply both definitions with
comments about their meaning.
On Thu, Jul 28, 2011 at 01:18:56PM +0300, sanja(a)askmonty.org wrote:
> === modified file 'sql/sql_expression_cache.cc'
> --- a/sql/sql_expression_cache.cc 2011-07-19 20:19:10 +0000
> +++ b/sql/sql_expression_cache.cc 2011-07-28 10:18:55 +0000
> @@ -16,6 +16,8 @@
> #include "mysql_priv.h"
> #include "sql_select.h"
>
> +#define EXPCACHE_DISK_HITMISS_RATIO 2
> /*
> Expression cache is used only for caching subqueries now, so its statistic
> variables we call subquery_cache*.
> @@ -26,7 +28,7 @@ Expression_cache_tmptable::Expression_ca
> List<Item> &dependants,
> Item *value)
> :cache_table(NULL), table_thd(thd), items(dependants), val(value),
> - inited (0)
> + hit(0), miss(0), inited (0)
> {
> DBUG_ENTER("Expression_cache_tmptable::Expression_cache_tmptable");
> DBUG_VOID_RETURN;
> @@ -180,10 +182,12 @@ Expression_cache::result Expression_cach
> if (res)
> {
> subquery_cache_miss++;
> + miss++;
> DBUG_RETURN(MISS);
> }
>
> subquery_cache_hit++;
> + hit++;
> *value= cached_result;
> DBUG_RETURN(Expression_cache::HIT);
> }
> @@ -224,12 +228,26 @@ my_bool Expression_cache_tmptable::put_v
> if ((error= cache_table->file->ha_write_tmp_row(cache_table->record[0])))
> {
> /* create_myisam_from_heap will generate error if needed */
> - if (cache_table->file->is_fatal_error(error, HA_CHECK_DUP) &&
> - create_internal_tmp_table_from_heap(table_thd, cache_table,
> - cache_table_param.start_recinfo,
> - &cache_table_param.recinfo,
> - error, 1))
> + if (cache_table->file->is_fatal_error(error, HA_CHECK_DUP))
> goto err;
> + else
> + {
> + if ((hit/miss) < EXPCACHE_DISK_HITMISS_RATIO)
> + {
> + DBUG_PRINT("info", ("hit/miss ratio is not so good to go to disk"));
> + free_tmp_table(table_thd, cache_table);
> + cache_table= NULL;
> + DBUG_RETURN(FALSE);
> + }
> + else
> + {
> + if (create_internal_tmp_table_from_heap(table_thd, cache_table,
> + cache_table_param.start_recinfo,
> + &cache_table_param.recinfo,
> + error, 1))
> + goto err;
> + }
> + }
> }
> cache_table->status= 0; /* cache_table->record contains an existed record */
> ref.has_record= TRUE; /* the same as above */
>
> === modified file 'sql/sql_expression_cache.h'
> --- a/sql/sql_expression_cache.h 2011-07-19 20:19:10 +0000
> +++ b/sql/sql_expression_cache.h 2011-07-28 10:18:55 +0000
> @@ -85,6 +85,8 @@ private:
> List<Item> &items;
> /* Value Item example */
> Item *val;
> + /* hit/miss counters */
> + uint hit, miss;
Please change to be ulong (same type as subquery_cache_hit/miss)
> /* Set on if the object has been succesfully initialized with init() */
> bool inited;
> };
>
--
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

[Maria-developers] WL#233 New (by Aag): Partial Range Indx
by worklog-noreply@askmonty.org 28 Jul '11
by worklog-noreply@askmonty.org 28 Jul '11
28 Jul '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Partial Range Indx
CREATION DATE..: Thu, 28 Jul 2011, 10:44
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Maria-RawIdeaBin
TASK ID........: 233 (http://askmonty.org/worklog/?tid=233)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
A way to make Indices significantly useful in some usage scenarios:
Scoping the index to a specific range of values. This can be useful if some
queries are only performed on a specific subset of the rows.
Example: A process that implements a state machine for each row. All finished
tasks have the state -1. To lookup the next task to perform only states > -1
have to be considered. Creating an index for the criteria to find the next task
quickly would also index all the finished tasks. Which can make index creation
expensive and waste several Gigabytes of diskspace (assuming millions of entries
in the DB).
While partitioning promises similar effects (a second axis for query
optimizations) it is rendered utterly useless by its restriction that the
partioning index must occur in *all* primary and unique keys which means one
cannot define a large natural key via unique and a small artificial ID as
primary key and then partition by an unrelated aspect (such as the state in my
example).
Range-restricted indices would allow similar optimizations: specify a
range-restricted column as first column and then add the remaining criteria as
other columns.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#232 New (by ColinCharles): Add missing SHUTDOWN statement
by worklog-noreply@askmonty.org 28 Jul '11
by worklog-noreply@askmonty.org 28 Jul '11
28 Jul '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Add missing SHUTDOWN statement
CREATION DATE..: Thu, 28 Jul 2011, 03:26
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......: Monty
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 232 (http://askmonty.org/worklog/?tid=232)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
>From http://www.jebriggs.com/blog/2011/07/mysqls-missing-shutdown-statement/
Databases are more easily managed if all operations and logging are available to
DBAs and scripts at the SQL client command line.
So an additional improvement would be to add a SQL command like Oracles SHUTDOWN.
See the blog post for a comparison table
Reference from Oracle: http://www.dba-oracle.com/concepts/shutdown_commands.htm
http://dev.mysql.com/doc/refman/5.5/en/mysql-shutdown.html
http://dev.mysql.com/doc/refman/5.5/en/server-shutdown.html
http://dev.mysql.com/doc/refman/5.5/en/kill.html
http://dev.mysql.com/doc/refman/5.5/en/stop-slave.html
USD$100 committed from James Briggs at the MariaDB BoF at OSCON 2011
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#231 New (by Monty): Faster UNIQUE key generation with ALTER TABLE
by worklog-noreply@askmonty.org 27 Jul '11
by worklog-noreply@askmonty.org 27 Jul '11
27 Jul '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Faster UNIQUE key generation with ALTER TABLE
CREATION DATE..: Wed, 27 Jul 2011, 16:49
SUPERVISOR.....: Monty
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 231 (http://askmonty.org/worklog/?tid=231)
VERSION........: Server-5.5
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 30 (hours remain)
ORIG. ESTIMATE.: 30
PROGRESS NOTES:
DESCRIPTION:
Faster UNIQUE key generation with ALTER TABLE
Generate also unique keys by sorting (as we do with non unique keys) to speed up
alter tables with unique keys significantly.
This worklog is for doing this for MyISAM and Aria tables.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

21 Jul '11
Hello,
The below really should be in documentation, but for now, I'm posting it here:
Semi-join processing with Duplicate Elimination
===============================================
There are three cases:
Semi-join next to outer join
----------------------------
ot1 left join (ot10, ot11) semi-join (it1, it2)
interesting possible join orders:
ot1 {ot10 ot11} it1 it2 <-- here we have just a "tail" so no problem.
it1 ot1 {ot10, ot11} it2
Here the range fully covers the inner join with all its
NULL-complemented record generation, etc. We need to take
care about
- NULL rowids are provided for NULL-complemented rows
- being able to jump over all this when doing weedout (can we
have a problem with some OJ's match flag not being reset?)
it1 ot1 it2 {ot10 ot11}
| |
+------------------+
dups-w range
This is a special case of the previous case. Need to
- check dups-w for NULL-complemented record.
(in case of nested outer joins: check for all NULL-complemented records
generated at this point? well they all call
evaluate_null_complemented_record, do they?)
- check if this works with Not-exists optimization.
it1 ot1 it2 {ot10 ot11}
| |
+------------+
dups-w range
This case is the most interesting. The question is: should we first
check dups-w, or care about outer joins?
- dups-w check can be moved to the right.
if we take a record combination of
{ot1.row it2.row ot10.row}
we must not discard it, because we'll need to know if this record
combination extends to
{ot1.row, it2.row ot10.row ot11.row }
If it does, outer join will not have NULL-complemented record, otherwise it
will.
this means: no dups-w checks inside outer joins. Move them to the right
until we've got the table that's last for all inner joins we're in.
Outer join inside semi-join
---------------------------
ot1 semi join (it1 left join (iit2, iit3))
Possible join orders:
1) ot1 it1 {iit2, iit3}
2) it1 ot1 {iit2, iit3}
3) it1 {iit2, iit3} ot1
4) ot1 {iit2, iit3} it1
#1 and #2 have an "outside" prefix followed by "tail" of SJ-inner OJ-inner
tables. For iit3, we must first form a record for which both parts of
WHERE and ON have been checked (or the record could be NULL-complemented)
for #3 and #3, dups-w check is done after OJ processing.
Semi-join inside outer join
---------------------------
- Not possible in current scheme.
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

[Maria-developers] WL#230 New (by Mitchh): Extended Aggregates Functionality
by worklog-noreply@askmonty.org 19 Jul '11
by worklog-noreply@askmonty.org 19 Jul '11
19 Jul '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Extended Aggregates Functionality
CREATION DATE..: Tue, 19 Jul 2011, 13:43
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 230 (http://askmonty.org/worklog/?tid=230)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
This idea is really an extension to SQL. It was implemented at my suggestion for
the SQL like EPL (Event Processing language) over at Esper project
(http://esper.codehaus.org)
Basically the idea is to extend all aggregates (count(), avg() etc) so that they
can accept an optional boolean filter expression as a second argument.
Example use case:
select count(*, color='black'), count(*) as percentBlack from Marbles;
This is more expressive and more efficient than using subselects.
original suggestion can be found at
http://old.nabble.com/Feature-suggestion--filtering-inside-aggregates-to319…
Mitch
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

Re: [Maria-developers] [Commits] Rev 3119: Fixed LP BUG#800696. in file:///home/bell/maria/bzr/work-maria-5.3-lpb800696/
by Timour Katchaounov 19 Jul '11
by Timour Katchaounov 19 Jul '11
19 Jul '11
Sanja,
These are some general notes about the patch:
- Change Item::add_if_unique() to a method of base_list, and the List
template class.
- There is no need in subselect_engine::nest_level() because a subquery
predicate is always at the same nest level irrespective of the chosen
engine. The class Item_subselect has a member Item_subselect::unit,
which should be sufficient to check the nest_level of the subquery.
IMO this will simplify the patch visibly. I am pretty sure that if
you add an assert, you will see that any engine will return the same
nest_level as Item_subselect::unit->first_select().
- The commit comment is hard to understand.
- Please first describe what was the problem, why there was a crash,
and what is the generic problem with the current implementation.
- Then describe what is the solution.
- Fix the English of the commit comment.
There are few more comments below marked with "timour:".
Timour
=== modified file 'mysql-test/r/subselect_cache.result'
--- a/mysql-test/r/subselect_cache.result 2011-02-03 15:00:28 +0000
+++ b/mysql-test/r/subselect_cache.result 2011-07-19 09:15:34 +0000
@@ -3272,6 +3272,7 @@ FROM t2 ) AND table1 .`col_varchar_key`
col_varchar_nokey
drop table t1,t2;
set @@optimizer_switch= default;
+set optimizer_switch='subquery_cache=on';
# LP BUG#615378 (incorrect NULL result returning in Item_cache)
CREATE TABLE `t1` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
@@ -3310,3 +3311,25 @@ GROUP BY field3
HAVING (field3 <= 'h' AND field2 != 4) ;
field2 field3
drop tables t1, t2, t3;
+#
+# Aggregate function in parameters test
+#
+CREATE TABLE t1 ( a INT, b INT, c INT, KEY (a, b));
+INSERT INTO t1 VALUES
+( 1, 1, 1 ),
+( 1, 2, 2 ),
+( 1, 3, 3 ),
+( 1, 4, 6 ),
+( 1, 5, 5 ),
+( 1, 9, 13 ),
+( 2, 1, 6 ),
+( 2, 2, 7 ),
+( 2, 3, 8 );
+SELECT a, AVG(t1.b),
+(SELECT t11.c FROM t1 t11 WHERE t11.a = t1.a AND t11.b = AVG(t1.b)) AS t11c
+FROM t1 GROUP BY a;
+a AVG(t1.b) t11c
+1 4.0000 6
+2 2.0000 7
+DROP TABLE t1;
+set @@optimizer_switch= default;
=== modified file 'mysql-test/r/subselect_scache.result'
--- a/mysql-test/r/subselect_scache.result 2011-07-15 08:36:36 +0000
+++ b/mysql-test/r/subselect_scache.result 2011-07-19 09:15:34 +0000
@@ -232,7 +232,7 @@ id select_type table type possible_keys
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
-Note 1003 select `test`.`t4`.`b` AS `b`,(select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) from `test`.`t2`) AS `(select
avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
+Note 1003 select `test`.`t4`.`b` AS `b`,<expr_cache><`test`.`t4`.`a`>((select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) from
`test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
select * from t3 where exists (select * from t2 where t2.b=t3.a);
a
7
@@ -2835,7 +2835,7 @@ id select_type table type possible_keys
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
Warnings:
-Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select
`test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and
trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and
trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
+Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select
`test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and
trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and
trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
@@ -2847,7 +2847,7 @@ id select_type table type possible_keys
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
Warnings:
-Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select
`test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or
isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and
trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
+Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select
`test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or
isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and
trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
DROP TABLE t1,t2;
CREATE TABLE t1 (a char(5), b char(5));
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
=== modified file 'mysql-test/t/subselect_cache.test'
--- a/mysql-test/t/subselect_cache.test 2010-11-28 13:02:12 +0000
+++ b/mysql-test/t/subselect_cache.test 2011-07-19 09:15:34 +0000
@@ -1567,6 +1567,7 @@ FROM t2 ) AND table1 .`col_varchar_key`
drop table t1,t2;
set @@optimizer_switch= default;
+set optimizer_switch='subquery_cache=on';
#
--echo # LP BUG#615378 (incorrect NULL result returning in Item_cache)
#
@@ -1614,3 +1615,6 @@ GROUP BY field3
HAVING (field3 <= 'h' AND field2 != 4) ;
--enable_warnings
drop tables t1, t2, t3;
+
+--echo #
+--echo # Aggregate function in parameters test
timour:
Change the above to:
"Test aggregate functions as parameters to ... (to what?)"
+--echo #
+
+CREATE TABLE t1 ( a INT, b INT, c INT, KEY (a, b));
+
+INSERT INTO t1 VALUES
+ ( 1, 1, 1 ),
+ ( 1, 2, 2 ),
+ ( 1, 3, 3 ),
+ ( 1, 4, 6 ),
+ ( 1, 5, 5 ),
+ ( 1, 9, 13 ),
+
+ ( 2, 1, 6 ),
+ ( 2, 2, 7 ),
+ ( 2, 3, 8 );
+
+SELECT a, AVG(t1.b),
+(SELECT t11.c FROM t1 t11 WHERE t11.a = t1.a AND t11.b = AVG(t1.b)) AS t11c
+FROM t1 GROUP BY a;
+
+DROP TABLE t1;
+
+
+set @@optimizer_switch= default;
=== modified file 'sql/item.cc'
--- a/sql/item.cc 2011-07-09 09:47:41 +0000
+++ b/sql/item.cc 2011-07-19 09:15:34 +0000
@@ -651,14 +651,14 @@ Item* Item::transform(Item_transformer t
A pointer to created wrapper item if successful, NULL - otherwise
*/
-Item* Item::set_expr_cache(THD *thd, List<Item *> &depends_on)
+Item* Item::set_expr_cache(THD *thd)
{
DBUG_ENTER("Item::set_expr_cache");
Item_cache_wrapper *wrapper;
if ((wrapper= new Item_cache_wrapper(this)) &&
!wrapper->fix_fields(thd, (Item**)&wrapper))
{
- if (wrapper->set_cache(thd, depends_on))
+ if (wrapper->set_cache(thd))
DBUG_RETURN(NULL);
DBUG_RETURN(wrapper);
}
@@ -666,6 +666,26 @@ Item* Item::set_expr_cache(THD *thd, Lis
}
+/**
+ Add this item to the items list if there is no such item in the list
+
+ @param list The list of the Items to add to
+*/
+
timour:
This method implements a set, which is a very generic functionality. Please
change this into a method of base_list and List template class.
+void Item::add_if_unique(List<Item> &list)
+{
+ List_iterator_fast<Item> li(list);
+ Item *item;
+ while ((item= li++))
+ {
+ if (eq(item, FALSE))
+ return;
+ }
+ list.push_back(this);
+ return;
+}
+
+
Item_ident::Item_ident(Name_resolution_context *context_arg,
const char *db_name_arg,const char *table_name_arg,
const char *field_name_arg)
@@ -742,6 +762,15 @@ bool Item_ident::remove_dependence_proce
}
+bool Item_ident::collect_outer_ref_processor(uchar *param)
+{
+ Collect_deps_prm *prm= (Collect_deps_prm *)param;
+ if (depended_from && depended_from->nest_level < prm->nest_level)
+ add_if_unique(*prm->parameters);
+ return FALSE;
+}
+
+
/**
Store the pointer to this item field into a list if not already there.
@@ -4357,9 +4386,6 @@ Item_field::fix_outer_field(THD *thd, Fi
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
(Item_ident*) (*reference) :
0));
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
/*
A reference to a view field had been found and we
substituted it instead of this Item (find_field_in_tables
@@ -4460,9 +4486,6 @@ Item_field::fix_outer_field(THD *thd, Fi
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex, rf,
rf);
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
return 0;
}
@@ -4471,9 +4494,6 @@ Item_field::fix_outer_field(THD *thd, Fi
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex,
this, (Item_ident*)*reference);
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
if (last_checked_context->select_lex->having_fix_field)
{
Item_ref *rf;
@@ -6304,9 +6324,6 @@ bool Item_ref::fix_fields(THD *thd, Item
refer_type == FIELD_ITEM) ?
(Item_ident*) (*reference) :
0));
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
/*
view reference found, we substituted it instead of this
Item, so can quit
@@ -6357,9 +6374,6 @@ bool Item_ref::fix_fields(THD *thd, Item
thd->change_item_tree(reference, fld);
mark_as_dependent(thd, last_checked_context->select_lex,
thd->lex->current_select, fld, fld);
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
/*
A reference is resolved to a nest level that's outer or the same as
the nest level of the enclosing set function : adjust the value of
@@ -6383,9 +6397,6 @@ bool Item_ref::fix_fields(THD *thd, Item
DBUG_ASSERT(*ref && (*ref)->fixed);
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex, this, this);
- context->select_lex->
- register_dependency_item(last_checked_context->select_lex,
- reference);
/*
A reference is resolved to a nest level that's outer or the same as
the nest level of the enclosing set function : adjust the value of
@@ -6400,12 +6411,6 @@ bool Item_ref::fix_fields(THD *thd, Item
}
else if (ref_type() != VIEW_REF)
{
- if (depended_from && reference)
- {
- DBUG_ASSERT(context->select_lex != get_depended_from());
- context->select_lex->register_dependency_item(get_depended_from(),
- reference);
- }
/*
It could be that we're referring to something that's in ancestor selects.
We must make an appropriate mark_as_dependent() call for each such
@@ -6901,6 +6906,7 @@ Item_cache_wrapper::~Item_cache_wrapper(
}
+
Item_cache_wrapper::Item_cache_wrapper(Item *item_arg)
:orig_item(item_arg), expr_cache(NULL), expr_value(NULL)
{
@@ -6914,6 +6920,7 @@ Item_cache_wrapper::Item_cache_wrapper(I
unsigned_flag= orig_item->unsigned_flag;
name= item_arg->name;
name_length= item_arg->name_length;
+ with_subselect= orig_item->with_subselect;
if ((expr_value= Item_cache::get_cache(orig_item)))
expr_value->setup(orig_item);
@@ -6922,11 +6929,28 @@ Item_cache_wrapper::Item_cache_wrapper(I
}
+/**
+ Initialize the cache if it is needed
+*/
+
timour: It seems that the cache is not initialized "if needed".
Insted it is intialized on-demand, if not yet initialized. Isn't
it so? If yes, please fix the comment. I also don't like the
method name - better something like init_on_demand().
+void Item_cache_wrapper::check_initialization()
+{
+ if (!expr_cache->is_inited())
+ {
+ orig_item->get_cache_parameters(parameters);
+ expr_cache->init();
+ }
+}
+
+
void Item_cache_wrapper::print(String *str, enum_query_type query_type)
{
str->append(func_name());
if (expr_cache)
+ {
+ check_initialization();
expr_cache->print(str, query_type);
+ }
else
str->append(STRING_WITH_LEN("<<DISABLED>>"));
str->append('(');
@@ -6962,6 +6986,7 @@ void Item_cache_wrapper::cleanup()
expr_cache= 0;
/* expr_value is Item so it will be destroyed from list of Items */
expr_value= 0;
+ parameters.empty();
DBUG_VOID_RETURN;
}
@@ -6982,11 +7007,11 @@ void Item_cache_wrapper::cleanup()
@retval TRUE Error
*/
-bool Item_cache_wrapper::set_cache(THD *thd, List<Item*> &depends_on)
+bool Item_cache_wrapper::set_cache(THD *thd)
{
DBUG_ENTER("Item_cache_wrapper::set_cache");
DBUG_ASSERT(expr_cache == 0);
- expr_cache= new Expression_cache_tmptable(thd, depends_on, expr_value);
+ expr_cache= new Expression_cache_tmptable(thd, parameters, expr_value);
DBUG_RETURN(expr_cache == NULL);
}
@@ -7011,6 +7036,7 @@ Item *Item_cache_wrapper::check_cache()
{
Expression_cache_tmptable::result res;
Item *cached_value;
+ check_initialization();
res= expr_cache->check_value(&cached_value);
if (res == Expression_cache_tmptable::HIT)
DBUG_RETURN(cached_value);
=== modified file 'sql/item.h'
--- a/sql/item.h 2011-07-03 21:59:01 +0000
+++ b/sql/item.h 2011-07-19 09:15:34 +0000
@@ -1155,6 +1155,15 @@ public:
{
return FALSE;
}
+ struct Collect_deps_prm
+ {
+ int nest_level;
+ List<Item> *parameters;
+ };
+ /**
+ Collect outer references
+ */
+ virtual bool collect_outer_ref_processor(uchar *arg) {return FALSE; }
/**
Find a function of a given type
@@ -1249,7 +1258,7 @@ public:
{ return Field::GEOM_GEOMETRY; };
String *check_well_formed_result(String *str, bool send_error= 0);
bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
- Item* set_expr_cache(THD *thd, List<Item*> &depends_on);
+ Item* set_expr_cache(THD *thd);
virtual Item *get_cached_item() { return NULL; }
virtual Item_equal *get_item_equal() { return NULL; }
@@ -1273,6 +1282,23 @@ public:
walk(&Item::view_used_tables_processor, 0, (uchar *) view);
return view->view_used_tables;
}
+
+ /**
+ Collect and add to the list cache parameters for this Item.
+
+ @note Now implemented only for subqueries and in_optimizer,
+ if we need it for general function then this method should
+ be defined for Item_func.
+ */
+ virtual void get_cache_parameters(List<Item> ¶meters) { };
+
+ /**
+ Add this item to the items list if there is no such item in the list
+
+ @param list The list of the Items to add to
+ */
+
+ void add_if_unique(List<Item> &list);
};
@@ -1677,6 +1703,10 @@ public:
virtual void print(String *str, enum_query_type query_type);
virtual bool change_context_processor(uchar *cntx)
{ context= (Name_resolution_context *)cntx; return FALSE; }
+ /**
+ Collect outer references
+ */
+ virtual bool collect_outer_ref_processor(uchar *arg);
friend bool insert_fields(THD *thd, Name_resolution_context *context,
const char *db_name,
const char *table_name, List_iterator<Item> *it,
@@ -2739,8 +2769,11 @@ private:
*/
Item_cache *expr_value;
+ List<Item> parameters;
+
Item *check_cache();
- inline void cache();
+ void cache();
+ void check_initialization();
public:
Item_cache_wrapper(Item *item_arg);
@@ -2750,7 +2783,7 @@ public:
enum Type type() const { return EXPR_CACHE_ITEM; }
enum Type real_type() const { return orig_item->type(); }
- bool set_cache(THD *thd, List<Item*> &depends_on);
+ bool set_cache(THD *thd);
bool fix_fields(THD *thd, Item **it);
void fix_length_and_dec() {}
@@ -2832,6 +2865,9 @@ public:
if (result_type() == ROW_RESULT)
orig_item->bring_value();
}
+ virtual bool is_expensive() { return orig_item->is_expensive(); }
+ bool is_expensive_processor(uchar *arg)
+ { return orig_item->is_expensive_processor(arg); }
bool check_vcol_func_processor(uchar *arg)
{
return trace_unsupported_by_check_vcol_func_processor("cache");
=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc 2011-07-11 19:48:35 +0000
+++ b/sql/item_cmpfunc.cc 2011-07-19 09:15:34 +0000
@@ -1464,32 +1464,40 @@ Item *Item_in_optimizer::expr_cache_inse
DBUG_ENTER("Item_in_optimizer::expr_cache_insert_transformer");
if (args[1]->type() != Item::SUBSELECT_ITEM)
DBUG_RETURN(this); // MAX/MIN transformed => do nothing
- List<Item*> &depends_on= ((Item_subselect *)args[1])->depends_on;
if (expr_cache)
DBUG_RETURN(expr_cache);
+ if (args[1]->expr_cache_is_needed(thd) &&
+ (expr_cache= set_expr_cache(thd)))
+ DBUG_RETURN(expr_cache);
+
+ DBUG_RETURN(this);
+}
+
+
+/**
+ Collect and add to the list cache parameters for this Item.
+
+ @param parameters The list where to add parameters
+*/
+
+void Item_in_optimizer::get_cache_parameters(List<Item> ¶meters)
+{
/* Add left expression to the list of the parameters of the subquery */
if (args[0]->cols() == 1)
- depends_on.push_front((Item**)args);
+ args[0]->add_if_unique(parameters);
else
{
for (uint i= 0; i < args[0]->cols(); i++)
{
- depends_on.push_front(args[0]->addr(i));
+ args[0]->element_index(i)->add_if_unique(parameters);
}
}
-
- if (args[1]->expr_cache_is_needed(thd) &&
- (expr_cache= set_expr_cache(thd, depends_on)))
- DBUG_RETURN(expr_cache);
-
- /* no cache => return list in original state just to be safe */
- for (uint i= 0; i < args[0]->cols(); i++)
- depends_on.pop();
- DBUG_RETURN(this);
+ args[1]->get_cache_parameters(parameters);
}
+
/*
The implementation of optimized \<outer expression\> [NOT] IN \<subquery\>
predicates. The implementation works as follows.
=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h 2011-07-13 18:05:33 +0000
+++ b/sql/item_cmpfunc.h 2011-07-19 09:15:34 +0000
@@ -259,6 +259,7 @@ public:
bool is_expensive();
void set_join_tab_idx(uint join_tab_idx_arg)
{ args[1]->set_join_tab_idx(join_tab_idx_arg); }
+ virtual void get_cache_parameters(List<Item> ¶meters);
};
class Comp_creator
=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc 2011-07-18 20:45:38 +0000
+++ b/sql/item_subselect.cc 2011-07-19 09:15:34 +0000
@@ -128,7 +128,6 @@ void Item_subselect::cleanup()
}
if (engine)
engine->cleanup();
- depends_on.empty();
reset();
value_assigned= 0;
expr_cache= 0;
@@ -520,6 +519,11 @@ bool Item_subselect::walk(Item_processor
{
for (SELECT_LEX *lex= unit->first_select(); lex; lex= lex->next_select())
{
+ /*
+ List_iterator<Item> li(lex->join ?
+ lex->join->all_fields :
+ lex->item_list);
+ */
List_iterator<Item> li(lex->item_list);
Item *item;
ORDER *order;
@@ -583,6 +587,12 @@ bool Item_subselect::exec()
}
+void Item_subselect::get_cache_parameters(List<Item> ¶meters)
+{
+ Collect_deps_prm prm= { engine->nest_level(), ¶meters };
+ walk(&Item::collect_outer_ref_processor, TRUE, (uchar*)&prm);
+}
+
int Item_in_subselect::optimize(double *out_rows, double *cost)
{
int res;
@@ -647,7 +657,7 @@ int Item_in_subselect::optimize(double *
bool Item_subselect::expr_cache_is_needed(THD *thd)
{
- return (depends_on.elements &&
+ return ((engine->uncacheable() & UNCACHEABLE_DEPENDENT) &&
engine->cols() == 1 &&
optimizer_flag(thd, OPTIMIZER_SWITCH_SUBQUERY_CACHE) &&
!(engine->uncacheable() & (UNCACHEABLE_RAND |
@@ -675,8 +685,7 @@ bool Item_subselect::expr_cache_is_neede
bool Item_in_subselect::expr_cache_is_needed(THD *thd)
{
- return (depends_on.elements &&
- optimizer_flag(thd, OPTIMIZER_SWITCH_SUBQUERY_CACHE) &&
+ return (optimizer_flag(thd, OPTIMIZER_SWITCH_SUBQUERY_CACHE) &&
!(engine->uncacheable() & (UNCACHEABLE_RAND |
UNCACHEABLE_SIDEEFFECT)));
}
@@ -1009,7 +1018,7 @@ Item* Item_singlerow_subselect::expr_cac
DBUG_RETURN(expr_cache);
if (expr_cache_is_needed(thd) &&
- (expr_cache= set_expr_cache(thd, depends_on)))
+ (expr_cache= set_expr_cache(thd)))
DBUG_RETURN(expr_cache);
DBUG_RETURN(this);
}
@@ -1270,7 +1279,7 @@ Item* Item_exists_subselect::expr_cache_
DBUG_RETURN(expr_cache);
if (substype() == EXISTS_SUBS && expr_cache_is_needed(thd) &&
- (expr_cache= set_expr_cache(thd, depends_on)))
+ (expr_cache= set_expr_cache(thd)))
DBUG_RETURN(expr_cache);
DBUG_RETURN(this);
}
@@ -4263,7 +4272,9 @@ subselect_hash_sj_engine::make_unique_en
tab->ref.tmp_table_index_lookup_init(thd, tmp_key, it, FALSE);
DBUG_RETURN(new subselect_uniquesubquery_engine(thd, tab, item,
- semi_join_conds));
+ semi_join_conds,
+ materialize_engine->
+ nest_level()));
}
@@ -5725,3 +5736,15 @@ end:
void subselect_table_scan_engine::cleanup()
{
}
+
timour:
Make the two methods below inline.
+
+int subselect_single_select_engine::nest_level()
+{
+ return select_lex->nest_level;
+};
+
+
+int subselect_union_engine::nest_level()
+{
+ return unit->first_select()->nest_level;
+};
=== modified file 'sql/item_subselect.h'
--- a/sql/item_subselect.h 2011-07-18 20:45:38 +0000
+++ b/sql/item_subselect.h 2011-07-19 09:15:34 +0000
@@ -102,14 +102,6 @@ public:
List<Ref_to_outside> upper_refs;
st_select_lex *parent_select;
- /**
- List of references on items subquery depends on (externally resolved);
-
- @note We can't store direct links on Items because it could be
- substituted with other item (for example for grouping).
- */
- List<Item*> depends_on;
-
/*
TRUE<=>Table Elimination has made it redundant to evaluate this select
(and so it is not part of QEP, etc)
@@ -225,6 +217,7 @@ public:
@retval FALSE otherwise
*/
bool is_expensive_processor(uchar *arg) { return TRUE; }
+
/**
Get the SELECT_LEX structure associated with this Item.
@return the SELECT_LEX structure associated with this Item
@@ -232,6 +225,7 @@ public:
st_select_lex* get_select_lex();
const char *func_name() const { DBUG_ASSERT(0); return "subselect"; }
virtual bool expr_cache_is_needed(THD *);
+ virtual void get_cache_parameters(List<Item> ¶meters);
friend class select_result_interceptor;
friend class Item_in_optimizer;
@@ -646,6 +640,7 @@ public:
virtual bool no_rows() = 0;
virtual enum_engine_type engine_type() { return ABSTRACT_ENGINE; }
virtual int get_identifier() { DBUG_ASSERT(0); return 0; }
+ virtual int nest_level()= 0;
protected:
void set_row(List<Item> &item_list, Item_cache **row);
};
@@ -679,6 +674,7 @@ public:
bool no_rows();
virtual enum_engine_type engine_type() { return SINGLE_SELECT_ENGINE; }
int get_identifier();
+ virtual int nest_level();
friend class subselect_hash_sj_engine;
friend class Item_in_subselect;
@@ -708,6 +704,7 @@ public:
bool is_executed() const;
bool no_rows();
virtual enum_engine_type engine_type() { return UNION_ENGINE; }
+ virtual int nest_level();
};
@@ -736,6 +733,7 @@ class subselect_uniquesubquery_engine: p
protected:
st_join_table *tab;
Item *cond; /* The WHERE condition of subselect */
+ int save_nest_level;
/*
TRUE<=> last execution produced empty set. Valid only when left
expression is NULL.
@@ -746,8 +744,9 @@ public:
// constructor can assign THD because it will be called after JOIN::prepare
subselect_uniquesubquery_engine(THD *thd_arg, st_join_table *tab_arg,
- Item_subselect *subs, Item *where)
- :subselect_engine(thd_arg, subs, 0), tab(tab_arg), cond(where)
+ Item_subselect *subs, Item *where, int lvl)
+ :subselect_engine(thd_arg, subs, 0), tab(tab_arg), cond(where),
+ save_nest_level(lvl)
{}
~subselect_uniquesubquery_engine();
void cleanup();
@@ -769,6 +768,7 @@ public:
int copy_ref_key_simple(); /* TIMOUR: this method needs refactoring. */
bool no_rows() { return empty_result_set; }
virtual enum_engine_type engine_type() { return UNIQUESUBQUERY_ENGINE; }
+ virtual int nest_level() { return save_nest_level;};
};
@@ -811,8 +811,8 @@ public:
// constructor can assign THD because it will be called after JOIN::prepare
subselect_indexsubquery_engine(THD *thd_arg, st_join_table *tab_arg,
Item_subselect *subs, Item *where,
- Item *having_arg, bool chk_null)
- :subselect_uniquesubquery_engine(thd_arg, tab_arg, subs, where),
+ Item *having_arg, bool chk_null, int lvl)
+ :subselect_uniquesubquery_engine(thd_arg, tab_arg, subs, where, lvl),
check_null(chk_null),
having(having_arg)
{}
@@ -905,6 +905,8 @@ public:
bool temp= FALSE);
bool no_tables();//=>base class
+ virtual int nest_level() { return materialize_engine->nest_level();};
+
protected:
/* The engine used to compute the IN predicate. */
subselect_engine *lookup_engine;
@@ -1185,6 +1187,7 @@ public:
return !(((Item_in_subselect *) item)->null_value);
}
void print(String*, enum_query_type);
+ virtual int nest_level() { return lookup_engine->nest_level(); }
friend void subselect_hash_sj_engine::cleanup();
};
=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc 2011-06-27 16:07:24 +0000
+++ b/sql/item_sum.cc 2011-07-19 09:15:34 +0000
@@ -319,7 +319,6 @@ bool Item_sum::register_sum_func(THD *th
if (aggr_level >= 0)
{
ref_by= ref;
- thd->lex->current_select->register_dependency_item(aggr_sel, ref);
/* Add the object to the list of registered objects assigned to aggr_sel */
if (!aggr_sel->inner_sum_func_list)
next= this;
@@ -355,6 +354,16 @@ bool Item_sum::register_sum_func(THD *th
return FALSE;
}
+
+bool Item_sum::collect_outer_ref_processor(uchar *param)
+{
+ Collect_deps_prm *prm= (Collect_deps_prm *)param;
+ SELECT_LEX *ds;
+ if ((ds= depended_from()) && ds->nest_level < prm->nest_level)
+ add_if_unique(*prm->parameters);
+ return FALSE;
+}
+
Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements),
forced_const(FALSE)
=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h 2011-05-10 15:17:43 +0000
+++ b/sql/item_sum.h 2011-07-19 09:15:34 +0000
@@ -374,6 +374,7 @@ public:
virtual Field *create_tmp_field(bool group, TABLE *table,
uint convert_blob_length);
bool walk(Item_processor processor, bool walk_subquery, uchar *argument);
+ virtual bool collect_outer_ref_processor(uchar *param);
bool init_sum_func_check(THD *thd);
bool check_sum_func(THD *thd, Item **ref);
bool register_sum_func(THD *thd, Item **ref);
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc 2011-07-04 11:51:16 +0000
+++ b/sql/opt_range.cc 2011-07-19 09:15:34 +0000
@@ -11731,17 +11731,19 @@ check_group_min_max_predicates(Item *con
Disallow loose index scan if the MIN/MAX argument field is referenced by
a subquery in the WHERE clause.
*/
+
if (cond_type == Item::SUBSELECT_ITEM)
{
Item_subselect *subs_cond= (Item_subselect*) cond;
if (subs_cond->is_correlated)
{
- DBUG_ASSERT(subs_cond->depends_on.elements > 0);
- List_iterator_fast<Item*> li(subs_cond->depends_on);
- Item **dep;
+ DBUG_ASSERT(subs_cond->upper_refs.elements > 0);
+ List_iterator_fast<Item_subselect::Ref_to_outside>
+ li(subs_cond->upper_refs);
+ Item_subselect::Ref_to_outside *dep;
while ((dep= li++))
{
- if ((*dep)->eq(min_max_arg_item, FALSE))
+ if (dep->item->eq(min_max_arg_item, FALSE))
DBUG_RETURN(FALSE);
}
}
=== modified file 'sql/opt_subselect.cc'
--- a/sql/opt_subselect.cc 2011-07-19 07:45:46 +0000
+++ b/sql/opt_subselect.cc 2011-07-19 09:15:34 +0000
@@ -4167,7 +4167,10 @@ int rewrite_to_index_subquery_engine(JOI
timour:
Here you could introduce one variable 'nest_level' in the
beginning of the method.
subselect_uniquesubquery_engine(thd,
join_tab,
unit->item,
- where)));
+ where,
+ join->
+ select_lex->
+ nest_level)));
}
else if (join_tab[0].type == JT_REF &&
join_tab[0].ref.items[0]->name == in_left_expr_name)
@@ -4183,7 +4186,10 @@ int rewrite_to_index_subquery_engine(JOI
unit->item,
where,
NULL,
- 0)));
+ 0,
+ join->
+ select_lex->
+ nest_level)));
}
} else if (join_tab[0].type == JT_REF_OR_NULL &&
join_tab[0].ref.items[0]->name == in_left_expr_name &&
@@ -4199,7 +4205,10 @@ int rewrite_to_index_subquery_engine(JOI
unit->item,
join->conds,
join->having,
- 1)));
+ 1,
+ join->
+ select_lex->
+ nest_level)));
}
}
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2011-07-11 21:00:44 +0000
+++ b/sql/sql_base.cc 2011-07-19 09:15:34 +0000
@@ -6454,11 +6454,6 @@ find_field_in_tables(THD *thd, Item_iden
{
mark_select_range_as_dependent(thd, last_select, current_sel,
found, *ref, item);
- if (item->can_be_depended)
- {
- DBUG_ASSERT((*ref) == (Item*)item);
- current_sel->register_dependency_item(last_select, ref);
- }
}
}
return found;
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2011-07-17 07:52:07 +0000
+++ b/sql/sql_class.h 2011-07-19 09:15:34 +0000
@@ -74,6 +74,22 @@ public:
/**
+ Item iterator over List_iterator_fast for Items
+*/
+
+class Item_iterator_list: public Item_iterator
+{
+ List_iterator<Item> list;
+public:
+ Item_iterator_list(List_iterator<Item> &arg_list):
+ list(arg_list) {}
+ void open() { list.rewind(); }
+ Item *next() { return (list++); }
+ void close() {}
+};
+
+
+/**
Item iterator over Item interface for rows
*/
=== modified file 'sql/sql_expression_cache.cc'
--- a/sql/sql_expression_cache.cc 2011-06-27 16:07:24 +0000
+++ b/sql/sql_expression_cache.cc 2011-07-19 09:15:34 +0000
@@ -23,9 +23,9 @@
ulong subquery_cache_miss, subquery_cache_hit;
Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
- List<Item*> &dependants,
- Item *value)
- :cache_table(NULL), table_thd(thd), list(&dependants), val(value),
+ List<Item> &dependants,
+ Item *value)
+ :cache_table(NULL), table_thd(thd), items(dependants), val(value),
inited (0)
{
DBUG_ENTER("Expression_cache_tmptable::Expression_cache_tmptable");
@@ -60,50 +60,32 @@ static uint field_enumerator(uchar *arg)
void Expression_cache_tmptable::init()
{
- List_iterator<Item*> li(*list);
- Item_iterator_ref_list it(li);
- Item **item;
+ List_iterator<Item> li(items);
+ Item_iterator_list it(li);
uint field_counter;
DBUG_ENTER("Expression_cache_tmptable::init");
DBUG_ASSERT(!inited);
inited= TRUE;
cache_table= NULL;
- while ((item= li++))
- {
- DBUG_ASSERT(item);
- if (*item)
- {
- DBUG_ASSERT((*item)->fixed);
- items.push_back((*item));
- }
- else
- {
- /*
- This is possible when optimizer already executed this subquery and
- optimized out the condition predicate.
- */
- li.remove();
- }
- }
-
- if (list->elements == 0)
+ if (items.elements == 0)
{
DBUG_PRINT("info", ("All parameters were removed by optimizer."));
DBUG_VOID_RETURN;
}
+ /* add result field */
+ items.push_front(val);
+
cache_table_param.init();
/* dependent items and result */
- cache_table_param.field_count= list->elements + 1;
+ cache_table_param.field_count= items.elements;
/* postpone table creation to index description */
cache_table_param.skip_create_table= 1;
- items.push_front(val);
-
if (!(cache_table= create_tmp_table(table_thd, &cache_table_param,
items, (ORDER*) NULL,
- FALSE, FALSE,
+ FALSE, TRUE,
((table_thd->options |
TMP_TABLE_ALL_COLUMNS) &
~(OPTION_BIG_TABLES |
@@ -122,16 +104,13 @@ void Expression_cache_tmptable::init()
goto error;
}
- /* This list do not contain result field */
- it.open();
-
- field_counter=1;
+ field_counter= 1;
if (cache_table->alloc_keys(1) ||
cache_table->add_tmp_key(0, items.elements - 1, &field_enumerator,
(uchar*)&field_counter, TRUE) ||
ref.tmp_table_index_lookup_init(table_thd, cache_table->key_info, it,
- TRUE))
+ TRUE, 1 /* skip result field*/))
{
DBUG_PRINT("error", ("creating index failed"));
goto error;
@@ -192,13 +171,6 @@ Expression_cache::result Expression_cach
int res;
DBUG_ENTER("Expression_cache_tmptable::check_value");
- /*
- We defer cache initialization to get item references that are
- used at the execution phase.
- */
- if (!inited)
- init();
-
if (cache_table)
{
DBUG_PRINT("info", ("status: %u has_record %u",
@@ -274,16 +246,17 @@ err:
void Expression_cache_tmptable::print(String *str, enum_query_type query_type)
{
- List_iterator<Item*> li(*list);
- Item **item;
+ List_iterator<Item> li(items);
+ Item *item;
bool is_first= TRUE;
str->append('<');
+ li++; // skip result field
while ((item= li++))
{
if (!is_first)
str->append(',');
- (*item)->print(str, query_type);
+ item->print(str, query_type);
is_first= FALSE;
}
str->append('>');
=== modified file 'sql/sql_expression_cache.h'
--- a/sql/sql_expression_cache.h 2010-10-27 03:03:59 +0000
+++ b/sql/sql_expression_cache.h 2011-07-19 09:15:34 +0000
@@ -37,6 +37,15 @@ public:
Print cache parameters
*/
virtual void print(String *str, enum_query_type query_type)= 0;
+
+ /**
+ Is this cache initialized
+ */
+ virtual bool is_inited()= 0;
+ /**
+ Initialize this cache
+ */
+ virtual void init()= 0;
};
struct st_table_ref;
@@ -51,15 +60,16 @@ class Item_field;
class Expression_cache_tmptable :public Expression_cache
{
public:
- Expression_cache_tmptable(THD *thd, List<Item*> &dependants, Item *value);
+ Expression_cache_tmptable(THD *thd, List<Item> &dependants, Item *value);
virtual ~Expression_cache_tmptable();
virtual result check_value(Item **value);
virtual my_bool put_value(Item *value);
void print(String *str, enum_query_type query_type);
+ bool is_inited() { return inited; };
+ void init();
private:
- void init();
/* tmp table parameters */
TMP_TABLE_PARAM cache_table_param;
@@ -71,10 +81,8 @@ private:
struct st_table_ref ref;
/* Cached result */
Item_field *cached_result;
- /* List of references to the parameters of the expression */
- List<Item*> *list;
- /* List of items */
- List<Item> items;
+ /* List of parameter items */
+ List<Item> &items;
/* Value Item example */
Item *val;
/* Set on if the object has been succesfully initialized with init() */
=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc 2011-07-19 03:05:33 +0000
+++ b/sql/sql_lex.cc 2011-07-19 09:15:34 +0000
@@ -1879,59 +1879,6 @@ void st_select_lex_unit::exclude_tree()
}
-/**
- Register reference to an item which the subqueries depends on
-
- @param def_sel select against which the item is resolved
- @param dependency reference to the item
-
- @details
- This function puts the reference dependency to an item that is either an
- outer field or an aggregate function resolved against an outer select into
- the list 'depends_on'. It adds it to the 'depends_on' lists for each
- subquery between this one and 'def_sel' - the subquery against which the
- item is resolved.
-*/
-
-void st_select_lex::register_dependency_item(st_select_lex *def_sel,
- Item **dependency)
-{
- SELECT_LEX *s= this;
- DBUG_ENTER("st_select_lex::register_dependency_item");
- DBUG_ASSERT(this != def_sel);
- DBUG_ASSERT(*dependency);
- //psergey-add-stupid:
- while (def_sel->merged_into)
- def_sel= def_sel->merged_into;
- //:eof
- do
- {
- /* check duplicates */
- List_iterator_fast<Item*> li(s->master_unit()->item->depends_on);
- Item **dep;
- while ((dep= li++))
- {
- if ((*dep)->eq(*dependency, FALSE))
- {
- DBUG_PRINT("info", ("dependency %s already present",
- ((*dependency)->name ?
- (*dependency)->name :
- "<no name>")));
- DBUG_VOID_RETURN;
- }
- }
-
- s->master_unit()->item->depends_on.push_back(dependency);
- DBUG_PRINT("info", ("depends_on: Select: %d added: %s",
- s->select_number,
- ((*dependency)->name ?
- (*dependency)->name :
- "<no name>")));
- } while ((s= s->outer_select()) != def_sel);
- DBUG_VOID_RETURN;
-}
-
-
/*
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
this to 'last' as dependent
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2011-07-17 06:57:43 +0000
+++ b/sql/sql_lex.h 2011-07-19 09:15:34 +0000
@@ -793,7 +793,6 @@ public:
inline bool is_subquery_function() { return master_unit()->item != 0; }
bool mark_as_dependent(THD *thd, st_select_lex *last, Item *dependency);
- void register_dependency_item(st_select_lex *last, Item **dependency);
bool set_braces(bool value);
bool inc_in_sum_expr();
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2011-07-18 06:12:31 +0000
+++ b/sql/sql_select.cc 2011-07-19 09:15:34 +0000
@@ -9613,6 +9613,7 @@ bool JOIN_TAB::preread_init()
@param thd Thread handle
@param tmp_key The temporary table key
@param it The iterator of items for lookup in the key
+ @param skip Number of fields from the beginning to skip
@details
Build TABLE_REF object for lookup in the key 'tmp_key' using items
@@ -9625,9 +9626,11 @@ bool JOIN_TAB::preread_init()
bool TABLE_REF::tmp_table_index_lookup_init(THD *thd,
KEY *tmp_key,
Item_iterator &it,
- bool value)
+ bool value,
+ uint skip)
{
uint tmp_key_parts= tmp_key->key_parts;
+ uint i;
DBUG_ENTER("TABLE_REF::tmp_table_index_lookup_init");
key= 0; /* The only temp table index. */
@@ -9648,7 +9651,8 @@ bool TABLE_REF::tmp_table_index_lookup_i
uchar *cur_ref_buff= key_buff;
it.open();
- for (uint i= 0; i < tmp_key_parts; i++, cur_key_part++, ref_key++)
+ for (i= 0; i < skip; i++) it.next();
+ for (i= 0; i < tmp_key_parts; i++, cur_key_part++, ref_key++)
{
Item *item= it.next();
DBUG_ASSERT(item);
=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h 2011-07-17 07:52:07 +0000
+++ b/sql/sql_select.h 2011-07-19 09:15:34 +0000
@@ -135,7 +135,7 @@ typedef struct st_table_ref
bool disable_cache;
bool tmp_table_index_lookup_init(THD *thd, KEY *tmp_key, Item_iterator &it,
- bool value);
+ bool value, uint skip= 0);
} TABLE_REF;
1
0

Re: [Maria-developers] [Commits] Rev 3115: Fix bug lp:782305 in file:///home/tsk/mprog/src/5.3-work/
by Oleksandr Byelkin 18 Jul '11
by Oleksandr Byelkin 18 Jul '11
18 Jul '11
Hi!
18.07.2011 23:45, timour(a)askmonty.org пишет:
> At file:///home/tsk/mprog/src/5.3-work/
>
> ------------------------------------------------------------
> revno: 3115
> revision-id: timour(a)askmonty.org-20110718204538-2976m25qh52g6l69
> parent: igor(a)askmonty.org-20110717075207-sg6f40o1ps8mwxrj
> fixes bug(s): https://launchpad.net/bugs/782305
> committer: timour(a)askmonty.org
> branch nick: 5.3-work
> timestamp: Mon 2011-07-18 23:45:38 +0300
> message:
> Fix bug lp:782305
>
> Analysis:
> Both the wrong result and the valgrind warning were a result
> of incomplete cleanup of the MIN/MAX subquery rewrite. At the
> first execution of the query, the non-aggregate subquery is
> transformed into an aggregate MIN/MAX subquery. During the
> fix_fields phase of the MIN/MAX function, it sets the property
> st_select_lex::with_sum_func to true.
>
> The second execution of the query finds this flag to be ON.
> When optimization reaches the same MIN/MAX subquery
> transformation, it tests if the subquery is an aggregate or not.
> Since select_lex->with_sum_func == true from the previous
> execution, the transformation executes the second branch that
> handles aggregate subqueries. This substitutes the subquery
> Item into a Item_maxmin_subselect. At the same time elsewhere
> it is assumed that the subquery Item is of type
> Item_allany_subselect. Ultimately this results in casting the
> actual object to the wrong class, and calling the wrong
> any_value() method from empty_underlying_subquery().
>
> Solution:
> Cleanup the st_select_lex::with_sum_func property in the case
> when the MIN/MAX transformation was performed for a non-aggregate
> subquery, so that the transformation can be repeated.
The patch is OK.
SUBS_MAXMIN_ENGINE is really good name, thank you!
[skip]
1
0

16 Jul '11
Hi, Holyfoot!
Basically, it's all ok.
There are comments, see below, but nothing big. Few small changes :)
And there's one thought.
Log rotation by size is great of course. But there's also log rotation
by time (e.g. every week). And logs often contain severity, facility,
this, and that, and so on. There are lots of different logging
frameworks for different languages (java, c++, .net, etc) - and they
exist for a reason.
To let plugins (and internal MariaDB subsystems) to log easily and
conveniently, we may eventually put all logging features that we have
(like, logging to a file, windows event log, or a table) into one place.
And even add a couple of new ones.
As I see it, you started creating a logging service, that may
be expanded in the future. So, I'd like it to be future proof.
See for example a list of features that a logger can have:
http://www.dotnetlogging.com/concepts/
(I'm not going to discuss this list and to what extent it may be
relevant for us :)
For now it boils down to two issues.
I think it deserves to be called not "logrotate" but "logger".
Never mind that it can only "logrotate" now :)
And second - logrotate_open() cannot be extended if we'd need rotation
by time, we'd need another function. Also log files may have more
attributes in the future. So I'd suggest to split logrotate_open() in
two:
logger_open(const char *path)
logger_set_rotation(LOGROTATE_FILE *log,
unsigned long size_limit,
unsigned int rotations);
or may be logger_configure_rotation, or logger_rotate_by_size.
Later we could easily add logger_rotate_by_time,
logger_set_autoflush, or logger_set_compression, whatever we
may need.
What do you think?
Regards,
Sergei
Now, comments to the patch:
> === modified file 'include/mysql/plugin.h'
> --- include/mysql/plugin.h 2010-10-21 09:49:16 +0000
> +++ include/mysql/plugin.h 2011-05-29 14:20:29 +0000
> @@ -71,7 +71,7 @@ typedef struct st_mysql_xid MYSQL_XID;
> Plugin API. Common for all plugin types.
> */
>
> -#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0102
> +#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0103
increase MARIA_PLUGIN_INTERFACE_VERSION instead, your change is not in
the vanilla MySQL.
by the way, please, fix the HOWTO to say that MARIA_PLUGIN_INTERFACE_VERSION
should be increased, not MYSQL_PLUGIN_INTERFACE_VERSION. Thanks.
> /*
> The allowable types of plugins
> === added file 'include/mysql/service_logrotate.h'
> --- include/mysql/service_logrotate.h 1970-01-01 00:00:00 +0000
> +++ include/mysql/service_logrotate.h 2011-05-30 15:23:25 +0000
> @@ -0,0 +1,94 @@
> +/* Copyright (C) 2011 Monty Program Ab
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; version 2 of the License.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
> +
> +#ifndef SERVICE_LOGROTATE_INCLUDED
> +#define SERVICE_LOGROTATE_INCLUDED
MYSQL_SERVICE_LOGROTATE_INCLUDED
that is, with the directory name (it's a general rule, to avoid
conflicts between include guards from identically named files in
different directories)
> +
> +#include <stdarg.h>
wrap this include in #ifndef MYSQL_ABI_CHECK ... #endif
(see, e.g. service_thd_alloc.h)
> +
> +/**
> + @file
> + logrotate service
> +
> + Log file with rotation implementation.
> +
> + This service implements logging with possible rotation
> + of the log files. Interface intentionally tries to be similar to FILE*
> + related functions.
> +
> + So that one can open the log with logrotate_open(), specifying
> + the limit on the logfile size and the rotations number.
> +
> + Then it's possible to write messages to the log with
> + logrotate_printf or logrotate_vprintf functions.
> +
> + As the size of the logfile grows over the specified limit,
> + it is renamed to 'logfile.1'. The former 'logfile.1' becomes
> + 'logfile.2', etc. The file 'logfile.rotations' is removed.
> + That's how the rotation works.
> +
> + The rotation can be forced with the logrotate_rotate() call.
> +
> + Finally the log should be closed with logrotate_close().
> +
> +NOTES:
Good comment!
Just change NOTES to @notes, let's use Doxygen tags inside Doxygen comments
> + Implementation checks the size of the log file before it starts new
> + printf into it. So the size of the file gets over the limit when it rotates.
> +
> + The access is secured with the mutex, so the log is threadsafe.
> +*/
> +
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +typedef struct logrotate_file_st LOGROTATE_FILE;
> +
> +extern struct logrotate_service_st {
> + LOGROTATE_FILE* (*open)(const char *, unsigned long, unsigned int);
> + int (*close)(LOGROTATE_FILE *log);
> + int (*vprintf)(LOGROTATE_FILE *log, const char *fmt, va_list argptr);
> + int (*printf)(LOGROTATE_FILE *log, const char *fmt, ...);
> + int (*rotate)(LOGROTATE_FILE *log);
> +} *logrotate_service;
> +
> +#ifdef MYSQL_DYNAMIC_PLUGIN
> +
> +#define logrotate_open(path,limit,rotations) logrotate_service->\
> + open(path,limit,rotations)
> +#define logrotate_close(log) logrotate_service->close(log)
> +#define logrotate_rotate(log) logrotate_service->rotate(log)
> +#define logrotate_vprintf(log, fmt, argptr) logrotate_service->\
> + vprintf(log, fmt, argptr)
> +#define logrotate_printf logrotate_service->printf
add parentheses around the whole macro (where possible):
(logrotate_service->vprintf(log, fmt, argptr))
> +#else
> +
> + LOGROTATE_FILE *logrotate_open(const char *path,
> + unsigned long size_limit,
> + unsigned int rotations);
> + int logrotate_close(LOGROTATE_FILE *log);
> + int logrotate_vprintf(LOGROTATE_FILE *log, const char *fmt, va_list argptr);
> + int logrotate_rotate(LOGROTATE_FILE *log);
> + int logrotate_printf(LOGROTATE_FILE *log, const char *fmt, ...);
> +#endif
> +
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /*SERVICE_LOGROTATE_INCLUDED*/
> +
> === modified file 'libmysqld/Makefile.am'
> --- libmysqld/Makefile.am 2010-11-04 15:40:18 +0000
> +++ libmysqld/Makefile.am 2011-05-29 15:55:28 +0000
> @@ -81,6 +81,7 @@ sqlsources = derror.cc field.cc field_co
> sql_bootstrap.cc \
> binlog.cc rpl_handler.cc mdl.cc keycaches.cc sql_audit.cc \
> gcalc_slicescan.cc gcalc_tools.cc \
> + sql_logrotate.cc \
What tree are you doing it in?
(why the question - Makefile.am and plug.in are no longer used in 5.5)
> sql_partition_admin.cc
>
> libmysqld_int_a_SOURCES= $(libmysqld_sources)
> === added file 'plugin/sql_errlog/CMakeLists.txt'
> --- plugin/sql_errlog/CMakeLists.txt 1970-01-01 00:00:00 +0000
> +++ plugin/sql_errlog/CMakeLists.txt 2011-05-29 15:58:22 +0000
> @@ -0,0 +1,17 @@
> +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
Really? Oracle? :)
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> +
> +MYSQL_ADD_PLUGIN(sql_errlog sql_errlog.c
> + MODULE_ONLY MODULE_OUTPUT_NAME "sql_erlg")
why non-default module output name?
I think MODULE_OUTPUT_NAME should only be used when converting old plugins
that have to keep non-default module name for compatibility reasons.
new plugins don't need to use MODULE_OUTPUT_NAME at all.
> === added file 'plugin/sql_errlog/sql_errlog.c'
> --- plugin/sql_errlog/sql_errlog.c 1970-01-01 00:00:00 +0000
> +++ plugin/sql_errlog/sql_errlog.c 2011-05-30 15:30:11 +0000
> @@ -0,0 +1,124 @@
> +/* Copyright (C) 2011 Monty Program Ab
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; version 2 of the License.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
> +
> +#include <mysql/plugin_audit.h>
> +#include <stdio.h>
> +#include <time.h>
> +
> +static char *filename;
> +static unsigned int rate;
> +static unsigned int size_limit;
> +static unsigned int rotations;
> +static char rotate;
> +
> +static unsigned int count;
> +LOGROTATE_FILE *logfile;
> +
> +static MYSQL_SYSVAR_UINT(rate, rate, PLUGIN_VAR_RQCMDARG,
> + "Sampling rate", NULL, NULL, 1, 0, 1000000, 1);
sampling rate of 0 - what does it mean?
if it means "disable logging", mention it in the help text.
if it doesn't have any sense, set the minimal value to be 1.
> +
> +static MYSQL_SYSVAR_UINT(size_limit, size_limit,
> + PLUGIN_VAR_READONLY, "Log file size limit", NULL, NULL,
> + 1000000, 100, 1024*1024L*1024L, 1);
> +
> +static MYSQL_SYSVAR_UINT(rotations, rotations,
> + PLUGIN_VAR_READONLY, "Number of rotations before log is removed.",
> + NULL, NULL, 9, 1, 999, 1);
> +
> +static MYSQL_SYSVAR_BOOL(rotate, rotate,
> + PLUGIN_VAR_NOSYSVAR, "Force log rotation", NULL, NULL/*rotate_log*/,
> + 0);
This seems to be unused.
> +
> +static MYSQL_SYSVAR_STR(filename, filename,
> + PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG,
> + "The file to log sql errors to", NULL, NULL,
> + "sql_errors.log");
> +
> +static struct st_mysql_sys_var* vars[] = {
> + MYSQL_SYSVAR(rate),
> + MYSQL_SYSVAR(size_limit),
> + MYSQL_SYSVAR(rotations),
> + MYSQL_SYSVAR(rotate),
> + MYSQL_SYSVAR(filename),
> + NULL
> +};
> +
> +static void log_sql_errors(MYSQL_THD thd __attribute__((unused)),
> + const struct mysql_event *ev)
> +{
> + const struct mysql_event_general *event =
> + (const struct mysql_event_general*)ev;
> + if (rate &&
> + event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR)
> + {
> + if (++count >= rate)
> + {
> + struct tm t;
> + time_t event_time = event->general_time;
> +
> + count = 0;
> + localtime_r(&event_time, &t);
> + logrotate_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d "
> + "[%s] ERROR %d: %s : %s\n",
> + t.tm_year + 1900, t.tm_mon + 1,
> + t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
> + event->general_user, event->general_error_code,
> + event->general_command, event->general_query);
Did you test that? Can you show a sample output?
> + }
> + }
> +}
> +
> +static int sql_error_log_init(void *p __attribute__((unused)))
> +{
> + logfile= logrotate_open(filename, size_limit, rotations);
> + if (logfile == NULL) {
> + fprintf(stderr, "Could not create file '%s'\n",
> + filename);
> + return 1;
> + }
> + count = 0;
> + return 0;
> +}
> +
> +static int sql_error_log_deinit(void *p __attribute__((unused)))
> +{
> + logrotate_close(logfile);
> + return 0;
> +}
> +
> +static struct st_mysql_audit descriptor =
> +{
> + MYSQL_AUDIT_INTERFACE_VERSION,
> + NULL,
> + log_sql_errors,
> + { MYSQL_AUDIT_GENERAL_CLASSMASK }
> +};
> +
> +mysql_declare_plugin(sql_errlog)
> +{
> + MYSQL_AUDIT_PLUGIN,
> + &descriptor,
> + "SQL_ERROR_LOG",
> + "Maria DB",
"Maria DB" is not the author. You can proudly put your name here :)
or "your name, Monty Program Ab" if you'd like
> + "Log SQL level errors to a file with rotation",
> + PLUGIN_LICENSE_GPL,
> + sql_error_log_init,
> + sql_error_log_deinit,
> + 0x0100,
> + NULL,
> + vars,
> + NULL
> +}
Add also maria_declare_plugin declaration.
Hmm, may be not "add" but "replace" - you can remove
mysql_declare_plugin, because this plugin won't work with MySQL anyway,
it uses logrotate service.
> +mysql_declare_plugin_end;
> === modified file 'sql/Makefile.am'
> --- sql/Makefile.am 2010-11-09 20:10:44 +0000
> +++ sql/Makefile.am 2011-05-29 15:52:47 +0000
> @@ -180,7 +180,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.
> sql_builtin.cc sql_tablespace.cc partition_info.cc \
> sql_servers.cc event_parse_data.cc sql_signal.cc \
> mdl.cc transaction.cc sql_audit.cc \
> - sha2.cc \
> + sha2.cc sql_logrotate.cc\
should it be in sql or mysys?
I think mysys is more appropriate, there's nothing
related to "SQL" in log rotation
> gcalc_slicescan.cc gcalc_tools.cc \
> sql_alter.cc \
> sql_partition_admin.cc
> === added file 'sql/sql_logrotate.cc'
> --- sql/sql_logrotate.cc 1970-01-01 00:00:00 +0000
> +++ sql/sql_logrotate.cc 2011-05-30 15:35:18 +0000
> @@ -0,0 +1,172 @@
> +/* Copyright (C) 2011 Monty Program Ab
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; version 2 of the License.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
> +
> +
> +#include "my_global.h"
> +#include <my_sys.h>
> +#include "sql_priv.h"
> +#include "mysqld.h"
> +#include <mysql/service_logrotate.h>
> +
> +extern "C" {
> +
> +typedef struct logrotate_file_st {
> + FILE *file;
> + char path[FN_REFLEN];
> + long size_limit;
> + unsigned int rotations;
> + unsigned int index_len;
> + size_t path_len;
> + pthread_mutex_t lock;
> +};
> +
> +
> +static unsigned int n_dig(unsigned int i)
> +{
> + return (i == 0) ? 0 : ((i < 10) ? 1 : ((i < 100) ? 2 : 3));
> +}
> +
> +
> +LOGROTATE_FILE *logrotate_open(const char *path,
> + unsigned long size_limit,
> + unsigned int rotations)
> +{
> + LOGROTATE_FILE *new_log;
> +
> + /* I don't think we need more rotations, */
> + /* but if it's so, the rotation procedure should be adapted to it. */
> + if (rotations > 999)
> + return 0;
> +
> + if (!(new_log= (LOGROTATE_FILE *) my_malloc(sizeof(LOGROTATE_FILE), MYF(0))))
> + return 0; /* End of memory */
> + new_log->rotations= rotations;
> + new_log->size_limit= size_limit;
> + new_log->index_len= n_dig(rotations);
> + new_log->path_len= strlen(fn_format(new_log->path, path,
> + mysql_data_home, "", 4));
> +
> + if (new_log->path_len+new_log->index_len+1 > FN_REFLEN ||
> + !(new_log->file= fopen(new_log->path, "a+")))
> + {
> + /* File path too long || Check errno for the cause */
> + my_free(new_log);
I'm not sure, but I think that my_free() will reset errno, so the caller
won't be able to see what was wrong.
To solve it, I think, you can fopen() first, and malloc() later, at the
end.
Indeed, file operations have a much higher chance of failing than a small
allocation, so they should be done first.
> + return 0;
> + }
> +
> + setbuf(new_log->file, 0);
> + fseek(new_log->file, 0, SEEK_END);
> + pthread_mutex_init(&new_log->lock, MY_MUTEX_INIT_FAST);
Is that 5.5?
use performance schema instrumentation for i/o and mutexes.
(ask me on irc, I can explain how)
> + return new_log;
> +}
> +
> +int logrotate_close(LOGROTATE_FILE *log)
> +{
> + int result;
> + pthread_mutex_destroy(&log->lock);
> + result= fclose(log->file);
> + my_free(log);
> + return result;
> +}
> +
> +
> +static char *logname(LOGROTATE_FILE *log, char *buf, unsigned int n_log)
> +{
> + unsigned int n_zeroes;
> + size_t path_len= log->path_len;
> + buf[path_len++]= '.';
> + for (n_zeroes= log->index_len - n_dig(n_log);
> + n_zeroes > 0; n_zeroes--, path_len++)
> + buf[path_len]= '0';
I think you're overcomplicating. index_len is at most three.
I'd simply do
strcpy(buf+path_len, ".000");
int10_to_str(...)
because int10_to_str will add '\0' at the end, in the correct place.
Or, even simpler, just use sprintf("%0*d") - this logname function
is never used in the tight loop, you don't need to squeeze every
last CPU cycle out of it. Being simple is more important here.
> +
> + int10_to_str(n_log, buf+path_len, 10);
> + return buf;
> +}
> +
> +
> +static int do_rotate(LOGROTATE_FILE *log)
> +{
> + char namebuf[FN_REFLEN];
> + struct stat stbuf;
> + int result;
> + unsigned int i;
> + char *buf_old, *buf_new, *tmp;
> +
> + memcpy(namebuf, log->path, log->path_len);
> +
> + /* Delete the latest logfile if exists */
> + if (!stat(logname(log, namebuf, log->rotations), &stbuf) &&
> + (result= remove(namebuf)))
> + return result;
No need to remove old file, just rename. see below.
> +
> + buf_new= namebuf;
> + buf_old= log->path;
> + for (i=log->rotations-1; i>0; i--)
> + {
> + logname(log, buf_old, i);
> + if (!stat(buf_old, &stbuf) &&
> + (result= rename(buf_old, buf_new)))
> + return result;
Use my_rename(). And don't bother if the old file exists.
> + tmp= buf_old;
> + buf_old= buf_new;
> + buf_new= tmp;
> + }
> + if ((result= fclose(log->file)))
> + return result;
> + namebuf[log->path_len]= 0;
> + result= rename(namebuf, logname(log, log->path, 1));
> + log->file= fopen(namebuf, "a+");
> + return log->file==NULL || result;
> +}
> +
> +
> +int logrotate_vprintf(LOGROTATE_FILE *log, const char* fmt, va_list ap)
> +{
> + int result;
> + pthread_mutex_lock(&log->lock);
> + if (ftell(log->file) >= log->size_limit &&
> + do_rotate(log))
> + {
> + result= -1;
> + goto exit; /* Log rotation needed but failed */
> + }
> +
> + result= vfprintf(log->file, fmt, ap);
my_vprintf
> +exit:
> + pthread_mutex_unlock(&log->lock);
> + return result;
> +}
> +
> +
> +int logrotate_rotate(LOGROTATE_FILE *log)
> +{
> + int result;
> + pthread_mutex_lock(&log->lock);
> + result= do_rotate(log);
> + pthread_mutex_unlock(&log->lock);
> + return result;
> +}
> +
> +
> +int logrotate_printf(LOGROTATE_FILE *log, const char *fmt, ...)
> +{
> + int result;
> + va_list args;
> + va_start(args,fmt);
> + result= logrotate_vprintf(log, fmt, args);
> + va_end(args);
> + return result;
> +}
> +} /*extern C*/
2
2

Re: [Maria-developers] [Commits] Rev 3103: Make subquery cache off by default. in file:///home/bell/maria/bzr/work-maria-5.3-off/
by Sergey Petrunya 14 Jul '11
by Sergey Petrunya 14 Jul '11
14 Jul '11
Hi Sanja,
There are TWO possible options:
subquery_cache=on
subquery_cache=off
subselect.test is run THREE times
- as t/subselect.test
- as subselect_scache.test
- as subselect_no_scache.test
Apparently one of the runs is redundant. Please run it only TWO times.
Ok to push after this is addressed. Please ping me on irc when you've pushed.
On Thu, Jul 14, 2011 at 12:11:12PM +0300, sanja(a)askmonty.org wrote:
> At file:///home/bell/maria/bzr/work-maria-5.3-off/
>
> ------------------------------------------------------------
> revno: 3103
> revision-id: sanja(a)askmonty.org-20110714091111-w1mlc85tn0o6zz5d
> parent: psergey(a)askmonty.org-20110713124952-n060gka7r3gxlrdk
> committer: sanja(a)askmonty.org
> branch nick: work-maria-5.3-off
> timestamp: Thu 2011-07-14 12:11:11 +0300
> message:
> Make subquery cache off by default.
> === modified file 'mysql-test/r/compare.result'
> --- a/mysql-test/r/compare.result 2010-09-06 12:34:24 +0000
> +++ b/mysql-test/r/compare.result 2011-07-14 09:11:11 +0000
> @@ -88,7 +88,7 @@ id select_type table type possible_keys
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`>((select count(0) from `test`.`t1` where ((`test`.`t1`.`b` = `test`.`t2`.`a`) and (concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01'))))) AS `x` from `test`.`t2` order by `test`.`t2`.`a`
> +Note 1003 select `test`.`t2`.`a` AS `a`,(select count(0) from `test`.`t1` where ((`test`.`t1`.`b` = `test`.`t2`.`a`) and (concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01')))) AS `x` from `test`.`t2` order by `test`.`t2`.`a`
> DROP TABLE t1,t2;
> CREATE TABLE t1 (a TIMESTAMP);
> INSERT INTO t1 VALUES (NOW()),(NOW()),(NOW());
>
> === modified file 'mysql-test/r/derived_view.result'
> --- a/mysql-test/r/derived_view.result 2011-07-11 00:19:45 +0000
> +++ b/mysql-test/r/derived_view.result 2011-07-14 09:11:11 +0000
> @@ -755,7 +755,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> 3 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort
> Warnings:
> -Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <expr_cache><`test`.`t3`.`a`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select `v1`.`a` from `test`.`v1` join `test`.`t2` where ((`test`.`t2`.`a` = `v1`.`b`) and (<cache>(`test`.`t3`.`a`) = `v1`.`a`)))))
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`a`,<exists>(select `v1`.`a` from `test`.`v1` join `test`.`t2` where ((`test`.`t2`.`a` = `v1`.`b`) and (<cache>(`test`.`t3`.`a`) = `v1`.`a`))))
> SELECT * FROM t3
> WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b);
> a
> @@ -962,7 +962,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> 3 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t1` left join `test`.`t2` on((0 <> 0)) where <expr_cache><0>(<in_optimizer>(0,<exists>(select 0 from `test`.`t1` where (<cache>(0) = 0))))
> +Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t1` left join `test`.`t2` on((0 <> 0)) where <in_optimizer>(0,<exists>(select 0 from `test`.`t1` where (<cache>(0) = 0)))
> SELECT * FROM t2 RIGHT JOIN v1 AS t ON t.a != 0
> WHERE t.a IN (SELECT b FROM t1);
> a a b
> @@ -975,6 +975,6 @@ id select_type table type possible_keys
> 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t1` left join `test`.`t2` on((0 <> 0)) where <expr_cache><0>(<in_optimizer>(0,<exists>(select 0 from `test`.`t1` where (<cache>(0) = 0))))
> +Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t1` left join `test`.`t2` on((0 <> 0)) where <in_optimizer>(0,<exists>(select 0 from `test`.`t1` where (<cache>(0) = 0)))
> DROP VIEW v1;
> DROP TABLE t1,t2;
>
> === modified file 'mysql-test/r/explain.result'
> --- a/mysql-test/r/explain.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/explain.result 2011-07-14 09:11:11 +0000
> @@ -228,7 +228,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> 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 `test`.`t1`
> +Note 1003 select (select 1 from `test`.`t2` where (`test`.`t2`.`d` = NULL)) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1`
> DROP TABLE t1, t2;
> #
> # Bug #48419: another explain crash..
>
> === modified file 'mysql-test/r/group_by.result'
> --- a/mysql-test/r/group_by.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/group_by.result 2011-07-14 09:11:11 +0000
> @@ -1742,7 +1742,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t1`.`a`>((select `test`.`t1`.`a`)) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by (<expr_cache><`test`.`t1`.`a`>((select `test`.`t1`.`a`)) + 0)
> +Note 1003 select (select `test`.`t1`.`a`) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by ((select `test`.`t1`.`a`) + 0)
> EXPLAIN EXTENDED
> SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
> id select_type table type possible_keys key key_len ref rows filtered Extra
> @@ -1750,7 +1750,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t1`.`a`>((select `test`.`t1`.`a`)) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by -(<expr_cache><`test`.`t1`.`a`>((select `test`.`t1`.`a`)))
> +Note 1003 select (select `test`.`t1`.`a`) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by -((select `test`.`t1`.`a`))
> # should return only one record
> SELECT (SELECT tt.a FROM t1 tt LIMIT 1) aa, COUNT(DISTINCT b) FROM t1
> GROUP BY aa;
>
> === modified file 'mysql-test/r/join_outer.result'
> --- a/mysql-test/r/join_outer.result 2011-05-28 02:11:32 +0000
> +++ b/mysql-test/r/join_outer.result 2011-07-14 09:11:11 +0000
> @@ -1438,7 +1438,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.t2.pk' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`pk` AS `pk`,<expr_cache><`test`.`t2`.`pk`>((select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1)) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk`
> +Note 1003 select `test`.`t2`.`pk` AS `pk`,(select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk`
> select t2.pk,
> (select t3.pk+if(isnull(t4.pk),0,t4.pk)
> from t3 left join t4 on t4.pk=t3.pk
>
> === modified file 'mysql-test/r/join_outer_jcl6.result'
> --- a/mysql-test/r/join_outer_jcl6.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/join_outer_jcl6.result 2011-07-14 09:11:11 +0000
> @@ -1446,7 +1446,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.t2.pk' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`pk` AS `pk`,<expr_cache><`test`.`t2`.`pk`>((select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1)) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk`
> +Note 1003 select `test`.`t2`.`pk` AS `pk`,(select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk`
> select t2.pk,
> (select t3.pk+if(isnull(t4.pk),0,t4.pk)
> from t3 left join t4 on t4.pk=t3.pk
>
> === modified file 'mysql-test/r/optimizer_switch.result'
> --- a/mysql-test/r/optimizer_switch.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/optimizer_switch.result 2011-07-14 09:11:11 +0000
> @@ -4,19 +4,19 @@
> #
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='index_merge=off,index_merge_union=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='index_merge_union=on';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,index_merge_sort_union=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch=4;
> ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
> set optimizer_switch=NULL;
> @@ -43,60 +43,60 @@ set optimizer_switch=default;
> set optimizer_switch='index_merge=off,index_merge_union=off,default';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch=default;
> select @@global.optimizer_switch;
> @@global.optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set @@global.optimizer_switch=default;
> select @@global.optimizer_switch;
> @@global.optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> #
> # Check index_merge's @@optimizer_switch flags
> #
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
>
> BUG#37120 optimizer_switch allowable values not according to specification
>
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,materialization=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,semijoin=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,loosescan=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,semijoin=off,materialization=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,materialization=off,semijoin=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,semijoin=off,materialization=off,loosescan=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,semijoin=off,loosescan=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch='default,materialization=off,loosescan=off';
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> set optimizer_switch=default;
> select @@optimizer_switch;
> @@optimizer_switch
> -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
> +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on
>
> === modified file 'mysql-test/r/subselect.result'
> --- a/mysql-test/r/subselect.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect.result 2011-07-14 09:11:11 +0000
> @@ -55,7 +55,7 @@ id select_type table type possible_keys
> 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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +Note 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> 1
> 1
> @@ -318,7 +318,7 @@ NULL UNION RESULT <union2,3> ALL NULL NU
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +Note 1003 select (select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> ERROR 21000: Subquery returns more than 1 row
> create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> @@ -336,7 +336,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> Warnings:
> Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> ERROR 23000: Column 'a' in field list is ambiguous
> drop table t1,t2,t3;
> @@ -750,7 +750,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> id
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> @@ -898,7 +898,7 @@ id select_type table type possible_keys
> 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
> 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`,<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');
> INSERT INTO t3 VALUES (1),(2),(3);
> SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> @@ -913,7 +913,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> drop table t1,t2,t3;
> create table t1 (a float);
> select 10.5 IN (SELECT * from t1 LIMIT 1);
> @@ -1474,25 +1474,25 @@ id select_type table type possible_keys
> 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
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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`,<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
> 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(<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;
> create table t2 (a int, b int);
> create table t3 (a int);
> @@ -1747,14 +1747,14 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> @@ -2290,7 +2290,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> drop table t1;
> CREATE TABLE t1 (t1_a int);
> INSERT INTO t1 VALUES (1);
> @@ -2831,7 +2831,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> @@ -2843,7 +2843,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> DROP TABLE t1,t2;
> CREATE TABLE t1 (a char(5), b char(5));
> INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> @@ -4326,13 +4326,13 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> 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
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> DROP TABLE t1;
> #
> # Bug#45061: Incorrectly market field caused wrong result.
>
> === modified file 'mysql-test/r/subselect3.result'
> --- a/mysql-test/r/subselect3.result 2011-07-04 21:44:15 +0000
> +++ b/mysql-test/r/subselect3.result 2011-07-14 09:11:11 +0000
> @@ -32,7 +32,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `Z` from `test`.`t2`
> explain extended
> select a, oref from t2
> where a in (select max(ie) from t1 where oref=t2.oref group by grp);
> @@ -41,7 +41,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))
> select a, oref, a in (
> select max(ie) from t1 where oref=t2.oref group by grp union
> select max(ie) from t1 where oref=t2.oref group by grp
> @@ -72,7 +72,7 @@ id select_type table type possible_keys
> 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select <expr_cache><`test`.`t3`.`a`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
> +Note 1003 select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
> set @@optimizer_switch=@save_optimizer_switch;
> drop table t1, t2, t3;
> create table t1 (a int, oref int, key(a));
> @@ -97,7 +97,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))) AS `Z` from `test`.`t2`
> flush status;
> select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
> oref a
> @@ -164,7 +164,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref a a 5 test.t1.b 1 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<expr_cache><`test`.`t3`.`a`,`test`.`t3`.`oref`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and (`test`.`t2`.`a` = `test`.`t1`.`b`)) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))) AS `Z` from `test`.`t3`
> +Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and (`test`.`t2`.`a` = `test`.`t1`.`b`)) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))) AS `Z` from `test`.`t3`
> drop table t1, t2, t3;
> create table t1 (a int NOT NULL, b int NOT NULL, key(a));
> insert into t1 values
> @@ -192,7 +192,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref a a 4 test.t1.b 1 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<expr_cache><`test`.`t3`.`a`,`test`.`t3`.`oref`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`)) and (`test`.`t2`.`a` = `test`.`t1`.`b`))))) AS `Z` from `test`.`t3`
> +Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`)) and (`test`.`t2`.`a` = `test`.`t1`.`b`)))) AS `Z` from `test`.`t3`
> drop table t1,t2,t3;
> create table t1 (oref int, grp int);
> insert into t1 (oref, grp) values
> @@ -216,7 +216,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select count(0) from `test`.`t1` group by `test`.`t1`.`grp` having ((`test`.`t1`.`grp` = `test`.`t2`.`oref`) and trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(count(0)))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select count(0) from `test`.`t1` group by `test`.`t1`.`grp` having ((`test`.`t1`.`grp` = `test`.`t2`.`oref`) and trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(count(0))))))) AS `Z` from `test`.`t2`
> drop table t1, t2;
> create table t1 (a int, b int, primary key (a));
> insert into t1 values (1,1), (3,1),(100,1);
> @@ -248,7 +248,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
> select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
> a b oref Z
> NULL 1 100 0
> @@ -265,7 +265,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))) AS `Z` from `test`.`t2`
> select a,b, oref,
> (a,b) in (select a,b from t1,t4 where c=t2.oref) Z
> from t2;
> @@ -310,7 +310,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`b` = 10) and (`test`.`t2`.`a` = 10))
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`)))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`b` = 10) and (`test`.`t2`.`a` = 10))
> drop table t1, t2;
> create table t1 (oref char(4), grp int, ie int);
> insert into t1 (oref, grp, ie) values
> @@ -580,7 +580,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`)))))) AS `Z` from `test`.`t2`
> drop table t1,t2;
> create table t1 (oref char(4), grp int, ie int primary key);
> insert into t1 (oref, grp, ie) values
> @@ -711,7 +711,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))))))
> SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
> a
> SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
>
> === modified file 'mysql-test/r/subselect3_jcl6.result'
> --- a/mysql-test/r/subselect3_jcl6.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect3_jcl6.result 2011-07-14 09:11:11 +0000
> @@ -40,7 +40,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `Z` from `test`.`t2`
> explain extended
> select a, oref from t2
> where a in (select max(ie) from t1 where oref=t2.oref group by grp);
> @@ -49,7 +49,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))
> select a, oref, a in (
> select max(ie) from t1 where oref=t2.oref group by grp union
> select max(ie) from t1 where oref=t2.oref group by grp
> @@ -80,7 +80,7 @@ id select_type table type possible_keys
> 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select <expr_cache><`test`.`t3`.`a`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`))))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
> +Note 1003 select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
> set @@optimizer_switch=@save_optimizer_switch;
> drop table t1, t2, t3;
> create table t1 (a int, oref int, key(a));
> @@ -105,7 +105,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))) AS `Z` from `test`.`t2`
> flush status;
> select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
> oref a
> @@ -172,7 +172,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref a a 5 test.t1.b 1 100.00 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
> Warnings:
> Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<expr_cache><`test`.`t3`.`a`,`test`.`t3`.`oref`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and (`test`.`t2`.`a` = `test`.`t1`.`b`)) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))) AS `Z` from `test`.`t3`
> +Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and (`test`.`t2`.`a` = `test`.`t1`.`b`)) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))) AS `Z` from `test`.`t3`
> drop table t1, t2, t3;
> create table t1 (a int NOT NULL, b int NOT NULL, key(a));
> insert into t1 values
> @@ -200,7 +200,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref a a 4 test.t1.b 1 100.00 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
> Warnings:
> Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<expr_cache><`test`.`t3`.`a`,`test`.`t3`.`oref`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`)) and (`test`.`t2`.`a` = `test`.`t1`.`b`))))) AS `Z` from `test`.`t3`
> +Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`)) and (`test`.`t2`.`a` = `test`.`t1`.`b`)))) AS `Z` from `test`.`t3`
> drop table t1,t2,t3;
> create table t1 (oref int, grp int);
> insert into t1 (oref, grp) values
> @@ -224,7 +224,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select count(0) from `test`.`t1` group by `test`.`t1`.`grp` having ((`test`.`t1`.`grp` = `test`.`t2`.`oref`) and trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(count(0)))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select count(0) from `test`.`t1` group by `test`.`t1`.`grp` having ((`test`.`t1`.`grp` = `test`.`t2`.`oref`) and trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(count(0))))))) AS `Z` from `test`.`t2`
> drop table t1, t2;
> create table t1 (a int, b int, primary key (a));
> insert into t1 values (1,1), (3,1),(100,1);
> @@ -256,7 +256,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
> select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
> a b oref Z
> NULL 1 100 0
> @@ -273,7 +273,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))) AS `Z` from `test`.`t2`
> select a,b, oref,
> (a,b) in (select a,b from t1,t4 where c=t2.oref) Z
> from t2;
> @@ -318,7 +318,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`b` = 10) and (`test`.`t2`.`a` = 10))
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`)))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`b` = 10) and (`test`.`t2`.`a` = 10))
> drop table t1, t2;
> create table t1 (oref char(4), grp int, ie int);
> insert into t1 (oref, grp, ie) values
> @@ -588,7 +588,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
> Warnings:
> Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`b`,`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2`
> +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`)))))) AS `Z` from `test`.`t2`
> drop table t1,t2;
> create table t1 (oref char(4), grp int, ie int primary key);
> insert into t1 (oref, grp, ie) values
> @@ -719,7 +719,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))))))
> SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
> a
> SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
>
> === modified file 'mysql-test/r/subselect4.result'
> --- a/mysql-test/r/subselect4.result 2011-07-09 07:20:15 +0000
> +++ b/mysql-test/r/subselect4.result 2011-07-14 09:11:11 +0000
> @@ -224,7 +224,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> Warnings:
> 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 0)) AS `RESULT` from `test`.`t1`
> +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from `test`.`t1`
> first equivalent variant
> SELECT (SELECT 1 FROM t2 WHERE d = IFNULL(c,NULL)) AS RESULT FROM t1 GROUP BY c ;
> RESULT
> @@ -235,7 +235,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> Warnings:
> 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 0)) AS `RESULT` from `test`.`t1` group by NULL
> +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from `test`.`t1` group by NULL
> second equivalent variant
> SELECT (SELECT 1 FROM t2 WHERE d = c) AS RESULT FROM t1 GROUP BY c ;
> RESULT
> @@ -246,7 +246,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> Warnings:
> 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 0)) AS `RESULT` from `test`.`t1` group by NULL
> +Note 1003 select (select 1 from `test`.`t2` where 0) AS `RESULT` from `test`.`t1` group by NULL
> DROP TABLE t1,t2;
> #
> # BUG#45928 "Differing query results depending on MRR and
>
> === modified file 'mysql-test/r/subselect_mat.result'
> --- a/mysql-test/r/subselect_mat.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect_mat.result 2011-07-14 09:11:11 +0000
> @@ -48,7 +48,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`)))))
> select * from t1 where a1 in (select b1 from t2 where b1 > '0');
> a1 a2
> 1 - 01 2 - 01
> @@ -59,7 +59,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`)))))
> select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -70,7 +70,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`)))))
> select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
> a1 a2
> 1 - 01 2 - 01
> @@ -81,7 +81,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`min(b2)`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))))
> select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -92,7 +92,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
> 2 SUBQUERY t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`)))))
> select * from t1i where a1 in (select b1 from t2i where b1 > '0');
> a1 a2
> 1 - 01 2 - 01
> @@ -103,7 +103,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL # 18 # 3 100.00 #
> 2 SUBQUERY t2i range it2i1,it2i3 # 9 # 3 100.00 #
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`)))))
> select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -114,7 +114,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
> 2 SUBQUERY t2i index it2i1,it2i3 it2i3 # NULL 5 100.00 Using where;
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`)))))
> select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
> a1 a2
> 1 - 01 2 - 01
> @@ -125,7 +125,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL # # # 3 100.00 #
> 2 SUBQUERY t2i range it2i1,it2i3 # # # 3 100.00 #
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`)))))
> select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
> a1 a2
> 1 - 01 2 - 01
> @@ -136,7 +136,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL # # # 3 100.00 #
> 2 SUBQUERY t2i range it2i1,it2i3 # # # 3 100.00 #
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`min(b2)`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`min(b2)`)))))
> select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -147,7 +147,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2i range NULL it2i3 9 NULL 3 100.00 Using index for group-by
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`max(b2)`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`max(b2)`)))))
> select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -176,7 +176,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2i range it2i1,it2i3 it2i3 18 NULL 3 100.00 Using where; Using index for group-by
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`min(b2)`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))))
> select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
> a1 a2
> 1 - 01 2 - 01
> @@ -223,7 +223,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`)))))
> select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
> a1 a2
> 1 - 01 2 - 01
> @@ -234,7 +234,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index
> 2 SUBQUERY t2i index NULL it2i3 18 NULL 5 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`)))))
> select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
> a1 a2
> 1 - 01 2 - 01
> @@ -289,7 +289,7 @@ id select_type table type possible_keys
> 4 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`)))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery4>`.`b1`) and (`test`.`t3`.`c2` = `<subquery4>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery3>`.`c1`) and (`test`.`t1`.`a2` = `<subquery3>`.`c2`)))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery4>`.`b1`) and (`test`.`t3`.`c2` = `<subquery4>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery3>`.`c1`) and (`test`.`t1`.`a2` = `<subquery3>`.`c2`))))))
> select * from t1
> where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
> (a1, a2) in (select c1, c2 from t3
> @@ -308,7 +308,7 @@ id select_type table type possible_keys
> 4 SUBQUERY t2i index it2i2 # # # 5 100.00 #
> 2 SUBQUERY t2i index it2i1,it2i3 # # # 5 100.00 #
> Warnings:
> -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`)))))) and <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c2`,`test`.`t3i`.`c1`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where ((`test`.`t3i`.`c1` = `<subquery4>`.`b1`) and (`test`.`t3i`.`c2` = `<subquery4>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery3>`.`c1`) and (`test`.`t1i`.`a2` = `<subquery3>`.`c2`)))))))
> +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery2>`.`b2`))))) and <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where ((`test`.`t3i`.`c1` = `<subquery4>`.`b1`) and (`test`.`t3i`.`c2` = `<subquery4>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery3>`.`c1`) and (`test`.`t1i`.`a2` = `<subquery3>`.`c2`))))))
> select * from t1i
> where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
> (a1, a2) in (select c1, c2 from t3i
> @@ -331,7 +331,7 @@ id select_type table type possible_keys
> 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> 3 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`)))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`)))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3`.`c2` = `<subquery6>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`)))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3`.`c2` = `<subquery6>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`))))))
> select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 where c2 LIKE '%02') or
> @@ -356,7 +356,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <expr_cache><`test`.`t3c`.`c2`,`test`.`t3c`.`c1`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3c`.`c1` in <temporary table> on distinct_key where ((`test`.`t3c`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3c`.`c2` = `<subquery6>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`)))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3c`.`c1` in <temporary table> on distinct_key where ((`test`.`t3c`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3c`.`c2` = `<subquery6>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`))))))
> select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 t3a where c1 = a1) or
> @@ -392,7 +392,7 @@ id select_type table type possible_keys
> 8 SUBQUERY t2i index it2i1,it2i3 # # # 5 100.00 #
> NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
> Warnings:
> -Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`)))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`)))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3`.`c2` = `<subquery6>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`)))))))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery8>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery8>`.`b2`)))))) and <expr_cache><`test`.`t1i`.`a2`,`test`.`t1i`.`a1`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c2`,`test`.`t3i`.`c1`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where ((`test`.`t3i`.`c1` = `<subquery10>`.`b1`) and (`test`.`t3i`.`c2` = `<subquery10>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery9>`.`c1`) and (`test`.`t1i`.`a2` = `<subquery9>`.`c2`))))))))
> +Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3`.`c2` = `<subquery6>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`))))))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery8>`.`b1`) and (`test`.`t1i`.`a2` = `<subquery8>`.`b2`))))) and <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where ((`test`.`t3i`.`c1` = `<subquery10>`.`b1`) and (`test`.`t3i`.`c2` = `<subquery10>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where ((`test`.`t1i`.`a1` = `<subquery9>`.`c1`) and (`test`.`t1i`.`a2` = `<subquery9>`.`c2`)))))))
> (select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 where c2 LIKE '%02') or
> @@ -421,7 +421,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery5>`.`b1`) and (`test`.`t3`.`c2` = `<subquery5>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery4>`.`c1`) and (`test`.`t1`.`a2` = `<subquery4>`.`c2`)))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery5>`.`b1`) and (`test`.`t3`.`c2` = `<subquery5>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery4>`.`c1`) and (`test`.`t1`.`a2` = `<subquery4>`.`c2`))))))
> select * from t1
> where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
> (a1, a2) in (select c1, c2 from t3
> @@ -444,7 +444,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`c1` = `test`.`t1`.`a1`) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c2`,`test`.`t3`.`c1`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery5>`.`b1`) and (`test`.`t3`.`c2` = `<subquery5>`.`b2`)))))) ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery4>`.`c1`) and (`test`.`t3`.`c2` = `<subquery4>`.`c2`)))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`c1` = `test`.`t1`.`a1`) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery5>`.`b1`) and (`test`.`t3`.`c2` = `<subquery5>`.`b2`))))) ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery4>`.`c1`) and (`test`.`t3`.`c2` = `<subquery4>`.`c2`))))))
> select * from t1, t3
> where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
> (c1, c2) in (select c1, c2 from t3
> @@ -466,7 +466,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`>(<in_optimizer>(`test`.`t3`.`c1`,<exists>(select `test`.`t1`.`a1` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select `test`.`t2`.`b1` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`)))))
> +Note 1003 select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`c1`,<exists>(select `test`.`t1`.`a1` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select `test`.`t2`.`b1` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))))
> select * from t3
> where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
> c1 c2
> @@ -490,14 +490,14 @@ id select_type table type possible_keys
> Warnings:
> Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where (<expr_cache><`test`.`t3c`.`c2`,`test`.`t3c`.`c1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),<exists>(<index_lookup>(<cache>(`test`.`t3c`.`c1`) in t2i on it2i3 where (((`test`.`t2i`.`b2` > '0') or (`test`.`t2i`.`b2` = `test`.`t1`.`a2`)) and (<cache>(`test`.`t3c`.`c1`) = `test`.`t2i`.`b1`) and (<cache>(`test`.`t3c`.`c2`) = `test`.`t2i`.`b2`)))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t3c`.`c1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t3c`.`c2`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where (<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),<exists>(<index_lookup>(<cache>(`test`.`t3c`.`c1`) in t2i on it2i3 where (((`test`.`t2i`.`b2` > '0') or (`test`.`t2i`.`b2` = `test`.`t1`.`a2`)) and (<cache>(`test`.`t3c`.`c1`) = `test`.`t2i`.`b1`) and (<cache>(`test`.`t3c`.`c2`) = `test`.`t2i`.`b2`))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t3c`.`c1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t3c`.`c2`)))))
> explain extended
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01')))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01'))))
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
> a1 a2
> 1 - 01 2 - 01
> @@ -507,7 +507,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01')))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01'))))
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
> a1 a2
> 1 - 01 2 - 01
> @@ -539,7 +539,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort
> 2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond((<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond((<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`)))))
> select * from t1 group by (a1 in (select col from columns));
> a1 a2
> 1 - 00 2 - 00
> @@ -596,7 +596,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select `test`.`t2_16`.`b1` from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`)))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select `test`.`t2_16`.`b1` from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))
> select left(a1,7), left(a2,7)
> from t1_16
> where a1 in (select b1 from t2_16 where b1 > '0');
> @@ -610,7 +610,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a2`,`test`.`t1_16`.`a1`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`)))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))))
> select left(a1,7), left(a2,7)
> from t1_16
> where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
> @@ -624,7 +624,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select substr(`test`.`t2_16`.`b1`,1,16) from `test`.`t2_16` where (`test`.`t2_16`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_16`.`a1` = `<subquery2>`.`substring(b1,1,16)`))))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select substr(`test`.`t2_16`.`b1`,1,16) from `test`.`t2_16` where (`test`.`t2_16`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_16`.`a1` = `<subquery2>`.`substring(b1,1,16)`)))))
> select left(a1,7), left(a2,7)
> from t1_16
> where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
> @@ -638,7 +638,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having (<cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ','))))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having (<cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ',')))))
> select left(a1,7), left(a2,7)
> from t1_16
> where a1 in (select group_concat(b1) from t2_16 group by b2);
> @@ -653,7 +653,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_16`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_16`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_16
> where a1 in (select group_concat(b1) from t2_16 group by b2);
> @@ -675,7 +675,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
> 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><concat(`test`.`t1`.`a1`,'x')>(<in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(select left(`test`.`t1_16`.`a1`,8) from `test`.`t1_16` where (<expr_cache><`test`.`t1_16`.`a2`,`test`.`t1_16`.`a1`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` join `test`.`t2` where ((`test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6)) and <expr_cache><`test`.`t2`.`b1`>(<in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (select `test`.`t3`.`c1` from `test`.`t3` where (`test`.`t3`.`c2` > '0') ), <primary_index_lookup>(`test`.`t2`.`b1` in <temporary table> on distinct_key where ((`test`.`t2`.`b1` = `<subquery4>`.`c1`)))))) and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))))) and (<cache>(concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(select left(`test`.`t1_16`.`a1`,8) from `test`.`t1_16` where (<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` join `test`.`t2` where ((`test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6)) and <in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (select `test`.`t3`.`c1` from `test`.`t3` where (`test`.`t3`.`c2` > '0') ), <primary_index_lookup>(`test`.`t2`.`b1` in <temporary table> on distinct_key where ((`test`.`t2`.`b1` = `<subquery4>`.`c1`))))) and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`)))) and (<cache>(concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))))
> drop table t1_16, t2_16, t3_16;
> set @blob_len = 512;
> set @suffix_len = @blob_len - @prefix_len;
> @@ -709,7 +709,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,<exists>(select `test`.`t2_512`.`b1` from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`)))))
> +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,<exists>(select `test`.`t2_512`.`b1` from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`))))
> select left(a1,7), left(a2,7)
> from t1_512
> where a1 in (select b1 from t2_512 where b1 > '0');
> @@ -723,7 +723,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a2`,`test`.`t1_512`.`a1`>(<in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(select `test`.`t2_512`.`b1`,`test`.`t2_512`.`b2` from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`) and (<cache>(`test`.`t1_512`.`a2`) = `test`.`t2_512`.`b2`)))))
> +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(select `test`.`t2_512`.`b1`,`test`.`t2_512`.`b2` from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`) and (<cache>(`test`.`t1_512`.`a2`) = `test`.`t2_512`.`b2`))))
> select left(a1,7), left(a2,7)
> from t1_512
> where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
> @@ -737,7 +737,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select substr(`test`.`t2_512`.`b1`,1,512) from `test`.`t2_512` where (`test`.`t2_512`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`substring(b1,1,512)`))))))
> +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select substr(`test`.`t2_512`.`b1`,1,512) from `test`.`t2_512` where (`test`.`t2_512`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`substring(b1,1,512)`)))))
> select left(a1,7), left(a2,7)
> from t1_512
> where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
> @@ -751,7 +751,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_512
> where a1 in (select group_concat(b1) from t2_512 group by b2);
> @@ -764,7 +764,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_512
> where a1 in (select group_concat(b1) from t2_512 group by b2);
> @@ -802,7 +802,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(select `test`.`t2_1024`.`b1` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`)))))
> +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(select `test`.`t2_1024`.`b1` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`))))
> select left(a1,7), left(a2,7)
> from t1_1024
> where a1 in (select b1 from t2_1024 where b1 > '0');
> @@ -816,7 +816,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a2`,`test`.`t1_1024`.`a1`>(<in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(select `test`.`t2_1024`.`b1`,`test`.`t2_1024`.`b2` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`) and (<cache>(`test`.`t1_1024`.`a2`) = `test`.`t2_1024`.`b2`)))))
> +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(select `test`.`t2_1024`.`b1`,`test`.`t2_1024`.`b2` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`) and (<cache>(`test`.`t1_1024`.`a2`) = `test`.`t2_1024`.`b2`))))
> select left(a1,7), left(a2,7)
> from t1_1024
> where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
> @@ -830,7 +830,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(select substr(`test`.`t2_1024`.`b1`,1,1024) from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024))))))
> +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(select substr(`test`.`t2_1024`.`b1`,1,1024) from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024)))))
> select left(a1,7), left(a2,7)
> from t1_1024
> where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
> @@ -844,7 +844,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_1024
> where a1 in (select group_concat(b1) from t2_1024 group by b2);
> @@ -857,7 +857,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_1024
> where a1 in (select group_concat(b1) from t2_1024 group by b2);
> @@ -895,7 +895,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(select `test`.`t2_1025`.`b1` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`)))))
> +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(select `test`.`t2_1025`.`b1` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`))))
> select left(a1,7), left(a2,7)
> from t1_1025
> where a1 in (select b1 from t2_1025 where b1 > '0');
> @@ -909,7 +909,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a2`,`test`.`t1_1025`.`a1`>(<in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(select `test`.`t2_1025`.`b1`,`test`.`t2_1025`.`b2` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`) and (<cache>(`test`.`t1_1025`.`a2`) = `test`.`t2_1025`.`b2`)))))
> +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(select `test`.`t2_1025`.`b1`,`test`.`t2_1025`.`b2` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`) and (<cache>(`test`.`t1_1025`.`a2`) = `test`.`t2_1025`.`b2`))))
> select left(a1,7), left(a2,7)
> from t1_1025
> where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
> @@ -923,7 +923,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(select substr(`test`.`t2_1025`.`b1`,1,1025) from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025))))))
> +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(select substr(`test`.`t2_1025`.`b1`,1,1025) from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025)))))
> select left(a1,7), left(a2,7)
> from t1_1025
> where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
> @@ -937,7 +937,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_1025
> where a1 in (select group_concat(b1) from t2_1025 group by b2);
> @@ -950,7 +950,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`))))))
> +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where ((`test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))))
> select left(a1,7), left(a2,7)
> from t1_1025
> where a1 in (select group_concat(b1) from t2_1025 group by b2);
> @@ -971,7 +971,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1bit ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 SUBQUERY t2bit ALL NULL NULL NULL NULL 3 100.00
> Warnings:
> -Note 1003 select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` where <expr_cache><`test`.`t1bit`.`a2`,`test`.`t1bit`.`a1`>(<in_optimizer>((`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`),(`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`) in ( <materialize> (select `test`.`t2bit`.`b1`,`test`.`t2bit`.`b2` from `test`.`t2bit` ), <primary_index_lookup>(`test`.`t1bit`.`a1` in <temporary table> on distinct_key where ((`test`.`t1bit`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1bit`.`a2` = `<subquery2>`.`b2`))))))
> +Note 1003 select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` where <in_optimizer>((`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`),(`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`) in ( <materialize> (select `test`.`t2bit`.`b1`,`test`.`t2bit`.`b2` from `test`.`t2bit` ), <primary_index_lookup>(`test`.`t1bit`.`a1` in <temporary table> on distinct_key where ((`test`.`t1bit`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1bit`.`a2` = `<subquery2>`.`b2`)))))
> select bin(a1), bin(a2)
> from t1bit
> where (a1, a2) in (select b1, b2 from t2bit);
> @@ -994,7 +994,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where
> Warnings:
> -Note 1003 select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` where <expr_cache><`test`.`t1bb`.`a2`,`test`.`t1bb`.`a1`>(<in_optimizer>((`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`),<exists>(select `test`.`t2bb`.`b1`,`test`.`t2bb`.`b2` from `test`.`t2bb` where ((<cache>(`test`.`t1bb`.`a1`) = `test`.`t2bb`.`b1`) and (<cache>(`test`.`t1bb`.`a2`) = `test`.`t2bb`.`b2`)))))
> +Note 1003 select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` where <in_optimizer>((`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`),<exists>(select `test`.`t2bb`.`b1`,`test`.`t2bb`.`b2` from `test`.`t2bb` where ((<cache>(`test`.`t1bb`.`a1`) = `test`.`t2bb`.`b1`) and (<cache>(`test`.`t1bb`.`a2`) = `test`.`t2bb`.`b2`))))
> select bin(a1), a2
> from t1bb
> where (a1, a2) in (select b1, b2 from t2bb);
> @@ -1042,7 +1042,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 where a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1056,7 +1056,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 where a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1070,7 +1070,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 where a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1083,7 +1083,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 group by a having a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1095,7 +1095,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 group by a having a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1109,7 +1109,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`,max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<expr_cache><`test`.`t2`.`d`,max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where (max(`test`.`t1`.`b`) = `test`.`t3`.`e`) having (<cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`)))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`)))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where (max(`test`.`t1`.`b`) = `test`.`t3`.`e`) having (<cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))))
> select a from t1 group by a
> having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
> a
> @@ -1124,7 +1124,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`)))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))))
> select a from t1
> where a in (select c from t2 where d >= some(select e from t3 where b=e));
> a
>
> === modified file 'mysql-test/r/subselect_mat_cost_bugs.result'
> --- a/mysql-test/r/subselect_mat_cost_bugs.result 2011-06-29 02:56:30 +0000
> +++ b/mysql-test/r/subselect_mat_cost_bugs.result 2011-07-14 09:11:11 +0000
> @@ -94,7 +94,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1a ref c2 c2 5 test.t1b.pk 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <expr_cache><`test`.`t1`.`c1`,`test`.`t1`.`pk`>(<in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t1a`.`c1` from `test`.`t1b` join `test`.`t2` left join `test`.`t1a` on((2 and (`test`.`t1a`.`c2` = `test`.`t1b`.`pk`))) where (`test`.`t1`.`pk` and (<cache>(`test`.`t1`.`c1`) = `test`.`t1a`.`c1`) and (`test`.`t1b`.`c4` = `test`.`t2`.`c3`)))))
> +Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t1a`.`c1` from `test`.`t1b` join `test`.`t2` left join `test`.`t1a` on((2 and (`test`.`t1a`.`c2` = `test`.`t1b`.`pk`))) where (`test`.`t1`.`pk` and (<cache>(`test`.`t1`.`c1`) = `test`.`t1a`.`c1`) and (`test`.`t1b`.`c4` = `test`.`t2`.`c3`))))
> SELECT pk
> FROM t1
> WHERE c1 IN
>
> === modified file 'mysql-test/r/subselect_no_mat.result'
> --- a/mysql-test/r/subselect_no_mat.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect_no_mat.result 2011-07-14 09:11:11 +0000
> @@ -60,7 +60,7 @@ id select_type table type possible_keys
> 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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +Note 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> 1
> 1
> @@ -323,7 +323,7 @@ NULL UNION RESULT <union2,3> ALL NULL NU
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +Note 1003 select (select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> ERROR 21000: Subquery returns more than 1 row
> create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> @@ -341,7 +341,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> Warnings:
> Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> ERROR 23000: Column 'a' in field list is ambiguous
> drop table t1,t2,t3;
> @@ -755,7 +755,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> id
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> @@ -903,7 +903,7 @@ id select_type table type possible_keys
> 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
> 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`,<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');
> INSERT INTO t3 VALUES (1),(2),(3);
> SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> @@ -918,7 +918,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> drop table t1,t2,t3;
> create table t1 (a float);
> select 10.5 IN (SELECT * from t1 LIMIT 1);
> @@ -1479,25 +1479,25 @@ id select_type table type possible_keys
> 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
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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`,<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
> 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(<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;
> create table t2 (a int, b int);
> create table t3 (a int);
> @@ -1752,14 +1752,14 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> @@ -2295,7 +2295,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> drop table t1;
> CREATE TABLE t1 (t1_a int);
> INSERT INTO t1 VALUES (1);
> @@ -2836,7 +2836,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> @@ -2848,7 +2848,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> DROP TABLE t1,t2;
> CREATE TABLE t1 (a char(5), b char(5));
> INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> @@ -4331,13 +4331,13 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> 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
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> DROP TABLE t1;
> #
> # Bug#45061: Incorrectly market field caused wrong result.
>
> === modified file 'mysql-test/r/subselect_no_opts.result'
> --- a/mysql-test/r/subselect_no_opts.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect_no_opts.result 2011-07-14 09:11:11 +0000
> @@ -56,7 +56,7 @@ id select_type table type possible_keys
> 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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +Note 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> 1
> 1
> @@ -319,7 +319,7 @@ NULL UNION RESULT <union2,3> ALL NULL NU
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +Note 1003 select (select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> ERROR 21000: Subquery returns more than 1 row
> create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> @@ -337,7 +337,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> Warnings:
> Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> ERROR 23000: Column 'a' in field list is ambiguous
> drop table t1,t2,t3;
> @@ -751,7 +751,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> id
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> @@ -899,7 +899,7 @@ id select_type table type possible_keys
> 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
> 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`,<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');
> INSERT INTO t3 VALUES (1),(2),(3);
> SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> @@ -914,7 +914,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> drop table t1,t2,t3;
> create table t1 (a float);
> select 10.5 IN (SELECT * from t1 LIMIT 1);
> @@ -1304,7 +1304,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1314,7 +1314,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1325,7 +1325,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where
> 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> drop table t1, t2, t3;
> create table t1 (a int, b int, index a (a,b));
> create table t2 (a int, index a (a));
> @@ -1347,7 +1347,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1357,7 +1357,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1368,7 +1368,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ref a a 5 func 1001 100.00 Using index
> 2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> insert into t1 values (3,31);
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> @@ -1384,7 +1384,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> drop table t0, t1, t2, t3;
> create table t1 (a int, b int);
> create table t2 (a int, b int);
> @@ -1475,25 +1475,25 @@ id select_type table type possible_keys
> 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
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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`,<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
> 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(<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;
> create table t2 (a int, b int);
> create table t3 (a int);
> @@ -1748,14 +1748,14 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> @@ -2291,7 +2291,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> drop table t1;
> CREATE TABLE t1 (t1_a int);
> INSERT INTO t1 VALUES (1);
> @@ -2832,19 +2832,19 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 Using where
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`)))))
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))
> explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> DROP TABLE t1,t2;
> CREATE TABLE t1 (a char(5), b char(5));
> INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> @@ -4327,13 +4327,13 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> 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
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> DROP TABLE t1;
> #
> # Bug#45061: Incorrectly market field caused wrong result.
>
> === added file 'mysql-test/r/subselect_no_scache.result'
> --- a/mysql-test/r/subselect_no_scache.result 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/r/subselect_no_scache.result 2011-07-14 09:11:11 +0000
> @@ -0,0 +1,5139 @@
> +select @@optimizer_switch like '%subquery_cache=on%';
> +@@optimizer_switch like '%subquery_cache=on%'
> +0
> +set optimizer_switch='subquery_cache=off';
> +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
> +drop view if exists v2;
> +set @subselect_tmp=@@optimizer_switch;
> +set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
> +"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
> +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
> +select (select 2);
> +(select 2)
> +2
> +explain extended select (select 2);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select 2 AS `(select 2)`
> +SELECT (SELECT 1) UNION SELECT (SELECT 2);
> +(SELECT 1)
> +1
> +2
> +explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1249 Select 4 was reduced during optimization
> +Note 1003 select 1 AS `(SELECT 1)` union select 2 AS `(SELECT 2)`
> +SELECT (SELECT (SELECT 0 UNION SELECT 0));
> +(SELECT (SELECT 0 UNION SELECT 0))
> +0
> +explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0));
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select (select 0 union select 0) AS `(SELECT (SELECT 0 UNION SELECT 0))`
> +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
> +ERROR 42S22: Reference 'a' not supported (forward reference in item list)
> +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
> +ERROR 42S22: Reference 'b' not supported (forward reference in item list)
> +SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
> +(SELECT 1) MAX(1)
> +1 1
> +SELECT (SELECT a) as a;
> +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;
> +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
> +3 DEPENDENT 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
> +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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> +SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> +1
> +1
> +SELECT (SELECT 1), a;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
> +a
> +1
> +SELECT 1 FROM (SELECT (SELECT a) b) c;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c ORDER BY id);
> +id
> +1
> +SELECT * FROM (SELECT 1) a WHERE 1 IN (SELECT 1,1);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT 1 IN (SELECT 1);
> +1 IN (SELECT 1)
> +1
> +SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
> +1
> +1
> +select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1));
> +ERROR HY000: Incorrect usage of PROCEDURE and subquery
> +SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1));
> +ERROR HY000: Incorrect parameters to procedure 'ANALYSE'
> +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT (SELECT 1,2,3) = ROW(1,2,3);
> +(SELECT 1,2,3) = ROW(1,2,3)
> +1
> +SELECT (SELECT 1,2,3) = ROW(1,2,1);
> +(SELECT 1,2,3) = ROW(1,2,1)
> +0
> +SELECT (SELECT 1,2,3) < ROW(1,2,1);
> +(SELECT 1,2,3) < ROW(1,2,1)
> +0
> +SELECT (SELECT 1,2,3) > ROW(1,2,1);
> +(SELECT 1,2,3) > ROW(1,2,1)
> +1
> +SELECT (SELECT 1,2,3) = ROW(1,2,NULL);
> +(SELECT 1,2,3) = ROW(1,2,NULL)
> +NULL
> +SELECT ROW(1,2,3) = (SELECT 1,2,3);
> +ROW(1,2,3) = (SELECT 1,2,3)
> +1
> +SELECT ROW(1,2,3) = (SELECT 1,2,1);
> +ROW(1,2,3) = (SELECT 1,2,1)
> +0
> +SELECT ROW(1,2,3) < (SELECT 1,2,1);
> +ROW(1,2,3) < (SELECT 1,2,1)
> +0
> +SELECT ROW(1,2,3) > (SELECT 1,2,1);
> +ROW(1,2,3) > (SELECT 1,2,1)
> +1
> +SELECT ROW(1,2,3) = (SELECT 1,2,NULL);
> +ROW(1,2,3) = (SELECT 1,2,NULL)
> +NULL
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a');
> +(SELECT 1.5,2,'a') = ROW(1.5,2,'a')
> +1
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b');
> +(SELECT 1.5,2,'a') = ROW(1.5,2,'b')
> +0
> +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b');
> +(SELECT 1.5,2,'a') = ROW('1.5b',2,'b')
> +0
> +Warnings:
> +Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
> +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
> +(SELECT 'b',2,'a') = ROW(1.5,2,'a')
> +0
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
> +(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
> +1
> +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
> +(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
> +0
> +SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT 1 as a,(SELECT a+a) b,(SELECT b);
> +a b (SELECT b)
> +1 2 2
> +create table t1 (a int);
> +create table t2 (a int, b int);
> +create table t3 (a int);
> +create table t4 (a int not null, b int not null);
> +insert into t1 values (2);
> +insert into t2 values (1,7),(2,7);
> +insert into t4 values (4,8),(3,8),(5,9);
> +select (select a from t1 where t1.a = a1) as a2, (select b from t2 where t2.b=a2) as a1;
> +ERROR 42S22: Reference 'a1' not supported (forward reference in item list)
> +select (select a from t1 where t1.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a) a
> +NULL 1
> +2 2
> +select (select a from t1 where t1.a=t2.b), a from t2;
> +(select a from t1 where t1.a=t2.b) a
> +NULL 1
> +NULL 2
> +select (select a from t1), a, (select 1 union select 2 limit 1) from t2;
> +(select a from t1) a (select 1 union select 2 limit 1)
> +2 1 1
> +2 2 1
> +select (select a from t3), a from t2;
> +(select a from t3) a
> +NULL 1
> +NULL 2
> +select * from t2 where t2.a=(select a from t1);
> +a b
> +2 7
> +insert into t3 values (6),(7),(3);
> +select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
> +a b
> +1 7
> +2 7
> +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 order by a limit 2) limit 3;
> +a b
> +1 7
> +2 7
> +3 8
> +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
> +a b
> +1 7
> +2 7
> +4 8
> +3 8
> +explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> +3 UNION t4 ALL NULL NULL NULL NULL 3 100.00 Using where
> +4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00
> +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`)
> +select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
> +(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
> +3 1
> +7 2
> +select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
> +(select * from t2 where a>1) as tt;
> +(select t3.a from t3 where a<8 order by 1 desc limit 1) a
> +7 2
> +explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
> +(select * from t2 where a>1) as tt;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using filesort
> +Warnings:
> +Note 1003 select (select `test`.`t3`.`a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,`test`.`t2`.`a` AS `a` from `test`.`t2` where (`test`.`t2`.`a` > 1)
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1);
> +a
> +2
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1);
> +a
> +2
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1);
> +a
> +select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
> +b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)
> +8 7.5000
> +8 4.5000
> +9 7.5000
> +explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00
> +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
> +Warnings:
> +Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
> +Note 1003 select `test`.`t4`.`b` AS `b`,(select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
> +select * from t3 where exists (select * from t2 where t2.b=t3.a);
> +a
> +7
> +select * from t3 where not exists (select * from t2 where t2.b=t3.a);
> +a
> +6
> +3
> +select * from t3 where a in (select b from t2);
> +a
> +7
> +select * from t3 where a not in (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a = some (select b from t2);
> +a
> +7
> +select * from t3 where a <> any (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a = all (select b from t2);
> +a
> +7
> +select * from t3 where a <> all (select b from t2);
> +a
> +6
> +3
> +insert into t2 values (100, 5);
> +select * from t3 where a < any (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a < all (select b from t2);
> +a
> +3
> +select * from t3 where a >= any (select b from t2);
> +a
> +6
> +7
> +explain extended select * from t3 where a >= any (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= (select min(`test`.`t2`.`b`) from `test`.`t2`))))
> +select * from t3 where a >= all (select b from t2);
> +a
> +7
> +delete from t2 where a=100;
> +select * from t3 where a in (select a,b from t2);
> +ERROR 21000: Operand should contain 1 column(s)
> +select * from t3 where a in (select * from t2);
> +ERROR 21000: Operand should contain 1 column(s)
> +insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
> +select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +insert into t2 values (2,10);
> +select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +10 1
> +delete from t2 where a=2 and b=10;
> +select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +7 12
> +create table t5 (a int);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +insert into t5 values (5);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +insert into t5 values (2);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
> +2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00
> +3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 100.00 Using where
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> +Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> +Note 1003 select (select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> +ERROR 21000: Subquery returns more than 1 row
> +create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> +create table t7( uq int primary key, name char(25));
> +insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
> +insert into t6 values (1,1),(1,2),(2,2),(1,3);
> +select * from t6 where exists (select * from t7 where uq = clinic_uq);
> +patient_uq clinic_uq
> +1 1
> +1 2
> +2 2
> +explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t6 ALL NULL NULL NULL NULL 4 100.00 Using where
> +2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> +Warnings:
> +Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> +select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> +ERROR 23000: Column 'a' in field list is ambiguous
> +drop table t1,t2,t3;
> +CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
> +INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
> +CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
> +INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
> +CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
> +INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
> +SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
> +a b
> +W 1732-02-22
> +SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
> +a b
> +W 1
> +SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
> +a b
> +W a
> +CREATE TABLE `t8` (
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +`email` varchar(60) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`pseudo`),
> +UNIQUE KEY `email` (`email`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
> +INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
> +INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
> +EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +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
> +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
> +3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
> +Warnings:
> +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where ('joce' = (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 ('joce' = (select 'joce' from `test`.`t8` where 1))
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
> +t8 WHERE pseudo='joce');
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE
> +pseudo='joce');
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
> +pseudo
> +joce
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
> +ERROR 21000: Subquery returns more than 1 row
> +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
> +CREATE TABLE `t1` (
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (topic,date,pseudo) VALUES
> +('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
> +EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index
> +Warnings:
> +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')
> +EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index
> +Warnings:
> +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')`
> +SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
> +date
> +2002-08-03
> +SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
> +(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')
> +2002-08-03
> +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
> +1
> +1
> +1
> +1
> +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
> +ERROR 21000: Subquery returns more than 1 row
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 index NULL topic 3 NULL 2 100.00 Using index
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where (1 = (select 1 union select 1))
> +drop table t1;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM ROW_FORMAT=FIXED;
> +INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
> +CREATE TABLE `t2` (
> +`mot` varchar(30) NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
> +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
> +INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
> +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
> +a
> +40143
> +SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
> +numeropost maxnumrep
> +43506 2
> +40143 1
> +SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b;
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT 1 IN (SELECT 1 FROM t2 HAVING a);
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1);
> +mot topic date pseudo
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1);
> +mot topic date pseudo
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2;
> +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100)
> +joce 40143 2002-10-22 joce 1
> +joce 43506 2002-10-22 joce 1
> +SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2);
> +mot topic date pseudo
> +SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2;
> +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000)
> +joce 40143 2002-10-22 joce 1
> +joce 43506 2002-10-22 joce 0
> +drop table t1,t2;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM ROW_FORMAT=FIXED;
> +INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
> +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
> +ERROR 21000: Subquery returns more than 1 row
> +select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
> +ERROR 21000: Subquery returns more than 1 row
> +show warnings;
> +Level Code Message
> +Error 1242 Subquery returns more than 1 row
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1),(2),(3);
> +(select * from t1) union (select * from t1) order by (select a from t1 limit 1);
> +a
> +1
> +2
> +3
> +drop table t1;
> +CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
> +INSERT INTO t1 VALUES ();
> +SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t1;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL default '0',
> +`numreponse` int(10) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) NOT NULL default '',
> +PRIMARY KEY (`numeropost`,`numreponse`),
> +UNIQUE KEY `numreponse` (`numreponse`),
> +KEY `pseudo` (`pseudo`,`numeropost`)
> +) ENGINE=MyISAM;
> +SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
> +ERROR 42S22: Reference 'numreponse' not supported (forward reference in item list)
> +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
> +numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
> +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');
> +ERROR 21000: Subquery returns more than 1 row
> +EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`)
> +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using index
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select 3 AS `numreponse` from `test`.`t1` where ((3 = (select max(`test`.`t1`.`numreponse`) from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`))))
> +drop table t1;
> +CREATE TABLE t1 (a int(1));
> +INSERT INTO t1 VALUES (1);
> +SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
> +1
> +1
> +drop table t1;
> +create table t1 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t1 values (0, 10),(1, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 22),(3, 23);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +2 12
> +update t1 set b= (select b from t1);
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +update t1 set b= (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +update t1 set b= (select b from t2 where t1.a = t2.a);
> +select * from t1;
> +a b
> +0 NULL
> +1 21
> +2 22
> +drop table t1, t2;
> +create table t1 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t1 values (0, 10),(1, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 12),(3, 23);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +2 12
> +select * from t1 where b = (select b from t2 where t1.a = t2.a);
> +a b
> +2 12
> +delete from t1 where b in (select b from t1);
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +delete from t1 where b = (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +delete from t1 where b = (select b from t2 where t1.a = t2.a);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +drop table t1, t2;
> +create table t11 (a int NOT NULL, b int, primary key (a));
> +create table t12 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t11 values (0, 10),(1, 11),(2, 12);
> +insert into t12 values (33, 10),(22, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 12),(3, 23);
> +select * from t11;
> +a b
> +0 10
> +1 11
> +2 12
> +select * from t12;
> +a b
> +33 10
> +22 11
> +2 12
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
> +ERROR HY000: You can't specify target table 't12' for update in FROM clause
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
> +select * from t11;
> +a b
> +0 10
> +1 11
> +select * from t12;
> +a b
> +33 10
> +22 11
> +drop table t11, t12, t2;
> +CREATE TABLE t1 (x int) ENGINE=MyISAM;
> +create table t2 (a int) ENGINE=MyISAM;
> +create table t3 (b int);
> +insert into t2 values (1);
> +insert into t3 values (1),(2);
> +INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +INSERT INTO t1 (x) VALUES ((SELECT b FROM t3));
> +ERROR 21000: Subquery returns more than 1 row
> +INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
> +select * from t1;
> +x
> +1
> +insert into t2 values (1);
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
> +select * from t1;
> +x
> +1
> +2
> +INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +11
> +11
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
> +ERROR 42S22: Unknown column 'x' in 'field list'
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +11
> +11
> +2
> +drop table t1, t2, t3;
> +CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM;
> +create table t2 (a int);
> +create table t3 (a int);
> +insert into t2 values (1);
> +insert into t3 values (1),(2);
> +select * from t1;
> +x y
> +replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2));
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +replace into t1 (x, y) VALUES ((SELECT a FROM t3), (SELECT a+1 FROM t2));
> +ERROR 21000: Subquery returns more than 1 row
> +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
> +select * from t1;
> +x y
> +1 2
> +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
> +select * from t1;
> +x y
> +1 3
> +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 1
> +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 2
> +replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 2
> +2 1
> +drop table t1, t2, t3;
> +SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
> +ERROR HY000: No tables used
> +CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (1),(2);
> +SELECT * FROM t2 WHERE id IN (SELECT 1);
> +id
> +1
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ref id id 5 const 1 100.00 Using index
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
> +SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
> +id
> +1
> +SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
> +id
> +2
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ref id id 5 const 1 100.00 Using index
> +Warnings:
> +Note 1249 Select 3 was reduced during optimization
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = (1 + 1))
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index NULL id 5 NULL 2 100.00 Using where; Using index
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> +id
> +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> +id
> +2
> +INSERT INTO t2 VALUES ((SELECT * FROM t2));
> +ERROR HY000: You can't specify target table 't2' for update in FROM clause
> +INSERT INTO t2 VALUES ((SELECT id FROM t2));
> +ERROR HY000: You can't specify target table 't2' for update in FROM clause
> +SELECT * FROM t2;
> +id
> +1
> +2
> +CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 values (1),(1);
> +UPDATE t2 SET id=(SELECT * FROM t1);
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t2, t1;
> +create table t1 (a int);
> +insert into t1 values (1),(2),(3);
> +select 1 IN (SELECT * from t1);
> +1 IN (SELECT * from t1)
> +1
> +select 10 IN (SELECT * from t1);
> +10 IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a=2;
> +select 1 IN (SELECT * from t1);
> +1 IN (SELECT * from t1)
> +1
> +select 3 IN (SELECT * from t1);
> +3 IN (SELECT * from t1)
> +1
> +select 10 IN (SELECT * from t1);
> +10 IN (SELECT * from t1)
> +NULL
> +select 1 > ALL (SELECT * from t1);
> +1 > ALL (SELECT * from t1)
> +0
> +select 10 > ALL (SELECT * from t1);
> +10 > ALL (SELECT * from t1)
> +NULL
> +select 1 > ANY (SELECT * from t1);
> +1 > ANY (SELECT * from t1)
> +NULL
> +select 10 > ANY (SELECT * from t1);
> +10 > ANY (SELECT * from t1)
> +1
> +drop table t1;
> +create table t1 (a varchar(20));
> +insert into t1 values ('A'),('BC'),('DEF');
> +select 'A' IN (SELECT * from t1);
> +'A' IN (SELECT * from t1)
> +1
> +select 'XYZS' IN (SELECT * from t1);
> +'XYZS' IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a='BC';
> +select 'A' IN (SELECT * from t1);
> +'A' IN (SELECT * from t1)
> +1
> +select 'DEF' IN (SELECT * from t1);
> +'DEF' IN (SELECT * from t1)
> +1
> +select 'XYZS' IN (SELECT * from t1);
> +'XYZS' IN (SELECT * from t1)
> +NULL
> +select 'A' > ALL (SELECT * from t1);
> +'A' > ALL (SELECT * from t1)
> +0
> +select 'XYZS' > ALL (SELECT * from t1);
> +'XYZS' > ALL (SELECT * from t1)
> +NULL
> +select 'A' > ANY (SELECT * from t1);
> +'A' > ANY (SELECT * from t1)
> +NULL
> +select 'XYZS' > ANY (SELECT * from t1);
> +'XYZS' > ANY (SELECT * from t1)
> +1
> +drop table t1;
> +create table t1 (a float);
> +insert into t1 values (1.5),(2.5),(3.5);
> +select 1.5 IN (SELECT * from t1);
> +1.5 IN (SELECT * from t1)
> +1
> +select 10.5 IN (SELECT * from t1);
> +10.5 IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a=2.5;
> +select 1.5 IN (SELECT * from t1);
> +1.5 IN (SELECT * from t1)
> +1
> +select 3.5 IN (SELECT * from t1);
> +3.5 IN (SELECT * from t1)
> +1
> +select 10.5 IN (SELECT * from t1);
> +10.5 IN (SELECT * from t1)
> +NULL
> +select 1.5 > ALL (SELECT * from t1);
> +1.5 > ALL (SELECT * from t1)
> +0
> +select 10.5 > ALL (SELECT * from t1);
> +10.5 > ALL (SELECT * from t1)
> +NULL
> +select 1.5 > ANY (SELECT * from t1);
> +1.5 > ANY (SELECT * from t1)
> +NULL
> +select 10.5 > ANY (SELECT * from t1);
> +10.5 > ANY (SELECT * from t1)
> +1
> +explain extended select (select a+1) from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select (`test`.`t1`.`a` + 1) AS `(select a+1)` from `test`.`t1`
> +select (select a+1) from t1;
> +(select a+1)
> +2.5
> +NULL
> +4.5
> +drop table t1;
> +CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY (a));
> +CREATE TABLE t2 (a int(11) default '0', INDEX (a));
> +INSERT INTO t1 VALUES (1),(2),(3),(4);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
> +a t1.a in (select t2.a from t2)
> +1 1
> +2 1
> +3 1
> +4 0
> +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
> +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
> +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`
> +CREATE TABLE t3 (a int(11) default '0');
> +INSERT INTO t3 VALUES (1),(2),(3);
> +SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> +a t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
> +1 1
> +2 1
> +3 1
> +4 0
> +explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> +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
> +2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +drop table t1,t2,t3;
> +create table t1 (a float);
> +select 10.5 IN (SELECT * from t1 LIMIT 1);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +drop table t1;
> +create table t1 (a int, b int, c varchar(10));
> +create table t2 (a int);
> +insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
> +insert into t2 values (1),(2),(NULL);
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a)
> +1 1 a
> +2 0 b
> +NULL NULL NULL
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a)
> +1 0 a
> +2 1 b
> +NULL NULL NULL
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a)
> +1 0 a
> +2 0 b
> +NULL NULL NULL
> +drop table t1,t2;
> +create table t1 (a int, b real, c varchar(10));
> +insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
> +select ROW(1, 1, 'a') IN (select a,b,c from t1);
> +ROW(1, 1, 'a') IN (select a,b,c from t1)
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1);
> +ROW(1, 2, 'a') IN (select a,b,c from t1)
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1);
> +ROW(1, 1, 'a') IN (select b,a,c from t1)
> +1
> +select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
> +ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null)
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
> +ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null)
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
> +ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null)
> +1
> +select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
> +ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a')
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
> +ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a')
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
> +ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a')
> +1
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1);
> +do @a:=(SELECT a from t1);
> +select @a;
> +@a
> +1
> +set @a:=2;
> +set @a:=(SELECT a from t1);
> +select @a;
> +@a
> +1
> +drop table t1;
> +do (SELECT a from t1);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +set @a:=(SELECT a from t1);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +CREATE TABLE t1 (a int, KEY(a));
> +HANDLER t1 OPEN;
> +HANDLER t1 READ a=((SELECT 1));
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1))' at line 1
> +HANDLER t1 CLOSE;
> +drop table t1;
> +create table t1 (a int);
> +create table t2 (b int);
> +insert into t1 values (1),(2);
> +insert into t2 values (1);
> +select a from t1 where a in (select a from t1 where a in (select b from t2));
> +a
> +1
> +drop table t1, t2;
> +create table t1 (a int, b int);
> +create table t2 like t1;
> +insert into t1 values (1,2),(1,3),(1,4),(1,5);
> +insert into t2 values (1,2),(1,3);
> +select * from t1 where row(a,b) in (select a,b from t2);
> +a b
> +1 2
> +1 3
> +drop table t1, t2;
> +CREATE TABLE `t1` (`i` int(11) NOT NULL default '0',PRIMARY KEY (`i`)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1);
> +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
> +select * from t1;
> +i
> +2
> +drop table t1;
> +CREATE TABLE t1 (a int(1));
> +EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select rand() from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
> +EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select encrypt('test') from `test`.`t1`) AS `(SELECT ENCRYPT('test') FROM t1)` from `test`.`t1`
> +EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select benchmark(1,1) from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1`
> +drop table t1;
> +CREATE TABLE `t1` (
> +`mot` varchar(30) character set latin1 NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
> +KEY `pseudo` (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +CREATE TABLE `t2` (
> +`mot` varchar(30) character set latin1 NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
> +KEY `pseudo` (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +CREATE TABLE `t3` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES ('joce','1','','joce'),('test','2','','test');
> +Warnings:
> +Warning 1265 Data truncated for column 'date' at row 1
> +Warning 1265 Data truncated for column 'date' at row 2
> +INSERT INTO t2 VALUES ('joce','1','','joce'),('test','2','','test');
> +Warnings:
> +Warning 1265 Data truncated for column 'date' at row 1
> +Warning 1265 Data truncated for column 'date' at row 2
> +INSERT INTO t3 VALUES (1,1);
> +SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE
> +numeropost=topic);
> +topic
> +2
> +select * from t1;
> +mot topic date pseudo
> +joce 1 0000-00-00 joce
> +test 2 0000-00-00 test
> +DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT
> +EXISTS(SELECT * FROM t3 WHERE numeropost=topic));
> +select * from t1;
> +mot topic date pseudo
> +joce 1 0000-00-00 joce
> +drop table t1, t2, t3;
> +SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
> +a (SELECT a)
> +1 1
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT 1)` int(1) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT a)` int(1) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT a+0)` int(3) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
> +select * from t1;
> +a
> +2
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` bigint(20) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +explain extended select a,(select (select rand() from t1 limit 1) from t1 limit 1)
> +from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
> +2 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00
> +3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1003 select `test`.`t1`.`a` AS `a`,(select (select rand() from `test`.`t1` limit 1) from `test`.`t1` limit 1) AS `(select (select rand() from t1 limit 1) from t1 limit 1)` from `test`.`t1`
> +drop table t1;
> +select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +CREATE TABLE t1 (
> +ID int(11) NOT NULL auto_increment,
> +name char(35) NOT NULL default '',
> +t2 char(3) NOT NULL default '',
> +District char(20) NOT NULL default '',
> +Population int(11) NOT NULL default '0',
> +PRIMARY KEY (ID)
> +) ENGINE=MyISAM;
> +INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
> +INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329);
> +INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117);
> +CREATE TABLE t2 (
> +Code char(3) NOT NULL default '',
> +Name char(52) NOT NULL default '',
> +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
> +Region char(26) NOT NULL default '',
> +SurfaceArea float(10,2) NOT NULL default '0.00',
> +IndepYear smallint(6) default NULL,
> +Population int(11) NOT NULL default '0',
> +LifeExpectancy float(3,1) default NULL,
> +GNP float(10,2) default NULL,
> +GNPOld float(10,2) default NULL,
> +LocalName char(45) NOT NULL default '',
> +GovernmentForm char(45) NOT NULL default '',
> +HeadOfState char(60) default NULL,
> +Capital int(11) default NULL,
> +Code2 char(2) NOT NULL default '',
> +PRIMARY KEY (Code)
> +) ENGINE=MyISAM;
> +INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU');
> +INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ');
> +select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent);
> +Continent Name Population
> +Oceania Sydney 3276207
> +drop table t1, t2;
> +CREATE TABLE `t1` (
> +`id` mediumint(8) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `pseudo` (`pseudo`)
> +) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (pseudo) VALUES ('test');
> +SELECT 0 IN (SELECT 1 FROM t1 a);
> +0 IN (SELECT 1 FROM t1 a)
> +0
> +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> +Warnings:
> +Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
> +INSERT INTO t1 (pseudo) VALUES ('test1');
> +SELECT 0 IN (SELECT 1 FROM t1 a);
> +0 IN (SELECT 1 FROM t1 a)
> +0
> +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> +Warnings:
> +Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
> +drop table t1;
> +CREATE TABLE `t1` (
> +`i` int(11) NOT NULL default '0',
> +PRIMARY KEY (`i`)
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1);
> +UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
> +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
> +UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
> +ERROR 42S22: Unknown column 't.i' in 'field list'
> +select * from t1;
> +i
> +3
> +drop table t1;
> +CREATE TABLE t1 (
> +id int(11) default NULL
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
> +CREATE TABLE t2 (
> +id int(11) default NULL,
> +name varchar(15) default NULL
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
> +update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
> +select * from t2;
> +id name
> +4 vita
> +1 lenka
> +2 lenka
> +1 lenka
> +drop table t1,t2;
> +create table t1 (a int, unique index indexa (a));
> +insert into t1 values (-1), (-4), (-2), (NULL);
> +select -10 IN (select a from t1 FORCE INDEX (indexa));
> +-10 IN (select a from t1 FORCE INDEX (indexa))
> +NULL
> +drop table t1;
> +create table t1 (id int not null auto_increment primary key, salary int, key(salary));
> +insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
> +explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ref salary salary 5 const 0 0.00 Using index condition
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select `test`.`t1`.`id` AS `id` from `test`.`t1` where (`test`.`t1`.`salary` = (select max(`test`.`t1`.`salary`) from `test`.`t1`))
> +drop table t1;
> +CREATE TABLE t1 (
> +ID int(10) unsigned NOT NULL auto_increment,
> +SUB_ID int(3) unsigned NOT NULL default '0',
> +REF_ID int(10) unsigned default NULL,
> +REF_SUB int(3) unsigned default '0',
> +PRIMARY KEY (ID,SUB_ID),
> +UNIQUE KEY t1_PK (ID,SUB_ID),
> +KEY t1_FK (REF_ID,REF_SUB),
> +KEY t1_REFID (REF_ID)
> +) ENGINE=MyISAM CHARSET=cp1251;
> +INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
> +SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
> +REF_ID
> +DROP TABLE t1;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +insert into t1 values (1,0), (2,0), (3,0);
> +insert into t2 values (1,1), (2,1), (3,1), (2,2);
> +update ignore t1 set b=(select b from t2 where t1.a=t2.a);
> +Warnings:
> +Error 1242 Subquery returns more than 1 row
> +select * from t1;
> +a b
> +1 1
> +2 NULL
> +3 1
> +drop table t1, t2;
> +CREATE TABLE `t1` (
> +`id` mediumint(8) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) NOT NULL default '',
> +`email` varchar(60) NOT NULL default '',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `email` (`email`),
> +UNIQUE KEY `pseudo` (`pseudo`)
> +) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
> +SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
> +a b
> +test test
> +test1 test1
> +drop table if exists t1;
> +(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
> +a
> +1
> +create table t1 (a int not null, b int, primary key (a));
> +create table t2 (a int not null, primary key (a));
> +create table t3 (a int not null, b int, primary key (a));
> +insert into t1 values (1,10), (2,20), (3,30), (4,40);
> +insert into t2 values (2), (3), (4), (5);
> +insert into t3 values (10,3), (20,4), (30,5);
> +select * from t2 where t2.a in (select a from t1);
> +a
> +2
> +3
> +4
> +explain extended select * from t2 where t2.a in (select a from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 75.00 Using where; Using index; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +a
> +2
> +3
> +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
> +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
> +drop table t1, t2, t3;
> +create table t1 (a int, b int, index a (a,b));
> +create table t2 (a int, index a (a));
> +create table t3 (a int, b int, index a (a));
> +insert into t1 values (1,10), (2,20), (3,30), (4,40);
> +create table t0(a int);
> +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +insert into t1
> +select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
> +insert into t2 values (2), (3), (4), (5);
> +insert into t3 values (10,3), (20,4), (30,5);
> +select * from t2 where t2.a in (select a from t1);
> +a
> +2
> +3
> +4
> +explain extended select * from t2 where t2.a in (select a from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`)
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +a
> +2
> +3
> +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`))
> +insert into t1 values (3,31);
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +3
> +4
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +drop table t0, t1, t2, t3;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +create table t3 (a int, b int);
> +insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
> +insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
> +insert into t3 values (3,3), (2,2), (1,1);
> +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3;
> +a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1)
> +3 1
> +2 2
> +1 2
> +drop table t1,t2,t3;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +insert into t1 values (1);
> +insert into t2 values (1);
> +select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
> +s1
> +1
> +drop table t1,t2;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +insert into t1 values (1);
> +insert into t2 values (1);
> +update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
> +ERROR 42S22: Unknown column 'x.s1' in 'field list'
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
> +s2 CHAR(5) COLLATE latin1_swedish_ci);
> +INSERT INTO t1 VALUES ('z','?');
> +select * from t1 where s1 > (select max(s2) from t1);
> +ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
> +select * from t1 where s1 > any (select max(s2) from t1);
> +ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
> +drop table t1;
> +create table t1(toid int,rd int);
> +create table t2(userid int,pmnew int,pmtotal int);
> +insert into t2 values(1,0,0),(2,0,0);
> +insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2);
> +select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1);
> +userid pmtotal pmnew calc_total calc_new
> +1 0 0 9 3
> +2 0 0 4 2
> +drop table t1, t2;
> +create table t1 (s1 char(5));
> +select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
> +ERROR 21000: Operand should contain 1 column(s)
> +insert into t1 values ('tttt');
> +select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1);
> +s1
> +tttt
> +explain extended (select * from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
> +Warnings:
> +Note 1003 (select 'tttt' AS `s1` from `test`.`t1`)
> +(select * from t1);
> +s1
> +tttt
> +drop table t1;
> +create table t1 (s1 char(5), index s1(s1));
> +create table t2 (s1 char(5), index s1(s1));
> +insert into t1 values ('a1'),('a2'),('a3');
> +insert into t2 values ('a1'),('a2');
> +select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
> +s1 s1 NOT IN (SELECT s1 FROM t2)
> +a1 0
> +a2 0
> +a3 1
> +select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
> +s1 s1 = ANY (SELECT s1 FROM t2)
> +a1 1
> +a2 1
> +a3 0
> +select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
> +s1 s1 <> ALL (SELECT s1 FROM t2)
> +a1 0
> +a2 0
> +a3 1
> +select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
> +s1 s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')
> +a1 0
> +a2 1
> +a3 1
> +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
> +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
> +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`
> +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
> +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
> +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`
> +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
> +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
> +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`
> +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
> +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
> +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`
> +drop table t1,t2;
> +create table t2 (a int, b int);
> +create table t3 (a int);
> +insert into t3 values (6),(7),(3);
> +select * from t3 where a >= all (select b from t2);
> +a
> +6
> +7
> +3
> +explain extended select * from t3 where a >= all (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` < (select max(NULL) from `test`.`t2`))))
> +select * from t3 where a >= some (select b from t2);
> +a
> +explain extended select * from t3 where a >= some (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where a >= all (select b from t2 group by 1);
> +a
> +6
> +7
> +3
> +explain extended select * from t3 where a >= all (select b from t2 group by 1);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` < <max>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where a >= some (select b from t2 group by 1);
> +a
> +explain extended select * from t3 where a >= some (select b from t2 group by 1);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= <min>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where NULL >= any (select b from t2);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where NULL >= any (select b from t2 group by 1);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= <min>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where NULL >= some (select b from t2);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where NULL >= some (select b from t2 group by 1);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= <min>(select NULL from `test`.`t2` group by 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);
> +a
> +6
> +7
> +explain extended select * from t3 where a > all (select max(b) from t2 group by a);
> +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 Using where
> +2 SUBQUERY t2 ALL NULL NULL NULL NULL 4 100.00 Using temporary
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` <= <max>(select max(`test`.`t2`.`b`) from `test`.`t2` group by `test`.`t2`.`a`))))
> +drop table t2, t3;
> +CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
> +INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
> +CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`),FULLTEXT KEY `name` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
> +INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
> +CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
> +INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
> +CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
> +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
> +dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')
> +-1 Valid 1
> +-1 Valid 2 1
> +-1 Should Not Return 0
> +SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
> +dbid name
> +-1 Valid
> +-1 Valid 2
> +drop table t1,t2,t3,t4;
> +CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1),(5);
> +CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (2),(6);
> +select * from t1 where (1,2,6) in (select * from t2);
> +ERROR 21000: Operand should contain 3 column(s)
> +DROP TABLE t1,t2;
> +create table t1 (s1 int);
> +insert into t1 values (1);
> +insert into t1 values (2);
> +set sort_buffer_size = (select s1 from t1);
> +ERROR 21000: Subquery returns more than 1 row
> +do (select * from t1);
> +Warnings:
> +Error 1242 Subquery returns more than 1 row
> +drop table t1;
> +create table t1 (s1 char);
> +insert into t1 values ('e');
> +select * from t1 where 'f' > any (select s1 from t1);
> +s1
> +e
> +select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
> +s1
> +e
> +explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
> +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
> +2 SUBQUERY 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
> +Warnings:
> +Note 1003 select 'e' AS `s1` from `test`.`t1` where <nop>(<in_optimizer>('f',('f' > <min>(select 'e' from `test`.`t1` union select 'e' from `test`.`t1`))))
> +drop table t1;
> +CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
> +CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
> +select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c;
> +phone code
> +69294728265 6
> +18621828126 1862
> +89356874041 NULL
> +95895001874 NULL
> +drop table t1, t2;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +select * from t1 where (select count(*) from t2 where t1.s2) = 1;
> +ERROR 42S22: Unknown column 't1.s2' in 'where clause'
> +select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
> +ERROR 42S22: Unknown column 't1.s2' in 'group statement'
> +select count(*) from t2 group by t1.s2;
> +ERROR 42S22: Unknown column 't1.s2' in 'group statement'
> +drop table t1, t2;
> +CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
> +CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
> +INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
> +INSERT INTO t2 VALUES (100, 200, 'C');
> +SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
> +COLC
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (a int(1));
> +INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
> +SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
> +(SELECT a)
> +1
> +2
> +3
> +4
> +5
> +DROP TABLE t1;
> +create table t1 (a int, b decimal(13, 3));
> +insert into t1 values (1, 0.123);
> +select a, (select max(b) from t1) into outfile "../../tmp/subselect.out.file.1" from t1;
> +delete from t1;
> +load data infile "../../tmp/subselect.out.file.1" into table t1;
> +select * from t1;
> +a b
> +1 0.123
> +drop table t1;
> +CREATE TABLE `t1` (
> +`id` int(11) NOT NULL auto_increment,
> +`id_cns` tinyint(3) unsigned NOT NULL default '0',
> +`tipo` enum('','UNO','DUE') NOT NULL default '',
> +`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
> +`particolare` mediumint(8) unsigned NOT NULL default '0',
> +`generale` mediumint(8) unsigned NOT NULL default '0',
> +`bis` tinyint(3) unsigned NOT NULL default '0',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
> +UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
> +);
> +INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
> +CREATE TABLE `t2` (
> +`id` tinyint(3) unsigned NOT NULL auto_increment,
> +`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
> +PRIMARY KEY (`id`)
> +);
> +INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
> +SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns;
> +id max_anno_dep PIPPO
> +16 1987 1
> +50 1990 0
> +51 1990 NULL
> +DROP TABLE t1, t2;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +SET SQL_SELECT_LIMIT=1;
> +select sum(a) from (select * from t1) as a;
> +sum(a)
> +6
> +select 2 in (select * from t1);
> +2 in (select * from t1)
> +1
> +SET SQL_SELECT_LIMIT=default;
> +drop table t1;
> +CREATE TABLE t1 (a int, b int, INDEX (a));
> +INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
> +SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
> +a b
> +1 1
> +1 2
> +1 3
> +DROP TABLE t1;
> +create table t1(val varchar(10));
> +insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
> +select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%');
> +count(*)
> +0
> +drop table t1;
> +create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
> +insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12');
> +select * from t1 where id not in (select id from t1 where id < 8);
> +id text
> +8 text8
> +9 text9
> +10 text10
> +11 text11
> +12 text12
> +select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> +id text
> +8 text8
> +9 text9
> +10 text10
> +11 text11
> +12 text12
> +explain extended select * from t1 where id not in (select id from t1 where id < 8);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> +Warnings:
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> +explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> +Warnings:
> +Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> +insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> +create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> +insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> +select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
> +id text id text id text
> +1 text1 1 text1 1 text1
> +2 text2 2 text2 2 text2
> +3 text3 3 text3 3 text3
> +4 text4 4 text4 4 text4
> +5 text5 5 text5 5 text5
> +6 text6 6 text6 6 text6
> +7 text7 7 text7 7 text7
> +8 text8 8 text8 8 text8
> +9 text9 9 text9 9 text9
> +10 text10 10 text10 10 text10
> +11 text11 11 text1 11 text11
> +12 text12 12 text2 12 text12
> +1000 text1000 NULL NULL 1000 text1000
> +1001 text1001 NULL NULL 1000 text1000
> +explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE a ALL NULL NULL NULL NULL 14 100.00
> +1 SIMPLE b eq_ref PRIMARY PRIMARY 4 test.a.id 2 100.00
> +1 SIMPLE c eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using index condition
> +Warnings:
> +Note 1003 select `test`.`a`.`id` AS `id`,`test`.`a`.`text` AS `text`,`test`.`b`.`id` AS `id`,`test`.`b`.`text` AS `text`,`test`.`c`.`id` AS `id`,`test`.`c`.`text` AS `text` from `test`.`t1` `a` left join `test`.`t2` `b` on(((`test`.`b`.`id` = `test`.`a`.`id`) or isnull(`test`.`b`.`id`))) join `test`.`t1` `c` where (if(isnull(`test`.`b`.`id`),1000,`test`.`b`.`id`) = `test`.`c`.`id`)
> +drop table t1,t2;
> +create table t1 (a int);
> +insert into t1 values (1);
> +explain select benchmark(1000, (select a from t1 where a=sha(rand())));
> +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
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 1
> +drop table t1;
> +create table t1(id int);
> +create table t2(id int);
> +create table t3(flag int);
> +select (select * from t3 where id not null) from t1, t2;
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) from t1, t2' at line 1
> +drop table t1,t2,t3;
> +CREATE TABLE t1 (id INT);
> +CREATE TABLE t2 (id INT);
> +INSERT INTO t1 VALUES (1), (2);
> +INSERT INTO t2 VALUES (1);
> +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
> +id c
> +1 1
> +2 0
> +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
> +id c
> +1 1
> +2 0
> +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
> +id c
> +1 1
> +2 0
> +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id;
> +id c
> +1 1
> +2 0
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 ( a int, b int );
> +INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
> +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +ALTER TABLE t1 ADD INDEX (a);
> +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 2 column(s)
> +SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +a
> +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 2 column(s)
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +3
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-')
> +0-
> +0-
> +1-
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-')
> +1-
> +0-
> +0-
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-')
> +0-
> +1-
> +0-
> +DROP TABLE t1;
> +CREATE TABLE t1 ( a double, b double );
> +INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +3
> +DROP TABLE t1;
> +CREATE TABLE t1 ( a char(1), b char(1));
> +INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +3
> +DROP TABLE t1;
> +create table t1 (a int, b int);
> +insert into t1 values (1,2),(3,4);
> +select * from t1 up where exists (select * from t1 where t1.a=up.a);
> +a b
> +1 2
> +3 4
> +explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> +Warnings:
> +Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> +drop table t1;
> +CREATE TABLE t1 (t1_a int);
> +INSERT INTO t1 VALUES (1);
> +CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b));
> +INSERT INTO t2 VALUES (1, 1), (1, 2);
> +SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
> +HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
> +t1_a t2_a t2_b
> +1 1 2
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
> +INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
> +CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
> +INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
> +SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
> +id name id pet
> +1 Tim 1 Fido
> +2 Rebecca 2 Spot
> +3 NULL 3 Felix
> +drop table t1,t2;
> +CREATE TABLE t1 ( a int, b int );
> +CREATE TABLE t2 ( c int, d int );
> +INSERT INTO t1 VALUES (1,2), (2,3), (3,4);
> +SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +abc b
> +1 2
> +2 3
> +3 4
> +INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +select * from t2;
> +c d
> +1 2
> +2 3
> +3 4
> +CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +select * from t3;
> +abc b
> +1 2
> +2 3
> +3 4
> +prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);";
> +execute stmt1;
> +deallocate prepare stmt1;
> +select * from t2;
> +c d
> +1 2
> +2 3
> +3 4
> +1 2
> +2 3
> +3 4
> +drop table t3;
> +prepare stmt1 from "CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);";
> +execute stmt1;
> +select * from t3;
> +abc b
> +1 2
> +2 3
> +3 4
> +deallocate prepare stmt1;
> +DROP TABLE t1, t2, t3;
> +CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> +insert into t1 values (1);
> +CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> +insert into t2 values (1,2);
> +select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
> +a C
> +1 1
> +drop table t1,t2;
> +create table t1 (a int not null auto_increment primary key, b varchar(40), fulltext(b));
> +insert into t1 (b) values ('ball'),('ball games'), ('games'), ('foo'), ('foobar'), ('Serg'), ('Sergei'),('Georg'), ('Patrik'),('Hakan');
> +create table t2 (a int);
> +insert into t2 values (1),(3),(2),(7);
> +select a,b from t1 where match(b) against ('Ball') > 0;
> +a b
> +1 ball
> +2 ball games
> +select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0);
> +a
> +1
> +2
> +drop table t1,t2;
> +CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin);
> +CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000003','603','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000004','101','D0000000001','I0000000001');
> +SELECT `IZAVORGANG_ID` FROM t1 WHERE `KUERZEL` IN(SELECT MIN(`KUERZEL`)`Feld1` FROM t1 WHERE `KUERZEL` LIKE'601%'And`IZAANALYSEART_ID`='D0000000001');
> +IZAVORGANG_ID
> +D0000000001
> +drop table t1;
> +CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
> +CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
> +insert into t1 values (1,1),(1,2),(2,1),(2,2);
> +insert into t2 values (1,2),(2,2);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +alter table t2 drop primary key;
> +alter table t2 add key KEY1 (aid, bid);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +alter table t2 drop key KEY1;
> +alter table t2 add primary key (bid, aid);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +drop table t1,t2;
> +CREATE TABLE t1 (howmanyvalues bigint, avalue int);
> +INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
> +SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
> +howmanyvalues count(*)
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 1
> +3 1
> +4 1
> +drop table t1;
> +create table t1 (x int);
> +select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x;
> +(select b.x from t1 as b where b.x=a.x)
> +drop table t1;
> +CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
> +INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
> +CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
> +INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
> +SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
> +ERROR 42S22: Unknown column 'b.sc' in 'field list'
> +SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
> +ac
> +700
> +NULL
> +drop tables t1,t2;
> +create table t1 (a int not null, b int not null, c int, primary key (a,b));
> +insert into t1 values (1,1,1), (2,2,2), (3,3,3);
> +set @b:= 0;
> +explain select sum(a) from t1 where b > @b;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index
> +set @a:= (select sum(a) from t1 where b > @b);
> +explain select a from t1 where c=2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
> +do @a:= (select sum(a) from t1 where b > @b);
> +explain select a from t1 where c=2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
> +drop table t1;
> +set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
> +insert into t2 values (1,3),(2,1);
> +select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
> +a b (select max(b) from t2 where t1.b=t2.a)
> +1 1 3
> +1 2 1
> +1 3 NULL
> +2 4 NULL
> +2 5 NULL
> +drop table t1, t2;
> +create table t1 (id int);
> +create table t2 (id int, body text, fulltext (body));
> +insert into t1 values(1),(2),(3);
> +insert into t2 values (1,'test'), (2,'mysql'), (3,'test'), (4,'test');
> +select count(distinct id) from t1 where id in (select id from t2 where match(body) against ('mysql' in boolean mode));
> +count(distinct id)
> +1
> +drop table t2,t1;
> +create table t1 (s1 int,s2 int);
> +insert into t1 values (20,15);
> +select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
> +s1 s2
> +drop table t1;
> +create table t1 (s1 int);
> +insert into t1 values (1),(null);
> +select * from t1 where s1 < all (select s1 from t1);
> +s1
> +select s1, s1 < all (select s1 from t1) from t1;
> +s1 s1 < all (select s1 from t1)
> +1 0
> +NULL NULL
> +drop table t1;
> +CREATE TABLE t1 (
> +Code char(3) NOT NULL default '',
> +Name char(52) NOT NULL default '',
> +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
> +Region char(26) NOT NULL default '',
> +SurfaceArea float(10,2) NOT NULL default '0.00',
> +IndepYear smallint(6) default NULL,
> +Population int(11) NOT NULL default '0',
> +LifeExpectancy float(3,1) default NULL,
> +GNP float(10,2) default NULL,
> +GNPOld float(10,2) default NULL,
> +LocalName char(45) NOT NULL default '',
> +GovernmentForm char(45) NOT NULL default '',
> +HeadOfState char(60) default NULL,
> +Capital int(11) default NULL,
> +Code2 char(2) NOT NULL default ''
> +) ENGINE=MyISAM;
> +INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
> +INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS');
> +INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF');
> +INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM');
> +/*!40000 ALTER TABLE t1 ENABLE KEYS */;
> +SELECT DISTINCT Continent AS c FROM t1 outr WHERE
> +Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND
> +Population < 200);
> +c
> +Oceania
> +drop table t1;
> +create table t1 (a1 int);
> +create table t2 (b1 int);
> +select * from t1 where a2 > any(select b1 from t2);
> +ERROR 42S22: Unknown column 'a2' in 'IN/ALL/ANY subquery'
> +select * from t1 where a1 > any(select b1 from t2);
> +a1
> +drop table t1,t2;
> +create table t1 (a integer, b integer);
> +select (select * from t1) = (select 1,2);
> +(select * from t1) = (select 1,2)
> +NULL
> +select (select 1,2) = (select * from t1);
> +(select 1,2) = (select * from t1)
> +NULL
> +select row(1,2) = ANY (select * from t1);
> +row(1,2) = ANY (select * from t1)
> +0
> +select row(1,2) != ALL (select * from t1);
> +row(1,2) != ALL (select * from t1)
> +1
> +drop table t1;
> +create table t1 (a integer, b integer);
> +select row(1,(2,2)) in (select * from t1 );
> +ERROR 21000: Operand should contain 2 column(s)
> +select row(1,(2,2)) = (select * from t1 );
> +ERROR 21000: Operand should contain 2 column(s)
> +select (select * from t1) = row(1,(2,2));
> +ERROR 21000: Operand should contain 1 column(s)
> +drop table t1;
> +create table t1 (a integer);
> +insert into t1 values (1);
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx );
> +xx 1 = ALL ( select 1 from t1 where 1 = xx )
> +1 1
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +drop table t1;
> +CREATE TABLE t1 (
> +categoryId int(11) NOT NULL,
> +courseId int(11) NOT NULL,
> +startDate datetime NOT NULL,
> +endDate datetime NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL,
> +attributes text NOT NULL
> +);
> +INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
> +(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(2,52,'2004-03-15','2004-10-01','2004-03-15','2004-09-17',''),
> +(2,53,'2004-03-16','2004-10-01','2004-03-16','2004-09-17',''),
> +(2,88,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
> +(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
> +CREATE TABLE t2 (
> +userId int(11) NOT NULL,
> +courseId int(11) NOT NULL,
> +date datetime NOT NULL
> +);
> +INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
> +(5141,72,'2003-11-25'),(5141,41,'2004-08-06'),
> +(5141,52,'2004-08-06'),(5141,53,'2004-08-06'),
> +(5141,12,'2004-08-06'),(5141,86,'2004-10-21'),
> +(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
> +(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
> +CREATE TABLE t3 (
> +groupId int(11) NOT NULL,
> +parentId int(11) NOT NULL,
> +startDate datetime NOT NULL,
> +endDate datetime NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL,
> +ordering int(11)
> +);
> +INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
> +CREATE TABLE t4 (
> +id int(11) NOT NULL,
> +groupTypeId int(11) NOT NULL,
> +groupKey varchar(50) NOT NULL,
> +name text,
> +ordering int(11),
> +description text,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL
> +);
> +INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
> +(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
> +CREATE TABLE t5 (
> +userId int(11) NOT NULL,
> +groupId int(11) NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL
> +);
> +INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
> +select
> +count(distinct t2.userid) pass,
> +groupstuff.*,
> +count(t2.courseid) crse,
> +t1.categoryid,
> +t2.courseid,
> +date_format(date, '%b%y') as colhead
> +from t2
> +join t1 on t2.courseid=t1.courseid
> +join
> +(
> +select
> +t5.userid,
> +parentid,
> +parentgroup,
> +childid,
> +groupname,
> +grouptypeid
> +from t5
> +join
> +(
> +select t4.id as parentid,
> +t4.name as parentgroup,
> +t4.id as childid,
> +t4.name as groupname,
> +t4.grouptypeid
> +from t4
> +) as gin on t5.groupid=gin.childid
> +) as groupstuff on t2.userid = groupstuff.userid
> +group by
> +groupstuff.groupname, colhead , t2.courseid;
> +pass userid parentid parentgroup childid groupname grouptypeid crse categoryid courseid colhead
> +1 5141 12 group2 12 group2 5 1 5 12 Aug04
> +1 5141 12 group2 12 group2 5 1 1 41 Aug04
> +1 5141 12 group2 12 group2 5 1 2 52 Aug04
> +1 5141 12 group2 12 group2 5 1 2 53 Aug04
> +1 5141 12 group2 12 group2 5 1 3 51 Oct04
> +1 5141 12 group2 12 group2 5 1 1 86 Oct04
> +1 5141 12 group2 12 group2 5 1 1 87 Oct04
> +1 5141 12 group2 12 group2 5 1 2 88 Oct04
> +1 5141 12 group2 12 group2 5 1 2 89 Oct04
> +drop table t1, t2, t3, t4, t5;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
> +1
> +1
> +1
> +1
> +drop table t1;
> +create table t1 (a int);
> +create table t2 (a int);
> +insert into t1 values (1),(2);
> +insert into t2 values (0),(1),(2),(3);
> +select a from t2 where a in (select a from t1);
> +a
> +1
> +2
> +select a from t2 having a in (select a from t1);
> +a
> +1
> +2
> +prepare stmt1 from "select a from t2 where a in (select a from t1)";
> +execute stmt1;
> +a
> +1
> +2
> +execute stmt1;
> +a
> +1
> +2
> +deallocate prepare stmt1;
> +prepare stmt1 from "select a from t2 having a in (select a from t1)";
> +execute stmt1;
> +a
> +1
> +2
> +execute stmt1;
> +a
> +1
> +2
> +deallocate prepare stmt1;
> +drop table t1, t2;
> +create table t1 (a int, b int);
> +insert into t1 values (1,2);
> +select 1 = (select * from t1);
> +ERROR 21000: Operand should contain 1 column(s)
> +select (select * from t1) = 1;
> +ERROR 21000: Operand should contain 2 column(s)
> +select (1,2) = (select a from t1);
> +ERROR 21000: Operand should contain 2 column(s)
> +select (select a from t1) = (1,2);
> +ERROR 21000: Operand should contain 1 column(s)
> +select (1,2,3) = (select * from t1);
> +ERROR 21000: Operand should contain 3 column(s)
> +select (select * from t1) = (1,2,3);
> +ERROR 21000: Operand should contain 2 column(s)
> +drop table t1;
> +CREATE TABLE `t1` (
> +`itemid` bigint(20) unsigned NOT NULL auto_increment,
> +`sessionid` bigint(20) unsigned default NULL,
> +`time` int(10) unsigned NOT NULL default '0',
> +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
> +NULL default '',
> +`data` text collate latin1_general_ci NOT NULL,
> +PRIMARY KEY (`itemid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
> +CREATE TABLE `t2` (
> +`sessionid` bigint(20) unsigned NOT NULL auto_increment,
> +`pid` int(10) unsigned NOT NULL default '0',
> +`date` int(10) unsigned NOT NULL default '0',
> +`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
> +PRIMARY KEY (`sessionid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
> +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
> +ip count( e.itemid )
> +10.10.10.1 1
> +drop tables t1,t2;
> +create table t1 (fld enum('0','1'));
> +insert into t1 values ('1');
> +select * from (select max(fld) from t1) as foo;
> +max(fld)
> +1
> +drop table t1;
> +CREATE TABLE t1 (one int, two int, flag char(1));
> +CREATE TABLE t2 (one int, two int, flag char(1));
> +INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
> +INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
> +SELECT * FROM t1
> +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N');
> +one two flag
> +5 6 N
> +7 8 N
> +SELECT * FROM t1
> +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
> +one two flag
> +5 6 N
> +7 8 N
> +insert into t2 values (null,null,'N');
> +insert into t2 values (null,3,'0');
> +insert into t2 values (null,5,'0');
> +insert into t2 values (10,null,'0');
> +insert into t1 values (10,3,'0');
> +insert into t1 values (10,5,'0');
> +insert into t1 values (10,10,'0');
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
> +one two test
> +1 2 NULL
> +2 3 NULL
> +3 4 NULL
> +5 6 1
> +7 8 1
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> +one two
> +5 6
> +7 8
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
> +one two test
> +1 2 NULL
> +2 3 NULL
> +3 4 NULL
> +5 6 1
> +7 8 1
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
> +one two test
> +1 2 0
> +2 3 NULL
> +3 4 0
> +5 6 0
> +7 8 0
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> +one two test
> +1 2 0
> +2 3 NULL
> +3 4 0
> +5 6 0
> +7 8 0
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> +explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; FirstMatch(t1)
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`two` = `test`.`t1`.`two`) and (`test`.`t2`.`one` = `test`.`t1`.`one`) and (`test`.`t2`.`flag` = 'N'))
> +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a char(5), b char(5));
> +INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> +SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
> +a b
> +aaa aaa
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int);
> +CREATE TABLE t2 (a int, b int);
> +CREATE TABLE t3 (b int NOT NULL);
> +INSERT INTO t1 VALUES (1), (2), (3), (4);
> +INSERT INTO t2 VALUES (1,10), (3,30);
> +SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b
> +WHERE t3.b IS NOT NULL OR t2.a > 10;
> +a b b
> +SELECT * FROM t1
> +WHERE t1.a NOT IN (SELECT a FROM t2 LEFT JOIN t3 ON t2.b=t3.b
> +WHERE t3.b IS NOT NULL OR t2.a > 10);
> +a
> +1
> +2
> +3
> +4
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (f1 INT);
> +CREATE TABLE t2 (f2 INT);
> +INSERT INTO t1 VALUES (1);
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
> +f1
> +1
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
> +f1
> +1
> +INSERT INTO t2 VALUES (1);
> +INSERT INTO t2 VALUES (2);
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
> +f1
> +1
> +DROP TABLE t1, t2;
> +select 1 from dual where 1 < any (select 2);
> +1
> +1
> +select 1 from dual where 1 < all (select 2);
> +1
> +1
> +select 1 from dual where 2 > any (select 1);
> +1
> +1
> +select 1 from dual where 2 > all (select 1);
> +1
> +1
> +select 1 from dual where 1 < any (select 2 from dual);
> +1
> +1
> +select 1 from dual where 1 < all (select 2 from dual where 1!=1);
> +1
> +1
> +create table t1 (s1 char);
> +insert into t1 values (1),(2);
> +select * from t1 where (s1 < any (select s1 from t1));
> +s1
> +1
> +select * from t1 where not (s1 < any (select s1 from t1));
> +s1
> +2
> +select * from t1 where (s1 < ALL (select s1+1 from t1));
> +s1
> +1
> +select * from t1 where not(s1 < ALL (select s1+1 from t1));
> +s1
> +2
> +select * from t1 where (s1+1 = ANY (select s1 from t1));
> +s1
> +1
> +select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
> +s1
> +2
> +select * from t1 where (s1 = ALL (select s1/s1 from t1));
> +s1
> +1
> +select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
> +s1
> +2
> +drop table t1;
> +create table t1 (
> +retailerID varchar(8) NOT NULL,
> +statusID int(10) unsigned NOT NULL,
> +changed datetime NOT NULL,
> +UNIQUE KEY retailerID (retailerID, statusID, changed)
> +);
> +INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
> +INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
> +INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56");
> +INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53");
> +INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50");
> +INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50");
> +select * from t1 r1
> +where (r1.retailerID,(r1.changed)) in
> +(SELECT r2.retailerId,(max(changed)) from t1 r2
> +group by r2.retailerId);
> +retailerID statusID changed
> +0026 2 2006-01-06 12:25:53
> +0037 2 2006-01-06 12:25:53
> +0048 1 2006-01-06 12:37:50
> +0059 1 2006-01-06 12:37:50
> +drop table t1;
> +create table t1(a int, primary key (a));
> +insert into t1 values (10);
> +create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
> +insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
> +explain 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'
> + 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
> +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
> +1 PRIMARY r const PRIMARY PRIMARY 4 const 1
> +2 DEPENDENT 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
> +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;
> +a a b
> +10 3 35989
> +explain 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'
> + 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
> +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
> +1 PRIMARY r const PRIMARY PRIMARY 4 const 1
> +2 DEPENDENT 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
> +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;
> +a a b
> +10 1 359
> +drop table t1,t2;
> +CREATE TABLE t1 (
> +field1 int NOT NULL,
> +field2 int NOT NULL,
> +field3 int NOT NULL,
> +PRIMARY KEY (field1,field2,field3)
> +);
> +CREATE TABLE t2 (
> +fieldA int NOT NULL,
> +fieldB int NOT NULL,
> +PRIMARY KEY (fieldA,fieldB)
> +);
> +INSERT INTO t1 VALUES
> +(1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1);
> +INSERT INTO t2 VALUES (1,1), (1,2), (1,3);
> +SELECT field1, field2, COUNT(*)
> +FROM t1 GROUP BY field1, field2;
> +field1 field2 COUNT(*)
> +1 1 2
> +1 2 3
> +1 3 1
> +SELECT field1, field2
> +FROM t1
> +GROUP BY field1, field2
> +HAVING COUNT(*) >= ALL (SELECT fieldB
> +FROM t2 WHERE fieldA = field1);
> +field1 field2
> +1 2
> +SELECT field1, field2
> +FROM t1
> +GROUP BY field1, field2
> +HAVING COUNT(*) < ANY (SELECT fieldB
> +FROM t2 WHERE fieldA = field1);
> +field1 field2
> +1 1
> +1 3
> +DROP TABLE t1, t2;
> +CREATE TABLE t1(a int, INDEX (a));
> +INSERT INTO t1 VALUES (1), (3), (5), (7);
> +INSERT INTO t1 VALUES (NULL);
> +CREATE TABLE t2(a int);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 3
> +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
> +SELECT a, a IN (SELECT a FROM t1) FROM t2;
> +a a IN (SELECT a FROM t1)
> +1 1
> +2 NULL
> +3 1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a DATETIME);
> +INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
> +CREATE TABLE t2 AS SELECT
> +(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a
> +FROM t1 WHERE a > '2000-01-01';
> +SHOW CREATE TABLE t2;
> +Table Create Table
> +t2 CREATE TABLE `t2` (
> + `sub_a` datetime DEFAULT NULL
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01');
> +SHOW CREATE TABLE t3;
> +Table Create Table
> +t3 CREATE TABLE `t3` (
> + `a` datetime DEFAULT NULL
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (1), (2);
> +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0;
> +a
> +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL;
> +a
> +1
> +2
> +EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL;
> +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 Impossible WHERE
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (2), (4), (1), (3);
> +CREATE TABLE t2 (b int, c int);
> +INSERT INTO t2 VALUES
> +(2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 );
> +a
> +2
> +4
> +1
> +3
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a;
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2);
> +b MAX(c)
> +1 4
> +2 2
> +4 4
> +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 2),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 1),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +a
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
> +ERROR 21000: Subquery returns more than 1 row
> +DROP TABLE t1,t2;
> +create table t1 (df decimal(5,1));
> +insert into t1 values(1.1);
> +insert into t1 values(2.2);
> +select * from t1 where df <= all (select avg(df) from t1 group by df);
> +df
> +1.1
> +select * from t1 where df >= all (select avg(df) from t1 group by df);
> +df
> +2.2
> +drop table t1;
> +create table t1 (df decimal(5,1));
> +insert into t1 values(1.1);
> +select 1.1 * exists(select * from t1);
> +1.1 * exists(select * from t1)
> +1.1
> +drop table t1;
> +CREATE TABLE t1 (
> +grp int(11) default NULL,
> +a decimal(10,2) default NULL);
> +insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
> +select * from t1;
> +grp a
> +1 1.00
> +2 2.00
> +2 3.00
> +3 4.00
> +3 5.00
> +3 6.00
> +NULL NULL
> +select min(a) from t1 group by grp;
> +min(a)
> +NULL
> +1.00
> +2.00
> +4.00
> +drop table t1;
> +CREATE table t1 ( c1 integer );
> +INSERT INTO t1 VALUES ( 1 );
> +INSERT INTO t1 VALUES ( 2 );
> +INSERT INTO t1 VALUES ( 3 );
> +CREATE TABLE t2 ( c2 integer );
> +INSERT INTO t2 VALUES ( 1 );
> +INSERT INTO t2 VALUES ( 4 );
> +INSERT INTO t2 VALUES ( 5 );
> +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1);
> +c1 c2
> +1 1
> +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2
> +WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) );
> +c1 c2
> +1 1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 ( c1 integer );
> +INSERT INTO t1 VALUES ( 1 );
> +INSERT INTO t1 VALUES ( 2 );
> +INSERT INTO t1 VALUES ( 3 );
> +INSERT INTO t1 VALUES ( 6 );
> +CREATE TABLE t2 ( c2 integer );
> +INSERT INTO t2 VALUES ( 1 );
> +INSERT INTO t2 VALUES ( 4 );
> +INSERT INTO t2 VALUES ( 5 );
> +INSERT INTO t2 VALUES ( 6 );
> +CREATE TABLE t3 ( c3 integer );
> +INSERT INTO t3 VALUES ( 7 );
> +INSERT INTO t3 VALUES ( 8 );
> +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2
> +WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL );
> +c1 c2
> +2 NULL
> +3 NULL
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE `t1` (
> +`itemid` bigint(20) unsigned NOT NULL auto_increment,
> +`sessionid` bigint(20) unsigned default NULL,
> +`time` int(10) unsigned NOT NULL default '0',
> +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
> +NULL default '',
> +`data` text collate latin1_general_ci NOT NULL,
> +PRIMARY KEY (`itemid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
> +CREATE TABLE `t2` (
> +`sessionid` bigint(20) unsigned NOT NULL auto_increment,
> +`pid` int(10) unsigned NOT NULL default '0',
> +`date` int(10) unsigned NOT NULL default '0',
> +`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
> +PRIMARY KEY (`sessionid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
> +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
> +ip count( e.itemid )
> +10.10.10.1 1
> +drop tables t1,t2;
> +CREATE TABLE t1 (EMPNUM CHAR(3));
> +CREATE TABLE t2 (EMPNUM CHAR(3) );
> +INSERT INTO t1 VALUES ('E1'),('E2');
> +INSERT INTO t2 VALUES ('E1');
> +DELETE FROM t1
> +WHERE t1.EMPNUM NOT IN
> +(SELECT t2.EMPNUM
> +FROM t2
> +WHERE t1.EMPNUM = t2.EMPNUM);
> +select * from t1;
> +EMPNUM
> +E1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(select_id BIGINT, values_id BIGINT);
> +INSERT INTO t1 VALUES (1, 1);
> +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT,
> +PRIMARY KEY(select_id,values_id));
> +INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id IN (1, 0));
> +values_id
> +1
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id BETWEEN 0 AND 1);
> +values_id
> +1
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id = 0 OR select_id = 1);
> +values_id
> +1
> +DROP TABLE t1, t2;
> +create table t1 (fld enum('0','1'));
> +insert into t1 values ('1');
> +select * from (select max(fld) from t1) as foo;
> +max(fld)
> +1
> +drop table t1;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (c int, d int);
> +CREATE TABLE t3 (e int);
> +INSERT INTO t1 VALUES
> +(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
> +INSERT INTO t2 VALUES
> +(2,10), (2,20), (4,10), (5,10), (3,20), (2,40);
> +INSERT INTO t3 VALUES (10), (30), (10), (20) ;
> +SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a;
> +a MAX(b) MIN(b)
> +1 20 10
> +2 30 10
> +3 20 20
> +4 40 40
> +SELECT * FROM t2;
> +c d
> +2 10
> +2 20
> +4 10
> +5 10
> +3 20
> +2 40
> +SELECT * FROM t3;
> +e
> +10
> +30
> +10
> +20
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20);
> +a
> +2
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d);
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d);
> +a
> +2
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE d >= SOME(SELECT e FROM t3 WHERE MAX(b)=e));
> +a
> +2
> +3
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
> +a
> +2
> +3
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE d > SOME(SELECT e FROM t3 WHERE MAX(b)=e));
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d));
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE MIN(b) < d AND
> +EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
> +a
> +2
> +SELECT a, SUM(a) FROM t1 GROUP BY a;
> +a SUM(a)
> +1 2
> +2 6
> +3 3
> +4 4
> +SELECT a FROM t1
> +WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a;
> +a
> +3
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c);
> +a
> +1
> +3
> +4
> +SELECT a FROM t1
> +WHERE a < 3 AND
> +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1
> +WHERE a < 3 AND
> +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c);
> +a
> +1
> +2
> +1
> +2
> +2
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
> +HAVING SUM(t1.a+t2.c) < t3.e/4));
> +a
> +1
> +2
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a > ALL(SELECT t2.c FROM t2
> +WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
> +HAVING SUM(t1.a+t2.c) < t3.e/4));
> +a
> +4
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a > ALL(SELECT t2.c FROM t2
> +WHERE EXISTS(SELECT t3.e FROM t3
> +WHERE SUM(t1.a+t2.c) < t3.e/4));
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20;
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING AVG(t2.c+SUM(t1.b)) > 20);
> +a
> +2
> +3
> +4
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING AVG(SUM(t1.b)) > 20);
> +a
> +2
> +4
> +SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING t2.c+sum > 20);
> +a sum
> +2 60
> +3 20
> +4 40
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a varchar(5), b varchar(10));
> +INSERT INTO t1 VALUES
> +('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
> +('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +a b
> +BBB 4
> +CCC 7
> +AAA 8
> +EXPLAIN
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 9 Using temporary
> +ALTER TABLE t1 ADD INDEX(a);
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +a b
> +BBB 4
> +CCC 7
> +AAA 8
> +EXPLAIN
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
> +2 DEPENDENT SUBQUERY t1 index NULL a 8 NULL 1
> +DROP TABLE t1;
> +create table t1( f1 int,f2 int);
> +insert into t1 values (1,1),(2,2);
> +select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1';
> +t
> +crash1
> +crash1
> +drop table t1;
> +create table t1 (c int, key(c));
> +insert into t1 values (1142477582), (1142455969);
> +create table t2 (a int, b int);
> +insert into t2 values (2, 1), (1, 0);
> +delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
> +drop table t1, t2;
> +CREATE TABLE t1 (a INT);
> +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'where clause'
> +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'where clause'
> +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'IN/ALL/ANY subquery'
> +DROP TABLE t1;
> +create table t1 (i int, j bigint);
> +insert into t1 values (1, 2), (2, 2), (3, 2);
> +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
> +min(i)
> +1
> +drop table t1;
> +CREATE TABLE t1 (i BIGINT UNSIGNED);
> +INSERT INTO t1 VALUES (10000000000000000000);
> +INSERT INTO t1 VALUES (1);
> +CREATE TABLE t2 (i BIGINT UNSIGNED);
> +INSERT INTO t2 VALUES (10000000000000000000);
> +INSERT INTO t2 VALUES (1);
> +/* simple test */
> +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i;
> +i
> +10000000000000000000
> +1
> +/* subquery test */
> +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
> +i
> +10000000000000000000
> +/* subquery test with cast*/
> +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
> +i
> +10000000000000000000
> +DROP TABLE t1;
> +DROP TABLE t2;
> +CREATE TABLE t1 (
> +id bigint(20) unsigned NOT NULL auto_increment,
> +name varchar(255) NOT NULL,
> +PRIMARY KEY (id)
> +);
> +INSERT INTO t1 VALUES
> +(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
> +CREATE TABLE t2 (
> +id bigint(20) unsigned NOT NULL auto_increment,
> +mid bigint(20) unsigned NOT NULL,
> +date date NOT NULL,
> +PRIMARY KEY (id)
> +);
> +INSERT INTO t2 VALUES
> +(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
> +(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
> +SELECT *,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 0, 1) AS date_last,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last
> +FROM t1;
> +id name date_last date_next_to_last
> +1 Balazs 2006-05-01 NULL
> +2 Joe 2006-04-20 NULL
> +3 Frank 2006-04-13 NULL
> +SELECT *,
> +(SELECT COUNT(*) FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 1, 1) AS date_count
> +FROM t1;
> +id name date_count
> +1 Balazs NULL
> +2 Joe NULL
> +3 Frank NULL
> +SELECT *,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 0, 1) AS date_last,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last
> +FROM t1;
> +id name date_last date_next_to_last
> +1 Balazs 2006-05-01 2006-03-30
> +2 Joe 2006-04-20 2006-04-06
> +3 Frank 2006-04-13 NULL
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (
> +i1 int(11) NOT NULL default '0',
> +i2 int(11) NOT NULL default '0',
> +t datetime NOT NULL default '0000-00-00 00:00:00',
> +PRIMARY KEY (i1,i2,t)
> +);
> +INSERT INTO t1 VALUES
> +(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
> +(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
> +(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'),
> +(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'),
> +(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'),
> +(24,2,'2005-05-27 12:40:06');
> +CREATE TABLE t2 (
> +i1 int(11) NOT NULL default '0',
> +i2 int(11) NOT NULL default '0',
> +t datetime default NULL,
> +PRIMARY KEY (i1)
> +);
> +INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
> +EXPLAIN
> +SELECT * FROM t1,t2
> +WHERE t1.t = (SELECT t1.t FROM t1
> +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
> +ORDER BY t1.t DESC LIMIT 1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 system NULL NULL NULL NULL 1
> +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
> +SELECT * FROM t1,t2
> +WHERE t1.t = (SELECT t1.t FROM t1
> +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
> +ORDER BY t1.t DESC LIMIT 1);
> +i1 i2 t i1 i2 t
> +24 1 2005-05-27 12:40:30 24 1 2006-06-20 12:29:40
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
> +insert into t1 (a) values (FLOOR(rand() * 100));
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +SELECT a,
> +(SELECT REPEAT(' ',250) FROM t1 i1
> +WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
> +FROM t1 ORDER BY a LIMIT 5;
> +a a
> +0 NULL
> +0 NULL
> +0 NULL
> +0 NULL
> +0 NULL
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT, b INT);
> +CREATE TABLE t2 (a INT);
> +INSERT INTO t2 values (1);
> +INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
> +SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
> +(SELECT COUNT(DISTINCT t1.b) from t2)
> +2
> +1
> +1
> +SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
> +FROM t1 GROUP BY t1.a;
> +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
> +2
> +1
> +1
> +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
> +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b))
> +2 2
> +1 1
> +1 1
> +SELECT COUNT(DISTINCT t1.b),
> +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
> +FROM t1 GROUP BY t1.a;
> +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
> +2 2
> +1 1
> +1 1
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a;
> +(
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +2
> +1
> +1
> +SELECT (
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a LIMIT 1)
> +FROM t1 t2
> +GROUP BY t2.a;
> +(
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a LIMIT 1)
> +2
> +2
> +2
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int, PRIMARY KEY (b));
> +CREATE TABLE t2 (x int auto_increment, y int, z int,
> +PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
> +create table t3 (a int);
> +insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
> +from t3 A, t3 B, t3 C, t3 D where D.a<3;
> +insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
> +SET SESSION sort_buffer_size = 32 * 1024;
> +SELECT SQL_NO_CACHE COUNT(*)
> +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
> +FROM t1) t;
> +COUNT(*)
> +3000
> +SET SESSION sort_buffer_size = 8 * 1024 * 1024;
> +SELECT SQL_NO_CACHE COUNT(*)
> +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
> +FROM t1) t;
> +COUNT(*)
> +3000
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
> +CREATE TABLE t2 (c int);
> +INSERT INTO t1 VALUES ('aa', 1);
> +INSERT INTO t2 VALUES (1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT c FROM t2 WHERE c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT c FROM t2 WHERE c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +bb 2
> +cc 3
> +dd 1
> +INSERT INTO t2 VALUES (2);
> +CREATE TABLE t3 (c int);
> +INSERT INTO t3 VALUES (1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +bb 2
> +cc 3
> +dd 1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1(f1 int);
> +CREATE TABLE t2(f2 int, f21 int, f3 timestamp);
> +INSERT INTO t1 VALUES (1),(1),(2),(2);
> +INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11"), (2,2,"2004-02-29 11:11:11");
> +SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1;
> +sq
> +2
> +4
> +SELECT (SELECT SUM(1) FROM t2 ttt GROUP BY t2.f3 LIMIT 1) AS tt FROM t2;
> +tt
> +2
> +2
> +PREPARE stmt1 FROM 'SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1';
> +EXECUTE stmt1;
> +sq
> +2
> +4
> +EXECUTE stmt1;
> +sq
> +2
> +4
> +DEALLOCATE PREPARE stmt1;
> +SELECT f2, AVG(f21),
> +(SELECT t.f3 FROM t2 AS t WHERE t2.f2=t.f2 AND t.f3=MAX(t2.f3)) AS test
> +FROM t2 GROUP BY f2;
> +f2 AVG(f21) test
> +1 1.0000 2004-02-29 11:11:11
> +2 2.0000 2004-02-29 11:11:11
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL);
> +INSERT INTO t1 VALUES
> +(1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'),
> +(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'),
> +(3,2,'k'), (3,1,'l'), (1,9,'m');
> +SELECT a, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test
> +FROM t1 GROUP BY a;
> +a MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +DROP TABLE t1;
> +DROP TABLE IF EXISTS t1;
> +DROP TABLE IF EXISTS t2;
> +DROP TABLE IF EXISTS t1xt2;
> +CREATE TABLE t1 (
> +id_1 int(5) NOT NULL,
> +t varchar(4) DEFAULT NULL
> +);
> +CREATE TABLE t2 (
> +id_2 int(5) NOT NULL,
> +t varchar(4) DEFAULT NULL
> +);
> +CREATE TABLE t1xt2 (
> +id_1 int(5) NOT NULL,
> +id_2 int(5) NOT NULL
> +);
> +INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
> +INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa');
> +INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +2
> +3
> +4
> +insert INTO t1xt2 VALUES (1, 12);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +2
> +3
> +4
> +insert INTO t1xt2 VALUES (2, 12);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +3
> +4
> +DROP TABLE t1;
> +DROP TABLE t2;
> +DROP TABLE t1xt2;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (3), (1), (2);
> +SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
> +col1 col2
> +this is a test. 3
> +this is a test. 1
> +this is a test. 2
> +SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t;
> +col1 t2
> +this is a test. 3
> +this is a test. 1
> +this is a test. 2
> +DROP table t1;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (m int, n int);
> +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
> +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
> +SELECT COUNT(*), a,
> +(SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
> +FROM t1 GROUP BY a;
> +COUNT(*) a (SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
> +2 2 2
> +3 3 3
> +1 4 1
> +SELECT COUNT(*), a,
> +(SELECT MIN(m) FROM t2 WHERE m = count(*))
> +FROM t1 GROUP BY a;
> +COUNT(*) a (SELECT MIN(m) FROM t2 WHERE m = count(*))
> +2 2 2
> +3 3 3
> +1 4 1
> +SELECT COUNT(*), a
> +FROM t1 GROUP BY a
> +HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1;
> +COUNT(*) a
> +2 2
> +3 3
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (m int, n int);
> +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
> +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
> +SELECT COUNT(*) c, a,
> +(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
> +FROM t1 GROUP BY a;
> +c a (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
> +2 2 2
> +3 3 3
> +1 4 1,1
> +SELECT COUNT(*) c, a,
> +(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
> +FROM t1 GROUP BY a;
> +c a (SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
> +2 2 3
> +3 3 4
> +1 4 2,2
> +DROP table t1,t2;
> +CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
> +INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
> +(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
> +(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
> +SELECT a, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test
> +FROM t1 GROUP BY a;
> +a MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +SELECT a x, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test
> +FROM t1 GROUP BY a;
> +x MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +SELECT a, AVG(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=AVG(t1.b)) AS test
> +FROM t1 WHERE t1.d=0 GROUP BY a;
> +a AVG(b) test
> +1 4.0000 d
> +2 2.0000 g
> +3 2.5000 NULL
> +SELECT tt.a,
> +(SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test
> +FROM t1 as tt;
> +a test
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +2 o
> +2 o
> +2 o
> +2 o
> +3 p
> +3 p
> +3 p
> +3 p
> +3 p
> +SELECT tt.a,
> +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1)
> +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test
> +FROM t1 as tt GROUP BY tt.a;
> +a test
> +1 n
> +2 o
> +3 p
> +SELECT tt.a, MAX(
> +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1)
> +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test
> +FROM t1 as tt GROUP BY tt.a;
> +a test
> +1 n
> +2 o
> +3 p
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int, b int);
> +INSERT INTO t1 VALUES (2,22),(1,11),(2,22);
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +a
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +a
> +1
> +2
> +SET @@sql_mode='ansi';
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SET @@sql_mode=default;
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT);
> +INSERT INTO t1 values (1),(1),(1),(1);
> +CREATE TABLE t2 (x INT);
> +INSERT INTO t1 values (1000),(1001),(1002);
> +SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT SUM( (SELECT SUM(COUNT(a)) FROM t2) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT COUNT(1) FROM DUAL;
> +COUNT(1)
> +1
> +SELECT SUM( (SELECT AVG( (SELECT t1.a FROM t2) ) FROM DUAL) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT
> +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) )
> +FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a as XXA,
> +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) )
> +FROM t1;
> +ERROR HY000: Invalid use of group function
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int, KEY (a));
> +INSERT INTO t1 VALUES (1,1),(2,1);
> +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
> +1 PRIMARY t1 ref a a 5 const 0 Using where; Using index
> +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
> +DROP TABLE t1;
> +CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
> +INSERT INTO t1 VALUES
> +(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
> +CREATE TABLE t2 (id int NOT NULL, INDEX idx(id));
> +INSERT INTO t2 VALUES (7), (5), (1), (3);
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
> +id st
> +3 FL
> +1 GA
> +7 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
> +GROUP BY id;
> +id st
> +1 GA
> +3 FL
> +7 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
> +id st
> +2 GA
> +4 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
> +GROUP BY id;
> +id st
> +2 GA
> +4 FL
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (1), (2);
> +EXPLAIN EXTENDED
> +SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
> +2 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
> +Warnings:
> +Note 1003 select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
> +DROP TABLE t1;
> +CREATE TABLE t1 (
> +a varchar(255) default NULL,
> +b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
> +INDEX idx(a,b)
> +);
> +CREATE TABLE t2 (
> +a varchar(255) default NULL
> +);
> +INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
> +INSERT INTO `t2` VALUES ('abcdefghijk');
> +INSERT INTO `t2` VALUES ('asdf');
> +SET session sort_buffer_size=8192;
> +SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
> +d1
> +1
> +1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INTEGER, b INTEGER);
> +CREATE TABLE t2 (x INTEGER);
> +INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
> +INSERT INTO t2 VALUES (1), (2);
> +SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
> +(SELECT SUM(t1.a)/AVG(t2.x) FROM t2)
> +3.3333
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INT, b INT);
> +INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
> +SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
> +AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
> +GROUP BY a1.a;
> +a COUNT(*)
> +1 3
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT);
> +CREATE TABLE t2 (a INT);
> +INSERT INTO t1 VALUES (1),(2);
> +INSERT INTO t2 VALUES (1),(2);
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
> +(SELECT SUM(t1.a) FROM t2 WHERE a=0)
> +NULL
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1;
> +(SELECT SUM(t1.a) FROM t2 WHERE a=1)
> +3
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a1 INT, a2 INT);
> +CREATE TABLE t2 (b1 INT, b2 INT);
> +INSERT INTO t1 VALUES (100, 200);
> +INSERT INTO t1 VALUES (101, 201);
> +INSERT INTO t2 VALUES (101, 201);
> +INSERT INTO t2 VALUES (103, 203);
> +SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
> +((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL
> +0
> +0
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
> +INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
> +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
> +s1 s2
> +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
> +s1 s2
> +CREATE INDEX I1 ON t1 (s1);
> +CREATE INDEX I2 ON t1 (s2);
> +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
> +s1 s2
> +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
> +s1 s2
> +TRUNCATE t1;
> +INSERT INTO t1 VALUES (0x41,0x41);
> +SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
> +s1 s2
> +DROP TABLE t1;
> +CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
> +CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
> +CREATE TABLE t3 (a3 BINARY(2) default '0');
> +INSERT INTO t1 VALUES (1),(2),(3),(4);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +INSERT INTO t3 VALUES (1),(2),(3);
> +SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
> +LEFT(t2.a2, 1)
> +1
> +2
> +3
> +SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
> +a1 t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
> +1 0
> +2 0
> +3 0
> +4 0
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
> +CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
> +CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
> +INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
> +INSERT INTO t2 VALUES (2), (3), (4), (5);
> +INSERT INTO t3 VALUES (10), (20), (30);
> +SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
> +LEFT(t1.a1,1)
> +1
> +2
> +3
> +SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
> +a2
> +DROP TABLE t1, t2, t3;
> +CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
> +INSERT INTO t1 VALUES ('a', 'aa');
> +INSERT INTO t1 VALUES ('a', 'aaa');
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +a b
> +CREATE INDEX I1 ON t1 (a);
> +CREATE INDEX I2 ON t1 (b);
> +EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +a b
> +CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
> +INSERT INTO t2 SELECT * FROM t1;
> +CREATE INDEX I1 ON t2 (a);
> +CREATE INDEX I2 ON t2 (b);
> +EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
> +SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
> +a b
> +EXPLAIN
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
> +a b
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(a INT, b INT);
> +INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
> +EXPLAIN
> +SELECT a AS out_a, MIN(b) FROM t1
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
> +GROUP BY a;
> +ERROR 42S22: Unknown column 'out_a' in 'where clause'
> +SELECT a AS out_a, MIN(b) FROM t1
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
> +GROUP BY a;
> +ERROR 42S22: Unknown column 'out_a' in 'where clause'
> +EXPLAIN
> +SELECT a AS out_a, MIN(b) FROM t1 t1_outer
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
> +GROUP BY a;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1_outer ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 Using where
> +SELECT a AS out_a, MIN(b) FROM t1 t1_outer
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
> +GROUP BY a;
> +out_a MIN(b)
> +1 2
> +2 4
> +DROP TABLE t1;
> +create table t0(a int);
> +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +create table t1(f11 int, f12 int);
> +create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
> +insert into t1 values(1,1),(2,2), (3, 3);
> +insert into t2
> +select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a
> +from t0 A, t0 B, t0 C, t0 D;
> +set session sort_buffer_size= 33*1024;
> +select count(*) from t1 where f12 =
> +(select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
> +count(*)
> +3
> +drop table t0,t1,t2;
> +CREATE TABLE t4 (
> +f7 varchar(32) collate utf8_bin NOT NULL default '',
> +f10 varchar(32) collate utf8_bin default NULL,
> +PRIMARY KEY (f7)
> +);
> +INSERT INTO t4 VALUES(1,1), (2,null);
> +CREATE TABLE t2 (
> +f4 varchar(32) collate utf8_bin NOT NULL default '',
> +f2 varchar(50) collate utf8_bin default NULL,
> +f3 varchar(10) collate utf8_bin default NULL,
> +PRIMARY KEY (f4),
> +UNIQUE KEY uk1 (f2)
> +);
> +INSERT INTO t2 VALUES(1,1,null), (2,2,null);
> +CREATE TABLE t1 (
> +f8 varchar(32) collate utf8_bin NOT NULL default '',
> +f1 varchar(10) collate utf8_bin default NULL,
> +f9 varchar(32) collate utf8_bin default NULL,
> +PRIMARY KEY (f8)
> +);
> +INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
> +CREATE TABLE t3 (
> +f6 varchar(32) collate utf8_bin NOT NULL default '',
> +f5 varchar(50) collate utf8_bin default NULL,
> +PRIMARY KEY (f6)
> +);
> +INSERT INTO t3 VALUES (1,null), (2,null);
> +SELECT
> +IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4,
> +IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3,
> +SUM(
> +IF(
> +(SELECT VPC.f2
> +FROM t2 VPC, t4 a2, t2 a3
> +WHERE
> +VPC.f4 = a2.f10 AND a3.f2 = a4
> +LIMIT 1) IS NULL,
> +0,
> +t3.f5
> +)
> +) AS a6
> +FROM
> +t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4
> +GROUP BY a4;
> +a4 f3 a6
> +1 NULL NULL
> +2 NULL NULL
> +DROP TABLE t1, t2, t3, t4;
> +create table t1 (a float(5,4) zerofill);
> +create table t2 (a float(5,4),b float(2,0));
> +select t1.a from t1 where
> +t1.a= (select b from t2 limit 1) and not
> +t1.a= (select a from t2 limit 1) ;
> +a
> +drop table t1, t2;
> +CREATE TABLE t1 (a INT);
> +INSERT INTO t1 VALUES (1),(2);
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 GROUP BY a);
> +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
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> +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
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> +DROP TABLE t1;
> +#
> +# Bug#45061: Incorrectly market field caused wrong result.
> +#
> +CREATE TABLE `C` (
> +`int_nokey` int(11) NOT NULL,
> +`int_key` int(11) NOT NULL,
> +KEY `int_key` (`int_key`)
> +);
> +INSERT INTO `C` VALUES (9,9), (0,0), (8,6), (3,6), (7,6), (0,4),
> +(1,7), (9,4), (0,8), (9,4), (0,7), (5,5), (0,0), (8,5), (8,7),
> +(5,2), (1,8), (7,0), (0,9), (9,5);
> +SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`);
> +int_nokey int_key
> +9 9
> +0 0
> +5 5
> +0 0
> +EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where
> +DROP TABLE C;
> +# End of test for bug#45061.
> +#
> +# Bug #46749: Segfault in add_key_fields() with outer subquery level
> +# field references
> +#
> +CREATE TABLE t1 (
> +a int,
> +b int,
> +UNIQUE (a), KEY (b)
> +);
> +INSERT INTO t1 VALUES (1,1), (2,1);
> +CREATE TABLE st1 like t1;
> +INSERT INTO st1 VALUES (1,1), (2,1);
> +CREATE TABLE st2 like t1;
> +INSERT INTO st2 VALUES (1,1), (2,1);
> +EXPLAIN
> +SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
> +FROM t1
> +WHERE a = 230;
> +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
> +2 DEPENDENT 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)
> +FROM t1
> +WHERE a = 230;
> +MAX(b) (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
> +NULL 0
> +DROP TABLE t1, st1, st2;
> +#
> +# Bug #48709: Assertion failed in sql_select.cc:11782:
> +# int join_read_key(JOIN_TAB*)
> +#
> +CREATE TABLE t1 (pk int PRIMARY KEY, int_key int);
> +INSERT INTO t1 VALUES (10,1), (14,1);
> +CREATE TABLE t2 (pk int PRIMARY KEY, int_key int);
> +INSERT INTO t2 VALUES (3,3), (5,NULL), (7,3);
> +# should have eq_ref for t1
> +EXPLAIN
> +SELECT * FROM t2 outr
> +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
> +ORDER BY outr.pk;
> +id select_type table type possible_keys key key_len ref rows Extra
> +x x outr ALL x x x x x x
> +x x t1 eq_ref x x x x x x
> +x x t2 index x x x x x x
> +# should not crash on debug binaries
> +SELECT * FROM t2 outr
> +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
> +ORDER BY outr.pk;
> +pk int_key
> +3 3
> +7 3
> +DROP TABLE t1,t2;
> +End of 5.0 tests.
> +create table t_out (subcase char(3),
> +a1 char(2), b1 char(2), c1 char(2));
> +create table t_in (a2 char(2), b2 char(2), c2 char(2));
> +insert into t_out values ('A.1','2a', NULL, '2a');
> +insert into t_out values ('A.3', '2a', NULL, '2a');
> +insert into t_out values ('A.4', '2a', NULL, 'xx');
> +insert into t_out values ('B.1', '2a', '2a', '2a');
> +insert into t_out values ('B.2', '2a', '2a', '2a');
> +insert into t_out values ('B.3', '3a', 'xx', '3a');
> +insert into t_out values ('B.4', 'xx', '3a', '3a');
> +insert into t_in values ('1a', '1a', '1a');
> +insert into t_in values ('2a', '2a', '2a');
> +insert into t_in values (NULL, '2a', '2a');
> +insert into t_in values ('3a', NULL, '3a');
> +
> +Test general IN semantics (not top-level)
> +
> +case A.1
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
> +from t_out where subcase = 'A.1';
> +subcase pred_in pred_not_in
> +A.1 0 1
> +case A.2 - impossible
> +case A.3
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'A.3';
> +subcase pred_in pred_not_in
> +A.3 NULL NULL
> +case A.4
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'A.4';
> +subcase pred_in pred_not_in
> +A.4 0 1
> +case B.1
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
> +from t_out where subcase = 'B.1';
> +subcase pred_in pred_not_in
> +B.1 0 1
> +case B.2
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.2';
> +subcase pred_in pred_not_in
> +B.2 1 0
> +case B.3
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.3';
> +subcase pred_in pred_not_in
> +B.3 NULL NULL
> +case B.4
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.4';
> +subcase pred_in pred_not_in
> +B.4 0 1
> +
> +Test IN as top-level predicate, and
> +as non-top level for cases A.3, B.3 (the only cases with NULL result).
> +
> +case A.1
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.1' and
> +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.1' and
> +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.1' and
> +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
> +not_pred_in
> +T
> +case A.3
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.3' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.3' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.3' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
> +where subcase = 'A.3' and
> +((a1, b1, c1) IN (select * from t_in)) is NULL and
> +((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
> +pred_in
> +N
> +case A.4
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.4' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.4' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.4' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +T
> +case B.1
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.1' and
> +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.1' and
> +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.1' and
> +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
> +not_pred_in
> +T
> +case B.2
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.2' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.2' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.2' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +case B.3
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.3' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.3' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.3' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
> +where subcase = 'B.3' and
> +((a1, b1, c1) IN (select * from t_in)) is NULL and
> +((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
> +pred_in
> +N
> +case B.4
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.4' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.4' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.4' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +T
> +drop table t_out;
> +drop table t_in;
> +CREATE TABLE t1 (a INT, b INT);
> +INSERT INTO t1 VALUES (2,22),(1,11),(2,22);
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +a
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +a
> +1
> +2
> +SET @@sql_mode='ansi';
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SET @@sql_mode=default;
> +DROP TABLE t1;
> +CREATE TABLE t1 (s1 CHAR(1));
> +INSERT INTO t1 VALUES ('a');
> +SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1);
> +s1
> +a
> +DROP TABLE t1;
> +CREATE TABLE t1(c INT, KEY(c));
> +CREATE TABLE t2(a INT, b INT);
> +INSERT INTO t2 VALUES (1, 10), (2, NULL);
> +INSERT INTO t1 VALUES (1), (3);
> +SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
> +a b
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(pk INT PRIMARY KEY, a INT, INDEX idx(a));
> +INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
> +CREATE TABLE t2(pk INT PRIMARY KEY, a INT, b INT, INDEX idxa(a));
> +INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
> +pk a
> +1 10
> +3 30
> +2 20
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), KEY b (b));
> +INSERT INTO t1 VALUES (1,NULL), (9,NULL);
> +CREATE TABLE t2 (
> +a INT,
> +b INT,
> +c INT,
> +d INT,
> +PRIMARY KEY (a),
> +UNIQUE KEY b (b,c,d),
> +KEY b_2 (b),
> +KEY c (c),
> +KEY d (d)
> +);
> +INSERT INTO t2 VALUES
> +(43, 2, 11 ,30),
> +(44, 2, 12 ,30),
> +(45, 1, 1 ,10000),
> +(46, 1, 2 ,10000),
> +(556,1, 32 ,10000);
> +CREATE TABLE t3 (
> +a INT,
> +b INT,
> +c INT,
> +PRIMARY KEY (a),
> +UNIQUE KEY b (b,c),
> +KEY c (c),
> +KEY b_2 (b)
> +);
> +INSERT INTO t3 VALUES (1,1,1), (2,32,1);
> +explain
> +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 Using index
> +1 PRIMARY t3 ref b,b_2 b 5 test.t1.a 1 Using index
> +2 DEPENDENT SUBQUERY t2 ref b,b_2,c b 10 test.t3.c,test.t1.a 1 Using where; Using index; Using filesort
> +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a;
> +a incorrect
> +1 1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (id int);
> +CREATE TABLE t2 (id int, c int);
> +INSERT INTO t1 (id) VALUES (1);
> +INSERT INTO t2 (id) VALUES (1);
> +INSERT INTO t1 (id) VALUES (1);
> +INSERT INTO t2 (id) VALUES (1);
> +CREATE VIEW v1 AS
> +SELECT t2.c AS c FROM t1, t2
> +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +UPDATE v1 SET c=1;
> +CREATE VIEW v2 (a,b) AS
> +SELECT t2.id, t2.c AS c FROM t1, t2
> +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +INSERT INTO v2(a,b) VALUES (2,2);
> +ERROR HY000: CHECK OPTION failed 'test.v2'
> +SELECT * FROM v1;
> +c
> +1
> +1
> +1
> +1
> +CREATE VIEW v3 AS
> +SELECT t2.c AS c FROM t2
> +WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +DELETE FROM v3;
> +DROP VIEW v1,v2,v3;
> +DROP TABLE t1,t2;
> +#
> +# BUG#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result
> +#
> +create table t1(id integer primary key, g integer, v integer, s char(1));
> +create table t2(id integer primary key, g integer, v integer, s char(1));
> +insert into t1 values
> +(10, 10, 10, 'l'),
> +(20, 20, 20, 'l'),
> +(40, 40, 40, 'l'),
> +(41, 40, null, 'l'),
> +(50, 50, 50, 'l'),
> +(51, 50, null, 'l'),
> +(60, 60, 60, 'l'),
> +(61, 60, null, 'l'),
> +(70, 70, 70, 'l'),
> +(90, 90, null, 'l');
> +insert into t2 values
> +(10, 10, 10, 'r'),
> +(30, 30, 30, 'r'),
> +(50, 50, 50, 'r'),
> +(60, 60, 60, 'r'),
> +(61, 60, null, 'r'),
> +(70, 70, 70, 'r'),
> +(71, 70, null, 'r'),
> +(80, 80, 80, 'r'),
> +(81, 80, null, 'r'),
> +(100,100,null, 'r');
> +select *
> +from t1
> +where v in(select v
> +from t2
> +where t1.g=t2.g) is unknown;
> +id g v s
> +51 50 NULL l
> +61 60 NULL l
> +drop table t1, t2;
> +#
> +# Bug#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result
> +#
> +create table t1(id integer primary key, g integer, v integer, s char(1));
> +create table t2(id integer primary key, g integer, v integer, s char(1));
> +insert into t1 values
> +(10, 10, 10, 'l'),
> +(20, 20, 20, 'l'),
> +(40, 40, 40, 'l'),
> +(41, 40, null, 'l'),
> +(50, 50, 50, 'l'),
> +(51, 50, null, 'l'),
> +(60, 60, 60, 'l'),
> +(61, 60, null, 'l'),
> +(70, 70, 70, 'l'),
> +(90, 90, null, 'l');
> +insert into t2 values
> +(10, 10, 10, 'r'),
> +(30, 30, 30, 'r'),
> +(50, 50, 50, 'r'),
> +(60, 60, 60, 'r'),
> +(61, 60, null, 'r'),
> +(70, 70, 70, 'r'),
> +(71, 70, null, 'r'),
> +(80, 80, 80, 'r'),
> +(81, 80, null, 'r'),
> +(100,100,null, 'r');
> +select *
> +from t1
> +where v in(select v
> +from t2
> +where t1.g=t2.g) is unknown;
> +id g v s
> +51 50 NULL l
> +61 60 NULL l
> +drop table t1, t2;
> +CREATE TABLE t1 (a ENUM('rainbow'));
> +INSERT INTO t1 VALUES (),(),(),(),();
> +SELECT 1 FROM t1 GROUP BY (SELECT 1 FROM t1 ORDER BY AVG(LAST_INSERT_ID()));
> +1
> +1
> +DROP TABLE t1;
> +CREATE TABLE t1 (a LONGBLOB);
> +INSERT INTO t1 SET a = 'aaaa';
> +INSERT INTO t1 SET a = 'aaaa';
> +SELECT 1 FROM t1 GROUP BY
> +(SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1);
> +1
> +1
> +DROP TABLE t1;
> +#
> +# Bug #49512 : subquery with aggregate function crash
> +# subselect_single_select_engine::exec()
> +CREATE TABLE t1(a INT);
> +INSERT INTO t1 VALUES();
> +# should not crash
> +SELECT 1 FROM t1 WHERE a <> SOME
> +(
> +SELECT MAX((SELECT a FROM t1 LIMIT 1)) AS d
> +FROM t1,t1 a
> +);
> +1
> +DROP TABLE t1;
> +#
> +# Bug #45989 take 2 : memory leak after explain encounters an
> +# error in the query
> +#
> +CREATE TABLE t1(a LONGTEXT);
> +INSERT INTO t1 VALUES (repeat('a',@@global.max_allowed_packet));
> +INSERT INTO t1 VALUES (repeat('b',@@global.max_allowed_packet));
> +EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
> +(SELECT DISTINCTROW a AS away FROM t1 GROUP BY a WITH ROLLUP) AS d1
> +WHERE t1.a = d1.a;
> +ERROR 42S22: Unknown column 'd1.a' in 'where clause'
> +DROP TABLE t1;
> +End of 5.1 tests.
> +Set up test tables.
> +CREATE TABLE t1 (
> +t1_id INT UNSIGNED,
> +PRIMARY KEY(t1_id)
> +) Engine=MyISAM;
> +INSERT INTO t1 (t1_id) VALUES (1), (2), (3), (4), (5);
> +CREATE TABLE t2 SELECT * FROM t1;
> +CREATE TABLE t3 (
> +t3_id INT UNSIGNED AUTO_INCREMENT,
> +t1_id INT UNSIGNED,
> +amount DECIMAL(16,2),
> +PRIMARY KEY(t3_id),
> +KEY(t1_id)
> +) Engine=MyISAM;
> +INSERT INTO t3 (t1_id, t3_id, amount)
> +VALUES (1, 1, 100.00), (2, 2, 200.00), (4, 4, 400.00);
> +This is the 'inner query' running by itself.
> +Produces correct results.
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +SELECT * FROM (the same inner query)
> +Produces correct results.
> +SELECT * FROM (
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +) AS t;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +Now make t2.t1_id part of a key.
> +ALTER TABLE t2 ADD PRIMARY KEY(t1_id);
> +Same inner query by itself.
> +Still correct results.
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +SELECT * FROM (the same inner query), now with indexes on the LEFT JOIN
> +SELECT * FROM (
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +) AS t;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +DROP TABLE t3;
> +DROP TABLE t2;
> +DROP TABLE t1;
> +#
> +# Bug #52711: Segfault when doing EXPLAIN SELECT with
> +# union...order by (select... where...)
> +#
> +CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a));
> +INSERT INTO t1 VALUES (1),(2);
> +CREATE TABLE t2 (b INT);
> +INSERT INTO t2 VALUES (1),(2);
> +# Should not crash
> +EXPLAIN
> +SELECT * FROM t2 UNION SELECT * FROM t2
> +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
> +# Should not crash
> +SELECT * FROM t2 UNION SELECT * FROM t2
> +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
> +DROP TABLE t1,t2;
> +# LP BUG#675248 - select->prep_where references on freed memory
> +CREATE TABLE t1 (a int, b int);
> +insert into t1 values (1,1),(0,0);
> +CREATE TABLE t2 (c int);
> +insert into t2 values (1),(2);
> +prepare stmt1 from "select sum(a),(select sum(c) from t2 where table1.b) as sub
> +from t1 as table1 group by sub";
> +execute stmt1;
> +sum(a) sub
> +0 NULL
> +1 3
> +deallocate prepare stmt1;
> +prepare stmt1 from "select sum(a),(select sum(c) from t2 having table1.b) as sub
> +from t1 as table1";
> +execute stmt1;
> +sum(a) sub
> +1 3
> +deallocate prepare stmt1;
> +drop table t1,t2;
> +#
> +# Bug LP#693935/#58727: Assertion failure with
> +# a single row subquery returning more than one row
> +#
> +create table t1 (a char(1) charset utf8);
> +insert into t1 values ('a'), ('b');
> +create table t2 (a binary(1));
> +insert into t2 values ('x'), ('y');
> +select * from t2 where a=(select a from t1) and a='x';
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t1,t2;
> +End of 5.1 tests
> +#
> +# No BUG#, a case brought from 5.2's innodb_mysql_lock.test
> +#
> +create table t1 (i int not null primary key);
> +insert into t1 values (1),(2),(3),(4),(5);
> +create table t2 (j int not null primary key);
> +insert into t2 values (1),(2),(3),(4),(5);
> +create table t3 (k int not null primary key);
> +insert into t3 values (1),(2),(3);
> +create view v2 as select t2.j as j from t2 where t2.j in (select t1.i from t1);
> +select * from t3 where k in (select j from v2);
> +k
> +1
> +2
> +3
> +drop table t1,t2,t3;
> +drop view v2;
> +#
> +# Bug#52068: Optimizer generates invalid semijoin materialization plan
> +#
> +drop table if exists ot1, ot2, it1, it2;
> +CREATE TABLE ot1(a INTEGER);
> +INSERT INTO ot1 VALUES(5), (8);
> +CREATE TABLE it2(a INTEGER);
> +INSERT INTO it2 VALUES(9), (5), (1), (8);
> +CREATE TABLE it3(a INTEGER);
> +INSERT INTO it3 VALUES(7), (1), (0), (5), (1), (4);
> +CREATE TABLE ot4(a INTEGER);
> +INSERT INTO ot4 VALUES(1), (3), (5), (7), (9), (7), (3), (1);
> +SELECT * FROM ot1,ot4
> +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
> +FROM it2,it3);
> +a a
> +5 1
> +8 1
> +5 5
> +8 5
> +5 7
> +8 7
> +5 7
> +8 7
> +5 1
> +8 1
> +explain SELECT * FROM ot1,ot4
> +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
> +FROM it2,it3);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY ot1 ALL NULL NULL NULL NULL 2 Start temporary
> +1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
> +1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
> +1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join)
> +DROP TABLE IF EXISTS ot1, ot4, it2, it3;
> +#
> +# Bug#729039: NULL keys used to evaluate subquery
> +#
> +CREATE TABLE t1 (a int) ;
> +INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
> +CREATE TABLE t2 (a int, INDEX idx(a)) ;
> +INSERT INTO t2 VALUES (NULL), (1), (NULL);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
> +a
> +1
> +EXPLAIN
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
> +a
> +1
> +EXPLAIN
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
> +2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
> +DROP TABLE t1,t2;
> +#
> +# BUG#752992: Wrong results for a subquery with 'semijoin=on'
> +#
> +CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL);
> +INSERT INTO t1 VALUES (11,0);
> +INSERT INTO t1 VALUES (12,5);
> +INSERT INTO t1 VALUES (15,0);
> +CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL);
> +INSERT INTO t2 VALUES (11,1);
> +INSERT INTO t2 VALUES (12,2);
> +INSERT INTO t2 VALUES (15,4);
> +EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3 Start temporary
> +1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; Using join buffer (flat, BNL join)
> +1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index; End temporary
> +SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
> +pk i
> +11 0
> +12 5
> +15 0
> +DROP table t1,t2;
> +#
> +# Bug#751350: crash with pushed condition for outer references when
> +# there should be none of such conditions
> +#
> +CREATE TABLE t1 (a int, b int) ;
> +INSERT INTO t1 VALUES (0,0),(0,0);
> +EXPLAIN
> +SELECT b FROM t1
> +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a )
> +GROUP BY b;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary
> +SELECT b FROM t1
> +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a )
> +GROUP BY b;
> +b
> +0
> +DROP TABLE t1;
> +#
> +# Bug #11765713 58705:
> +# OPTIMIZER LET ENGINE DEPEND ON UNINITIALIZED VALUES
> +# CREATED BY OPT_SUM_QUERY
> +#
> +CREATE TABLE t1(a INT NOT NULL, KEY (a));
> +INSERT INTO t1 VALUES (0), (1);
> +SELECT 1 as foo FROM t1 WHERE a < SOME
> +(SELECT a FROM t1 WHERE a <=>
> +(SELECT a FROM t1)
> +);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT 1 as foo FROM t1 WHERE a < SOME
> +(SELECT a FROM t1 WHERE a <=>
> +(SELECT a FROM t1 where a is null)
> +);
> +foo
> +DROP TABLE t1;
> +#
> +# BUG#779885: Crash in eliminate_item_equal with materialization=on in
> +# maria-5.3
> +#
> +CREATE TABLE t1 ( f1 int );
> +INSERT INTO t1 VALUES (19), (20);
> +CREATE TABLE t2 ( f10 varchar(32) );
> +INSERT INTO t2 VALUES ('c'),('d');
> +CREATE TABLE t3 ( f10 varchar(32) );
> +INSERT INTO t3 VALUES ('a'),('b');
> +SELECT *
> +FROM t1
> +WHERE
> +( 't' ) IN (
> +SELECT t3.f10
> +FROM t3
> +JOIN t2
> +ON t2.f10 = t3.f10
> +);
> +f1
> +DROP TABLE t1,t2,t3;
> +End of 5.3 tests
> +set optimizer_switch=@subselect_tmp;
> +set optimizer_switch=default;
> +select @@optimizer_switch like '%subquery_cache=on%';
> +@@optimizer_switch like '%subquery_cache=on%'
> +0
>
> === modified file 'mysql-test/r/subselect_no_semijoin.result'
> --- a/mysql-test/r/subselect_no_semijoin.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect_no_semijoin.result 2011-07-14 09:11:11 +0000
> @@ -56,7 +56,7 @@ id select_type table type possible_keys
> 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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +Note 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> 1
> 1
> @@ -319,7 +319,7 @@ NULL UNION RESULT <union2,3> ALL NULL NU
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +Note 1003 select (select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> ERROR 21000: Subquery returns more than 1 row
> create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> @@ -337,7 +337,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> Warnings:
> Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> ERROR 23000: Column 'a' in field list is ambiguous
> drop table t1,t2,t3;
> @@ -751,7 +751,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> id
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> @@ -899,7 +899,7 @@ id select_type table type possible_keys
> 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
> 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`,<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');
> INSERT INTO t3 VALUES (1),(2),(3);
> SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> @@ -914,7 +914,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> drop table t1,t2,t3;
> create table t1 (a float);
> select 10.5 IN (SELECT * from t1 LIMIT 1);
> @@ -1304,7 +1304,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1314,7 +1314,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1325,7 +1325,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where
> 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> drop table t1, t2, t3;
> create table t1 (a int, b int, index a (a,b));
> create table t2 (a int, index a (a));
> @@ -1347,7 +1347,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1357,7 +1357,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1368,7 +1368,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ref a a 5 func 1001 100.00 Using index
> 2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> insert into t1 values (3,31);
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> @@ -1384,7 +1384,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> drop table t0, t1, t2, t3;
> create table t1 (a int, b int);
> create table t2 (a int, b int);
> @@ -1475,25 +1475,25 @@ id select_type table type possible_keys
> 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
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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`,<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
> 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(<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;
> create table t2 (a int, b int);
> create table t3 (a int);
> @@ -1748,14 +1748,14 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> @@ -2291,7 +2291,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> drop table t1;
> CREATE TABLE t1 (t1_a int);
> INSERT INTO t1 VALUES (1);
> @@ -2832,19 +2832,19 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 Using where
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`)))))
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))
> explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> DROP TABLE t1,t2;
> CREATE TABLE t1 (a char(5), b char(5));
> INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> @@ -4327,13 +4327,13 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> 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
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1))))
> DROP TABLE t1;
> #
> # Bug#45061: Incorrectly market field caused wrong result.
>
> === added file 'mysql-test/r/subselect_scache.result'
> --- a/mysql-test/r/subselect_scache.result 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/r/subselect_scache.result 2011-07-14 09:11:11 +0000
> @@ -0,0 +1,5139 @@
> +select @@optimizer_switch like '%subquery_cache=on%';
> +@@optimizer_switch like '%subquery_cache=on%'
> +0
> +set optimizer_switch='subquery_cache=on';
> +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
> +drop view if exists v2;
> +set @subselect_tmp=@@optimizer_switch;
> +set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
> +"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
> +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
> +select (select 2);
> +(select 2)
> +2
> +explain extended select (select 2);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select 2 AS `(select 2)`
> +SELECT (SELECT 1) UNION SELECT (SELECT 2);
> +(SELECT 1)
> +1
> +2
> +explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1249 Select 4 was reduced during optimization
> +Note 1003 select 1 AS `(SELECT 1)` union select 2 AS `(SELECT 2)`
> +SELECT (SELECT (SELECT 0 UNION SELECT 0));
> +(SELECT (SELECT 0 UNION SELECT 0))
> +0
> +explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0));
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select (select 0 union select 0) AS `(SELECT (SELECT 0 UNION SELECT 0))`
> +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
> +ERROR 42S22: Reference 'a' not supported (forward reference in item list)
> +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
> +ERROR 42S22: Reference 'b' not supported (forward reference in item list)
> +SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
> +(SELECT 1) MAX(1)
> +1 1
> +SELECT (SELECT a) as a;
> +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;
> +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
> +3 DEPENDENT 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
> +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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> +1
> +1
> +SELECT (SELECT 1), a;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
> +a
> +1
> +SELECT 1 FROM (SELECT (SELECT a) b) c;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c ORDER BY id);
> +id
> +1
> +SELECT * FROM (SELECT 1) a WHERE 1 IN (SELECT 1,1);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT 1 IN (SELECT 1);
> +1 IN (SELECT 1)
> +1
> +SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
> +1
> +1
> +select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1));
> +ERROR HY000: Incorrect usage of PROCEDURE and subquery
> +SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1));
> +ERROR HY000: Incorrect parameters to procedure 'ANALYSE'
> +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL;
> +ERROR 42S22: Unknown column 'a' in 'field list'
> +SELECT (SELECT 1,2,3) = ROW(1,2,3);
> +(SELECT 1,2,3) = ROW(1,2,3)
> +1
> +SELECT (SELECT 1,2,3) = ROW(1,2,1);
> +(SELECT 1,2,3) = ROW(1,2,1)
> +0
> +SELECT (SELECT 1,2,3) < ROW(1,2,1);
> +(SELECT 1,2,3) < ROW(1,2,1)
> +0
> +SELECT (SELECT 1,2,3) > ROW(1,2,1);
> +(SELECT 1,2,3) > ROW(1,2,1)
> +1
> +SELECT (SELECT 1,2,3) = ROW(1,2,NULL);
> +(SELECT 1,2,3) = ROW(1,2,NULL)
> +NULL
> +SELECT ROW(1,2,3) = (SELECT 1,2,3);
> +ROW(1,2,3) = (SELECT 1,2,3)
> +1
> +SELECT ROW(1,2,3) = (SELECT 1,2,1);
> +ROW(1,2,3) = (SELECT 1,2,1)
> +0
> +SELECT ROW(1,2,3) < (SELECT 1,2,1);
> +ROW(1,2,3) < (SELECT 1,2,1)
> +0
> +SELECT ROW(1,2,3) > (SELECT 1,2,1);
> +ROW(1,2,3) > (SELECT 1,2,1)
> +1
> +SELECT ROW(1,2,3) = (SELECT 1,2,NULL);
> +ROW(1,2,3) = (SELECT 1,2,NULL)
> +NULL
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a');
> +(SELECT 1.5,2,'a') = ROW(1.5,2,'a')
> +1
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b');
> +(SELECT 1.5,2,'a') = ROW(1.5,2,'b')
> +0
> +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b');
> +(SELECT 1.5,2,'a') = ROW('1.5b',2,'b')
> +0
> +Warnings:
> +Warning 1292 Truncated incorrect DOUBLE value: '1.5b'
> +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
> +(SELECT 'b',2,'a') = ROW(1.5,2,'a')
> +0
> +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
> +(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
> +1
> +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
> +(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
> +0
> +SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT 1 as a,(SELECT a+a) b,(SELECT b);
> +a b (SELECT b)
> +1 2 2
> +create table t1 (a int);
> +create table t2 (a int, b int);
> +create table t3 (a int);
> +create table t4 (a int not null, b int not null);
> +insert into t1 values (2);
> +insert into t2 values (1,7),(2,7);
> +insert into t4 values (4,8),(3,8),(5,9);
> +select (select a from t1 where t1.a = a1) as a2, (select b from t2 where t2.b=a2) as a1;
> +ERROR 42S22: Reference 'a1' not supported (forward reference in item list)
> +select (select a from t1 where t1.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a) a
> +NULL 1
> +2 2
> +select (select a from t1 where t1.a=t2.b), a from t2;
> +(select a from t1 where t1.a=t2.b) a
> +NULL 1
> +NULL 2
> +select (select a from t1), a, (select 1 union select 2 limit 1) from t2;
> +(select a from t1) a (select 1 union select 2 limit 1)
> +2 1 1
> +2 2 1
> +select (select a from t3), a from t2;
> +(select a from t3) a
> +NULL 1
> +NULL 2
> +select * from t2 where t2.a=(select a from t1);
> +a b
> +2 7
> +insert into t3 values (6),(7),(3);
> +select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
> +a b
> +1 7
> +2 7
> +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 order by a limit 2) limit 3;
> +a b
> +1 7
> +2 7
> +3 8
> +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
> +a b
> +1 7
> +2 7
> +4 8
> +3 8
> +explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> +3 UNION t4 ALL NULL NULL NULL NULL 3 100.00 Using where
> +4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00
> +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`)
> +select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
> +(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
> +3 1
> +7 2
> +select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
> +(select * from t2 where a>1) as tt;
> +(select t3.a from t3 where a<8 order by 1 desc limit 1) a
> +7 2
> +explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
> +(select * from t2 where a>1) as tt;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using filesort
> +Warnings:
> +Note 1003 select (select `test`.`t3`.`a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,`test`.`t2`.`a` AS `a` from `test`.`t2` where (`test`.`t2`.`a` > 1)
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1);
> +a
> +2
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1);
> +a
> +2
> +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1);
> +a
> +select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
> +b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)
> +8 7.5000
> +8 4.5000
> +9 7.5000
> +explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00
> +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
> +Warnings:
> +Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
> +Note 1003 select `test`.`t4`.`b` AS `b`,(select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
> +select * from t3 where exists (select * from t2 where t2.b=t3.a);
> +a
> +7
> +select * from t3 where not exists (select * from t2 where t2.b=t3.a);
> +a
> +6
> +3
> +select * from t3 where a in (select b from t2);
> +a
> +7
> +select * from t3 where a not in (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a = some (select b from t2);
> +a
> +7
> +select * from t3 where a <> any (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a = all (select b from t2);
> +a
> +7
> +select * from t3 where a <> all (select b from t2);
> +a
> +6
> +3
> +insert into t2 values (100, 5);
> +select * from t3 where a < any (select b from t2);
> +a
> +6
> +3
> +select * from t3 where a < all (select b from t2);
> +a
> +3
> +select * from t3 where a >= any (select b from t2);
> +a
> +6
> +7
> +explain extended select * from t3 where a >= any (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= (select min(`test`.`t2`.`b`) from `test`.`t2`))))
> +select * from t3 where a >= all (select b from t2);
> +a
> +7
> +delete from t2 where a=100;
> +select * from t3 where a in (select a,b from t2);
> +ERROR 21000: Operand should contain 1 column(s)
> +select * from t3 where a in (select * from t2);
> +ERROR 21000: Operand should contain 1 column(s)
> +insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
> +select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +insert into t2 values (2,10);
> +select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +10 1
> +delete from t2 where a=2 and b=10;
> +select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b);
> +b ma
> +7 12
> +create table t5 (a int);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +insert into t5 values (5);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +insert into t5 values (2);
> +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a
> +NULL 1
> +2 2
> +explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
> +2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00
> +3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 100.00 Using where
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> +Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> +Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from `test`.`t1` where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> +ERROR 21000: Subquery returns more than 1 row
> +create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> +create table t7( uq int primary key, name char(25));
> +insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
> +insert into t6 values (1,1),(1,2),(2,2),(1,3);
> +select * from t6 where exists (select * from t7 where uq = clinic_uq);
> +patient_uq clinic_uq
> +1 1
> +1 2
> +2 2
> +explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t6 ALL NULL NULL NULL NULL 4 100.00 Using where
> +2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> +Warnings:
> +Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> +ERROR 23000: Column 'a' in field list is ambiguous
> +drop table t1,t2,t3;
> +CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
> +INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
> +CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
> +INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
> +CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
> +INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
> +SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
> +a b
> +W 1732-02-22
> +SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
> +a b
> +W 1
> +SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
> +a b
> +W a
> +CREATE TABLE `t8` (
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +`email` varchar(60) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`pseudo`),
> +UNIQUE KEY `email` (`email`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
> +INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
> +INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
> +EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +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
> +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
> +3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
> +Warnings:
> +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where ('joce' = (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 ('joce' = (select 'joce' from `test`.`t8` where 1))
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
> +t8 WHERE pseudo='joce');
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE
> +pseudo='joce');
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
> +pseudo
> +joce
> +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
> +ERROR 21000: Subquery returns more than 1 row
> +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
> +CREATE TABLE `t1` (
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (topic,date,pseudo) VALUES
> +('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
> +EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index
> +Warnings:
> +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')
> +EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index
> +Warnings:
> +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')`
> +SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
> +date
> +2002-08-03
> +SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
> +(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')
> +2002-08-03
> +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
> +1
> +1
> +1
> +1
> +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
> +ERROR 21000: Subquery returns more than 1 row
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 index NULL topic 3 NULL 2 100.00 Using index
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where (1 = (select 1 union select 1))
> +drop table t1;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM ROW_FORMAT=FIXED;
> +INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
> +CREATE TABLE `t2` (
> +`mot` varchar(30) NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
> +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
> +INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
> +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
> +a
> +40143
> +SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
> +numeropost maxnumrep
> +43506 2
> +40143 1
> +SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b;
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT 1 IN (SELECT 1 FROM t2 HAVING a);
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1);
> +mot topic date pseudo
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1);
> +mot topic date pseudo
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic);
> +mot topic date pseudo
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2;
> +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100)
> +joce 40143 2002-10-22 joce 1
> +joce 43506 2002-10-22 joce 1
> +SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2);
> +mot topic date pseudo
> +SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +joce 43506 2002-10-22 joce
> +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
> +mot topic date pseudo
> +joce 40143 2002-10-22 joce
> +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2;
> +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000)
> +joce 40143 2002-10-22 joce 1
> +joce 43506 2002-10-22 joce 0
> +drop table t1,t2;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM ROW_FORMAT=FIXED;
> +INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
> +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
> +ERROR 21000: Subquery returns more than 1 row
> +select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
> +ERROR 21000: Subquery returns more than 1 row
> +show warnings;
> +Level Code Message
> +Error 1242 Subquery returns more than 1 row
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1),(2),(3);
> +(select * from t1) union (select * from t1) order by (select a from t1 limit 1);
> +a
> +1
> +2
> +3
> +drop table t1;
> +CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
> +INSERT INTO t1 VALUES ();
> +SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t1;
> +CREATE TABLE `t1` (
> +`numeropost` mediumint(8) unsigned NOT NULL default '0',
> +`numreponse` int(10) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) NOT NULL default '',
> +PRIMARY KEY (`numeropost`,`numreponse`),
> +UNIQUE KEY `numreponse` (`numreponse`),
> +KEY `pseudo` (`pseudo`,`numeropost`)
> +) ENGINE=MyISAM;
> +SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
> +ERROR 42S22: Reference 'numreponse' not supported (forward reference in item list)
> +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
> +ERROR 42S22: Unknown column 'a' in 'having clause'
> +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
> +numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
> +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');
> +ERROR 21000: Subquery returns more than 1 row
> +EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`)
> +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using index
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select 3 AS `numreponse` from `test`.`t1` where ((3 = (select max(`test`.`t1`.`numreponse`) from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`))))
> +drop table t1;
> +CREATE TABLE t1 (a int(1));
> +INSERT INTO t1 VALUES (1);
> +SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
> +1
> +1
> +drop table t1;
> +create table t1 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t1 values (0, 10),(1, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 22),(3, 23);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +2 12
> +update t1 set b= (select b from t1);
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +update t1 set b= (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +update t1 set b= (select b from t2 where t1.a = t2.a);
> +select * from t1;
> +a b
> +0 NULL
> +1 21
> +2 22
> +drop table t1, t2;
> +create table t1 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t1 values (0, 10),(1, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 12),(3, 23);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +2 12
> +select * from t1 where b = (select b from t2 where t1.a = t2.a);
> +a b
> +2 12
> +delete from t1 where b in (select b from t1);
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +delete from t1 where b = (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +delete from t1 where b = (select b from t2 where t1.a = t2.a);
> +select * from t1;
> +a b
> +0 10
> +1 11
> +drop table t1, t2;
> +create table t11 (a int NOT NULL, b int, primary key (a));
> +create table t12 (a int NOT NULL, b int, primary key (a));
> +create table t2 (a int NOT NULL, b int, primary key (a));
> +insert into t11 values (0, 10),(1, 11),(2, 12);
> +insert into t12 values (33, 10),(22, 11),(2, 12);
> +insert into t2 values (1, 21),(2, 12),(3, 23);
> +select * from t11;
> +a b
> +0 10
> +1 11
> +2 12
> +select * from t12;
> +a b
> +33 10
> +22 11
> +2 12
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
> +ERROR HY000: You can't specify target table 't12' for update in FROM clause
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
> +ERROR 21000: Subquery returns more than 1 row
> +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
> +select * from t11;
> +a b
> +0 10
> +1 11
> +select * from t12;
> +a b
> +33 10
> +22 11
> +drop table t11, t12, t2;
> +CREATE TABLE t1 (x int) ENGINE=MyISAM;
> +create table t2 (a int) ENGINE=MyISAM;
> +create table t3 (b int);
> +insert into t2 values (1);
> +insert into t3 values (1),(2);
> +INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +INSERT INTO t1 (x) VALUES ((SELECT b FROM t3));
> +ERROR 21000: Subquery returns more than 1 row
> +INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
> +select * from t1;
> +x
> +1
> +insert into t2 values (1);
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
> +select * from t1;
> +x
> +1
> +2
> +INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +11
> +11
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
> +ERROR 42S22: Unknown column 'x' in 'field list'
> +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
> +select * from t1;
> +x
> +1
> +2
> +3
> +3
> +11
> +11
> +2
> +drop table t1, t2, t3;
> +CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM;
> +create table t2 (a int);
> +create table t3 (a int);
> +insert into t2 values (1);
> +insert into t3 values (1),(2);
> +select * from t1;
> +x y
> +replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2));
> +ERROR HY000: You can't specify target table 't1' for update in FROM clause
> +replace into t1 (x, y) VALUES ((SELECT a FROM t3), (SELECT a+1 FROM t2));
> +ERROR 21000: Subquery returns more than 1 row
> +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
> +select * from t1;
> +x y
> +1 2
> +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
> +select * from t1;
> +x y
> +1 3
> +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 1
> +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 2
> +replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
> +select * from t1;
> +x y
> +1 3
> +4 2
> +2 1
> +drop table t1, t2, t3;
> +SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
> +ERROR HY000: No tables used
> +CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (1),(2);
> +SELECT * FROM t2 WHERE id IN (SELECT 1);
> +id
> +1
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ref id id 5 const 1 100.00 Using index
> +Warnings:
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
> +SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
> +id
> +1
> +SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
> +id
> +2
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 ref id id 5 const 1 100.00 Using index
> +Warnings:
> +Note 1249 Select 3 was reduced during optimization
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = (1 + 1))
> +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index NULL id 5 NULL 2 100.00 Using where; Using index
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> +Warnings:
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> +id
> +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> +id
> +2
> +INSERT INTO t2 VALUES ((SELECT * FROM t2));
> +ERROR HY000: You can't specify target table 't2' for update in FROM clause
> +INSERT INTO t2 VALUES ((SELECT id FROM t2));
> +ERROR HY000: You can't specify target table 't2' for update in FROM clause
> +SELECT * FROM t2;
> +id
> +1
> +2
> +CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 values (1),(1);
> +UPDATE t2 SET id=(SELECT * FROM t1);
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t2, t1;
> +create table t1 (a int);
> +insert into t1 values (1),(2),(3);
> +select 1 IN (SELECT * from t1);
> +1 IN (SELECT * from t1)
> +1
> +select 10 IN (SELECT * from t1);
> +10 IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a=2;
> +select 1 IN (SELECT * from t1);
> +1 IN (SELECT * from t1)
> +1
> +select 3 IN (SELECT * from t1);
> +3 IN (SELECT * from t1)
> +1
> +select 10 IN (SELECT * from t1);
> +10 IN (SELECT * from t1)
> +NULL
> +select 1 > ALL (SELECT * from t1);
> +1 > ALL (SELECT * from t1)
> +0
> +select 10 > ALL (SELECT * from t1);
> +10 > ALL (SELECT * from t1)
> +NULL
> +select 1 > ANY (SELECT * from t1);
> +1 > ANY (SELECT * from t1)
> +NULL
> +select 10 > ANY (SELECT * from t1);
> +10 > ANY (SELECT * from t1)
> +1
> +drop table t1;
> +create table t1 (a varchar(20));
> +insert into t1 values ('A'),('BC'),('DEF');
> +select 'A' IN (SELECT * from t1);
> +'A' IN (SELECT * from t1)
> +1
> +select 'XYZS' IN (SELECT * from t1);
> +'XYZS' IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a='BC';
> +select 'A' IN (SELECT * from t1);
> +'A' IN (SELECT * from t1)
> +1
> +select 'DEF' IN (SELECT * from t1);
> +'DEF' IN (SELECT * from t1)
> +1
> +select 'XYZS' IN (SELECT * from t1);
> +'XYZS' IN (SELECT * from t1)
> +NULL
> +select 'A' > ALL (SELECT * from t1);
> +'A' > ALL (SELECT * from t1)
> +0
> +select 'XYZS' > ALL (SELECT * from t1);
> +'XYZS' > ALL (SELECT * from t1)
> +NULL
> +select 'A' > ANY (SELECT * from t1);
> +'A' > ANY (SELECT * from t1)
> +NULL
> +select 'XYZS' > ANY (SELECT * from t1);
> +'XYZS' > ANY (SELECT * from t1)
> +1
> +drop table t1;
> +create table t1 (a float);
> +insert into t1 values (1.5),(2.5),(3.5);
> +select 1.5 IN (SELECT * from t1);
> +1.5 IN (SELECT * from t1)
> +1
> +select 10.5 IN (SELECT * from t1);
> +10.5 IN (SELECT * from t1)
> +0
> +select NULL IN (SELECT * from t1);
> +NULL IN (SELECT * from t1)
> +NULL
> +update t1 set a=NULL where a=2.5;
> +select 1.5 IN (SELECT * from t1);
> +1.5 IN (SELECT * from t1)
> +1
> +select 3.5 IN (SELECT * from t1);
> +3.5 IN (SELECT * from t1)
> +1
> +select 10.5 IN (SELECT * from t1);
> +10.5 IN (SELECT * from t1)
> +NULL
> +select 1.5 > ALL (SELECT * from t1);
> +1.5 > ALL (SELECT * from t1)
> +0
> +select 10.5 > ALL (SELECT * from t1);
> +10.5 > ALL (SELECT * from t1)
> +NULL
> +select 1.5 > ANY (SELECT * from t1);
> +1.5 > ANY (SELECT * from t1)
> +NULL
> +select 10.5 > ANY (SELECT * from t1);
> +10.5 > ANY (SELECT * from t1)
> +1
> +explain extended select (select a+1) from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
> +Note 1249 Select 2 was reduced during optimization
> +Note 1003 select (`test`.`t1`.`a` + 1) AS `(select a+1)` from `test`.`t1`
> +select (select a+1) from t1;
> +(select a+1)
> +2.5
> +NULL
> +4.5
> +drop table t1;
> +CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY (a));
> +CREATE TABLE t2 (a int(11) default '0', INDEX (a));
> +INSERT INTO t1 VALUES (1),(2),(3),(4);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
> +a t1.a in (select t2.a from t2)
> +1 1
> +2 1
> +3 1
> +4 0
> +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
> +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
> +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`
> +CREATE TABLE t3 (a int(11) default '0');
> +INSERT INTO t3 VALUES (1),(2),(3);
> +SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> +a t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
> +1 1
> +2 1
> +3 1
> +4 0
> +explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> +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
> +2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +drop table t1,t2,t3;
> +create table t1 (a float);
> +select 10.5 IN (SELECT * from t1 LIMIT 1);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +drop table t1;
> +create table t1 (a int, b int, c varchar(10));
> +create table t2 (a int);
> +insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
> +insert into t2 values (1),(2),(NULL);
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a)
> +1 1 a
> +2 0 b
> +NULL NULL NULL
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a)
> +1 0 a
> +2 1 b
> +NULL NULL NULL
> +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2;
> +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a)
> +1 0 a
> +2 0 b
> +NULL NULL NULL
> +drop table t1,t2;
> +create table t1 (a int, b real, c varchar(10));
> +insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
> +select ROW(1, 1, 'a') IN (select a,b,c from t1);
> +ROW(1, 1, 'a') IN (select a,b,c from t1)
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1);
> +ROW(1, 2, 'a') IN (select a,b,c from t1)
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1);
> +ROW(1, 1, 'a') IN (select b,a,c from t1)
> +1
> +select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
> +ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null)
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
> +ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null)
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
> +ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null)
> +1
> +select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
> +ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a')
> +1
> +select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
> +ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a')
> +0
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
> +ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a')
> +1
> +select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
> +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1);
> +do @a:=(SELECT a from t1);
> +select @a;
> +@a
> +1
> +set @a:=2;
> +set @a:=(SELECT a from t1);
> +select @a;
> +@a
> +1
> +drop table t1;
> +do (SELECT a from t1);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +set @a:=(SELECT a from t1);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +CREATE TABLE t1 (a int, KEY(a));
> +HANDLER t1 OPEN;
> +HANDLER t1 READ a=((SELECT 1));
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1))' at line 1
> +HANDLER t1 CLOSE;
> +drop table t1;
> +create table t1 (a int);
> +create table t2 (b int);
> +insert into t1 values (1),(2);
> +insert into t2 values (1);
> +select a from t1 where a in (select a from t1 where a in (select b from t2));
> +a
> +1
> +drop table t1, t2;
> +create table t1 (a int, b int);
> +create table t2 like t1;
> +insert into t1 values (1,2),(1,3),(1,4),(1,5);
> +insert into t2 values (1,2),(1,3);
> +select * from t1 where row(a,b) in (select a,b from t2);
> +a b
> +1 2
> +1 3
> +drop table t1, t2;
> +CREATE TABLE `t1` (`i` int(11) NOT NULL default '0',PRIMARY KEY (`i`)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1);
> +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
> +select * from t1;
> +i
> +2
> +drop table t1;
> +CREATE TABLE t1 (a int(1));
> +EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select rand() from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
> +EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select encrypt('test') from `test`.`t1`) AS `(SELECT ENCRYPT('test') FROM t1)` from `test`.`t1`
> +EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select (select benchmark(1,1) from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1`
> +drop table t1;
> +CREATE TABLE `t1` (
> +`mot` varchar(30) character set latin1 NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
> +KEY `pseudo` (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +CREATE TABLE `t2` (
> +`mot` varchar(30) character set latin1 NOT NULL default '',
> +`topic` mediumint(8) unsigned NOT NULL default '0',
> +`date` date NOT NULL default '0000-00-00',
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
> +KEY `pseudo` (`pseudo`,`date`,`topic`),
> +KEY `topic` (`topic`)
> +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
> +CREATE TABLE `t3` (
> +`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
> +`maxnumrep` int(10) unsigned NOT NULL default '0',
> +PRIMARY KEY (`numeropost`),
> +UNIQUE KEY `maxnumrep` (`maxnumrep`)
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES ('joce','1','','joce'),('test','2','','test');
> +Warnings:
> +Warning 1265 Data truncated for column 'date' at row 1
> +Warning 1265 Data truncated for column 'date' at row 2
> +INSERT INTO t2 VALUES ('joce','1','','joce'),('test','2','','test');
> +Warnings:
> +Warning 1265 Data truncated for column 'date' at row 1
> +Warning 1265 Data truncated for column 'date' at row 2
> +INSERT INTO t3 VALUES (1,1);
> +SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE
> +numeropost=topic);
> +topic
> +2
> +select * from t1;
> +mot topic date pseudo
> +joce 1 0000-00-00 joce
> +test 2 0000-00-00 test
> +DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT
> +EXISTS(SELECT * FROM t3 WHERE numeropost=topic));
> +select * from t1;
> +mot topic date pseudo
> +joce 1 0000-00-00 joce
> +drop table t1, t2, t3;
> +SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
> +a (SELECT a)
> +1 1
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT 1)` int(1) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT a)` int(1) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(1) NOT NULL DEFAULT '0',
> + `(SELECT a+0)` int(3) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
> +select * from t1;
> +a
> +2
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` bigint(20) NOT NULL DEFAULT '0'
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +drop table t1;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +explain extended select a,(select (select rand() from t1 limit 1) from t1 limit 1)
> +from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
> +2 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00
> +3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00
> +Warnings:
> +Note 1003 select `test`.`t1`.`a` AS `a`,(select (select rand() from `test`.`t1` limit 1) from `test`.`t1` limit 1) AS `(select (select rand() from t1 limit 1) from t1 limit 1)` from `test`.`t1`
> +drop table t1;
> +select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent);
> +ERROR 42S02: Table 'test.t1' doesn't exist
> +CREATE TABLE t1 (
> +ID int(11) NOT NULL auto_increment,
> +name char(35) NOT NULL default '',
> +t2 char(3) NOT NULL default '',
> +District char(20) NOT NULL default '',
> +Population int(11) NOT NULL default '0',
> +PRIMARY KEY (ID)
> +) ENGINE=MyISAM;
> +INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
> +INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329);
> +INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117);
> +CREATE TABLE t2 (
> +Code char(3) NOT NULL default '',
> +Name char(52) NOT NULL default '',
> +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
> +Region char(26) NOT NULL default '',
> +SurfaceArea float(10,2) NOT NULL default '0.00',
> +IndepYear smallint(6) default NULL,
> +Population int(11) NOT NULL default '0',
> +LifeExpectancy float(3,1) default NULL,
> +GNP float(10,2) default NULL,
> +GNPOld float(10,2) default NULL,
> +LocalName char(45) NOT NULL default '',
> +GovernmentForm char(45) NOT NULL default '',
> +HeadOfState char(60) default NULL,
> +Capital int(11) default NULL,
> +Code2 char(2) NOT NULL default '',
> +PRIMARY KEY (Code)
> +) ENGINE=MyISAM;
> +INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU');
> +INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ');
> +select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent);
> +Continent Name Population
> +Oceania Sydney 3276207
> +drop table t1, t2;
> +CREATE TABLE `t1` (
> +`id` mediumint(8) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) character set latin1 NOT NULL default '',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `pseudo` (`pseudo`)
> +) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (pseudo) VALUES ('test');
> +SELECT 0 IN (SELECT 1 FROM t1 a);
> +0 IN (SELECT 1 FROM t1 a)
> +0
> +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> +Warnings:
> +Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
> +INSERT INTO t1 (pseudo) VALUES ('test1');
> +SELECT 0 IN (SELECT 1 FROM t1 a);
> +0 IN (SELECT 1 FROM t1 a)
> +0
> +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
> +Warnings:
> +Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
> +drop table t1;
> +CREATE TABLE `t1` (
> +`i` int(11) NOT NULL default '0',
> +PRIMARY KEY (`i`)
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1);
> +UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
> +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
> +UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
> +ERROR 42S22: Unknown column 't.i' in 'field list'
> +select * from t1;
> +i
> +3
> +drop table t1;
> +CREATE TABLE t1 (
> +id int(11) default NULL
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
> +CREATE TABLE t2 (
> +id int(11) default NULL,
> +name varchar(15) default NULL
> +) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
> +update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
> +select * from t2;
> +id name
> +4 vita
> +1 lenka
> +2 lenka
> +1 lenka
> +drop table t1,t2;
> +create table t1 (a int, unique index indexa (a));
> +insert into t1 values (-1), (-4), (-2), (NULL);
> +select -10 IN (select a from t1 FORCE INDEX (indexa));
> +-10 IN (select a from t1 FORCE INDEX (indexa))
> +NULL
> +drop table t1;
> +create table t1 (id int not null auto_increment primary key, salary int, key(salary));
> +insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
> +explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ref salary salary 5 const 0 0.00 Using index condition
> +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
> +Warnings:
> +Note 1003 select `test`.`t1`.`id` AS `id` from `test`.`t1` where (`test`.`t1`.`salary` = (select max(`test`.`t1`.`salary`) from `test`.`t1`))
> +drop table t1;
> +CREATE TABLE t1 (
> +ID int(10) unsigned NOT NULL auto_increment,
> +SUB_ID int(3) unsigned NOT NULL default '0',
> +REF_ID int(10) unsigned default NULL,
> +REF_SUB int(3) unsigned default '0',
> +PRIMARY KEY (ID,SUB_ID),
> +UNIQUE KEY t1_PK (ID,SUB_ID),
> +KEY t1_FK (REF_ID,REF_SUB),
> +KEY t1_REFID (REF_ID)
> +) ENGINE=MyISAM CHARSET=cp1251;
> +INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
> +SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
> +REF_ID
> +DROP TABLE t1;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +insert into t1 values (1,0), (2,0), (3,0);
> +insert into t2 values (1,1), (2,1), (3,1), (2,2);
> +update ignore t1 set b=(select b from t2 where t1.a=t2.a);
> +Warnings:
> +Error 1242 Subquery returns more than 1 row
> +select * from t1;
> +a b
> +1 1
> +2 NULL
> +3 1
> +drop table t1, t2;
> +CREATE TABLE `t1` (
> +`id` mediumint(8) unsigned NOT NULL auto_increment,
> +`pseudo` varchar(35) NOT NULL default '',
> +`email` varchar(60) NOT NULL default '',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `email` (`email`),
> +UNIQUE KEY `pseudo` (`pseudo`)
> +) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
> +INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
> +SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
> +a b
> +test test
> +test1 test1
> +drop table if exists t1;
> +(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
> +a
> +1
> +create table t1 (a int not null, b int, primary key (a));
> +create table t2 (a int not null, primary key (a));
> +create table t3 (a int not null, b int, primary key (a));
> +insert into t1 values (1,10), (2,20), (3,30), (4,40);
> +insert into t2 values (2), (3), (4), (5);
> +insert into t3 values (10,3), (20,4), (30,5);
> +select * from t2 where t2.a in (select a from t1);
> +a
> +2
> +3
> +4
> +explain extended select * from t2 where t2.a in (select a from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 75.00 Using where; Using index; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +a
> +2
> +3
> +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
> +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
> +drop table t1, t2, t3;
> +create table t1 (a int, b int, index a (a,b));
> +create table t2 (a int, index a (a));
> +create table t3 (a int, b int, index a (a));
> +insert into t1 values (1,10), (2,20), (3,30), (4,40);
> +create table t0(a int);
> +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +insert into t1
> +select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
> +insert into t2 values (2), (3), (4), (5);
> +insert into t3 values (10,3), (20,4), (30,5);
> +select * from t2 where t2.a in (select a from t1);
> +a
> +2
> +3
> +4
> +explain extended select * from t2 where t2.a in (select a from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`)
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +a
> +2
> +3
> +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`))
> +insert into t1 values (3,31);
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +a
> +2
> +3
> +4
> +select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
> +a
> +2
> +4
> +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
> +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
> +Warnings:
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
> +drop table t0, t1, t2, t3;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +create table t3 (a int, b int);
> +insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
> +insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
> +insert into t3 values (3,3), (2,2), (1,1);
> +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3;
> +a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1)
> +3 1
> +2 2
> +1 2
> +drop table t1,t2,t3;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +insert into t1 values (1);
> +insert into t2 values (1);
> +select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
> +s1
> +1
> +drop table t1,t2;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +insert into t1 values (1);
> +insert into t2 values (1);
> +update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
> +ERROR 42S22: Unknown column 'x.s1' in 'field list'
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
> +s2 CHAR(5) COLLATE latin1_swedish_ci);
> +INSERT INTO t1 VALUES ('z','?');
> +select * from t1 where s1 > (select max(s2) from t1);
> +ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
> +select * from t1 where s1 > any (select max(s2) from t1);
> +ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>'
> +drop table t1;
> +create table t1(toid int,rd int);
> +create table t2(userid int,pmnew int,pmtotal int);
> +insert into t2 values(1,0,0),(2,0,0);
> +insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2);
> +select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1);
> +userid pmtotal pmnew calc_total calc_new
> +1 0 0 9 3
> +2 0 0 4 2
> +drop table t1, t2;
> +create table t1 (s1 char(5));
> +select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
> +ERROR 21000: Operand should contain 1 column(s)
> +insert into t1 values ('tttt');
> +select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1);
> +s1
> +tttt
> +explain extended (select * from t1);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
> +Warnings:
> +Note 1003 (select 'tttt' AS `s1` from `test`.`t1`)
> +(select * from t1);
> +s1
> +tttt
> +drop table t1;
> +create table t1 (s1 char(5), index s1(s1));
> +create table t2 (s1 char(5), index s1(s1));
> +insert into t1 values ('a1'),('a2'),('a3');
> +insert into t2 values ('a1'),('a2');
> +select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
> +s1 s1 NOT IN (SELECT s1 FROM t2)
> +a1 0
> +a2 0
> +a3 1
> +select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
> +s1 s1 = ANY (SELECT s1 FROM t2)
> +a1 1
> +a2 1
> +a3 0
> +select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
> +s1 s1 <> ALL (SELECT s1 FROM t2)
> +a1 0
> +a2 0
> +a3 1
> +select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
> +s1 s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')
> +a1 0
> +a2 1
> +a3 1
> +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
> +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
> +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`
> +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
> +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
> +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`
> +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
> +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
> +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`
> +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
> +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
> +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`
> +drop table t1,t2;
> +create table t2 (a int, b int);
> +create table t3 (a int);
> +insert into t3 values (6),(7),(3);
> +select * from t3 where a >= all (select b from t2);
> +a
> +6
> +7
> +3
> +explain extended select * from t3 where a >= all (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` < (select max(NULL) from `test`.`t2`))))
> +select * from t3 where a >= some (select b from t2);
> +a
> +explain extended select * from t3 where a >= some (select b from t2);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where a >= all (select b from t2 group by 1);
> +a
> +6
> +7
> +3
> +explain extended select * from t3 where a >= all (select b from t2 group by 1);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` < <max>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where a >= some (select b from t2 group by 1);
> +a
> +explain extended select * from t3 where a >= some (select b from t2 group by 1);
> +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 Using where
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` >= <min>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where NULL >= any (select b from t2);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where NULL >= any (select b from t2 group by 1);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= <min>(select NULL from `test`.`t2` group by 1))))
> +select * from t3 where NULL >= some (select b from t2);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= (select min(NULL) from `test`.`t2`))))
> +select * from t3 where NULL >= some (select b from t2 group by 1);
> +a
> +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
> +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
> +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(NULL,(NULL >= <min>(select NULL from `test`.`t2` group by 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);
> +a
> +6
> +7
> +explain extended select * from t3 where a > all (select max(b) from t2 group by a);
> +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 Using where
> +2 SUBQUERY t2 ALL NULL NULL NULL NULL 4 100.00 Using temporary
> +Warnings:
> +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(`test`.`t3`.`a` <= <max>(select max(`test`.`t2`.`b`) from `test`.`t2` group by `test`.`t2`.`a`))))
> +drop table t2, t3;
> +CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
> +INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
> +CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`),FULLTEXT KEY `name` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
> +INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
> +CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
> +INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
> +CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
> +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
> +dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')
> +-1 Valid 1
> +-1 Valid 2 1
> +-1 Should Not Return 0
> +SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
> +dbid name
> +-1 Valid
> +-1 Valid 2
> +drop table t1,t2,t3,t4;
> +CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES (1),(5);
> +CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES (2),(6);
> +select * from t1 where (1,2,6) in (select * from t2);
> +ERROR 21000: Operand should contain 3 column(s)
> +DROP TABLE t1,t2;
> +create table t1 (s1 int);
> +insert into t1 values (1);
> +insert into t1 values (2);
> +set sort_buffer_size = (select s1 from t1);
> +ERROR 21000: Subquery returns more than 1 row
> +do (select * from t1);
> +Warnings:
> +Error 1242 Subquery returns more than 1 row
> +drop table t1;
> +create table t1 (s1 char);
> +insert into t1 values ('e');
> +select * from t1 where 'f' > any (select s1 from t1);
> +s1
> +e
> +select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
> +s1
> +e
> +explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
> +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
> +2 SUBQUERY 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
> +Warnings:
> +Note 1003 select 'e' AS `s1` from `test`.`t1` where <nop>(<in_optimizer>('f',('f' > <min>(select 'e' from `test`.`t1` union select 'e' from `test`.`t1`))))
> +drop table t1;
> +CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
> +CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
> +INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
> +select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c;
> +phone code
> +69294728265 6
> +18621828126 1862
> +89356874041 NULL
> +95895001874 NULL
> +drop table t1, t2;
> +create table t1 (s1 int);
> +create table t2 (s1 int);
> +select * from t1 where (select count(*) from t2 where t1.s2) = 1;
> +ERROR 42S22: Unknown column 't1.s2' in 'where clause'
> +select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
> +ERROR 42S22: Unknown column 't1.s2' in 'group statement'
> +select count(*) from t2 group by t1.s2;
> +ERROR 42S22: Unknown column 't1.s2' in 'group statement'
> +drop table t1, t2;
> +CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
> +CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
> +INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
> +INSERT INTO t2 VALUES (100, 200, 'C');
> +SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
> +COLC
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (a int(1));
> +INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
> +SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
> +(SELECT a)
> +1
> +2
> +3
> +4
> +5
> +DROP TABLE t1;
> +create table t1 (a int, b decimal(13, 3));
> +insert into t1 values (1, 0.123);
> +select a, (select max(b) from t1) into outfile "../../tmp/subselect.out.file.1" from t1;
> +delete from t1;
> +load data infile "../../tmp/subselect.out.file.1" into table t1;
> +select * from t1;
> +a b
> +1 0.123
> +drop table t1;
> +CREATE TABLE `t1` (
> +`id` int(11) NOT NULL auto_increment,
> +`id_cns` tinyint(3) unsigned NOT NULL default '0',
> +`tipo` enum('','UNO','DUE') NOT NULL default '',
> +`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
> +`particolare` mediumint(8) unsigned NOT NULL default '0',
> +`generale` mediumint(8) unsigned NOT NULL default '0',
> +`bis` tinyint(3) unsigned NOT NULL default '0',
> +PRIMARY KEY (`id`),
> +UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
> +UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
> +);
> +INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
> +CREATE TABLE `t2` (
> +`id` tinyint(3) unsigned NOT NULL auto_increment,
> +`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
> +PRIMARY KEY (`id`)
> +);
> +INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
> +SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns;
> +id max_anno_dep PIPPO
> +16 1987 1
> +50 1990 0
> +51 1990 NULL
> +DROP TABLE t1, t2;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +SET SQL_SELECT_LIMIT=1;
> +select sum(a) from (select * from t1) as a;
> +sum(a)
> +6
> +select 2 in (select * from t1);
> +2 in (select * from t1)
> +1
> +SET SQL_SELECT_LIMIT=default;
> +drop table t1;
> +CREATE TABLE t1 (a int, b int, INDEX (a));
> +INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
> +SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
> +a b
> +1 1
> +1 2
> +1 3
> +DROP TABLE t1;
> +create table t1(val varchar(10));
> +insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
> +select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%');
> +count(*)
> +0
> +drop table t1;
> +create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
> +insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12');
> +select * from t1 where id not in (select id from t1 where id < 8);
> +id text
> +8 text8
> +9 text9
> +10 text10
> +11 text11
> +12 text12
> +select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> +id text
> +8 text8
> +9 text9
> +10 text10
> +11 text11
> +12 text12
> +explain extended select * from t1 where id not in (select id from t1 where id < 8);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> +Warnings:
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> +Warnings:
> +Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> +create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> +insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> +select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
> +id text id text id text
> +1 text1 1 text1 1 text1
> +2 text2 2 text2 2 text2
> +3 text3 3 text3 3 text3
> +4 text4 4 text4 4 text4
> +5 text5 5 text5 5 text5
> +6 text6 6 text6 6 text6
> +7 text7 7 text7 7 text7
> +8 text8 8 text8 8 text8
> +9 text9 9 text9 9 text9
> +10 text10 10 text10 10 text10
> +11 text11 11 text1 11 text11
> +12 text12 12 text2 12 text12
> +1000 text1000 NULL NULL 1000 text1000
> +1001 text1001 NULL NULL 1000 text1000
> +explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 SIMPLE a ALL NULL NULL NULL NULL 14 100.00
> +1 SIMPLE b eq_ref PRIMARY PRIMARY 4 test.a.id 2 100.00
> +1 SIMPLE c eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using index condition
> +Warnings:
> +Note 1003 select `test`.`a`.`id` AS `id`,`test`.`a`.`text` AS `text`,`test`.`b`.`id` AS `id`,`test`.`b`.`text` AS `text`,`test`.`c`.`id` AS `id`,`test`.`c`.`text` AS `text` from `test`.`t1` `a` left join `test`.`t2` `b` on(((`test`.`b`.`id` = `test`.`a`.`id`) or isnull(`test`.`b`.`id`))) join `test`.`t1` `c` where (if(isnull(`test`.`b`.`id`),1000,`test`.`b`.`id`) = `test`.`c`.`id`)
> +drop table t1,t2;
> +create table t1 (a int);
> +insert into t1 values (1);
> +explain select benchmark(1000, (select a from t1 where a=sha(rand())));
> +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
> +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 1
> +drop table t1;
> +create table t1(id int);
> +create table t2(id int);
> +create table t3(flag int);
> +select (select * from t3 where id not null) from t1, t2;
> +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) from t1, t2' at line 1
> +drop table t1,t2,t3;
> +CREATE TABLE t1 (id INT);
> +CREATE TABLE t2 (id INT);
> +INSERT INTO t1 VALUES (1), (2);
> +INSERT INTO t2 VALUES (1);
> +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
> +id c
> +1 1
> +2 0
> +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
> +id c
> +1 1
> +2 0
> +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
> +id c
> +1 1
> +2 0
> +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id;
> +id c
> +1 1
> +2 0
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 ( a int, b int );
> +INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
> +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +ALTER TABLE t1 ADD INDEX (a);
> +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 2 column(s)
> +SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2);
> +a
> +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 2 column(s)
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +ERROR 21000: Operand should contain 1 column(s)
> +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
> +a
> +1
> +2
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2);
> +a
> +1
> +3
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-')
> +0-
> +0-
> +1-
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-')
> +1-
> +0-
> +0-
> +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
> +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-')
> +0-
> +1-
> +0-
> +DROP TABLE t1;
> +CREATE TABLE t1 ( a double, b double );
> +INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
> +a
> +1
> +3
> +DROP TABLE t1;
> +CREATE TABLE t1 ( a char(1), b char(1));
> +INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
> +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +3
> +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +3
> +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +3
> +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +2
> +3
> +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2');
> +a
> +1
> +3
> +DROP TABLE t1;
> +create table t1 (a int, b int);
> +insert into t1 values (1,2),(3,4);
> +select * from t1 up where exists (select * from t1 where t1.a=up.a);
> +a b
> +1 2
> +3 4
> +explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> +Warnings:
> +Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +drop table t1;
> +CREATE TABLE t1 (t1_a int);
> +INSERT INTO t1 VALUES (1);
> +CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b));
> +INSERT INTO t2 VALUES (1, 1), (1, 2);
> +SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
> +HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
> +t1_a t2_a t2_b
> +1 1 2
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
> +INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
> +CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
> +INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
> +SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
> +id name id pet
> +1 Tim 1 Fido
> +2 Rebecca 2 Spot
> +3 NULL 3 Felix
> +drop table t1,t2;
> +CREATE TABLE t1 ( a int, b int );
> +CREATE TABLE t2 ( c int, d int );
> +INSERT INTO t1 VALUES (1,2), (2,3), (3,4);
> +SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +abc b
> +1 2
> +2 3
> +3 4
> +INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +select * from t2;
> +c d
> +1 2
> +2 3
> +3 4
> +CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b =
> +(SELECT MIN(b) FROM t1 WHERE a=outr.a);
> +select * from t3;
> +abc b
> +1 2
> +2 3
> +3 4
> +prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);";
> +execute stmt1;
> +deallocate prepare stmt1;
> +select * from t2;
> +c d
> +1 2
> +2 3
> +3 4
> +1 2
> +2 3
> +3 4
> +drop table t3;
> +prepare stmt1 from "CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);";
> +execute stmt1;
> +select * from t3;
> +abc b
> +1 2
> +2 3
> +3 4
> +deallocate prepare stmt1;
> +DROP TABLE t1, t2, t3;
> +CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> +insert into t1 values (1);
> +CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> +insert into t2 values (1,2);
> +select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
> +a C
> +1 1
> +drop table t1,t2;
> +create table t1 (a int not null auto_increment primary key, b varchar(40), fulltext(b));
> +insert into t1 (b) values ('ball'),('ball games'), ('games'), ('foo'), ('foobar'), ('Serg'), ('Sergei'),('Georg'), ('Patrik'),('Hakan');
> +create table t2 (a int);
> +insert into t2 values (1),(3),(2),(7);
> +select a,b from t1 where match(b) against ('Ball') > 0;
> +a b
> +1 ball
> +2 ball games
> +select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0);
> +a
> +1
> +2
> +drop table t1,t2;
> +CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin);
> +CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000003','603','D0000000001','I0000000001');
> +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000004','101','D0000000001','I0000000001');
> +SELECT `IZAVORGANG_ID` FROM t1 WHERE `KUERZEL` IN(SELECT MIN(`KUERZEL`)`Feld1` FROM t1 WHERE `KUERZEL` LIKE'601%'And`IZAANALYSEART_ID`='D0000000001');
> +IZAVORGANG_ID
> +D0000000001
> +drop table t1;
> +CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
> +CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
> +insert into t1 values (1,1),(1,2),(2,1),(2,2);
> +insert into t2 values (1,2),(2,2);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +alter table t2 drop primary key;
> +alter table t2 add key KEY1 (aid, bid);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +alter table t2 drop key KEY1;
> +alter table t2 add primary key (bid, aid);
> +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
> +aid bid
> +1 1
> +2 1
> +drop table t1,t2;
> +CREATE TABLE t1 (howmanyvalues bigint, avalue int);
> +INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
> +SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
> +howmanyvalues count(*)
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 2
> +3 3
> +4 4
> +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
> +howmanyvalues mycount
> +1 1
> +2 1
> +3 1
> +4 1
> +drop table t1;
> +create table t1 (x int);
> +select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x;
> +(select b.x from t1 as b where b.x=a.x)
> +drop table t1;
> +CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
> +INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
> +CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
> +INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
> +SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
> +ERROR 42S22: Unknown column 'b.sc' in 'field list'
> +SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
> +ac
> +700
> +NULL
> +drop tables t1,t2;
> +create table t1 (a int not null, b int not null, c int, primary key (a,b));
> +insert into t1 values (1,1,1), (2,2,2), (3,3,3);
> +set @b:= 0;
> +explain select sum(a) from t1 where b > @b;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index
> +set @a:= (select sum(a) from t1 where b > @b);
> +explain select a from t1 where c=2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
> +do @a:= (select sum(a) from t1 where b > @b);
> +explain select a from t1 where c=2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
> +drop table t1;
> +set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
> +create table t1 (a int, b int);
> +create table t2 (a int, b int);
> +insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
> +insert into t2 values (1,3),(2,1);
> +select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
> +a b (select max(b) from t2 where t1.b=t2.a)
> +1 1 3
> +1 2 1
> +1 3 NULL
> +2 4 NULL
> +2 5 NULL
> +drop table t1, t2;
> +create table t1 (id int);
> +create table t2 (id int, body text, fulltext (body));
> +insert into t1 values(1),(2),(3);
> +insert into t2 values (1,'test'), (2,'mysql'), (3,'test'), (4,'test');
> +select count(distinct id) from t1 where id in (select id from t2 where match(body) against ('mysql' in boolean mode));
> +count(distinct id)
> +1
> +drop table t2,t1;
> +create table t1 (s1 int,s2 int);
> +insert into t1 values (20,15);
> +select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
> +s1 s2
> +drop table t1;
> +create table t1 (s1 int);
> +insert into t1 values (1),(null);
> +select * from t1 where s1 < all (select s1 from t1);
> +s1
> +select s1, s1 < all (select s1 from t1) from t1;
> +s1 s1 < all (select s1 from t1)
> +1 0
> +NULL NULL
> +drop table t1;
> +CREATE TABLE t1 (
> +Code char(3) NOT NULL default '',
> +Name char(52) NOT NULL default '',
> +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
> +Region char(26) NOT NULL default '',
> +SurfaceArea float(10,2) NOT NULL default '0.00',
> +IndepYear smallint(6) default NULL,
> +Population int(11) NOT NULL default '0',
> +LifeExpectancy float(3,1) default NULL,
> +GNP float(10,2) default NULL,
> +GNPOld float(10,2) default NULL,
> +LocalName char(45) NOT NULL default '',
> +GovernmentForm char(45) NOT NULL default '',
> +HeadOfState char(60) default NULL,
> +Capital int(11) default NULL,
> +Code2 char(2) NOT NULL default ''
> +) ENGINE=MyISAM;
> +INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
> +INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS');
> +INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF');
> +INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM');
> +/*!40000 ALTER TABLE t1 ENABLE KEYS */;
> +SELECT DISTINCT Continent AS c FROM t1 outr WHERE
> +Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND
> +Population < 200);
> +c
> +Oceania
> +drop table t1;
> +create table t1 (a1 int);
> +create table t2 (b1 int);
> +select * from t1 where a2 > any(select b1 from t2);
> +ERROR 42S22: Unknown column 'a2' in 'IN/ALL/ANY subquery'
> +select * from t1 where a1 > any(select b1 from t2);
> +a1
> +drop table t1,t2;
> +create table t1 (a integer, b integer);
> +select (select * from t1) = (select 1,2);
> +(select * from t1) = (select 1,2)
> +NULL
> +select (select 1,2) = (select * from t1);
> +(select 1,2) = (select * from t1)
> +NULL
> +select row(1,2) = ANY (select * from t1);
> +row(1,2) = ANY (select * from t1)
> +0
> +select row(1,2) != ALL (select * from t1);
> +row(1,2) != ALL (select * from t1)
> +1
> +drop table t1;
> +create table t1 (a integer, b integer);
> +select row(1,(2,2)) in (select * from t1 );
> +ERROR 21000: Operand should contain 2 column(s)
> +select row(1,(2,2)) = (select * from t1 );
> +ERROR 21000: Operand should contain 2 column(s)
> +select (select * from t1) = row(1,(2,2));
> +ERROR 21000: Operand should contain 1 column(s)
> +drop table t1;
> +create table t1 (a integer);
> +insert into t1 values (1);
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx );
> +xx 1 = ALL ( select 1 from t1 where 1 = xx )
> +1 1
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL;
> +ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
> +drop table t1;
> +CREATE TABLE t1 (
> +categoryId int(11) NOT NULL,
> +courseId int(11) NOT NULL,
> +startDate datetime NOT NULL,
> +endDate datetime NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL,
> +attributes text NOT NULL
> +);
> +INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
> +(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(2,52,'2004-03-15','2004-10-01','2004-03-15','2004-09-17',''),
> +(2,53,'2004-03-16','2004-10-01','2004-03-16','2004-09-17',''),
> +(2,88,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
> +(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
> +(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
> +CREATE TABLE t2 (
> +userId int(11) NOT NULL,
> +courseId int(11) NOT NULL,
> +date datetime NOT NULL
> +);
> +INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
> +(5141,72,'2003-11-25'),(5141,41,'2004-08-06'),
> +(5141,52,'2004-08-06'),(5141,53,'2004-08-06'),
> +(5141,12,'2004-08-06'),(5141,86,'2004-10-21'),
> +(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
> +(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
> +CREATE TABLE t3 (
> +groupId int(11) NOT NULL,
> +parentId int(11) NOT NULL,
> +startDate datetime NOT NULL,
> +endDate datetime NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL,
> +ordering int(11)
> +);
> +INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
> +CREATE TABLE t4 (
> +id int(11) NOT NULL,
> +groupTypeId int(11) NOT NULL,
> +groupKey varchar(50) NOT NULL,
> +name text,
> +ordering int(11),
> +description text,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL
> +);
> +INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
> +(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
> +CREATE TABLE t5 (
> +userId int(11) NOT NULL,
> +groupId int(11) NOT NULL,
> +createDate datetime NOT NULL,
> +modifyDate timestamp NOT NULL
> +);
> +INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
> +select
> +count(distinct t2.userid) pass,
> +groupstuff.*,
> +count(t2.courseid) crse,
> +t1.categoryid,
> +t2.courseid,
> +date_format(date, '%b%y') as colhead
> +from t2
> +join t1 on t2.courseid=t1.courseid
> +join
> +(
> +select
> +t5.userid,
> +parentid,
> +parentgroup,
> +childid,
> +groupname,
> +grouptypeid
> +from t5
> +join
> +(
> +select t4.id as parentid,
> +t4.name as parentgroup,
> +t4.id as childid,
> +t4.name as groupname,
> +t4.grouptypeid
> +from t4
> +) as gin on t5.groupid=gin.childid
> +) as groupstuff on t2.userid = groupstuff.userid
> +group by
> +groupstuff.groupname, colhead , t2.courseid;
> +pass userid parentid parentgroup childid groupname grouptypeid crse categoryid courseid colhead
> +1 5141 12 group2 12 group2 5 1 5 12 Aug04
> +1 5141 12 group2 12 group2 5 1 1 41 Aug04
> +1 5141 12 group2 12 group2 5 1 2 52 Aug04
> +1 5141 12 group2 12 group2 5 1 2 53 Aug04
> +1 5141 12 group2 12 group2 5 1 3 51 Oct04
> +1 5141 12 group2 12 group2 5 1 1 86 Oct04
> +1 5141 12 group2 12 group2 5 1 1 87 Oct04
> +1 5141 12 group2 12 group2 5 1 2 88 Oct04
> +1 5141 12 group2 12 group2 5 1 2 89 Oct04
> +drop table t1, t2, t3, t4, t5;
> +create table t1 (a int);
> +insert into t1 values (1), (2), (3);
> +SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
> +1
> +1
> +1
> +1
> +drop table t1;
> +create table t1 (a int);
> +create table t2 (a int);
> +insert into t1 values (1),(2);
> +insert into t2 values (0),(1),(2),(3);
> +select a from t2 where a in (select a from t1);
> +a
> +1
> +2
> +select a from t2 having a in (select a from t1);
> +a
> +1
> +2
> +prepare stmt1 from "select a from t2 where a in (select a from t1)";
> +execute stmt1;
> +a
> +1
> +2
> +execute stmt1;
> +a
> +1
> +2
> +deallocate prepare stmt1;
> +prepare stmt1 from "select a from t2 having a in (select a from t1)";
> +execute stmt1;
> +a
> +1
> +2
> +execute stmt1;
> +a
> +1
> +2
> +deallocate prepare stmt1;
> +drop table t1, t2;
> +create table t1 (a int, b int);
> +insert into t1 values (1,2);
> +select 1 = (select * from t1);
> +ERROR 21000: Operand should contain 1 column(s)
> +select (select * from t1) = 1;
> +ERROR 21000: Operand should contain 2 column(s)
> +select (1,2) = (select a from t1);
> +ERROR 21000: Operand should contain 2 column(s)
> +select (select a from t1) = (1,2);
> +ERROR 21000: Operand should contain 1 column(s)
> +select (1,2,3) = (select * from t1);
> +ERROR 21000: Operand should contain 3 column(s)
> +select (select * from t1) = (1,2,3);
> +ERROR 21000: Operand should contain 2 column(s)
> +drop table t1;
> +CREATE TABLE `t1` (
> +`itemid` bigint(20) unsigned NOT NULL auto_increment,
> +`sessionid` bigint(20) unsigned default NULL,
> +`time` int(10) unsigned NOT NULL default '0',
> +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
> +NULL default '',
> +`data` text collate latin1_general_ci NOT NULL,
> +PRIMARY KEY (`itemid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
> +CREATE TABLE `t2` (
> +`sessionid` bigint(20) unsigned NOT NULL auto_increment,
> +`pid` int(10) unsigned NOT NULL default '0',
> +`date` int(10) unsigned NOT NULL default '0',
> +`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
> +PRIMARY KEY (`sessionid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
> +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
> +ip count( e.itemid )
> +10.10.10.1 1
> +drop tables t1,t2;
> +create table t1 (fld enum('0','1'));
> +insert into t1 values ('1');
> +select * from (select max(fld) from t1) as foo;
> +max(fld)
> +1
> +drop table t1;
> +CREATE TABLE t1 (one int, two int, flag char(1));
> +CREATE TABLE t2 (one int, two int, flag char(1));
> +INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
> +INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
> +SELECT * FROM t1
> +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N');
> +one two flag
> +5 6 N
> +7 8 N
> +SELECT * FROM t1
> +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
> +one two flag
> +5 6 N
> +7 8 N
> +insert into t2 values (null,null,'N');
> +insert into t2 values (null,3,'0');
> +insert into t2 values (null,5,'0');
> +insert into t2 values (10,null,'0');
> +insert into t1 values (10,3,'0');
> +insert into t1 values (10,5,'0');
> +insert into t1 values (10,10,'0');
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
> +one two test
> +1 2 NULL
> +2 3 NULL
> +3 4 NULL
> +5 6 1
> +7 8 1
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> +one two
> +5 6
> +7 8
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
> +one two test
> +1 2 NULL
> +2 3 NULL
> +3 4 NULL
> +5 6 1
> +7 8 1
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
> +one two test
> +1 2 0
> +2 3 NULL
> +3 4 0
> +5 6 0
> +7 8 0
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> +one two test
> +1 2 0
> +2 3 NULL
> +3 4 0
> +5 6 0
> +7 8 0
> +10 3 NULL
> +10 5 NULL
> +10 10 NULL
> +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; FirstMatch(t1)
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`two` = `test`.`t1`.`two`) and (`test`.`t2`.`one` = `test`.`t1`.`one`) and (`test`.`t2`.`flag` = 'N'))
> +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> +Warnings:
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a char(5), b char(5));
> +INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
> +SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
> +a b
> +aaa aaa
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int);
> +CREATE TABLE t2 (a int, b int);
> +CREATE TABLE t3 (b int NOT NULL);
> +INSERT INTO t1 VALUES (1), (2), (3), (4);
> +INSERT INTO t2 VALUES (1,10), (3,30);
> +SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b
> +WHERE t3.b IS NOT NULL OR t2.a > 10;
> +a b b
> +SELECT * FROM t1
> +WHERE t1.a NOT IN (SELECT a FROM t2 LEFT JOIN t3 ON t2.b=t3.b
> +WHERE t3.b IS NOT NULL OR t2.a > 10);
> +a
> +1
> +2
> +3
> +4
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (f1 INT);
> +CREATE TABLE t2 (f2 INT);
> +INSERT INTO t1 VALUES (1);
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
> +f1
> +1
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
> +f1
> +1
> +INSERT INTO t2 VALUES (1);
> +INSERT INTO t2 VALUES (2);
> +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
> +f1
> +1
> +DROP TABLE t1, t2;
> +select 1 from dual where 1 < any (select 2);
> +1
> +1
> +select 1 from dual where 1 < all (select 2);
> +1
> +1
> +select 1 from dual where 2 > any (select 1);
> +1
> +1
> +select 1 from dual where 2 > all (select 1);
> +1
> +1
> +select 1 from dual where 1 < any (select 2 from dual);
> +1
> +1
> +select 1 from dual where 1 < all (select 2 from dual where 1!=1);
> +1
> +1
> +create table t1 (s1 char);
> +insert into t1 values (1),(2);
> +select * from t1 where (s1 < any (select s1 from t1));
> +s1
> +1
> +select * from t1 where not (s1 < any (select s1 from t1));
> +s1
> +2
> +select * from t1 where (s1 < ALL (select s1+1 from t1));
> +s1
> +1
> +select * from t1 where not(s1 < ALL (select s1+1 from t1));
> +s1
> +2
> +select * from t1 where (s1+1 = ANY (select s1 from t1));
> +s1
> +1
> +select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
> +s1
> +2
> +select * from t1 where (s1 = ALL (select s1/s1 from t1));
> +s1
> +1
> +select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
> +s1
> +2
> +drop table t1;
> +create table t1 (
> +retailerID varchar(8) NOT NULL,
> +statusID int(10) unsigned NOT NULL,
> +changed datetime NOT NULL,
> +UNIQUE KEY retailerID (retailerID, statusID, changed)
> +);
> +INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
> +INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
> +INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56");
> +INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53");
> +INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50");
> +INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50");
> +select * from t1 r1
> +where (r1.retailerID,(r1.changed)) in
> +(SELECT r2.retailerId,(max(changed)) from t1 r2
> +group by r2.retailerId);
> +retailerID statusID changed
> +0026 2 2006-01-06 12:25:53
> +0037 2 2006-01-06 12:25:53
> +0048 1 2006-01-06 12:37:50
> +0059 1 2006-01-06 12:37:50
> +drop table t1;
> +create table t1(a int, primary key (a));
> +insert into t1 values (10);
> +create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
> +insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
> +explain 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'
> + 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
> +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
> +1 PRIMARY r const PRIMARY PRIMARY 4 const 1
> +2 DEPENDENT 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
> +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;
> +a a b
> +10 3 35989
> +explain 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'
> + 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
> +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
> +1 PRIMARY r const PRIMARY PRIMARY 4 const 1
> +2 DEPENDENT 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
> +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;
> +a a b
> +10 1 359
> +drop table t1,t2;
> +CREATE TABLE t1 (
> +field1 int NOT NULL,
> +field2 int NOT NULL,
> +field3 int NOT NULL,
> +PRIMARY KEY (field1,field2,field3)
> +);
> +CREATE TABLE t2 (
> +fieldA int NOT NULL,
> +fieldB int NOT NULL,
> +PRIMARY KEY (fieldA,fieldB)
> +);
> +INSERT INTO t1 VALUES
> +(1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1);
> +INSERT INTO t2 VALUES (1,1), (1,2), (1,3);
> +SELECT field1, field2, COUNT(*)
> +FROM t1 GROUP BY field1, field2;
> +field1 field2 COUNT(*)
> +1 1 2
> +1 2 3
> +1 3 1
> +SELECT field1, field2
> +FROM t1
> +GROUP BY field1, field2
> +HAVING COUNT(*) >= ALL (SELECT fieldB
> +FROM t2 WHERE fieldA = field1);
> +field1 field2
> +1 2
> +SELECT field1, field2
> +FROM t1
> +GROUP BY field1, field2
> +HAVING COUNT(*) < ANY (SELECT fieldB
> +FROM t2 WHERE fieldA = field1);
> +field1 field2
> +1 1
> +1 3
> +DROP TABLE t1, t2;
> +CREATE TABLE t1(a int, INDEX (a));
> +INSERT INTO t1 VALUES (1), (3), (5), (7);
> +INSERT INTO t1 VALUES (NULL);
> +CREATE TABLE t2(a int);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 ALL NULL NULL NULL NULL 3
> +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key
> +SELECT a, a IN (SELECT a FROM t1) FROM t2;
> +a a IN (SELECT a FROM t1)
> +1 1
> +2 NULL
> +3 1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a DATETIME);
> +INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
> +CREATE TABLE t2 AS SELECT
> +(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a
> +FROM t1 WHERE a > '2000-01-01';
> +SHOW CREATE TABLE t2;
> +Table Create Table
> +t2 CREATE TABLE `t2` (
> + `sub_a` datetime DEFAULT NULL
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01');
> +SHOW CREATE TABLE t3;
> +Table Create Table
> +t3 CREATE TABLE `t3` (
> + `a` datetime DEFAULT NULL
> +) ENGINE=MyISAM DEFAULT CHARSET=latin1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (1), (2);
> +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0;
> +a
> +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL;
> +a
> +1
> +2
> +EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL;
> +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 Impossible WHERE
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (2), (4), (1), (3);
> +CREATE TABLE t2 (b int, c int);
> +INSERT INTO t2 VALUES
> +(2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 );
> +a
> +2
> +4
> +1
> +3
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a;
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2);
> +b MAX(c)
> +1 4
> +2 2
> +4 4
> +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 2),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 1),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
> +a
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
> +a
> +1
> +2
> +3
> +4
> +SELECT a FROM t1
> +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
> +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
> +ERROR 21000: Subquery returns more than 1 row
> +DROP TABLE t1,t2;
> +create table t1 (df decimal(5,1));
> +insert into t1 values(1.1);
> +insert into t1 values(2.2);
> +select * from t1 where df <= all (select avg(df) from t1 group by df);
> +df
> +1.1
> +select * from t1 where df >= all (select avg(df) from t1 group by df);
> +df
> +2.2
> +drop table t1;
> +create table t1 (df decimal(5,1));
> +insert into t1 values(1.1);
> +select 1.1 * exists(select * from t1);
> +1.1 * exists(select * from t1)
> +1.1
> +drop table t1;
> +CREATE TABLE t1 (
> +grp int(11) default NULL,
> +a decimal(10,2) default NULL);
> +insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
> +select * from t1;
> +grp a
> +1 1.00
> +2 2.00
> +2 3.00
> +3 4.00
> +3 5.00
> +3 6.00
> +NULL NULL
> +select min(a) from t1 group by grp;
> +min(a)
> +NULL
> +1.00
> +2.00
> +4.00
> +drop table t1;
> +CREATE table t1 ( c1 integer );
> +INSERT INTO t1 VALUES ( 1 );
> +INSERT INTO t1 VALUES ( 2 );
> +INSERT INTO t1 VALUES ( 3 );
> +CREATE TABLE t2 ( c2 integer );
> +INSERT INTO t2 VALUES ( 1 );
> +INSERT INTO t2 VALUES ( 4 );
> +INSERT INTO t2 VALUES ( 5 );
> +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1);
> +c1 c2
> +1 1
> +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2
> +WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) );
> +c1 c2
> +1 1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 ( c1 integer );
> +INSERT INTO t1 VALUES ( 1 );
> +INSERT INTO t1 VALUES ( 2 );
> +INSERT INTO t1 VALUES ( 3 );
> +INSERT INTO t1 VALUES ( 6 );
> +CREATE TABLE t2 ( c2 integer );
> +INSERT INTO t2 VALUES ( 1 );
> +INSERT INTO t2 VALUES ( 4 );
> +INSERT INTO t2 VALUES ( 5 );
> +INSERT INTO t2 VALUES ( 6 );
> +CREATE TABLE t3 ( c3 integer );
> +INSERT INTO t3 VALUES ( 7 );
> +INSERT INTO t3 VALUES ( 8 );
> +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2
> +WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL );
> +c1 c2
> +2 NULL
> +3 NULL
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE `t1` (
> +`itemid` bigint(20) unsigned NOT NULL auto_increment,
> +`sessionid` bigint(20) unsigned default NULL,
> +`time` int(10) unsigned NOT NULL default '0',
> +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
> +NULL default '',
> +`data` text collate latin1_general_ci NOT NULL,
> +PRIMARY KEY (`itemid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
> +CREATE TABLE `t2` (
> +`sessionid` bigint(20) unsigned NOT NULL auto_increment,
> +`pid` int(10) unsigned NOT NULL default '0',
> +`date` int(10) unsigned NOT NULL default '0',
> +`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
> +PRIMARY KEY (`sessionid`)
> +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
> +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
> +ip count( e.itemid )
> +10.10.10.1 1
> +drop tables t1,t2;
> +CREATE TABLE t1 (EMPNUM CHAR(3));
> +CREATE TABLE t2 (EMPNUM CHAR(3) );
> +INSERT INTO t1 VALUES ('E1'),('E2');
> +INSERT INTO t2 VALUES ('E1');
> +DELETE FROM t1
> +WHERE t1.EMPNUM NOT IN
> +(SELECT t2.EMPNUM
> +FROM t2
> +WHERE t1.EMPNUM = t2.EMPNUM);
> +select * from t1;
> +EMPNUM
> +E1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(select_id BIGINT, values_id BIGINT);
> +INSERT INTO t1 VALUES (1, 1);
> +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT,
> +PRIMARY KEY(select_id,values_id));
> +INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id IN (1, 0));
> +values_id
> +1
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id BETWEEN 0 AND 1);
> +values_id
> +1
> +SELECT values_id FROM t1
> +WHERE values_id IN (SELECT values_id FROM t2
> +WHERE select_id = 0 OR select_id = 1);
> +values_id
> +1
> +DROP TABLE t1, t2;
> +create table t1 (fld enum('0','1'));
> +insert into t1 values ('1');
> +select * from (select max(fld) from t1) as foo;
> +max(fld)
> +1
> +drop table t1;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (c int, d int);
> +CREATE TABLE t3 (e int);
> +INSERT INTO t1 VALUES
> +(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
> +INSERT INTO t2 VALUES
> +(2,10), (2,20), (4,10), (5,10), (3,20), (2,40);
> +INSERT INTO t3 VALUES (10), (30), (10), (20) ;
> +SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a;
> +a MAX(b) MIN(b)
> +1 20 10
> +2 30 10
> +3 20 20
> +4 40 40
> +SELECT * FROM t2;
> +c d
> +2 10
> +2 20
> +4 10
> +5 10
> +3 20
> +2 40
> +SELECT * FROM t3;
> +e
> +10
> +30
> +10
> +20
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20);
> +a
> +2
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d);
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d);
> +a
> +2
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE d >= SOME(SELECT e FROM t3 WHERE MAX(b)=e));
> +a
> +2
> +3
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
> +a
> +2
> +3
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE d > SOME(SELECT e FROM t3 WHERE MAX(b)=e));
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d));
> +a
> +2
> +SELECT a FROM t1 GROUP BY a
> +HAVING a IN (SELECT c FROM t2
> +WHERE MIN(b) < d AND
> +EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
> +a
> +2
> +SELECT a, SUM(a) FROM t1 GROUP BY a;
> +a SUM(a)
> +1 2
> +2 6
> +3 3
> +4 4
> +SELECT a FROM t1
> +WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a;
> +a
> +3
> +4
> +SELECT a FROM t1 GROUP BY a
> +HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c);
> +a
> +1
> +3
> +4
> +SELECT a FROM t1
> +WHERE a < 3 AND
> +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1
> +WHERE a < 3 AND
> +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c);
> +a
> +1
> +2
> +1
> +2
> +2
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
> +HAVING SUM(t1.a+t2.c) < t3.e/4));
> +a
> +1
> +2
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a > ALL(SELECT t2.c FROM t2
> +WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
> +HAVING SUM(t1.a+t2.c) < t3.e/4));
> +a
> +4
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a > ALL(SELECT t2.c FROM t2
> +WHERE EXISTS(SELECT t3.e FROM t3
> +WHERE SUM(t1.a+t2.c) < t3.e/4));
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20;
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING AVG(t2.c+SUM(t1.b)) > 20);
> +a
> +2
> +3
> +4
> +SELECT t1.a FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING AVG(SUM(t1.b)) > 20);
> +a
> +2
> +4
> +SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a
> +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
> +HAVING t2.c+sum > 20);
> +a sum
> +2 60
> +3 20
> +4 40
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a varchar(5), b varchar(10));
> +INSERT INTO t1 VALUES
> +('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
> +('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +a b
> +BBB 4
> +CCC 7
> +AAA 8
> +EXPLAIN
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 9 Using temporary
> +ALTER TABLE t1 ADD INDEX(a);
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +a b
> +BBB 4
> +CCC 7
> +AAA 8
> +EXPLAIN
> +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
> +2 DEPENDENT SUBQUERY t1 index NULL a 8 NULL 1
> +DROP TABLE t1;
> +create table t1( f1 int,f2 int);
> +insert into t1 values (1,1),(2,2);
> +select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1';
> +t
> +crash1
> +crash1
> +drop table t1;
> +create table t1 (c int, key(c));
> +insert into t1 values (1142477582), (1142455969);
> +create table t2 (a int, b int);
> +insert into t2 values (2, 1), (1, 0);
> +delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
> +drop table t1, t2;
> +CREATE TABLE t1 (a INT);
> +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'where clause'
> +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'where clause'
> +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1);
> +ERROR 42S22: Unknown column 'no_such_column' in 'IN/ALL/ANY subquery'
> +DROP TABLE t1;
> +create table t1 (i int, j bigint);
> +insert into t1 values (1, 2), (2, 2), (3, 2);
> +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
> +min(i)
> +1
> +drop table t1;
> +CREATE TABLE t1 (i BIGINT UNSIGNED);
> +INSERT INTO t1 VALUES (10000000000000000000);
> +INSERT INTO t1 VALUES (1);
> +CREATE TABLE t2 (i BIGINT UNSIGNED);
> +INSERT INTO t2 VALUES (10000000000000000000);
> +INSERT INTO t2 VALUES (1);
> +/* simple test */
> +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i;
> +i
> +10000000000000000000
> +1
> +/* subquery test */
> +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
> +i
> +10000000000000000000
> +/* subquery test with cast*/
> +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
> +i
> +10000000000000000000
> +DROP TABLE t1;
> +DROP TABLE t2;
> +CREATE TABLE t1 (
> +id bigint(20) unsigned NOT NULL auto_increment,
> +name varchar(255) NOT NULL,
> +PRIMARY KEY (id)
> +);
> +INSERT INTO t1 VALUES
> +(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
> +CREATE TABLE t2 (
> +id bigint(20) unsigned NOT NULL auto_increment,
> +mid bigint(20) unsigned NOT NULL,
> +date date NOT NULL,
> +PRIMARY KEY (id)
> +);
> +INSERT INTO t2 VALUES
> +(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
> +(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
> +SELECT *,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 0, 1) AS date_last,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last
> +FROM t1;
> +id name date_last date_next_to_last
> +1 Balazs 2006-05-01 NULL
> +2 Joe 2006-04-20 NULL
> +3 Frank 2006-04-13 NULL
> +SELECT *,
> +(SELECT COUNT(*) FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 1, 1) AS date_count
> +FROM t1;
> +id name date_count
> +1 Balazs NULL
> +2 Joe NULL
> +3 Frank NULL
> +SELECT *,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 0, 1) AS date_last,
> +(SELECT date FROM t2 WHERE mid = t1.id
> +ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last
> +FROM t1;
> +id name date_last date_next_to_last
> +1 Balazs 2006-05-01 2006-03-30
> +2 Joe 2006-04-20 2006-04-06
> +3 Frank 2006-04-13 NULL
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (
> +i1 int(11) NOT NULL default '0',
> +i2 int(11) NOT NULL default '0',
> +t datetime NOT NULL default '0000-00-00 00:00:00',
> +PRIMARY KEY (i1,i2,t)
> +);
> +INSERT INTO t1 VALUES
> +(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
> +(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
> +(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'),
> +(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'),
> +(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'),
> +(24,2,'2005-05-27 12:40:06');
> +CREATE TABLE t2 (
> +i1 int(11) NOT NULL default '0',
> +i2 int(11) NOT NULL default '0',
> +t datetime default NULL,
> +PRIMARY KEY (i1)
> +);
> +INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
> +EXPLAIN
> +SELECT * FROM t1,t2
> +WHERE t1.t = (SELECT t1.t FROM t1
> +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
> +ORDER BY t1.t DESC LIMIT 1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 system NULL NULL NULL NULL 1
> +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
> +SELECT * FROM t1,t2
> +WHERE t1.t = (SELECT t1.t FROM t1
> +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1
> +ORDER BY t1.t DESC LIMIT 1);
> +i1 i2 t i1 i2 t
> +24 1 2005-05-27 12:40:30 24 1 2006-06-20 12:29:40
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
> +insert into t1 (a) values (FLOOR(rand() * 100));
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +insert into t1 (a) select FLOOR(rand() * 100) from t1;
> +SELECT a,
> +(SELECT REPEAT(' ',250) FROM t1 i1
> +WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
> +FROM t1 ORDER BY a LIMIT 5;
> +a a
> +0 NULL
> +0 NULL
> +0 NULL
> +0 NULL
> +0 NULL
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT, b INT);
> +CREATE TABLE t2 (a INT);
> +INSERT INTO t2 values (1);
> +INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
> +SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
> +(SELECT COUNT(DISTINCT t1.b) from t2)
> +2
> +1
> +1
> +SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
> +FROM t1 GROUP BY t1.a;
> +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
> +2
> +1
> +1
> +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
> +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b))
> +2 2
> +1 1
> +1 1
> +SELECT COUNT(DISTINCT t1.b),
> +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
> +FROM t1 GROUP BY t1.a;
> +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
> +2 2
> +1 1
> +1 1
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a;
> +(
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +2
> +1
> +1
> +SELECT (
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a LIMIT 1)
> +FROM t1 t2
> +GROUP BY t2.a;
> +(
> +SELECT (
> +SELECT (
> +SELECT COUNT(DISTINCT t1.b)
> +)
> +)
> +FROM t1 GROUP BY t1.a LIMIT 1)
> +2
> +2
> +2
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int, PRIMARY KEY (b));
> +CREATE TABLE t2 (x int auto_increment, y int, z int,
> +PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
> +create table t3 (a int);
> +insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
> +from t3 A, t3 B, t3 C, t3 D where D.a<3;
> +insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
> +SET SESSION sort_buffer_size = 32 * 1024;
> +SELECT SQL_NO_CACHE COUNT(*)
> +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
> +FROM t1) t;
> +COUNT(*)
> +3000
> +SET SESSION sort_buffer_size = 8 * 1024 * 1024;
> +SELECT SQL_NO_CACHE COUNT(*)
> +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
> +FROM t1) t;
> +COUNT(*)
> +3000
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (id char(4) PRIMARY KEY, c int);
> +CREATE TABLE t2 (c int);
> +INSERT INTO t1 VALUES ('aa', 1);
> +INSERT INTO t2 VALUES (1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT c FROM t2 WHERE c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT c FROM t2 WHERE c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +bb 2
> +cc 3
> +dd 1
> +INSERT INTO t2 VALUES (2);
> +CREATE TABLE t3 (c int);
> +INSERT INTO t3 VALUES (1);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
> +UNION
> +SELECT c from t2 WHERE c=t1.c);
> +id c
> +aa 1
> +bb 2
> +cc 3
> +dd 1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1(f1 int);
> +CREATE TABLE t2(f2 int, f21 int, f3 timestamp);
> +INSERT INTO t1 VALUES (1),(1),(2),(2);
> +INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11"), (2,2,"2004-02-29 11:11:11");
> +SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1;
> +sq
> +2
> +4
> +SELECT (SELECT SUM(1) FROM t2 ttt GROUP BY t2.f3 LIMIT 1) AS tt FROM t2;
> +tt
> +2
> +2
> +PREPARE stmt1 FROM 'SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1';
> +EXECUTE stmt1;
> +sq
> +2
> +4
> +EXECUTE stmt1;
> +sq
> +2
> +4
> +DEALLOCATE PREPARE stmt1;
> +SELECT f2, AVG(f21),
> +(SELECT t.f3 FROM t2 AS t WHERE t2.f2=t.f2 AND t.f3=MAX(t2.f3)) AS test
> +FROM t2 GROUP BY f2;
> +f2 AVG(f21) test
> +1 1.0000 2004-02-29 11:11:11
> +2 2.0000 2004-02-29 11:11:11
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL);
> +INSERT INTO t1 VALUES
> +(1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'),
> +(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'),
> +(3,2,'k'), (3,1,'l'), (1,9,'m');
> +SELECT a, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test
> +FROM t1 GROUP BY a;
> +a MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +DROP TABLE t1;
> +DROP TABLE IF EXISTS t1;
> +DROP TABLE IF EXISTS t2;
> +DROP TABLE IF EXISTS t1xt2;
> +CREATE TABLE t1 (
> +id_1 int(5) NOT NULL,
> +t varchar(4) DEFAULT NULL
> +);
> +CREATE TABLE t2 (
> +id_2 int(5) NOT NULL,
> +t varchar(4) DEFAULT NULL
> +);
> +CREATE TABLE t1xt2 (
> +id_1 int(5) NOT NULL,
> +id_2 int(5) NOT NULL
> +);
> +INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
> +INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa');
> +INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +2
> +3
> +4
> +insert INTO t1xt2 VALUES (1, 12);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +2
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +2
> +3
> +4
> +insert INTO t1xt2 VALUES (2, 12);
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +1
> +2
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
> +id_1
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
> +id_1
> +3
> +4
> +SELECT DISTINCT t1.id_1 FROM t1 WHERE
> +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
> +id_1
> +3
> +4
> +DROP TABLE t1;
> +DROP TABLE t2;
> +DROP TABLE t1xt2;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (3), (1), (2);
> +SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
> +col1 col2
> +this is a test. 3
> +this is a test. 1
> +this is a test. 2
> +SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t;
> +col1 t2
> +this is a test. 3
> +this is a test. 1
> +this is a test. 2
> +DROP table t1;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (m int, n int);
> +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
> +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
> +SELECT COUNT(*), a,
> +(SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
> +FROM t1 GROUP BY a;
> +COUNT(*) a (SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
> +2 2 2
> +3 3 3
> +1 4 1
> +SELECT COUNT(*), a,
> +(SELECT MIN(m) FROM t2 WHERE m = count(*))
> +FROM t1 GROUP BY a;
> +COUNT(*) a (SELECT MIN(m) FROM t2 WHERE m = count(*))
> +2 2 2
> +3 3 3
> +1 4 1
> +SELECT COUNT(*), a
> +FROM t1 GROUP BY a
> +HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1;
> +COUNT(*) a
> +2 2
> +3 3
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int);
> +CREATE TABLE t2 (m int, n int);
> +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
> +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
> +SELECT COUNT(*) c, a,
> +(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
> +FROM t1 GROUP BY a;
> +c a (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
> +2 2 2
> +3 3 3
> +1 4 1,1
> +SELECT COUNT(*) c, a,
> +(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
> +FROM t1 GROUP BY a;
> +c a (SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
> +2 2 3
> +3 3 4
> +1 4 2,2
> +DROP table t1,t2;
> +CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
> +INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
> +(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
> +(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
> +SELECT a, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test
> +FROM t1 GROUP BY a;
> +a MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +SELECT a x, MAX(b),
> +(SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test
> +FROM t1 GROUP BY a;
> +x MAX(b) test
> +1 9 m
> +2 3 h
> +3 4 i
> +SELECT a, AVG(b),
> +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=AVG(t1.b)) AS test
> +FROM t1 WHERE t1.d=0 GROUP BY a;
> +a AVG(b) test
> +1 4.0000 d
> +2 2.0000 g
> +3 2.5000 NULL
> +SELECT tt.a,
> +(SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test
> +FROM t1 as tt;
> +a test
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +1 n
> +2 o
> +2 o
> +2 o
> +2 o
> +3 p
> +3 p
> +3 p
> +3 p
> +3 p
> +SELECT tt.a,
> +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1)
> +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test
> +FROM t1 as tt GROUP BY tt.a;
> +a test
> +1 n
> +2 o
> +3 p
> +SELECT tt.a, MAX(
> +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
> +LIMIT 1)
> +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test
> +FROM t1 as tt GROUP BY tt.a;
> +a test
> +1 n
> +2 o
> +3 p
> +DROP TABLE t1;
> +CREATE TABLE t1 (a int, b int);
> +INSERT INTO t1 VALUES (2,22),(1,11),(2,22);
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +a
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +a
> +1
> +2
> +SET @@sql_mode='ansi';
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SET @@sql_mode=default;
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT);
> +INSERT INTO t1 values (1),(1),(1),(1);
> +CREATE TABLE t2 (x INT);
> +INSERT INTO t1 values (1000),(1001),(1002);
> +SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT SUM( (SELECT SUM(COUNT(a)) FROM t2) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT COUNT(1) FROM DUAL;
> +COUNT(1)
> +1
> +SELECT SUM( (SELECT AVG( (SELECT t1.a FROM t2) ) FROM DUAL) ) FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT
> +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) )
> +FROM t1;
> +ERROR HY000: Invalid use of group function
> +SELECT t1.a as XXA,
> +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) )
> +FROM t1;
> +ERROR HY000: Invalid use of group function
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int, b int, KEY (a));
> +INSERT INTO t1 VALUES (1,1),(2,1);
> +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
> +1 PRIMARY t1 ref a a 5 const 0 Using where; Using index
> +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
> +DROP TABLE t1;
> +CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id));
> +INSERT INTO t1 VALUES
> +(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
> +CREATE TABLE t2 (id int NOT NULL, INDEX idx(id));
> +INSERT INTO t2 VALUES (7), (5), (1), (3);
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
> +id st
> +3 FL
> +1 GA
> +7 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
> +GROUP BY id;
> +id st
> +1 GA
> +3 FL
> +7 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
> +id st
> +2 GA
> +4 FL
> +SELECT id, st FROM t1
> +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
> +GROUP BY id;
> +id st
> +2 GA
> +4 FL
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a int);
> +INSERT INTO t1 VALUES (1), (2);
> +EXPLAIN EXTENDED
> +SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
> +2 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
> +Warnings:
> +Note 1003 select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
> +DROP TABLE t1;
> +CREATE TABLE t1 (
> +a varchar(255) default NULL,
> +b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
> +INDEX idx(a,b)
> +);
> +CREATE TABLE t2 (
> +a varchar(255) default NULL
> +);
> +INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO t1 SELECT * FROM t1;
> +INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
> +INSERT INTO `t2` VALUES ('abcdefghijk');
> +INSERT INTO `t2` VALUES ('asdf');
> +SET session sort_buffer_size=8192;
> +SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
> +d1
> +1
> +1
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INTEGER, b INTEGER);
> +CREATE TABLE t2 (x INTEGER);
> +INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
> +INSERT INTO t2 VALUES (1), (2);
> +SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
> +(SELECT SUM(t1.a)/AVG(t2.x) FROM t2)
> +3.3333
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INT, b INT);
> +INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
> +SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
> +AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
> +GROUP BY a1.a;
> +a COUNT(*)
> +1 3
> +DROP TABLE t1;
> +CREATE TABLE t1 (a INT);
> +CREATE TABLE t2 (a INT);
> +INSERT INTO t1 VALUES (1),(2);
> +INSERT INTO t2 VALUES (1),(2);
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
> +(SELECT SUM(t1.a) FROM t2 WHERE a=0)
> +NULL
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1;
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1;
> +(SELECT SUM(t1.a) FROM t2 WHERE a=1)
> +3
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a1 INT, a2 INT);
> +CREATE TABLE t2 (b1 INT, b2 INT);
> +INSERT INTO t1 VALUES (100, 200);
> +INSERT INTO t1 VALUES (101, 201);
> +INSERT INTO t2 VALUES (101, 201);
> +INSERT INTO t2 VALUES (103, 203);
> +SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
> +((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL
> +0
> +0
> +DROP TABLE t1, t2;
> +CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
> +INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
> +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
> +s1 s2
> +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
> +s1 s2
> +CREATE INDEX I1 ON t1 (s1);
> +CREATE INDEX I2 ON t1 (s2);
> +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
> +s1 s2
> +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
> +s1 s2
> +TRUNCATE t1;
> +INSERT INTO t1 VALUES (0x41,0x41);
> +SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
> +s1 s2
> +DROP TABLE t1;
> +CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
> +CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
> +CREATE TABLE t3 (a3 BINARY(2) default '0');
> +INSERT INTO t1 VALUES (1),(2),(3),(4);
> +INSERT INTO t2 VALUES (1),(2),(3);
> +INSERT INTO t3 VALUES (1),(2),(3);
> +SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
> +LEFT(t2.a2, 1)
> +1
> +2
> +3
> +SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
> +a1 t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
> +1 0
> +2 0
> +3 0
> +4 0
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
> +CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
> +CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
> +INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
> +INSERT INTO t2 VALUES (2), (3), (4), (5);
> +INSERT INTO t3 VALUES (10), (20), (30);
> +SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
> +LEFT(t1.a1,1)
> +1
> +2
> +3
> +SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
> +a2
> +DROP TABLE t1, t2, t3;
> +CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
> +INSERT INTO t1 VALUES ('a', 'aa');
> +INSERT INTO t1 VALUES ('a', 'aaa');
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +a b
> +CREATE INDEX I1 ON t1 (a);
> +CREATE INDEX I2 ON t1 (b);
> +EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
> +a b
> +CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
> +INSERT INTO t2 SELECT * FROM t1;
> +CREATE INDEX I1 ON t2 (a);
> +CREATE INDEX I2 ON t2 (b);
> +EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
> +SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
> +a b
> +EXPLAIN
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
> +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
> +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
> +a b
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(a INT, b INT);
> +INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
> +EXPLAIN
> +SELECT a AS out_a, MIN(b) FROM t1
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
> +GROUP BY a;
> +ERROR 42S22: Unknown column 'out_a' in 'where clause'
> +SELECT a AS out_a, MIN(b) FROM t1
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
> +GROUP BY a;
> +ERROR 42S22: Unknown column 'out_a' in 'where clause'
> +EXPLAIN
> +SELECT a AS out_a, MIN(b) FROM t1 t1_outer
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
> +GROUP BY a;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1_outer ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 Using where
> +SELECT a AS out_a, MIN(b) FROM t1 t1_outer
> +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
> +GROUP BY a;
> +out_a MIN(b)
> +1 2
> +2 4
> +DROP TABLE t1;
> +create table t0(a int);
> +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> +create table t1(f11 int, f12 int);
> +create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
> +insert into t1 values(1,1),(2,2), (3, 3);
> +insert into t2
> +select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a
> +from t0 A, t0 B, t0 C, t0 D;
> +set session sort_buffer_size= 33*1024;
> +select count(*) from t1 where f12 =
> +(select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
> +count(*)
> +3
> +drop table t0,t1,t2;
> +CREATE TABLE t4 (
> +f7 varchar(32) collate utf8_bin NOT NULL default '',
> +f10 varchar(32) collate utf8_bin default NULL,
> +PRIMARY KEY (f7)
> +);
> +INSERT INTO t4 VALUES(1,1), (2,null);
> +CREATE TABLE t2 (
> +f4 varchar(32) collate utf8_bin NOT NULL default '',
> +f2 varchar(50) collate utf8_bin default NULL,
> +f3 varchar(10) collate utf8_bin default NULL,
> +PRIMARY KEY (f4),
> +UNIQUE KEY uk1 (f2)
> +);
> +INSERT INTO t2 VALUES(1,1,null), (2,2,null);
> +CREATE TABLE t1 (
> +f8 varchar(32) collate utf8_bin NOT NULL default '',
> +f1 varchar(10) collate utf8_bin default NULL,
> +f9 varchar(32) collate utf8_bin default NULL,
> +PRIMARY KEY (f8)
> +);
> +INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
> +CREATE TABLE t3 (
> +f6 varchar(32) collate utf8_bin NOT NULL default '',
> +f5 varchar(50) collate utf8_bin default NULL,
> +PRIMARY KEY (f6)
> +);
> +INSERT INTO t3 VALUES (1,null), (2,null);
> +SELECT
> +IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4,
> +IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3,
> +SUM(
> +IF(
> +(SELECT VPC.f2
> +FROM t2 VPC, t4 a2, t2 a3
> +WHERE
> +VPC.f4 = a2.f10 AND a3.f2 = a4
> +LIMIT 1) IS NULL,
> +0,
> +t3.f5
> +)
> +) AS a6
> +FROM
> +t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4
> +GROUP BY a4;
> +a4 f3 a6
> +1 NULL NULL
> +2 NULL NULL
> +DROP TABLE t1, t2, t3, t4;
> +create table t1 (a float(5,4) zerofill);
> +create table t2 (a float(5,4),b float(2,0));
> +select t1.a from t1 where
> +t1.a= (select b from t2 limit 1) and not
> +t1.a= (select a from t2 limit 1) ;
> +a
> +drop table t1, t2;
> +CREATE TABLE t1 (a INT);
> +INSERT INTO t1 VALUES (1),(2);
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 GROUP BY a);
> +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
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
> +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
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
> +Warnings:
> +Note 1003 select 1 AS `1` from `test`.`t1` where <expr_cache><1>(<in_optimizer>(1,<exists>(select 1 from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (1 = <ref_null_helper>(1)))))
> +DROP TABLE t1;
> +#
> +# Bug#45061: Incorrectly market field caused wrong result.
> +#
> +CREATE TABLE `C` (
> +`int_nokey` int(11) NOT NULL,
> +`int_key` int(11) NOT NULL,
> +KEY `int_key` (`int_key`)
> +);
> +INSERT INTO `C` VALUES (9,9), (0,0), (8,6), (3,6), (7,6), (0,4),
> +(1,7), (9,4), (0,8), (9,4), (0,7), (5,5), (0,0), (8,5), (8,7),
> +(5,2), (1,8), (7,0), (0,9), (9,5);
> +SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`);
> +int_nokey int_key
> +9 9
> +0 0
> +5 5
> +0 0
> +EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`);
> +id select_type table type possible_keys key key_len ref rows filtered Extra
> +1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where
> +DROP TABLE C;
> +# End of test for bug#45061.
> +#
> +# Bug #46749: Segfault in add_key_fields() with outer subquery level
> +# field references
> +#
> +CREATE TABLE t1 (
> +a int,
> +b int,
> +UNIQUE (a), KEY (b)
> +);
> +INSERT INTO t1 VALUES (1,1), (2,1);
> +CREATE TABLE st1 like t1;
> +INSERT INTO st1 VALUES (1,1), (2,1);
> +CREATE TABLE st2 like t1;
> +INSERT INTO st2 VALUES (1,1), (2,1);
> +EXPLAIN
> +SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
> +FROM t1
> +WHERE a = 230;
> +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
> +2 DEPENDENT 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)
> +FROM t1
> +WHERE a = 230;
> +MAX(b) (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
> +NULL 0
> +DROP TABLE t1, st1, st2;
> +#
> +# Bug #48709: Assertion failed in sql_select.cc:11782:
> +# int join_read_key(JOIN_TAB*)
> +#
> +CREATE TABLE t1 (pk int PRIMARY KEY, int_key int);
> +INSERT INTO t1 VALUES (10,1), (14,1);
> +CREATE TABLE t2 (pk int PRIMARY KEY, int_key int);
> +INSERT INTO t2 VALUES (3,3), (5,NULL), (7,3);
> +# should have eq_ref for t1
> +EXPLAIN
> +SELECT * FROM t2 outr
> +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
> +ORDER BY outr.pk;
> +id select_type table type possible_keys key key_len ref rows Extra
> +x x outr ALL x x x x x x
> +x x t1 eq_ref x x x x x x
> +x x t2 index x x x x x x
> +# should not crash on debug binaries
> +SELECT * FROM t2 outr
> +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
> +ORDER BY outr.pk;
> +pk int_key
> +3 3
> +7 3
> +DROP TABLE t1,t2;
> +End of 5.0 tests.
> +create table t_out (subcase char(3),
> +a1 char(2), b1 char(2), c1 char(2));
> +create table t_in (a2 char(2), b2 char(2), c2 char(2));
> +insert into t_out values ('A.1','2a', NULL, '2a');
> +insert into t_out values ('A.3', '2a', NULL, '2a');
> +insert into t_out values ('A.4', '2a', NULL, 'xx');
> +insert into t_out values ('B.1', '2a', '2a', '2a');
> +insert into t_out values ('B.2', '2a', '2a', '2a');
> +insert into t_out values ('B.3', '3a', 'xx', '3a');
> +insert into t_out values ('B.4', 'xx', '3a', '3a');
> +insert into t_in values ('1a', '1a', '1a');
> +insert into t_in values ('2a', '2a', '2a');
> +insert into t_in values (NULL, '2a', '2a');
> +insert into t_in values ('3a', NULL, '3a');
> +
> +Test general IN semantics (not top-level)
> +
> +case A.1
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
> +from t_out where subcase = 'A.1';
> +subcase pred_in pred_not_in
> +A.1 0 1
> +case A.2 - impossible
> +case A.3
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'A.3';
> +subcase pred_in pred_not_in
> +A.3 NULL NULL
> +case A.4
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'A.4';
> +subcase pred_in pred_not_in
> +A.4 0 1
> +case B.1
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
> +from t_out where subcase = 'B.1';
> +subcase pred_in pred_not_in
> +B.1 0 1
> +case B.2
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.2';
> +subcase pred_in pred_not_in
> +B.2 1 0
> +case B.3
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.3';
> +subcase pred_in pred_not_in
> +B.3 NULL NULL
> +case B.4
> +select subcase,
> +(a1, b1, c1) IN (select * from t_in) pred_in,
> +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
> +from t_out where subcase = 'B.4';
> +subcase pred_in pred_not_in
> +B.4 0 1
> +
> +Test IN as top-level predicate, and
> +as non-top level for cases A.3, B.3 (the only cases with NULL result).
> +
> +case A.1
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.1' and
> +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.1' and
> +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.1' and
> +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
> +not_pred_in
> +T
> +case A.3
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.3' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.3' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.3' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
> +where subcase = 'A.3' and
> +((a1, b1, c1) IN (select * from t_in)) is NULL and
> +((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
> +pred_in
> +N
> +case A.4
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'A.4' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'A.4' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'A.4' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +T
> +case B.1
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.1' and
> +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.1' and
> +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.1' and
> +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
> +not_pred_in
> +T
> +case B.2
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.2' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.2' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.2' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +case B.3
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.3' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.3' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.3' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +F
> +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
> +where subcase = 'B.3' and
> +((a1, b1, c1) IN (select * from t_in)) is NULL and
> +((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
> +pred_in
> +N
> +case B.4
> +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
> +where subcase = 'B.4' and
> +(a1, b1, c1) IN (select * from t_in);
> +pred_in
> +F
> +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
> +where subcase = 'B.4' and
> +(a1, b1, c1) NOT IN (select * from t_in);
> +pred_not_in
> +T
> +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
> +where subcase = 'B.4' and
> +NOT((a1, b1, c1) IN (select * from t_in));
> +not_pred_in
> +T
> +drop table t_out;
> +drop table t_in;
> +CREATE TABLE t1 (a INT, b INT);
> +INSERT INTO t1 VALUES (2,22),(1,11),(2,22);
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +a
> +1
> +2
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +a
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +a
> +1
> +2
> +SET @@sql_mode='ansi';
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SELECT a FROM t1 t0
> +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a;
> +ERROR HY000: Invalid use of group function
> +SET @@sql_mode=default;
> +DROP TABLE t1;
> +CREATE TABLE t1 (s1 CHAR(1));
> +INSERT INTO t1 VALUES ('a');
> +SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1);
> +s1
> +a
> +DROP TABLE t1;
> +CREATE TABLE t1(c INT, KEY(c));
> +CREATE TABLE t2(a INT, b INT);
> +INSERT INTO t2 VALUES (1, 10), (2, NULL);
> +INSERT INTO t1 VALUES (1), (3);
> +SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
> +a b
> +DROP TABLE t1,t2;
> +CREATE TABLE t1(pk INT PRIMARY KEY, a INT, INDEX idx(a));
> +INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
> +CREATE TABLE t2(pk INT PRIMARY KEY, a INT, b INT, INDEX idxa(a));
> +INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
> +pk a
> +1 10
> +3 30
> +2 20
> +DROP TABLE t1,t2;
> +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), KEY b (b));
> +INSERT INTO t1 VALUES (1,NULL), (9,NULL);
> +CREATE TABLE t2 (
> +a INT,
> +b INT,
> +c INT,
> +d INT,
> +PRIMARY KEY (a),
> +UNIQUE KEY b (b,c,d),
> +KEY b_2 (b),
> +KEY c (c),
> +KEY d (d)
> +);
> +INSERT INTO t2 VALUES
> +(43, 2, 11 ,30),
> +(44, 2, 12 ,30),
> +(45, 1, 1 ,10000),
> +(46, 1, 2 ,10000),
> +(556,1, 32 ,10000);
> +CREATE TABLE t3 (
> +a INT,
> +b INT,
> +c INT,
> +PRIMARY KEY (a),
> +UNIQUE KEY b (b,c),
> +KEY c (c),
> +KEY b_2 (b)
> +);
> +INSERT INTO t3 VALUES (1,1,1), (2,32,1);
> +explain
> +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 Using index
> +1 PRIMARY t3 ref b,b_2 b 5 test.t1.a 1 Using index
> +2 DEPENDENT SUBQUERY t2 ref b,b_2,c b 10 test.t3.c,test.t1.a 1 Using where; Using index; Using filesort
> +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a;
> +a incorrect
> +1 1
> +DROP TABLE t1,t2,t3;
> +CREATE TABLE t1 (id int);
> +CREATE TABLE t2 (id int, c int);
> +INSERT INTO t1 (id) VALUES (1);
> +INSERT INTO t2 (id) VALUES (1);
> +INSERT INTO t1 (id) VALUES (1);
> +INSERT INTO t2 (id) VALUES (1);
> +CREATE VIEW v1 AS
> +SELECT t2.c AS c FROM t1, t2
> +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +UPDATE v1 SET c=1;
> +CREATE VIEW v2 (a,b) AS
> +SELECT t2.id, t2.c AS c FROM t1, t2
> +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +INSERT INTO v2(a,b) VALUES (2,2);
> +ERROR HY000: CHECK OPTION failed 'test.v2'
> +SELECT * FROM v1;
> +c
> +1
> +1
> +1
> +1
> +CREATE VIEW v3 AS
> +SELECT t2.c AS c FROM t2
> +WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
> +DELETE FROM v3;
> +DROP VIEW v1,v2,v3;
> +DROP TABLE t1,t2;
> +#
> +# BUG#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result
> +#
> +create table t1(id integer primary key, g integer, v integer, s char(1));
> +create table t2(id integer primary key, g integer, v integer, s char(1));
> +insert into t1 values
> +(10, 10, 10, 'l'),
> +(20, 20, 20, 'l'),
> +(40, 40, 40, 'l'),
> +(41, 40, null, 'l'),
> +(50, 50, 50, 'l'),
> +(51, 50, null, 'l'),
> +(60, 60, 60, 'l'),
> +(61, 60, null, 'l'),
> +(70, 70, 70, 'l'),
> +(90, 90, null, 'l');
> +insert into t2 values
> +(10, 10, 10, 'r'),
> +(30, 30, 30, 'r'),
> +(50, 50, 50, 'r'),
> +(60, 60, 60, 'r'),
> +(61, 60, null, 'r'),
> +(70, 70, 70, 'r'),
> +(71, 70, null, 'r'),
> +(80, 80, 80, 'r'),
> +(81, 80, null, 'r'),
> +(100,100,null, 'r');
> +select *
> +from t1
> +where v in(select v
> +from t2
> +where t1.g=t2.g) is unknown;
> +id g v s
> +51 50 NULL l
> +61 60 NULL l
> +drop table t1, t2;
> +#
> +# Bug#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result
> +#
> +create table t1(id integer primary key, g integer, v integer, s char(1));
> +create table t2(id integer primary key, g integer, v integer, s char(1));
> +insert into t1 values
> +(10, 10, 10, 'l'),
> +(20, 20, 20, 'l'),
> +(40, 40, 40, 'l'),
> +(41, 40, null, 'l'),
> +(50, 50, 50, 'l'),
> +(51, 50, null, 'l'),
> +(60, 60, 60, 'l'),
> +(61, 60, null, 'l'),
> +(70, 70, 70, 'l'),
> +(90, 90, null, 'l');
> +insert into t2 values
> +(10, 10, 10, 'r'),
> +(30, 30, 30, 'r'),
> +(50, 50, 50, 'r'),
> +(60, 60, 60, 'r'),
> +(61, 60, null, 'r'),
> +(70, 70, 70, 'r'),
> +(71, 70, null, 'r'),
> +(80, 80, 80, 'r'),
> +(81, 80, null, 'r'),
> +(100,100,null, 'r');
> +select *
> +from t1
> +where v in(select v
> +from t2
> +where t1.g=t2.g) is unknown;
> +id g v s
> +51 50 NULL l
> +61 60 NULL l
> +drop table t1, t2;
> +CREATE TABLE t1 (a ENUM('rainbow'));
> +INSERT INTO t1 VALUES (),(),(),(),();
> +SELECT 1 FROM t1 GROUP BY (SELECT 1 FROM t1 ORDER BY AVG(LAST_INSERT_ID()));
> +1
> +1
> +DROP TABLE t1;
> +CREATE TABLE t1 (a LONGBLOB);
> +INSERT INTO t1 SET a = 'aaaa';
> +INSERT INTO t1 SET a = 'aaaa';
> +SELECT 1 FROM t1 GROUP BY
> +(SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1);
> +1
> +1
> +DROP TABLE t1;
> +#
> +# Bug #49512 : subquery with aggregate function crash
> +# subselect_single_select_engine::exec()
> +CREATE TABLE t1(a INT);
> +INSERT INTO t1 VALUES();
> +# should not crash
> +SELECT 1 FROM t1 WHERE a <> SOME
> +(
> +SELECT MAX((SELECT a FROM t1 LIMIT 1)) AS d
> +FROM t1,t1 a
> +);
> +1
> +DROP TABLE t1;
> +#
> +# Bug #45989 take 2 : memory leak after explain encounters an
> +# error in the query
> +#
> +CREATE TABLE t1(a LONGTEXT);
> +INSERT INTO t1 VALUES (repeat('a',@@global.max_allowed_packet));
> +INSERT INTO t1 VALUES (repeat('b',@@global.max_allowed_packet));
> +EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
> +(SELECT DISTINCTROW a AS away FROM t1 GROUP BY a WITH ROLLUP) AS d1
> +WHERE t1.a = d1.a;
> +ERROR 42S22: Unknown column 'd1.a' in 'where clause'
> +DROP TABLE t1;
> +End of 5.1 tests.
> +Set up test tables.
> +CREATE TABLE t1 (
> +t1_id INT UNSIGNED,
> +PRIMARY KEY(t1_id)
> +) Engine=MyISAM;
> +INSERT INTO t1 (t1_id) VALUES (1), (2), (3), (4), (5);
> +CREATE TABLE t2 SELECT * FROM t1;
> +CREATE TABLE t3 (
> +t3_id INT UNSIGNED AUTO_INCREMENT,
> +t1_id INT UNSIGNED,
> +amount DECIMAL(16,2),
> +PRIMARY KEY(t3_id),
> +KEY(t1_id)
> +) Engine=MyISAM;
> +INSERT INTO t3 (t1_id, t3_id, amount)
> +VALUES (1, 1, 100.00), (2, 2, 200.00), (4, 4, 400.00);
> +This is the 'inner query' running by itself.
> +Produces correct results.
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +SELECT * FROM (the same inner query)
> +Produces correct results.
> +SELECT * FROM (
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +) AS t;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +Now make t2.t1_id part of a key.
> +ALTER TABLE t2 ADD PRIMARY KEY(t1_id);
> +Same inner query by itself.
> +Still correct results.
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +SELECT * FROM (the same inner query), now with indexes on the LEFT JOIN
> +SELECT * FROM (
> +SELECT
> +t1.t1_id,
> +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount
> +FROM
> +t1
> +LEFT JOIN t2 ON t2.t1_id=t1.t1_id
> +GROUP BY
> +t1.t1_id
> +) AS t;
> +t1_id total_amount
> +1 100.00
> +2 200.00
> +3 0.00
> +4 400.00
> +5 0.00
> +DROP TABLE t3;
> +DROP TABLE t2;
> +DROP TABLE t1;
> +#
> +# Bug #52711: Segfault when doing EXPLAIN SELECT with
> +# union...order by (select... where...)
> +#
> +CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a));
> +INSERT INTO t1 VALUES (1),(2);
> +CREATE TABLE t2 (b INT);
> +INSERT INTO t2 VALUES (1),(2);
> +# Should not crash
> +EXPLAIN
> +SELECT * FROM t2 UNION SELECT * FROM t2
> +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
> +# Should not crash
> +SELECT * FROM t2 UNION SELECT * FROM t2
> +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
> +DROP TABLE t1,t2;
> +# LP BUG#675248 - select->prep_where references on freed memory
> +CREATE TABLE t1 (a int, b int);
> +insert into t1 values (1,1),(0,0);
> +CREATE TABLE t2 (c int);
> +insert into t2 values (1),(2);
> +prepare stmt1 from "select sum(a),(select sum(c) from t2 where table1.b) as sub
> +from t1 as table1 group by sub";
> +execute stmt1;
> +sum(a) sub
> +0 NULL
> +1 3
> +deallocate prepare stmt1;
> +prepare stmt1 from "select sum(a),(select sum(c) from t2 having table1.b) as sub
> +from t1 as table1";
> +execute stmt1;
> +sum(a) sub
> +1 3
> +deallocate prepare stmt1;
> +drop table t1,t2;
> +#
> +# Bug LP#693935/#58727: Assertion failure with
> +# a single row subquery returning more than one row
> +#
> +create table t1 (a char(1) charset utf8);
> +insert into t1 values ('a'), ('b');
> +create table t2 (a binary(1));
> +insert into t2 values ('x'), ('y');
> +select * from t2 where a=(select a from t1) and a='x';
> +ERROR 21000: Subquery returns more than 1 row
> +drop table t1,t2;
> +End of 5.1 tests
> +#
> +# No BUG#, a case brought from 5.2's innodb_mysql_lock.test
> +#
> +create table t1 (i int not null primary key);
> +insert into t1 values (1),(2),(3),(4),(5);
> +create table t2 (j int not null primary key);
> +insert into t2 values (1),(2),(3),(4),(5);
> +create table t3 (k int not null primary key);
> +insert into t3 values (1),(2),(3);
> +create view v2 as select t2.j as j from t2 where t2.j in (select t1.i from t1);
> +select * from t3 where k in (select j from v2);
> +k
> +1
> +2
> +3
> +drop table t1,t2,t3;
> +drop view v2;
> +#
> +# Bug#52068: Optimizer generates invalid semijoin materialization plan
> +#
> +drop table if exists ot1, ot2, it1, it2;
> +CREATE TABLE ot1(a INTEGER);
> +INSERT INTO ot1 VALUES(5), (8);
> +CREATE TABLE it2(a INTEGER);
> +INSERT INTO it2 VALUES(9), (5), (1), (8);
> +CREATE TABLE it3(a INTEGER);
> +INSERT INTO it3 VALUES(7), (1), (0), (5), (1), (4);
> +CREATE TABLE ot4(a INTEGER);
> +INSERT INTO ot4 VALUES(1), (3), (5), (7), (9), (7), (3), (1);
> +SELECT * FROM ot1,ot4
> +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
> +FROM it2,it3);
> +a a
> +5 1
> +8 1
> +5 5
> +8 5
> +5 7
> +8 7
> +5 7
> +8 7
> +5 1
> +8 1
> +explain SELECT * FROM ot1,ot4
> +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
> +FROM it2,it3);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY ot1 ALL NULL NULL NULL NULL 2 Start temporary
> +1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
> +1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
> +1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join)
> +DROP TABLE IF EXISTS ot1, ot4, it2, it3;
> +#
> +# Bug#729039: NULL keys used to evaluate subquery
> +#
> +CREATE TABLE t1 (a int) ;
> +INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
> +CREATE TABLE t2 (a int, INDEX idx(a)) ;
> +INSERT INTO t2 VALUES (NULL), (1), (NULL);
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
> +a
> +1
> +EXPLAIN
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
> +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
> +a
> +1
> +EXPLAIN
> +SELECT * FROM t1
> +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
> +2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
> +DROP TABLE t1,t2;
> +#
> +# BUG#752992: Wrong results for a subquery with 'semijoin=on'
> +#
> +CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL);
> +INSERT INTO t1 VALUES (11,0);
> +INSERT INTO t1 VALUES (12,5);
> +INSERT INTO t1 VALUES (15,0);
> +CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL);
> +INSERT INTO t2 VALUES (11,1);
> +INSERT INTO t2 VALUES (12,2);
> +INSERT INTO t2 VALUES (15,4);
> +EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3 Start temporary
> +1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; Using join buffer (flat, BNL join)
> +1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index; End temporary
> +SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
> +pk i
> +11 0
> +12 5
> +15 0
> +DROP table t1,t2;
> +#
> +# Bug#751350: crash with pushed condition for outer references when
> +# there should be none of such conditions
> +#
> +CREATE TABLE t1 (a int, b int) ;
> +INSERT INTO t1 VALUES (0,0),(0,0);
> +EXPLAIN
> +SELECT b FROM t1
> +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a )
> +GROUP BY b;
> +id select_type table type possible_keys key key_len ref rows Extra
> +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
> +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary
> +SELECT b FROM t1
> +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a )
> +GROUP BY b;
> +b
> +0
> +DROP TABLE t1;
> +#
> +# Bug #11765713 58705:
> +# OPTIMIZER LET ENGINE DEPEND ON UNINITIALIZED VALUES
> +# CREATED BY OPT_SUM_QUERY
> +#
> +CREATE TABLE t1(a INT NOT NULL, KEY (a));
> +INSERT INTO t1 VALUES (0), (1);
> +SELECT 1 as foo FROM t1 WHERE a < SOME
> +(SELECT a FROM t1 WHERE a <=>
> +(SELECT a FROM t1)
> +);
> +ERROR 21000: Subquery returns more than 1 row
> +SELECT 1 as foo FROM t1 WHERE a < SOME
> +(SELECT a FROM t1 WHERE a <=>
> +(SELECT a FROM t1 where a is null)
> +);
> +foo
> +DROP TABLE t1;
> +#
> +# BUG#779885: Crash in eliminate_item_equal with materialization=on in
> +# maria-5.3
> +#
> +CREATE TABLE t1 ( f1 int );
> +INSERT INTO t1 VALUES (19), (20);
> +CREATE TABLE t2 ( f10 varchar(32) );
> +INSERT INTO t2 VALUES ('c'),('d');
> +CREATE TABLE t3 ( f10 varchar(32) );
> +INSERT INTO t3 VALUES ('a'),('b');
> +SELECT *
> +FROM t1
> +WHERE
> +( 't' ) IN (
> +SELECT t3.f10
> +FROM t3
> +JOIN t2
> +ON t2.f10 = t3.f10
> +);
> +f1
> +DROP TABLE t1,t2,t3;
> +End of 5.3 tests
> +set optimizer_switch=@subselect_tmp;
> +set optimizer_switch=default;
> +select @@optimizer_switch like '%subquery_cache=on%';
> +@@optimizer_switch like '%subquery_cache=on%'
> +0
>
> === modified file 'mysql-test/r/subselect_sj.result'
> --- a/mysql-test/r/subselect_sj.result 2011-07-13 12:49:52 +0000
> +++ b/mysql-test/r/subselect_sj.result 2011-07-14 09:11:11 +0000
> @@ -761,11 +761,11 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
> show warnings;
> Level Code Message
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
> select a from t1
> where a in (select c from t2 where d >= some(select e from t3 where b=e));
> a
>
> === modified file 'mysql-test/r/subselect_sj_jcl6.result'
> --- a/mysql-test/r/subselect_sj_jcl6.result 2011-07-13 12:49:52 +0000
> +++ b/mysql-test/r/subselect_sj_jcl6.result 2011-07-14 09:11:11 +0000
> @@ -771,11 +771,11 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
> show warnings;
> Level Code Message
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
> select a from t1
> where a in (select c from t2 where d >= some(select e from t3 where b=e));
> a
>
> === modified file 'mysql-test/r/subselect_sj_mat.result'
> --- a/mysql-test/r/subselect_sj_mat.result 2011-07-08 14:46:47 +0000
> +++ b/mysql-test/r/subselect_sj_mat.result 2011-07-14 09:11:11 +0000
> @@ -349,7 +349,7 @@ id select_type table type possible_keys
> 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> 3 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`)))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) and (`test`.`t3`.`c2` > '0'))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) and (`test`.`t3`.`c2` > '0'))
> select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 where c2 LIKE '%02') or
> @@ -375,7 +375,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where ((`test`.`t2`.`b2` = `test`.`t1`.`a2`) and (`test`.`t2i`.`b2` = `test`.`t3c`.`c2`) and (`test`.`t2`.`b1` = `test`.`t1`.`a1`) and (`test`.`t2i`.`b1` = `test`.`t3c`.`c1`) and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) and (`test`.`t3c`.`c2` > '0'))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where ((`test`.`t2`.`b2` = `test`.`t1`.`a2`) and (`test`.`t2i`.`b2` = `test`.`t3c`.`c2`) and (`test`.`t2`.`b1` = `test`.`t1`.`a1`) and (`test`.`t2i`.`b1` = `test`.`t3c`.`c1`) and (<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) and (`test`.`t3c`.`c2` > '0'))
> select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 t3a where c1 = a1) or
> @@ -414,7 +414,7 @@ id select_type table type possible_keys
> 9 SUBQUERY t3i index it3i1,it3i2,it3i3 # # # 4 75.00 #
> NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
> Warnings:
> -Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`)))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2`) semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t1` where ((`test`.`t3`.`c2` = `<subquery2>`.`b2`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`) and (`test`.`t2i`.`b2` = `<subquery2>`.`b2`) and (`test`.`t3`.`c1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t2i`.`b1` = `<subquery2>`.`b1`) and (`<subquery2>`.`b2` > '0'))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t3i`.`c2` = `test`.`t2i`.`b2`) and (`test`.`t3i`.`c1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t2i`.`b2` > '0')))
> +Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2`) semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t1` where ((`test`.`t3`.`c2` = `<subquery2>`.`b2`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`) and (`test`.`t2i`.`b2` = `<subquery2>`.`b2`) and (`test`.`t3`.`c1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t2i`.`b1` = `<subquery2>`.`b1`) and (`<subquery2>`.`b2` > '0'))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t3i`.`c2` = `test`.`t2i`.`b2`) and (`test`.`t3i`.`c1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t2i`.`b2` > '0')))
> (select * from t1
> where (a1, a2) in (select b1, b2 from t2
> where b2 in (select c2 from t3 where c2 LIKE '%02') or
> @@ -444,7 +444,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and (`test`.`t3`.`c2` > '0'))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and (`test`.`t3`.`c2` > '0'))
> select * from t1
> where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
> (a1, a2) in (select c1, c2 from t3
> @@ -468,7 +468,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t3` where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t3`.`c1` = `test`.`t1`.`a1`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))))) and (`test`.`t3`.`c2` > '0'))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t3` where ((`test`.`t2i`.`b2` = `test`.`t3`.`c2`) and (`test`.`t3`.`c1` = `test`.`t1`.`a1`) and (`test`.`t2i`.`b1` = `test`.`t3`.`c1`) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and (`test`.`t3`.`c2` > '0'))
> select * from t1, t3
> where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
> (c1, c2) in (select c1, c2 from t3
> @@ -490,7 +490,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`>(<in_optimizer>(`test`.`t3`.`c1`,<exists>(select `test`.`t1`.`a1` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select `test`.`t2`.`b1` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`)))))
> +Note 1003 select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`c1`,<exists>(select `test`.`t1`.`a1` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select `test`.`t2`.`b1` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))))
> select * from t3
> where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
> c1 c2
> @@ -514,14 +514,14 @@ id select_type table type possible_keys
> Warnings:
> Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where ((`test`.`t2i`.`b2` = `test`.`t1`.`a2`) and (`test`.`t2`.`b2` = `test`.`t1`.`a2`) and (`test`.`t3c`.`c2` = `test`.`t1`.`a2`) and (`test`.`t2i`.`b1` = `test`.`t1`.`a1`) and (`test`.`t2`.`b1` = `test`.`t1`.`a1`) and (`test`.`t3c`.`c1` = `test`.`t1`.`a1`) and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`))))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where ((`test`.`t2i`.`b2` = `test`.`t1`.`a2`) and (`test`.`t2`.`b2` = `test`.`t1`.`a2`) and (`test`.`t3c`.`c2` = `test`.`t1`.`a2`) and (`test`.`t2i`.`b1` = `test`.`t1`.`a1`) and (`test`.`t2`.`b1` = `test`.`t1`.`a1`) and (`test`.`t3c`.`c1` = `test`.`t1`.`a1`) and (<in_optimizer>(`test`.`t2`.`b2`,<exists>(select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))))
> explain extended
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01')))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01'))))
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
> a1 a2
> 1 - 01 2 - 01
> @@ -531,7 +531,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a2`,`test`.`t1`.`a1`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01')))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01','2 - 01' having (((<cache>(`test`.`t1`.`a1`) = '1 - 01') or isnull('1 - 01')) and ((<cache>(`test`.`t1`.`a2`) = '2 - 01') or isnull('2 - 01')) and <is_not_null_test>('1 - 01') and <is_not_null_test>('2 - 01'))))
> select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
> a1 a2
> 1 - 01 2 - 01
> @@ -563,7 +563,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort
> 2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key
> Warnings:
> -Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond((<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`))))))
> +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond((<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`)))))
> select * from t1 group by (a1 in (select col from columns));
> a1 a2
> 1 - 00 2 - 00
> @@ -663,7 +663,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
> 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort
> Warnings:
> -Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having (<cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ','))))))
> +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having (<cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ',')))))
> select left(a1,7), left(a2,7)
> from t1_16
> where a1 in (select group_concat(b1) from t2_16 group by b2);
> @@ -1118,7 +1118,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 group by a having a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1130,7 +1130,7 @@ id select_type table type possible_keys
> 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
> 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` from `test`.`t2` where (`test`.`t2`.`d` >= 20) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`c`)))))
> select a from t1 group by a having a in (select c from t2 where d >= 20);
> a
> 2
> @@ -1144,7 +1144,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`,max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<expr_cache><`test`.`t2`.`d`,max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where (max(`test`.`t1`.`b`) = `test`.`t3`.`e`) having (<cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`)))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`)))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`c` from `test`.`t2` where (<nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where (max(`test`.`t1`.`b`) = `test`.`t3`.`e`) having (<cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`))))) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))))
> select a from t1 group by a
> having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
> a
> @@ -1159,7 +1159,7 @@ id select_type table type possible_keys
> 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))))))
> +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
> select a from t1
> where a in (select c from t2 where d >= some(select e from t3 where b=e));
> a
>
> === modified file 'mysql-test/r/type_datetime.result'
> --- a/mysql-test/r/type_datetime.result 2011-07-04 21:44:15 +0000
> +++ b/mysql-test/r/type_datetime.result 2011-07-14 09:11:11 +0000
> @@ -518,7 +518,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
> Warnings:
> 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 `test`.`t1` where <expr_cache><1,'2007-04-25 18:30:22'>(<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 `test`.`t1` where <in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where 0))
> select * from t1
> where id in (select id from t1 as x1 where (t1.cur_date is null));
> id cur_date
> @@ -530,7 +530,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
> Warnings:
> 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 `test`.`t2` where <expr_cache><1,'2007-04-25'>(<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 `test`.`t2` where <in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where 0))
> select * from t2
> where id in (select id from t2 as x1 where (t2.cur_date is null));
> id cur_date
> @@ -544,7 +544,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY x1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` where <expr_cache><`test`.`t1`.`id`,`test`.`t1`.`cur_date`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where ((`test`.`t1`.`cur_date` = 0) and (<cache>(`test`.`t1`.`id`) = `test`.`x1`.`id`)))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where ((`test`.`t1`.`cur_date` = 0) and (<cache>(`test`.`t1`.`id`) = `test`.`x1`.`id`))))
> select * from t1
> where id in (select id from t1 as x1 where (t1.cur_date is null));
> id cur_date
> @@ -556,7 +556,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY x1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`,`test`.`t2`.`cur_date`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where ((`test`.`t2`.`cur_date` = 0) and (<cache>(`test`.`t2`.`id`) = `test`.`x1`.`id`)))))
> +Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where ((`test`.`t2`.`cur_date` = 0) and (<cache>(`test`.`t2`.`id`) = `test`.`x1`.`id`))))
> select * from t2
> where id in (select id from t2 as x1 where (t2.cur_date is null));
> id cur_date
>
> === modified file 'mysql-test/suite/pbxt/r/subselect.result'
> --- a/mysql-test/suite/pbxt/r/subselect.result 2011-07-06 18:32:07 +0000
> +++ b/mysql-test/suite/pbxt/r/subselect.result 2011-07-14 09:11:11 +0000
> @@ -50,7 +50,7 @@ id select_type table type possible_keys
> 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 1003 select 1 AS `1` from (select 1 AS `a`) `b` having (<expr_cache><1>((select 1)) = 1)
> +Note 1003 select 1 AS `1` from (select 1 AS `a`) `b` having ((select 1) = 1)
> SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
> 1
> 1
> @@ -313,7 +313,7 @@ NULL UNION RESULT <union2,3> ALL NULL NU
> Warnings:
> Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
> Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
> -Note 1003 select <expr_cache><`test`.`t2`.`a`>((select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> +Note 1003 select (select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
> select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
> ERROR 21000: Subquery returns more than 1 row
> create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
> @@ -331,7 +331,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 100.00 Using index
> Warnings:
> Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where <expr_cache><`test`.`t6`.`clinic_uq`>(exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`)))
> +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
> select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
> ERROR 23000: Column 'a' in field list is ambiguous
> drop table t1,t2,t3;
> @@ -742,7 +742,7 @@ id select_type table type possible_keys
> 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
> NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
> Warnings:
> -Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3)))))
> +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
> id
> SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
> @@ -892,7 +892,7 @@ id select_type table type possible_keys
> 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
> 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`,<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');
> INSERT INTO t3 VALUES (1),(2),(3);
> SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
> @@ -907,7 +907,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
> Warnings:
> -Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
> drop table t1,t2,t3;
> create table t1 (a float);
> select 10.5 IN (SELECT * from t1 LIMIT 1);
> @@ -1297,7 +1297,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1307,7 +1307,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1318,7 +1318,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where
> 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> drop table t1, t2, t3;
> create table t1 (a int, b int, index a (a,b));
> create table t2 (a int, index a (a));
> @@ -1336,7 +1336,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a)))
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> 2
> @@ -1346,7 +1346,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
> a
> 2
> @@ -1357,7 +1357,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ref a a 5 func 1 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t3 ref a a 5 test.t1.b 1 100.00 Using index
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
> insert into t1 values (3,31);
> select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
> a
> @@ -1373,7 +1373,7 @@ id select_type table type possible_keys
> 1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
> 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))))
> +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
> drop table t1, t2, t3;
> create table t1 (a int, b int);
> create table t2 (a int, b int);
> @@ -1464,25 +1464,25 @@ id select_type table type possible_keys
> 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
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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`,<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
> 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(<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;
> 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
> 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
> 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(<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;
> create table t2 (a int, b int);
> create table t3 (a int);
> @@ -1737,14 +1737,14 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))))))
> +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
> explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
> 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
> Warnings:
> Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))
> +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
> insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
> create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
> insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
> @@ -2281,7 +2281,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`)))
> +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
> drop table t1;
> CREATE TABLE t1 (t1_a int);
> INSERT INTO t1 VALUES (1);
> @@ -2824,19 +2824,19 @@ id select_type table type possible_keys
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 Using where
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`)))))
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = 'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))
> explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
> id select_type table type possible_keys key key_len ref rows filtered Extra
> 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary
> Warnings:
> -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`two`,`test`.`t1`.`one`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1`
> +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
> DROP TABLE t1,t2;
> set @@optimizer_switch=@save_optimizer_switch;
> CREATE TABLE t1 (a char(5), b char(5));
> @@ -4279,7 +4279,7 @@ id select_type table type possible_keys
> 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
> Warnings:
> Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
> -Note 1003 select 2 AS `2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(exists(select 1 from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
> +Note 1003 select 2 AS `2` from `test`.`t1` where exists(select 1 from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`))
> EXPLAIN EXTENDED
> SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
> (SELECT 1 FROM t2 WHERE t1.a = t2.a));
>
> === added file 'mysql-test/t/subselect_no_scache.test'
> --- a/mysql-test/t/subselect_no_scache.test 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/t/subselect_no_scache.test 2011-07-14 09:11:11 +0000
> @@ -0,0 +1,11 @@
> +#
> +# Run subselect.test without semi-join optimization (test materialize)
> +#
> +select @@optimizer_switch like '%subquery_cache=on%';
> +set optimizer_switch='subquery_cache=off';
> +
> +--source t/subselect.test
> +
> +set optimizer_switch=default;
> +select @@optimizer_switch like '%subquery_cache=on%';
> +
>
> === added file 'mysql-test/t/subselect_scache.test'
> --- a/mysql-test/t/subselect_scache.test 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/t/subselect_scache.test 2011-07-14 09:11:11 +0000
> @@ -0,0 +1,11 @@
> +#
> +# Run subselect.test without semi-join optimization (test materialize)
> +#
> +select @@optimizer_switch like '%subquery_cache=on%';
> +set optimizer_switch='subquery_cache=on';
> +
> +--source t/subselect.test
> +
> +set optimizer_switch=default;
> +select @@optimizer_switch like '%subquery_cache=on%';
> +
>
> === modified file 'sql/mysql_priv.h'
> --- a/sql/mysql_priv.h 2011-07-08 15:09:30 +0000
> +++ b/sql/mysql_priv.h 2011-07-14 09:11:11 +0000
> @@ -610,7 +610,6 @@ enabled by default, add OPTIMIZER_SWITCH
> OPTIMIZER_SWITCH_IN_TO_EXISTS | \
> OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
> OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
> - OPTIMIZER_SWITCH_SUBQUERY_CACHE|\
> OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \
> OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \
> OPTIMIZER_SWITCH_JOIN_CACHE_BKA | \
>
> === modified file 'sql/mysqld.cc'
> --- a/sql/mysqld.cc 2011-07-08 15:09:30 +0000
> +++ b/sql/mysqld.cc 2011-07-14 09:11:11 +0000
> @@ -491,7 +491,7 @@ static const char *optimizer_switch_str=
> "semijoin=off,"
> "partial_match_rowid_merge=on,"
> "partial_match_table_scan=on,"
> - "subquery_cache=on,"
> + "subquery_cache=off,"
> "mrr=off,"
> "mrr_cost_based=off,"
> "mrr_sort_keys=off,"
>
> _______________________________________________
> commits mailing list
> commits(a)mariadb.org
> https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits
--
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

[Maria-developers] Fwd: [Commits] Rev 3108: Fix bug lp:777691 in file:///home/tsk/mprog/src/5.3-work/
by Timour Katchaounov 14 Jul '11
by Timour Katchaounov 14 Jul '11
14 Jul '11
Sergey,
Please review the below patch. As discussed, all other
solutions that try to keep the call to mark_as_null_row()
lead to a chicken-egg-like problem that is tricky to
solve. Since I am not sure it is worth solving, I suggest
the below simple solution.
Timour
------------------------------------------------------------
revno: 3108
revision-id: timour(a)askmonty.org-20110714095300-bwi0z7x542cj2avd
parent: timour(a)askmonty.org-20110714072218-hty7xnwn1dxmn9a3
fixes bug(s): https://launchpad.net/bugs/777691
committer: timour(a)askmonty.org
branch nick: 5.3-work
timestamp: Thu 2011-07-14 12:53:00 +0300
message:
Fix bug lp:777691
Analysis:
For some of the re-executions of the correlated subquery the
where clause is false. In these cases the execution of the
subquery detects that it must generate a NULL row because of
implicit grouping. In this case the subquery execution reaches
the following code in do_select():
while ((table= li++))
mark_as_null_row(table->table);
This code marks all rows in the table as complete NULL rows.
In the example, when evaluating the field t2.f10 for the second
row, all bits of Field::null_ptr[0] are set by the previous call
to mark_as_null_row(). Then the call to Field::is_null()
returns true, resulting in a NULL for the MAX function.
Thus the lines above are not suitable for subquery re-execution
because mark_as_null_row() changes the NULL bits of each table
field, and there is no logic to restore these fields.
Solution:
The call to mark_as_null_row() was added by the fix for bug
lp:613029. Therefore removing the fix for lp:613029 corrects
this wrong result. At the same time the test for lp:613029
behaves correctly because the changes of MWL#89 result in a
different execution path where:
- the constant subquery is evaluated via JOIN::exec_const_cond
- detecting that it has an empty result triggers the branch
if (zero_result_cause)
return_zero_rows()
- return_zero_rows() calls mark_as_null_row().
1
0

[Maria-developers] Fwd: [Commits] Rev 3092: Fixed bug lp:809245 in file:///home/tsk/mprog/src/5.3-mwl89/
by Timour Katchaounov 14 Jul '11
by Timour Katchaounov 14 Jul '11
14 Jul '11
Igor,
Could you please review my patch for bug LP:809245.
Ttimour
-------- Original Message --------
Return-Path: <commits-bounces(a)mariadb.org>
X-Original-To: timour(a)askmonty.org
Delivered-To: timour(a)askmonty.org
Received: from localhost (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id 1014BE104C; Wed, 13 Jul 2011 17:09:26 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
Received: from hasky.askmonty.org ([127.0.0.1]) by localhost (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2zpPCMRHKtn9; Wed, 13 Jul 2011 17:09:26 +0300 (EEST)
Received: from hasky.askmonty.org (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id BC862E1049; Wed, 13 Jul 2011 17:09:26 +0300 (EEST)
Received: by hasky.askmonty.org (Postfix) id 756A7E1049; Wed, 13 Jul 2011 17:09:25 +0300 (EEST)
Delivered-To: commits(a)mariadb.org
Received: from localhost (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id 641B3E104A for <commits(a)mariadb.org>; Wed, 13 Jul 2011 17:09:25 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
Received: from hasky.askmonty.org ([127.0.0.1]) by localhost (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PF4tvWx7nmEU for <commits(a)mariadb.org>; Wed, 13 Jul 2011 17:09:19
+0300 (EEST)
Received: from localhost6.localdomain6 (unknown [91.148.138.177]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by hasky.askmonty.org (Postfix) with
ESMTPSA id DCEAEE1049 for <commits(a)mariadb.org>; Wed, 13 Jul 2011 17:09:18 +0300 (EEST)
Content-Type: multipart/mixed; boundary="===============3088248604612826632=="
MIME-Version: 1.0
From: <timour(a)askmonty.org>
User-Agent: bzr/2.3.1
To: <commits(a)mariadb.org>
Message-Id: <20110713140918.DCEAEE1049(a)hasky.askmonty.org>
Date: Wed, 13 Jul 2011 17:09:18 +0300 (EEST)
Subject: [Commits] Rev 3092: Fixed bug lp:809245 in file:///home/tsk/mprog/src/5.3-mwl89/
X-BeenThere: commits(a)mariadb.org
X-Mailman-Version: 2.1.9
Precedence: list
Reply-To: maria-developers(a)lists.launchpad.net
List-Id: MariaDB Commits List <commits.mariadb.org>
List-Unsubscribe: <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>, <mailto:commits-request@mariadb.org?subject=unsubscribe>
List-Archive: <http://lists.askmonty.org/pipermail/commits>
List-Post: <mailto:commits@mariadb.org>
List-Help: <mailto:commits-request@mariadb.org?subject=help>
List-Subscribe: <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>, <mailto:commits-request@mariadb.org?subject=subscribe>
Sender: commits-bounces(a)mariadb.org
Errors-To: commits-bounces(a)mariadb.org
At file:///home/tsk/mprog/src/5.3-mwl89/
------------------------------------------------------------
revno: 3092
revision-id: timour(a)askmonty.org-20110713140909-rkka410svyafz4jn
parent: timour(a)askmonty.org-20110708075646-h4kmmn8mmihfmh1f
fixes bug(s): https://launchpad.net/bugs/809245
committer: timour(a)askmonty.org
branch nick: 5.3-mwl89
timestamp: Wed 2011-07-13 17:09:09 +0300
message:
Fixed bug lp:809245
In addition to the bug fix explained below, the patch performs
few renames, and adds some comments to avoid similar problems.
Analysis:
The failed assert was due to a bug in MWL#68, where it was
incorrectly assumed that the size of the bitmap
subselect_rowid_merge_engine::null_only_columns should be
the same as the size of the array of Ordered_keys.
The bitmap null_only_columns contains bits to mark columns
that contain only NULLs. Therefore the indexes of the bits
to be set in null_only_columns are different from the indexes
of the Ordered_keys. If there is a NULL-only column that appears
in a table after the last partial match column with Ordered_key,
this NULL-only column would require setting a bit with index
bigger than the size of the bitmap null_only_columns.
Accessing such a bit caused the failed assert.
Solution:
Upon analysis, it turns out that null_only_columns is not needed
at all, because we are looking for partial matches, and having
such columns guarantees that there is a partial match for any
corresponding outer value.
Therefore the patch removes
subselect_rowid_merge_engine::null_only_columns.
2
1

[Maria-developers] Fwd: [Commits] Rev 3104: Fix bug lp:809266 in file:///home/tsk/mprog/src/5.3-mwl89/
by Timour Katchaounov 14 Jul '11
by Timour Katchaounov 14 Jul '11
14 Jul '11
Igor,
Could you please review this fix for bug lp:809266.
Timour
------------------------------------------------------------
revno: 3104
revision-id: timour(a)askmonty.org-20110713211507-j9v80yk2tzae8tq2
parent: timour(a)askmonty.org-20110713141146-339e3xwz17hogqsb
fixes bug(s): https://launchpad.net/bugs/809266
committer: timour(a)askmonty.org
branch nick: 5.3-mwl89
timestamp: Thu 2011-07-14 00:15:07 +0300
message:
Fix bug lp:809266
Analysis:
This is a bug in MWL#68, where it was incorrectly assumed
that if there is a match in the only non-null key, then
if there is a covering NULL row on all remaining NULL-able
columns there is a partial match. However, this is not the case,
because even if there is such a null-only sub-row, it is not
guaranteed to be part of the matched sub-row. The matched sub-row
and the NULL-only sub-row may be parts of different rows.
In fact there are two cases:
- there is a complete row with only NULL values, and
- all nullable columns contain only NULL values.
These two cases were incorrectly mixed up in the class member
subselect_partial_match_engine::covering_null_row_width.
Solution:
The solution is to:
- split covering_null_row_width into two members:
has_covering_null_row, and has_covering_null_columns, and
- take into account each state during initialization and
execution.
2
1

[Maria-developers] Timour please review: [Commits] Rev 3096: BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
by Sergey Petrunya 13 Jul '11
by Sergey Petrunya 13 Jul '11
13 Jul '11
Hi Timour,
Could you please review the below:
----- Forwarded message from Sergey Petrunya <psergey(a)askmonty.org> -----
From: Sergey Petrunya <psergey(a)askmonty.org>
To: commits(a)mariadb.org
X-Mailer: mail (GNU Mailutils 1.2)
Date: Thu, 14 Jul 2011 00:43:12 +0400 (MSD)
Subject: [Commits] Rev 3096: BUG#778434 Wrong result with in_to_exists=on in
maria-5.3-mwl89 in file:///home/psergey/dev2/5.3-push7/
At file:///home/psergey/dev2/5.3-push7/
------------------------------------------------------------
revno: 3096
revision-id: psergey(a)askmonty.org-20110713204306-tsxnddr8v3v0i6bg
parent: psergey(a)askmonty.org-20110709123340-1qe0558i8p352p2v
committer: Sergey Petrunya <psergey(a)askmonty.org>
branch nick: 5.3-push7
timestamp: Thu 2011-07-14 00:43:06 +0400
message:
BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
- Make {ha_myisam,ha_maria}::index_read_idx_map check pushed index condition.
=== modified file 'mysql-test/include/icp_tests.inc'
--- a/mysql-test/include/icp_tests.inc 2011-02-09 03:17:12 +0000
+++ b/mysql-test/include/icp_tests.inc 2011-07-13 20:43:06 +0000
@@ -225,3 +225,32 @@
DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3;
+
+--echo #
+--echo # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
+--echo #
+CREATE TABLE t1 ( f11 int) ;
+INSERT IGNORE INTO t1 VALUES (0);
+
+CREATE TABLE t2 ( f10 int) ;
+INSERT IGNORE INTO t2 VALUES (0);
+
+CREATE TABLE t3 ( f1 int NOT NULL , f10 int, PRIMARY KEY (f1)) ;
+INSERT IGNORE INTO t3 VALUES (6,0),(10,0);
+
+CREATE TABLE t4 ( f11 int) ;
+INSERT IGNORE INTO t4 VALUES
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(NULL),
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
+
+set @tmp_778434=@@optimizer_switch;
+SET optimizer_switch='materialization=off,in_to_exists=on,subquery_cache=off,semijoin=off';
+
+SELECT * FROM t1 INNER JOIN t2 ON t2.f10 = t1.f11
+WHERE (6, 234) IN (
+ SELECT t3.f1, t3.f1
+ FROM t3 JOIN t4 ON t4.f11 = t3.f10
+);
+
+DROP TABLE t1,t2,t3,t4;
+set optimizer_switch= @tmp_778434;
=== modified file 'mysql-test/r/innodb_icp.result'
--- a/mysql-test/r/innodb_icp.result 2011-07-08 14:46:47 +0000
+++ b/mysql-test/r/innodb_icp.result 2011-07-13 20:43:06 +0000
@@ -202,5 +202,28 @@
12
DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3;
+#
+# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
+#
+CREATE TABLE t1 ( f11 int) ;
+INSERT IGNORE INTO t1 VALUES (0);
+CREATE TABLE t2 ( f10 int) ;
+INSERT IGNORE INTO t2 VALUES (0);
+CREATE TABLE t3 ( f1 int NOT NULL , f10 int, PRIMARY KEY (f1)) ;
+INSERT IGNORE INTO t3 VALUES (6,0),(10,0);
+CREATE TABLE t4 ( f11 int) ;
+INSERT IGNORE INTO t4 VALUES
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(NULL),
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
+set @tmp_778434=@@optimizer_switch;
+SET optimizer_switch='materialization=off,in_to_exists=on,subquery_cache=off,semijoin=off';
+SELECT * FROM t1 INNER JOIN t2 ON t2.f10 = t1.f11
+WHERE (6, 234) IN (
+SELECT t3.f1, t3.f1
+FROM t3 JOIN t4 ON t4.f11 = t3.f10
+);
+f11 f10
+DROP TABLE t1,t2,t3,t4;
+set optimizer_switch= @tmp_778434;
set optimizer_switch=@innodb_icp_tmp;
set storage_engine= @save_storage_engine;
=== modified file 'mysql-test/r/maria_icp.result'
--- a/mysql-test/r/maria_icp.result 2011-07-08 14:46:47 +0000
+++ b/mysql-test/r/maria_icp.result 2011-07-13 20:43:06 +0000
@@ -202,5 +202,28 @@
12
DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3;
+#
+# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
+#
+CREATE TABLE t1 ( f11 int) ;
+INSERT IGNORE INTO t1 VALUES (0);
+CREATE TABLE t2 ( f10 int) ;
+INSERT IGNORE INTO t2 VALUES (0);
+CREATE TABLE t3 ( f1 int NOT NULL , f10 int, PRIMARY KEY (f1)) ;
+INSERT IGNORE INTO t3 VALUES (6,0),(10,0);
+CREATE TABLE t4 ( f11 int) ;
+INSERT IGNORE INTO t4 VALUES
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(NULL),
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
+set @tmp_778434=@@optimizer_switch;
+SET optimizer_switch='materialization=off,in_to_exists=on,subquery_cache=off,semijoin=off';
+SELECT * FROM t1 INNER JOIN t2 ON t2.f10 = t1.f11
+WHERE (6, 234) IN (
+SELECT t3.f1, t3.f1
+FROM t3 JOIN t4 ON t4.f11 = t3.f10
+);
+f11 f10
+DROP TABLE t1,t2,t3,t4;
+set optimizer_switch= @tmp_778434;
set storage_engine= @save_storage_engine;
set optimizer_switch=@maria_icp_tmp;
=== modified file 'mysql-test/r/myisam_icp.result'
--- a/mysql-test/r/myisam_icp.result 2011-07-08 14:46:47 +0000
+++ b/mysql-test/r/myisam_icp.result 2011-07-13 20:43:06 +0000
@@ -198,6 +198,29 @@
12
DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3;
+#
+# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
+#
+CREATE TABLE t1 ( f11 int) ;
+INSERT IGNORE INTO t1 VALUES (0);
+CREATE TABLE t2 ( f10 int) ;
+INSERT IGNORE INTO t2 VALUES (0);
+CREATE TABLE t3 ( f1 int NOT NULL , f10 int, PRIMARY KEY (f1)) ;
+INSERT IGNORE INTO t3 VALUES (6,0),(10,0);
+CREATE TABLE t4 ( f11 int) ;
+INSERT IGNORE INTO t4 VALUES
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(NULL),
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
+set @tmp_778434=@@optimizer_switch;
+SET optimizer_switch='materialization=off,in_to_exists=on,subquery_cache=off,semijoin=off';
+SELECT * FROM t1 INNER JOIN t2 ON t2.f10 = t1.f11
+WHERE (6, 234) IN (
+SELECT t3.f1, t3.f1
+FROM t3 JOIN t4 ON t4.f11 = t3.f10
+);
+f11 f10
+DROP TABLE t1,t2,t3,t4;
+set optimizer_switch= @tmp_778434;
set @myisam_icp_tmp=@@optimizer_switch;
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
drop table if exists t0, t1, t1i, t1m;
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2011-07-01 12:08:30 +0000
+++ b/sql/sql_class.h 2011-07-13 20:43:06 +0000
@@ -3633,6 +3633,7 @@
enum ha_rkey_function find_flag)
{
increment_statistics(&SSV::ha_read_key_count);
+ DBUG_ASSERT(inited==NONE);
int error= index_read_idx_map(buf, index, key, keypart_map, find_flag);
if (!error)
{
=== modified file 'storage/maria/ha_maria.cc'
--- a/storage/maria/ha_maria.cc 2011-07-01 12:16:10 +0000
+++ b/storage/maria/ha_maria.cc 2011-07-13 20:43:06 +0000
@@ -2259,7 +2259,14 @@
key_part_map keypart_map,
enum ha_rkey_function find_flag)
{
- int error= maria_rkey(file, buf, index, key, keypart_map, find_flag);
+ int error;
+ /* Use the pushed index condition if it matches the index we're scanning */
+ if (index == pushed_idx_cond_keyno)
+ ma_set_index_cond_func(file, index_cond_func_maria, this);
+
+ error= maria_rkey(file, buf, index, key, keypart_map, find_flag);
+
+ ma_set_index_cond_func(file, NULL, 0);
table->status= error ? STATUS_NOT_FOUND : 0;
return error;
}
=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc 2011-06-24 17:43:31 +0000
+++ b/storage/myisam/ha_myisam.cc 2011-07-13 20:43:06 +0000
@@ -1790,7 +1790,13 @@
key_part_map keypart_map,
enum ha_rkey_function find_flag)
{
- return mi_rkey(file, buf, index, key, keypart_map, find_flag);
+ int res;
+ /* Use the pushed index condition if it matches the index we're scanning */
+ if (index == pushed_idx_cond_keyno)
+ mi_set_index_cond_func(file, index_cond_func_myisam, this);
+ res= mi_rkey(file, buf, index, key, keypart_map, find_flag);
+ mi_set_index_cond_func(file, NULL, 0);
+ return res;
}
int ha_myisam::index_next(uchar *buf)
_______________________________________________
commits mailing list
commits(a)mariadb.org
https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits
----- End forwarded message -----
--
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

Re: [Maria-developers] [Commits] Rev 3096: Alternate version of MySQL's fix for BUG#49453. in file:///home/psergey/dev2/5.3-push6/
by Timour Katchaounov 11 Jul '11
by Timour Katchaounov 11 Jul '11
11 Jul '11
Sergey,
This is not a review, just a quick look at the patch.
The below solution is totally cryptic. Please add a
comment why items in the ref_array are the right ones.
If someone ever has to deal with this code, even your
commit comment (not speaking that there is no code comment)
will provide absolutely no clue why items should be taken
from the ref-array.
Timour
1
0

07 Jul '11
Hello,
I have not been very active in my open source (or online!) life lately as
I have been busy with my own wedding and starting work programming for a
new company. I apologize for my freebsd buildbot not having been up, a
power outage and a software raid issue; followed by the afore mentioned
wedding have kept me from bringing it back online or otherwise
pre-occupied so I hadn't stopped to think about the buildbot not having
started on boot. My apologies..
All of this aside I am about to launch a new software product; well more
of a production its for a single client and is not intended to come in a
box at this moment (or ever, should be freely available once I can get
organized enough again to get a project page together). Its for
inventory/calendar and truck management for an HVAC company; I would like
to base it on MariaDB explicitly but with enterprise class stability and
support forward looking. I have a good idea already of how to use the
database itself however I would like a fail safe (though small scale,
think small business) which is low in hardware requirements in general (to
make redundancy more affordable, mostly).
The big topic is, storage engine, I am actually still seeing performance
gain in many simpler scenarios from the classic MyISAM moniker from recent
applications I have launched; also the straight up file copy type backup
being an option is appealing for simplicity in scenarios where the user(s)
are less savvy but definitely dependent on their apps. Is there a
reliability loss with PBXT compared to InnoDB/XtraDB?
I would like to do this right, in addition I do plan to make this
community information with the site I am launching. If anyone could
outline why one engine is better over another for this simple
application that would be great. I would like to build something very
progressive and supportable for this client who is personally
important to me. Also Language choice I suppose would be a factor,
python and java have suited me well and seem to due extremely well
interfacing with MariaDB performance wise with widely available stable
MySQL/MariaDB API's.
Lastly, I will make it brief, Postgresql interoperability? My current
employer uses this database extensively; I would like to replicate
(even if only by snapshot) there data structures into this environment
for development, I believe in the long run a performance gain may be
attainable this way, is there any outlook of something like FederatedX
(or other method) allowing interoperability; replication would be
ideal (especially since postgresql does have some short comings as far
as replication methods), slony is currently employed. Our software is
from a significant consulting firm who has informed me that it should
work on basically "any" dbms. Replacement isn't an option at this
point in the deployment but tools to allow the two backends to work
together would open some doors for me, hence bringing up federation.
This is an old topic I know but to have tables that I are dissparate
but centrally acessiible by SQL via MariaDB would be preferrable and
very neat.
Thank you for your time, and I would appreciate any feedback that I
receive.
Jakob Lorberblatt
1
0
http://kb.askmonty.org/en/wince-client
Thanks.
--
Daniel Bartholomew
MariaDB - http://mariadb.org
Monty Program - http://montyprogram.com
AskMonty Knowledgebase - http://kb.askmonty.org
1
0

[Maria-developers] Fwd: [Commits] Rev 3071: Fix LP bug lp:802979 in file:///home/tsk/mprog/src/5.3-mwl89/
by Timour Katchaounov 06 Jul '11
by Timour Katchaounov 06 Jul '11
06 Jul '11
Sergey
Could you please review my fix for bug lp:802979.
I need you specifically because I needed to touch
the range optimzizer to disable evaluation of
single-row subqueries.
Please consider if I chose the best place in the
range optimizer to disable this evaluation of
single-row subqueries.
I will be back from vacation on Tuesday, so if there
is need for discussion, we can talk on Tuesday evening
or Wednesday any time.
Timour
-------- Original Message --------
Return-Path: <commits-bounces(a)mariadb.org>
X-Original-To: timour(a)askmonty.org
Delivered-To: timour(a)askmonty.org
Received: from localhost (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id 2FB01D0A86; Mon, 4 Jul 2011 14:51:35 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
Received: from hasky.askmonty.org ([127.0.0.1]) by localhost (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VhBdpL-sj25D; Mon, 4 Jul 2011 14:51:34 +0300 (EEST)
Received: from hasky.askmonty.org (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id D6837D0A72; Mon, 4 Jul 2011 14:51:34 +0300 (EEST)
Received: by hasky.askmonty.org (Postfix) id 13265D0A72; Mon, 4 Jul 2011 14:51:33 +0300 (EEST)
Delivered-To: commits(a)mariadb.org
Received: from localhost (localhost.localdomain [127.0.0.1]) by hasky.askmonty.org (Postfix) with ESMTP id 02961D0A84 for <commits(a)mariadb.org>; Mon, 4 Jul 2011 14:51:33 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at mail.askmonty.org
Received: from hasky.askmonty.org ([127.0.0.1]) by localhost (mail.askmonty.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xbI1dw-8fTxt for <commits(a)mariadb.org>; Mon, 4 Jul 2011 14:51:29
+0300 (EEST)
Received: from localhost6.localdomain6 (unknown [213.226.63.169]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by hasky.askmonty.org (Postfix) with
ESMTPSA id DC670D0A72 for <commits(a)mariadb.org>; Mon, 4 Jul 2011 14:51:28 +0300 (EEST)
Content-Type: multipart/mixed; boundary="===============4096211003537732309=="
MIME-Version: 1.0
From: <timour(a)askmonty.org>
User-Agent: bzr/2.3.1
To: <commits(a)mariadb.org>
Message-Id: <20110704115128.DC670D0A72(a)hasky.askmonty.org>
Date: Mon, 4 Jul 2011 14:51:28 +0300 (EEST)
Subject: [Commits] Rev 3071: Fix LP bug lp:802979 in file:///home/tsk/mprog/src/5.3-mwl89/
X-BeenThere: commits(a)mariadb.org
X-Mailman-Version: 2.1.9
Precedence: list
Reply-To: maria-developers(a)lists.launchpad.net
List-Id: MariaDB Commits List <commits.mariadb.org>
List-Unsubscribe: <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>, <mailto:commits-request@mariadb.org?subject=unsubscribe>
List-Archive: <http://lists.askmonty.org/pipermail/commits>
List-Post: <mailto:commits@mariadb.org>
List-Help: <mailto:commits-request@mariadb.org?subject=help>
List-Subscribe: <https://lists.askmonty.org/cgi-bin/mailman/listinfo/commits>, <mailto:commits-request@mariadb.org?subject=subscribe>
Sender: commits-bounces(a)mariadb.org
Errors-To: commits-bounces(a)mariadb.org
At file:///home/tsk/mprog/src/5.3-mwl89/
------------------------------------------------------------
revno: 3071
revision-id: timour(a)askmonty.org-20110704115116-cx7ibyty8uiwrpg7
parent: igor(a)askmonty.org-20110630030724-l43c25gdezawuum3
fixes bug(s): https://launchpad.net/bugs/802979
committer: timour(a)askmonty.org
branch nick: 5.3-mwl89
timestamp: Mon 2011-07-04 14:51:16 +0300
message:
Fix LP bug lp:802979
Analysis:
This bug consists of two related problems that are
result of too early evaluation of single-row subqueries
during the optimization phase of the outer query.
Several optimizer code paths try to evaluate single-row
subqueries in order to produce a constant and use that
constant for further optimzation.
When the execution of the subquery peforms destructive
changes to the representation of the subquery, and these
changes are not anticipated by the subsequent optimization
phases of the outer query, we tipically get a crash or
failed assert.
Specifically, in this bug the inner-most suqbuery with
DISTINCT triggers a substitution of the original JOIN
object by a single-table JOIN object with a temp table
needed to perform the DISTINCT operation (created by
JOIN::make_simple_join).
This substitution breaks EXPLAIN because:
a) in the first example JOIN::cleanup no longer can
reach the original table of the innermost subquery, and
close all indexes, and
b) in this second test query, EXPLAIN attempts to print
the name of the internal temp table, and crashes because
the temp table has no name (NULL pointer instead).
Solution:
a) fully disable subquery evaluation during optimization
in all cases - both for constant propagation and range
optimization, and
b) change JOIN::join_free() to perform cleanup irrespective
of EXPLAIN or not.
2
3

Re: [Maria-developers] [Commits] Rev 2955: Fix compiling on Windows. in file:///H:/bzr/mwl192/
by Kristian Nielsen 06 Jul '11
by Kristian Nielsen 06 Jul '11
06 Jul '11
Vladislav Vaintroub <wlad(a)montyprogram.com> writes:
> Fix compiling on Windows.
Thanks for your help! I'm now merging this into the MWL#192 tree.
All the changes are good, but I would like your help to understand a couple of them:
> === modified file 'client/async_example.c'
> --- a/client/async_example.c 2011-06-14 09:11:47 +0000
> +++ b/client/async_example.c 2011-06-22 14:38:52 +0000
> @@ -17,8 +17,6 @@
> along with this. If not, see <http://www.gnu.org/licenses/>.
> */
>
> -#include <stdlib.h>
> -#include <stdio.h>
>
> #ifndef __WIN__
> #include <poll.h>
> @@ -26,10 +24,9 @@
> #include <WinSock2.h>
> #endif
>
> -/* For some reason, mysql.h does not work here on Windows, but client_priv.h does.
> +#include <stdlib.h>
> +#include <stdio.h>
> #include <mysql.h>
> -*/
> -#include <client_priv.h>
>
> #define SL(s) (s), sizeof(s)
Why does this patch fix the problem? I guess the real question is what did I
do wrong originally? Is it that it is incorrect on windows to include stdlib.h
/ stdio.h before Winsock2.h ?
> === modified file 'include/typelib.h'
> --- a/include/typelib.h 2009-03-12 22:27:35 +0000
> +++ b/include/typelib.h 2011-06-22 14:38:52 +0000
> @@ -29,7 +29,7 @@
> extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
> extern int find_type_with_warning(const char *x, TYPELIB *typelib,
> const char *option);
> -extern uint find_type_or_exit(const char *x, TYPELIB *typelib,
> +extern unsigned int find_type_or_exit(const char *x, TYPELIB *typelib,
> const char *option);
> extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name);
> extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
I do not understand what this patch has to do with my MWL#192 changes, can you
help explain? (Again, I think the change is correct, I just would like to
understand what I did to make this change necessary).
- Kristian.
2
3

Re: [Maria-developers] [Commits] Rev 3067: Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. in lp:maria/5.3
by Sergei Golubchik 05 Jul '11
by Sergei Golubchik 05 Jul '11
05 Jul '11
Hi, Michael!
On Jun 30, Michael Widenius wrote:
> message:
> Added progress reporting for alter table, LOAD DATA INFILE and for
> aria tables: check table, repair table, analyze table.
> - The client gets a progress report message that triggers a callback
> function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK,
> function)
> - Added Progress field last to 'show processlist'
> - Stage, Max_stage and Progress field added to
> information_schema.progresslist
> - The 'mysql' client by defaults enables progress reports when the
> output is a tty.
> - Added progress_report_time time variable to configure how often
> progress reports is sent to client
> Added read only system variable 'in_transaction' which is 1 if we
> have executed a BEGIN statement.
> === modified file 'include/mysql/plugin.h'
> --- a/include/mysql/plugin.h 2010-10-25 13:21:16 +0000
> +++ b/include/mysql/plugin.h 2011-06-30 12:23:49 +0000
> @@ -783,6 +784,21 @@ int thd_killed(const MYSQL_THD thd);
>
>
> /**
> + Report progress for long running operations (for information schema)
> +
> + @param thd User thread connection handle
> + @param progress Where we are now
> + @param max_progress Progress will continue up to this
> +*/
> +
> +void thd_progress_init(MYSQL_THD thd, unsigned int max_stage);
> +void thd_progress_report(MYSQL_THD thd,
> + unsigned long long progress,
> + unsigned long long max_progress);
> +void thd_progress_next_stage(MYSQL_THD thd);
> +void thd_progress_end(MYSQL_THD thd);
This should be implemented as a service.
See libservices/HOWTO
> +
> +/**
> Return the thread id of a user thread
>
> @param thd user thread connection handle
>
> === modified file 'mysql-test/r/create.result'
> --- a/mysql-test/r/create.result 2011-05-16 11:05:45 +0000
> +++ b/mysql-test/r/create.result 2011-06-30 12:23:49 +0000
> @@ -1760,7 +1760,10 @@ t1 CREATE TABLE `t1` (
> `TIME` int(7) NOT NULL DEFAULT '0',
> `STATE` varchar(64) DEFAULT NULL,
> `INFO` longtext,
> - `TIME_MS` decimal(22,3) NOT NULL DEFAULT '0.000'
> + `TIME_MS` decimal(22,3) NOT NULL DEFAULT '0.000',
> + `STAGE` tinyint(2) NOT NULL DEFAULT '0',
> + `MAX_STAGE` tinyint(2) NOT NULL DEFAULT '0',
> + `PROGRESS_DONE` decimal(7,3) NOT NULL DEFAULT '0.000'
please run
./mtr --suite funcs_1 --ps-protocol
and update test results accordingly.
> ) DEFAULT CHARSET=utf8
> drop table t1;
> create temporary table t1 like information_schema.processlist;
> === modified file 'scripts/mytop.sh'
> --- a/scripts/mytop.sh 2011-06-27 16:30:05 +0000
> +++ b/scripts/mytop.sh 2011-06-30 12:23:49 +0000
> @@ -17,6 +17,7 @@ use strict;
> use DBI;
> use Getopt::Long;
> use Socket;
> +use List::Util qw[min max];
conventionally one uses qw/.../ or qw(...)
> $main::VERSION = "1.9a";
>
> @@ -1075,21 +1076,22 @@ sub GetData()
> ## Threads
> ##
>
> - #my $sz = $width - 52;
> - my @sz = (9, 9, 15, 10, 10, 6, 8);
> + my @sz = (9, 8, 15, 9, 6, 5, 6, 8);
do I understand correctly, that you've also committed other
mytop bugfixes in this changeset?
> my $used = scalar(@sz) + Sum(@sz);
> - my $free = $width - $used;
> -
> + my $state= $width <= 80 ? 6 : int(min(6+($width-80)/3, 15));
> + my $free = $width - $used - ($state - 6);
> + my $format= "%9s %8s %15s %9s %6s %5s %6s %${state}s %-.${free}s\n";
> + my $format2= "%9d %8.8s %15.15s %9.9s %6d %5.1f %6.6s %${state}.${state}s %-${free}.${free}s\n";
> print BOLD() if ($HAS_COLOR);
>
> - printf "%9s %9s %15s %10s %10s %6s %8s %-${free}s\n",
> - 'Id','User','Host/IP','DB','Time', 'Cmd', 'State', 'Query';
> + printf $format,
> + 'Id','User','Host/IP','DB','Time', '%', 'Cmd', 'State', 'Query';
>
> print RESET() if ($HAS_COLOR);
>
> ## Id User Host DB
> - printf "%9s %9s %15s %10s %10s %6s %8s %-.${free}s\n",
> - '--','----','-------','--','----', '---', '-----', '----------';
> + printf $format,
> + '--','----','-------','--','----', '-', '---', '-----', '----------';
>
> $lines_left -= 2;
>
> === modified file 'sql-common/client.c'
> --- a/sql-common/client.c 2011-03-18 15:03:43 +0000
> +++ b/sql-common/client.c 2011-06-30 12:23:49 +0000
> @@ -875,6 +886,29 @@ static void cli_flush_use_result(MYSQL *
> }
>
>
> +static void cli_report_progress(MYSQL *mysql, uchar *packet, uint length)
> +{
> + if (mysql->options.extension && mysql->options.extension->report_progress &&
> + length > 5)
you basically ignore the packet if length <= 5.
Better report an error here.
> + {
> + uint stage, max_stage, proc_length;
> + double progress;
> + uchar *start= packet;
> +
> + packet++; /* Ignore number of strings */
> + stage= (uint) *packet++;
> + max_stage= (uint) *packet++;
> + progress= uint3korr(packet)/1000.0;
> + packet+= 3;
> + proc_length= net_field_length(&packet);
> + if (packet + proc_length > start + length)
> + return; /* Error packet */
same here.
I am not sure I like the idea of silently ignoring bad packets.
> + (*mysql->options.extension->report_progress)(mysql, stage, max_stage,
> + progress, (char*) packet,
> + proc_length);
> + }
> +}
> +
> #ifdef __WIN__
> static my_bool is_NT(void)
> {
> @@ -883,57 +917,6 @@ static my_bool is_NT(void)
> }
> #endif
>
> -
> -#ifdef CHECK_LICENSE
> -/**
> - Check server side variable 'license'.
> -
> - If the variable does not exist or does not contain 'Commercial',
> - we're talking to non-commercial server from commercial client.
> -
> - @retval 0 success
> - @retval !0 network error or the server is not commercial.
> - Error code is saved in mysql->net.last_errno.
> -*/
> -
> -static int check_license(MYSQL *mysql)
> -{
> - MYSQL_ROW row;
> - MYSQL_RES *res;
> - NET *net= &mysql->net;
> - static const char query[]= "SELECT @@license";
> - static const char required_license[]= STRINGIFY_ARG(LICENSE);
> -
> - if (mysql_real_query(mysql, query, sizeof(query)-1))
> - {
> - if (net->last_errno == ER_UNKNOWN_SYSTEM_VARIABLE)
> - {
> - set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
> - ER(CR_WRONG_LICENSE), required_license);
> - }
> - return 1;
> - }
> - if (!(res= mysql_use_result(mysql)))
> - return 1;
> - row= mysql_fetch_row(res);
> - /*
> - If no rows in result set, or column value is NULL (none of these
> - two is ever true for server variables now), or column value
> - mismatch, set wrong license error.
> - */
> - if (!net->last_errno &&
> - (!row || !row[0] ||
> - strncmp(row[0], required_license, sizeof(required_license))))
> - {
> - set_mysql_extended_error(mysql, CR_WRONG_LICENSE, unknown_sqlstate,
> - ER(CR_WRONG_LICENSE), required_license);
> - }
> - mysql_free_result(res);
> - return net->last_errno;
> -}
> -#endif /* CHECK_LICENSE */
should be a separate changeset
> @@ -3737,6 +3715,15 @@ mysql_options(MYSQL *mysql,enum mysql_op
> case MYSQL_DEFAULT_AUTH:
> extension_set_string(&mysql->options, default_auth, arg);
> break;
> + case MYSQL_PROGRESS_CALLBACK:
> + if (!mysql->options.extension)
> + mysql->options.extension= (struct st_mysql_options_extention *)
> + my_malloc(sizeof(struct st_mysql_options_extention),
> + MYF(MY_WME | MY_ZEROFILL));
> + if (mysql->options.extension)
> + mysql->options.extension->report_progress=
> + (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg;
> + break;
please create a macro extension_set(), and rewrite
extension_set_string() to use extension_set(). Something like
#define extension_set(OPTS, X, VAL) \
if (!(OPTS)->extension) \
(OPTS)->extension= (struct st_mysql_options_extention *) \
my_malloc(sizeof(struct st_mysql_options_extention), \
MYF(MY_WME | MY_ZEROFILL)); \
(OPTS)->extension->X= VAL;
#define extension_set_string(OPTS, X, STR) \
if ((OPTS)->extension) \
my_free((OPTS)->extension->X, MYF(MY_ALLOW_ZERO_PTR)); \
extension_set(OPTS, X, my_strdup((STR), MYF(MY_WME)));
> default:
> DBUG_RETURN(1);
> }
>
> === modified file 'sql/protocol.cc'
> --- a/sql/protocol.cc 2011-05-28 02:11:32 +0000
> +++ b/sql/protocol.cc 2011-06-30 12:23:49 +0000
> @@ -515,6 +515,52 @@ void net_end_statement(THD *thd)
> }
>
>
> +/**
> + Send a progress report to the client
> +
> + What we send is:
> + header (255,255,255,1)
> + stage, max_stage as on byte integers
> + % withing the stage as %*100000 as a 3 byte integer
write "percentage" not "%". It only takes few more key presses to type
the complete word, and is much more clear than printf-like %*100000
besides, in the packet you put percentage*1000 or ratio*100000, but
not percentage*100000.
> + proc_info as a string
> +*/
> +
> +const uchar progress_header[2]= {(uchar) 255, (uchar) 255 };
> +
> +void net_send_progress_packet(THD *thd)
> +{
> + uchar buff[200], *pos;
> + const char *proc_info= thd->proc_info ? thd->proc_info : "";
> + uint length= strlen(proc_info);
> + ulonglong progress;
> +
> + if (unlikely(!thd->net.vio))
> + return; // Socket is closed
> +
> + pos= buff;
> + /*
> + Store number of strings first. This allows us to later expand the
> + progress indicator if needed.
> + */
> + *pos++= (uchar) 1; // Number of strings
> + *pos++= (uchar) thd->progress.stage + 1;
> + /*
> + We have the max() here to avoid problems if max_stage is not set,
> + which may happen during automatic repair of table
> + */
> + *pos++= (uchar) max(thd->progress.max_stage, thd->progress.stage + 1);
> + progress= 0;
> + if (thd->progress.max_counter)
> + progress= 100000ULL * thd->progress.counter / thd->progress.max_counter;
> + int3store(pos, progress); // Between 0 & 100000
> + pos+= 3;
> + pos= net_store_data(pos, (const uchar*) proc_info,
> + min(length, sizeof(buff)-7));
> + net_write_command(&thd->net, (uchar) 255, progress_header, 2, (uchar*) buff,
better sizeof(progress_header) instead of a literal 2.
> + (uint) (pos - buff));
> +}
> +
> +
> /****************************************************************************
> Functions used by the protocol functions (like net_send_ok) to store
> strings and numbers in the header result packet.
>
> === modified file 'sql/set_var.cc'
> --- a/sql/set_var.cc 2011-06-11 09:04:42 +0000
> +++ b/sql/set_var.cc 2011-06-30 12:23:49 +0000
> @@ -527,6 +528,10 @@ static sys_var_thd_ulong sys_opti
> static sys_var_thd_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
> &SV::optimizer_switch);
>
> +static sys_var_long_ptr sys_progress_report_time(&vars,
> + "progress_report_time",
> + &opt_progress_report_time);
this should be session local variable, not global.
(as discussed on the phone)
> @@ -997,6 +1002,12 @@ static sys_var_enum_const sys_plugin
> &plugin_maturity,
> &plugin_maturity_values);
>
> +static sys_var_readonly sys_in_transaction(&vars, "in_transaction",
> + OPT_SESSION, SHOW_BOOL,
> + in_transaction);
> +
> +
> +
this belongs to a separate changeset
> bool sys_var::check(THD *thd, set_var *var)
> {
> var->save_result.ulonglong_value= var->value->val_int();
> @@ -3399,6 +3410,13 @@ static uchar *get_myisam_mmap_size(THD *
> return (uchar *)&myisam_mmap_size;
> }
>
> +static uchar *in_transaction(THD *thd)
> +{
> + long tmp; // Not active
> + tmp= test(thd->options & OPTION_BEGIN);
better
tmp= test(thd->server_status & SERVER_STATUS_IN_TRANS);
> + thd->sys_var_tmp.my_bool_value= tmp;
> + return (uchar*) &thd->sys_var_tmp.my_bool_value;
> +}
>
> /****************************************************************************
> Main handling of variables:
>
> === modified file 'sql/sql_acl.cc'
> --- a/sql/sql_acl.cc 2011-05-20 19:47:39 +0000
> +++ b/sql/sql_acl.cc 2011-06-30 12:23:49 +0000
> @@ -7478,7 +7478,7 @@ static ulong parse_client_handshake_pack
> THD *thd= mpvio->thd;
> NET *net= &thd->net;
> char *end;
> -
> + ulonglong client_capabilities;
why? client_capabilities are 32-bit, not 64.
> DBUG_ASSERT(mpvio->status == MPVIO_EXT::FAILURE);
>
> if (pkt_len < MIN_HANDSHAKE_SIZE)
> === modified file 'sql/sql_class.h'
> --- a/sql/sql_class.h 2011-06-27 16:07:24 +0000
> +++ b/sql/sql_class.h 2011-06-30 12:23:49 +0000
> @@ -1551,6 +1551,17 @@ class THD :public Statement,
> ulonglong prior_thr_create_utime, thr_create_utime;
> ulonglong start_utime, utime_after_lock;
>
> + // Process indicator
> + struct {
> + /* Set to 1 if command should report progress to client for the command */
> + my_bool report_to_client;
> + /* Internal: If we should report progress to client */
> + my_bool report;
these comments are confusing. I could not understand from them what is
the difference between report_to_client and report - both specify "if we
should report progress to client".
and why they are my_bool, not bool?
> + uint stage, max_stage;
> + ulonglong counter, max_counter;
> + ulonglong last_report_time;
> + } progress;
> +
> thr_lock_type update_lock_default;
> Delayed_insert *di;
>
> === modified file 'sql/sql_table.cc'
> --- a/sql/sql_table.cc 2011-06-27 16:07:24 +0000
> +++ b/sql/sql_table.cc 2011-06-30 12:23:49 +0000
> @@ -8015,8 +8018,10 @@ copy_data_between_tables(TABLE *from,TAB
> HA_POS_ERROR)
> goto err;
> }
> - };
> + thd_progress_next_stage(thd);
> + }
>
> + thd_proc_info(thd, "copy to tmp table");
you need to document explicitly that stage name (that is sent over wire)
may change any time, without changing the number of a stage.
Which, I'd say, is not a very logical requirement, and it may be better
not to change stage names in the middle of a stage.
> /* Tell handler that we have values for all columns in the to table */
> to->use_all_columns();
> to->mark_virtual_columns_for_write(TRUE);
> === modified file 'storage/maria/ha_maria.cc'
> --- a/storage/maria/ha_maria.cc 2011-06-27 16:07:24 +0000
> +++ b/storage/maria/ha_maria.cc 2011-06-30 12:23:49 +0000
> @@ -711,6 +711,15 @@ int _ma_killed_ptr(HA_CHECK *param)
> }
>
>
> +void _ma_report_progress(HA_CHECK *param, ulonglong progress,
> + ulonglong max_progress)
> +{
> + thd_progress_report((THD*)param->thd,
> + progress + max_progress * param->stage,
> + max_progress * param->max_stage);
why? I'd expect simple
thd_progress_report((THD*)param->thd, progress, max_progress)
explained on the phone.
but this absolutely needs a comment here.
> +}
> +
> +
> void _ma_check_print_error(HA_CHECK *param, const char *fmt, ...)
> {
> va_list args;
> @@ -1132,12 +1141,16 @@ int ha_maria::check(THD * thd, HA_CHECK_
> return HA_ADMIN_ALREADY_DONE;
>
> maria_chk_init_for_check(¶m, file);
> + old_proc_info= thd_proc_info(thd, "Checking table");
> + thd_progress_init(thd, 3);
> (void) maria_chk_status(¶m, file); // Not fatal
> error= maria_chk_size(¶m, file);
> if (!error)
> error|= maria_chk_del(¶m, file, param.testflag);
> + thd_progress_next_stage(thd);
> if (!error)
> error= maria_chk_key(¶m, file);
you forgot to set proc_info for a new stage (here, and above)
> + thd_progress_next_stage(thd);
> if (!error)
> {
> if ((!(param.testflag & T_QUICK) &&
> === modified file 'storage/maria/ma_sort.c'
> --- a/storage/maria/ma_sort.c 2011-01-11 13:36:41 +0000
> +++ b/storage/maria/ma_sort.c 2011-06-30 12:23:49 +0000
> @@ -1066,6 +1087,8 @@ merge_index(MARIA_SORT_PARAM *info, uint
> if (merge_buffers(info,keys,tempfile,(IO_CACHE*) 0,sort_keys,buffpek,buffpek,
> buffpek+maxbuffer))
> DBUG_RETURN(1); /* purecov: inspected */
> + if (info->sort_info->param->max_stage != 1) /* If not parallel */
> + _ma_report_progress(info->sort_info->param, 1, 1);
> DBUG_RETURN(0);
> } /* merge_index */
would be nice if you'd copied these changes into MyISAM too.
> === modified file 'tests/mysql_client_test.c'
> --- a/tests/mysql_client_test.c 2011-06-07 16:13:02 +0000
> +++ b/tests/mysql_client_test.c 2011-06-30 12:23:49 +0000
> @@ -309,7 +309,8 @@ mysql_simple_prepare(MYSQL *mysql_arg, c
>
> @return pointer to initialized and connected MYSQL object
> */
> -static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect)
> +static MYSQL* client_connect(ulonglong flag, uint protocol,
flags fit in 32 bits, no need to change to ulonglong
> + my_bool auto_reconnect)
> {
> MYSQL* mysql;
> int rc;
Regards,
Sergei
3
2

[Maria-developers] TCP CRCs - relevant for client/server including replication communications
by Arjen Lentz 05 Jul '11
by Arjen Lentz 05 Jul '11
05 Jul '11
Hi all
See http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.7611
In a nutshell, you cannot expect TCP streams to be error free, instead expect a packet to go wrong every few days; that's quite significant, particularly when talking about replication streams. And most if not all of us in the real world have encountered this.
It's a serious case for having CRCs in the binlog (yes I know it's put in from Google patches to later versions in 5.5+ but I really want it in MariaDB, urgently!), but also as a potential consideration for other communications, including client/server.
The replication streams are the most critical though, that's where stuff has been seen to break in practice - and that's when your lucky and the fail results in a syntax error - if it changes data rather than keywords, it can remain invisible.
(in such cases you could have a replication slave copying a transaction "perfectly" except it has wrong data...)
Regards,
Arjen.
--
Arjen Lentz, Exec.Director @ Open Query (http://openquery.com)
Remote expertise & maintenance for MySQL/MariaDB server environments.
Follow us at http://openquery.com/blog/ & http://twitter.com/openquery
2
2

04 Jul '11
Hello Igor,
I've discovered the following:
Consider a testcase for https://bugs.launchpad.net/maria/+bug/803365.
There we have a query that's using a derived table that's on the inner side
of an outer join:
SELECT *
FROM t1
WHERE t1.f1 IN (
SELECT t2.f2
FROM t2
LEFT JOIN (
SELECT *
FROM t3
) AS alias1
ON alias1.f3 = t2.f2
);
If I follow it in debugger to right after simplify_joins(), I can see this structure (the
[] brackets denote List<TABLE_LIST> bounds):
['t1'---'(sj-nest)']
|
['alias1'---'t2' ]
|
[t3]
'alias1' is on the inner side of an outer join (it has non-NULL on_expr, and outer_join==1).
It has got a single child, t3, which has on_expr==NULL and outer_join==0. Is it really correct
that simplify_joins() didn't remove 'alias1', like it does with regular join nests?
Could it be that simplify_joins() code can't handle single-child join nests just because the parser
never produced them (but after conversion of derived tables to join nests they are now possible?)
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0
Hello,
Following what has been decided on the optimizer call, I'm nearly done with
making semi-join optimizations off by default in 5.3. However, some of 5.3's
new optimizations are still turned on by default.
Here is a list of 5.3 features and flags that control them:
index_merge_sort_intersection=off
semijoin=off
firstmatch=off
loosescan=off
^^ just done the above.
materialization=off
derived_merge=on
derived_with_keys=on
^^ Are we sure about this?
index_condition_pushdown=on
^^ This needs to be discussed too.
partial_match_rowid_merge=on
partial_match_table_scan=on
^^ These are still off because materialization is off.
subquery_cache=on
^^ Need to discuss this.
mrr=on
mrr_cost_based=off
mrr_sort_keys=on
^^ Need to discuss this. I take we should disable MRR, too (since BKA is
disabled anyway?)
join_cache_incremental=on
join_cache_hashed=on
join_cache_bka=on
optimize_join_buffer_size=on
^^ These are not really on because default join_cache_level setting prevents
any of these from being used.
Another question is that we *MUST* have documentation in place if we're making
a release with features that are disabled by default.
BR
Sergey
--
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
1
0

Re: [Maria-developers] [Commits] Rev 3077: Fixed LP bug #804686. in file:///home/igor/maria/maria-5.3-merge/
by Oleksandr Byelkin 04 Jul '11
by Oleksandr Byelkin 04 Jul '11
04 Jul '11
Hi!
04.07.2011 00:59, Igor Babaev пишет:
> At file:///home/igor/maria/maria-5.3-merge/
>
> ------------------------------------------------------------
> revno: 3077
> revision-id: igor(a)askmonty.org-20110703215901-xmisn92l37tswlw8
> parent: monty(a)askmonty.org-20110702143759-sy79jwmahe66we7g
> committer: Igor Babaev<igor(a)askmonty.org>
> branch nick: maria-5.3-merge
> timestamp: Sun 2011-07-03 14:59:01 -0700
> message:
> Fixed LP bug #804686.
> The assert conditions in the functions Item_direct_ref_to_ident::transform
> and Item_direct_ref_to_ident::compile could be not valid after constant
> propagation when fields and field references may be substituted for constants.
> Not only these invalid asserts have been removed, but the functions containing
> them have been removed as well because now Item_ref::transform and
> Item_ref::compile can be used instead of them.
The patch is OK.
1
0

[Maria-developers] WL#229 New (by Monty): Multiple InnoDB Buffer pools
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Multiple InnoDB Buffer pools
CREATION DATE..: Thu, 30 Jun 2011, 18:16
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 229 (http://askmonty.org/worklog/?tid=229)
VERSION........: Server-5.7
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Innodb multiple buffer pools, but size of each, and to which pool will a page go
configured by the dba (instead of random/hash as in 5.5, at table level)
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Dynamic ENUM
CREATION DATE..: Thu, 30 Jun 2011, 18:13
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 228 (http://askmonty.org/worklog/?tid=228)
VERSION........: Server-5.7
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 200 (hours remain)
ORIG. ESTIMATE.: 200
PROGRESS NOTES:
DESCRIPTION:
Create a ENUM-type like data type that does string compression (at a scale). For
example, create a type LOOKUP(255) CHARSET utf8. We store browser user-agent
strings here, you store bigint unsigned numbers internally, and create a lookup
structure so that each occurrence of a string is physically stored only once.
Convert from VARCHAR to LOOKUP using ALTER TABLE.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#227 New (by Monty): Add a time types that contains timezone
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Add a time types that contains timezone
CREATION DATE..: Thu, 30 Jun 2011, 18:11
SUPERVISOR.....: Monty
IMPLEMENTOR....: Sergei
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 227 (http://askmonty.org/worklog/?tid=227)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 160 (hours remain)
ORIG. ESTIMATE.: 160
PROGRESS NOTES:
DESCRIPTION:
Create DATE_TZ, TIME_TZ, DATETIME_TZ and TIMESTAMP_TZ types.
Relegate the timezone in a session to the same function as the charset in a
session ('this is what the client uses') and convert accordingly.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#226 New (by Monty): Replace the MYISAM mysql.* tables with Aria / XtraDB
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Replace the MYISAM mysql.* tables with Aria / XtraDB
CREATION DATE..: Thu, 30 Jun 2011, 18:06
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 226 (http://askmonty.org/worklog/?tid=226)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 120 (hours remain)
ORIG. ESTIMATE.: 120
PROGRESS NOTES:
DESCRIPTION:
Replace the MYISAM mysql.* tables with Aria / XtraDB
We need to get these files crash safe.
There is some unknown (for me) reasons why it's hard to use XtraDB for these
tables. Using crash safe Aria tables should however be possible.
To use Aria, we should first fix that one can use aria_chk to change page size
for Aria tables, as otherwise there will be problems with the system tables if
one want's to change the aria page size.
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Cache VIEW's
CREATION DATE..: Thu, 30 Jun 2011, 17:58
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 225 (http://askmonty.org/worklog/?tid=225)
VERSION........: Server-5.7
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 40 (hours remain)
ORIG. ESTIMATE.: 40
PROGRESS NOTES:
DESCRIPTION:
Views are read from file and parsed for every access.
We should fix this in two stages:
This task: Cache the VIEW file in memory (easy task)
Later: Store a pre-parsed view in memory (hard task)
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#224 New (by Monty): Handle milions of users & roles.
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Handle milions of users & roles.
CREATION DATE..: Thu, 30 Jun 2011, 17:54
SUPERVISOR.....: Sergei
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-BackLog
TASK ID........: 224 (http://askmonty.org/worklog/?tid=224)
VERSION........: Server-5.7
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
The database should be able to work fine with one million users, one million
roles. Do not keep all data in memory, load the required info on login into a
cache (size changeable without restart).
On login, load the requested data, if it is not in cache already.
Example:
SET GLOBAL USERNAME_CACHE = 1000000;
SET GLOBAL ROLE_CACHE = 1000000;
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#223 New (by Monty): Handle millions of tables (add dictionary)
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Handle millions of tables (add dictionary)
CREATION DATE..: Thu, 30 Jun 2011, 17:48
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-Sprint
TASK ID........: 223 (http://askmonty.org/worklog/?tid=223)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 200 (hours remain)
ORIG. ESTIMATE.: 200
PROGRESS NOTES:
DESCRIPTION:
Information_schema falls apart when there is millions of tables.
Fix is to add a table dictionary of the existing files into a mysql.dict file
and use this instead of the file system to return information schema queries
that doesn't require a table to be opened.
When we try to access a table that doesn't exists in the dictionary,
we should open it to see if the .frm file exists and if yes, add it to the
dictionary.
In a similar fashion, if a table that should exist doesn't, we should remove it
from the dictionary.
We would also need a refresh command to update the dict from the .frm file (to
be used if one copies a table over an old table with different information).
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#222 New (by Monty): Make all innodb variables changeable without server restart
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: Make all innodb variables changeable without server restart
CREATION DATE..: Thu, 30 Jun 2011, 17:41
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-Sprint
TASK ID........: 222 (http://askmonty.org/worklog/?tid=222)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Make all XtraDB variables changeable without server restart.
"About every second innodb config change requires a server restart to be picked up"
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0

[Maria-developers] WL#221 New (by Monty): move InnoDB data files between servers
by worklog-noreply@askmonty.org 30 Jun '11
by worklog-noreply@askmonty.org 30 Jun '11
30 Jun '11
-----------------------------------------------------------------------
WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: move InnoDB data files between servers
CREATION DATE..: Thu, 30 Jun 2011, 17:34
SUPERVISOR.....:
IMPLEMENTOR....:
COPIES TO......:
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 221 (http://askmonty.org/worklog/?tid=221)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0
PROGRESS NOTES:
DESCRIPTION:
Add ALTER TABLE ... DETACH/ATTACH commands (or similar) to XtraDB/InnoDB to
allow one to easily copy tables between servers.
(Aria can already do this)
ESTIMATED WORK TIME
ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)
1
0