0
0
Snowflakecloud~10 mins

Query history and profiling in Snowflake - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Query history and profiling
User runs a query
Query recorded in history
Query ID generated
User requests profiling info
System fetches query details
Display execution stats and profile
When a query runs, Snowflake records it with an ID. Users can then request detailed history and profiling info to see how the query performed.
Execution Sample
Snowflake
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE USER_NAME = 'JOHNDOE'
ORDER BY START_TIME DESC
LIMIT 3;
This code fetches the last 3 queries run by user JOHNDOE from the query history.
Process Table
StepActionQuery IDUserStart TimeExecution TimeResult Rows
1Fetch latest query01a2b3c4-d5e6-7f89-0abc-def123456789JOHNDOE2024-06-01 10:00:002.5s1000
2Fetch second latest query02b3c4d5-e6f7-890a-bcde-f234567890abJOHNDOE2024-06-01 09:45:001.2s500
3Fetch third latest query03c4d5e6-f789-0abc-def1-34567890abcdJOHNDOE2024-06-01 09:30:003.0s1500
4Stop fetching-----
💡 Limit reached: 3 queries fetched for user JOHNDOE
Status Tracker
VariableStartAfter 1After 2After 3Final
Query IDNone01a2b3c4-d5e6-7f89-0abc-def12345678902b3c4d5-e6f7-890a-bcde-f234567890ab03c4d5e6-f789-0abc-def1-34567890abcd03c4d5e6-f789-0abc-def1-34567890abcd
Execution TimeNone2.5s1.2s3.0s3.0s
Result RowsNone100050015001500
Key Moments - 2 Insights
Why does the query history show multiple queries instead of just one?
Because the LIMIT 3 clause in the query fetches the last three queries run by the user, as shown in execution_table rows 1 to 3.
What does the Query ID represent in the profiling?
The Query ID uniquely identifies each query run and helps fetch detailed profiling info, as seen in the variable_tracker showing different IDs per step.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Execution Time of the second latest query?
A2.5s
B1.2s
C3.0s
DNot listed
💡 Hint
Check the Execution Time column in row 2 of the execution_table.
At which step does the system stop fetching queries?
AStep 3
BStep 2
CStep 4
DStep 1
💡 Hint
Look at the Action column in the execution_table for the stop fetching action.
If the LIMIT was changed to 2, how many rows would be fetched according to the execution_table pattern?
A2
B1
C3
D4
💡 Hint
The LIMIT controls how many queries are fetched; currently 3 rows are fetched with LIMIT 3.
Concept Snapshot
Query History & Profiling in Snowflake:
- Queries are logged with unique Query IDs.
- Use ACCOUNT_USAGE.QUERY_HISTORY to see past queries.
- Filter by USER_NAME and order by START_TIME.
- LIMIT controls how many queries to fetch.
- Profiling shows execution time and rows processed.
Full Transcript
When a user runs a query in Snowflake, the system records it with a unique Query ID and stores details like start time, execution time, and rows returned. Users can query the ACCOUNT_USAGE.QUERY_HISTORY view to see their recent queries. By filtering on USER_NAME and ordering by START_TIME descending, they get the latest queries first. The LIMIT clause restricts how many queries are shown. This helps users profile their queries to understand performance and results. The execution table shows step-by-step fetching of the last three queries for user JOHNDOE, including their execution times and result counts.