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+opt: translate upcasts in comparisons to suitable bound enlargements #27503

Open
knz opened this issue Jul 13, 2018 · 7 comments
Open

sql+opt: translate upcasts in comparisons to suitable bound enlargements #27503

knz opened this issue Jul 13, 2018 · 7 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-performance Perf of queries or internals. Solution not expected to change functional behavior. S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption. T-sql-queries SQL Queries Team

Comments

@knz
Copy link
Contributor

knz commented Jul 13, 2018

This is something I tripped up against earlier, which I saw @awoods187 trip against, and which Andrew Deally just reported customers trip up on:

select * from sometable where tscol::date = '2018-07-01'

where tscol has type TIMESTAMP and is indexed, will (currently) not use an index. This is a major surprise.

The workaround is pretty inconvenient, the query must be manually translated to

... where tscol >= '2018-07-01'::timestamp and tscol < '2018-07-02'::timestamp

(which is itself error prone in edge cases like February 28th on leap years etc).

This optimization must be performed for any comparison of the pattern Val::T = LITERAL where:

  • T is a type of lower precision than Val
  • there is a "natural", unambiguous projection from the type of Val to T.
  • the = comparison can be translated to an exact interval.

Other examples:

but not TIMESTAMP vs INT (no natural conversion) or DECIMAL vs FLOAT (no natural conversion).

Jira issue: CRDB-4951

@knz knz added C-performance Perf of queries or internals. Solution not expected to change functional behavior. S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption. A-sql-optimizer SQL logical planning and optimizations. labels Jul 13, 2018
@knz
Copy link
Contributor Author

knz commented Jul 13, 2018

cc @RaduBerinde @andy-kimball

@knz
Copy link
Contributor Author

knz commented Jul 13, 2018

Also optimization is possible for inequalities when the bound has an exact representation in both types!

@RaduBerinde
Copy link
Member

#20046 is similar.

@justinj justinj self-assigned this Sep 18, 2018
@github-actions
Copy link

github-actions bot commented Jun 6, 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
Copy link
Contributor Author

knz commented Jun 7, 2021

still exists in 21.1

@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@mgartner mgartner moved this to New Backlog in SQL Queries Jul 24, 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!

@knz
Copy link
Contributor Author

knz commented Sep 22, 2023

still relevant

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-performance Perf of queries or internals. Solution not expected to change functional behavior. S-3-ux-surprise Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

4 participants