Details
Description
Likely cause: MDEV-21195, commit b0fa30808622fe12d474a70af1838906e60b9897, in CS 10.3.23. Its fix made INSERT put a DECIMAL value in the partition of the value rounded down. Partition pruning still rounds the value to the nearest integer, as INSERT did before that fix.
--source include/have_partition.inc
|
CREATE TABLE t1 (c DECIMAL(10,2)) PARTITION BY RANGE (c) (PARTITION p0 VALUES LESS THAN (10), PARTITION p1 VALUES LESS THAN MAXVALUE); |
INSERT INTO t1 VALUES (9.99), (10); |
--let $n= query_get_value(SELECT COUNT(*) AS n FROM t1 WHERE c = 9.99, n, 1)
|
if ($n != 1) |
{
|
--die The row 9.99 is stored in p0, and the lookup c = 9.99 on the RANGE partitioned table finds $n rows |
}
|
CREATE TABLE t2 (c DECIMAL(10,2)) PARTITION BY LIST (c) (PARTITION p0 VALUES IN (1, 2), PARTITION p1 VALUES IN (3)); |
INSERT INTO t2 VALUES (2.6); |
--let $n= query_get_value(SELECT COUNT(*) AS n FROM t2 WHERE c = 2.6, n, 1)
|
if ($n != 1) |
{
|
--die The row 2.6 is stored in p0, and the lookup c = 2.6 on the LIST partitioned table finds $n rows |
}
|
DROP TABLE t1, t2; |
Leads to:
|
CS 13.1.2 c8e6ab229f030119c19f3208d40f415decb41dae (Debug, Clang 22.1.8-20260622) Build 19/11/2026 |
mysqltest: At line 7: The row 9.99 is stored in p0, and the lookup c = 9.99 on the RANGE partitioned table finds 0 rows
|
Partitioning changes the query result. Without partitioning, WHERE c = 9.99 finds the row.
EXPLAIN PARTITIONS shows p1 for WHERE c = 9.99, while the row is in p0. With the rows 9.5 and 9.49 added to t1, c = 9.5, c IN (9.99, 9.5), c <=> 9.99 and c > 9.9 also miss rows, while c = 9.49 and c + 0 = 9.99 give the right count. With the partition bound 0, c = -0.4 misses its row in the same way. Run alone, the LIST case fails too: c = 2.6 finds 0 rows. Optimized builds give the same result.
MySQL does not allow a DECIMAL column here: MySQL 5.5, 5.7, 8.0 and 9.1 give "Field 'c' is of a not allowed type for this type of partitioning" for the CREATE TABLE of t1.
From the code it seems that part_val_int() places a row by its DECIMAL value rounded down (FLOOR). Pruning gets the value from Item_field::val_int_endpoint(), which calls Field_new_decimal::val_int(), and that rounds to the nearest integer (HALF_UP).
Attachments
Issue Links
- is caused by
-
MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column
-
- Closed
-
- relates to
-
MDEV-41475 Partitioning by TO_SECONDS(), TO_DAYS() or UNIX_TIMESTAMP() changes the query result: a row with fractional seconds is not found
-
- Open
-