Skip to content

[opt] retain IN expression in prepared stmt - #16797

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
aunjgr:cpk
Jun 11, 2024
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
aunjgr:cpk

Conversation

@aunjgr

@aunjgr aunjgr commented Jun 11, 2024 •

Copy link
Copy Markdown
Contributor

User description

rework #16744

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #16730

What this PR does / why we need it:

fix #16744


PR Type

Enhancement


Description

  • Added a condition to check if the argument type is variable length before deciding no cast is needed in BindFuncExprImplByPlanExpr.
  • Included Expr_List in the types checked in extractColRefInFilter.
  • Removed redundant numeric type check in checkNoNeedCast.

Changes walkthrough 📝

Relevant files
Enhancement
base_binder.go
Add varlen type check in BindFuncExprImplByPlanExpr function

pkg/sql/plan/base_binder.go

  • Added a condition to check if the argument type is variable length
    before deciding no cast is needed.
  • +1/-1     
    utils.go
    Enhance filter extraction and simplify type check logic   

    pkg/sql/plan/utils.go

  • Included Expr_List in the types checked in extractColRefInFilter.
  • Removed redundant numeric type check in checkNoNeedCast.
  • +2/-2     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5]

    2

    🧪 Relevant tests

    No

    🔒 Security concerns

    No

    ⚡ Key issues to review

    Logic Change:
    The change in base_binder.go introduces a condition to check if the argument type is variable length before deciding no cast is needed. Ensure that this new condition does not inadvertently affect other functionalities where a cast might still be necessary despite the variable length type.

    Type Handling:
    In utils.go, the inclusion of Expr_List in the types checked could potentially alter the behavior of the filter extraction logic. Verify that this change correctly handles all scenarios, especially with complex nested expressions.

    @mergify mergify Bot added the kind/feature label Jun 11, 2024
    @matrix-meow matrix-meow added the size/XS Denotes a PR that changes [1, 9] lines label Jun 11, 2024
    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a length check for the argsType slice to prevent out-of-bounds errors

    To ensure that the argsType slice has at least two elements before accessing argsType[0]
    and argsType[1], add a length check to prevent potential out-of-bounds errors.

    pkg/sql/plan/base_binder.go [1664]

    -if argsType[0].IsVarlen() && checkNoNeedCast(argsType[1], argsType[0], args[1]) {
    +if len(argsType) > 1 && argsType[0].IsVarlen() && checkNoNeedCast(argsType[1], argsType[0], args[1]) {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: This suggestion correctly identifies a potential out-of-bounds error in the code, which is a critical issue that could cause runtime crashes.

    8
    Possible issue
    Add a nil check for constExpr to avoid potential nil pointer dereference

    To avoid potential nil pointer dereference, add a nil check for constExpr before calling
    constExpr.GetP().

    pkg/sql/plan/utils.go [1248]

    -if constExpr.GetP() != nil && columnT.IsNumeric() {
    +if constExpr != nil && constExpr.GetP() != nil && columnT.IsNumeric() {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion to add a nil check before dereferencing constExpr addresses a potential crash due to nil pointer dereference, which is a significant issue.

    8
    Best practice
    Use a type switch with a default case to handle unexpected types in the switch statement

    To improve readability and maintainability, consider using a type switch with a default
    case to handle unexpected types in the exprImpl.F.Args[1].Expr switch statement.

    pkg/sql/plan/utils.go [630-632]

     switch e := exprImpl.F.Args[1].Expr.(type) {
     case *plan.Expr_Lit, *plan.Expr_P, *plan.Expr_V, *plan.Expr_Vec, *plan.Expr_List:
    +    return extractColRefInFilter(exprImpl.F.Args[0])
    +default:
    +    // handle unexpected types
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding a default case to handle unexpected types improves the robustness and maintainability of the code. It's a good practice, but not critical for functionality.

    6

    @mergify
    mergify Bot merged commit 9162803 into matrixorigin:main Jun 11, 2024
    @aunjgr
    aunjgr deleted the cpk branch June 17, 2024 02:22
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants