Skip to content

Commit 0361569

Browse files
author
Steinar H. Gunderson
committed
Bug #33067260: WL#14419: SIG11 IN MY_FILL_8BIT|STRINGS/CTYPE-SIMPLE.CC
Implicit grouping can make NULL rows in tables that are not marked to have NULL rows, which causes any filesort after it to potentially write corrupted data (we assume we don't have to write NULL row flags, but also assume we don't have to write any field data). ORDER BY is removed in this case, but we can still have sorts stemming from ordering clauses in window functions. The old join optimizer has special code for this case (const plans) and applies the window functions in a separate way, but the hypergraph optimizer still has the sort, and gets the crash. Fix by always counting the input to window functions as ordered when we have implicit grouping. We don't need the highest possible efficiency here, as these plans are generally not allowed by the SQL standard anyway. Change-Id: If23f3860bcd3b009388c9a7ed1182237995cf8b1
1 parent 1a2eacc commit 0361569

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

mysql-test/r/window_functions_bugs.result

+16
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,19 @@ FROM t1;
12301230
a SUM(1) OVER (ORDER BY b) SUM(1) OVER (ORDER BY b DESC)
12311231
1 1 1
12321232
DROP TABLE t1;
1233+
#
1234+
# Bug #33067260: WL#14419: SIG11 IN MY_FILL_8BIT|STRINGS/CTYPE-SIMPLE.CC
1235+
#
1236+
CREATE TABLE t1 (a INTEGER, b VARCHAR(255));
1237+
INSERT INTO t1 VALUES (1,'x');
1238+
INSERT INTO t1 VALUES (-3,'y');
1239+
CREATE TABLE t2 ( a INTEGER );
1240+
SET sql_mode='';
1241+
SELECT MIN(a) AS field1 FROM t1 WHERE b IN ( SELECT a FROM t2 ) ORDER BY LEAD(a, 5, 7) OVER (ORDER BY b);
1242+
field1
1243+
NULL
1244+
SELECT MIN(a), LEAD(a, 5, 7) OVER (ORDER BY b) AS field1 FROM t1 WHERE b IN ( SELECT a FROM t2 ) ORDER BY b;
1245+
MIN(a) field1
1246+
NULL 7
1247+
SET sql_mode=DEFAULT;
1248+
DROP TABLE t1, t2;

mysql-test/t/window_functions_bugs.test

+18
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,21 @@ SELECT
764764
FROM t1;
765765

766766
DROP TABLE t1;
767+
768+
--echo #
769+
--echo # Bug #33067260: WL#14419: SIG11 IN MY_FILL_8BIT|STRINGS/CTYPE-SIMPLE.CC
770+
--echo #
771+
772+
CREATE TABLE t1 (a INTEGER, b VARCHAR(255));
773+
INSERT INTO t1 VALUES (1,'x');
774+
INSERT INTO t1 VALUES (-3,'y');
775+
776+
CREATE TABLE t2 ( a INTEGER );
777+
778+
SET sql_mode='';
779+
780+
SELECT MIN(a) AS field1 FROM t1 WHERE b IN ( SELECT a FROM t2 ) ORDER BY LEAD(a, 5, 7) OVER (ORDER BY b);
781+
SELECT MIN(a), LEAD(a, 5, 7) OVER (ORDER BY b) AS field1 FROM t1 WHERE b IN ( SELECT a FROM t2 ) ORDER BY b;
782+
783+
SET sql_mode=DEFAULT;
784+
DROP TABLE t1, t2;

sql/filesort.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,10 @@ uint Sort_param::make_sortkey(Bounds_checked_array<uchar> dst,
15051505
if (addon_fields->using_packed_addons()) {
15061506
for (const Sort_addon_field &addonf : *addon_fields) {
15071507
Field *field = addonf.field;
1508-
if (field->table->has_null_row()) continue;
1508+
if (field->table->has_null_row()) {
1509+
assert(field->table->is_nullable());
1510+
continue;
1511+
}
15091512
if (addonf.null_bit && field->is_null()) {
15101513
nulls[addonf.null_offset] |= addonf.null_bit;
15111514
} else {

sql/join_optimizer/join_optimizer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3554,7 +3554,7 @@ static Prealloced_array<AccessPath *, 4> ApplyWindowFunctions(
35543554
for (size_t window_idx = 0; window_idx < join->m_windows.size();
35553555
++window_idx) {
35563556
Window *window = join->m_windows[window_idx];
3557-
if (window->m_ordering_idx == -1 ||
3557+
if (window->m_ordering_idx == -1 || join->implicit_grouping ||
35583558
orderings.DoesFollowOrder(root_path->ordering_state,
35593559
window->m_ordering_idx)) {
35603560
if (trace) {

sql/sql_select.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4188,7 +4188,7 @@ bool JOIN::make_tmp_tables_info() {
41884188

41894189
/*
41904190
If the plan is constant, we will not do window tmp table processing
4191-
cf. special code path in do_query_block.
4191+
cf. special code path for handling const plans.
41924192
*/
41934193
m_windowing_steps = m_windows.elements > 0 && !plan_is_const() &&
41944194
!implicit_grouping && !group_optimized_away;

0 commit comments

Comments
 (0)