You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should be able to use idx1 to implement the query with a single indexed table access, no filter required. And if the query uses a non-NULL value for c0, we do. But whenc0 is being compared to NULL, the engine won't pick the secondary index.
The text was updated successfully, but these errors were encountered:
Digging into the index coster, I'm seeing some odd results:
Both the primary and the secondary index have a nil histogram, which results in them both have an estimated row count of 0.
Both the primary and the secondary index have a computed prefix length of 0, which seems inaccurate for both.
The stats for the secondary index says that there are 9 distinct rows and 0 null rows, which unless I'm misunderstanding how those are calculated for multi-column indexes where only some of the columns are NULL, also seems odd.
Tagging @max-hoffman since he may have additional context about what the coster is doing here.
Okay, the issue seems to be that conjCollector::add has a case for null safe equality, but no case for "IS NULL", causing it to treat "IS NULL" expressions like an inequality and preventing the coster from considering them in a prefix.
As a workaround, replacing IS NULL in the query with <=> NULL allows the coster to pick the correct index.
This still doesn't explain why the coster is using an estimated row count of 0 for both indexes, since it seems to be causing them to be rated higher than an index with a non-zero estimated row count.
Expected plan:
Actual plan:
We should be able to use
idx1
to implement the query with a single indexed table access, no filter required. And if the query uses a non-NULL value forc0
, we do. But whenc0
is being compared toNULL
, the engine won't pick the secondary index.The text was updated successfully, but these errors were encountered: