mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge remote-tracking branch 'origin/11.2' into 11.4
This commit is contained in:
@@ -4520,6 +4520,180 @@ row_number() OVER (order by a)
|
||||
3
|
||||
drop table t1;
|
||||
#
|
||||
# MDEV-29307: join of 2 derived tables over the same grouping view such
|
||||
# that the first of the joined tables contains a window
|
||||
# function and the view's specification contains a subquery
|
||||
# with a set function aggregated on the top level
|
||||
#
|
||||
CREATE TABLE t1 (
|
||||
tst int NOT NULL,
|
||||
flat tinyint unsigned NOT NULL,
|
||||
type tinyint unsigned NOT NULL,
|
||||
val int NOT NULL,
|
||||
PRIMARY KEY (tst,flat,type)
|
||||
) ENGINE=ARIA;
|
||||
INSERT INTO t1 VALUES
|
||||
(5, 20, 2, 100),
|
||||
(7, 20, 2, 150),
|
||||
(9, 20, 1, 200);
|
||||
CREATE VIEW v1 AS (
|
||||
SELECT
|
||||
flat,
|
||||
type,
|
||||
( SELECT val FROM t1 sw
|
||||
WHERE sw.tst = MAX(w.tst) AND sw.flat = w.flat AND sw.type = w.type)
|
||||
AS total
|
||||
FROM t1 w
|
||||
GROUP BY flat, type
|
||||
);
|
||||
EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 2
|
||||
) AS w2
|
||||
ON w1.flat = w2.flat;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||
1 PRIMARY <derived6> ref key0 key0 1 v1.flat 1 100.00 Using where
|
||||
6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort
|
||||
7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort
|
||||
5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`v1`.`total` AS `w1_total` from `test`.`v1` join `test`.`v1` where `v1`.`flat` = `v1`.`flat` and `v1`.`type` = 2 and `v1`.`type` = 1
|
||||
SELECT w2.total AS w2_total, w1.total AS w1_total
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 2
|
||||
) AS w2
|
||||
ON w1.flat = w2.flat;
|
||||
w2_total w1_total
|
||||
150 200
|
||||
EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total,
|
||||
COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u
|
||||
FROM v1
|
||||
WHERE type = 1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 2
|
||||
) AS w2
|
||||
ON w1.flat = w2.flat;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||
1 PRIMARY <derived6> ref key0 key0 1 w1.flat 1 100.00 Using where
|
||||
6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort
|
||||
7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
2 DERIVED <derived4> ALL NULL NULL NULL NULL 3 100.00 Using where; Using temporary
|
||||
4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort
|
||||
5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`type` order by `v1`.`type`) AS `u` from `test`.`v1` where `v1`.`type` = 1) `w1` join `test`.`v1` where `v1`.`flat` = `w1`.`flat` and `v1`.`type` = 2
|
||||
SELECT w2.total AS w2_total, w1.total AS w1_total
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total,
|
||||
COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u
|
||||
FROM v1
|
||||
WHERE type = 1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
WHERE type = 2
|
||||
) AS w2
|
||||
ON w1.flat = w2.flat;
|
||||
w2_total w1_total
|
||||
150 200
|
||||
EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total, u
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total,
|
||||
COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u
|
||||
FROM v1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
) AS w2;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
|
||||
1 PRIMARY <derived6> ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
|
||||
6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort
|
||||
7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
2 DERIVED <derived4> ALL NULL NULL NULL NULL 3 100.00 Using temporary
|
||||
4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort
|
||||
5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4
|
||||
Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6
|
||||
Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6
|
||||
Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total`,`w1`.`u` AS `u` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`flat` order by `v1`.`flat`) AS `u` from `test`.`v1`) `w1` join `test`.`v1`
|
||||
SELECT w2.total AS w2_total, w1.total AS w1_total, u
|
||||
FROM
|
||||
(
|
||||
SELECT flat, type, total,
|
||||
COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u
|
||||
FROM v1
|
||||
) AS w1
|
||||
JOIN
|
||||
(
|
||||
SELECT flat, type, total
|
||||
FROM v1
|
||||
) AS w2;
|
||||
w2_total w1_total u
|
||||
150 150 2
|
||||
150 200 2
|
||||
200 150 2
|
||||
200 200 2
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
# End of 10.5 tests
|
||||
#
|
||||
# MDEV-28206 SIGSEGV in Item_field::fix_fields when using LEAD...OVER
|
||||
#
|
||||
CREATE TABLE t(c1 INT);
|
||||
|
Reference in New Issue
Block a user