Skip to content

Commit 8bbda2c

Browse files
author
Steinar H. Gunderson
committed
Bug #32617876: SIG11 IN SORT_PARAM::MAKE_SORTKEY|SQL/FILESORT.CC WITH HYPERGRAPH
If we have a sort by row ID, and we try to store a row from an uninitialized temporary table (this can only happen if it is never read, and below an outer join -- so we store a NULL-complemented row), don't actually try to read the nonexistent row ID. Change-Id: I75370600d64615a92753b410b63ab7447ba62501
1 parent a2e1e32 commit 8bbda2c

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

mysql-test/r/filesort.result

+24
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,27 @@ SELECT 1 AS a FROM t1 LEFT JOIN t2 ON FALSE GROUP BY a;
149149
a
150150
1
151151
DROP TABLE t1, t2;
152+
#
153+
# Bug #32617876: SIG11 IN SORT_PARAM::MAKE_SORTKEY|SQL/FILESORT.CC WITH HYPERGRAPH
154+
#
155+
CREATE TABLE t1 (
156+
a LONGBLOB,
157+
b INTEGER,
158+
c INTEGER
159+
);
160+
INSERT INTO t1 VALUES (NULL,1,3);
161+
INSERT INTO t1 VALUES (NULL,1,NULL);
162+
ANALYZE TABLE t1;
163+
Table Op Msg_type Msg_text
164+
test.t1 analyze status OK
165+
SELECT *
166+
FROM t1
167+
LEFT JOIN (
168+
t1 AS t2 JOIN t1 AS t3 ON t2.c = t3.b
169+
JOIN ( SELECT DISTINCT b FROM t1 ) AS d1
170+
) ON TRUE
171+
ORDER BY t1.c;
172+
a b c a b c a b c b
173+
NULL 1 NULL NULL NULL NULL NULL NULL NULL NULL
174+
NULL 1 3 NULL NULL NULL NULL NULL NULL NULL
175+
DROP TABLE t1;

mysql-test/t/filesort.test

+27
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,30 @@ INSERT INTO t1 VALUES ('a');
137137
CREATE TABLE t2 (a INTEGER PRIMARY KEY) PARTITION BY key() PARTITIONS 2;
138138
SELECT 1 AS a FROM t1 LEFT JOIN t2 ON FALSE GROUP BY a;
139139
DROP TABLE t1, t2;
140+
141+
--echo #
142+
--echo # Bug #32617876: SIG11 IN SORT_PARAM::MAKE_SORTKEY|SQL/FILESORT.CC WITH HYPERGRAPH
143+
--echo #
144+
145+
CREATE TABLE t1 (
146+
a LONGBLOB,
147+
b INTEGER,
148+
c INTEGER
149+
);
150+
151+
INSERT INTO t1 VALUES (NULL,1,3);
152+
INSERT INTO t1 VALUES (NULL,1,NULL);
153+
ANALYZE TABLE t1;
154+
155+
# Set up a sort by row ID, where a temporary table (belonging to the
156+
# nonmergable derived table) has a NULL-complemented row, but never gets
157+
# properly initialized, and thus does not actually have a row ID.
158+
SELECT *
159+
FROM t1
160+
LEFT JOIN (
161+
t1 AS t2 JOIN t1 AS t3 ON t2.c = t3.b
162+
JOIN ( SELECT DISTINCT b FROM t1 ) AS d1
163+
) ON TRUE
164+
ORDER BY t1.c;
165+
166+
DROP TABLE t1;

sql/filesort.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,13 @@ uint Sort_param::make_sortkey(Bounds_checked_array<uchar> dst,
15441544
if (table->is_nullable()) {
15451545
*to++ = table->has_null_row();
15461546
}
1547-
memcpy(to, table->file->ref, table->file->ref_length);
1547+
if (table->is_nullable() && table->has_null_row()) {
1548+
// The contents are not used, but it's nice to have them
1549+
// defined when writing them to disk nevertheless.
1550+
memset(to, 0, table->file->ref_length);
1551+
} else {
1552+
memcpy(to, table->file->ref, table->file->ref_length);
1553+
}
15481554
to += table->file->ref_length;
15491555
}
15501556
}

0 commit comments

Comments
 (0)