This is an automated email from the ASF dual-hosted git repository.
zhenchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 28ace851e0 Minor optimizations to the document
28ace851e0 is described below
commit 28ace851e0afb9a4922bf25a821b86cd46e151b2
Author: Zhen Chen <[email protected]>
AuthorDate: Fri Dec 19 15:05:15 2025 +0800
Minor optimizations to the document
---
site/_docs/algebra.md | 35 ++++++++--------
site/_docs/materialized_views.md | 88 ++++++++++++++++++++--------------------
2 files changed, 61 insertions(+), 62 deletions(-)
diff --git a/site/_docs/algebra.md b/site/_docs/algebra.md
index 30a6b8175b..ed4b9cc962 100644
--- a/site/_docs/algebra.md
+++ b/site/_docs/algebra.md
@@ -155,7 +155,6 @@ ### Push and pop
building a bushy join:
{% highlight text %}
-.
join
/ \
join join
@@ -212,8 +211,8 @@ ### Field names and ordinals
The field names of an operator are guaranteed to be unique, but sometimes that
means that the names are not exactly what you expect. For example, when you
-join EMP to DEPT, one of the output fields will be called DEPTNO and another
-will be called something like DEPTNO_1.
+join `EMP` to `DEPT`, one of the output fields will be called `DEPTNO` and
another
+will be called something like `DEPTNO_1`.
Some relational expression methods give you more control over field names:
@@ -239,39 +238,39 @@ ### Field names and ordinals
you need to build field references that take that into account. This occurs
most often when building join conditions.
-Suppose you are building a join on EMP,
-which has 8 fields [EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO]
-and DEPT,
-which has 3 fields [DEPTNO, DNAME, LOC].
+Suppose you are building a join on `EMP`,
+which has 8 fields [`EMPNO`, `ENAME`, `JOB`, `MGR`, `HIREDATE`, `SAL`, `COMM`,
`DEPTNO`]
+and `DEPT`,
+which has 3 fields [`DEPTNO`, `DNAME`, `LOC`].
Internally, Calcite represents those fields as offsets into
a combined input row with 11 fields: the first field of the left input is
-field #0 (0-based, remember), and the first field of the right input is
-field #8.
+field `#0 (0-based, remember)`, and the first field of the right input is
+field `#8`.
But through the builder API, you specify which field of which input.
-To reference "SAL", internal field #5,
+To reference `SAL`, internal field `#5`,
write `builder.field(2, 0, "SAL")`, `builder.field(2, "EMP", "SAL")`,
or `builder.field(2, 0, 5)`.
-This means "the field #5 of input #0 of two inputs".
+This means "the field `#5` of input `#0` of two inputs".
(Why does it need to know that there are two inputs? Because they are stored on
-the stack; input #1 is at the top of the stack, and input #0 is below it.
+the stack; input `#1` is at the top of the stack, and input `#0` is below it.
If we did not tell the builder that were two inputs, it would not know how deep
-to go for input #0.)
+to go for input `#0`.)
-Similarly, to reference "DNAME", internal field #9 (8 + 1),
+Similarly, to reference `DNAME`, internal field `#9 (8 + 1)`,
write `builder.field(2, 1, "DNAME")`, `builder.field(2, "DEPT", "DNAME")`,
or `builder.field(2, 1, 1)`.
### Recursive Queries
Warning: The current API is experimental and subject to change without notice.
-A SQL recursive query, e.g. this one that generates the sequence 1, 2, 3,
...10:
+A SQL recursive query, e.g. this one that generates the sequence 1, 2, 3, ...,
10:
{% highlight sql %}
WITH RECURSIVE aux(i) AS (
VALUES (1)
UNION ALL
- SELECT i+1 FROM aux WHERE i < 10
+ SELECT i + 1 FROM aux WHERE i < 10
)
SELECT * FROM aux
{% endhighlight %}
@@ -413,7 +412,7 @@ #### Scalar expression methods
([RexNode]({{ site.apiRoot }}/org/apache/calcite/rex/RexNode.html)).
Many of them use the contents of the stack. For example, `field("DEPTNO")`
-returns a reference to the "DEPTNO" field of the relational expression just
+returns a reference to the `DEPTNO` field of the relational expression just
added to the stack.
| Method | Description
@@ -448,7 +447,7 @@ #### Sub-query methods
The following methods convert a sub-query into a scalar value (a `BOOLEAN` in
the case of `in`, `exists`, `some`, `all`, `unique`;
-any scalar type for `scalarQuery`).
+any scalar type for `scalarQuery`),
an `ARRAY` for `arrayQuery`,
a `MAP` for `mapQuery`,
and a `MULTISET` for `multisetQuery`).
diff --git a/site/_docs/materialized_views.md b/site/_docs/materialized_views.md
index 419835fa8b..7d5862847f 100644
--- a/site/_docs/materialized_views.md
+++ b/site/_docs/materialized_views.md
@@ -77,7 +77,7 @@ ##### Rewriting coverage
Let us illustrate with some examples the coverage of the view rewriting
algorithm implemented in `MaterializedViewRule`. The examples are based on the
following database schema.
-```sql
+{% highlight sql %}
CREATE TABLE depts(
deptno INT NOT NULL,
deptname VARCHAR(20),
@@ -98,7 +98,7 @@ ##### Rewriting coverage
FOREIGN KEY (deptno) REFERENCES depts(deptno),
FOREIGN KEY (locationid) REFERENCES locations(locationid)
);
-```
+{% endhighlight %}
###### Join rewriting
@@ -106,7 +106,7 @@ ###### Join rewriting
* Query:
-```sql
+{% highlight sql %}
SELECT empid
FROM depts
JOIN (
@@ -114,80 +114,80 @@ ###### Join rewriting
FROM emps
WHERE empid = 1) AS subq
ON depts.deptno = subq.deptno
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid
FROM emps
JOIN depts USING (deptno)
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT empid
FROM mv
WHERE empid = 1
-```
+{% endhighlight %}
###### Aggregate rewriting
* Query:
-```sql
+{% highlight sql %}
SELECT deptno
FROM emps
WHERE deptno > 10
GROUP BY deptno
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, deptno
FROM emps
WHERE deptno > 5
GROUP BY empid, deptno
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT deptno
FROM mv
WHERE deptno > 10
GROUP BY deptno
-```
+{% endhighlight %}
###### Aggregate rewriting (with aggregation rollup)
* Query:
-```sql
+{% highlight sql %}
SELECT deptno, COUNT(*) AS c, SUM(salary) AS s
FROM emps
GROUP BY deptno
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, deptno, COUNT(*) AS c, SUM(salary) AS s
FROM emps
GROUP BY empid, deptno
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT deptno, SUM(c), SUM(s)
FROM mv
GROUP BY deptno
-```
+{% endhighlight %}
###### Query partial rewriting
@@ -196,84 +196,84 @@ ###### Query partial rewriting
* Query:
-```sql
+{% highlight sql %}
SELECT deptno, COUNT(*)
FROM emps
GROUP BY deptno
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, depts.deptno, COUNT(*) AS c, SUM(salary) AS s
FROM emps
JOIN depts USING (deptno)
GROUP BY empid, depts.deptno
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT deptno, SUM(c)
FROM mv
GROUP BY deptno
-```
+{% endhighlight %}
###### View partial rewriting
* Query:
-```sql
+{% highlight sql %}
SELECT deptname, state, SUM(salary) AS s
FROM emps
JOIN depts ON emps.deptno = depts.deptno
JOIN locations ON emps.locationid = locations.locationid
GROUP BY deptname, state
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, deptno, state, SUM(salary) AS s
FROM emps
JOIN locations ON emps.locationid = locations.locationid
GROUP BY empid, deptno, state
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT deptname, state, SUM(s)
FROM mv
JOIN depts ON mv.deptno = depts.deptno
GROUP BY deptname, state
-```
+{% endhighlight %}
###### Union rewriting
* Query:
-```sql
+{% highlight sql %}
SELECT empid, deptname
FROM emps
JOIN depts ON emps.deptno = depts.deptno
WHERE salary > 10000
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, deptname
FROM emps
JOIN depts ON emps.deptno = depts.deptno
WHERE salary > 12000
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT empid, deptname
FROM mv
UNION ALL
@@ -281,34 +281,34 @@ ###### Union rewriting
FROM emps
JOIN depts ON emps.deptno = depts.deptno
WHERE salary > 10000 AND salary <= 12000
-```
+{% endhighlight %}
###### Union rewriting with aggregate
* Query:
-```sql
+{% highlight sql %}
SELECT empid, deptname, SUM(salary) AS s
FROM emps
JOIN depts ON emps.deptno = depts.deptno
WHERE salary > 10000
GROUP BY empid, deptname
-```
+{% endhighlight %}
* Materialized view definition:
-```sql
+{% highlight sql %}
SELECT empid, deptname, SUM(salary) AS s
FROM emps
JOIN depts ON emps.deptno = depts.deptno
WHERE salary > 12000
GROUP BY empid, deptname
-```
+{% endhighlight %}
* Rewriting:
-```sql
+{% highlight sql %}
SELECT empid, deptname, SUM(s)
FROM (
SELECT empid, deptname, s
@@ -320,7 +320,7 @@ ###### Union rewriting with aggregate
WHERE salary > 10000 AND salary <= 12000
GROUP BY empid, deptname) AS subq
GROUP BY empid, deptname
-```
+{% endhighlight %}
##### Limitations