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/storage_billing_models.md
Storage Billing Models: Logical vs. Physical Optimization
Guidance for evaluating whether a BigQuery dataset achieves better
cost-efficiency under LOGICAL or PHYSICAL storage billing.
Table of Contents
1. Evaluation Workflow (Lines 17-81)
Step 1: Gather Target Metrics (Lines 22-34)
Step 2: Calculate Cost Comparison (Lines 36-61)
Step 3: Evaluate Decision Rules & Trade-offs (Lines 63-81)
2. Actionable Recommendations (Lines 83-107)
If Currently on Logical Billing: (Lines 88-97)
If Currently on Physical Billing: (Lines 99-107)
3. Critical Footguns (Lines 109-129)
1. Evaluation Workflow
Follow this step-by-step workflow when a user inquires about switching storage billing models:
Step 1: Gather Target Metrics
Retrieve storage metrics from the regional INFORMATION_SCHEMA.TABLE_STORAGE
view for the target dataset.
Scope: Query
`{project_id}`.`region-{location}`.INFORMATION_SCHEMA.TABLE_STORAGEfiltered bytable_schema = '{dataset_id}',table_type = 'BASE TABLE', and non-zero storage (total_physical_bytes + fail_safe_physical_bytes > 0) to isolate billable native base tables.Inputs Required:
active_logical_bytes,long_term_logical_bytes,active_physical_bytes,long_term_physical_bytes,time_travel_physical_bytes, andfail_safe_physical_bytes.
Step 2: Calculate Cost Comparison
Calculate the forecasted monthly costs for both models using regional or contract unit rates:
logical_cost = (active_logical_gib * price_active_logical)
+ (long_term_logical_gib * price_long_term_logical)
physical_cost = (
(active_physical_gib + fail_safe_physical_gib)
* price_active_physical
)
+ (long_term_physical_gib * price_long_term_physical)
forecast_total_cost_difference = logical_cost - physical_cost(Note: In TABLE_STORAGE, active_physical_bytes already includes baseline
active data and time_travel_physical_bytes. Adding fail_safe_physical_bytes
completes the active physical storage footprint).
Positive Delta (
> 0): Physical billing is forecasted to have lower total cost.Negative Delta (
< 0): Logical billing is cheaper; transitioning to Physical billing would increase costs.
Step 3: Evaluate Decision Rules & Trade-offs
Break-Even Compression Threshold:
Baseline Ratio: Physical rates ($0.04/GiB active, $0.02/GiB long-term in US) are roughly 2x Logical rates ($0.02/GiB active, $0.01/GiB long-term). In standard US regions, data must compress better than 2:1 (>2x) (
logical_volume / physical_volume > 2) before accounting for overhead.Regional & Contract Adjustments: For non-US regions or enterprise contracts, calculate the specific
price_physical / price_logicalratio dynamically using current rates from BigQuery Storage Pricing.
Time Travel & Fail-Safe Overhead:
Under Logical billing, Time Travel and Fail-Safe bytes are free.
Under Physical billing, Time Travel and Fail-Safe bytes are billed at the physical active rate.
High-churn workloads (frequent
UPDATE/DELETEor daily full-table overwrites) inflate physical storage and require higher break-even compression (often 2.5x–3x+).
2. Actionable Recommendations
Determine the dataset's current storage billing model (via metadata or
INFORMATION_SCHEMA.TABLE_STORAGE):
If Currently on Logical Billing:
Physical is More Cost-Effective (
forecast_total_cost_difference > 0& Low Churn): Recommend updating the dataset storage billing model toPHYSICALin dataset settings.High Churn but Strong Compression: Recommend reducing the dataset Time Travel window (e.g., from 7 days down to 2 days) before transitioning to Physical billing to minimize overhead.
Logical is More Cost-Effective (
forecast_total_cost_difference < 0): Recommend remaining onLOGICALbilling.
If Currently on Physical Billing:
Logical is More Cost-Effective (
forecast_total_cost_difference < 0): Recommend transitioning the dataset back toLOGICALbilling in dataset settings (verifying the 14-day lock-in cooldown has elapsed).Physical is Favorable but Inflated by Time Travel: Recommend reducing the dataset Time Travel window to lower billable physical active bytes without changing the billing model.
Physical is Optimal: Recommend maintaining
PHYSICALbilling.
3. Critical Footguns
14-Day Cooldown (Hard Lock-in): Once a dataset's storage billing model is updated, it cannot be changed again for 14 days. Verify compression and historical churn across a full cycle before advising a change.
24-Hour Propagation Delay: After updating the storage billing model on a dataset, it takes up to 24 hours for the change to take effect and be reflected in storage billing calculations.
Time Travel & Fail-Safe Incur Active Physical Rates: Under Physical billing, both Time Travel (1–7 days) and Fail-Safe (7-day non-configurable disaster recovery) storage are billed at the active physical rate. In contrast, Time Travel and Fail-Safe bytes are completely free under Logical billing. For high-churn datasets, Time Travel + Fail-Safe overhead can outweigh compression savings.
Free Tier Proration & Scope: The 10 GiB monthly free tier is pooled across the Cloud Billing account and prorated per second (e.g., 100 GiB stored for 1 day is ~3.3 GiB-months, fitting within the free tier).
Deletion Footgun on Physical Storage: Deleting a table stops billing immediately under Logical storage, but continues accruing active physical charges for 9–14 days (Time Travel + 7-day Fail-Safe) under Physical storage.
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