Skip to content

fix: ELT() function fully compatible with MySQL - #23841

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
gouhongshen:fix/elt-mysql-compat
Mar 12, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
gouhongshen:fix/elt-mysql-compat

Conversation

@gouhongshen

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 #22992

What this PR does / why we need it:

Fix the ELT() function to be fully compatible with MySQL.

Root Cause:
eltCheck skipped casting for integer types other than int64 (e.g. int32, int16, bool), but the Elt executor hardcodes GenerateFunctionFixedTypeParameter[int64], causing a type mismatch panic when using INT/SMALLINT/TINYINT columns or BOOL values as the index argument.

Fix:
In eltCheck, explicitly handle all numeric types (bool, integer, float, decimal, bit) by always casting the first argument to int64. For other types (e.g. varchar), fall back to tryToMatch.

Test Coverage:
Updated BVT tests (52 SQL statements) covering:

  • INT/SMALLINT/TINYINT/UNSIGNED column as index (was panic)
  • BOOL index: ELT(TRUE, ...) / ELT(FALSE, ...)
  • Float index with rounding: ELT(1.9, ...) → 2
  • String index: ELT('2', ...)
  • Negative/zero float index
  • Table with NULL index rows
  • Table with out-of-range index rows
  • BINARY return type
  • Expression as index
  • ELT + FIELD complement
  • Removed all @bvt:issue#22992 skip tags

Fix eltCheck to always cast the first argument to int64, resolving
panic when using INT/SMALLINT/TINYINT/UNSIGNED column as index.

The root cause was that eltCheck skipped casting for integer types
other than int64 (e.g. int32), but the Elt executor hardcodes
GenerateFunctionFixedTypeParameter[int64], causing type mismatch.

Also adds test coverage for:
- INT/SMALLINT/TINYINT/UNSIGNED index types
- Float index (MySQL rounds to nearest integer)
- Boolean index (TRUE=1, FALSE=0)
- Expression as index
- ELT + FIELD complement

Closes matrixorigin#22992
…c types

BOOL is not covered by IsInteger() or tryToMatch(BOOL, int64) in MO,
so explicitly list bool/integer/float/decimal/bit for direct cast to int64.
@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

🛑 Queue command has been cancelled

@mergify

mergify Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-03-12 03:21 UTC · Rule: main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-03-12 03:21 UTC · at 3bb5f8cd20cb37e42614cc5e891009b7c37581b0

This pull request spent 10 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants