Commit f6f93eef authored by MySQL Build Team's avatar MySQL Build Team

Backport into build-201003230706-5.1.43sp1

> ------------------------------------------------------------
> revno: 3333.1.31
> revision-id: joro@sun.com-20091223104518-o29t0i3thgs7wgm1
> parent: sergey.glukhov@sun.com-20100205093946-bx1hsljxlm12h7uf
> committer: Georgi Kodinov <joro@sun.com>
> branch nick: B39022-5.1-bugteam
> timestamp: Wed 2009-12-23 12:45:18 +0200
> message:
>   Bug #39022: Mysql randomly crashing in lock_sec_rec_cons_read_sees
>   
>   flush_cached_records() was not correctly checking for errors after calling
>   Item::val_xxx() methods. The expressions may contain subqueries
>   or stored procedures that cause errors that should stop the statement.
>   Fixed by correctly checking for errors and propagating them up the call stack.

> ------------------------------------------------------------
> revno: 3358
> revision-id: sergey.glukhov@sun.com-20100226113925-mxwn1hfxe3l8khc4
> parent: gshchepa@mysql.com-20100225191311-1x71dkk0h5e1alvx
> committer: Sergey Glukhov <Sergey.Glukhov@sun.com>
> branch nick: mysql-5.1-bugteam
> timestamp: Fri 2010-02-26 15:39:25 +0400
> message:
>   Bug#50995 Having clause on subquery result produces incorrect results.
>   The problem is that cond->fix_fields(thd, 0) breaks
>   condition(cuts off 'having'). The reason of that is
>   that NULL valued Item pointer is present in the
>   middle of Item list and it breaks the Item processing
>   loop.
parent 5aa2394a
......@@ -430,4 +430,24 @@ SELECT b, COUNT(DISTINCT a) FROM t1 GROUP BY b HAVING b is NULL;
b COUNT(DISTINCT a)
NULL 1
DROP TABLE t1;
#
# Bug#50995 Having clause on subquery result produces incorrect results.
#
CREATE TABLE t1
(
id1 INT,
id2 INT NOT NULL,
INDEX id1(id2)
);
INSERT INTO t1 SET id1=1, id2=1;
INSERT INTO t1 SET id1=2, id2=1;
INSERT INTO t1 SET id1=3, id2=1;
SELECT t1.id1,
(SELECT 0 FROM DUAL
WHERE t1.id1=t1.id1) AS amount FROM t1
WHERE t1.id2 = 1
HAVING amount > 0
ORDER BY t1.id1;
id1 amount
DROP TABLE t1;
End of 5.0 tests
......@@ -442,4 +442,30 @@ INSERT INTO t1 VALUES (1, 1), (2,2), (3, NULL);
SELECT b, COUNT(DISTINCT a) FROM t1 GROUP BY b HAVING b is NULL;
DROP TABLE t1;
--echo #
--echo # Bug#50995 Having clause on subquery result produces incorrect results.
--echo #
CREATE TABLE t1
(
id1 INT,
id2 INT NOT NULL,
INDEX id1(id2)
);
INSERT INTO t1 SET id1=1, id2=1;
INSERT INTO t1 SET id1=2, id2=1;
INSERT INTO t1 SET id1=3, id2=1;
SELECT t1.id1,
(SELECT 0 FROM DUAL
WHERE t1.id1=t1.id1) AS amount FROM t1
WHERE t1.id2 = 1
HAVING amount > 0
ORDER BY t1.id1;
DROP TABLE t1;
--echo End of 5.0 tests
......@@ -1474,9 +1474,21 @@ public:
Item_cond(THD *thd, Item_cond *item);
Item_cond(List<Item> &nlist)
:Item_bool_func(), list(nlist), abort_on_null(0) {}
bool add(Item *item) { return list.push_back(item); }
bool add_at_head(Item *item) { return list.push_front(item); }
void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
bool add(Item *item)
{
DBUG_ASSERT(item);
return list.push_back(item);
}
bool add_at_head(Item *item)
{
DBUG_ASSERT(item);
return list.push_front(item);
}
void add_at_head(List<Item> *nlist)
{
DBUG_ASSERT(nlist->elements);
list.prepand(nlist);
}
bool fix_fields(THD *, Item **ref);
enum Type type() const { return COND_ITEM; }
......
......@@ -8176,7 +8176,8 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *upper_levels,
else
{
DBUG_ASSERT(cond->type() == Item::COND_ITEM);
((Item_cond *) cond)->add_at_head(&eq_list);
if (eq_list.elements)
((Item_cond *) cond)->add_at_head(&eq_list);
}
cond->quick_fix_field();
......@@ -15613,7 +15614,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
Item_cond_and *cond=new Item_cond_and();
TABLE *table=join_tab->table;
int error;
int error= 0;
if (!cond)
DBUG_RETURN(TRUE);
......@@ -15631,7 +15632,8 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
cond->fix_fields(thd, (Item**)&cond);
if (join_tab->select)
{
error=(int) cond->add(join_tab->select->cond);
if (join_tab->select->cond)
error=(int) cond->add(join_tab->select->cond);
join_tab->select_cond=join_tab->select->cond=cond;
}
else if ((join_tab->select= make_select(join_tab->table, 0, 0, cond, 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