Skip to content

Commit 0000e7c

Browse files
committed
SQL: add sub-selects to the Limitations page (#37012)
(cherry picked from commit 39a0723)
1 parent 885a28a commit 0000e7c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

docs/reference/sql/limitations.asciidoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,24 @@ a field is an array (has multiple values) or not, so without reading all the dat
6969
When doing aggregations (`GROUP BY`) {es-sql} relies on {es}'s `composite` aggregation for its support for paginating results.
7070
But this type of aggregation does come with a limitation: sorting can only be applied on the key used for the aggregation's buckets. This
7171
means that queries like `SELECT * FROM test GROUP BY age ORDER BY COUNT(*)` are not possible.
72+
73+
[float]
74+
=== Using a sub-select
75+
76+
Using sub-selects (`SELECT X FROM (SELECT Y)`) is **supported to a small degree**: any sub-select that can be "flattened" into a single
77+
`SELECT` is possible with {es-sql}. For example:
78+
79+
["source","sql",subs="attributes,macros"]
80+
--------------------------------------------------
81+
include-tagged::{sql-specs}/docs.csv-spec[limitationSubSelect]
82+
--------------------------------------------------
83+
84+
The query above is possible because it is equivalent with:
85+
86+
["source","sql",subs="attributes,macros"]
87+
--------------------------------------------------
88+
include-tagged::{sql-specs}/docs.csv-spec[limitationSubSelectRewritten]
89+
--------------------------------------------------
90+
91+
But, if the sub-select would include a `GROUP BY` or `HAVING` or the enclosing `SELECT` would be more complex than `SELECT X
92+
FROM (SELECT ...) WHERE [simple_condition]`, this is currently **un-supported**.

x-pack/plugin/sql/qa/src/main/resources/docs.csv-spec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,30 @@ SELECT NOW() AS result;
21302130
2018-12-12T14:48:52.448Z
21312131
// end::nowFunction
21322132
;
2133+
2134+
////////////
2135+
// Next two queries need to have the same output, as they should be equivalent.
2136+
// They are used in the "SQL Limitations" page.
2137+
////////////
2138+
limitationSubSelect
2139+
// tag::limitationSubSelect
2140+
SELECT * FROM (SELECT first_name, last_name FROM emp WHERE last_name NOT LIKE '%a%') WHERE first_name LIKE 'A%';
2141+
2142+
first_name | last_name
2143+
---------------+---------------
2144+
Anneke |Preusig
2145+
Anoosh |Peyn
2146+
Arumugam |Ossenbruggen
2147+
// end::limitationSubSelect
2148+
;
2149+
2150+
limitationSubSelect
2151+
// tag::limitationSubSelectRewritten
2152+
SELECT first_name, last_name FROM emp WHERE last_name NOT LIKE '%a%' AND first_name LIKE 'A%';
2153+
// end::limitationSubSelectRewritten
2154+
first_name | last_name
2155+
---------------+---------------
2156+
Anneke |Preusig
2157+
Anoosh |Peyn
2158+
Arumugam |Ossenbruggen
2159+
;

0 commit comments

Comments
 (0)