Skip to content

Commit 072b366

Browse files
committed
MDEV-28206: SIGSEGV in Item_field::fix_fields when using LEAD...OVER
thd->lex->in_sum_func->max_arg_level cannot be set to a bigger value of select->nest_level if select is null.
1 parent 4783f37 commit 072b366

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

mysql-test/main/win.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,3 +4352,27 @@ row_number() OVER (order by a)
43524352
2
43534353
3
43544354
drop table t1;
4355+
#
4356+
# MDEV-28206 SIGSEGV in Item_field::fix_fields when using LEAD...OVER
4357+
#
4358+
CREATE TABLE t(c1 INT);
4359+
CREATE FUNCTION f() RETURNS INT READS SQL DATA BEGIN
4360+
DECLARE v INT;
4361+
SELECT 1 INTO v FROM (SELECT c1,COALESCE(LEAD(a2.c1) OVER (PARTITION BY a2.c1 ORDER BY a2.c1),a2.c1) AS a1 FROM (t a2 JOIN t a3 USING (c1))) a4;
4362+
RETURN 1;
4363+
END//
4364+
SELECT f(),f();
4365+
f() f()
4366+
1 1
4367+
EXECUTE IMMEDIATE "SELECT LEAD(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
4368+
LEAD(c1) OVER (ORDER BY c1)
4369+
EXECUTE IMMEDIATE "SELECT SUM(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
4370+
SUM(c1) OVER (ORDER BY c1)
4371+
EXECUTE IMMEDIATE "SELECT LEAD(c) OVER (ORDER BY c) FROM (SELECT 1 AS c) AS a NATURAL JOIN (SELECT 1 AS c) AS b;";
4372+
LEAD(c) OVER (ORDER BY c)
4373+
NULL
4374+
DROP FUNCTION f;
4375+
DROP TABLE t;
4376+
#
4377+
# End of 10.6 tests
4378+
#

mysql-test/main/win.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,3 +2829,31 @@ create table t1 (a int);
28292829
insert into t1 values (1),(2),(3);
28302830
SELECT row_number() OVER (order by a) FROM t1 order by NAME_CONST('myname',NULL);
28312831
drop table t1;
2832+
2833+
--echo #
2834+
--echo # MDEV-28206 SIGSEGV in Item_field::fix_fields when using LEAD...OVER
2835+
--echo #
2836+
2837+
CREATE TABLE t(c1 INT);
2838+
2839+
DELIMITER //;
2840+
CREATE FUNCTION f() RETURNS INT READS SQL DATA BEGIN
2841+
DECLARE v INT;
2842+
SELECT 1 INTO v FROM (SELECT c1,COALESCE(LEAD(a2.c1) OVER (PARTITION BY a2.c1 ORDER BY a2.c1),a2.c1) AS a1 FROM (t a2 JOIN t a3 USING (c1))) a4;
2843+
RETURN 1;
2844+
END//
2845+
DELIMITER ;//
2846+
2847+
SELECT f(),f();
2848+
2849+
EXECUTE IMMEDIATE "SELECT LEAD(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
2850+
EXECUTE IMMEDIATE "SELECT SUM(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
2851+
2852+
EXECUTE IMMEDIATE "SELECT LEAD(c) OVER (ORDER BY c) FROM (SELECT 1 AS c) AS a NATURAL JOIN (SELECT 1 AS c) AS b;";
2853+
2854+
DROP FUNCTION f;
2855+
DROP TABLE t;
2856+
2857+
--echo #
2858+
--echo # End of 10.6 tests
2859+
--echo #

mysql-test/suite/encryption/r/tempfiles_encrypted.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,6 +4359,30 @@ row_number() OVER (order by a)
43594359
3
43604360
drop table t1;
43614361
#
4362+
# MDEV-28206 SIGSEGV in Item_field::fix_fields when using LEAD...OVER
4363+
#
4364+
CREATE TABLE t(c1 INT);
4365+
CREATE FUNCTION f() RETURNS INT READS SQL DATA BEGIN
4366+
DECLARE v INT;
4367+
SELECT 1 INTO v FROM (SELECT c1,COALESCE(LEAD(a2.c1) OVER (PARTITION BY a2.c1 ORDER BY a2.c1),a2.c1) AS a1 FROM (t a2 JOIN t a3 USING (c1))) a4;
4368+
RETURN 1;
4369+
END//
4370+
SELECT f(),f();
4371+
f() f()
4372+
1 1
4373+
EXECUTE IMMEDIATE "SELECT LEAD(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
4374+
LEAD(c1) OVER (ORDER BY c1)
4375+
EXECUTE IMMEDIATE "SELECT SUM(c1) OVER (ORDER BY c1) FROM t NATURAL JOIN t AS a;";
4376+
SUM(c1) OVER (ORDER BY c1)
4377+
EXECUTE IMMEDIATE "SELECT LEAD(c) OVER (ORDER BY c) FROM (SELECT 1 AS c) AS a NATURAL JOIN (SELECT 1 AS c) AS b;";
4378+
LEAD(c) OVER (ORDER BY c)
4379+
NULL
4380+
DROP FUNCTION f;
4381+
DROP TABLE t;
4382+
#
4383+
# End of 10.6 tests
4384+
#
4385+
#
43624386
# MDEV-23867: select crash in compute_window_func
43634387
#
43644388
set @save_sort_buffer_size=@@sort_buffer_size;

sql/item.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6114,6 +6114,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
61146114

61156115
if (!thd->lex->current_select->no_wrap_view_item &&
61166116
thd->lex->in_sum_func &&
6117+
select &&
61176118
thd->lex == select->parent_lex &&
61186119
thd->lex->in_sum_func->nest_level ==
61196120
select->nest_level)

0 commit comments

Comments
 (0)