本頁面中的部分或全部資訊可能不適用於 Trusted Cloud by S3NS。
使用 BigQuery 進階執行階段
本文說明如何啟用及停用 BigQuery 進階執行階段,以及如何評估進階執行階段對查詢效能的影響。
角色和權限
如要取得指定設定所需的權限,請要求管理員授予您專案或機構的 BigQuery 管理員 (roles/bigquery.admin
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
您或許還可透過自訂角色或其他預先定義的角色取得必要權限。
功能
在 BigQuery 專案中啟用進階執行階段後,查詢處理器就會開啟相關功能,以減少查詢延遲和運算單元耗用量,且不會產生額外費用。
強化向量化
向量化執行作業是一種查詢處理模型,可處理與 CPU 快取大小一致的資料區塊,並使用單指令多資料 (SIMD) 指令。強化向量化功能可將 BigQuery 中的向量化查詢執行作業,擴展至查詢處理的下列層面:
- 透過運用 Capacitor 儲存格式中的專用資料編碼,即可對編碼資料執行篩選器評估作業。
- 專用編碼會透過查詢計畫傳播,因此在資料編碼時,系統就能處理更多資料。
- BigQuery 實作運算式摺疊功能來評估決定性函式和常數運算式,可將複雜述詞簡化為常數值。
短查詢最佳化
BigQuery 通常會在分散式環境中執行查詢,並使用隨機播放中繼層。短查詢最佳化
動態識別可做為單一階段執行的查詢,縮短延遲時間並減少運算單元用量。如果查詢是在單一階段執行,就能更有效地使用專用編碼。搭配選用工作建立模式使用時,這些最佳化措施最有效,可將工作啟動、維護和結果擷取延遲時間降到最低。
短查詢最佳化功能的適用資格不固定,會受到下列因素影響:
- 預測的資料掃描大小。
- 所需資料移動量。
- 查詢篩選器的選擇性。
- 儲存空間中資料的類型和實體配置。
- 整體查詢結構。
- 過去查詢執行的歷史統計資料。
啟用進階執行階段
如要為專案或機構啟用進階執行階段,請使用 ALTER PROJECT
或 ALTER ORGANIZATION
陳述式變更預設設定。在陳述式中,將 query_runtime
引數設為 'advanced'
。例如:
ALTER PROJECT PROJECT_NAME
SET OPTIONS (
`region-LOCATION
.query_runtime` = 'advanced'
);
更改下列內容:
PROJECT_NAME
:專案名稱
LOCATION
:專案的位置
變更可能需要幾分鐘才會生效。
啟用進階執行階段後,專案或機構中的合格查詢就會使用進階執行階段,無論查詢作業是由哪位使用者建立都一樣。
停用進階執行階段
如要為專案或機構停用進階執行階段,請使用 ALTER PROJECT
或 ALTER ORGANIZATION
陳述式變更預設設定。在陳述式中,將 query_runtime
引數設為 NULL
。例如:
ALTER PROJECT PROJECT_NAME
SET OPTIONS (
`region-LOCATION
.query_runtime` = NULL
);
更改下列內容:
PROJECT_NAME
:專案名稱
LOCATION
:專案的位置
變更可能需要幾分鐘才會生效。
您可以使用管理工作探索器和INFORMATION_SCHEMA
檢視畫面,評估進階執行階段對查詢執行時間和運算單元用量的影響。
請按照下列步驟評估啟用和未啟用進階執行階段時的查詢效能:
前往 Trusted Cloud 控制台的「BigQuery」頁面。
前往「BigQuery」
在查詢編輯器中開啟新分頁。
停用該查詢分頁的快取查詢結果。
在查詢分頁中輸入或複製測試查詢。
執行測試查詢幾次,建立基準效能。每次執行後,請依下列方式判斷查詢效能指標:
- 在管理工作探索器中查看查詢執行詳細資料。
在新的查詢分頁中執行下列查詢,從 INFORMATION_SCHEMA.JOBS_BY_USER
檢視畫面 擷取工作成效資料:
SELECT
job_id,
end_time - start_time AS duration,
total_slot_ms,
query
FROM
`region-us`.INFORMATION_SCHEMA.JOBS_BY_USER
WHERE
creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND job_type='QUERY'
AND total_slot_ms IS NOT NULL
ORDER BY
creation_time DESC,
query ASC
LIMIT 1000;
啟用進階執行階段。
重複步驟 5。
比較啟用進階執行階段前後的測試查詢查詢延遲時間和時段用量指標。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-17 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-17 (世界標準時間)。"],[],[],null,["# Use the BigQuery advanced runtime\n=================================\n\n|\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n| **Note:** To provide feedback or request support for this feature, send email to [bqarfeedback@google.com](mailto:bqarfeedback@google.com).\n\nThis document describes how to enable and disable the BigQuery\nadvanced runtime, and how to evaluate the advanced runtime's effects on your\nquery performance.\n\nRoles and permissions\n---------------------\n\n\nTo get the permissions that\nyou need to specify a configuration setting,\n\nask your administrator to grant you the\n\n\n[BigQuery Admin](/iam/docs/roles-permissions/bigquery#bigquery.admin) (`roles/bigquery.admin`)\nIAM role on your project or organization.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nFeatures\n--------\n\nEnabling the advanced runtime on a BigQuery project turns on\nfeatures in the query processor that reduce query latency and slot consumption\nat no additional cost.\n\n### Enhanced vectorization\n\nVectorized execution is a query processing model that operates on columns of\ndata in blocks that align with CPU cache size and uses\nsingle instruction, multiple data (SIMD) instructions. Enhanced vectorization\nextends the vectorized query execution in BigQuery to\nthe following aspects of query processing:\n\n- By leveraging specialized data encodings within the Capacitor storage format, filter evaluation operations can be executed on the encoded data.\n- Specialized encodings are propagated through the query plan, which allows more data to be processed while it's still encoded.\n- By implementing expression folding to evaluate deterministic functions and constant expressions, BigQuery can simplify complex predicates into constant values.\n\n### Short query optimizations\n\nBigQuery typically executes queries in a distributed environment\nusing a shuffle intermediate layer. Short query optimizations\ndynamically identify queries that can be run as a\nsingle stage, reducing latency and slot consumption. Specialized encodings can\nbe used more effectively when a query is run in a single stage.\nThese optimizations are most effective when used with\n[optional job creation mode](/bigquery/docs/running-queries#optional-job-creation),\nwhich minimizes job startup, maintenance, and result retrieval latency.\n\nEligibility for short query optimization is dynamic and influenced by\nthe following factors:\n\n- The predicted size of the data scan.\n- The amount of data movement required.\n- The selectivity of query filters.\n- The type and physical layout of the data in storage.\n- The overall query structure.\n- The [historical statistics](/bigquery/docs/history-based-optimizations) of past query executions.\n\nEnable the advanced runtime\n---------------------------\n\nTo enable the advanced runtime for your project or organization, use the\n[`ALTER PROJECT`](/bigquery/docs/reference/standard-sql/data-definition-language#alter_project_set_options_statement)\nor\n[`ALTER ORGANIZATION`](/bigquery/docs/reference/standard-sql/data-definition-language#alter_organization_set_options_statement)\nstatement to change the\n[default configuration](/bigquery/docs/default-configuration). In the\nstatement, set the `query_runtime` argument to `'advanced'`. For example: \n\n ALTER PROJECT \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e\n SET OPTIONS (\n `region-\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e.query_runtime` = 'advanced'\n );\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: the name of the project\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the location of the project\n\nIt can take several minutes for the change to take effect.\n\nOnce you've enabled the advanced runtime, qualifying queries in the project or organization\nuse the advanced runtime regardless of which user created the\nquery job.\n\nDisable the advanced runtime\n----------------------------\n\nTo disable the advanced runtime for your project or organization, use the\n`ALTER PROJECT` or `ALTER ORGANIZATION` statement to change the\n[default configuration](/bigquery/docs/default-configuration). In the\nstatement, set the `query_runtime` argument to `NULL`. For example: \n\n ALTER PROJECT \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e\n SET OPTIONS (\n `region-\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e.query_runtime` = NULL\n );\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: the name of the project\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the location of the project\n\nIt can take several minutes for the change to take effect.\n\nEvaluate query performance\n--------------------------\n\nYou can use the\n[administrative job explorer](/bigquery/docs/admin-jobs-explorer) and\n[`INFORMATION_SCHEMA` views](/bigquery/docs/information-schema-intro) to\nevaluate the effect of the advanced runtime on query execution time and slot\nusage.\n\nFollow these steps to evaluate query performance with and without the\nadvanced runtime enabled:\n\n1. In the Google Cloud console, go to the **BigQuery** page.\n\n [Go to BigQuery](https://console.cloud.google.com/bigquery)\n2. Open a new tab in the query editor.\n\n3. [Disable the use of cached query results](/bigquery/docs/cached-results#disabling_retrieval_of_cached_results)\n for that query tab.\n\n4. Type or copy your test queries into the query tab.\n\n5. Run your test queries a few times to establish baseline performance.\n After each run, determine the query performance metrics as follows:\n\n 1. [View the query execution details](/bigquery/docs/admin-jobs-explorer#view_query_execution_details) in the administrative job explorer.\n 2. Retrieve job performance data from the\n [`INFORMATION_SCHEMA.JOBS_BY_USER` view](/bigquery/docs/information-schema-jobs-by-user)\n by running the following query in a new query tab:\n\n SELECT\n job_id,\n end_time - start_time AS duration,\n total_slot_ms,\n query\n FROM\n `region-us`.INFORMATION_SCHEMA.JOBS_BY_USER\n WHERE\n creation_time \u003e TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n AND job_type='QUERY'\n AND total_slot_ms IS NOT NULL\n ORDER BY\n creation_time DESC,\n query ASC\n LIMIT 1000;\n\n6. [Enable the advanced runtime](#enable-advanced-runtime).\n\n7. Repeat Step 5.\n\n8. Compare the query latency and slot usage metrics for the test queries\n from before and after you enabled the advanced runtime."]]