Skip to content

fix(evalengine): preserve decimal scale in ABS and COALESCE - #22156

Open
Vishal-wk wants to merge 1 commit into
vitessio:mainfrom
Vishal-wk:fix/evalengine-preserve-decimal-scale
Open

Vishal-wk wants to merge 1 commit into
vitessio:mainfrom
Vishal-wk:fix/evalengine-preserve-decimal-scale

Conversation

@Vishal-wk

Copy link
Copy Markdown

Description

This PR fixes decimal precision and scale being lost in the compiled EvalEngine implementations of ABS and COALESCE.

  • Preserve the input decimal's size and scale when compiling ABS.
  • Preserve the aggregated size and scale when compiling COALESCE.
  • Add regression coverage comparing interpreted and compiled evaluation for TIME(d), TIME(ABS(d)), and TIME(COALESCE(d, d)) using a DECIMAL(10,2) value of 12.55.

Motivation

The compiled evaluator was dropping decimal metadata, causing fractional seconds to be rounded away when decimal expressions were used with TIME().

For example, TIME(ABS(d)) and TIME(COALESCE(d, d)) could return 00:00:13 instead of 00:00:12.55.

This change ensures that the compiled evaluator preserves the decimal metadata and produces results consistent with the interpreter.

How do you use Vitess? (pick one)

  • In production
  • In staging or development
  • Evaluating it
  • I don't use Vitess

Did you run this change against a real Vitess deployment?

No. I reproduced the issue using the EvalEngine regression tests and additionally compared the affected expressions against a local MySQL instance using Vitess's MySQL differential integration test harness.

Related Issue(s)

Fixes #22126

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

No deployment steps, schema migrations, or configuration changes are required.

AI Disclosure

ChatGPT assisted with regression test design; I reviewed, implemented, and validated the final changes.

Signed-off-by: vishal-wk <tac1ee7@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 18:03
@github-actions github-actions Bot added this to the v25.0.0 milestone Nov 24, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Nov 24, 2026
@vitess-bot

vitess-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@github-actions github-actions Bot added Component: Evalengine changes to the evaluation engine Component: VTGate labels Nov 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the changes preserving decimal metadata in compiled expressions.

No open issues 🎉

What changed in this PR

Fixes #22126 by preserving decimal size and scale in compiled EvalEngine expressions, preventing fractional seconds from being rounded away when used with TIME().

Changes:

  • Preserve the argument’s decimal metadata when compiling ABS.
  • Preserve aggregated size and scale when compiling COALESCE.
  • Add regression coverage comparing interpreted and compiled results for decimal-to-time expressions.
File Description
go/​vt/​vtgate/​evalengine/​fn_numeric.go Retains decimal size and scale in compiled ABS.
go/​vt/​vtgate/​evalengine/​fn_compare.go Returns aggregated size and scale from compiled COALESCE.
go/​vt/​vtgate/​evalengine/​compiler_test.go Checks fractional-second preservation for TIME(d), TIME(ABS(d)), and TIME(COALESCE(d, d)) within CASE.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Evalengine changes to the evaluation engine Component: VTGate NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: compiled ABS and COALESCE drop the size and scale of a decimal argument, so TIME() over them rounds its fraction away

3 participants