Skip to content

Commit 50b0b17

Browse files
author
Tor Didriksen
committed
Bug #33030289 REGRESSION: ASSERTION `REC_SZ <= M_ELEMENT_SIZE' FAILED.
When sorting decimal values, the function make_sortkey_from_item() may return UINT_MAX as length of the generated key in case of evaluation failures. This could hit an assert in the prioriy queue code. Relax the assert() in Bounded_queue::push. Change-Id: Ia2aec6030db279269f2ca2a7b08ad892beb4acf3
1 parent 839a4cb commit 50b0b17

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

mysql-test/r/filesort.result

+13
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,16 @@ SELECT 'a' AS f1 FROM t1 WHERE a='8' GROUP BY f1 ORDER BY CONCAT(f1);
182182
f1
183183
a
184184
DROP TABLE t1;
185+
#
186+
# Bug #33030289 REGRESSION: ASSERTION `REC_SZ <= M_ELEMENT_SIZE' FAILED.
187+
#
188+
CREATE TABLE t(a DECIMAL(55,19) NOT NULL);
189+
INSERT INTO t VALUES(0),(1),(2),(3),(4),(5);
190+
SELECT
191+
(
192+
SELECT 1 FROM t
193+
ORDER BY ST_HAUSDORFFDISTANCE(a, ST_ASTEXT(1,'axis-order=lat-long')), a
194+
LIMIT 1
195+
);
196+
ERROR 22023: Invalid GIS data provided to function st_astext.
197+
DROP TABLE t;

mysql-test/t/filesort.test

+15
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,18 @@ CREATE TABLE t1 (a LONGTEXT);
174174
INSERT INTO t1 VALUES ('8');
175175
SELECT 'a' AS f1 FROM t1 WHERE a='8' GROUP BY f1 ORDER BY CONCAT(f1);
176176
DROP TABLE t1;
177+
178+
--echo #
179+
--echo # Bug #33030289 REGRESSION: ASSERTION `REC_SZ <= M_ELEMENT_SIZE' FAILED.
180+
--echo #
181+
182+
CREATE TABLE t(a DECIMAL(55,19) NOT NULL);
183+
INSERT INTO t VALUES(0),(1),(2),(3),(4),(5);
184+
--error ER_GIS_INVALID_DATA
185+
SELECT
186+
(
187+
SELECT 1 FROM t
188+
ORDER BY ST_HAUSDORFFDISTANCE(a, ST_ASTEXT(1,'axis-order=lat-long')), a
189+
LIMIT 1
190+
);
191+
DROP TABLE t;

sql/bounded_queue.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ class Bounded_queue {
117117
const Key_type &pq_top = m_queue.top();
118118
[[maybe_unused]] const uint rec_sz =
119119
m_sort_param->make_sortkey(pq_top, element_size, opaque);
120-
assert(rec_sz <= m_element_size);
120+
// UINT_MAX means error, but we do not want to add a dependency
121+
// on class THD here, as in current_thd->is_error().
122+
assert(rec_sz <= m_element_size || rec_sz == UINT_MAX);
121123
m_queue.update_top();
122124
} else {
123125
[[maybe_unused]] const uint rec_sz = m_sort_param->make_sortkey(
124126
m_sort_keys[m_queue.size()], element_size, opaque);
125-
assert(rec_sz <= m_element_size);
127+
// UINT_MAX means error, but we do not want to add a dependency
128+
// on class THD here, as in current_thd->is_error().
129+
assert(rec_sz <= m_element_size || rec_sz == UINT_MAX);
126130
m_queue.push(m_sort_keys[m_queue.size()]);
127131
}
128132
}

0 commit comments

Comments
 (0)