limitations.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-limitations]]
  4. == SQL Limitations
  5. [float]
  6. [[large-parsing-trees]]
  7. === Large queries may throw `ParsingExpection`
  8. Extremely large queries can consume too much memory during the parsing phase, in which case the {es-sql} engine will
  9. abort parsing and throw an error. In such cases, consider reducing the query to a smaller size by potentially
  10. simplifying it or splitting it into smaller queries.
  11. [float]
  12. [[sys-columns-describe-table-nested-fields]]
  13. === Nested fields in `SYS COLUMNS` and `DESCRIBE TABLE`
  14. {es} has a special type of relationship fields called `nested` fields. In {es-sql} they can be used by referencing their inner
  15. sub-fields. Even though `SYS COLUMNS` in non-driver mode (in the CLI and in REST calls) and `DESCRIBE TABLE` will still display
  16. them as having the type `NESTED`, they cannot be used in a query. One can only reference its sub-fields in the form:
  17. [source, sql]
  18. --------------------------------------------------
  19. [nested_field_name].[sub_field_name]
  20. --------------------------------------------------
  21. For example:
  22. [source, sql]
  23. --------------------------------------------------
  24. SELECT dep.dep_name.keyword FROM test_emp GROUP BY languages;
  25. --------------------------------------------------
  26. [float]
  27. === Scalar functions on nested fields are not allowed in `WHERE` and `ORDER BY` clauses
  28. {es-sql} doesn't support the usage of scalar functions on top of nested fields in `WHERE`
  29. and `ORDER BY` clauses with the exception of comparison and logical operators.
  30. For example:
  31. [source, sql]
  32. --------------------------------------------------
  33. SELECT * FROM test_emp WHERE LENGTH(dep.dep_name.keyword) > 5;
  34. --------------------------------------------------
  35. and
  36. [source, sql]
  37. --------------------------------------------------
  38. SELECT * FROM test_emp ORDER BY YEAR(dep.start_date);
  39. --------------------------------------------------
  40. are not supported but:
  41. [source, sql]
  42. --------------------------------------------------
  43. SELECT * FROM test_emp WHERE dep.start_date >= CAST('2020-01-01' AS DATE) OR dep.dep_end_date IS NULL;
  44. --------------------------------------------------
  45. is supported.
  46. [float]
  47. === Multi-nested fields
  48. {es-sql} doesn't support multi-nested documents, so a query cannot reference more than one nested field in an index.
  49. This applies to multi-level nested fields, but also multiple nested fields defined on the same level. For example, for this index:
  50. [source, sql]
  51. ----------------------------------------------------
  52. column | type | mapping
  53. ----------------------+---------------+-------------
  54. nested_A |STRUCT |NESTED
  55. nested_A.nested_X |STRUCT |NESTED
  56. nested_A.nested_X.text|VARCHAR |KEYWORD
  57. nested_A.text |VARCHAR |KEYWORD
  58. nested_B |STRUCT |NESTED
  59. nested_B.text |VARCHAR |KEYWORD
  60. ----------------------------------------------------
  61. `nested_A` and `nested_B` cannot be used at the same time, nor `nested_A`/`nested_B` and `nested_A.nested_X` combination.
  62. For such situations, {es-sql} will display an error message.
  63. [float]
  64. === Paginating nested inner hits
  65. When SELECTing a nested field, pagination will not work as expected, {es-sql} will return __at least__ the page size records.
  66. This is because of the way nested queries work in {es}: the root nested field will be returned and it's matching inner nested fields as well,
  67. pagination taking place on the **root nested document and not on its inner hits**.
  68. [float]
  69. [[normalized-keyword-fields]]
  70. === Normalized `keyword` fields
  71. `keyword` fields in {es} can be normalized by defining a `normalizer`. Such fields are not supported in {es-sql}.
  72. [float]
  73. === Array type of fields
  74. Array fields are not supported due to the "invisible" way in which {es} handles an array of values: the mapping doesn't indicate whether
  75. a field is an array (has multiple values) or not, so without reading all the data, {es-sql} cannot know whether a field is a single or multi value.
  76. When multiple values are returned for a field, by default, {es-sql} will throw an exception. However, it is possible to change this behavior through `field_multi_value_leniency` parameter in REST (disabled by default) or
  77. `field.multi.value.leniency` in drivers (enabled by default).
  78. [float]
  79. === Sorting by aggregation
  80. When doing aggregations (`GROUP BY`) {es-sql} relies on {es}'s `composite` aggregation for its support for paginating results.
  81. However this type of aggregation does come with a limitation: sorting can only be applied on the key used for the aggregation's buckets.
  82. {es-sql} overcomes this limitation by doing client-side sorting however as a safety measure, allows only up to *512* rows.
  83. It is recommended to use `LIMIT` for queries that use sorting by aggregation, essentially indicating the top N results that are desired:
  84. [source, sql]
  85. --------------------------------------------------
  86. SELECT * FROM test GROUP BY age ORDER BY COUNT(*) LIMIT 100;
  87. --------------------------------------------------
  88. It is possible to run the same queries without a `LIMIT` however in that case if the maximum size (*10000*) is passed,
  89. an exception will be returned as {es-sql} is unable to track (and sort) all the results returned.
  90. [float]
  91. === Using aggregation functions on top of scalar functions
  92. Aggregation functions like <<sql-functions-aggs-min,`MIN`>>, <<sql-functions-aggs-max,`MAX`>>, etc. can only be used
  93. directly on fields, and so queries like `SELECT MAX(abs(age)) FROM test` are not possible.
  94. [float]
  95. === Using a sub-select
  96. Using sub-selects (`SELECT X FROM (SELECT Y)`) is **supported to a small degree**: any sub-select that can be "flattened" into a single
  97. `SELECT` is possible with {es-sql}. For example:
  98. ["source","sql",subs="attributes,macros"]
  99. --------------------------------------------------
  100. include-tagged::{sql-specs}/docs/docs.csv-spec[limitationSubSelect]
  101. --------------------------------------------------
  102. The query above is possible because it is equivalent with:
  103. ["source","sql",subs="attributes,macros"]
  104. --------------------------------------------------
  105. include-tagged::{sql-specs}/docs/docs.csv-spec[limitationSubSelectRewritten]
  106. --------------------------------------------------
  107. But, if the sub-select would include a `GROUP BY` or `HAVING` or the enclosing `SELECT` would be more complex than `SELECT X
  108. FROM (SELECT ...) WHERE [simple_condition]`, this is currently **un-supported**.
  109. [float]
  110. [[first-last-agg-functions-having-clause]]
  111. === Using <<sql-functions-aggs-first, `FIRST`>>/<<sql-functions-aggs-last,`LAST`>> aggregation functions in `HAVING` clause
  112. Using `FIRST` and `LAST` in the `HAVING` clause is not supported. The same applies to
  113. <<sql-functions-aggs-min,`MIN`>> and <<sql-functions-aggs-max,`MAX`>> when their target column
  114. is of type <<keyword, `keyword`>> as they are internally translated to `FIRST` and `LAST`.
  115. [float]
  116. [[group-by-time]]
  117. === Using TIME data type in GROUP BY or <<sql-functions-grouping-histogram>>
  118. Using `TIME` data type as a grouping key is currently not supported. For example:
  119. [source, sql]
  120. -------------------------------------------------------------
  121. SELECT count(*) FROM test GROUP BY CAST(date_created AS TIME);
  122. -------------------------------------------------------------
  123. On the other hand, it can still be used if it's wrapped with a scalar function that returns another data type,
  124. for example:
  125. [source, sql]
  126. -------------------------------------------------------------
  127. SELECT count(*) FROM test GROUP BY MINUTE((CAST(date_created AS TIME));
  128. -------------------------------------------------------------
  129. `TIME` data type is also currently not supported in histogram grouping function. For example:
  130. [source, sql]
  131. -------------------------------------------------------------
  132. SELECT HISTOGRAM(CAST(birth_date AS TIME), INTERVAL '10' MINUTES) as h, COUNT(*) FROM t GROUP BY h
  133. -------------------------------------------------------------
  134. [float]
  135. [[geo-sql-limitations]]
  136. === Geo-related functions
  137. Since `geo_shape` fields don't have doc values these fields cannot be used for filtering, grouping or sorting.
  138. By default,`geo_points` fields are indexed and have doc values. However only latitude and longitude are stored and
  139. indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and
  140. 8.381903171539307E-8 for longitude). The altitude component is accepted but not stored in doc values nor indexed.
  141. Therefore calling `ST_Z` function in the filtering, grouping or sorting will return `null`.
  142. [float]
  143. [[fields-from-source]]
  144. === Retrieving from `_source`
  145. Most of {es-sql}'s columns are retrieved from the document's `_source` and there is no attempt to get the columns content from
  146. `docvalue_fields` not even in the case <<mapping-source-field,`_source`>> field is disabled in the mapping explicitly.
  147. If a column, for which there is no source stored, is asked for in a query, {es-sql} will not return it. Field types that don't follow
  148. this restriction are: `keyword`, `date`, `scaled_float`, `geo_point`, `geo_shape` since they are NOT returned from `_source` but
  149. from `docvalue_fields`.
  150. [float]
  151. [[fields-from-docvalues]]
  152. === Retrieving from `docvalue_fields`
  153. When the number of columns retrievable from `docvalue_fields` is greater than the configured <<dynamic-index-settings,`index.max_docvalue_fields_search` setting>>
  154. the query will fail with `IllegalArgumentException: Trying to retrieve too many docvalue_fields` error. Either the mentioned {es}
  155. setting needs to be adjusted or fewer columns retrievable from `docvalue_fields` need to be selected.
  156. [float]
  157. [[aggs-in-pivot]]
  158. === Aggregations in the <<sql-syntax-pivot, `PIVOT`>> clause
  159. The aggregation expression in <<sql-syntax-pivot, `PIVOT`>> will currently accept only one aggregation. It is thus not possible to obtain multiple aggregations for any one pivoted column.
  160. [float]
  161. [[subquery-in-pivot]]
  162. === Using a subquery in <<sql-syntax-pivot, `PIVOT`>>'s `IN`-subclause
  163. The values that the <<sql-syntax-pivot, `PIVOT`>> query could pivot must be provided in the query as a list of literals; providing a subquery instead to build this list is not currently supported. For example, in this query:
  164. [source, sql]
  165. -------------------------------------------------------------
  166. SELECT * FROM test_emp PIVOT (SUM(salary) FOR languages IN (1, 2))
  167. -------------------------------------------------------------
  168. the `languages` of interest must be listed explicitly: `IN (1, 2)`. On the other hand, this example would **not work**:
  169. [source, sql]
  170. -------------------------------------------------------------
  171. SELECT * FROM test_emp PIVOT (SUM(salary) FOR languages IN (SELECT languages FROM test_emp WHERE languages <=2 GROUP BY languages))
  172. -------------------------------------------------------------