一键导入
dbt-snowflake-optimization-pattern
Cross-Tool Integration Pattern: dbt + Snowflake Model Optimization
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Cross-Tool Integration Pattern: dbt + Snowflake Model Optimization
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Generate comprehensive PR descriptions from project context and git changes
Framework for when to use Skills, Agents, or Patterns for organizing knowledge in the ADLC platform with decision criteria and migration strategies
Generate dbt model boilerplate with tests, documentation, and best practices
Validate documentation completeness and quality before project completion
Initialize new ADLC project with standard directory structure, documentation templates, and git branch
Complete reference for MCP tool integration across specialist and role agents including server inventory, tool recommendations, and security protocols
| name | dbt-snowflake-optimization-pattern |
| description | Cross-Tool Integration Pattern: dbt + Snowflake Model Optimization |
Pattern Type: Performance Optimization Tools: dbt-mcp, snowflake-mcp Confidence: HIGH (0.92) - Production-validated pattern Primary Users: dbt-expert, snowflake-expert, analytics-engineer-role
Scenario: Slow-running dbt model impacting downstream dashboards and reports Symptoms: Model runtime >30 minutes, warehouse queuing, excessive costs Goal: Reduce runtime to <5 minutes while maintaining data accuracy
dbt-mcp → Get model metadata, dependencies, compiled SQL
↓
snowflake-mcp → Profile query performance, analyze warehouse usage
↓
dbt-expert → Analyze findings, design optimization strategy
↓
snowflake-mcp → Validate optimized query performance
↓
dbt-mcp → Update model configuration, verify impact
Why both tools needed:
Gather model context:
# 1. Get model details (compiled SQL, config, dependencies)
mcp__dbt-mcp__get_model_details \
model_name="fct_orders"
Returns:
Extract for analysis:
Execute model query for profiling:
# 2. Run the compiled SQL to get query profile
mcp__snowflake-mcp__run_snowflake_query \
statement="[Compiled SQL from step 1]"
Get query execution details:
# 3. Query Snowflake query history for performance metrics
mcp__snowflake-mcp__run_snowflake_query \
statement="
SELECT
query_id,
execution_time / 1000 as execution_seconds,
bytes_scanned,
partitions_scanned,
partitions_total,
compilation_time,
warehouse_size,
credits_used_cloud_services
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE query_text ILIKE '%fct_orders%'
AND start_time >= DATEADD(hour, -24, CURRENT_TIMESTAMP())
ORDER BY start_time DESC
LIMIT 5
"
Analyze bottlenecks:
Check upstream dependencies:
# 4. Get parent models (upstream dependencies)
mcp__dbt-mcp__get_model_parents \
model_name="fct_orders"
Check downstream impact:
# 5. Get child models (blast radius of changes)
mcp__dbt-mcp__get_model_children \
model_name="fct_orders"
Assess impact:
Delegate to specialist:
DELEGATE TO: dbt-expert
CONTEXT:
- Task: Optimize slow-running fct_orders model
- Current State:
- Model: fct_orders (fact table, 50M rows)
- Runtime: 45 minutes (unacceptable)
- Materialization: view (full table scan on every query)
- Dependencies: 3 upstream staging models, 12 downstream marts
- Performance Metrics (from Snowflake):
- Execution time: 45 minutes
- Partitions scanned: 2,500 / 2,500 (100% - no clustering)
- Bytes scanned: 15 GB
- Warehouse: MEDIUM (4 credits/hour)
- Requirements:
- Reduce runtime to <5 minutes
- Maintain daily refresh SLA
- No data accuracy impact
- Must support downstream mart dependencies
- Constraints:
- Production model (high visibility)
- Cannot increase warehouse size (cost constraint)
- Downstream marts run at 3 AM daily
REQUEST: "Validated optimization strategy with dbt model changes and expected performance improvement"
Specialist provides:
order_date (common filter)Test optimized query:
# 6. Execute optimized SQL to validate performance
mcp__snowflake-mcp__run_snowflake_query \
statement="[Optimized SQL from dbt-expert]"
Validate clustering effectiveness:
# 7. Check clustering metrics
mcp__snowflake-mcp__run_snowflake_query \
statement="
SELECT
clustering_depth,
partition_depth,
total_partitions
FROM TABLE(INFORMATION_SCHEMA.AUTOMATIC_CLUSTERING_HISTORY(
TABLE_NAME => 'FCT_ORDERS',
DATABASE_NAME => 'ANALYTICS_DW',
SCHEMA_NAME => 'PROD_SALES_DM'
))
WHERE start_time >= DATEADD(day, -1, CURRENT_TIMESTAMP())
LIMIT 5
"
Expected improvements:
Update model configuration:
-- models/marts/fct_orders.sql
{{
config(
materialized='incremental',
unique_key='order_id',
cluster_by=['order_date'],
incremental_strategy='merge',
on_schema_change='fail'
)
}}
WITH source_data AS (
SELECT * FROM {{ ref('stg_orders') }}
{% if is_incremental() %}
WHERE order_date >= DATEADD(day, -3, CURRENT_DATE)
{% endif %}
),
-- ... rest of transformation logic
Run dbt build:
# 8. Build incremental model (first run - full refresh)
mcp__dbt-mcp__build \
selector="fct_orders" \
is_full_refresh=true
Validate model health:
# 9. Check model health after build
mcp__dbt-mcp__get_model_health \
model_name="fct_orders"
Run tests:
# 10. Execute dbt tests
mcp__dbt-mcp__test \
selector="fct_orders"
Validate incremental runtime:
# 11. Run incremental update to test daily runtime
mcp__dbt-mcp__build \
selector="fct_orders" \
is_full_refresh=false
Check actual performance:
# 12. Query performance metrics for validation
mcp__snowflake-mcp__run_snowflake_query \
statement="
SELECT
execution_time / 1000 as execution_seconds,
partitions_scanned,
bytes_scanned / 1024 / 1024 / 1024 as gb_scanned,
credits_used_cloud_services
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE query_text ILIKE '%fct_orders%'
AND start_time >= DATEADD(hour, -1, CURRENT_TIMESTAMP())
ORDER BY start_time DESC
LIMIT 1
"
Success criteria:
Model: fct_customer_transactions (75M rows)
Issue: 60-minute runtime, blocking downstream dashboards
Metrics:
dbt-mcp findings:
# Model details showed:
- Materialization: view
- No incremental logic
- No clustering
- Complex window functions (recalculating all history)
snowflake-mcp findings:
# Performance query showed:
- 60-minute execution time
- Full table scan on every query
- No partition pruning
- Sorting 75M rows repeatedly
Changes implemented:
transaction_dateResults:
Annual savings: 365 days × 3.77 credits × $4/credit = $5,505/year for single model
When: Large fact tables queried frequently dbt-mcp: Change materialization config snowflake-mcp: Validate query performance improvement Benefit: 90-95% runtime reduction typical
When: Large tables with common filter columns
dbt-mcp: Add cluster_by config
snowflake-mcp: Validate partition pruning effectiveness
Benefit: 80-95% scan reduction on filtered queries
When: Incremental models with duplicates or late arrivals
dbt-mcp: Update unique_key and incremental_strategy
snowflake-mcp: Validate merge performance
Benefit: Data accuracy + performance improvement
When: Warehouse too large or too small for workload dbt-mcp: Understand query patterns and dependencies snowflake-mcp: Analyze warehouse utilization and queue times Benefit: Cost optimization without performance degradation
Symptoms: Same runtime after incremental conversion Root causes:
Debug with snowflake-mcp:
# Check if clustering is working
mcp__snowflake-mcp__run_snowflake_query \
statement="
SELECT
clustering_depth,
partition_depth
FROM TABLE(INFORMATION_SCHEMA.AUTOMATIC_CLUSTERING_HISTORY(...))
"
Symptoms: Tests fail, duplicate primary keys Root causes:
unique_keyDebug with dbt-mcp:
# Check model tests
mcp__dbt-mcp__test selector="fct_orders"
# Validate data with query
mcp__dbt-mcp__show sql_query="
SELECT order_id, COUNT(*)
FROM {{ ref('fct_orders') }}
GROUP BY order_id
HAVING COUNT(*) > 1
LIMIT 10
"
Symptoms: Child models fail after optimization Root causes:
Debug with dbt-mcp:
# Identify affected downstream models
mcp__dbt-mcp__get_model_children model_name="fct_orders"
# Test downstream models
mcp__dbt-mcp__test selector="fct_orders+"
get_model_childrendbt test --select fct_orders+.claude/skills/reference-knowledge/testing-patterns/SKILL.md.claude/agents/specialists/dbt-expert.mdCreated: 2025-10-08 Pattern Type: Cross-Tool Integration Confidence: HIGH (0.92) - Production-validated