Skip to content

Commit

Permalink
docs: add a step in AQUMV doc and move doc dir
Browse files Browse the repository at this point in the history
  • Loading branch information
TomShawn authored and tuhaihe committed Dec 17, 2024
1 parent 7397ff2 commit e3a5974
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
18 changes: 12 additions & 6 deletions docs/performance/use-auto-materialized-view-to-answer-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ Since v1.5.0, Cloudberry Database supports automatically using materialized view

To enable AQUMV, you need to create a materialized view and set the value of the system parameter `enable_answer_query_using_materialized_views` to `ON`. The following example compares the results of the same complex query without AQUMV and with AQUMV.

1. Create a table `aqumv_t1`.
1. Turn off the GPORCA planner to use the Postgres-based planner.

```sql
SET optimizer TO off;
```

2. Create a table `aqumv_t1`.

```sql
CREATE TABLE aqumv_t1(c1 INT, c2 INT, c3 INT) DISTRIBUTED BY (c1);
```

2. Insert data into the table and collect statistics from the table.
3. Insert data into the table and collect statistics from the table.

```sql
INSERT INTO aqumv_t1 SELECT i, i+1, i+2 FROM generate_series(1, 100000000) i;
ANALYZE aqumv_t1;
```

3. Execute a query without enabling AQUMV. The query takes 7384.329 ms.
4. Execute a query without enabling AQUMV. The query takes 7384.329 ms.

```sql
SELECT SQRT(ABS(ABS(c2) - c1 - 1) + ABS(c2)) FROM aqumv_t1 WHERE c1 > 30 AND c1 < 40 AND SQRT(ABS(c2)) > 5.8;
Expand Down Expand Up @@ -57,7 +63,7 @@ To enable AQUMV, you need to create a materialized view and set the value of the
(4 rows)
```

4. Create a materialized view `mvt1` based on `aqumv_t1` and collect statistics on the view.
5. Create a materialized view `mvt1` based on `aqumv_t1` and collect statistics on the view.

```sql
CREATE INCREMENTAL MATERIALIZED VIEW mvt1 AS SELECT c1 AS mc1, c2 AS mc2, ABS(c2) AS mc3, ABS(ABS(c2) - c1 - 1) AS mc4
Expand All @@ -66,13 +72,13 @@ To enable AQUMV, you need to create a materialized view and set the value of the
ANALYZE mvt1;
```

5. Enable the AQUMV-related configuration parameter.
6. Enable the AQUMV-related configuration parameter.

```sql
SET enable_answer_query_using_materialized_views = ON;
```

6. Now AQUMV is enabled. Execute the same query again, which takes only 45.701 ms.
7. Now AQUMV is enabled. Execute the same query again, which takes only 45.701 ms.

