跳到正文
Skillpedia
分析与电子表格48k · #6301

sql-sentinel

它能做什么

SQL Sentinel 会分析你的 SQL 代码,找出让它运行得更快、成本更低的方法。它会检查那些可能推高你成本的常见问题,并告诉你该怎么修改。

适用场景

  • ✓当你编写或审查 SQL 代码时。
  • ✓如果你不明白为什么某个查询很慢或很费钱。
  • ✓在把重要的 SQL 代码部署到生产环境之前。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/sql-sentinel/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/sql-sentinel/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“分析一下这段 SQL 代码,告诉我怎样能让它更快、更省钱:[在此粘贴你的 SQL 代码]”

每周 5 个新技能,1 分钟读完。

工作原理

它会读取你的 SQL 代码,并将其与一份已知会导致变慢或成本过高的“不良写法”清单进行比对。每发现一个问题,它都会解释问题所在,以及该如何修复。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

sql-sentinel

Overview

A static-analysis skill that audits SQL for the cost & performance anti-patterns that dominate warehouse bills — SELECT *, full-table scans, non-sargable predicates, Cartesian joins, the NOT IN NULL trap, and 15 more. It scores warehouse query health 0-100 (A-F) and outputs a prioritized cost-reduction plan, each finding with a why, a concrete fix, and an estimated savings.

Built for analytics engineers (dbt, Looker), data platform teams running FinOps / "reduce cloud spend" initiatives, and anyone reviewing a SQL pull request before it hits production. Works across BigQuery, Snowflake, Redshift, and Postgres. Zero dependencies, MIT licensed.

The executable engine and full rule set live in the source repository: https://github.com/takeaseatventure/sql-sentinel. Treat that repository as third-party executable code.

When to Use This Skill

  • A user writes or reviews a query for BigQuery, Snowflake, Redshift, Postgres, or Spark SQL.
  • A user asks "why is this query so slow?" or "why is my warehouse bill so high?"
  • A user is about to promote a dashboard query or dbt model to production.
  • A data engineer wants a second pair of eyes before a code review or a cost-optimization sweep.
  • A team is running a "reduce cloud spend" or FinOps initiative.

How It Works

The engine splits a SQL script into statements (honoring quotes and comments), runs 20 rules over each statement, scores health 0-100 weighted by severity (critical 25, high 12, medium 5, low 1), and returns a prioritized cost-reduction plan.

Step 1: Run the audit

Install or clone the source repository only after choosing a reviewed commit, tag, or release to trust. Do not run code from a mutable default branch just because this skill links to it:

git clone https://github.com/takeaseatventure/sql-sentinel.git
cd sql-sentinel
git checkout <reviewed-commit-or-tag>
node scripts/sql-sentinel.js path/to/query.sql

Or programmatically:

const { auditSql } = require('./scripts/sql-sentinel');
const report = auditSql(yourSqlString, { dialect: 'bigquery' });
console.log(report.healthScore);      // 0-100
console.log(report.grade);            // 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
console.log(report.prioritizedPlan);  // array, worst findings first

Step 2: Read the prioritized plan

The output leads with critical findings (Cartesian joins, mass DELETE) and descends to low-severity style issues. Each finding explains why it costs money and how to fix it.

Examples

Example 1: A messy dashboard query

SELECT DISTINCT *
FROM user_events, raw_logs
WHERE LOWER(event_name) LIKE '%signup%'
  AND user_id NOT IN (SELECT id FROM deleted_users)
ORDER BY created_at;

The audit scores this 17/100 (grade F) and flags 7 findings:

  • CRITICAL: comma-join produces a Cartesian product (can turn a $0.02 query into a $200 query)
  • HIGH: SELECT * forces full column scan (30-90% wasted bytes on wide tables)
  • HIGH: leading-wildcard LIKE '%signup%' defeats indexes
  • HIGH: LOWER(event_name) defeats indexes (non-sargable)
  • HIGH: NOT IN (SELECT ...) — NULL semantics hazard
  • MEDIUM: SELECT DISTINCT dedup cost
  • MEDIUM: ORDER BY without LIMIT sorts the full result

Example 2: A clean, sargable query

-- This scores 90+/100 (grade A) — no findings
SELECT id, email, created_at
FROM users
WHERE created_at >= TIMESTAMP '2026-01-01'
  AND created_at <  TIMESTAMP '2026-02-01'
ORDER BY id
LIMIT 100;

The 20 rules (ruleset v1.0.0)

Rule Severity Catches
SQL001 high SELECT * full column scan
SQL002 critical No WHERE → full table scan
SQL003 high LIKE '%term' non-sargable
SQL004 high Function on column kills index
SQL005 critical CROSS JOIN / comma-join
SQL006 medium SELECT DISTINCT dedup cost
SQL007 medium ORDER BY without LIMIT
SQL008 high NOT IN (SELECT ...) NULL trap
SQL009 medium Implicit type cast
SQL010 low Many ORs (use IN/UNION)
SQL011 medium COUNT(DISTINCT) at scale (use HLL)
SQL012 low LIMIT without ORDER BY
SQL013 medium Scalar subquery in SELECT
SQL014 medium 5+ JOINs broadcast/spill risk
SQL015 high Fact table, no partition filter
SQL017 low String concat in SELECT
SQL018 medium Window OVER () no PARTITION
SQL020 critical DELETE/UPDATE without WHERE

…

常见问题

它会运行我的 SQL 代码吗?

不会,它只读取代码的文本内容。可以放心用于任何 SQL 文件。

它支持所有 SQL 数据库吗?

它支持 BigQuery、Snowflake、Redshift 和 Postgres。

什么是“反模式”?

指的是一些常见的 SQL 写法,它们会在无意中让代码运行得更慢或更费钱。

详情

作者的原始描述

Audit SQL for the cost & performance anti-patterns that burn warehouse credits. Scores warehouse health 0-100 and outputs a prioritized cost-reduction plan for BigQuery, Snowflake, Redshift, and Postgres.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#6301
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能