This section describes how to query materialized views.
Query the definition of a materialized view
Use the SHOW CREATE TABLE statement to query the definition of a materialized view.
Example:
Query the definition of the materialized view mv_tbl1.
SHOW CREATE TABLE mv_tbl1;
The 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 materialized view information by using views
You can query system views for information about materialized views. The available views are:
View name |
Feature description |
|---|---|
| DBA_MVIEWS | Displays materialized view information. |
| DBA_MVREF_STATS_SYS_DEFAULTS | The system-wide default value for the materialized view refresh history statistics attribute. |
| DBA_MVREF_STATS_PARAMS | Displays the refresh statistics attributes associated with each materialized view. |
| DBA_MVREF_RUN_STATS | Displays information about each refresh operation of a materialized view, with each operation identified by a REFRESH_ID. |
| DBA_MVREF_STATS | Displays basic timing statistics for materialized view refreshes. |
| DBA_MVREF_CHANGE_STATS | Displays statistics related to materialized view refresh. |
| DBA_MVREF_STMT_STATS | Displays information associated with the refresh statement. |
| DBA_SCHEDULER_JOBS | Displays information about all scheduler jobs in the database. |
Example:
Query the DBA_SCHEDULER_JOBS view for information about the background refresh tasks of the auto-refresh materialized view mv_rc_swn1_tbl1.
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 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