Skip to content

fix(index): propagate decimal scale in zonemap Between - #24285

Closed
aunjgr wants to merge 1 commit into
matrixorigin:mainfrom
aunjgr:fix/decimal-pk-between
Closed

aunjgr wants to merge 1 commit into
matrixorigin:mainfrom
aunjgr:fix/decimal-pk-between

Conversation

@aunjgr

@aunjgr aunjgr commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24282

What this PR does / why we need it:

ZM.Between(lb, ub []byte) calls BuildZM(zm.GetType(), lb) to construct a temporary zonemap representing the query range, but never copies the scale from the source zonemap. When the type is DECIMAL(p,s), the subsequent Intersect() call uses CompareDecimal64WithScale which multiplies one operand by 10^scale — but since the temp zonemap has scale=0, the comparison produces wrong results and prunes blocks that actually contain matching rows.

Fix: add oth.SetScale(zm.GetScale()) after BuildZM().

Also wires in_range function into CompileFilterExpr (zonemap pruning) and ConstructBasePKFilter (PK row filtering) so it benefits from the same block/object elimination as BETWEEN.

Verified:

  • Unit tests pass (go test ./pkg/vm/engine/tae/index/)
  • DECIMAL(10,2) PK BETWEEN on 20K-row table returns correct 5001 rows (was 0 before fix)
  • in_range_operator.sql BVT: 368/368 pass (was failing on DECIMAL cases)
  • All in_range flag variants (closed-closed, left-open, right-open, both-open) return correct counts

…nge filter

ZM.Between() built a temporary zonemap without copying the scale from
the source, causing CompareDecimal64WithScale to miscompare and prune
blocks that actually contain matching rows.  Also wires the in_range
function into both CompileFilterExpr (zonemap pruning) and
ConstructBasePKFilter (PK row filtering) so it benefits from the same
block/object elimination as BETWEEN.

Closes matrixorigin#24282

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@aunjgr
aunjgr requested a review from XuPeng-SH as a code owner May 6, 2026 09:00
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@aunjgr

aunjgr commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Absorbed into #24275 — the decimal zonemap fix and in_range wiring are now part of the secondary index range query PR.

@aunjgr aunjgr closed this May 6, 2026
@aunjgr
aunjgr deleted the fix/decimal-pk-between branch May 6, 2026 15:04

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants