Skip to content

Commit 3d2ae78

Browse files
DaveGosselin-MariaDBgrooverdan
authored andcommitted
MDEV-39494: UBSAN error on division by zero.
An incorrectly backported test from 11.x revealed an UBSAN error in 10.11, so fix that problem by preventing a division-by-zero from happening. Remove the other incorrectly backported tests and relabel the retained test in terms of the current ticket.
1 parent 8f434a1 commit 3d2ae78

3 files changed

Lines changed: 21 additions & 119 deletions

File tree

mysql-test/main/merge.result

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,73 +3968,18 @@ a
39683968
5
39693969
DROP TABLE t1;
39703970
#
3971-
# End of 10.11 tests
3972-
#
3973-
#
3974-
# MDEV-30088 Assertion `cond_selectivity <= 1.0' failed in get_range_limit_read_cost
3975-
#
3976-
CREATE TABLE t1 (a TIMESTAMP, KEY(a)) ENGINE=MRG_MyISAM;
3977-
explain SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
3978-
id select_type table type possible_keys key key_len ref rows Extra
3979-
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3980-
SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
3981-
a COUNT(*)
3982-
DROP TABLE t1;
3971+
# MDEV-39494 UBSAN failure
39833972
#
3984-
# MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::keyread_time
3973+
# This test was ported down from 11.x and was originally implemented under MDEV-30525.
3974+
# Under 10.11, this scenario results in a divide-by-zero failure because there are zero
3975+
# table records available.
39853976
#
39863977
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
39873978
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
39883979
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
39893980
SELECT DISTINCT a FROM tm WHERE a > 50;
39903981
a
39913982
DROP TABLE tm, t1, t2;
3992-
# Testcase 2:
3993-
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
3994-
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
3995-
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
3996-
ANALYZE TABLE tm PERSISTENT FOR ALL;
3997-
Table Op Msg_type Msg_text
3998-
test.tm analyze status Engine-independent statistics collected
3999-
test.tm analyze note The storage engine for the table doesn't support analyze
4000-
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
4001-
a
4002-
DROP TABLE tm, t1, t2;
4003-
#
4004-
# MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
4005-
#
4006-
CREATE TABLE t1 (f INT, KEY(f)) ENGINE=MyISAM;
4007-
CREATE TABLE t2 (f INT, KEY(f)) ENGINE=MyISAM;
4008-
CREATE TABLE tm (f INT, KEY(f)) ENGINE=MERGE UNION = (t1, t2);
4009-
SELECT DISTINCT f FROM tm WHERE f IN (47, 126, 97, 48, 73, 0);
4010-
f
4011-
DROP TABLE tm, t1, t2;
4012-
#
4013-
# MDEV-30786 SIGFPE in cost_group_min_max on EXP
4014-
#
4015-
SET use_stat_tables='preferably';
4016-
CREATE TABLE t1 (a INT,b INT,KEY i1 (a),KEY i2 (b)) ENGINE=MRG_MyISAM;
4017-
ANALYZE LOCAL TABLE t1;
4018-
Table Op Msg_type Msg_text
4019-
test.t1 analyze status Engine-independent statistics collected
4020-
test.t1 analyze note The storage engine for the table doesn't support analyze
4021-
EXPLAIN SELECT DISTINCT a FROM t1;
4022-
id select_type table type possible_keys key key_len ref rows Extra
4023-
1 SIMPLE t1 range NULL i1 5 NULL 1 Using index for group-by
4024-
drop table t1;
4025-
set use_stat_tables=default;
4026-
#
4027-
# End of 11.0 tests
4028-
#
4029-
#
4030-
# MDEV-29174: UPDATE of view that uses MERGE table
4031-
#
4032-
CREATE TABLE t1 (a int) ENGINE=MERGE;
4033-
CREATE VIEW v1 AS SELECT a FROM t1;
4034-
UPDATE v1 SET a=0;
4035-
DROP VIEW v1;
4036-
DROP TABLE t1;
4037-
# End of 11.1 tests
40383983
#
40393984
# MDEV-38474 Double free or corruption, ASAN heap-use-after-free in st_join_table::cleanup
40403985
#
@@ -4061,5 +4006,5 @@ UPDATE t1 STRAIGHT_JOIN t2 SET a = 89 WHERE 9 IN (SELECT c FROM t3 WHERE c IN (S
40614006
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
40624007
DROP TABLE t1, t2, t3, t4;
40634008
#
4064-
# End of 11.4 tests
4009+
# End of 10.11 tests
40654010
#

mysql-test/main/merge.test

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,69 +2903,19 @@ EXECUTE nested;
29032903
DROP TABLE t1;
29042904

29052905
--echo #
2906-
--echo # End of 10.11 tests
2907-
--echo #
2908-
2909-
--echo #
2910-
--echo # MDEV-30088 Assertion `cond_selectivity <= 1.0' failed in get_range_limit_read_cost
2911-
--echo #
2912-
2913-
CREATE TABLE t1 (a TIMESTAMP, KEY(a)) ENGINE=MRG_MyISAM;
2914-
explain SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
2915-
SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
2916-
DROP TABLE t1;
2917-
2906+
--echo # MDEV-39494 UBSAN failure
29182907
--echo #
2919-
--echo # MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::keyread_time
2908+
--echo # This test was ported down from 11.x and was originally implemented under MDEV-30525.
2909+
--echo # Under 10.11, this scenario results in a divide-by-zero failure because there are zero
2910+
--echo # table records available.
29202911
--echo #
29212912
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
29222913
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
29232914
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
2915+
# Must have zero records to produce UBSAN failure on divide-by-zero.
29242916
SELECT DISTINCT a FROM tm WHERE a > 50;
29252917
DROP TABLE tm, t1, t2;
29262918

2927-
--echo # Testcase 2:
2928-
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
2929-
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
2930-
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
2931-
ANALYZE TABLE tm PERSISTENT FOR ALL;
2932-
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
2933-
DROP TABLE tm, t1, t2;
2934-
2935-
--echo #
2936-
--echo # MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
2937-
--echo #
2938-
CREATE TABLE t1 (f INT, KEY(f)) ENGINE=MyISAM;
2939-
CREATE TABLE t2 (f INT, KEY(f)) ENGINE=MyISAM;
2940-
CREATE TABLE tm (f INT, KEY(f)) ENGINE=MERGE UNION = (t1, t2);
2941-
SELECT DISTINCT f FROM tm WHERE f IN (47, 126, 97, 48, 73, 0);
2942-
DROP TABLE tm, t1, t2;
2943-
2944-
--echo #
2945-
--echo # MDEV-30786 SIGFPE in cost_group_min_max on EXP
2946-
--echo #
2947-
SET use_stat_tables='preferably';
2948-
CREATE TABLE t1 (a INT,b INT,KEY i1 (a),KEY i2 (b)) ENGINE=MRG_MyISAM;
2949-
ANALYZE LOCAL TABLE t1;
2950-
EXPLAIN SELECT DISTINCT a FROM t1;
2951-
drop table t1;
2952-
set use_stat_tables=default;
2953-
2954-
--echo #
2955-
--echo # End of 11.0 tests
2956-
--echo #
2957-
--echo #
2958-
--echo # MDEV-29174: UPDATE of view that uses MERGE table
2959-
--echo #
2960-
2961-
CREATE TABLE t1 (a int) ENGINE=MERGE;
2962-
CREATE VIEW v1 AS SELECT a FROM t1;
2963-
UPDATE v1 SET a=0;
2964-
DROP VIEW v1;
2965-
DROP TABLE t1;
2966-
2967-
--echo # End of 11.1 tests
2968-
29692919
--echo #
29702920
--echo # MDEV-38474 Double free or corruption, ASAN heap-use-after-free in st_join_table::cleanup
29712921
--echo #
@@ -2997,6 +2947,5 @@ UPDATE t1 STRAIGHT_JOIN t2 SET a = 89 WHERE 9 IN (SELECT c FROM t3 WHERE c IN (S
29972947
DROP TABLE t1, t2, t3, t4;
29982948

29992949
--echo #
3000-
--echo # End of 11.4 tests
2950+
--echo # End of 10.11 tests
30012951
--echo #
3002-

sql/opt_range.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,8 +15071,16 @@ void cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
1507115071
keys_per_group= (table_records / 10) + 1;
1507215072
num_groups= (table_records / keys_per_group) + 1;
1507315073

15074-
/* Apply the selectivity of the quick select for group prefixes. */
15075-
if (range_tree && (quick_prefix_records != HA_POS_ERROR))
15074+
DBUG_ASSERT(keys_per_group > 0);
15075+
DBUG_ASSERT(num_groups > 0);
15076+
15077+
/*
15078+
Apply the selectivity of the quick select for group prefixes.
15079+
15080+
If there are no records in the table, then there's nothing to select so
15081+
let num_groups continue to be 1 as set above.
15082+
*/
15083+
if (range_tree && (quick_prefix_records != HA_POS_ERROR) && table_records > 0)
1507615084
{
1507715085
quick_prefix_selectivity= (double) quick_prefix_records /
1507815086
(double) table_records;

0 commit comments

Comments
 (0)