-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add subquery representation (#134)
* feat: add correlated subquery representation * refactor: rename operation enums * refactor: move IN predicate up * docs: add comments * chore: field ordering * docs: move comment up to message * style: format * docs: add subquery docs * style: format markdown
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Subqueries | ||
|
||
Subqueries are scalar expressions comprised of another query. | ||
|
||
## Forms | ||
|
||
### Scalar | ||
|
||
Scalar subqueries are subqueries that return one row and one column. | ||
|
||
| Property | Description | Required | | ||
| -------- | -------------- | -------- | | ||
| Input | Input relation | Yes | | ||
|
||
### `IN` predicate | ||
|
||
An `IN` subquery predicate checks that the left expression is contained in the | ||
right subquery. | ||
|
||
#### Examples | ||
|
||
```sql | ||
SELECT * | ||
FROM t1 | ||
WHERE x IN (SELECT * FROM t2) | ||
``` | ||
|
||
```sql | ||
SELECT * | ||
FROM t1 | ||
WHERE (x, y) IN (SELECT a, b FROM t2) | ||
``` | ||
|
||
| Property | Description | Required | | ||
| -------- | ----------------------------------------- | -------- | | ||
| Needles | Expressions who existence will be checked | Yes | | ||
| Haystack | Subquery to check | Yes | | ||
|
||
### Set predicates | ||
|
||
A set predicate is a predicate over a set of rows in the form of a subquery. | ||
|
||
`EXISTS` and `UNIQUE` are common SQL spellings of these kinds of predicates. | ||
|
||
| Property | Description | Required | | ||
| --------- | ------------------------------------------ | -------- | | ||
| Operation | The operation to perform over the set | Yes | | ||
| Tuples | Set of tuples to check using the operation | Yes | | ||
|
||
### Set comparisons | ||
|
||
A set comparison subquery is a subquery comparison using `ANY` or `ALL` operations. | ||
|
||
#### Examples | ||
|
||
```sql | ||
SELECT * | ||
FROM t1 | ||
WHERE x < ANY(SELECT y from t2) | ||
``` | ||
|
||
| Property | Description | Required | | ||
| --------------------- | ---------------------------------------------- | -------- | | ||
| Reduction operation | The kind of reduction to use over the subquery | Yes | | ||
| Comparision operation | The kind of comparison operation to use | Yes | | ||
| Expression | Left hand side expression to check | Yes | | ||
| Subquery | Subquery to check | Yes | |