Skip to content

Commit 6b99859

Browse files
committed
after-merge fix for a7ed464
(10.0+ changes, as specified in the MDEV) and remove unused variable (compiler warning)
1 parent 89dc445 commit 6b99859

8 files changed

+64
-25
lines changed

mysql-test/r/subselect.result

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,19 +7121,21 @@ INSERT INTO t1 VALUES (1),(2);
71217121
CREATE TABLE t2 (f2 INT, KEY(f2));
71227122
INSERT INTO t2 VALUES (3);
71237123
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7124+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7125+
ERROR 42000: Can't group on 'sq'
71247126
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7125-
sq
7126-
3
7127+
ERROR 42000: Can't group on 'sq'
71277128
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71287129
f2
71297130
3
71307131
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71317132
count(*)
71327133
1
71337134
delete from t1;
7135+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7136+
ERROR 42000: Can't group on 'sq'
71347137
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7135-
sq
7136-
NULL
7138+
ERROR 42000: Can't group on 'sq'
71377139
drop view v2;
71387140
drop table t1,t2;
71397141
#

mysql-test/r/subselect_no_exists_to_in.result

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,19 +7121,21 @@ INSERT INTO t1 VALUES (1),(2);
71217121
CREATE TABLE t2 (f2 INT, KEY(f2));
71227122
INSERT INTO t2 VALUES (3);
71237123
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7124+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7125+
ERROR 42000: Can't group on 'sq'
71247126
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7125-
sq
7126-
3
7127+
ERROR 42000: Can't group on 'sq'
71277128
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71287129
f2
71297130
3
71307131
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71317132
count(*)
71327133
1
71337134
delete from t1;
7135+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7136+
ERROR 42000: Can't group on 'sq'
71347137
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7135-
sq
7136-
NULL
7138+
ERROR 42000: Can't group on 'sq'
71377139
drop view v2;
71387140
drop table t1,t2;
71397141
#
@@ -7147,6 +7149,28 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 );
71477149
f1 f2
71487150
foo bar
71497151
DROP TABLE t1;
7152+
#
7153+
# MDEV-10146: Wrong result (or questionable result and behavior)
7154+
# with aggregate function in uncorrelated SELECT subquery
7155+
#
7156+
CREATE TABLE t1 (f1 INT);
7157+
CREATE VIEW v1 AS SELECT * FROM t1;
7158+
INSERT INTO t1 VALUES (1),(2);
7159+
CREATE TABLE t2 (f2 int);
7160+
INSERT INTO t2 VALUES (3);
7161+
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
7162+
( SELECT MAX(f1) FROM t2 )
7163+
2
7164+
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
7165+
( SELECT MAX(f1) FROM t2 )
7166+
2
7167+
INSERT INTO t2 VALUES (4);
7168+
SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1;
7169+
ERROR 21000: Subquery returns more than 1 row
7170+
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
7171+
ERROR 21000: Subquery returns more than 1 row
7172+
drop view v1;
7173+
drop table t1,t2;
71507174
set optimizer_switch=default;
71517175
select @@optimizer_switch like '%exists_to_in=off%';
71527176
@@optimizer_switch like '%exists_to_in=off%'

mysql-test/r/subselect_no_mat.result

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,19 +7114,21 @@ INSERT INTO t1 VALUES (1),(2);
71147114
CREATE TABLE t2 (f2 INT, KEY(f2));
71157115
INSERT INTO t2 VALUES (3);
71167116
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7117+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7118+
ERROR 42000: Can't group on 'sq'
71177119
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7118-
sq
7119-
3
7120+
ERROR 42000: Can't group on 'sq'
71207121
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71217122
f2
71227123
3
71237124
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71247125
count(*)
71257126
1
71267127
delete from t1;
7128+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7129+
ERROR 42000: Can't group on 'sq'
71277130
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7128-
sq
7129-
NULL
7131+
ERROR 42000: Can't group on 'sq'
71307132
drop view v2;
71317133
drop table t1,t2;
71327134
#

mysql-test/r/subselect_no_opts.result

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7112,19 +7112,21 @@ INSERT INTO t1 VALUES (1),(2);
71127112
CREATE TABLE t2 (f2 INT, KEY(f2));
71137113
INSERT INTO t2 VALUES (3);
71147114
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7115+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7116+
ERROR 42000: Can't group on 'sq'
71157117
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7116-
sq
7117-
3
7118+
ERROR 42000: Can't group on 'sq'
71187119
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71197120
f2
71207121
3
71217122
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71227123
count(*)
71237124
1
71247125
delete from t1;
7126+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7127+
ERROR 42000: Can't group on 'sq'
71257128
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7126-
sq
7127-
NULL
7129+
ERROR 42000: Can't group on 'sq'
71287130
drop view v2;
71297131
drop table t1,t2;
71307132
#

mysql-test/r/subselect_no_scache.result

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7127,19 +7127,21 @@ INSERT INTO t1 VALUES (1),(2);
71277127
CREATE TABLE t2 (f2 INT, KEY(f2));
71287128
INSERT INTO t2 VALUES (3);
71297129
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7130+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7131+
ERROR 42000: Can't group on 'sq'
71307132
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7131-
sq
7132-
3
7133+
ERROR 42000: Can't group on 'sq'
71337134
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71347135
f2
71357136
3
71367137
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71377138
count(*)
71387139
1
71397140
delete from t1;
7141+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7142+
ERROR 42000: Can't group on 'sq'
71407143
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7141-
sq
7142-
NULL
7144+
ERROR 42000: Can't group on 'sq'
71437145
drop view v2;
71447146
drop table t1,t2;
71457147
#

mysql-test/r/subselect_no_semijoin.result

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7112,19 +7112,21 @@ INSERT INTO t1 VALUES (1),(2);
71127112
CREATE TABLE t2 (f2 INT, KEY(f2));
71137113
INSERT INTO t2 VALUES (3);
71147114
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
7115+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7116+
ERROR 42000: Can't group on 'sq'
71157117
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7116-
sq
7117-
3
7118+
ERROR 42000: Can't group on 'sq'
71187119
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
71197120
f2
71207121
3
71217122
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
71227123
count(*)
71237124
1
71247125
delete from t1;
7126+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
7127+
ERROR 42000: Can't group on 'sq'
71257128
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
7126-
sq
7127-
NULL
7129+
ERROR 42000: Can't group on 'sq'
71287130
drop view v2;
71297131
drop table t1,t2;
71307132
#

mysql-test/t/subselect.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,11 +6002,17 @@ INSERT INTO t2 VALUES (3);
60026002

60036003
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
60046004

6005+
--error ER_WRONG_GROUP_FIELD
6006+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
6007+
--error ER_WRONG_GROUP_FIELD
60056008
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
60066009
SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
60076010
SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
60086011

60096012
delete from t1;
6013+
--error ER_WRONG_GROUP_FIELD
6014+
SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
6015+
--error ER_WRONG_GROUP_FIELD
60106016
SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
60116017

60126018
drop view v2;

sql/item.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4991,7 +4991,6 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
49914991
if (thd->lex->in_sum_func &&
49924992
thd->lex->in_sum_func->nest_level >= select->nest_level)
49934993
{
4994-
Item::Type ref_type= (*reference)->type();
49954994
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
49964995
select->nest_level);
49974996
}

0 commit comments

Comments
 (0)