Skip to content

[fix] : always build on sinkScan node for fuzzy - #16830

Merged
mergify[bot] merged 9 commits into
matrixorigin:mainfrom
jensenojs:fix-moc3462
Jun 17, 2024
Merged

mergify[bot] merged 9 commits into
matrixorigin:mainfrom
jensenojs:fix-moc3462

Conversation

@jensenojs

@jensenojs jensenojs commented Jun 12, 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 #https://github.com/matrixorigin/MO-Cloud/issues/3462

What this PR does / why we need it:

Currently, tableScan Stats updates slowly and cannot be trusted, so if build on table Scan Node, we cause many many problem

however, This may make some optimizations impossible. like #16375


PR Type

Bug fix


Description

  • Commented out the logic that builds on the tableScan node due to unreliable tableScan statistics.
  • Ensured that the build always occurs on the sinkScan node by setting BuildIdx to 1.
  • Adjusted the calculation of arg.N to be 1.2 times the sinkScan.Stats.Outcnt to improve reliability.

Changes walkthrough 📝

Relevant files
Bug fix
operator.go
Always build on `sinkScan` node in `constructFuzzyFilter` function

pkg/sql/compile/operator.go

  • Commented out logic to build on tableScan node.
  • Always build on sinkScan node by setting BuildIdx to 1.
  • Adjusted the calculation of arg.N to be 1.2 times
    sinkScan.Stats.Outcnt.
  • +6/-6     

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

    * Currently, tableScan Stats updates slowly and cannot be trusted
    @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

    Possible Bug:
    The hardcoded multiplier of 1.2 for arg.N might not be optimal or justified by empirical data. Consider parameterizing this value or providing justification for the chosen multiplier.

    Performance Concern:
    Always building on sinkScan might limit optimization opportunities as mentioned in the related issue. It's important to ensure that this change does not negatively impact performance in scenarios where tableScan could be more efficient.

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jun 12, 2024
    @mergify mergify Bot added the kind/bug Something isn't working label Jun 12, 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
    Ensure sinkScan.Stats.Outcnt is initialized before using it to avoid runtime errors

    The variable arg.N is being set to a value based on sinkScan.Stats.Outcnt. Ensure that
    sinkScan.Stats.Outcnt is always initialized and has a valid value before this assignment
    to avoid potential runtime errors.

    pkg/sql/compile/operator.go [568]

    +if sinkScan.Stats.Outcnt == 0 {
    +    return nil, errors.New("sinkScan.Stats.Outcnt is not initialized")
    +}
     arg.N = 1.2 * sinkScan.Stats.Outcnt
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Checking for initialization before using a variable is crucial to prevent runtime errors, making this suggestion highly relevant for ensuring the robustness of the code.

    8
    Maintainability
    Use a constant for the multiplier to improve code maintainability and readability

    The calculation for arg.N should be consistent and clear. Instead of using a hardcoded
    multiplier (1.2), consider defining a constant or a configuration parameter for this
    multiplier to make the code more maintainable and understandable.

    pkg/sql/compile/operator.go [568]

    -arg.N = 1.2 * sinkScan.Stats.Outcnt
    +const multiplier = 1.2
    +arg.N = multiplier * sinkScan.Stats.Outcnt
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a constant for the multiplier instead of a hardcoded value enhances maintainability and readability, making it easier to manage and understand the code.

    7
    Best practice
    Add a comment explaining why the code is commented out and under what conditions it might be re-enabled

    If the commented-out code is no longer needed, it should be removed to keep the codebase
    clean. If it might be needed in the future, consider adding a comment explaining why it is
    commented out and under what circumstances it might be re-enabled.

    pkg/sql/compile/operator.go [563-566]

    +// The following code is commented out because we always build on sinkScan.
    +// Uncomment if the logic changes to conditionally build on tableScan.
     // if tableScan.Stats.Outcnt < sinkScan.Stats.Outcnt {
     // 	arg.BuildIdx = 0 // build on tableScan
     // 	arg.N = sinkScan.Stats.Outcnt + tableScan.Stats.Outcnt
     // } else {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding explanatory comments for commented-out code is a good practice as it clarifies the purpose and potential future use of the code, improving maintainability.

    6
    Enhancement
    Add a log statement to help with debugging and understanding the flow of the program

    Consider adding a log statement before setting arg.BuildIdx and arg.N to help with
    debugging and understanding the flow of the program.

    pkg/sql/compile/operator.go [567-568]

    +log.Printf("Building on sinkScan with Outcnt: %f", sinkScan.Stats.Outcnt)
     arg.BuildIdx = 1 // build on sinkScan
     arg.N = 1.2 * sinkScan.Stats.Outcnt
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Adding a log statement can aid in debugging and understanding program flow, although it's a minor enhancement compared to other potential improvements.

    5

    @jensenojs

    Copy link
    Copy Markdown
    Contributor Author

    https://github.com/matrixorigin/MO-Cloud/issues/3462#issuecomment-2160093320

    用深圳的台式机测了一下导入etao_001的数据, 现在不会卡住了

    image

    @mergify
    mergify Bot merged commit 137cfce into matrixorigin:main Jun 17, 2024
    @jensenojs
    jensenojs deleted the fix-moc3462 branch June 18, 2024 02:30
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    Currently, tableScan Stats updates slowly and cannot be trusted, so if build on table Scan Node, we cause many many problem
    
    however, This may make some optimizations impossible. like matrixorigin#16375
    
    Approved by: @ouyuanning, @m-schen, @badboynt1, @aunjgr
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Bug fix kind/bug Something isn't working Review effort [1-5]: 2 size/S Denotes a PR that changes [10,99] lines

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    6 participants