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

sql: generic query plans do not push limit into lookup join #128704

Open
michae2 opened this issue Aug 9, 2024 · 2 comments
Open

sql: generic query plans do not push limit into lookup join #128704

michae2 opened this issue Aug 9, 2024 · 2 comments
Labels
A-generic-query-plans A-sql-optimizer SQL logical planning and optimizations. C-performance Perf of queries or internals. Solution not expected to change functional behavior. O-qa T-sql-queries SQL Queries Team

Comments

@michae2
Copy link
Collaborator

michae2 commented Aug 9, 2024

In generic query plans, we use lookup joins instead of constrained scans. But there is no lookup join equivalent to a limited constrained scan, so in generic plans we cannot push the limit into the lookup join. Supporting this might depend on #62471, though we think we could also use an overall limit for the entire lookup join instead of a per-lookup limit.

Here's an example using cockroach demo movr on v24.2.0-rc.1:

-- custom plan uses a limited constrained scan
EXPLAIN ANALYZE SELECT id FROM rides WHERE city = 'seattle' ORDER BY city, id LIMIT 10;

SET plan_cache_mode = force_generic_plan;
PREPARE p AS SELECT id FROM rides WHERE city = $1 ORDER BY city, id LIMIT 10;
-- generic plan cannot push the limit down into lookup join
EXPLAIN ANALYZE EXECUTE p ('seattle');

Jira issue: CRDB-41156

@michae2 michae2 added C-performance Perf of queries or internals. Solution not expected to change functional behavior. O-qa A-sql-optimizer SQL logical planning and optimizations. T-sql-queries SQL Queries Team labels Aug 9, 2024
@github-project-automation github-project-automation bot moved this to Triage in SQL Queries Aug 9, 2024
@michae2 michae2 moved this from Triage to Backlog in SQL Queries Aug 13, 2024
@michae2
Copy link
Collaborator Author

michae2 commented Aug 14, 2024

Pushing an overall limit down into JoinReader will also help #121917.

@michae2
Copy link
Collaborator Author

michae2 commented Aug 15, 2024

This might require fixing #67885.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-generic-query-plans A-sql-optimizer SQL logical planning and optimizations. C-performance Perf of queries or internals. Solution not expected to change functional behavior. O-qa T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

1 participant