Skip to content
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

Join planner chooses suboptimal plan for lookup join #8924

Open
nicktobey opened this issue Mar 4, 2025 · 0 comments
Open

Join planner chooses suboptimal plan for lookup join #8924

nicktobey opened this issue Mar 4, 2025 · 0 comments
Labels

Comments

@nicktobey
Copy link
Contributor

dolthub/go-mysql-server#2868 exposed a potentially join costing bug. In each of the modified PlanTests, the engine is picking a strictly worse index than before.

Basically, the planner is evaluating a where clause that binds the orgId, name, and val columns to constants. So it needs to pick between two different indexes:

  • The non-unique index (orgId, name, val)
  • The prefix (orgId, name) on the unique index (orgId, name, assetId) (plus a filter for the val column.)

The former is the strictly better choice because it only matches the relevant rows and doesn't require an additional filter. But as we can see in the diffs of the ExpectedEstimates fields, the coster is computing a lower cost for the latter.

Prior to the linked PR, the planner was picking the correct index for the wrong reason: it was treating the index as unique and incorrectly determining that it would have at most one row, overriding the cost comparison. Fixing this issue allowed the planner to compare the costs and pick the worse index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant