797 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
		
		
			
		
	
	
			797 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| 
								 | 
							
								--disable_warnings
							 | 
						||
| 
								 | 
							
								drop table if exists t0, t1, t2, t3, t4, t5;
							 | 
						||
| 
								 | 
							
								--enable_warnings
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# 1. Subquery with GROUP/HAVING
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								create table t1 (oref int, grp int, ie int) ;
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp, ie) values
							 | 
						||
| 
								 | 
							
								 (1, 1, 1),
							 | 
						||
| 
								 | 
							
								 (1, 1, 1),
							 | 
						||
| 
								 | 
							
								 (1, 2, NULL),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 (2, 1, 3),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 (3, 1, 4),
							 | 
						||
| 
								 | 
							
								 (3, 2, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Ok, for
							 | 
						||
| 
								 | 
							
								#   select max(ie) from t1 where oref=PARAM group by grp
							 | 
						||
| 
								 | 
							
								# we'll have:
							 | 
						||
| 
								 | 
							
								# PARAM      subquery result  
							 | 
						||
| 
								 | 
							
								#   1   ->   {(1), (NULL)}    matching + NULL
							 | 
						||
| 
								 | 
							
								#   2   ->   {(3)}            non-matching
							 | 
						||
| 
								 | 
							
								#   3   ->   {(3), (NULL)}    non-matching + NULL
							 | 
						||
| 
								 | 
							
								#   4   ->   {}               empty set
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (oref int, a int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  (1, 1),
							 | 
						||
| 
								 | 
							
								  (2, 2),
							 | 
						||
| 
								 | 
							
								  (3, 3),
							 | 
						||
| 
								 | 
							
								  (4, NULL),
							 | 
						||
| 
								 | 
							
								  (2, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# true, false, null, false, null
							 | 
						||
| 
								 | 
							
								select a, oref, a in (select max(ie) 
							 | 
						||
| 
								 | 
							
								  from t1 where oref=t2.oref group by grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# This must have a trigcond
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select a, oref, a in (select max(ie) 
							 | 
						||
| 
								 | 
							
								  from t1 where oref=t2.oref group by grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# This must not have a trigcond:
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select a, oref from t2 
							 | 
						||
| 
								 | 
							
								where a in (select max(ie) from t1 where oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								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
							 | 
						||
| 
								 | 
							
								  ) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Non-correlated subquery, 2 NULL evaluations
							 | 
						||
| 
								 | 
							
								create table t3 (a int);
							 | 
						||
| 
								 | 
							
								insert into t3 values (NULL), (NULL);
							 | 
						||
| 
								 | 
							
								flush status;
							 | 
						||
| 
								 | 
							
								select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
							 | 
						||
| 
								 | 
							
								show status like 'Handler_read_rnd_next';
							 | 
						||
| 
								 | 
							
								select ' ^ This must show 11' Z;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# This must show trigcond:
							 | 
						||
| 
								 | 
							
								explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1, t2, t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# 
							 | 
						||
| 
								 | 
							
								#  2. Subquery handled with 'index_subquery':
							 | 
						||
| 
								 | 
							
								# 
							 | 
						||
| 
								 | 
							
								create table t1 (a int, oref int, key(a));
							 | 
						||
| 
								 | 
							
								insert into t1 values 
							 | 
						||
| 
								 | 
							
								  (1, 1),
							 | 
						||
| 
								 | 
							
								  (1, NULL),
							 | 
						||
| 
								 | 
							
								  (2, 3),
							 | 
						||
| 
								 | 
							
								  (2, NULL),
							 | 
						||
| 
								 | 
							
								  (3, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (a int, oref int);
							 | 
						||
| 
								 | 
							
								insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# The next explain shows "using index" but that is just incorrect display
							 | 
						||
| 
								 | 
							
								# (there is a bug filed about this).
							 | 
						||
| 
								 | 
							
								explain extended 
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								flush status;
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								# This will only show access to t2:
							 | 
						||
| 
								 | 
							
								show status like '%Handler_read_rnd_next';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Check that repeated NULL-scans are not cached (subq. is not correlated):
							 | 
						||
| 
								 | 
							
								delete from t2;
							 | 
						||
| 
								 | 
							
								insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								flush status;
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								show status like '%Handler_read%';
							 | 
						||
| 
								 | 
							
								select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# 3. Subquery handled with 'unique_index_subquery':
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								create table t1 (a int, b int, primary key (a));
							 | 
						||
| 
								 | 
							
								insert into t1 values (1,1), (3,1),(100,1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# 4. Subquery that is a join, with ref access
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								create table t1 (a int, b int, key(a));
							 | 
						||
| 
								 | 
							
								insert into t1 values 
							 | 
						||
| 
								 | 
							
								  (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 like t1;
							 | 
						||
| 
								 | 
							
								insert into t2 select * from t1;
							 | 
						||
| 
								 | 
							
								update t2 set b=1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t3 (a int, oref int);
							 | 
						||
| 
								 | 
							
								insert into t3 values (1, 1), (NULL,1), (NULL,0);
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z 
							 | 
						||
| 
								 | 
							
								from t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# This must have trigcond in WHERE and HAVING:
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z 
							 | 
						||
| 
								 | 
							
								from t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1, t2, t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# BUG#24085: Wrong query result for "NULL IN (SELECT ... UNION SELECT ...)"
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# case 1: NULL IN (SELECT not_null_val FROM ...) w/o HAVING/GROUP-BY/etc
							 | 
						||
| 
								 | 
							
								create table t1 (a int NOT NULL, b int NOT NULL, key(a));
							 | 
						||
| 
								 | 
							
								insert into t1 values 
							 | 
						||
| 
								 | 
							
								  (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 like t1;
							 | 
						||
| 
								 | 
							
								insert into t2 select * from t1;
							 | 
						||
| 
								 | 
							
								update t2 set b=1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t3 (a int, oref int);
							 | 
						||
| 
								 | 
							
								insert into t3 values (1, 1), (NULL,1), (NULL,0);
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z 
							 | 
						||
| 
								 | 
							
								from t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo This must show a trig_cond:
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z 
							 | 
						||
| 
								 | 
							
								from t3;
							 | 
						||
| 
								 | 
							
								drop table t1,t2,t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# case 2: NULL IN (SELECT not_null_val FROM) where SELECT has GROUP BY
							 | 
						||
| 
								 | 
							
								create table t1 (oref int, grp int);
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp) values
							 | 
						||
| 
								 | 
							
								 (1, 1),
							 | 
						||
| 
								 | 
							
								 (1, 1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Ok, for  
							 | 
						||
| 
								 | 
							
								#   select count(*) from t1 group by grp having grp=PARAM
							 | 
						||
| 
								 | 
							
								# we'll have:
							 | 
						||
| 
								 | 
							
								#  PARAM    subuqery result
							 | 
						||
| 
								 | 
							
								#    1  ->    {(2)}   
							 | 
						||
| 
								 | 
							
								#    2  ->    {} - empty set
							 | 
						||
| 
								 | 
							
								create table t2 (oref int, a int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  (1, NULL),
							 | 
						||
| 
								 | 
							
								  (2, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       a in (select count(*) from t1 group by grp having grp=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo This must show a trig_cond:
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select a, oref, 
							 | 
						||
| 
								 | 
							
								       a in (select count(*) from t1 group by grp having grp=t2.oref) Z from 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);
							 | 
						||
| 
								 | 
							
								create table t2 (a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select a,b, a in (select a from t1 where t1.b = t2.b union select a from
							 | 
						||
| 
								 | 
							
								t1 where t1.b = t2.b) Z from t2 ;
							 | 
						||
| 
								 | 
							
								select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
							 | 
						||
| 
								 | 
							
								drop table t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# BUG#24127: Incorrect results of row-based subqueries with NULLs on the left side.
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								create table t3 (a int);
							 | 
						||
| 
								 | 
							
								insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
							 | 
						||
| 
								 | 
							
								create table t2 (a int, b int, oref int);
							 | 
						||
| 
								 | 
							
								insert into t2 values (NULL,1, 100), (NULL,2, 100);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t1 (a int, b int, c int, key(a,b));
							 | 
						||
| 
								 | 
							
								insert into t1 select 2*A, 2*A, 100 from t3;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# First test index subquery engine
							 | 
						||
| 
								 | 
							
								explain extended select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Then check that we do turn off 'ref' scans in the subquery
							 | 
						||
| 
								 | 
							
								create table t4 (x int);
							 | 
						||
| 
								 | 
							
								insert into t4 select A.a + 10*B.a from t1 A, t1 B;
							 | 
						||
| 
								 | 
							
								explain extended 
							 | 
						||
| 
								 | 
							
								  select a,b, oref, 
							 | 
						||
| 
								 | 
							
								         (a,b) in (select a,b from t1,t4 where c=t2.oref) Z 
							 | 
						||
| 
								 | 
							
								  from t2;
							 | 
						||
| 
								 | 
							
								select a,b, oref, 
							 | 
						||
| 
								 | 
							
								       (a,b) in (select a,b from t1,t4 where c=t2.oref) Z 
							 | 
						||
| 
								 | 
							
								from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1,t2,t3,t4;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# More tests for tricky multi-column cases, where some of pushed-down
							 | 
						||
| 
								 | 
							
								# equalities are used for index lookups and some arent.
							 | 
						||
| 
								 | 
							
								create table t1 (oref char(4), grp int, ie1 int, ie2 int);
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp, ie1, ie2) values
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 2, 1),
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 1, 1),
							 | 
						||
| 
								 | 
							
								 ('aa', 20, 2, 1),
							 | 
						||
| 
								 | 
							
								 ('bb', 10, 3, 1),
							 | 
						||
| 
								 | 
							
								 ('cc', 10, 4, 2),
							 | 
						||
| 
								 | 
							
								 ('cc', 20, 3, 2),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ee', 10, 2, 1),
							 | 
						||
| 
								 | 
							
								 ('ee', 10, 1, 2),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 2, 2),
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 1, 2);
							 | 
						||
| 
								 | 
							
								create table t2 (oref char(4), a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  ('ee', NULL, 1),
							 | 
						||
| 
								 | 
							
								  ('bb', 2, 1),
							 | 
						||
| 
								 | 
							
								  ('ff', 2, 2),
							 | 
						||
| 
								 | 
							
								  ('cc', 3, NULL),
							 | 
						||
| 
								 | 
							
								  ('bb', NULL, NULL),
							 | 
						||
| 
								 | 
							
								  ('aa', 1, 1),
							 | 
						||
| 
								 | 
							
								  ('dd', 1, NULL);
							 | 
						||
| 
								 | 
							
								alter table t1 add index idx(ie1,ie2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# cc 3 NULL NULL
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=3 and b is null ;
							 | 
						||
| 
								 | 
							
								insert into t2 values ('new1', 10,10);
							 | 
						||
| 
								 | 
							
								insert into t1 values ('new1', 1234, 10, NULL); 
							 | 
						||
| 
								 | 
							
								# new1, 10, 10, NULL,
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10; 
							 | 
						||
| 
								 | 
							
								explain extended
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10; 
							 | 
						||
| 
								 | 
							
								drop table t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Now test different column types:
							 | 
						||
| 
								 | 
							
								create table t1 (oref char(4), grp int, ie int);
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp, ie) values
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 2),
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 1),
							 | 
						||
| 
								 | 
							
								 ('aa', 20, NULL),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('bb', 10, 3),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('cc', 10, 4),
							 | 
						||
| 
								 | 
							
								 ('cc', 20, NULL),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ee', 10, NULL),
							 | 
						||
| 
								 | 
							
								 ('ee', 10, NULL),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 2),
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (oref char(4), a int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  ('ee', NULL),
							 | 
						||
| 
								 | 
							
								  ('bb', 2),
							 | 
						||
| 
								 | 
							
								  ('ff', 2),
							 | 
						||
| 
								 | 
							
								  ('cc', 3),
							 | 
						||
| 
								 | 
							
								  ('aa', 1),
							 | 
						||
| 
								 | 
							
								  ('dd', NULL),
							 | 
						||
| 
								 | 
							
								  ('bb', NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select ie from t1 where oref=t2.oref); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where 
							 | 
						||
| 
								 | 
							
								  a in (select min(ie) from t1 where oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								  
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where 
							 | 
						||
| 
								 | 
							
								  a not in (select min(ie) from t1 where oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								update t1 set ie=3 where oref='ff' and ie=1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by
							 | 
						||
| 
								 | 
							
								grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select min(ie) from t1 where
							 | 
						||
| 
								 | 
							
								oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select min(ie) from t1 where
							 | 
						||
| 
								 | 
							
								oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by
							 | 
						||
| 
								 | 
							
								grp having min(ie) > 1) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select min(ie) from t1 where
							 | 
						||
| 
								 | 
							
								oref=t2.oref group by grp having min(ie) > 1);
							 | 
						||
| 
								 | 
							
								  
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select min(ie) from t1 where
							 | 
						||
| 
								 | 
							
								oref=t2.oref group by grp having min(ie) > 1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								alter table t1 add index idx(ie);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select ie from t1 where oref=t2.oref); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								alter table t1 drop index idx;
							 | 
						||
| 
								 | 
							
								alter table t1 add index idx(oref,ie);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select ie from t1 where oref=t2.oref); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain 
							 | 
						||
| 
								 | 
							
								select oref, a, 
							 | 
						||
| 
								 | 
							
								       a in (select min(ie) from t1 where oref=t2.oref 
							 | 
						||
| 
								 | 
							
								             group by grp having min(ie) > 1) Z 
							 | 
						||
| 
								 | 
							
								from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, 
							 | 
						||
| 
								 | 
							
								       a in (select min(ie) from t1 where oref=t2.oref 
							 | 
						||
| 
								 | 
							
								             group by grp having min(ie) > 1) Z 
							 | 
						||
| 
								 | 
							
								from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select min(ie) from t1 where oref=t2.oref 
							 | 
						||
| 
								 | 
							
								                                   group by grp having min(ie) > 1);
							 | 
						||
| 
								 | 
							
								  
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select min(ie) from t1 where oref=t2.oref 
							 | 
						||
| 
								 | 
							
								                                       group by grp having min(ie) > 1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t1 (oref char(4), grp int, ie1 int, ie2 int);
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp, ie1, ie2) values
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 2, 1),
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 1, 1),
							 | 
						||
