Skip to content

Commit

Permalink
MDEV-30313 Sporadic assertion `cond_selectivity <= 1.0' failure in ge…
Browse files Browse the repository at this point in the history
…t_range_limit_read_cost

The bug was related to floating point rounding. Fixed the assert to take
that into account.
  • Loading branch information
montywi committed Feb 10, 2023
1 parent 5de734d commit 8d4bccf
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
49 changes: 49 additions & 0 deletions mysql-test/main/selectivity_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -2208,3 +2208,52 @@ set optimizer_use_condition_selectivity= @tmp_oucs;
set @@global.histogram_size=@save_histogram_size;
SET SESSION DEFAULT_STORAGE_ENGINE=DEFAULT;
SET GLOBAL innodb_stats_persistent=@save_stats_persistent;
#
# MDEV-30313 Sporadic assertion `cond_selectivity <= 1.0' failure in get_range_limit_read_cost
#
CREATE TABLE t (a CHAR(8), b INT, c TIMESTAMP, KEY(b,c)) ENGINE=InnoDB;
INSERT INTO t VALUES
('g',1,'1980-09-26'),('l',2,'1979-10-07'),('e',3,'1992-04-22'),
('v',9,'1975-09-21'),('w',3,'1973-10-06'),('y',8,'1986-10-28'),
('a',4,'2015-02-15'),('v',9,'1980-01-13'),('f',1,'1972-02-27'),
('z',7,'1981-05-25'),('z',8,'1980-06-14'),('c',9,'1985-01-24'),
('x',5,'1999-12-14'),('h',3,'1994-12-18'),('j',6,'1985-08-17'),
('b',6,'1989-08-02'),('h',6,'2024-07-06'),('h',4,'2024-02-10'),
('s',1,'1981-07-21'),('c',2,'1988-09-16'),('e',3,'1981-08-26'),
('a',2,'1986-05-23'),('l',0,'1997-12-19'),('b',5,'2018-05-01'),
('q',2,'1990-01-01'),('v',9,'1982-10-12'),('x',2,'2005-04-29'),
('f',8,'2005-08-20'),('d',3,'2002-01-24'),('b',9,'1982-02-04'),
('a',4,'1978-04-12'),('c',9,'1984-06-08'),('n',9,'1983-10-19'),
('l',1,'2023-01-05'),('f',2,'1988-11-18'),('a',9,'1977-11-11'),
('k',2,'1980-09-27'),('i',7,'1988-08-09'),('e',4,'1992-07-30'),
('l',5,'1980-01-01'),('h',5,'2011-12-24'),('d',6,'2035-03-28'),
('h',7,'1994-05-14'),('y',1,'1990-01-01'),('x',6,'1981-09-12'),
('x',9,'1980-01-01'),('s',9,'1995-11-09'),('i',4,'1980-01-01'),
('p',4,'1980-01-01'),('a',6,'2026-05-05'),('c',6,'1991-09-23'),
('l',8,'1980-01-01'),('n',4,'1999-09-15'),('b',1,'2011-07-23'),
('a',9,'1980-01-01'),('a',0,'1977-12-21'),('v',6,'1986-10-29'),
('r',0,'1997-03-27'),('a',9,'2000-05-05'),('x',1,'1990-01-01'),
('n',7,'1985-08-01'),('m',6,'1994-09-14'),('s',9,'2009-09-27'),
('r',8,'2028-10-30'),('e',6,'1982-08-31'),('x',0,'1989-12-21'),
('d',0,'1984-06-24'),('r',6,'1982-02-11'),('a',3,'1997-10-22'),
('s',9,'2007-08-29'),('a',3,'1990-01-01'),('o',1,'2015-02-10'),
('x',0,'1978-08-30'),('k',5,'1989-06-15'),('b',0,'1984-08-21'),
('v',0,'1990-01-01'),('a',9,'1993-06-23'),('n',5,'1979-11-10'),
('o',8,'2024-08-31'),('k',6,'1983-12-25'),('y',5,'2013-02-19'),
('a',9,'1989-12-03'),('k',4,'1973-08-07'),('o',7,'1988-03-19'),
('o',3,'2007-01-07'),('t',6,'1990-02-22'),('f',4,'2032-10-22'),
('p',0,'1977-09-12'),('f',3,'2036-11-26'),('a',9,'2008-06-26'),
('k',2,'2004-09-11'),('x',1,'2005-07-28'),('s',8,'2027-08-28'),
('a',8,'2000-06-11'),('a',7,'2005-05-20'),('u',9,'1980-01-01'),
('v',5,'1990-01-01'),('x',7,'1984-11-01'),('a',1,'2006-05-14');
SELECT b FROM t WHERE a > 'a' GROUP BY b HAVING b >= 6 OR b <= 0;
b
0
6
7
8
9
DROP TABLE t;
#
# End of 11.0 tests
#
49 changes: 49 additions & 0 deletions mysql-test/main/selectivity_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,52 @@ set optimizer_use_condition_selectivity= @tmp_oucs;
set @@global.histogram_size=@save_histogram_size;
SET SESSION DEFAULT_STORAGE_ENGINE=DEFAULT;
SET GLOBAL innodb_stats_persistent=@save_stats_persistent;

