[MDEV-18478] ANALYZE for statement should show selectivity of pushed index condition Created: 2019-02-05 Updated: 2024-02-08 |
|
| Status: | In Testing |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2, 10.3, 10.4 |
| Fix Version/s: | 11.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Lena Startseva |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | optimizer-easy, optimizer-feature | ||
| Issue Links: |
|
||||||||
| Description |
| Comments |
| Comment by Sergei Petrunia [ 2023-10-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Notes: There is another similar optimization, Rowid Filtering (https://mariadb.com/kb/en/rowid-filtering-optimization/) . It also works by pushing a check into the storage engine. It does print its selectivity into ANALYZE output, example: It's possible that both Rowid Filtering and Index Condition Pushdown are used at the same time. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-11-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Take-aways from Slack discussion: proceeding to Milestone#1:
| |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jason (Inactive) [ 2023-12-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
For Milestone 1, proposed patch in https://github.com/MariaDB/server/tree/bb-11.4-MDEV-18478. This is an example of the new output added to ANALYZE FORMAT=JSON (which can be seen in context in the test cases in the link above):
The meanings are:
I'm open to suggestions for better names for the counters. PR coming shortly for psergei. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Some review notes:
| |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
How does ANALYZE output look for Rowid Filters?
r_lookups is how many lookups were made (think "rows before the filter") | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
an example from rowid_filter.result:
This shows that
| |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jason (Inactive) [ 2023-12-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
For:
It seems that pushed conditions are supported in sql_update.cc and sql_delete.cc under some code related to the spider storage engine.
It seems to be not generally possible. I tested it by adding DBUG_ASSERT(1) and running mtr, which did not hit at all. We can choose to: | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jason (Inactive) [ 2023-12-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||
This is a good question. It appears to me that the rowid_filter r_lookups is also a overall total and is also not divided by r_loops. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jason (Inactive) [ 2023-12-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
For
and
I'm not sure if you are suggesting a some kind of change? Or are you just confirming that the output provides a useful analysis for how many rows are filtered at each step? If it is the latter, then I agree with the analysis, and there is a similar example with ICP and rowid filter in mysql-test/main/analyze_format_json.test. The comments in the added test indicate that there is a case with both ICP and rowid filter, and indicates how much filtering happened for each step. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||
This is "Table condition pushdown" which is a different feature from Index Condition Pushdown. It's outside of the scope of this MDEV.
I think both should be fixed to be comparable with r_rows, then. Let me continue to look at this to make sure the opinion doesn't change...
Sorry hit submit before finishing the comment. I was just checking that the output numbers make sense. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Note: the patch can do division-by-zero if there were not ICP checks. IIRC, division by zero is not harmless, it used to caused errors on some platforms in BB. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Tried to do a sketch of desired output: | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jason (Inactive) [ 2023-12-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
I've updated the patch to address divide-by-zero and dividing r_rows_idx and r_lookups by r_loops. I didn't do it in this patch, but you may want to consider making r_rows_idx and r_lookups (and r_rows, too?) of type double instead of an integer type, because the result of the division cast to an integer truncates the digits after the decimal point, which for small numbers can look misleading (especially when the result becomes 0). | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
jasoncu, thanks for the updated patch.. I'll continue from here... | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Difference of the above sketch from the current code:
Plus, members are re-ordered so members describing earlier phases come next. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Implemented in three patches: bb-11.4-MDEV-18478-v2: EDIT:
| |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-12-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
1. Comments on the 1st commit are left at GitHub. 2. Comments on the 2nd commit are also left at GitHub. In my opinion, attribute names are not quite descriptive, one can't read the ANALYZE output without documentation. I'd suggest renaming to more verbose names, like these: Also I'd explicitly indicate that values are expressed in percents either by adding "_pct" suffix (like it's done for "$.rowid_filter.r_selectivity_pct") or the "%" sign after values (which is more natural and short) 3. Comments on the 3rd commit are here. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
oleg.smirnov, we can't easily rename r_filtered as it has been that way for many years already. I don't think it's realistic to expect ANALYZE output to be comprehensible without documentation, there is just too much detail. (And if one doesn't read documentation, how do they know what is ICP or Rowid Filter anyway?) On the question of typecasts: some (most?) of them are actually necessary: https://buildbot.mariadb.org/#/builders/234/builds/25143/steps/8/logs/stdio
| |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-12-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
oleg.smirnov, I've addressed all input except the request for renames: https://github.com/MariaDB/server/pull/2970 | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-12-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Added some more comments to the PR. | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2024-01-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
(Got approval on the pull request). | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2024-01-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
(lstartseva, we need testing for this, but let me provide at least documentation first) | |||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2024-01-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||
|
Documentation: |