This topic describes how to query materialized views.
Query the definition of a materialized view
You can execute the SHOW CREATE TABLE statement to query the definition of a materialized view.
Here is an example:
Query the definition of the materialized view mv_tbl1.
SHOW CREATE TABLE mv_tbl1;
The return result is as follows:
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| mv_tbl1 | CREATE MATERIALIZED VIEW `mv_tbl1` DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 10 REFRESH FORCE ON DEMAND AS select `db_test`.`tbl1`.`col1` AS `col1`,`db_test`.`tbl1`.`col2` AS `col2` from `db_test`.`tbl1` where (`db_test`.`tbl1`.`col3` >= 20) | utf8mb4 | utf8mb4_general_ci |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set
Query information about materialized views by using views
You can query information about materialized views by using the following views:
| View | Description |
|---|---|
| DBA_MVIEWS | Displays information about materialized views. |
| DBA_MVREF_STATS_SYS_DEFAULTS | Displays the system default values of refresh statistics attributes for materialized views. |
| DBA_MVREF_STATS_PARAMS | Displays the refresh statistics attributes associated with each materialized view. |
| DBA_MVREF_RUN_STATS | Displays information about each refresh run of a materialized view, which is identified by the REFRESH_ID. |
| DBA_MVREF_STATS | Displays basic timing statistics about materialized view refreshes. |
| DBA_MVREF_CHANGE_STATS | Displays statistics about materialized view refreshes. |
| DBA_MVREF_STMT_STATS | Displays information about refresh statements. |
| DBA_SCHEDULER_JOBS | Displays information about all scheduler jobs in the database. |
Here is an example:
Query the background refresh task of the automatically refreshed materialized view mv_rc_swn1_tbl1 by using the DBA_SCHEDULER_JOBS view.
SELECT JOB_NAME,JOB_ACTION,START_DATE,REPEAT_INTERVAL,LAST_START_DATE,NEXT_RUN_DATE
FROM oceanbase.DBA_SCHEDULER_JOBS
WHERE JOB_ACTION like "%mv_rc_swn1_tbl1%";
The return result is as follows:
+----------------------------------+----------------------------------------------------------------------+----------------------------+--------------------------------+----------------------------+----------------------------+
| JOB_NAME | JOB_ACTION | START_DATE | REPEAT_INTERVAL | LAST_START_DATE | NEXT_RUN_DATE |
+----------------------------------+----------------------------------------------------------------------+----------------------------+--------------------------------+----------------------------+----------------------------+
| MVIEW_REFRESH$J_1125899908922625 | DBMS_MVIEW.refresh('db_test.mv_rc_swn1_tbl1', refresh_parallel => 1) | 2024-12-17 17:54:54.000000 | sysdate() + interval 30 minute | 2024-12-18 09:24:57.006246 | 2024-12-18 09:54:57.000000 |
+----------------------------------+----------------------------------------------------------------------+----------------------------+--------------------------------+----------------------------+----------------------------+
1 row in set