Bigquery optimization
Skill Ocean1346/bigquery-expert/skills/bigquery-optimization
Use when writing, reviewing, or optimizing BigQuery SQL, asking about BigQuery best practices, working with .sql files targeting BigQuery, or troubleshooting slow/expensive BigQuery queries. Symptoms: high slot consumption, full table scans, expensive joins, slow queries, high bytes billed.From its SKILL.md
npx -y skills add Ocean1346/bigquery-expert --skill bigquery-optimizationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.0 KB, 939 tokens by cl100k_base, as published. Nobody here has run it
BigQuery SQL Optimization
You are a BigQuery SQL optimization expert. When you encounter BigQuery SQL, evaluate it against the 11 known anti-patterns documented in the references. When writing new SQL, proactively avoid all anti-patterns.
Anti-Pattern Quick Reference
| # | Name | What to Look For | Quick Fix | Severity |
|---|---|---|---|---|
| 1 | SimpleSelectStar | SELECT * on single-table query without JOINs or GROUP BY | Specify only needed columns | High |
| 2 | SemiJoinWithoutAgg | IN/NOT IN subquery without DISTINCT or GROUP BY | Add DISTINCT to subquery | Medium |
| 3 | CTEsEvalMultipleTimes | CTE (WITH) alias referenced more than once | Convert to CREATE TEMP TABLE | High |
| 4 | OrderByWithoutLimit | Outermost ORDER BY without LIMIT | Add LIMIT clause | Medium |
| 5 | StringComparison | REGEXP_CONTAINS with simple .*pattern.* | Use LIKE '%pattern%' instead | Low |
| 6 | LatestRecordWithAnalyticFun | ROW_NUMBER()/RANK() + WHERE rn = 1 | Use ARRAY_AGG(... ORDER BY ... LIMIT 1) | High |
| 7 | DynamicPredicate | Subquery inside WHERE predicate | Extract to DECLARE variable or CTE | Medium |
| 8 | WhereOrder | AND predicates not ordered by selectivity | Reorder: = > >/< > >=/<= > != > LIKE (advisory -- BigQuery's optimizer may reorder independently) | Low |
| 9 | JoinOrder | Smaller table on the left side of JOIN | Place largest table first (advisory -- optimizer usually handles this) | Low |
| 10 | MissingDropStatement | CREATE TEMP TABLE without corresponding DROP | Add DROP TABLE at end of script | Low |
| 11 | ConvertTableToTemp | CREATE TABLE + DROP TABLE in same script | Use CREATE TEMP TABLE instead | Low |
Behavioral Rules
When Writing New SQL
- Proactively apply all best practices. Never generate SQL that contains known anti-patterns.
- Select only the columns needed, not
SELECT *. - Use
LIKEinstead ofREGEXP_CONTAINSfor simple wildcard matches. - Place the largest table first in JOINs.
- Always add
LIMITwhen usingORDER BYunless ordering is required for correctness. - Use
ARRAY_AGGinstead ofROW_NUMBER()for "latest record per group" patterns.
When Reviewing Existing SQL
- Check the query against all 11 anti-patterns.
- Report findings grouped by severity: High, Medium, Low.
- For each finding, provide a before/after code example showing the fix.
- Always preserve query semantics -- never change what data the query returns.
- If no anti-patterns are found, explicitly state: "No anti-patterns detected. This query follows BigQuery best practices."
Review Output Format
## BigQuery SQL Review
### Findings
**[HIGH]** PatternName: Description of the issue found.
**[MEDIUM]** PatternName: Description of the issue found.
### Recommended Fixes
#### Fix 1: PatternName
**Before:**
(original SQL snippet)
**After:**
(optimized SQL snippet)
**Why:** Explanation of the performance/cost improvement.
### Summary
X anti-pattern(s) found (Y high, Z medium, W low).
Important Notes
- JoinOrder requires knowledge of table sizes. If table sizes are unknown, flag it as advisory and recommend the user verify which table is larger.
- SimpleSelectStar only applies to simple single-table queries.
SELECT *with JOINs or GROUP BY is not flagged. - OrderByWithoutLimit only applies to the outermost query. ORDER BY inside subqueries or CTEs is acceptable.
- DynamicPredicate has two fix patterns: use
DECLARE varfor single-value subqueries, orDECLARE var ARRAY<type>+UNNEST(var)for multi-value (IN) subqueries.
For detailed detection rules, edge cases, and comprehensive examples, see the anti-patterns reference.
What ships with it: 11 files
13.5 KB alongside SKILL.md
references/
- 01-simple-select-star.md930 B
- 02-semi-join-without-agg.md1.1 KB
- 03-ctes-eval-multiple-times.md1.3 KB
- 04-order-by-without-limit.md975 B
- 05-string-comparison.md979 B
- 06-latest-record-with-analytic-fun.md1.3 KB
- 07-dynamic-predicate.md1.6 KB
- 08-where-order.md1.7 KB
- 09-join-order.md1.6 KB
- 10-missing-drop-statement.md922 B
- 11-convert-table-to-temp.md1.2 KB
Gives 0 of the 12 instructions most performance cost skills give in 939 tokens
Counted across 797 of the 1,117 authors here whose files we hold, read 2026-09-06
- Check for product marketing context firstin 46 of 797, across 20 files
- Measure before optimizingin 31 of 797, across 25 files
- Profile first to identify the actual bottleneckin 23 of 797, across 22 files
- Verify your robots.txt allows AI crawlersin 21 of 797, across 12 files
- Import directly and avoid barrel filesin 19 of 797, across 15 files
- Spawn all runs in the same turnin 18 of 797, across 11 files
- Write a draft of the skillin 17 of 797, across 10 files
- Understand the user's intentin 17 of 797, across 10 files
- Use React.cache for per-request deduplicationin 16 of 797, across 11 files
- Profile before optimizingin 16 of 797, across 14 files
- Include specific numbers with sourcesin 15 of 797, across 8 files
- Add lazy loading to below-fold imagesin 15 of 797, across 10 files
Said here and by no other author read
- Add DISTINCT to subquery
- Convert to temporary table
- Add LIMIT clause
- Use LIKE instead of REGEXP
- Use ARRAY AGG for latest records
- Extract subquery to variable
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.