BI Engine → in-memory cache for Looker/Data Studio; does NOT replace Bigtable for OLTP
Cross-region BigQuery JOIN → significant data transfer cost; prefer co-located datasets
1---2name: bigquery-optimization3description: BigQuery Optimization4---56# BigQuery Optimization78## When to Use9- Designing tables for an analytics use case on GCP10- Queries are slow or unexpectedly expensive11- Planning partitioning/clustering strategy12- Preparing for GCP Professional Data Engineer exam1314## Core Jobs1516### 1. Schema Design17- Prefer **denormalized** schemas for analytics (avoid JOINs at scale)18- Use **ARRAY** and **STRUCT** for nested/repeated data instead of separate tables19- Choose correct column types: INT64 over STRING for IDs, TIMESTAMP over STRING for dates20- Avoid nullable columns on high-cardinality fields2122### 2. Partitioning Strategy23- **Time-unit partitioned** (DAY, HOUR, MONTH, YEAR) — most common, use for time-series data24- **Integer range partitioned** — for numeric IDs with predictable ranges25- **Ingestion-time partitioned** — auto-partitions on load time (_PARTITIONTIME pseudo-column)26- Always add partition filter in queries (`WHERE date = '2024-01-01'`) to reduce bytes billed2728### 3. Clustering29- Apply after partitioning; up to 4 clustering columns30- Order columns by highest cardinality first (most selective → least selective)31- Best for filter columns: user_id, country, event_type32- Clustering improves query performance but does NOT reduce bytes billed (unlike partitioning)3334### 4. Query Optimization35- Avoid `SELECT *` — select only needed columns (columnar storage)36- Filter early with `WHERE` on partitioned/clustered columns37- Use `WITH` CTEs for readability; avoid deep nesting38- Avoid self-joins; use window functions instead39- Use `APPROX_COUNT_DISTINCT` for large cardinality estimates4041### 5. Cost Management42- **On-demand pricing** — pay per bytes scanned (good for irregular workloads)43- **Capacity pricing (slots)** — flat-rate, good for predictable high-volume workloads44- Monitor with INFORMATION_SCHEMA.JOBS_BY_PROJECT45- Use BI Engine for in-memory acceleration of dashboard queries46- Materialized views for repeated aggregations (auto-refresh on DML)4748### 6. Access Control49- Use **Authorized Views** for row/column-level security without data duplication50- Apply dataset-level IAM before table-level (principle of least privilege)51- Column-level security via **Policy Tags** (BigQuery column security + Data Catalog)5253## Key Concepts54- **Slot** — unit of BigQuery compute (1 slot = 1 CPU thread for query processing)55- **Shuffle** — cross-node data transfer; minimize with partition pruning56- **Materialized View** — pre-computed results, auto-refreshed; use for repeated aggregations57- **INFORMATION_SCHEMA** — metadata views for monitoring jobs, tables, partitions5859## Checklist60- [ ] Table partitioned on a date/timestamp column?61- [ ] Clustering applied (up to 4 cols, high cardinality first)?62- [ ] All queries use partition filter in WHERE clause?63- [ ] SELECT * avoided — only needed columns selected?64- [ ] Authorized views used for sensitive data instead of data copies?65- [ ] Materialized views created for repeated aggregations?66- [ ] Cost monitoring via INFORMATION_SCHEMA.JOBS?6768## Output Format69- 🔴 **Critical** — full table scan with no partition filter (unbounded cost)70- 🟡 **Warning** — missing clustering, suboptimal JOIN order, no partition pruning71- 🟢 **Suggestion** — materialized view opportunity, slot reservation candidate7273## Exam Tips74- **Partitioning reduces cost** (fewer bytes scanned); **clustering improves performance** (not cost)75- Authorized views → share data without duplicating; row-level security without VPC-SC76- `INFORMATION_SCHEMA.JOBS_BY_PROJECT` → monitor slot usage and bytes billed77- Flat-rate (capacity) pricing → predictable cost for high-volume; on-demand → pay-per-query78- BI Engine → in-memory cache for Looker/Data Studio; does NOT replace Bigtable for OLTP79- Cross-region BigQuery JOIN → significant data transfer cost; prefer co-located datasets
Run npx skillmds@latest add kienbui1995/bigquery-optimization in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
BigQuery Optimization It is listed under DevOps & Infra on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
kienbui1995 (@kienbui1995) published this skill. Their other Agent Skills are listed on their SkillMD profile.