```sql
SELECT SQRT(ABS(ABS(c2) - c1 - 1) + ABS(c2)) FROM aqumv_t1 WHERE c1 > 30 AND c1 < 40 AND SQRT(ABS(c2)) > 5.8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ title: 并行创建 AO/AOCO 表与刷新物化视图

## 相关其他特性

[自动使用物化视图进行查询优化](/i18n/zh/docusaurus-plugin-content-docs/current/use-auto-materialized-view-to-answer-queries.md)
[自动使用物化视图进行查询优化](/i18n/zh/docusaurus-plugin-content-docs/current/performance/use-auto-materialized-view-to-answer-queries.md)

[增量物化视图说明文档](/i18n/zh/docusaurus-plugin-content-docs/current/use-incremental-materialized-view.md)
[增量物化视图说明文档](/i18n/zh/docusaurus-plugin-content-docs/current/performance/use-incremental-materialized-view.md)
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ title: 自动使用物化视图进行查询优化

要启用 AQUMV 功能,需要先创建物化视图,并将系统参数 `enable_answer_query_using_materialized_views` 的值设为 `ON`。下面是不使用 AQUMV 与使用 AQUMV 执行相同复杂查询的结果对比。

1. 创建表格 `aqumv_t1`
1. 关闭 GPORCA 执行优化器,使用基于 Postgres 的执行优化器。

```sql
SET optimizer TO off;
```

2. 创建表格 `aqumv_t1`

```sql
CREATE TABLE aqumv_t1(c1 INT, c2 INT, c3 INT) DISTRIBUTED BY (c1);
```

2. 往表中插入数据,并收集表上的统计信息。
3. 往表中插入数据,并收集表上的统计信息。

```sql
INSERT INTO aqumv_t1 SELECT i, i+1, i+2 FROM generate_series(1, 100000000) i;
ANALYZE aqumv_t1;
```

3. 在不开启 AQUMV 的情况下执行查询,耗时 7384.329 ms。
4. 在不开启 AQUMV 的情况下执行查询,耗时 7384.329 ms。

```sql
SELECT SQRT(ABS(ABS(c2) - c1 - 1) + ABS(c2)) FROM aqumv_t1 WHERE c1 > 30 AND c1 < 40 AND SQRT(ABS(c2)) > 5.8;
Expand Down Expand Up @@ -57,7 +63,7 @@ title: 自动使用物化视图进行查询优化
(4 rows)
```

4. 现在基于 `aqumv_t1` 创建物化视图 `mvt1`,并收集该视图的统计信息。
5. 现在基于 `aqumv_t1` 创建物化视图 `mvt1`,并收集该视图的统计信息。

```sql
CREATE INCREMENTAL MATERIALIZED VIEW mvt1 AS SELECT c1 AS mc1, c2 AS mc2, ABS(c2) AS mc3, ABS(ABS(c2) - c1 - 1) AS mc4
Expand All @@ -66,13 +72,13 @@ title: 自动使用物化视图进行查询优化
ANALYZE mvt1;
```

5. 开启 AQUMV 相关配置参数:
6. 开启 AQUMV 相关配置参数:

```sql
SET enable_answer_query_using_materialized_views = ON;
```

6. 现在 AQUMV 已开启,再次执行相同的表查询,耗时 45.701 ms。
7. 现在 AQUMV 已开启,再次执行相同的表查询,耗时 45.701 ms。

```sql
SELECT SQRT(ABS(ABS(c2) - c1 - 1) + ABS(c2)) FROM aqumv_t1 WHERE c1 > 30 AND c1 < 40 AND SQRT(ABS(c2)) > 5.8;
Expand Down Expand Up @@ -127,6 +133,6 @@ AQUMV 是通过对查询树进行等效转换来实现查询优化的。

## 相关其他功能

[并行创建 AO 表与刷新物化视图](/i18n/zh/docusaurus-plugin-content-docs/current/parallel-create-ao-refresh-mv.md)
[并行创建 AO 表与刷新物化视图](/i18n/zh/docusaurus-plugin-content-docs/current/performance/parallel-create-ao-refresh-mv.md)

[增量物化视图说明文档](/i18n/zh/docusaurus-plugin-content-docs/current/use-incremental-materialized-view.md)
[增量物化视图说明文档](/i18n/zh/docusaurus-plugin-content-docs/current/performance/use-incremental-materialized-view.md)
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ CREATE [INCREMENTAL] MATERIALIZED VIEW [ IF NOT EXISTS ] table_name

# 其他相关功能

[并行创建 AO 表与刷新物化视图](/i18n/zh/docusaurus-plugin-content-docs/current/parallel-create-ao-refresh-mv.md)
[并行创建 AO 表与刷新物化视图](/i18n/zh/docusaurus-plugin-content-docs/current/performance/parallel-create-ao-refresh-mv.md)

[自动使用物化视图进行查询优化](/i18n/zh/docusaurus-plugin-content-docs/current/use-auto-materialized-view-to-answer-queries.md)
[自动使用物化视图进行查询优化](/i18n/zh/docusaurus-plugin-content-docs/current/performance/use-auto-materialized-view-to-answer-queries.md)

0 comments on commit e3a5974

Please sign in to comment.