ExamGecko
Question list
Search
Search

Question 687 - COF-C02 discussion

Report
Export

A query containing a WHERE clause is running longer than expected. The Query Profile shows that all micro-partitions being scanned How should this query be optimized?

A.
Create a view on the table.
Answers
A.
Create a view on the table.
B.
Add a clustering key to the table
Answers
B.
Add a clustering key to the table
C.
Add a limit clause to the query.
Answers
C.
Add a limit clause to the query.
D.
Add a Dynamic Data Masking policy to the table.
Answers
D.
Add a Dynamic Data Masking policy to the table.
Suggested answer: B

Explanation:

When a query containing a WHERE clause is running longer than expected, and the Query Profile shows that all micro-partitions are being scanned, the query can be optimized by adding a clustering key to the table.

Understanding Micro-Partitioning in Snowflake:

Snowflake automatically partitions tables into micro-partitions for efficient storage and query performance.

Each micro-partition contains metadata about the range of values it holds, which helps in pruning irrelevant partitions during query execution.

Role of Clustering Keys:

A clustering key defines how data in a table is organized within micro-partitions.

By specifying a clustering key, you can control the physical layout of data, ensuring that related rows are stored together.

This organization improves query performance by reducing the number of micro-partitions that need to be scanned.

Optimizing Queries with Clustering Keys:

Adding a clustering key based on columns frequently used in WHERE clauses helps Snowflake quickly locate and scan relevant micro-partitions.

This minimizes the amount of data scanned and reduces query execution time.

Example:

ALTER TABLE my_table CLUSTER BY (column1, column2);

This command adds a clustering key to my_table using column1 and column2.

Future queries that filter on these columns will benefit from improved performance.

Benefits:

Reduced query execution time: Fewer micro-partitions need to be scanned.

Improved resource utilization: More efficient data retrieval leads to lower compute costs.

References:

Snowflake Documentation: Clustering Keys

Snowflake Documentation: Query Profile

asked 23/09/2024
Robert Calderon
36 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first