| 
								 | 
							
								 ('aa', 20, 2, 1),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('bb', 10, 3, 1),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('cc', 10, 4, 2),
							 | 
						||
| 
								 | 
							
								 ('cc', 20, 3, 2),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ee', 10, 2, 1),
							 | 
						||
| 
								 | 
							
								 ('ee', 10, 1, 2),
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 2, 2),
							 | 
						||
| 
								 | 
							
								 ('ff', 20, 1, 2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (oref char(4), a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  ('ee', NULL, 1),
							 | 
						||
| 
								 | 
							
								  ('bb', 2, 1),
							 | 
						||
| 
								 | 
							
								  ('ff', 2, 2),
							 | 
						||
| 
								 | 
							
								  ('cc', 3, NULL),
							 | 
						||
| 
								 | 
							
								  ('bb', NULL, NULL),
							 | 
						||
| 
								 | 
							
								  ('aa', 1, 1),
							 | 
						||
| 
								 | 
							
								  ('dd', 1, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where (a,b) in (select ie1,ie2 from t1 where oref=t2.oref); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where (a,b) not in (select ie1,ie2 from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b, 
							 | 
						||
| 
								 | 
							
								             (a,b) in (select min(ie1),max(ie2) from t1 
							 | 
						||
| 
								 | 
							
								                       where oref=t2.oref group by grp) Z 
							 | 
						||
| 
								 | 
							
								from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where 
							 | 
						||
| 
								 | 
							
								  (a,b) in (select min(ie1), max(ie2) from t1 where oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								  
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where
							 | 
						||
| 
								 | 
							
								  (a,b) not in (select min(ie1), max(ie2) from t1 where oref=t2.oref group by grp);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								alter table t1 add index idx(ie1,ie2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where (a,b) in (select ie1,ie2 from t1 where oref=t2.oref); 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, b from t2 where (a,b) not in (select ie1,ie2 from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain extended 
							 | 
						||
| 
								 | 
							
								select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t1 (oref char(4), grp int, ie int primary key);
							 | 
						||
| 
								 | 
							
								insert into t1 (oref, grp, ie) values
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 2),
							 | 
						||
| 
								 | 
							
								 ('aa', 10, 1),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('bb', 10, 3),
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								 ('cc', 10, 4),
							 | 
						||
| 
								 | 
							
								 ('cc', 20, 5),
							 | 
						||
| 
								 | 
							
								 ('cc', 10, 6);
							 | 
						||
| 
								 | 
							
								 
							 | 
						||
| 
								 | 
							
								create table t2 (oref char(4), a int);
							 | 
						||
| 
								 | 
							
								insert into t2 values 
							 | 
						||
| 
								 | 
							
								  ('ee', NULL),
							 | 
						||
| 
								 | 
							
								  ('bb', 2),
							 | 
						||
| 
								 | 
							
								  ('cc', 5),
							 | 
						||
| 
								 | 
							
								  ('cc', 2),
							 | 
						||
| 
								 | 
							
								  ('cc', NULL),
							 | 
						||
| 
								 | 
							
								  ('aa', 1),
							 | 
						||
| 
								 | 
							
								  ('bb', NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								explain 
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# BUG#24420: row-based IN suqueries with aggregation when the left operand
							 | 
						||
| 
								 | 
							
								#            of the subquery predicate may contain NULL values
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t1 (a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t1 values (0,0), (2,2), (3,3);
							 | 
						||
| 
								 | 
							
								create table t2 (a int, b int);
							 | 
						||
| 
								 | 
							
								insert into t2 values (1,1), (3,3);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								select a, b, (a,b) in (select a, min(b) from t2 group by a) Z from t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								insert into t2 values (NULL,4);
							 | 
						||
| 
								 | 
							
								select a, b, (a,b) in (select a, min(b) from t2 group by a) Z from t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #24484: Aggregate function used in column list subquery gives erroneous 
							 | 
						||
| 
								 | 
							
								# error
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
							 | 
						||
| 
								 | 
							
								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');
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (a int, b INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 SELECT * FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Gives error, but should work since it is (a, b) is the PK so only one 
							 | 
						||
| 
								 | 
							
								# given match possible
							 | 
						||
| 
								 | 
							
								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;
							 | 
						||
| 
								 | 
							
								SELECT * FROM t1 GROUP by t1.a
							 | 
						||
| 
								 | 
							
								  HAVING (MAX(t1.b) > (SELECT MAX(t2.b) FROM t2 WHERE t2.c < t1.c
							 | 
						||
| 
								 | 
							
								                                                HAVING MAX(t2.b+t1.a) < 10));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT a,b,c FROM t1 WHERE b in (9,3,4) ORDER BY b,c;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT a, MAX(b),
							 | 
						||
| 
								 | 
							
								 (SELECT COUNT(DISTINCT t.c) FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) 
							 | 
						||
| 
								 | 
							
								  LIMIT 1) 
							 | 
						||
| 
								 | 
							
								  as cnt, 
							 | 
						||
| 
								 | 
							
								 (SELECT t.b FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1) 
							 | 
						||
| 
								 | 
							
								  as t_b,
							 | 
						||
| 
								 | 
							
								 (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1) 
							 | 
						||
| 
								 | 
							
								  as t_b,
							 | 
						||
| 
								 | 
							
								 (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) ORDER BY t.c LIMIT 1)
							 | 
						||
| 
								 | 
							
								  as t_b
							 | 
						||
| 
								 | 
							
								 FROM t1 GROUP BY a;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT a, MAX(b),
							 | 
						||
| 
								 | 
							
								 (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1) as test 
							 | 
						||
| 
								 | 
							
								 FROM t1 GROUP BY a;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #27870: crash of an equijoin query with WHERE condition containing 
							 | 
						||
| 
								 | 
							
								#             a subquery predicate of the form <join attr> NOT IN (SELECT ...)
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a int);
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (b int, PRIMARY KEY(b));
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1), (NULL), (4);
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								EXPLAIN EXTENDED 
							 | 
						||
| 
								 | 
							
								SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
							 | 
						||
| 
								 | 
							
								SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
							 | 
						||
| 
								 | 
							
								SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #28375: crash for NOT IN subquery predicate when left operand becomes NULL  
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (id int);
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (id int PRIMARY KEY);
							 | 
						||
| 
								 | 
							
								CREATE TABLE t3 (id int PRIMARY KEY, name varchar(10));
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (2), (NULL), (3), (1);
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES (234), (345), (457);
							 | 
						||
| 
								 | 
							
								INSERT INTO t3 VALUES (222,'bbb'), (333,'ccc'), (111,'aaa');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								EXPLAIN
							 | 
						||
| 
								 | 
							
								SELECT * FROM t1
							 | 
						||
| 
								 | 
							
								  WHERE t1.id NOT IN (SELECT t2.id FROM t2,t3 
							 | 
						||
| 
								 | 
							
								                        WHERE t3.name='xxx' AND t2.id=t3.id);
							 | 
						||
| 
								 | 
							
								SELECT * FROM t1
							 | 
						||
| 
								 | 
							
								  WHERE t1.id NOT IN (SELECT t2.id FROM t2,t3 
							 | 
						||
| 
								 | 
							
								                        WHERE t3.name='xxx' AND t2.id=t3.id);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT (t1.id IN (SELECT t2.id FROM t2,t3 
							 | 
						||
| 
								 | 
							
								                    WHERE t3.name='xxx' AND t2.id=t3.id)) AS x
							 | 
						||
| 
								 | 
							
								  FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1,t2,t3;   
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #22855: Optimizer doesn't rewrite NOT IN subselects to a correlated 
							 | 
						||
| 
								 | 
							
								# subquery 
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a INT NOT NULL);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1),(-1), (65),(66);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (a INT UNSIGNED NOT NULL PRIMARY KEY);
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES (65),(66);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT a FROM t1 WHERE a NOT IN (65,66);
							 | 
						||
| 
								 | 
							
								SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2);
							 | 
						||
| 
								 | 
							
								EXPLAIN SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #34763: item_subselect.cc:1235:Item_in_subselect::row_value_transformer:
							 | 
						||
| 
								 | 
							
								#             Assertion failed, unexpected error message:
							 | 
						||
| 
								 | 
							
								#             ERROR 1247 (42S22): Reference '<list ref>' not supported (forward
							 | 
						||
| 
								 | 
							
								#             reference in item list)
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a INT);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (placeholder CHAR(11));
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES("placeholder");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT ROW(1, 2) IN (SELECT t1.a, 2)         FROM t1 GROUP BY t1.a;
							 | 
						||
| 
								 | 
							
								SELECT ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) FROM t1 GROUP BY t1.a;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #36005: crash in subselect with single row
							 | 
						||
