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
Copy file name to clipboardExpand all lines: docs-parts/queries/13-Transpiler-Design_lang1.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Moving `SELECT` to an earlier phase allows the `GROUP BY` and `HAVING` clauses t
11
11
The current implementation targets the MySQL implementation where table column aliases can be used in `HAVING`.
12
12
If postgres or CockroachDB cannot be coerced to work this way, restrictions of aggregations will have to be updated accordingly.
13
13
14
-
###QueryExpression
14
+
## QueryExpression
15
15
`QueryExpression` is the main object representing a distinct `SELECT` statement.
16
16
It implements operators `&`, `*`, and `proj` — restriction, join, and projection.
17
17
@@ -28,11 +28,11 @@ At least one element must be present in `support`. Multiple elements in `support
28
28
29
29
From the user's perspective `QueryExpression` objects are immutable: once created they cannot be modified. All operators derive new objects.
30
30
31
-
####Alias attributes
31
+
### Alias attributes
32
32
`proj` can create an alias attribute by renaming an existing attribute or calculating a new attribute.
33
33
Alias attributes are the primary reason why subqueries are sometimes required.
34
34
35
-
####Subqueries
35
+
### Subqueries
36
36
Projections, restrictions, and joins do not necessarily trigger new subqueries: the resulting `QueryExpression` object simply merges the properties of its inputs into self: `heading`, `restriction`, and `support`.
37
37
38
38
The input object is treated as a subquery in the following cases:
@@ -48,7 +48,7 @@ An error arises if
48
48
49
49
A subquery is created by creating a new `QueryExpression` object (or a subclass object) with its `support` pointing to the input object.
50
50
51
-
####Join compatibility
51
+
### Join compatibility
52
52
The join is always natural (i.e. *equijoin* on the namesake attributes).
53
53
54
54
**Before version 0.13:** As of version `0.12.*` and earlier, two query expressions were considered join-compatible if their namesake attributes were the primary key of at least one of the input expressions. This rule was easiest to implement but does not provide best semantics.
@@ -60,17 +60,17 @@ The join is always natural (i.e. *equijoin* on the namesake attributes).
60
60
61
61
The same join compatibility rules apply when restricting one query expression with another.
62
62
63
-
####Join mechanics
63
+
### Join mechanics
64
64
Any restriction applied to the inputs of a join can be applied to its output.
65
65
Therefore, those inputs that are not turned into queries donate their supports, restrictions, and projections to the join itself.
66
66
67
-
###Table
67
+
## Table
68
68
`Table` is a subclass of `QueryExpression` implementing table manipulation methods such as `insert`, `insert1`, `delete`, `update1`, and `drop`.
69
69
70
70
The restriction operator `&` applied to a `Table` preserves its class identity so that the result remains of type `Table`.
71
71
However, `proj` converts the result into a `QueryExpression` object. This may produce a base query that is not an instance of Table.
72
72
73
-
###Aggregation
73
+
## Aggregation
74
74
`Aggregation` is a subclass of `QueryExpression`.
75
75
Its main input is the *aggregating* query expression and it takes an additional second input — the *aggregated* query expression.
76
76
@@ -88,7 +88,7 @@ With respect to the second input, the projection part of aggregation allows only
88
88
89
89
All other rules for subqueries remain the same as for `QueryExpression`
90
90
91
-
###Union
91
+
## Union
92
92
`Union` is a subclass of `QueryExpression`.
93
93
A `Union` object results from the `+` operator on two `QueryExpression` objects.
94
94
Its `support` property contains the list of expressions (at least two) to unify.
@@ -98,16 +98,16 @@ The `Union` operator performs an OUTER JOIN of its inputs provided that the inpu
98
98
99
99
Union treats all its inputs as subqueries except for unrestricted Union objects.
100
100
101
-
###Universal Sets `dj.U`
101
+
## Universal Sets `dj.U`
102
102
`dj.U` is a special operand in query expressions that allows performing special operations. By itself, it can never form a query and is not a subclass of `QueryExpression`. Other query expressions are modified through participation in operations with `dj.U`.
103
103
104
-
####Aggegating by `dj.U`
104
+
### Aggegating by `dj.U`
105
105
106
-
####Resttricting a `dj.U` object with a `QueryExpression` object
106
+
### Resttricting a `dj.U` object with a `QueryExpression` object
107
107
108
-
####Joining a `dj.U` object
108
+
### Joining a `dj.U` object
109
109
110
-
###Query "Backprojection"
110
+
## Query "Backprojection"
111
111
Once a QueryExpression is used in a `fetch` operation or becomes a subquery in another query, it can project out all unnecessary attributes from its own inputs, recursively.
112
112
This is implemented by the `finalize` method.
113
113
This simplification produces much leaner queries resulting in improved query performance in version 0.13, especially on complex queries with blob data, compensating for MySQL's deficiencies in query optimization.
0 commit comments