Developer builds workaround to trace slow queries inside Snowflake stored procedures
A developer found that Snowflake's ACCOUNT_USAGE.QUERY_HISTORY table lacks a PARENT_QUERY_ID column, making it impossible to directly link child statements to their parent stored procedure call. To work around this, they devised a SQL correlation technique using SESSION_ID and timestamp containment, selecting the tightest enclosing query window to reconstruct parent-child relationships. The approach was validated against edge cases including nested procedures, concurrent sessions, and rapid back-to-back calls, all of which produced clean, reliable results. Building on this, the developer created three diagnostic stored procedures to bulk-scan for regressions, drill into per-operator query profiles, and optionally request an AI-generated analysis via Snowflake Cortex. The tooling is designed to run under owner's rights, requiring only a one-time GRANT on ACCOUNT_USAGE to function across customer environments.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in