| 
								 | 
							
								#             (subselect_single_select_engine::exec)
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a INT);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1),(2),(3);
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 SELECT * FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT 1 FROM t1 WHERE t1.a NOT IN (SELECT 1 FROM t1, t2 WHERE 0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1, t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #37894: Assertion in init_read_record_seq in handler.h line 1444
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (
							 | 
						||
| 
								 | 
							
								  pk INT PRIMARY KEY,
							 | 
						||
| 
								 | 
							
								  int_key INT,
							 | 
						||
| 
								 | 
							
								  varchar_key VARCHAR(5) UNIQUE,
							 | 
						||
| 
								 | 
							
								  varchar_nokey VARCHAR(5)
							 | 
						||
| 
								 | 
							
								);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (9, 7,NULL,NULL), (10,8,'p' ,'p');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								SELECT varchar_nokey
							 | 
						||
| 
								 | 
							
								FROM t1
							 | 
						||
| 
								 | 
							
								WHERE NULL NOT IN (
							 | 
						||
| 
								 | 
							
								 SELECT INNR.pk FROM t1 AS INNR2
							 | 
						||
| 
								 | 
							
								   LEFT JOIN t1 AS INNR ON ( INNR2.int_key = INNR.int_key )
							 | 
						||
| 
								 | 
							
								   WHERE INNR.varchar_key > 'n{'
							 | 
						||
| 
								 | 
							
								);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #39069: <row constructor> IN <table-subquery> seriously messed up
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a INT);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1), (2), (11);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo # 2nd and 3rd columns should be same
							 | 
						||
| 
								 | 
							
								SELECT a, ROW(11, 12) = (SELECT a, 22), ROW(11, 12) IN (SELECT a, 22) FROM t1 GROUP BY t1.a;
							 | 
						||
| 
								 | 
							
								SELECT a, ROW(11, 12) = (SELECT a, 12), ROW(11, 12) IN (SELECT a, 12) FROM t1 GROUP BY t1.a;
							 | 
						||
| 
								 | 
							
								SELECT a, ROW(11, 12) = (SELECT a, 22), ROW(11, 12) IN (SELECT a, 22) FROM t1;
							 | 
						||
| 
								 | 
							
								SELECT a, ROW(11, 12) = (SELECT a, 12), ROW(11, 12) IN (SELECT a, 12) FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# The x alias is used below to workaround bug #40674.
							 | 
						||
| 
								 | 
							
								# Regression tests for sum function on outer column in subselect from dual:
							 | 
						||
| 
								 | 
							
								SELECT a AS x, ROW(11, 12) = (SELECT MAX(x), 22), ROW(11, 12) IN (SELECT MAX(x), 22) FROM t1;
							 | 
						||
| 
								 | 
							
								--echo # 2nd and 3rd columns should be same for x == 11 only
							 | 
						||
| 
								 | 
							
								SELECT a AS x, ROW(11, 12) = (SELECT MAX(x), 12), ROW(11, 12) IN (SELECT MAX(x), 12) FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo # both columns should be same
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT NULL, NULL), ROW(1,2) IN (SELECT NULL, NULL);
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT   1,  NULL), ROW(1,2) IN (SELECT    1, NULL);
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT NULL,    2), ROW(1,2) IN (SELECT NULL,    2);
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT NULL,    1), ROW(1,2) IN (SELECT NULL,    1);
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT    1,    1), ROW(1,2) IN (SELECT    1,    1);
							 | 
						||
| 
								 | 
							
								SELECT ROW(1,2) = (SELECT    1,    2), ROW(1,2) IN (SELECT    1,    2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# Bug #37362      Crash in do_field_eq
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (a INT, b INT, c INT);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1,1,1), (1,1,1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--error 1054
							 | 
						||
| 
								 | 
							
								EXPLAIN EXTENDED 
							 | 
						||
| 
								 | 
							
								  SELECT c FROM 
							 | 
						||
| 
								 | 
							
								    ( SELECT 
							 | 
						||
| 
								 | 
							
								      (SELECT COUNT(a) FROM 
							 | 
						||
| 
								 | 
							
								        (SELECT COUNT(b) FROM t1) AS x GROUP BY c
							 | 
						||
| 
								 | 
							
								      ) FROM t1 GROUP BY b
							 | 
						||
| 
								 | 
							
								    ) AS y;
							 | 
						||
| 
								 | 
							
								SHOW WARNINGS;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo End of 5.0 tests
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# BUG#36135 "void Diagnostics_area::set_eof_status(THD*): Assertion `!is_set()' failed."
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								create table t0 (a int);
							 | 
						||
| 
								 | 
							
								insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t1 (
							 | 
						||
| 
								 | 
							
								  a int(11) default null,
							 | 
						||
| 
								 | 
							
								  b int(11) default null,
							 | 
						||
| 
								 | 
							
								  key (a)
							 | 
						||
| 
								 | 
							
								);
							 | 
						||
| 
								 | 
							
								# produce numbers 0..999
							 | 
						||
| 
								 | 
							
								insert into t1 select A.a+10*(B.a+10*C.a),A.a+10*(B.a+10*C.a) from t0 A, t0 B, t0 C;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t2 (a int(11) default null);
							 | 
						||
| 
								 | 
							
								insert into t2 values (0),(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t3 (a int(11) default null);
							 | 
						||
| 
								 | 
							
								insert into t3 values (0),(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t4 (a int(11) default null);
							 | 
						||
| 
								 | 
							
								insert into t4 values (0),(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								create table t5 (a int(11) default null);
							 | 
						||
| 
								 | 
							
								insert into t5 values (0),(1),(0),(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# this must not fail assertion
							 | 
						||
| 
								 | 
							
								--error 1242
							 | 
						||
| 
								 | 
							
								select * from t2, t3 
							 | 
						||
| 
								 | 
							
								where
							 | 
						||
| 
								 | 
							
								    t2.a < 10 and
							 | 
						||
| 
								 | 
							
								    t3.a+1 = 2 and
							 | 
						||
| 
								 | 
							
								    t3.a in (select t1.b from t1
							 | 
						||
| 
								 | 
							
								                 where t1.a+1=t1.a+1 and
							 | 
						||
| 
								 | 
							
								                       t1.a < (select t4.a+10                                  
							 | 
						||
| 
								 | 
							
								                                  from t4, t5 limit 2));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								drop table t0, t1, t2, t3, t4, t5;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo # 
							 | 
						||
| 
								 | 
							
								--echo # BUG#48177 - SELECTs with NOT IN subqueries containing NULL 
							 | 
						||
| 
								 | 
							
								--echo #             values return too many records
							 | 
						||
| 
								 | 
							
								--echo # 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t1 (
							 | 
						||
| 
								 | 
							
								  i1 int DEFAULT NULL,
							 | 
						||
| 
								 | 
							
								  i2 int DEFAULT NULL
							 | 
						||
| 
								 | 
							
								) ;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (1,    NULL);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (2,    3);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (4,    NULL);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (4,    0);
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (NULL, NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								CREATE TABLE t2 (
							 | 
						||
| 
								 | 
							
								  i1 int DEFAULT NULL,
							 | 
						||
| 
								 | 
							
								  i2 int DEFAULT NULL
							 | 
						||
| 
								 | 
							
								) ;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES (4, NULL);
							 | 
						||
| 
								 | 
							
								INSERT INTO t2 VALUES (5, 0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								--echo Data in t1
							 | 
						||
| 
								 | 
							
								SELECT i1, i2 FROM t1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								--echo Data in subquery (should be filtered out)
							 | 
						||
| 
								 | 
							
								SELECT i1, i2 FROM t2 ORDER BY i1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								FLUSH STATUS;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								SELECT i1, i2
							 | 
						||
| 
								 | 
							
								FROM t1
							 | 
						||
| 
								 | 
							
								WHERE (i1, i2) 
							 | 
						||
| 
								 | 
							
								      NOT IN (SELECT i1, i2 FROM t2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								--echo # Check that the subquery only has to be evaluated once 
							 | 
						||
| 
								 | 
							
								--echo # for all-NULL values even though there are two (NULL,NULL) records
							 | 
						||
| 
								 | 
							
								--echo # Baseline:
							 | 
						||
| 
								 | 
							
								SHOW STATUS LIKE '%Handler_read_rnd_next';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								INSERT INTO t1 VALUES (NULL, NULL); 
							 | 
						||
| 
								 | 
							
								FLUSH STATUS;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								SELECT i1, i2
							 | 
						||
| 
								 | 
							
								FROM t1
							 | 
						||
| 
								 | 
							
								WHERE (i1, i2) 
							 | 
						||
| 
								 | 
							
								      NOT IN (SELECT i1, i2 FROM t2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo 
							 | 
						||
| 
								 | 
							
								--echo # Handler_read_rnd_next should be one more than baseline 
							 | 
						||
| 
								 | 
							
								--echo # (read record from t1, but do not read from t2)
							 | 
						||
| 
								 | 
							
								SHOW STATUS LIKE '%Handler_read_rnd_next';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								DROP TABLE t1,t2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								--echo End of 5.1 tests
							 |