Skip to content
Development
Skill

/bigquery-slot-cost-optimizer

Analyzes Google Cloud BigQuery slot consumption, query costs, and execution bottlenecks using INFORMATION_SCHEMA. Use when diagnosing slow BigQuery queries, slot starvation, high on-demand query costs, unpartitioned table scans, or join performance issues. Don't use for generic

From plugin
google-skills
20k146 skills1 MCP
Install
$ npx -y skills add google/skills --skill bigquery-slot-cost-optimizer --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/bigquery-slot-cost-optimizer

Context preview

The summary Claude sees to decide when to auto-load this skill.

Analyzes Google Cloud BigQuery slot consumption, query costs, and execution bottlenecks using INFORMATION_SCHEMA. Use when diagnosing slow BigQuery queries, slot starvation, high on-demand query costs, unpartitioned table scans, or join performance issues. Don't use for generic

SKILL.md

bigquery-slot-cost-optimizer.SKILL.md
name: bigquery-slot-cost-optimizer
description: >-
  Analyzes Google Cloud BigQuery slot consumption, query costs, and execution
  bottlenecks using INFORMATION_SCHEMA. Use when diagnosing slow BigQuery queries,
  slot starvation, high on-demand query costs, unpartitioned table scans, or join
  performance issues. Don't use for generic BigQuery administration (use
  bigquery-basics), BigQuery ML (use bigquery-ai-ml), or DataFrame operations
  (use bigquery-bigframes).
metadata:
  version: 1.0.0
  publisher: google
  category: BigDataAndAnalytics
  tags:
    - bigquery
    - performance
    - cost-optimization
    - slot-analysis
    - sql

BigQuery slot and cost optimizer

This skill equips AI agents and cloud engineers with procedural heuristics to analyze BigQuery resource consumption, calculate slot hours, identify slot contention and queueing, mitigate Cartesian joins, and optimize unpartitioned table scans.

Trigger conditions and intent mapping

Activate this skill whenever the user asks to:

  • "Optimize BigQuery query performance or reduce slot usage"
  • "Find the most expensive queries in BigQuery"
  • "Diagnose BigQuery slot contention or queueing"
  • "Fix slow running BigQuery jobs or memory spillage"
  • "Detect Cartesian joins or row count explosions in BigQuery"
  • "Identify unpartitioned table scans or missing partition filters"

Prerequisites and environment setup

Before executing this skill, ensure the environment is configured with the necessary SDKs, permissions, and billing:

1. **Cloud SDK and client library installation**:

  • Install the Google Cloud CLI: [Google Cloud SDK installation guide](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt)
  • Install the BigQuery Python client:
     pip install google-cloud-bigquery

1. **Project, billing, and regional selection**:

  • Set the active project:
     gcloud config set project <PROJECT_ID>
  • **Important**: the target Google Cloud project must have an active Cloud Billing account attached.
  • **Regional selection**: specify the target BigQuery dataset location or execution region, as BigQuery `INFORMATION_SCHEMA` views are strictly region-scoped (for example, multi-regions like `region-us` or `region-eu`, or single regions like `region-us-central1`). Querying the wrong region returns empty job telemetry. Pass the matching region via `--region` (the script automatically normalizes location names like `us-central1` to `region-us-central1`). For valid location identifiers, see [BigQuery locations](https://docs.cloud.google.com/bigquery/docs/locations.md.txt).

1. **API enablement**:

  • Enable the BigQuery API on the project:
     gcloud services enable bigquery.googleapis.com

1. **Authentication setup**:

  • Authenticate the local gcloud environment and configure Application Default Credentials (ADC):
     gcloud auth login
     gcloud auth application-default login

1. **IAM roles and permissions**:

  • The executing principal requires the following minimum IAM roles:
  • `roles/bigquery.jobUser`: grants permission to run queries and analyze telemetry.
  • `roles/bigquery.resourceViewer`: grants read-only access to query metadata in `INFORMATION_SCHEMA.JOBS_BY_PROJECT` and capacity reservations.

1. **Pricing reference**:

  • Cost estimates in this skill are for planning purposes. Before running `scripts/slot_analyzer.py`, retrieve live BigQuery billing rates at runtime from official [Google Cloud BigQuery Pricing](https://cloud.google.com/bigquery/pricing) (and consult [BigQuery editions introduction](https://docs.cloud.google.com/bigquery/docs/editions-intro.md.txt) for edition capabilities) after considering user-specific parameters such as target region, chosen edition (`Standard`, `Enterprise`, `Enterprise Plus`), and commitment tier (`Pay-as-you-go`, `1-year`, `3-year`). Pass these runtime-fetched rates explicitly via `--ondemand-rate <USD_PER_TIB>` and `--slot-hour-rate <USD_PER_SLOT_HOUR>`.

Diagnostic execution workflow

Execute automated telemetry extraction

Run `scripts/slot_analyzer.py` to pull and analyze historical query telemetry from `INFORMATION_SCHEMA.JOBS_BY_PROJECT`, passing the runtime-retrieved pricing rates for your specific region, edition, and commitment tier:

# General analysis passing live regional pricing rates fetched from BigQuery pricing
python3 scripts/slot_analyzer.py --project-id <PROJECT_ID> --days 7 \
  --ondemand-rate <USD_PER_TIB> --slot-hour-rate <USD_PER_SLOT_HOUR> --format table

# Output structured JSON for programmatically parsing recommendations
python3 scripts/slot_analyzer.py --project-id <PROJECT_ID> --days 7 \
  --ondemand-rate <USD_PER_TIB> --slot-hour-rate <USD_PER_SLOT_HOUR> --format json

# Offline verification mode using synthetic or extracted telemetry
python3 scripts/slot_analyzer.py --mock-data-file path/to/extracted_telemetry.json \
  --ondemand-rate <USD_PER_TIB> --slot-hour-rate <USD_PER_SLOT_HOUR> --format table

# Dry-run mode to inspect regional SQL query
python3 scripts/slot_analyzer.py --project-id <PROJECT_ID> --region region-us --dry-run

Run `python3 scripts/slot_analyzer.py --help` to inspect all supported CLI flags, focus modes (`--mode`), and required pricing rate arguments (`--ondemand-rate` per TiB and `--slot-hour-rate` per slot-hour).

Metric interpretation and decision tree

Evaluate the telemetry output using the following decision rules. **CRITICAL MANDATE: After classifying the query issue using the decision tree below, you MUST immediately call `view_file` on [references/remediation_playbooks.md](references/remediation_playbooks.md) to read and execute the corresponding remediation playbook (`Rule SLOT-001`, `Rule JOIN-001`, or `Rule PART-001`) and include all mandatory diagnostic SQL queries and 4-step checklists in your response.**

[Query Telemetry Analyzed]
       |
       +---> If
Read more
Ships withgoogle-skills

This repository contains Agent Skills for Google products and technologies, including Google Cloud.

Get the whole plugin

Other skills on google-skills.