Skip to content

Commit fc68548

Browse files
author
Dag Wanvik
committed
Bug#33069747 ASSERTION `M_COUNT >= M_FRAME_NULL_COUNT && M_FRAME_NULL_COUNT > 0' FAILED
Missing call to split_sum func caused error when accessing rows from a window frame of a window function call only present in the ORDER BY list. This means that the argument of the window function was never put in the select list nor never replaced with an Item_aggregate_ref to it (in base_ref_items), cf. what happens if the window function is part of an expression in the select list. Change-Id: I287b701c48d0f96e57acba93b98f0312394a53c3
1 parent 5c00dff commit fc68548

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

mysql-test/r/window_functions_bugs.result

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,3 +1664,32 @@ a PERCENT_RANK() OVER (ORDER BY a)
16641664
NULL 0
16651665
02:00:00 1
16661666
DROP TABLE t1;
1667+
#
1668+
# Bug#33069747 ASSERTION `M_COUNT >= M_FRAME_NULL_COUNT && M_FRAME_NULL_COUNT > 0' FAILED
1669+
#
1670+
CREATE TABLE t1 ( a INTEGER, b INTEGER );
1671+
INSERT INTO t1 VALUES (0,NULL);
1672+
INSERT INTO t1 VALUES (NULL,1);
1673+
ANALYZE TABLE t1;
1674+
Table Op Msg_type Msg_text
1675+
test.t1 analyze status OK
1676+
SELECT 1 FROM t1
1677+
ORDER BY BIT_OR(a) OVER (ORDER BY b ROWS CURRENT ROW);
1678+
1
1679+
1
1680+
1
1681+
SELECT SUM(a) OVER w
1682+
FROM t1
1683+
WINDOW w AS (ORDER BY b ROWS CURRENT ROW)
1684+
ORDER BY SUM(b) OVER w;
1685+
SUM(a) OVER w
1686+
0
1687+
NULL
1688+
SELECT a, b, SUM(a) OVER w, SUM(b) OVER w
1689+
FROM t1
1690+
WINDOW w AS (ORDER BY b ROWS CURRENT ROW)
1691+
ORDER BY SUM(b) OVER w;
1692+
a b SUM(a) OVER w SUM(b) OVER w
1693+
0 NULL 0 NULL
1694+
NULL 1 NULL 1
1695+
DROP TABLE t1;

mysql-test/t/window_functions_bugs.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,3 +1127,28 @@ INSERT INTO t1 VALUES (NULL);
11271127
SELECT a, PERCENT_RANK() OVER (ORDER BY a) FROM t1;
11281128

11291129
DROP TABLE t1;
1130+
1131+
--echo #
1132+
--echo # Bug#33069747 ASSERTION `M_COUNT >= M_FRAME_NULL_COUNT && M_FRAME_NULL_COUNT > 0' FAILED
1133+
--echo #
1134+
1135+
CREATE TABLE t1 ( a INTEGER, b INTEGER );
1136+
1137+
INSERT INTO t1 VALUES (0,NULL);
1138+
INSERT INTO t1 VALUES (NULL,1);
1139+
ANALYZE TABLE t1;
1140+
1141+
SELECT 1 FROM t1
1142+
ORDER BY BIT_OR(a) OVER (ORDER BY b ROWS CURRENT ROW);
1143+
1144+
SELECT SUM(a) OVER w
1145+
FROM t1
1146+
WINDOW w AS (ORDER BY b ROWS CURRENT ROW)
1147+
ORDER BY SUM(b) OVER w;
1148+
1149+
SELECT a, b, SUM(a) OVER w, SUM(b) OVER w
1150+
FROM t1
1151+
WINDOW w AS (ORDER BY b ROWS CURRENT ROW)
1152+
ORDER BY SUM(b) OVER w;
1153+
1154+
DROP TABLE t1;

sql/sql_resolver.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4624,8 +4624,7 @@ bool Query_block::setup_order_final(THD *thd) {
46244624
(item->type() == Item::SUM_FUNC_ITEM && !item->m_is_window_function);
46254625
if (is_grouped_aggregate) continue;
46264626

4627-
if (item->has_aggregation() ||
4628-
(!item->m_is_window_function && item->has_wf())) {
4627+
if (item->has_aggregation() || item->has_wf()) {
46294628
item->split_sum_func(thd, base_ref_items, &fields);
46304629
if (thd->is_error()) return true; /* purecov: inspected */
46314630
}

0 commit comments

Comments
 (0)