Skip to content

Fix MySQL expression type inference for numeric division#4391

Open
rubensantoniorosa2704 wants to merge 3 commits intosqlc-dev:mainfrom
rubensantoniorosa2704:fix/4153-mysql-expression-inference
Open

Fix MySQL expression type inference for numeric division#4391
rubensantoniorosa2704 wants to merge 3 commits intosqlc-dev:mainfrom
rubensantoniorosa2704:fix/4153-mysql-expression-inference

Conversation

@rubensantoniorosa2704
Copy link
Copy Markdown
Contributor

This PR improves MySQL expression type inference for simple numeric expressions, with a focus on division.

In November 2025 I started working on this issue but closed my previous attempt because I felt I was changing too much at once. This is a smaller, more focused version of that work, and it’s my first non-trivial contribution to this project.

What this PR does:

  • Fixes the mapping of MySQL division opcodes so that / and DIV are distinguished correctly.
  • Introduces a small internal type representation (Kind/Type) for MySQL expression inference.
  • Adds inferExprType for MySQL and uses it in output_columns only when inference succeeds, preserving the original fallback behavior otherwise.
  • Implements minimal, conservative rules for / so that:
    • FLOAT / is inferred as FLOAT
    • INT / is inferred as DECIMAL
    • nullability is propagated from the operands

The goal is not to provide a complete expression type system, but to address the concrete bug with FLOAT NULL columns and division while leaving clear extension points for future work.

I would really appreciate feedback on:

  • Whether the internal Type/Kind abstraction and the scope of this change feel appropriate for the project.
  • Any edge cases or additional tests you think should be covered.
  • Style/naming/preferences that would make this easier to maintain.

I’m happy to adjust the approach, change the design if you’d prefer a different direction, add more tests, or explain any part of the implementation if something is unclear.

Fixes #4153

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How can i get correct type

1 participant