--echo #
--echo # MDEV-30313 Sporadic assertion `cond_selectivity <= 1.0' failure in get_range_limit_read_cost
--echo #

CREATE TABLE t (a CHAR(8), b INT, c TIMESTAMP, KEY(b,c)) ENGINE=InnoDB;
INSERT INTO t VALUES
('g',1,'1980-09-26'),('l',2,'1979-10-07'),('e',3,'1992-04-22'),
('v',9,'1975-09-21'),('w',3,'1973-10-06'),('y',8,'1986-10-28'),
('a',4,'2015-02-15'),('v',9,'1980-01-13'),('f',1,'1972-02-27'),
('z',7,'1981-05-25'),('z',8,'1980-06-14'),('c',9,'1985-01-24'),
('x',5,'1999-12-14'),('h',3,'1994-12-18'),('j',6,'1985-08-17'),
('b',6,'1989-08-02'),('h',6,'2024-07-06'),('h',4,'2024-02-10'),
('s',1,'1981-07-21'),('c',2,'1988-09-16'),('e',3,'1981-08-26'),
('a',2,'1986-05-23'),('l',0,'1997-12-19'),('b',5,'2018-05-01'),
('q',2,'1990-01-01'),('v',9,'1982-10-12'),('x',2,'2005-04-29'),
('f',8,'2005-08-20'),('d',3,'2002-01-24'),('b',9,'1982-02-04'),
('a',4,'1978-04-12'),('c',9,'1984-06-08'),('n',9,'1983-10-19'),
('l',1,'2023-01-05'),('f',2,'1988-11-18'),('a',9,'1977-11-11'),
('k',2,'1980-09-27'),('i',7,'1988-08-09'),('e',4,'1992-07-30'),
('l',5,'1980-01-01'),('h',5,'2011-12-24'),('d',6,'2035-03-28'),
('h',7,'1994-05-14'),('y',1,'1990-01-01'),('x',6,'1981-09-12'),
('x',9,'1980-01-01'),('s',9,'1995-11-09'),('i',4,'1980-01-01'),
('p',4,'1980-01-01'),('a',6,'2026-05-05'),('c',6,'1991-09-23'),
('l',8,'1980-01-01'),('n',4,'1999-09-15'),('b',1,'2011-07-23'),
('a',9,'1980-01-01'),('a',0,'1977-12-21'),('v',6,'1986-10-29'),
('r',0,'1997-03-27'),('a',9,'2000-05-05'),('x',1,'1990-01-01'),
('n',7,'1985-08-01'),('m',6,'1994-09-14'),('s',9,'2009-09-27'),
('r',8,'2028-10-30'),('e',6,'1982-08-31'),('x',0,'1989-12-21'),
('d',0,'1984-06-24'),('r',6,'1982-02-11'),('a',3,'1997-10-22'),
('s',9,'2007-08-29'),('a',3,'1990-01-01'),('o',1,'2015-02-10'),
('x',0,'1978-08-30'),('k',5,'1989-06-15'),('b',0,'1984-08-21'),
('v',0,'1990-01-01'),('a',9,'1993-06-23'),('n',5,'1979-11-10'),
('o',8,'2024-08-31'),('k',6,'1983-12-25'),('y',5,'2013-02-19'),
('a',9,'1989-12-03'),('k',4,'1973-08-07'),('o',7,'1988-03-19'),
('o',3,'2007-01-07'),('t',6,'1990-02-22'),('f',4,'2032-10-22'),
('p',0,'1977-09-12'),('f',3,'2036-11-26'),('a',9,'2008-06-26'),
('k',2,'2004-09-11'),('x',1,'2005-07-28'),('s',8,'2027-08-28'),
('a',8,'2000-06-11'),('a',7,'2005-05-20'),('u',9,'1980-01-01'),
('v',5,'1990-01-01'),('x',7,'1984-11-01'),('a',1,'2006-05-14');

SELECT b FROM t WHERE a > 'a' GROUP BY b HAVING b >= 6 OR b <= 0;

# Cleanup
DROP TABLE t;

--echo #
--echo # End of 11.0 tests
--echo #
3 changes: 2 additions & 1 deletion sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30382,7 +30382,8 @@ static bool get_range_limit_read_cost(const POSITION *pos,
*/
best_rows= pos->records_out; // Best rows with any key/keys
double cond_selectivity= best_rows / range_rows;
DBUG_ASSERT(cond_selectivity <= 1.0);
DBUG_ASSERT(cond_selectivity <= 1.000000001);
set_if_smaller(cond_selectivity, 1.0);

/*
We have to examine more rows in the proportion to the selectivity of the
Expand Down

0 comments on commit 8d4bccf

Please sign in to comment.