Bigquery Optimization
GoogleOfficialPublished by Google
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The bigquery-optimization skill provides a structured approach to improving the cost-efficiency and performance of Google BigQuery environments. It covers capacity planning for Editions, storage lifecycle and billing model management, table partitioning and clustering strategies, and SQL query refinement. The skill emphasizes manual configuration through the Cloud Console for financial changes while providing templates and guidance for technical optimizations like materialized views, search indexes, and BI Engine acceleration.
What it does
- Models cost-efficiency for BigQuery Editions and reservation rightsizing.
- Provides DDL templates for table partitioning, clustering, and storage lifecycle management.
- Guides the evaluation of physical vs. logical storage billing models.
- Offers strategies for implementing acceleration structures like materialized views and search indexes.
- Provides workflows for optimizing individual SQL queries to reduce slot-time and data read.
- Includes strict guardrails for regional scope and cost-framing terminology.
When to use it
- When you need to optimize BigQuery storage costs or evaluate billing model changes.
- When designing table schemas to improve query performance via partitioning and clustering.
- When migrating workloads between On-Demand and Editions.
- When troubleshooting high-cost queries or identifying opportunities for BI Engine acceleration.
- When managing data retention through TTL and partition expiration policies.
Advantages
- Standardizes optimization practices across capacity, storage, and query layers.
- Reduces manual research by providing clear decision frameworks for acceleration tools.
- Ensures safe operations by requiring manual execution for financial or resource-intensive changes.
- Promotes consistent regional scoping and attribution for all operations.
Usage examples
- “How can I optimize storage costs for my dataset in us-east1?”
- The agent will guide you through evaluating your storage billing model (logical vs. physical), checking compression ratios, and implementing lifecycle policies to expire old partitions.
- “My dashboard is slow; should I use BI Engine or a materialized view?”
- The agent will analyze your use case to recommend BI Engine for in-memory acceleration, materialized views for pre-aggregated data, or a combination of both.
- “Generate DDL to partition my large unpartitioned table by day.”
- The agent will provide the necessary CREATE TABLE or CTAS statements to migrate your data to a partitioned structure while enforcing partition filters.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/google/bigquery-optimization/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip bigquery-optimization.zip -d .agents/skills
Documentation by Google
BigQuery Optimization Workflow
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-optimization)"
and append agent-skills/1.0 (skill:bigquery-optimization) to User-Agent headers.
Prerequisites & Environment Setup
Before executing optimization analyses, evaluating editions, or applying DDL modifications:
Google Cloud SDK: Ensure the Google Cloud SDK is installed and configured.
Project Selection: Set the active Google Cloud project:
gcloud config set project {project_id}API Enablement: Ensure BigQuery and BigQuery Reservation APIs are enabled:
gcloud services enable \ bigquery.googleapis.com bigqueryreservation.googleapis.comAuthentication: Authenticate the environment:
CLI tools and
bqcommands:gcloud auth loginSDKs and automation:
gcloud auth application-default loginService accounts: Set
GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
Billing & IAM Roles:
Verify an active Google Cloud Billing account is attached to
{project_id}.Ensure appropriate IAM roles:
roles/bigquery.adminorroles/bigquery.resourceAdmin: Reservation and capacity commitment management.roles/bigquery.dataEditororroles/bigquery.admin: Modifying table schemas, partitioning, clustering, and storage billing models.roles/bigquery.jobUser: Running evaluation queries.
Companion Skills Installation: This skill is part of a 3-pillar operations suite (
bigquery-observability,bigquery-optimization,bigquery-troubleshooting). If any companion skill is not yet installed in your environment, install the full suite:npx skills add google/skills --skill bigquery-observability --skill bigquery-optimization --skill bigquery-troubleshooting(If
bigquery-observabilityis not installed, use the self-contained baseline formulas and query templates provided directly in the reference sections below).
Workflows
Determine the optimization focus of the user's request and follow the relevant workflow:
Telemetry & Observability Baseline: For direct raw usage telemetry,
INFORMATION_SCHEMAqueries, and baseline metric calculations, consult bigquery-observability (bigquery_observability). If thebigquery-observabilitycompanion skill is not available in the active environment, all optimization guidelines, DDL templates, and decision models across this skill and its reference guides are fully self-contained.Capacity & Editions Modeling: Evaluate the cost-efficiency of migrating workloads from On-Demand to Editions, as well as rightsizing active Edition reservations, baseline commitments, and autoscaling caps.
Instructions: Read
references/capacity_planning_editions.mdto provide deep links to BigQuery's built-in recommendation UIs (e.g., Slot Estimator) and guide the user through UI navigation: 1. navigate to the Slot Estimator tab, 2. select 'On-Demand' as the source to analyze historical query volume, and 3. review the Cost-Optimized Recommendations and Slot Usage Chart.
Table & Storage Optimization: Optimize storage costs from a billing model, physical layout, and lifecycle perspective.
Billing Architecture: Read
references/storage_billing_models.mdfor guidance on evaluating aggregate compression ratios (e.g. >2:1 threshold in US) to recommend Physical vs. Logical billing, noting that the break-even ratio depends on specific regional rates and custom enterprise contracts. When providingTABLE_STORAGEqueries, always scope withWHERE table_schema = '{dataset_id}', use the regional dataset view, and warn that 0 rows indicates a region mismatch or lack of native tables rather than zero billable usage.Partitioning & Clustering Strategy: Read
references/table_partitioning_clustering.mdto generate production DDL templates (CREATE TABLE, CTAS migrations for unpartitioned tables, and modifying clustering specifications), enforce pruning withrequire_partition_filter = true, and manage partition limits (up to 10,000 partitions/table).Lifecycle Management: Read
references/storage_lifecycle_management.mdto pinpoint inactive data and define precise Time-to-Live (TTL) partition expirations, dataset expirations, and Time Travel window reductions.Acceleration Structures: Read
references/search_indexes.mdto decide when to propose a search index for selective lookups overSTRINGorJSONdata, write theCREATE SEARCH INDEXDDL, and tell the user how to verify index coverage and usage. Readreferences/materialized_views.mdto decide when to propose a materialized view for repeated aggregations or joins over large base tables, write theCREATE MATERIALIZED VIEWDDL, and tell the user how to verify that smart tuning uses it. Readreferences/bi_engine.mdto decide when to propose BI Engine vs. Materialized Views for BI dashboard acceleration, diagnosePARTIALorDISABLEDBI Engine fallback reasons (bi_engine_statistics), and combine BI Engine with materialized views that pre-join or pre-aggregate the data.
SQL Optimization: Optimize individual SQL queries to reduce slot-time and the amount of data read.
Instructions: Follow the instructions in
references/sql_optimization.mdto provide recommendations to the user on how to rewrite their SQL query to reduce slot-time and the amount of data read.
Execution Guardrails
Terminology & Cost Framing: Never promise or guarantee "cost-reduction" or "reducing expenditure." Always frame recommendations using the terminology "optimizing your bill" or "improving cost-efficiency."
Explicit Scope Framing & Region Resolution: Always state the target
project_idandregionat the very top of your response so the user immediately knows the exact scope being evaluated. Follow this 3-tier resolution hierarchy:Explicit Region: Use the region specified in the user's prompt (e.g.,
europe-west1).Contextual Region: Resolve the region from the specific dataset or resource mentioned in the context.
Unspecified Fallback: Default to
us/region-us, explicitly state thatuswas assumed as the default, and instruct the user to substitute their region if their resources reside elsewhere. Region Formatting: In Cloud Console deep links, use the region identifier directly (e.g.,region=us,region=europe-west1). In SQL queries againstINFORMATION_SCHEMA, use the regional dataset qualifier (e.g.,region-us,region-europe-west1).
Zero-Row Result Guard: If querying
TABLE_STORAGEwithWHERE table_schema = '{dataset_id}'returns 0 rows, do not proceed with an empty or zero-usage evaluation. Treat this as an indicator that the dataset may reside in a different region or have no native tables; stop and prompt the user to confirm the dataset's regional location.Populate Concrete Parameters: When generating URLs and SQL queries, always substitute known
project_idandregionvalues directly into the code and links. Never leave literal{project_id}or{location}placeholders for the user to manually edit.No Autonomous Purchasing or Financial Mutations: Never provide the user with executable scripts (e.g.,
gcloudorbqshell commands likebq update --storage_billing_model=...) designed to autonomously purchase annual commitments, alter edition tier bindings, or mutate storage billing models. Always guide the user to execute commitment purchases, reservation changes, and storage billing model updates manually via the Cloud Console UI.
Files
- ATTRIBUTION.mdAdded by AutoGineer860 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md9.3 KiB
- references/attribution.md1.9 KiB
- references/bi_engine.md7.3 KiB
- references/capacity_planning_editions.md7.0 KiB
- references/materialized_views.md4.9 KiB
- references/search_indexes.md4.1 KiB
- references/sql_optimization.md23.5 KiB
- references/storage_billing_models.md6.2 KiB
- references/storage_lifecycle_management.md2.2 KiB
- references/table_partitioning_clustering.md15.3 KiB
references/bi_engine.md
BI Engine Acceleration Strategy
Architectural guidelines, eligibility constraints, and remediation workflows for accelerating BI dashboard queries using BigQuery BI Engine.
Table of Contents
1. When to Propose BI Engine vs. Materialized Views (Lines 19-43)
2. BI Engine Capacity & Preferred Tables (Lines 45-61)
3. Limitations & Fallback Causes (
PARTIALorDISABLED) (Lines 63-86)4. Remediating BI Engine Fallback with Materialized Views (Lines 88-110)
5. Telemetry & Data Retrieval Reference (Lines 112-126)
1. When to Propose BI Engine vs. Materialized Views
Use BI Engine and Materialized Views together or independently depending on the bottleneck:
<!-- mdformat off -->
| Dimension | BigQuery BI Engine | Materialized Views (CREATE MATERIALIZED VIEW) | Combined (BI Engine + Materialized View) |
|---|---|---|---|
| Primary Goal | Accelerate BI dashboard queries from tools such as Looker, Data Studio (formerly Looker Studio), or Tableau. | Precompute and store aggregated results (such as SUM and COUNT) for queries that repeatedly aggregate large base tables. | Accelerate dashboards over a materialized view that pre-joins or pre-aggregates the data, so the same joins are not performed for each query. |
| Mechanism | In-memory analysis service that caches only the queried parts of columns and partitions. | BigQuery automatically adds incremental base-table changes to the view; smart tuning can reroute eligible base-table queries to it. | The materialized view joins and flattens (or pre-aggregates) the data, and BI Engine accelerates queries to the view. |
<!-- mdformat on -->
Decision Rule:
Propose BI Engine when users analyze data with BI tools (such as Looker, Data Studio, or Tableau), or when a subset of tables is queried more frequently or backs high-visibility dashboards (designate those tables as preferred tables).
Propose a Materialized View when queries repeatedly aggregate or join large base tables.
Propose Both Together when dashboards repeatedly join or aggregate large tables: use a materialized view to pre-join or pre-aggregate the data, and mark the view and its base tables as preferred tables. If the dashboard only displays recent data, also partition the tables by time so that only the latest partitions are loaded into memory.
2. BI Engine Capacity & Preferred Tables
Capacity & Cost: You incur costs for the reservation that you create for BI Engine capacity.
Configuring BI Engine Reservations & Preferred Tables:
Never execute CLI scripts to purchase or mutate BI Engine capacity reservations autonomously. Guide the user to configure BI Engine capacity or Preferred Tables in the Google Cloud Console under BigQuery > Administration > BI Engine:
https://console.cloud.google.com/bigquery/admin/bi-engine?project={project_id}Preferred Tables: If a subset of tables is queried more frequently or backs high-visibility dashboards, designate those tables as preferred tables. Queries to all other tables use regular BigQuery slots. Queries that access multiple tables (such as a
JOIN) are only accelerated if all tables in the query are in the preferred tables list, and queries to materialized views are only accelerated if both the materialized views and their base tables are in the preferred tables list.
3. Limitations & Fallback Causes (PARTIAL or DISABLED)
When the project is configured to use BI Engine, INFORMATION_SCHEMA.JOBS
reports each query's acceleration status in
bi_engine_statistics.bi_engine_mode (FULL, PARTIAL, or DISABLED) and
bi_engine_statistics.acceleration_mode (for example, FULL_INPUT when all of
the query inputs were accelerated, or FULL_QUERY when all of the query was
accelerated). For PARTIAL or DISABLED,
bi_engine_statistics.bi_engine_reasons (code and message) explains why.
Query stages that BI Engine can't accelerate fall back to standard BigQuery
execution slots without failing the query. Documented limitations include:
Join Limits: BI Engine accelerates leaf-level subqueries with
INNERandLEFT OUTERjoins where a large fact table is joined with up to four smaller dimension tables. Each dimension table must have fewer than 5 million rows and be 5 GiB or less (unpartitioned tables) or have referenced partitions of 1 GiB or less (partitioned tables).Unsupported Features: BI Engine acceleration isn't available for:
Queries that reference wildcard tables
External tables, including BigLake tables
JavaScript UDFs and remote functions
Row-level security
Queries that use
SEARCHorVECTOR_SEARCHfunctions, or are optimized by search indexes or vector indexes
4. Remediating BI Engine Fallback with Materialized Views
When diagnostic telemetry (bi_engine_statistics) shows a high rate of
PARTIAL or DISABLED queries on a dashboard workload:
Inspect
bi_engine_reasons: GroupINFORMATION_SCHEMA.JOBS_BY_PROJECTbybi_engine_statistics.bi_engine_modeandUNNEST(bi_engine_statistics.bi_engine_reasons)to identify the exact reason code (such asINPUT_TOO_LARGE,UNSUPPORTED_SQL_TEXT,TABLE_EXCLUDED, orINSUFFICIENT_RESERVATION).Offload Heavy Aggregations & Joins to a Materialized View: If dashboard queries repeatedly aggregate or join large base tables:
Create a partitioned, clustered materialized view (see materialized_views.md) that pre-aggregates the dashboard dimensions and measures (such as
SUMandCOUNT).Smart tuning can rewrite eligible queries against the base tables to read the materialized view. If you use preferred tables, add both the materialized view and its base tables so that queries to the view can be accelerated.
Prune Scanned Partitions: If the dashboard only displays recent data, partition the base tables by time and make sure dashboard queries filter on the partitioning column, so that only the latest partitions are loaded into memory.
5. Telemetry & Data Retrieval Reference
If the bigquery-observability skill is available in your workspace, refer to
its shared telemetry references for canonical query templates and schema
dictionaries. All architectural rules, eligibility limits, and remediation
workflows are self-contained within this guide.
BI Engine Acceleration Usage & Fallback Reasons: See the
bigquery-observabilityskill (references/job_performance_queries.md, section "BI Engine Acceleration Usage") to querybi_engine_statistics.bi_engine_modeandUNNEST(bi_engine_statistics.bi_engine_reasons).Jobs Schema (
bi_engine_statistics): See thebigquery-observabilityskill (references/schema_compute.md, section "1. Jobs & Compute Telemetry Views") forINFORMATION_SCHEMA.JOBScolumn definitions.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs a command-line tool, Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Publisher
- Google (Official)
- Source
- google/skills · skills/cloud/bigquery-optimization · commit 2194d3b
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Google or Google.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download bigquery-optimization.zip