-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Partial index using ranges not been selected in plan #8349
Comments
The optimizer cannot detect that value 42 matches the index range, as expressions are not evaluated at compile time. You need to specify that explicitly:
This may look cumbersome but should work. |
Thanks for the reply 👍. I have modified the filter on the index to use OR instead (a couple of dozen conditions covers most of our use cases fine). After doing this we get the following results
So the outlier there is the IN (42,43) however changing that to an OR works. I do feel that they should get the same result (i.e. both use the index) so maybe something to look at. I had a feeling a read somewhere that the parser/optimizer actually turns IN( ) into OR anyway so they should end up being equivalent. (but this inconsistency is something we can deal with although having it work consistently sometime in the future would be nice) |
Starting with v5, IN is not decomposed into ORs but instead is processed natively. |
In Firebird 5.0.1 when using a partial index with various range selections it always seems to fall back to a table scan (PLAN NATURAL)
Tried various other options such as LINETYPE > 0, LINETYPE IN (40,41,42,43,44,45,46,47), LINETYPE BETWEEN 40 AND 47, all of which result in a table scan, But the following does work (and technically is probably equivalent to the IN ( ) above)
LINETYPE = 40 OR LINETYPE = 41 OR LINETYPE = 42 OR ... OR LINETYPE = 47
But is is pretty inconvenient since there is probably a couple of dozen line types that should be included in the partial index so using a range or IN would be much better. The condition mentioned at the top would be OK since in our case around 3/4 of the values in the index would be either 0 or 32767, but probably ideally something like the following would be slightly better to exclude some additional values we are not interested in.
(LINETYPE BETWEEN 1 AND 7999) OR (LINETYPE BETWEEN 8100 AND 32766)
(possibly related to #7804 )
The text was updated successfully, but these errors were encountered: