# sql-optimization

> Claude/Codex skill by [@allium-labs](https://omgskills.com/library/allium-labs/index.md) · 0 stars · Updated 2026-10-23

\*\*Required reading before writing or running any SQL.\*\* Patterns for Snowflake query performance and chain-specific pitfalls. Covers: never querying deprecated tables, default time ranges, partition-pruning rules, CTE filtering, \`QUALIFY\` for dedup, \`UNION ALL\` over \`UNION\`, \`APPROX\_COUNT\_DISTINCT\` for exploration, pre-aggregated \`\*.metrics.\*\` tables vs raw aggregation, EVM address lowercasing (and when not to), per-chain vs \`crosschain.\*\` tables, verifying guessed categorical filter values with \`SELECT DISTINCT\`, and Solana voting/non-voting optimized views. Call \`get\_skill(name="sql-optimization")\` before writing SQL — especially for large tables, long time ranges, or crosschain queries.

## Install

```sh
git clone https://github.com/allium-labs/allium-claude-plugin /tmp/allium-claude-plugin && ln -s /tmp/allium-claude-plugin/skills/sql-optimization ~/.claude/skills/sql-optimization
```

## From README

SQL Optimization for Snowflake Apply these patterns when writing or optimizing SQL against Allium's Snowflake warehouse, especially for multi-billion-row tables (.raw.transactions, .raw.transfers, .raw.logs, .dex.trades). Verify Guessed Categorical Filters Before committing to guessed categorical values in a WHERE clause, run a quick exploration query to verify the values present in the table. Use schema descriptions to choose the table and column; use data exploration when the exact stored value is not already confirmed. For categorical/text columns you plan to filter on (e.g., coin, markettype, pair, status, type, dexname, chain): Run SELECT DISTINCT FROM \[WHERE \] LIMIT 50 first On large tables, scope with a recent timestamp filter (e.g., WHERE timestamp \>= DATEADD('day', -7, CURRENTDATE())) to keep exploration cheap For small metadata/dimension tables, a bare SELECT DISTINCT is fine If schema content or sample rows show the exact stored value, use that spelling.

## Links

- HTML page: https://omgskills.com/library/allium-labs/allium-claude-plugin/skills/sql-optimization/
- GitHub: https://github.com/allium-labs/allium-claude-plugin
- Author: [@allium-labs](https://omgskills.com/library/allium-labs/index.md)

## More from this repo

- [allium-investigation](https://omgskills.com/library/allium-labs/allium-claude-plugin/skills/allium-investigation/index.md) — Investigate an onchain entity, protocol, market, or wallet question with Allium.
   - [@allium-labs](https://omgskills.com/library/allium-labs/index.md) · 0 stars
- [bridge-analysis](https://omgskills.com/library/allium-labs/allium-claude-plugin/skills/bridge-analysis/index.md) — Methodology playbook for analyzing cross-chain bridge and messaging-protocol data on Allium — CCTP, LayerZero,...
   - [@allium-labs](https://omgskills.com/library/allium-labs/index.md) · 0 stars
- [dashboard-design](https://omgskills.com/library/allium-labs/allium-claude-plugin/skills/dashboard-design/index.md) — Used to build and update Allium Explorer dashboards with set\_dashboard.
   - [@allium-labs](https://omgskills.com/library/allium-labs/index.md) · 0 stars
