1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-30706 Different results of selects from view and CTE with same definition

MDEV-30668 Set function aggregated in outer select used in view definition

This patch fixes two bugs concerning views whose specifications contain
subqueries with set functions aggregated in outer selects.
Due to the first bug those such views that have implicit grouping were
considered as mergeable. This led to wrong result sets for selects from
these views.
Due to the second bug the aggregation select was determined incorrectly and
this led to bogus error messages.
The patch added several test cases for these two bugs and for four other
duplicate bugs.
The patch also enables view-protocol for many other test cases.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
Igor Babaev
2023-03-01 22:49:27 -08:00
parent a6a906d766
commit ccec9b1de9
23 changed files with 2021 additions and 722 deletions

View File

@ -774,11 +774,9 @@ SELECT 1 FROM t1 as t1_outer GROUP BY a
SELECT (SELECT SUM(t1_inner.a) FROM t1 AS t1_inner LIMIT 1)
FROM t1 AS t1_outer GROUP BY t1_outer.b;
#enable after fix MDEV-27871
--disable_view_protocol
SELECT (SELECT SUM(t1_inner.a) FROM t1 AS t1_inner GROUP BY t1_inner.b LIMIT 1)
AS m
FROM t1 AS t1_outer;
--enable_view_protocol
--error ER_WRONG_FIELD_WITH_GROUP
SELECT (SELECT SUM(t1_outer.a) FROM t1 AS t1_inner LIMIT 1)
@ -854,6 +852,7 @@ DROP TABLE t1;
--echo #
--echo # Bug#27219: Aggregate functions in ORDER BY.
--echo #
SET @save_sql_mode=@@sql_mode;
SET @@sql_mode='ONLY_FULL_GROUP_BY';
@ -875,6 +874,8 @@ SELECT 1 FROM t1 ORDER BY SUM(a) + 1;
--error 1140
SELECT 1 FROM t1 ORDER BY SUM(a), b;
--disable_service_connection
--error 1140
SELECT a FROM t1 ORDER BY COUNT(b);
@ -887,9 +888,6 @@ SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2 ORDER BY t2.a);
--error 1140
SELECT t1.a FROM t1 ORDER BY (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1);
#enable after fix MDEV-28570
--disable_view_protocol
--error 1140
SELECT t1.a FROM t1
WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1);
@ -927,7 +925,7 @@ SELECT 1 FROM t1 GROUP BY t1.a
SELECT 1 FROM t1 GROUP BY t1.a
HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY t2.a LIMIT 1);
--enable_view_protocol
--enable_service_connection
# Both SUMs are aggregated in the subquery, no mixture:
SELECT t1.a FROM t1
@ -952,18 +950,17 @@ SELECT t1.a, SUM(t1.b) FROM t1
ORDER BY SUM(t2.b + t1.a) LIMIT 1)
GROUP BY t1.a;
#enable after fix MDEV-28570, MDEV-28571
--disable_view_protocol
SELECT t1.a FROM t1 GROUP BY t1.a
HAVING (1, 1) = (SELECT SUM(t1.a), t1.a FROM t2 LIMIT 1);
select avg (
(select
(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt
from t1 as outr order by outr.a limit 1))
from t1 as outr order by outr.a limit 1)) as m
from t1 as most_outer;
--disable_service_connection
--error 1140
select avg (
(select (
@ -971,7 +968,7 @@ select avg (
from t1 as outr order by count(outr.a) limit 1)) as tt
from t1 as most_outer;
--enable_view_protocol
--enable_service_connection
select (select sum(outr.a + t1.a) from t1 limit 1) as tt from t1 as outr order by outr.a;
@ -1369,7 +1366,7 @@ DROP TABLE t1;
--echo # Bug#11765254 (58200): Assertion failed: param.sort_length when grouping
--echo # by functions
--echo #
#createing view adds one new warning
#creating view adds one new warning
--disable_view_protocol
SET BIG_TABLES=1;