Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of query history in Snowflake?
Query history in Snowflake helps you see details about past queries, such as when they ran, how long they took, and if they succeeded or failed. It helps track and troubleshoot query performance.
Click to reveal answer
intermediate
Which Snowflake feature provides detailed information about query execution steps?
The QUERY_HISTORY view shows general query info, but the Query Profile provides detailed execution steps and resource usage for profiling queries.
Click to reveal answer
beginner
How can you filter query history to see only queries from the last 24 hours?
Use a SQL filter on the START_TIME column, for example: WHERE START_TIME > DATEADD(hour, -24, CURRENT_TIMESTAMP()).
Click to reveal answer
intermediate
What key metrics can you find in query profiling to improve performance?
You can find metrics like execution time per step, bytes scanned, rows processed, and wait times. These help identify slow parts and optimize queries.
Click to reveal answer
beginner
Why is it important to monitor query history regularly in Snowflake?
Regular monitoring helps catch inefficient queries early, manage resource usage, and maintain good performance and cost control.
Click to reveal answer
Which Snowflake view shows the general history of executed queries?
AQUERY_PROFILE
BUSER_SESSIONS
CINFORMATION_SCHEMA.TABLES
DQUERY_HISTORY
✗ Incorrect
QUERY_HISTORY contains records of executed queries with timestamps and status.
What does Query Profile provide that QUERY_HISTORY does not?
How can you limit query history results to recent queries in SQL?
AUse ORDER BY QUERY_ID
BUse WHERE START_TIME > DATEADD(hour, -24, CURRENT_TIMESTAMP())
CUse LIMIT 10
DUse GROUP BY USER_NAME
✗ Incorrect
Filtering by START_TIME limits queries to a recent time window.
Which metric is NOT typically found in query profiling?
AUser password
BBytes scanned
CRows processed
DExecution time per step
✗ Incorrect
User password is not part of query profiling data.
Why is query history useful for cost management?
AIt helps identify long-running or resource-heavy queries
BIt shows query text only
CIt lists user emails
DIt controls user access
✗ Incorrect
Identifying heavy queries helps control compute costs.
Explain how you would use Snowflake's query history and profiling features to improve query performance.
Think about how history shows what happened and profiling shows how it happened.
You got /5 concepts.
Describe the benefits of regularly monitoring query history in Snowflake.
Consider both performance and cost aspects.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of the QUERY_HISTORY view in Snowflake?
easy
A. To see details of past queries executed in the system
B. To create new tables and schemas
C. To manage user permissions and roles
D. To monitor network traffic between Snowflake and clients
Solution
Step 1: Understand the role of QUERY_HISTORY
The QUERY_HISTORY view stores information about queries that have already run, including their text, execution time, and status. Its main purpose is to see details of past queries executed in the system.
Final Answer:
To see details of past queries executed in the system -> Option A
Quick Check:
QUERY_HISTORY = past query details [OK]
Hint: QUERY_HISTORY shows past queries and their info [OK]
Common Mistakes:
Confusing QUERY_HISTORY with user management
Thinking it manages network or security settings
Assuming it creates or modifies database objects
2. Which SQL clause correctly filters queries executed by a specific user in the QUERY_HISTORY view?
easy
A. FILTER BY USER = 'john_doe'
B. WHERE USER_NAME = 'john_doe'
C. SELECT USER_NAME FROM QUERY_HISTORY WHERE 'john_doe'
D. HAVING USER_NAME = 'john_doe'
Solution
Step 1: Recall SQL filtering syntax
To filter rows in SQL, the WHERE clause is used with a condition like USER_NAME = 'value'. WHERE USER_NAME = 'john_doe' is valid and standard SQL syntax.
Final Answer:
WHERE USER_NAME = 'john_doe' -> Option B
Quick Check:
Filter with WHERE clause = WHERE USER_NAME = 'john_doe' [OK]
Hint: Use WHERE to filter rows by user name [OK]
Common Mistakes:
Using FILTER BY instead of WHERE
Misplacing HAVING without GROUP BY
Incorrect SELECT syntax without WHERE
3. Given the query:
SELECT query_text, total_elapsed_time FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) WHERE execution_status = 'FAILED' ORDER BY start_time DESC LIMIT 1;
What does this query return?
medium
A. The most recent failed query's text and its total elapsed time
B. All successful queries ordered by start time
C. The oldest failed query's text and elapsed time
D. An error because QUERY_HISTORY is not a table
Solution
Step 1: Analyze the query clauses
The query uses TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) to access query history, filters for execution_status = 'FAILED', orders by start_time DESC (most recent first), and limits to 1 row, returning the most recent failed query's text and total elapsed time.
Final Answer:
The most recent failed query's text and its total elapsed time -> Option A
Quick Check:
Filter failed + order desc + limit 1 = most recent failed query [OK]
Hint: ORDER BY DESC + LIMIT 1 gets latest record [OK]
Common Mistakes:
Thinking QUERY_HISTORY is a normal table
Confusing oldest vs most recent due to ORDER BY
Ignoring the WHERE filter on execution_status
4. You wrote this query to find slow queries but it returns no results:
SELECT query_text FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) WHERE total_elapsed_time > 1000;
What is the likely issue?
medium
A. The TABLE() function cannot be used with QUERY_HISTORY
B. QUERY_HISTORY does not have total_elapsed_time column
C. The query_text column cannot be selected from QUERY_HISTORY
D. total_elapsed_time is in microseconds, so 1000 is too small a threshold
Solution
Step 1: Check the unit of total_elapsed_time
In Snowflake, total_elapsed_time is measured in microseconds, so 1000 microseconds (1 millisecond) is too small a threshold, and few or no queries exceed it, resulting in no results.
Final Answer:
total_elapsed_time is in microseconds, so 1000 is too small a threshold -> Option D
Quick Check:
Elapsed time unit = microseconds, threshold too low [OK]
Hint: Check units: elapsed time is microseconds, not milliseconds [OK]
Common Mistakes:
Assuming elapsed time is in seconds or milliseconds
Thinking QUERY_HISTORY lacks columns
Misusing TABLE() function syntax
5. You want to profile query performance by grouping queries by user and calculating average execution time. Which query correctly achieves this?
hard
A. SELECT user_name, SUM(total_elapsed_time) FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) WHERE execution_status = 'SUCCESS';
B. SELECT user_name, total_elapsed_time FROM QUERY_HISTORY GROUP BY user_name;
C. SELECT user_name, AVG(total_elapsed_time) AS avg_time FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) GROUP BY user_name ORDER BY avg_time DESC;
D. SELECT user_name, AVG(total_elapsed_time) FROM QUERY_HISTORY WHERE total_elapsed_time > 1000 ORDER BY user_name;
Solution
Step 1: Identify correct aggregation and grouping
To get average execution time per user, use AVG(total_elapsed_time) with GROUP BY user_name from TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()), as in SELECT user_name, AVG(total_elapsed_time) AS avg_time ... GROUP BY user_name ORDER BY avg_time DESC.
Final Answer:
SELECT user_name, AVG(total_elapsed_time) AS avg_time FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) GROUP BY user_name ORDER BY avg_time DESC; -> Option C
Quick Check:
Group by user + AVG + ORDER BY avg_time = SELECT user_name, AVG(total_elapsed_time) AS avg_time FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) GROUP BY user_name ORDER BY avg_time DESC; [OK]
Hint: Use GROUP BY user_name with AVG for profiling [OK]