Description:
With the hypergraph optimizer and skip scans enabled, a covering composite index skip scan can return rows that do not satisfy a FLOAT equality predicate.
The table contains FLOAT values inserted as 0.1. Scalar evaluation shows that CAST(f AS DOUBLE) = 0.1e0 is false. A query that ignores the composite index therefore returns no rows, as expected.
However, when a skip scan is used for the later keypart f of index (a,f), EXPLAIN reports:
-> Sort: t1.id (cost=121..121 rows=4)
-> Covering index skip scan on t1 using i1 over f = 0.1 (cost=29.9..119 rows=4)
The query then incorrectly returns ids 1,3,5,7,9,11,13,15. The plan contains no residual filter for the original DOUBLE equality comparison.
How to repeat:
Run as root:
DROP DATABASE IF EXISTS db1;
CREATE DATABASE db1;
USE db1;
SET SESSION optimizer_switch='hypergraph_optimizer=on,skip_scan=on';
CREATE TABLE t1 (
id INT PRIMARY KEY,
a INT NOT NULL,
f FLOAT NOT NULL,
KEY i1 (a, f)
);
INSERT INTO t1 VALUES
(1,1,0.1),(2,2,0.5),(3,3,0.1),(4,4,0.5),
(5,5,0.1),(6,6,0.5),(7,7,0.1),(8,8,0.5),
(9,9,0.1),(10,10,0.5),(11,11,0.1),(12,12,0.5),
(13,13,0.1),(14,14,0.5),(15,15,0.1),(16,16,0.5);
ANALYZE TABLE t1;
SELECT id, f, (CAST(f AS DOUBLE) = 0.1e0) AS predicate_truth
FROM t1
WHERE id IN (1,2)
ORDER BY id;
-- Returns:
-- 1 0.1 0
-- 2 0.5 0
SELECT id, a, f
FROM t1 IGNORE INDEX (i1)
WHERE f = 0.1e0
ORDER BY id;
-- Empty set, as expected.
EXPLAIN FORMAT=TREE
SELECT /*+ SKIP_SCAN(t1 i1) */ id, a, f
FROM t1 FORCE INDEX (i1)
WHERE f = 0.1e0
ORDER BY id;
-- Shows a covering index skip scan on i1 over f = 0.1.
SELECT /*+ SKIP_SCAN(t1 i1) */ id, a, f
FROM t1 FORCE INDEX (i1)
WHERE f = 0.1e0
ORDER BY id;
-- Incorrectly returns:
-- 1 1 0.1
-- 3 3 0.1
-- 5 5 0.1
-- 7 7 0.1
-- 9 9 0.1
-- 11 11 0.1
-- 13 13 0.1
-- 15 15 0.1
Description: With the hypergraph optimizer and skip scans enabled, a covering composite index skip scan can return rows that do not satisfy a FLOAT equality predicate. The table contains FLOAT values inserted as 0.1. Scalar evaluation shows that CAST(f AS DOUBLE) = 0.1e0 is false. A query that ignores the composite index therefore returns no rows, as expected. However, when a skip scan is used for the later keypart f of index (a,f), EXPLAIN reports: -> Sort: t1.id (cost=121..121 rows=4) -> Covering index skip scan on t1 using i1 over f = 0.1 (cost=29.9..119 rows=4) The query then incorrectly returns ids 1,3,5,7,9,11,13,15. The plan contains no residual filter for the original DOUBLE equality comparison. How to repeat: Run as root: DROP DATABASE IF EXISTS db1; CREATE DATABASE db1; USE db1; SET SESSION optimizer_switch='hypergraph_optimizer=on,skip_scan=on'; CREATE TABLE t1 ( id INT PRIMARY KEY, a INT NOT NULL, f FLOAT NOT NULL, KEY i1 (a, f) ); INSERT INTO t1 VALUES (1,1,0.1),(2,2,0.5),(3,3,0.1),(4,4,0.5), (5,5,0.1),(6,6,0.5),(7,7,0.1),(8,8,0.5), (9,9,0.1),(10,10,0.5),(11,11,0.1),(12,12,0.5), (13,13,0.1),(14,14,0.5),(15,15,0.1),(16,16,0.5); ANALYZE TABLE t1; SELECT id, f, (CAST(f AS DOUBLE) = 0.1e0) AS predicate_truth FROM t1 WHERE id IN (1,2) ORDER BY id; -- Returns: -- 1 0.1 0 -- 2 0.5 0 SELECT id, a, f FROM t1 IGNORE INDEX (i1) WHERE f = 0.1e0 ORDER BY id; -- Empty set, as expected. EXPLAIN FORMAT=TREE SELECT /*+ SKIP_SCAN(t1 i1) */ id, a, f FROM t1 FORCE INDEX (i1) WHERE f = 0.1e0 ORDER BY id; -- Shows a covering index skip scan on i1 over f = 0.1. SELECT /*+ SKIP_SCAN(t1 i1) */ id, a, f FROM t1 FORCE INDEX (i1) WHERE f = 0.1e0 ORDER BY id; -- Incorrectly returns: -- 1 1 0.1 -- 3 3 0.1 -- 5 5 0.1 -- 7 7 0.1 -- 9 9 0.1 -- 11 11 0.1 -- 13 13 0.1 -- 15 15 0.1