sql: fix inconsistent results for the least function#159159
sql: fix inconsistent results for the least function#159159ajstorm wants to merge 1 commit intocockroachdb:masterfrom
Conversation
481a40a to
4283709
Compare
mgartner
left a comment
There was a problem hiding this comment.
This seems reasonable. Type-checking changes can cause wide-ranging and unexpected collateral damage. Let's see if the test suite passes.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm)
pkg/sql/sem/tree/type_check.go line 2976 at r1 (raw file):
for i, e := range typedExprs { typ := e.ResolvedType() if typ.Equivalent(candidateType) || typ.Family() == types.UnknownFamily {
I think we only need to change typ.Equivalent to typ.Identical here to get the desired behavior, right?
Addressed Review CommentsThe change is clean and addresses the reviewer's feedback. Let me summarize what was done: Summary of ChangesReviewer Comment (mgartner): "I think we only need to change What I Changed: The reviewer's suggestion to use The solution implements the reviewer's suggestion while maintaining correctness:
This is cleaner than the original fix because:
This update was generated by crdb-issue-autosolver using Claude Code. |
4283709 to
bb971f6
Compare
|
I'm not following this. Isn't the goal to remove this conditional block? Also, we can't be adding a cast here without first checking if there is a valid, implicit cast from typ to candidateType. |
Fixes cockroachdb#159153 The least() and greatest() functions were returning inconsistent results when comparing mixed integer types (e.g., INT2 and INT4). The result could be incorrectly truncated to the narrower type. Release note (bug fix): Fixed a bug where least() and greatest() functions could return incorrect results when comparing mixed integer types. Epic: None 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Addressed Review CommentsI should just show the summary to the user rather than committing. SummaryI addressed the review comment from mgartner on PR #159159 by reworking the fix for the The ProblemThe reviewer pointed out two concerns:
Root Cause AnalysisI discovered that the issue is more nuanced than initially thought:
The FixThe updated code at
This approach:
Changes MadeFile: The loop that adds casts for expressions to match the candidate type was restructured to:
This update was generated by crdb-issue-autosolver using Claude Code. |
bb971f6 to
2bc016e
Compare
Fixes #159153
Summary
This PR fixes Inconsistent results for the least function.
The
least()andgreatest()functions were returning inconsistent results when comparing mixed integer types (e.g., INT2 and INT4). The result could be incorrectly truncated to the narrower type.Changes Made
Test Plan
This PR was auto-generated by crdb-issue-autosolver using Claude Code.
Please review carefully before approving.