mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
Fixed bug mdev-5078.
For aggregated fields from views/derived tables the possible adjustment of thd->lex->in_sum_func->max_arg_level in the function Item_field::fix_fields must be done before we leave the function.
This commit is contained in:
parent
00816a964f
commit
ec226e553a
3 changed files with 42 additions and 5 deletions
|
@ -2205,6 +2205,24 @@ DROP VIEW v1;
|
|||
DROP TABLE t1,t2;
|
||||
set optimizer_switch=@save_optimizer_switch;
|
||||
#
|
||||
# mdev-5078: sum over a view/derived table
|
||||
#
|
||||
CREATE TABLE t1 (a int);
|
||||
INSERT INTO t1 (a) VALUES (1), (2);
|
||||
CREATE TABLE t2 (b int(11));
|
||||
INSERT INTO t2 (b) VALUES (1), (2);
|
||||
CREATE VIEW v AS SELECT b as c FROM t2;
|
||||
SELECT a, (SELECT SUM(a + c) FROM v) FROM t1;
|
||||
a (SELECT SUM(a + c) FROM v)
|
||||
1 5
|
||||
2 7
|
||||
SELECT a, (SELECT SUM(a + c) FROM (SELECT b as c FROM t2) AS v1) FROM t1;
|
||||
a (SELECT SUM(a + c) FROM (SELECT b as c FROM t2) AS v1)
|
||||
1 5
|
||||
2 7
|
||||
DROP VIEW v;
|
||||
DROP TABLE t1,t2;
|
||||
#
|
||||
# end of 5.3 tests
|
||||
#
|
||||
set optimizer_switch=@exit_optimizer_switch;
|
||||
|
|
|
@ -1545,6 +1545,25 @@ DROP TABLE t1,t2;
|
|||
set optimizer_switch=@save_optimizer_switch;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # mdev-5078: sum over a view/derived table
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a int);
|
||||
INSERT INTO t1 (a) VALUES (1), (2);
|
||||
|
||||
CREATE TABLE t2 (b int(11));
|
||||
INSERT INTO t2 (b) VALUES (1), (2);
|
||||
|
||||
CREATE VIEW v AS SELECT b as c FROM t2;
|
||||
|
||||
SELECT a, (SELECT SUM(a + c) FROM v) FROM t1;
|
||||
|
||||
SELECT a, (SELECT SUM(a + c) FROM (SELECT b as c FROM t2) AS v1) FROM t1;
|
||||
|
||||
DROP VIEW v;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # end of 5.3 tests
|
||||
--echo #
|
||||
|
|
10
sql/item.cc
10
sql/item.cc
|
@ -4746,6 +4746,11 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
|
|||
goto mark_non_agg_field;
|
||||
}
|
||||
|
||||
if (thd->lex->in_sum_func &&
|
||||
thd->lex->in_sum_func->nest_level ==
|
||||
thd->lex->current_select->nest_level)
|
||||
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
||||
thd->lex->current_select->nest_level);
|
||||
/*
|
||||
if it is not expression from merged VIEW we will set this field.
|
||||
|
||||
|
@ -4762,11 +4767,6 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
|
|||
return FALSE;
|
||||
|
||||
set_field(from_field);
|
||||
if (thd->lex->in_sum_func &&
|
||||
thd->lex->in_sum_func->nest_level ==
|
||||
thd->lex->current_select->nest_level)
|
||||
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
||||
thd->lex->current_select->nest_level);
|
||||
}
|
||||
else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue