-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
opt: incorrect index chosen when using LIKE #31929
Comments
I confirmed that it was Bilal's change #30827 that fixed it:
The row counts are still really close so I doubt that this change fixed the root cause - the second index should have significantly fewer rows. |
CC @rytaft |
Part of the problem here is not generating a (non-index) constraint for
The constrained scan then estimates 9.8 rows. I think any index constraint on a column should have at least 1/3 selectivity to make these two things compatible. |
Note: adding support for constraints on LIKE should fix this and is good to have. But I think this should have worked without it so there's another underlying problem here that I'd like to get to the bottom of. |
Taking a look now - thanks! |
Actually, I just tried it and if we have a constraint for the string column, the disparity is even worse - the estimation for the initial
|
Unlike the constraints found in Select and Join filters, an index constraint may represent multiple conjuncts. Therefore, the selectivity estimate for a Scan should account for the selectivity of each constrained column in the index constraint. This commit fixes the selectivity estimation in the optimizer to properly account for each constrained column in a Scan. Fixes cockroachdb#31929 Release note (bug fix): In some cases the optimizer was choosing the wrong index for a scan because of incorrect selectivity estimation. This estimation error has been fixed.
Adding constraint builder support for `LikeOp` and `SimilarToOp`. Also improving the logic to still try to determine not-null constraints if `buildSingleColumnConstraintConst` fails to come up with a constraint. Related to cockroachdb#31929. Release note: None
Adding constraint builder support for `LikeOp` and `SimilarToOp`. Also improving the logic to still try to determine not-null constraints if `buildSingleColumnConstraintConst` fails to come up with a constraint. Related to cockroachdb#31929. Release note: None
31835: ui: add node id to debug index page r=couchand a=couchand <img width="960" alt="screen shot 2018-10-24 at 5 25 17 pm" src="https://user-images.githubusercontent.com/793969/47462966-e4592c80-d7b2-11e8-996c-54bb09c13974.png"> ui: extract debug annotation from license type Release note: None ui: add node id to debug index page Fixes: #31540 Release note (admin ui change): Add the current node ID to the debug index page, to help identify the current node when viewing the web UI through a load balancer. 31942: opt: (non-index) constraints for LIKE, SIMILAR TO r=RaduBerinde a=RaduBerinde Adding constraint builder support for `LikeOp` and `SimilarToOp`. Also improving the logic to still try to determine not-null constraints if `buildSingleColumnConstraintConst` fails to come up with a constraint. Related to #31929. Release note: None Co-authored-by: Andrew Couch <andrew@cockroachlabs.com> Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Unlike the constraints found in Select and Join filters, an index constraint may represent multiple conjuncts. Therefore, the selectivity estimate for a Scan should account for the selectivity of each constrained column in the index constraint. This commit fixes the selectivity estimation in the optimizer to properly account for each constrained column in a Scan. Fixes cockroachdb#31929 Release note (bug fix): In some cases the optimizer was choosing the wrong index for a scan because of incorrect selectivity estimation. This estimation error has been fixed.
31937: opt: fix selectivity estimates for index constraints r=rytaft a=rytaft Unlike the constraints found in Select and Join filters, an index constraint may represent multiple conjuncts. Therefore, the selectivity estimate for a Scan should account for the selectivity of each constrained column in the index constraint. This commit fixes the selectivity estimation in the optimizer to properly account for each constrained column in a Scan. Fixes #31929 Release note (bug fix): In some cases the optimizer was choosing the wrong index for a scan because of incorrect selectivity estimation. This estimation error has been fixed. Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Unlike the constraints found in Select and Join filters, an index constraint may represent multiple conjuncts. Therefore, the selectivity estimate for a Scan should account for the selectivity of each constrained column in the index constraint. This commit fixes the selectivity estimation in the optimizer to properly account for each constrained column in a Scan. Fixes cockroachdb#31929 Release note (bug fix): In some cases the optimizer was choosing the wrong index for a scan because of incorrect selectivity estimation. This estimation error has been fixed.
Adding constraint builder support for `LikeOp` and `SimilarToOp`. Also improving the logic to still try to determine not-null constraints if `buildSingleColumnConstraintConst` fails to come up with a constraint. Related to cockroachdb#31929. Release note (performance improvement): Queries using LIKE get better execution plans in some cases.
This case was encountered by a customer.
The better plan is to use the other index where we can constrain the second column as well. It seems to be a stat issue, both plans estimate 10 rows for the scan even though one is strictly more constrained than the other:
Note that this works fine on master, but not on release-2.1. We need to figure out which change fixed it, and whether it fixed the root cause or it's just by chance that this particular case is fixed.
CC @rytaft
The text was updated successfully, but these errors were encountered: