Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry pick stats related fix to 1.2-dev #17052

Merged
merged 7 commits into from
Jun 21, 2024

Conversation

badboynt1
Copy link
Contributor

@badboynt1 badboynt1 commented Jun 21, 2024

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #16846

What this PR does / why we need it:

cherry pick stats related fix to 1.2-dev

fix stats for runtime filter in some cases

___

### **PR Type**
Bug fix

___

### **Description**
- Added calls to `recalcStatsByRuntimeFilter` in various functions to ensure stats are recalculated after applying runtime filters.
- Refactored `recalcStatsByRuntimeFilter` to use `builder` for selectivity calculation instead of passing `runtimeFilterSel`.
- Adjusted stats recalculation logic for scan and join nodes in `recalcStatsByRuntimeFilter`.

___

### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix
</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>apply_indices.go</strong><dd><code>Add stats recalculation for runtime filter in applyIndicesForJoins</code></dd></summary>
<hr>

pkg/sql/plan/apply_indices.go

<li>Added call to <code>recalcStatsByRuntimeFilter</code> after appending runtime <br>filter to <code>RuntimeFilterBuildList</code>.<br>

</details>

</td>
<td><a href="https://github.com/matrixorigin/matrixone/pull/16491/files#diff-b92e434ebc0c08092943a8c5a8abaed315f3e5722db3ffde4e3fbbb878d325b2">+1/-0</a>&nbsp; &nbsp; &nbsp; </td>

</tr>

<tr>
<td>
<details>
<summary><strong>build_constraint_util.go</strong><dd><code>Add stats recalculation for runtime filter in build constraint utility</code></dd></summary>
<hr>

pkg/sql/plan/build_constraint_util.go

<li>Added call to <code>recalcStatsByRuntimeFilter</code> in <code>appendPrimaryConstrantPlan</code> <br>function.<br>

</details>

</td>
<td><a href="https://github.com/matrixorigin/matrixone/pull/16491/files#diff-6eb56175b52eb3302f1d9ae1cde88ced82c25bb8dd90562238cc8d9757adb76b">+2/-0</a>&nbsp; &nbsp; &nbsp; </td>

</tr>

<tr>
<td>
<details>
<summary><strong>build_dml_util.go</strong><dd><code>Add stats recalculation for runtime filter in DML utility</code></dd></summary>
<hr>

pkg/sql/plan/build_dml_util.go

<li>Added call to <code>recalcStatsByRuntimeFilter</code> in <code>appendDeleteIndexTablePlan</code> <br>function.<br>

</details>

</td>
<td><a href="https://github.com/matrixorigin/matrixone/pull/16491/files#diff-095fb233d51021791cb24454839b013236680bbc6bbc22e0d2f6741ac8fe7dff">+1/-0</a>&nbsp; &nbsp; &nbsp; </td>

</tr>

<tr>
<td>
<details>
<summary><strong>runtime_filter.go</strong><dd><code>Update stats recalculation method calls in runtime filter</code></dd></summary>
<hr>

pkg/sql/plan/runtime_filter.go

<li>Modified calls to <code>recalcStatsByRuntimeFilter</code> to use <code>builder</code> instead of <br><code>runtimeFilterSel</code>.<br>

</details>

</td>
<td><a href="https://github.com/matrixorigin/matrixone/pull/16491/files#diff-597fe1a4b6c932d815482502c1ae60c5f8c69921e00b27dba2f5e4ea5b25b54b">+2/-3</a>&nbsp; &nbsp; &nbsp; </td>

</tr>

<tr>
<td>
<details>
<summary><strong>stats.go</strong><dd><code>Refactor stats recalculation logic in stats utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

pkg/sql/plan/stats.go

<li>Refactored <code>recalcStatsByRuntimeFilter</code> to use <code>builder</code> for selectivity <br>calculation.<br> <li> Adjusted stats recalculation logic for scan and join nodes.<br>

</details>

</td>
<td><a href="https://github.com/matrixorigin/matrixone/pull/16491/files#diff-3b3d55fa9884dcf8980f90043a05b26a04d0153ae89fcf032cec998752c0cafa">+11/-7</a>&nbsp; &nbsp; </td>

</tr>
</table></td></tr></tr></tbody></table>

___

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

Approved by: @ouyuanning
由于索引表总是将主键序列化进去,导致ndv很高,索引表的过滤度估计严重错误,会导致优化器错判tp/ap语句
现在改成利用原始过滤条件的过滤度去计算prefix_eq函数的过滤度

Approved by: @aunjgr
@mergify mergify bot requested a review from sukki37 June 21, 2024 01:51
@mergify mergify bot added the kind/bug Something isn't working label Jun 21, 2024
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 21, 2024
@mergify mergify bot merged commit a4da5e9 into matrixorigin:1.2-dev Jun 21, 2024
16 of 18 checks passed
@badboynt1 badboynt1 deleted the stats1.2 branch June 21, 2024 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants