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

opt: push filters into window functions when columns are referenced in the ORDER BY #38728

Open
justinj opened this issue Jul 8, 2019 · 2 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team

Comments

@justinj
Copy link
Contributor

justinj commented Jul 8, 2019

We already push down filters that are determined by the partition-by columns of the window function. We should also be able to push down filters bound by the order-by in certain situations.

Consider this query:

SELECT acct-id, time, ravg
FROM (SELECT  acct-id, time,
     AVG(balance) OVER (PARTITION BY acc-id ORDER BY
       time ROWS BETWEEN UNBOUNDED
      PROCEEDING
         AND CURRENT ROW) ravg
      FROM accounts
      WHERE acct-id = ’ORCL’ AND
time<=12);

The filter on time can be pushed down, since the window function being computed is prefix-safe and the filter allows through a prefix of the results.

Jira issue: CRDB-5615

@andreimatei andreimatei added this to Triage in BACKLOG, NO NEW ISSUES: SQL Optimizer via automation Jul 11, 2019
@awoods187 awoods187 added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-optimizer SQL logical planning and optimizations. labels Jul 23, 2019
@RaduBerinde RaduBerinde moved this from Triage to Lower Priority Backlog in BACKLOG, NO NEW ISSUES: SQL Optimizer Aug 1, 2019
@RaduBerinde RaduBerinde moved this from Lower Priority Backlog to Plan enhancements (lower priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Apr 18, 2020
@github-actions
Copy link

github-actions bot commented Jun 4, 2021

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
5 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@knz knz added this to Triage in SQL Queries via automation Jun 5, 2021
@rytaft rytaft moved this from Triage to Backlog in SQL Queries Jun 8, 2021
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@mgartner mgartner moved this from Backlog to New Backlog in SQL Queries Feb 16, 2023
@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Plan enhancements (lower priority) to Done Oct 2, 2023
@yuzefovich yuzefovich reopened this May 1, 2024
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Done to Triage May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects
Archived in project
SQL Queries
New Backlog
Development

No branches or pull requests

5 participants