Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
12.3.3
-
None
-
Linux x86_64, MariaDB.org Ubuntu 24.04 binary distribution
-
Not for Release Notes
Description
A forced index lookup on a BIT(8) column returns one row for the fractional DOUBLE value 1.6e0, while the equivalent table scan returns zero rows. The forced and scan access paths therefore disagree on the result of the same predicate.
Steps to reproduce
- Save the following as case.sql.
- Run mariadb < case.sql with an account that can create and drop a database.
CREATE DATABASE IF NOT EXISTS bit_test; |
USE bit_test; |
DROP TABLE IF EXISTS probes; |
CREATE TABLE probes ( |
id INT PRIMARY KEY, |
v_year YEAR, |
v_bit BIT(8), |
KEY k_year(v_year), |
KEY k_bit(v_bit) |
);
|
INSERT INTO probes VALUES (1,2000,b'00000001'); |
|
|
SELECT 'year_force' AS case_name, COUNT(*) AS matched |
FROM probes FORCE INDEX(k_year) |
WHERE v_year=2000.6e0; |
SELECT 'year_scan' AS case_name, COUNT(*) AS matched |
FROM probes IGNORE INDEX(k_year) |
WHERE v_year=2000.6e0; |
SELECT 'bit_force' AS case_name, COUNT(*) AS matched |
FROM probes FORCE INDEX(k_bit) |
WHERE v_bit=1.6e0; |
SELECT 'bit_scan' AS case_name, COUNT(*) AS matched |
FROM probes IGNORE INDEX(k_bit) |
WHERE v_bit=1.6e0; |
|
|
EXPLAIN SELECT id FROM probes FORCE INDEX(k_year) |
WHERE v_year=2000.6e0; |
EXPLAIN SELECT id FROM probes FORCE INDEX(k_bit) |
WHERE v_bit=1.6e0; |
|
|
DROP TABLE probes; |
DROP DATABASE bit_test; |
Actual result
year_force 1
|
year_scan 1
|
bit_force 1
|
bit_scan 0
|
The YEAR control agrees across both access paths. For BIT, however, the forced lookup returns one row and the scan returns none. The recorded EXPLAIN output reports ref access through k_bit with a constant key, confirming that the forced query used the BIT index.
Expected result
The forced-index and ignored-index queries evaluate the same v_bit=1.6e0 predicate and must return the same count. The scan establishes that the stored bit value 1 does not equal the fractional DOUBLE value 1.6, so bit_force should also return 0.
This occurs when an indexed BIT column is compared with a fractional DOUBLE value and the optimizer forms a forced index lookup.
Attachments
Issue Links
- duplicates
-
MDEV-29259 Comparison semantic of int = string changes with creation of an index
-
- Confirmed
-