首批通过分布式安全可靠测评,为关键业务系统打造
查询物化视图
更新时间:2024-07-16 23:00:00
本节主要介绍物化视图的查看方法。
查看物化视图定义
使用 SHOW CREATE TABLE 语句查看物化视图定义。
示例如下:
查看物化视图 mv_tbl1 的定义。
obclient [test]> SHOW CREATE TABLE mv_tbl1;
返回结果如下:
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| mv_tbl1 | CREATE MATERIALIZED VIEW `mv_tbl1` AS select `test`.`tbl1`.`id` AS `id`,`test`.`tbl1`.`name` AS `name` from `test`.`tbl1` where (`test`.`tbl1`.`age` >= 20) | utf8mb4 | utf8mb4_general_ci |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set
使用视图查看物化视图信息
可以通过系统视图来查看物化视图的相关信息,可查看的视图有:
| 视图名 | 功能描述 |
|---|---|
| DBA_MVIEWS | 展示物化视图信息。 |
| DBA_MVREF_STATS_SYS_DEFAULTS | 物化视图刷新历史统计属性的系统范围默认值。 |
| DBA_MVREF_STATS_PARAMS | 展示与每个物化视图关联的刷新统计信息属性。 |
| DBA_MVREF_RUN_STATS | 展示物化视图的每次刷新运行的信息,每次运行均由 REFRESH_ID 标识。 |
| DBA_MVREF_STATS | 展示物化视图刷新的基本计时统计信息。 |
| DBA_MVREF_CHANGE_STATS | 展示物化视图刷新相关的统计信息。 |
| DBA_MVREF_STMT_STATS | 展示刷新语句关联的信息。 |
示例如下:
SELECT owner, mview_name, container_name, query, query_len FROM oceanbase.DBA_MVIEWS;
返回结果如下:
+---------+--------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+
| owner | mview_name | container_name | query | query_len |
+---------+--------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+
| test_db | mv_tbl1_tbl2 | mv_tbl1_tbl2 | select `t1`.`id` AS `id`,`t1`.`name` AS `name`,`t2`.`notes` AS `notes` from `test_db`.`tbl1` `t1`,`test_db`.`tbl2` `t2` where (`t1`.`id` = `t2`.`tbl1_id`) | 154 |
| test_db | mv3_tbl1 | mv3_tbl1 | select `test_db`.`tbl1`.`id` AS `id`,`test_db`.`tbl1`.`name` AS `name` from `test_db`.`tbl1` where (`test_db`.`tbl1`.`age` >= 20) | 129 |
| test_db | mv2_tbl1 | mv2_tbl1 | select `test_db`.`tbl1`.`id` AS `id`,`test_db`.`tbl1`.`name` AS `name` from `test_db`.`tbl1` where (`test_db`.`tbl1`.`age` >= 20) | 129 |
| test_db | mv1_tbl1 | mv1_tbl1 | select `test_db`.`tbl1`.`id` AS `id`,`test_db`.`tbl1`.`name` AS `name` from `test_db`.`tbl1` where (`test_db`.`tbl1`.`age` >= 20) | 129 |
| test_db | mv_tbl3 | mv_tbl3 | select `test_db`.`tbl3`.`col2` AS `col2`,count(*) AS `cnt`,count(`test_db`.`tbl3`.`col3`) AS `cnt_col3`,sum(`test_db`.`tbl3`.`col3`) AS `sum_col3` from `test_db`.`tbl3` group by `test_db`.`tbl3`.`col2` | 201 |
| test_db | mv_tbl1 | mv_tbl1 | select `test_db`.`tbl1`.`id` AS `id`,`test_db`.`tbl1`.`name` AS `name` from `test_db`.`tbl1` where (`test_db`.`tbl1`.`age` >= 20) | 129 |
+---------+--------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+
6 rows in set