You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: DECIMAL PK BETWEEN returns 0 rows on flushed data #24282
When a table has a DECIMAL(15,2) primary key and data is flushed to disk, BETWEEN queries on the PK column return 0 rows. The same query returns correct results before flush (data in memory) or when using >= AND <= instead of BETWEEN.
CREATETABLEt1(a DECIMAL(15,2) PRIMARY KEY);
INSERT INTO t1 SELECT*FROM generate_series(1, 10) t;
SELECT mo_ctl('dn', 'flush', 'test_db.t1');
SELECT Sleep(1);
-- Returns 0 rows (WRONG)SELECT*FROM t1 WHERE a BETWEEN 3.00AND8.00;
-- Returns 6 rows (CORRECT)SELECT*FROM t1 WHERE a >=3.00AND a <=8.00;
This also affects IN_RANGE on DECIMAL PK columns after flush.
Expected Behavior
SELECT * FROM t1 WHERE a BETWEEN 3.00 AND 8.00 should return rows 3.00 through 8.00 (6 rows), matching the behavior of a >= 3.00 AND a <= 8.00.
Steps to Reproduce
CREATEDATABASEtest_db;
USE test_db;
CREATETABLEt1(a DECIMAL(15,2) PRIMARY KEY);
INSERT INTO t1 SELECT*FROM generate_series(1, 10) t;
SELECT mo_ctl('dn', 'flush', 'test_db.t1');
SELECT Sleep(1);
-- This returns 0 rowsSELECTCOUNT(*) FROM t1 WHERE a BETWEEN 3.00AND8.00;
-- This returns 6 (correct)SELECTCOUNT(*) FROM t1 WHERE a >=3.00AND a <=8.00;
DROPDATABASE test_db;
Additional information
Root cause: In pkg/vm/engine/readutil/pk_filter.go, the DECIMAL case in the BETWEEN handler uses CollectOffsetsByBetweenWithCompareFactory which does not accept a hint parameter for open/closed boundary semantics. More critically, ConstructBasePKFilter constructs the PK filter with function.BETWEEN for the "between" case, and the byte values from evalValue may not encode DECIMAL constants in the same format as what's stored in the block data, causing the binary search to miss all rows.
The >= AND <= path works because it goes through mergeFilters which constructs the range differently (individual GREAT_EQUAL + LESS_EQUAL filters merged).
Activity
fix(index): propagate decimal scale in zonemap Between and wire in_ra…