Commit c7c8c33c authored by unknown's avatar unknown
Browse files

Merge macbook.gmz:/Users/kgeorge/mysql/work/B20792-4.1-opt

into  macbook.gmz:/Users/kgeorge/mysql/work/B20792-5.0-opt


mysql-test/r/subselect2.result:
  Auto merged
sql/sql_select.cc:
  Auto merged
parents 38091170 6b75e24b
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -132,3 +132,15 @@ id select_type table type possible_keys key key_len ref rows Extra
5	DEPENDENT SUBQUERY	t3	unique_subquery	PRIMARY,FFOLDERID_IDX	PRIMARY	34	func	1	Using index; Using where
6	DEPENDENT SUBQUERY	t3	unique_subquery	PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX	PRIMARY	34	func	1	Using index; Using where
drop table t1, t2, t3, t4;
CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t2 VALUES (1);
CREATE TABLE t3 (a int(10), b int(10), c int(10),
PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t3 VALUES (1,2,1);
SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a 
and t2.a='1' AND t1.a=t3.b) > 0;
a
2
DROP TABLE t1,t2,t3;
+18 −0
Original line number Diff line number Diff line
@@ -150,3 +150,21 @@ EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JO

drop table t1, t2, t3, t4;
# End of 4.1 tests

#
# Bug #20792: Incorrect results from aggregate subquery
#
CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t1 VALUES (1),(2);

CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t2 VALUES (1);

CREATE TABLE t3 (a int(10), b int(10), c int(10),
                PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t3 VALUES (1,2,1);

SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a 
                           and t2.a='1' AND t1.a=t3.b) > 0;

DROP TABLE t1,t2,t3;
+8 −2
Original line number Diff line number Diff line
@@ -6194,10 +6194,16 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables,
  DBUG_RETURN(0);
}


/*
  used only in JOIN::clear
*/
static void clear_tables(JOIN *join)
{
  for (uint i=0 ; i < join->tables ; i++)
  /* 
    must clear only the non-const tables, as const tables
    are not re-calculated.
  */
  for (uint i=join->const_tables ; i < join->tables ; i++)
    mark_as_null_row(join->table[i]);		// All fields are NULL
}