Bigquery Slot Cost Optimizer logo

Bigquery Slot Cost Optimizer

OrganizationPopular
google
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 BigQuery administration (use bigquery-basics), BigQuery ML (use bigquery-ai-ml), or DataFrame operations (use bigquery-bigframes).

Overview

Publishergoogle
Repositoryskills
Skill namebigquery-slot-cost-optimizer
Stars
20.1K
Forks
1.6K
Bundled files
3
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by google on GitHub. Read the source before you install it.

Installation

Install the Bigquery Slot Cost Optimizer AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/google/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/cloud/bigquery-slot-cost-optimizer .claude/skills/bigquery-slot-cost-optimizer
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Bigquery Slot Cost Optimizer in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Bigquery Slot Cost Optimizer on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Bigquery Slot Cost Optimizer is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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:

  2. Project, billing, and regional selection:

    • Set the active project:

      bash
      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.

  3. API enablement:

    • Enable the BigQuery API on the project:

      bash
      gcloud services enable bigquery.googleapis.com
  4. Authentication setup:

    • Authenticate the local gcloud environment and configure Application Default Credentials (ADC):

      bash
      gcloud auth login
      gcloud auth application-default login
  5. 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.
  6. 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 (and consult BigQuery editions introduction 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:

bash
# 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 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 wait_ratio_avg > 0.40 OR slot_contention == TRUE
       |     --> Classify as slot contention and queueing (Rule SLOT-001)
       |     --> MANDATORY: Read Rule SLOT-001 in references/remediation_playbooks.md
       |
       +---> If shuffle_output_bytes_spilled > 0 OR records_written > 10 * records_read
       |     --> Classify as Cartesian join (Rule JOIN-001)
       |     --> MANDATORY: Read Rule JOIN-001 in references/remediation_playbooks.md
       |
       +---> If total_bytes_billed > 10 GB AND no date/partition filters
       |     --> Classify as unpartitioned scan (Rule PART-001)
       |     --> MANDATORY: Read Rule PART-001 in references/remediation_playbooks.md
       |
       +---> Otherwise
             --> Check BI Engine, search indexes, or materialized view opportunities
             --> MANDATORY: Read references/optimization_rules.md

Remediation playbooks and architectural reference links

To minimize token consumption in SKILL.md, concrete remediation playbooks (Rule SLOT-001, Rule JOIN-001, Rule PART-001), diagnostic SQL queries, and DDL rewrite patterns are housed in references/:

Verification and validation protocol

Before finalizing query rewrites:

Dry-run validation

Validate query syntax and calculate estimated bytes scanned without incurring cost:

python
from google.cloud import bigquery
client = bigquery.Client()
job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False)
query_job = client.query(optimized_sql, job_config=job_config)
print(f"Scanned bytes: {query_job.total_bytes_processed / (1024**3):.2f} GB")

Offline and dry-run validation

  • Offline mock telemetry verification: validate heuristic classification, slot contention detection, Cartesian join identification, and cost estimation offline using synthetic or extracted JSON telemetry payloads (--mock-data-file):

    bash
    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
  • CLI dry-run inspection: verify regional SQL query formation and script execution without contacting BigQuery or incurring costs:

    bash
    python3 scripts/slot_analyzer.py --project-id <PROJECT_ID> --region region-us --dry-run

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Bigquery Slot Cost Optimizer AI skill do?

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).

Why use Bigquery Slot Cost Optimizer on TypingMind?

Because you install it once and use it with any model. Bigquery Slot Cost Optimizer is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Bigquery Slot Cost Optimizer in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/google/skills/tree/main/skills/cloud/bigquery-slot-cost-optimizer. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Bigquery Slot Cost Optimizer?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Bigquery Slot Cost Optimizer?

As many as you like. As long as a model supports skills, you can use Bigquery Slot Cost Optimizer with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Bigquery Slot Cost Optimizer AI skill free?

Yes. It is published on GitHub by google under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