Skip to content

SQL: Fix issue with optimization on queries with ORDER BY/LIMIT #40256

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

Merged
merged 4 commits into from
Mar 20, 2019

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Mar 20, 2019

Previously, when a trival plain SELECT or a trivial SELECT with
aggregations has also an ORDER BY or a LIMIT or both, then the
optimization to convert it to a LocalRelation was skipped resulting
in exception thrown. E.g.::

SELECT 'foo' FROM test LIMIT 10

or

SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1

Fixes: #40211

Previously, when a trival plain `SELECT` or a trivial `SELECT` with
aggregations has also an `ORDER BY` or a `LIMIT` or both, then the
optimization to convert it to a `LocalRelation` was skipped resulting
in exception thrown. E.g.::
```
SELECT 'foo' FROM test LIMIT 10
```
or
```
SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1
```

Fixes: elastic#40211
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@matriv matriv requested review from costin and astefan March 20, 2019 13:02

private static LocalRelation findLocalRelation(LogicalPlan plan) {
Holder<LocalRelation> logicalPlanHolder = new Holder<>();
plan.transformDown(l -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is transformDown really needed here or forEachDown is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thx, didn't think of that!

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left one comment.

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@matriv
Copy link
Contributor Author

matriv commented Mar 20, 2019

@elasticmachine run elasticsearch-ci/default-distro

@matriv
Copy link
Contributor Author

matriv commented Mar 20, 2019

@elasticmachine run elasticsearch-ci/1
@elasticmachine run elasticsearch-ci/2
@elasticmachine run elasticsearch-ci/bwc
@elasticmachine run elasticsearch-ci/docbldesx
@elasticmachine run elasticsearch-ci/oss-distro-docs
@elasticmachine run elasticsearch-ci/packaging-sample

@matriv
Copy link
Contributor Author

matriv commented Mar 20, 2019

@elasticmachine run elasticsearch-ci/default-distro
@elasticmachine run elasticsearch-ci/bwc

@matriv matriv merged commit 8832d25 into elastic:master Mar 20, 2019
@matriv matriv deleted the mt/fix-40211 branch March 20, 2019 22:51
matriv added a commit that referenced this pull request Mar 20, 2019
Previously, when a trival plain `SELECT` or a trivial `SELECT` with
aggregations has also an `ORDER BY` or a `LIMIT` or both, then the
optimization to convert it to a `LocalRelation` was skipped resulting
in exception thrown. E.g.::
```
SELECT 'foo' FROM test LIMIT 10
```
or
```
SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1
```

Fixes: #40211
matriv added a commit that referenced this pull request Mar 20, 2019
Previously, when a trival plain `SELECT` or a trivial `SELECT` with
aggregations has also an `ORDER BY` or a `LIMIT` or both, then the
optimization to convert it to a `LocalRelation` was skipped resulting
in exception thrown. E.g.::
```
SELECT 'foo' FROM test LIMIT 10
```
or
```
SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1
```

Fixes: #40211
matriv added a commit that referenced this pull request Mar 20, 2019
Previously, when a trival plain `SELECT` or a trivial `SELECT` with
aggregations has also an `ORDER BY` or a `LIMIT` or both, then the
optimization to convert it to a `LocalRelation` was skipped resulting
in exception thrown. E.g.::
```
SELECT 'foo' FROM test LIMIT 10
```
or
```
SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1
```

Fixes: #40211
@matriv
Copy link
Contributor Author

matriv commented Mar 21, 2019

Backported to 7.x with f37f2b5
to 7.0 with d118f85
to 6.7 with 3c00866
to 6.6 with 1b30a62

matriv added a commit that referenced this pull request Mar 21, 2019
Previously, when a trival plain `SELECT` or a trivial `SELECT` with
aggregations has also an `ORDER BY` or a `LIMIT` or both, then the
optimization to convert it to a `LocalRelation` was skipped resulting
in exception thrown. E.g.::
```
SELECT 'foo' FROM test LIMIT 10
```
or
```
SELECT 'foo' FROM test GROUP BY 1 ORDER BY 1
```

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

Successfully merging this pull request may close these issues.

SQL: Exception thrown for trivial GROUP BY and LIMIT
6 participants