[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-17。"],[],[],null,["# Monitor materialized views\n==========================\n\nYou can monitor [materialized view](/bigquery/docs/materialized-views-intro)\nusage and refresh jobs by viewing the BigQuery\n`INFORMATION_SCHEMA` view. To create a list of materialized views, see\n[List materialized views](/bigquery/docs/materialized-views-manage#list).\n\nMaterialized view `INFORMATION_SCHEMA` view\n-------------------------------------------\n\nTo discover materialized views, query the [`INFORMATION_SCHEMA.TABLES`\nview](/bigquery/docs/information-schema-tables). To retrieve the properties of a\nmaterialized view, query the\n[`INFORMATION_SCHEMA.TABLE_OPTIONS` view](/bigquery/docs/information-schema-table-options).\n\nMaterialized views are not listed in the [`INFORMATION_SCHEMA.VIEWS` views](/bigquery/docs/information-schema-views)\ntable.\n\nMonitor automatic refresh\n-------------------------\n\nThis section shows how to view [refresh details for materialized views](/bigquery/docs/materialized-views-manage#refresh).\n\n### View last refresh status\n\nTo retrieve the current status of materialized views, call the\n[`tables.get` method](/bigquery/docs/reference/rest/v2/tables/get), or query the\n[`INFORMATION_SCHEMA.MATERIALIZED_VIEWS` view](/bigquery/docs/information-schema-materialized-views).\n\nFor example: \n\n```googlesql\nSELECT\n table_name, last_refresh_time, refresh_watermark, last_refresh_status\nFROM\n `DATASET`.INFORMATION_SCHEMA.MATERIALIZED_VIEWS;\n```\n\nIf the value for `last_refresh_status` is not `NULL`, then the last automatic\nrefresh job failed. Manual refresh requests are not reflected here. Changes to\nbase tables can invalidate a materialized view definition, resulting in an error\nduring automatic refresh. For more information, see [Incremental\nupdates](/bigquery/docs/materialized-views-use#incremental_updates). For\nexample, if a column that is referenced by the materialized view gets dropped\nfrom the base table, then the `last_refresh_status` field returns an\n`invalidQuery` error. For more information, see [Error\nmessages](/bigquery/docs/error-messages).\n\n### List automatic refresh jobs\n\nTo list materialized view automatic refresh jobs, call the [`jobs.list`\nmethod](/bigquery/docs/reference/rest/v2/jobs/list). To retrieve details about\nthe jobs, call the [`jobs.get`\nmethod](/bigquery/docs/reference/rest/v2/jobs/get). You can also query the\n[`INFORMATION_SCHEMA.JOBS_BY_*` views](/bigquery/docs/information-schema-jobs) to\nget the jobs. Automatic refresh jobs contain the `materialized_view_refresh`\nprefix within the [job ID](/bigquery/docs/reference/rest/v2/Job#FIELDS.id) and\nare started by a BigQuery administrator account.\n\nFor example: \n\n```googlesql\nSELECT\n job_id, total_slot_ms, total_bytes_processed,\n materialized_view_statistics.materialized_view[SAFE_OFFSET(0)].rejected_reason\n AS full_refresh_reason\nFROM\n `region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT`\nWHERE\n job_id LIKE '%materialized_view_refresh_%'\nLIMIT 10;\n```\n\nTo monitor the cost of refresh jobs and adjust the automatic refresh interval if\nneeded, view the `total_bytes_processed` and `total_slot_ms` fields.\n\nFor example, if the ingestion rate in the base tables is relatively small, it\nmakes sense to refresh the view less often. If the underlying data\nchanges quickly, it makes sense to refresh more often.\n\nIf the base tables ingest data at predefined points in time, such as by using a\nnightly extract, transform, and load (ETL) pipeline, consider taking control of\nthe materialized view maintenance schedule as follows:\n\n1. [Disable automatic refresh](/bigquery/docs/materialized-views-manage#automatic-refresh).\n\n2. [Perform a manual refresh](/bigquery/docs/materialized-views-manage#manual-refresh),\n either as part of the ETL pipeline, or by configuring a scheduled query at\n specific times of the day.\n\n| **Note:** Table truncation, partition truncation, partition expiration, and `UPDATE`, `DELETE`, and `MERGE` data manipulation language (DML) statements on a base table can all invalidate their materialized views. If the materialized view is partitioned, then the modified partitions are invalidated; if not partitioned, then the whole materialized view is invalidated. For this reason, you might want to batch your DML statements and perform the manual refresh at the end of your query.\n\nFor more information on pricing for materialized views, see [materialized views\npricing](/bigquery/docs/materialized-views-intro#materialized_views_pricing).\n\nMonitor materialized view usage\n-------------------------------\n\nTo view the materialized view usage for a query job, you can call the\n[`jobs.get` method](/bigquery/docs/reference/rest/v2/jobs/get) or query the\n[`INFORMATION_SCHEMA.JOBS_BY_*` view](/bigquery/docs/information-schema-jobs),\nand view the `materialized_view_statistics` field. It provides details about the\nuse of materialized views by the query, including the following details:\n\n- Whether the materialized view was used.\n- If the materialized view was not used, [the reason it was rejected](/bigquery/docs/reference/rest/v2/Job#rejectedreason).\n\nFor example: \n\n```googlesql\nSELECT\n job_id, materialized_view_statistics\nFROM\n region-US.INFORMATION_SCHEMA.JOBS_BY_PROJECT\nWHERE\n job_id = '\u003cmy-query-job-id\u003e';\n```\n\nTo view the usage of a materialized view over time, query the\n[`INFORMATION_SCHEMA.JOBS_BY_*` views](/bigquery/docs/information-schema-jobs).\n\nFor example, the following query returns a summary of recent query jobs that\nuse the target materialized view: \n\n```googlesql\nSELECT\n mv.table_reference.dataset_id,\n mv.table_reference.table_id,\n MAX(job.creation_time) latest_job_time,\n COUNT(job_id) job_count\nFROM\n region-US.INFORMATION_SCHEMA.JOBS_BY_PROJECT job,\n UNNEST(materialized_view_statistics.materialized_view) mv\nWHERE\n job.creation_time \u003e TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 7 DAY)\n AND mv.table_reference.dataset_id = 'my_dataset'\n AND mv.table_reference.table_id = 'my_materialized_view'\n AND mv.chosen = TRUE\nGROUP BY 1, 2;\n```\n\nTroubleshoot slow queries with materialized views\n-------------------------------------------------\n\nIf your query uses materialized views and is running slower than expected,\ndo the following:\n\n1. Verify that the intended materialized views are actually being used by the query. For detailed instructions, see [Monitor materialized view usage](#monitor_materialized_view_usage).\n2. [Check the freshness of your materialized view](#view_last_refresh_status).\n3. Review the materialized view definition and the data it references and consider [techniques to optimize your materialized view usage](/bigquery/docs/materialized-views-create#considerations_when_creating_materialized_views)."]]