Commit 096ce53b authored by unknown's avatar unknown

Merge dfischer@bk-internal.mysql.com:/home/bk/mysql-4.1

into  pippilotta.erinye.com:/shared/home/df/mysql/build/mysql-4.1
parents 294926a7 7b119247
......@@ -158,3 +158,22 @@ EXPLAIN SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
DROP table t1;
CREATE TABLE t1 (a int PRIMARY KEY);
CREATE TABLE t2 (b int PRIMARY KEY, a int);
CREATE TABLE t3 (b int, flag int);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1,1), (2,1), (3,1);
INSERT INTO t3(b,flag) VALUES (2, 1);
SELECT t1.a
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
a
SELECT DISTINCT t1.a, MAX(t3.flag)
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
a MAX(t3.flag)
SELECT DISTINCT t1.a
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
a
DROP TABLE t1,t2,t3;
......@@ -151,4 +151,30 @@ EXPLAIN SELECT 0 AS x, a FROM t1 GROUP BY x,a HAVING x=1 AND a > 1;
DROP table t1;
#
# Bug #29911: HAVING clause depending on constant table and evaluated to false
#
CREATE TABLE t1 (a int PRIMARY KEY);
CREATE TABLE t2 (b int PRIMARY KEY, a int);
CREATE TABLE t3 (b int, flag int);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1,1), (2,1), (3,1);
INSERT INTO t3(b,flag) VALUES (2, 1);
SELECT t1.a
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
SELECT DISTINCT t1.a, MAX(t3.flag)
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
SELECT DISTINCT t1.a
FROM t1 INNER JOIN t2 ON t1.a=t2.a LEFT JOIN t3 ON t2.b=t3.b
GROUP BY t1.a, t2.b HAVING MAX(t3.flag)=0;
DROP TABLE t1,t2,t3;
# End of 4.1 tests
......@@ -1176,12 +1176,12 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
/* fields count may be wrong */
DBUG_ASSERT ((field - result) < fields);
cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7);
field->catalog = strdup_root(alloc,(char*) row->data[0]);
field->db = strdup_root(alloc,(char*) row->data[1]);
field->table = strdup_root(alloc,(char*) row->data[2]);
field->org_table= strdup_root(alloc,(char*) row->data[3]);
field->name = strdup_root(alloc,(char*) row->data[4]);
field->org_name = strdup_root(alloc,(char*) row->data[5]);
field->catalog= strmake_root(alloc,(char*) row->data[0], lengths[0]);
field->db= strmake_root(alloc,(char*) row->data[1], lengths[1]);
field->table= strmake_root(alloc,(char*) row->data[2], lengths[2]);
field->org_table= strmake_root(alloc,(char*) row->data[3], lengths[3]);
field->name= strmake_root(alloc,(char*) row->data[4], lengths[4]);
field->org_name= strmake_root(alloc,(char*) row->data[5], lengths[5]);
field->catalog_length= lengths[0];
field->db_length= lengths[1];
......@@ -1202,7 +1202,7 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
field->flags|= NUM_FLAG;
if (default_value && row->data[7])
{
field->def=strdup_root(alloc,(char*) row->data[7]);
field->def=strmake_root(alloc,(char*) row->data[7], lengths[7]);
field->def_length= lengths[7];
}
else
......
......@@ -8118,7 +8118,7 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having)
field_count++;
}
if (!field_count && !(join->select_options & OPTION_FOUND_ROWS))
if (!field_count && !(join->select_options & OPTION_FOUND_ROWS) && !having)
{ // only const items with no OPTION_FOUND_ROWS
join->unit->select_limit_cnt= 1; // Only send first row
DBUG_RETURN(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment