Skip to content

[Bug]: DECIMAL PK BETWEEN returns 0 rows on flushed data #24282

Closed

Description

@aunjgr

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

7395c5f

Other Environment Information

  • Hardware parameters: x86_64
  • OS type: Linux
  • Others: N/A

Actual Behavior

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.

CREATE TABLE t1(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.00 AND 8.00;

-- Returns 6 rows (CORRECT)
SELECT * FROM t1 WHERE a >= 3.00 AND 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

CREATE DATABASE test_db;
USE test_db;
CREATE TABLE t1(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 rows
SELECT COUNT(*) FROM t1 WHERE a BETWEEN 3.00 AND 8.00;

-- This returns 6 (correct)
SELECT COUNT(*) FROM t1 WHERE a >= 3.00 AND a <= 8.00;

DROP DATABASE 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

  1. self-assigned this
    on May 6, 2026
  2. added theissue type on May 6, 2026
  3. added a commit that references this issue on May 6, 2026
    5ba4464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions