Skip to content

[opt] : remove output operator after fuzzy filter - #17077

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
jensenojs:remove_output
Jun 24, 2024
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
jensenojs:remove_output

Conversation

@jensenojs

@jensenojs jensenojs commented Jun 21, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #17075

What this PR does / why we need it:

prepare for the subsequent TP performance improvement


PR Type

Enhancement


Description

  • Added a callback function execution after setting the row count in the fuzzy filter process.
  • Introduced a new Callback function field in the Argument struct to handle batch processing.
  • Replaced the output operator with a callback function in the fuzzy filter compilation process, simplifying the code.
  • Simplified struct initialization syntax in the MySQL parser for better readability.

Changes walkthrough 📝

Relevant files
Enhancement
filter.go
Add callback execution after setting row count in fuzzy filter

pkg/sql/colexec/fuzzyfilter/filter.go

  • Added a callback function call after setting row count.
  • Ensured the callback function is executed before setting the result
    status.
  • +2/-0     
    types.go
    Introduce Callback function field in Argument struct         

    pkg/sql/colexec/fuzzyfilter/types.go

  • Introduced a new Callback function field in the Argument struct.
  • +1/-0     
    compile.go
    Replace output operator with callback in fuzzy filter compilation

    pkg/sql/compile/compile.go

  • Replaced output operator with a callback function for fuzzy filter.
  • Simplified the fuzzy filter compilation process.
  • +13/-17 
    mysql_sql.go
    Simplify struct initialization in MySQL parser                     

    pkg/sql/parsers/dialect/mysql/mysql_sql.go

    • Simplified struct initialization syntax in MySQL parser.
    +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 Callback Error Handling:
    Ensure that the new callback function in filter.go and compile.go handles errors properly. It's crucial to verify that any error from the callback function is caught and managed correctly to avoid runtime issues.
    Function Signature Consistency:
    The callback function added in types.go should have a consistent and clear purpose, and its usage across different files should align with its intended functionality.

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jun 21, 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 issue
    Add error handling for the callback function to manage potential errors

    Consider adding error handling for the arg.Callback(ctr.rbat) call to ensure that any
    potential errors are caught and managed appropriately.

    pkg/sql/colexec/fuzzyfilter/filter.go [214]

    -arg.Callback(ctr.rbat)
    +if err := arg.Callback(ctr.rbat); err != nil {
    +    return vm.CallResult{}, err
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding error handling for the callback function is crucial as it ensures robustness and proper error management in the system, which is a significant improvement.

    8
    Maintainability
    Extract the callback function into a separate named function for better readability

    To improve readability, consider extracting the callback function assigned to arg.Callback
    into a separate named function.

    pkg/sql/compile/compile.go [3176-3186]

    -arg.Callback = func(bat *batch.Batch) error {
    -    if bat == nil || bat.IsEmpty() {
    +arg.Callback = c.createFuzzyCallback(fuzzyCheck)
    +
    +...
    +
    +func (c *Compile) createFuzzyCallback(fuzzyCheck *FuzzyCheck) func(bat *batch.Batch) error {
    +    return func(bat *batch.Batch) error {
    +        if bat == nil || bat.IsEmpty() {
    +            return nil
    +        }
    +        // the batch will contain the key that fuzzyCheck
    +        if err := fuzzyCheck.fill(c.ctx, bat); err != nil {
    +            return err
    +        }
    +
             return nil
         }
    -    // the batch will contain the key that fuzzyCheck
    -    if err := fuzzyCheck.fill(c.ctx, bat); err != nil {
    -        return err
    -    }
    -
    -    return nil
     }
     
    Suggestion importance[1-10]: 7

    Why: Extracting the callback into a separate function improves readability and maintainability of the code, making it easier to manage and understand.

    7
    Best practice
    Simplify the slice initialization by removing unnecessary braces

    The assignments slice initialization can be simplified by removing the unnecessary braces
    around the tree.VarAssignmentExpr struct.

    pkg/sql/parsers/dialect/mysql/mysql_sql.go [13468-13472]

     assignments := []*tree.VarAssignmentExpr{
    -    {
    +    &tree.VarAssignmentExpr{
             System: true,
             Global: true,
             Name:   yyDollar[6].str,
    -    }
    +    },
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: The suggestion is incorrect as it recommends reintroducing the braces that were removed in the PR, thus it does not improve the code.

    3

    @mergify
    mergify Bot merged commit 8eb9e70 into matrixorigin:main Jun 24, 2024
    @jensenojs
    jensenojs deleted the remove_output branch June 24, 2024 04:22
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    prepare for the subsequent TP performance improvement
    
    Approved by: @m-schen, @aunjgr, @ouyuanning
    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.

    5 participants