You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Allow table name as column reference to return row as struct (`SELECT t from t`) - [PR #4195](https://github.com/FoundationDB/fdb-record-layer/pull/4195)
16
+
17
+
<details>
18
+
<summary>
19
+
20
+
<h4> Build/Test/Documentation/Style Improvements (click to expand) </h4>
* Indexer: fix typed records optimization - [PR #4244](https://github.com/FoundationDB/fdb-record-layer/pull/4244)
51
+
<h4> Bug Fixes </h4>
52
+
53
+
* Make the null-supplying side of `OUTER JOIN` nullable in the result value - [PR #4274](https://github.com/FoundationDB/fdb-record-layer/pull/4274)
54
+
* Fail if metrics are missing for a query in yaml-tests - [PR #4194](https://github.com/FoundationDB/fdb-record-layer/pull/4194)
55
+
* Fix an unreachable `if` branch in `QueryPredicateSimplificationRule` - [PR #4257](https://github.com/FoundationDB/fdb-record-layer/pull/4257)
56
+
<h4> Performance Improvements </h4>
57
+
58
+
* Removed a check from `checkVersion` that would clear the `omit_unsplit_record_suffix` on empty stores - [PR #4277](https://github.com/FoundationDB/fdb-record-layer/pull/4277)
59
+
* Enable efficient rule-index-based matching for `AbsorptionRule` - [PR #4255](https://github.com/FoundationDB/fdb-record-layer/pull/4255)
60
+
* Remove a dead call to `Simplification.optimize()` from `VectorIndexExpansionVisitor` - [PR #4256](https://github.com/FoundationDB/fdb-record-layer/pull/4256)
61
+
<h4> Dependency Updates </h4>
62
+
63
+
* Add a dependabot.yml to enable automatic dependency updates - [PR #4250](https://github.com/FoundationDB/fdb-record-layer/pull/4250)
64
+
65
+
<details>
66
+
<summary>
67
+
68
+
<h4> Build/Test/Documentation/Style Improvements (click to expand) </h4>
69
+
70
+
</summary>
71
+
72
+
* improve numerical stability of test - [PR #4276](https://github.com/FoundationDB/fdb-record-layer/pull/4276)
73
+
* Update some Gradle plugins and remove the `com.github.ben-manes.versions` plugin - [PR #4267](https://github.com/FoundationDB/fdb-record-layer/pull/4267)
74
+
* Expand the SQL documentation for ARRAY unnesting - [PR #4271](https://github.com/FoundationDB/fdb-record-layer/pull/4271)
Copy file name to clipboardExpand all lines: docs/sphinx/source/reference/sql_commands/DDL/CREATE/INDEX.rst
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,6 +279,8 @@ ORDER BY clause:
279
279
- Expressions in GROUP BY are supported
280
280
- WHERE clauses can be used with aggregate indexes for filtered aggregates
281
281
282
+
.. _index-on-syntax:
283
+
282
284
INDEX ON Syntax
283
285
===============
284
286
@@ -361,6 +363,21 @@ First define a view with the filter:
361
363
362
364
CREATE INDEX idx_expensive_products ON v_expensive_products(price)
363
365
366
+
**Index on View (Array Unnesting)**
367
+
368
+
A common pattern is to create a view that unnests an array column, then index the result. This creates a self-contained schema template with the table, view, and index together:
369
+
370
+
.. code-block:: sql
371
+
372
+
CREATE SCHEMA TEMPLATE my_template
373
+
CREATE TABLE products (
374
+
id BIGINT,
375
+
tags STRING ARRAY,
376
+
PRIMARY KEY(id))
377
+
CREATE VIEW product_tags AS
378
+
SELECT SQ.tag FROM products AS p, (SELECT tag FROM p.tags AS tag) AS SQ
Clause in a :ref:`schema template definition <create-schema-template>` to create a non-materialized view. A view is a virtual table whose contents are defined by a SQL query. Views do not store data themselves; each query against a view executes the underlying query against the base tables. Views are read-only and cannot be the target of ``INSERT``, ``UPDATE``, or ``DELETE`` statements. ``CREATE VIEW`` is a clause within a schema template and cannot be a standalone statement. View names must not collide with table, type, or function names in the same schema template.
8
+
9
+
Syntax
10
+
======
11
+
12
+
.. raw:: html
13
+
:file: VIEW.diagram.svg
14
+
15
+
Parameters
16
+
==========
17
+
18
+
``viewName``
19
+
The name of the view. Must be unique within the schema template — cannot collide with table, type, or other view names.
20
+
21
+
``query``
22
+
The SQL ``SELECT`` statement that defines the view. The query can reference tables, other views, and functions defined in the same schema template.
23
+
24
+
Examples
25
+
========
26
+
27
+
Setup
28
+
-----
29
+
30
+
``CREATE VIEW`` must appear inside a :ref:`schema template <create-schema-template>` definition and cannot be a standalone statement. For the examples on this page, assume the following schema template:
31
+
32
+
.. code-block:: sql
33
+
34
+
CREATE SCHEMA TEMPLATE my_template
35
+
CREATE TABLE employees (
36
+
id BIGINT,
37
+
name STRING,
38
+
dept STRING,
39
+
salary BIGINT,
40
+
PRIMARY KEY(id))
41
+
42
+
Basic View
43
+
----------
44
+
45
+
Create a view that filters rows from a base table:
46
+
47
+
.. code-block:: sql
48
+
49
+
CREATE VIEW engineering AS
50
+
SELECT id, name, salary
51
+
FROM employees
52
+
WHERE dept = 'Engineering'
53
+
54
+
Query the view like a table:
55
+
56
+
.. code-block:: sql
57
+
58
+
SELECT * FROM engineering
59
+
60
+
.. list-table::
61
+
:header-rows: 1
62
+
63
+
* - :sql:`id`
64
+
- :sql:`name`
65
+
- :sql:`salary`
66
+
* - :json:`1`
67
+
- :json:`"Alice"`
68
+
- :json:`100000`
69
+
* - :json:`2`
70
+
- :json:`"Bob"`
71
+
- :json:`110000`
72
+
73
+
Nested Views
74
+
------------
75
+
76
+
Views can reference other views. The following creates a second view on top of the first:
77
+
78
+
.. code-block:: sql
79
+
80
+
CREATE VIEW engineering AS
81
+
SELECT id, name, salary
82
+
FROM employees
83
+
WHERE dept = 'Engineering'
84
+
85
+
CREATE VIEW high_earners AS
86
+
SELECT id, name
87
+
FROM engineering
88
+
WHERE salary > 100000
89
+
90
+
.. code-block:: sql
91
+
92
+
SELECT * FROM high_earners
93
+
94
+
.. list-table::
95
+
:header-rows: 1
96
+
97
+
* - :sql:`id`
98
+
- :sql:`name`
99
+
* - :json:`2`
100
+
- :json:`"Bob"`
101
+
102
+
View with JOIN
103
+
--------------
104
+
105
+
Views support joins, including self-joins (see :ref:`inner_join` for join syntax):
106
+
107
+
.. code-block:: sql
108
+
109
+
CREATE VIEW peer_pairs AS
110
+
SELECT A.name AS emp1, B.name AS emp2
111
+
FROM employees A, employees B
112
+
WHERE A.dept = B.dept AND A.id < B.id
113
+
114
+
View with CTE
115
+
-------------
116
+
117
+
Views can use Common Table Expressions (see :doc:`WITH` for CTE syntax):
118
+
119
+
.. code-block:: sql
120
+
121
+
CREATE VIEW senior_engineering AS
122
+
WITH filtered AS (
123
+
SELECT id, name, salary
124
+
FROM employees
125
+
WHERE dept = 'Engineering' AND salary > 100000
126
+
)
127
+
SELECT * FROM filtered
128
+
129
+
Indexes on Views
130
+
----------------
131
+
132
+
Indexes can be defined on views using the standard ``CREATE INDEX`` syntax. For a self-contained example including array unnesting, see :ref:`index-on-syntax` in :doc:`INDEX`.
133
+
134
+
See Also
135
+
========
136
+
137
+
* :ref:`create-schema-template` — Schema templates and their clauses
138
+
* :doc:`TABLE` — Defining tables within a schema template
139
+
* :doc:`INDEX` — Defining indexes, including :ref:`index-on-syntax` for indexes on views
Copy file name to clipboardExpand all lines: docs/sphinx/source/reference/sql_commands/DQL/SELECT.rst
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,56 @@ It is also possible to project individual columns from a table, for example, sup
113
113
* - :json:`"Restaurant4"`
114
114
115
115
116
+
Projecting the entire row as a struct
117
+
-------------------------------------
118
+
119
+
It is possible to project the entire row as a single :sql:`STRUCT` column rather than expanding individual fields. There are two equivalent ways to do this.
120
+
121
+
**Using** :sql:`(*)`
122
+
123
+
.. code-block:: sql
124
+
125
+
SELECT (*) FROM restaurant;
126
+
127
+
This returns one column per row, named after the table, whose value is a :sql:`STRUCT` containing all of the table's fields:
0 commit comments