Same message modified version

Analyze warehouse and query performance in Snowflake with dashboards and quality reports, offers optimization recommendations and cost reduction, and exports to Power BI for governance and decision-making.

sábado, 16 de agosto de 2025 • 4 min read • Q2BSTUDIO Team

Artificial-Intelligence-

This article presents a Spanish and reformulated version of a set of scripts designed to analyze the performance of warehouses and queries in Snowflake and to generate query quality reports and actionable recommendations.

The first script creates a table called WAREHOUSE_ANALYTICS_DASHBOARD_with_queries that consolidates three main sources of information: warehouse metadata, query history, and consumption metrics. The goal is to offer a per-warehouse view with counts by query duration ranges, queue times, spills to local and remote storage, execution status, credit consumption distribution, and lists of query identifiers grouped by category. This table facilitates the quick identification of warehouses with the highest query volume, spilling issues, failed or long-running queries, and the associated credit consumption.

The second script creates QUERY_HISTORY_SUMMARY, which summarizes each query record with key information for quick filtering and exploration. It includes query identification, text preview, start and end times, compilation and execution times, user and session, warehouse information, database context, data processing metrics such as bytes scanned and rows produced, credit usage, spills, queue times, and classifications into duration and cost buckets. This table is useful for creating operational dashboards and feeding business intelligence tools such as Power BI.

The third script generates QUERY_DETAILS_COMPLETE, which delivers an expanded and calculated record per query. In addition to the native history fields, it incorporates calculated percentages such as percentage of partitions scanned, percentage of compilation and execution time relative to the total, rows per MB scanned, performance and cache efficiency classifications, and a classification of the type of spilling. This detailed view is ideal for forensic query analysis, advanced diagnostics, and in-depth optimization.

The fourth script creates user_query_performance_report, which groups and scores user behavior over a recent period. It calculates percentiles by warehouse size, detects flags such as over-provisioned queries, long queries during peak hours, use of star selects, scans without partitioning, spills, errors, repeated queries, and other inefficient practices. For each user, it generates samples of problematic queries, aggregated metrics, a weighted risk score, and concrete recommendations for cost reduction and performance improvement. This report is very useful for teams responsible for governance, cost optimization, and user training.

All scripts employ techniques such as duration and consumption buckets, aggregations by warehouse, use of percentile functions to establish adaptive thresholds, and construction of objects with arrays of query identifiers to facilitate direct navigation from dashboards to the original records. The results can be enriched by exporting to Power BI for interactive visualizations and dashboards that integrate alerts and drill down to QUERY_DETAILS_COMPLETE.

Practical recommendations for implementing these scripts: schedule daily or hourly loads as needed, limit the time horizon in production environments to avoid unnecessary costs, apply filters to exclude service users, and combine with query labeling policies to improve traceability and cost attribution. Additionally, automating the generation of recommendations and notifications by email or through AI agents integrated with collaborative platforms improves the adoption of good practices.

Q2BSTUDIO is a software development company that can support the implementation, customization, and automation of these analyses. Our experience includes custom applications and custom software that integrate artificial intelligence for businesses, AI agents, and cybersecurity solutions. We can deploy pipelines that send data to AWS and Azure cloud services, build dashboards in Power BI, and develop customized business intelligence services that accelerate cost reduction and improve operational efficiency.

Services we offer: custom application development, custom software consulting, implementation of artificial intelligence solutions and AI for businesses, design and operation of cybersecurity strategies, migration and architecture in AWS and Azure cloud services, creation of reports and visualizations with Power BI, and development of AI agents for task automation and incident response. These capabilities make it possible to transform the analyses derived from the scripts into concrete and governable actions.

If you are looking to optimize credit consumption, reduce spills, and improve query performance, Q2BSTUDIO can audit your environment, adapt the scripts to your business rules, implement interactive dashboards, and train your teams. Our recommendations typically include warehouse resizing, implementation of clustering or partitioning, refactoring of expensive queries, systematic query labeling, and automation of alerts based on percentiles and risk scores.

In summary, these scripts offer a robust foundation for understanding and managing query performance and associated costs in Snowflake environments. Q2BSTUDIO combines experience in custom application development, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, and Power BI to turn data into decisions and optimize cloud operations.

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.