[MDEV-20595] Assertion `0 < sel && sel <= 2.0' failed in table_cond_selectivity Created: 2019-09-15 Updated: 2023-04-27 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Igor Babaev |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
I see 10.1 crashing after Here is the stack trace
This crash is reproducible with the below mtr test :
|
| Comments |
| Comment by Varun Gupta (Inactive) [ 2019-09-16 ] | ||||||||||||||||||||||||||||||
ANALYSISLooking at the test case in the description: The WHERE clause is A.a = B.a AND A.id=65 There is a primary key on A.id, so we will only read one table, hence so A is a const table. So the join planner picked ref access for table B
Discount the seletivity for ref(const).
After discount, we have
Discount selectivity for ref(non-const)Here we again consider the case B.a = A.a
So here the discount happens
Then we hit the assert, as selectivity value is again absurd. So the discount should have only happened once not twice, we should make sure that selectivity for a field is discounted only once | ||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2019-09-19 ] | ||||||||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2019-09-24 ] | ||||||||||||||||||||||||||||||
|
--source include/have_sequence.inc
Now lets consider the same query with EXPLAIN SELECT * FROM t1 A, t1 B WHERE A.id = B.a and A.id = 65; Table A has a sargable condition A.id = 65 [index idx1] So for cond_selectivity for table B we would have selectivity(B.a=65) = table->quick_rows[1] / table_records Now while discounting in table_cond_selectivity for table B Case 1Check if we have a prefix of key=const that matches a quick select. Case 2Go through the remaining keypart where key_part_i=const equalities and find those that were Case 3If the field f from the table is equal to a field from one the In this case we discount the selectivity for the condition B.a = A.id. This is incorrect as we have already | ||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-09-26 ] | ||||||||||||||||||||||||||||||
|
The patch is ok to push. | ||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-12-03 ] | ||||||||||||||||||||||||||||||
|
A larger change that addresses these problems is being worked on in MDEV-20740. | ||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2022-04-13 ] | ||||||||||||||||||||||||||||||
|
I checked this test case against 10.7-selectivity and it works (no crash) |