mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
MDEV-10146: Wrong result (or questionable result and behavior) with aggregate function in uncorrelated SELECT subquery
When outer reference resolved in a VIEW it still should mark aggregate function resolving border.
This commit is contained in:
parent
23ac2dd2a4
commit
a7ed4644a6
7 changed files with 142 additions and 0 deletions
|
@ -7116,3 +7116,25 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
|||
f1 f2
|
||||
foo bar
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
# with aggregate function in uncorrelated SELECT subquery
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (f2 int);
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
INSERT INTO t2 VALUES (4);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
|
|
|
@ -7113,6 +7113,28 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
|||
f1 f2
|
||||
foo bar
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
# with aggregate function in uncorrelated SELECT subquery
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (f2 int);
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
INSERT INTO t2 VALUES (4);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%materialization=on%';
|
||||
@@optimizer_switch like '%materialization=on%'
|
||||
|
|
|
@ -7111,4 +7111,26 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
|||
f1 f2
|
||||
foo bar
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
# with aggregate function in uncorrelated SELECT subquery
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (f2 int);
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
INSERT INTO t2 VALUES (4);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
set @optimizer_switch_for_subselect_test=null;
|
||||
|
|
|
@ -7122,6 +7122,28 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
|||
f1 f2
|
||||
foo bar
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
# with aggregate function in uncorrelated SELECT subquery
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (f2 int);
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
INSERT INTO t2 VALUES (4);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%subquery_cache=on%';
|
||||
@@optimizer_switch like '%subquery_cache=on%'
|
||||
|
|
|
@ -7111,5 +7111,27 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
|||
f1 f2
|
||||
foo bar
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
# with aggregate function in uncorrelated SELECT subquery
|
||||
#
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (f2 int);
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
( SELECT MAX(f1) FROM t2 )
|
||||
2
|
||||
INSERT INTO t2 VALUES (4);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
set @optimizer_switch_for_subselect_test=null;
|
||||
set @join_cache_level_for_subselect_test=NULL;
|
||||
|
|
|
@ -5998,3 +5998,28 @@ INSERT INTO t1 VALUES ('foo','bar');
|
|||
SELECT * FROM t1 WHERE f2 >= SOME ( SELECT f1 FROM t1 );
|
||||
SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-10146: Wrong result (or questionable result and behavior)
|
||||
--echo # with aggregate function in uncorrelated SELECT subquery
|
||||
--echo #
|
||||
CREATE TABLE t1 (f1 INT);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
|
||||
CREATE TABLE t2 (f2 int);
|
||||
|
||||
INSERT INTO t2 VALUES (3);
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
|
||||
INSERT INTO t2 VALUES (4);
|
||||
|
||||
--error ER_SUBQUERY_NO_1_ROW
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
|
||||
--error ER_SUBQUERY_NO_1_ROW
|
||||
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
|
||||
|
||||
drop view v1;
|
||||
drop table t1,t2;
|
||||
|
|
|
@ -5045,6 +5045,13 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
|
|||
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
|
||||
(Item_ident*) (*reference) :
|
||||
0));
|
||||
if (thd->lex->in_sum_func &&
|
||||
thd->lex->in_sum_func->nest_level >= select->nest_level)
|
||||
{
|
||||
Item::Type ref_type= (*reference)->type();
|
||||
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
||||
select->nest_level);
|
||||
}
|
||||
/*
|
||||
A reference to a view field had been found and we
|
||||
substituted it instead of this Item (find_field_in_tables
|
||||
|
|
Loading…
Reference in a new issue