本页面上的部分或全部信息可能不适用于 Trusted Cloud by S3NS。
使用 BigQuery 高级运行时
本文档介绍了如何启用和停用 BigQuery 高级运行时,以及如何评估高级运行时对查询性能的影响。
角色与权限
如需获得指定配置设置所需的权限,请让您的管理员为您授予项目或组织的 BigQuery Admin (roles/bigquery.admin
) IAM 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
您也可以通过自定义角色或其他预定义角色来获取所需的权限。
特性
在 BigQuery 项目中启用高级运行时,即可在查询处理器中开启相关功能,从而在不产生额外费用的情况下缩短查询延迟时间并减少槽消耗量。
增强型矢量化
矢量化执行是一种查询处理模型,可对与 CPU 缓存大小对齐的数据块中的数据列进行操作,并使用单指令多数据 (SIMD) 指令。增强型矢量化功能将 BigQuery 中的矢量化查询执行扩展到查询处理的以下方面:
- 通过利用 Capacitor 存储格式中的专用数据编码,可以对编码后的数据执行过滤条件评估操作。
- 专用编码会通过查询计划进行传播,从而可以在数据仍处于编码状态时处理更多数据。
- 通过实现表达式折叠来评估确定性函数和常量表达式,BigQuery 可以将复杂的谓词简化为常量值。
短查询优化
BigQuery 通常会在分布式环境中使用 Shuffle 中间层来执行查询。短查询优化功能可动态识别可以作为单个阶段运行的查询,从而缩短延迟时间并减少槽消耗。当查询在单个阶段运行时,可以更有效地使用专用编码。与可选作业创建模式搭配使用时,这些优化效果最为显著,因为该模式可最大限度地缩短作业启动、维护和结果检索延迟时间。
短查询优化功能的适用条件是动态变化的,受以下因素的影响:
- 数据扫描的预测大小。
- 所需的数据迁移量。
- 查询过滤条件的选择性。
- 存储空间中数据的类型和物理布局。
- 查询的总体结构。
- 过去查询执行的历史统计信息。
启用高级运行时
如需为项目或组织启用高级运行时,请使用 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
视图来评估高级运行时对查询执行时间和 slot 使用情况的影响。
请按照以下步骤评估启用和未启用高级运行时时的查询性能:
在 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 步。
比较启用高级运行时之前和之后测试查询的查询延迟时间和 slot 使用情况指标。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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."]]