技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
snowflake-query-forensics【数据与研究】Audit, analyze, and diagnose completed or failed Snowflake queries from query history, Query Insights, and GET_QUERY_OPERATOR_STATS evidence. Use when investigating slow queries, queueing, lock waits, local or remote spill, poor pruning, exploding joins, repeated query-hash regressions, or requests for a defensible query root-cause packet. Trigger wi…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: snowflake-query-forensics description: >- Audit, analyze, and diagnose completed or failed Snowflake queries from query history, Query Insights, and GET_QUERY_OPERATOR_STATS evidence. Use when investigating slow queries, queueing, lock waits, local or remote spill, poor pruning, exploding joins, repeated query-hash regressions, or requests for a defensible query root-cause packet. Trigger with "Snowflake query spilled", "why is this Snowflake query queued", "Snowflake query ID", "exploding join", or "Snowflake pruning regression". Do not use for generic SQL tutoring, automatic query rewrites, warehouse resizing, cancellation, or clustering changes. allowed-tools: Read, Write, Bash(python3:*) argument-hint: "[query-id-or-evidence-json]" model: inherit effort: high version: 3.16.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io tags:
Build a read-only query root-cause packet from platform evidence. Distinguish observed facts, derived metrics, and hypotheses; isolate one variable for any later experiment.
Problem: A slow elapsed time does not identify whether compilation, execution, queueing, blocking, spill, pruning, or query shape is responsible, and some diagnostic surfaces are delayed or unavailable for particular query classes.
Outcome: A query-scoped packet that ranks observed operator evidence, preserves competing explanations, and defines the next read-only check without changing SQL or compute.
OPERATE or MONITOR on the
warehouse when operator statistics are required.Write only for new local evidence and
report artifacts; never use it to alter SQL or Snowflake state.ACCOUNTADMIN. Query-history visibility and operator-stat access
depend on the approved role. GET_QUERY_OPERATOR_STATS requires OPERATE or
MONITOR on the warehouse. Report missing access; do not grant it.metadata.history_source and role must
exactly match the receipted anchor row and source; a digest cannot repair a semantic
mismatch.query_runs, never
attribute them to the anchor, and require the explicit comparison-alignment fields.has_* metadata is safe only when its value is an actual boolean.Before collection, read references/history-and-collection.md. For a completed query, read references/operator-statistics.md. When Query Insights is available, read references/query-insights-boundaries.md.
For bounded live history collection, use the shared read-only collector with an approved Snowflake CLI profile:
python3 "${CLAUDE_SKILL_DIR}/scripts/collect_snowflake_evidence.py" \
--surface query --connection <approved-readonly-profile> \
--source-max-age-seconds <positive-incident-bound> \
--output snowflake-query-collector.json
Use normalized input schema 2.0 and collector receipt schema 2. Before analysis,
apply the complete contract in
History and collection, including exact anchor
UUID, source, role, source-specific terminal status, anchor-only maximum time, reviewed
SQL cap, and an independently preserved input digest. Treat an embedded checksum as
consistency evidence, never authenticity. A missing or mismatched receipt field, stale
anchor, cap hit, truncation, or absent external digest blocks confirmed, completeness,
comparison, regression, and ROI claims. Keep aligned comparison runs in query_runs;
do not attribute them to the anchor. Narrow or partition any truncated collection before
making workload or absence claims.
Follow this sequence:
Require at least one of:
Capture the symptom, expected behavior, comparison query/run if available, account, role, warehouse, execution state, and source timestamps. If the user only says “queries are slow,” first identify a bounded candidate set; do not scan unbounded history.
SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY for longer historical comparisons, while
disclosing its documented latency.QUERY_INSIGHTS only as an additional platform-detected signal; absence of an
insight does not prove absence of a problem.GET_QUERY_OPERATOR_STATS(QUERY_ID) only after confirming the query completed,
is within the supported retrieval window, and the role has warehouse visibility.Use only the source-specific terminal statuses listed in History and collection. Unknown, running, queued, blocked, and warehouse-resume states remain nonterminal and fail closed. The bundled collector receipts Account Usage; Information Schema discovery remains partial without its own reviewed matching receipt.
The detailed choice table and bounded SQL are in references/history-and-collection.md.
Collect only fields needed to distinguish:
Exclude raw query text by default. If literals or object names are relevant, have the operator provide a redacted fragment separately.
Normalize the bundle to the schema in references/operator-statistics.md, then run:
python3 "${CLAUDE_SKILL_DIR}/scripts/analyze_query_evidence.py" \
--input query-evidence.json \
--json-out query-forensics.json \
--markdown-out query-forensics.md
The analyzer emits:
It never rewrites SQL, chooses a warehouse size, or assigns a root cause from a single metric.
For every hypothesis, include at least one competing explanation and the next read-only test. Examples:
Use references/output-contract.md. Required contents:
Before delivery, verify that the packet names the query ID and evidence surfaces, gives
actual source timestamps, reports evidence_binding: BOUND and source_freshness: FRESH before making a completeness claim, contains no raw query text or credentials,
includes at least one operator row bound to a surface-compatible terminal query, and
keeps all three confidence classes separate. Re-run the analyzer on the saved
normalized JSON; the machine-readable result must be identical for identical input. If
a proposed experiment appears, confirm it changes one variable, uses a user-supplied
success objective, names an approver, and has not been executed.
Return query-forensics.json and query-forensics.md in the user's chosen working
directory, plus the exact analyzer command used. The packet includes identity and
freshness, confirmed observations, estimated/derived metrics, at-risk hypotheses, top
operators, warnings, non-claims, and a one-variable experiment proposal only when the
user supplies a success objective. Do not write runtime output into the skill directory.
Return a partial or inconclusive packet rather than guessing when:
| Condition | Meaning | Required response |
|---|---|---|
| Query ID cannot be found | Wrong surface/window/account, retention, latency, or visibility may apply | Check scope and freshness; return unknown rather than “query did not run.” |
| Query is running or too old | Operator statistics are not available | Produce a history-only partial packet and state the missing operator boundary. |
GET_QUERY_OPERATOR_STATS privilege failure | Approved role lacks warehouse OPERATE/MONITOR | Preserve the sanitized error and request owner review; do not grant privileges. |
| No Query Insights row | Exclusion, availability, timing, or no supported signal are all possible | State which interpretation is supported; never certify health from absence. |
| Analyzer rejects evidence | Negative/non-finite counters, malformed timestamps, or invalid objects | Correct from source data; do not coerce or invent fields. |
| User demands resize, rewrite, cancellation, or clustering change | Mutation exceeds this skill's authority | Return evidence and an approval-bounded experiment proposal, then stop. |
Confirm the query completed, collect operator statistics, and report the exact remote spill bytes and affected operator. Compare the same parameterized hash and aligned data volume. Return query-shape and capacity-pressure hypotheses separately; do not resize.
Decompose queue and transaction-blocked time from query history. If blocked time is present, identify the relevant transaction evidence through approved read-only surfaces. Do not cancel the blocker. The packet names the blocker owner and escalation path.
Reject that inference. Query Insights has documented exclusions. Use history and operator evidence, and report whether insights were unavailable, inapplicable, absent, or actually returned no rows.
scripts/analyze_query_evidence.py — deterministic
evidence validator and classifier.