Micro partitions and Clustering Flashcards

1
Q

What is Microparitioning?

A

It is a way how SF physically stores the data. Incoming source data is divided into smaller chunks, their metadata collected and stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why there is a need for micropartitioning?

A

For query efficiency. This avoids full table scan by using query pruning. SF collects some metadata on micro partitions. So when a query runs, based on the metadata it prunes away some partitions, so full table scan is avoided.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the size of micro partition?

A

50 to 500MB before compression. Data is always stored as compressed format in SF.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is query pruning?

A

It is simply a concept where unnecessary partitions are avoided to be scanned for that query. It is based on the metadata collected while creating micro partitions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What metadata is collected on micropartitions?

A

Range of values.
distinct values.
additional properties that SF collects for query performance which is not revealed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Micro partitions are collected by users? Can it be changed by users?

A

It is not created by users. SF automatically does it as data is coming in. It cannot be changed by users.
Users can do clustering from their end which will improve performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is clustering depth?

A

Once micro partitions are created, SF also collects metadata on how many micro partitions overlap… This overlapping is called clustering depth. Lower the depth it is good.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the clustering depth of empty table?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the disadvantages of static partitioning done in traditional databases which Microparitioning takes care of ?

A
  1. maintenance (as data gets updated, static partitioning can go outdated)
  2. Data skew if partition columns are not uniformly distributed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Is micro partitions logical storage or physical storage?

A

They are physical storage - how tables are physically stored at the back end - data is stored in columnar format.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When do you need clustering/setting up cluster keys?

A

When clustering depth is large on micropartitions, (because ordering at the time of the insert was not perfect)
when lot of DMLs has happened on the tables and existing micropartitions are not causing efficient query pruning etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Clustering can be done on what object types?

A

Tables and materialized views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Clustering is recommended for what tables?

A

large tables where queries are running slower.
large tables where DML is happening frequently.
generally tables in Terabyte range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you choose columns for clustering?

A

Clustering will create new micropartitions (MPs) so it will add to storage cost so you have to be careful about how many columns and what columns you choose.

  1. 3 to 4 columns is ok.
  2. Choose columns used in filters and then used in joins.

Choose columns

  1. that have lot of distinct values so many MPs can be ignored using query pruning
  2. as well as it should not be so unique that MPs cannot group them.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What columns should not be chosen for clustering?

A

Extremely high cardinal (most unique values) like id columns should not be chosen….because it cannot be grouped together for creating a cluster.

Extremely low cardinal columns (less unique values) like gender should not be chosen as well….because query pruning cannot be done efficiently.

For high cardinal columns like timestamp, you can do expressions like to_date conversion to do efficient clustering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When choosing multiple columns for clustering - what order to be followed?

A

Choose from lowest cardinality to highest.

17
Q

What is Reclustering?

A

when lot of DMLs has happened on clustered tables over time, SF automatically does Reclustering to keep clustering/query performance efficient.

18
Q

Does reclustering end up in additional costs?

A

Yes, because it will create new MPs. Old MPs will be reserved for time travel and fail safe.

19
Q

Can you do expressions on clustering key columns?

A

Yes, some limited expressions like timestamp to date conversions can be done.

20
Q

Does changing the clustering key using ALTER impact anything to the table immediately?

A

There will be no impact unless there is another reclustering.

21
Q

When does SF does reclustering?

A

When SF determines there is a benefit in doing this….it is doing automatically.
No need to monitor clustered table current state by users.
No need for users to designate any WHs for reclustering.
Everything is done by SF.

22
Q

What are benefits of automated reclustering from SF?

A
  1. Users need not allocate resources/WHs for it. SF does it dynamically when it sees the benefit.
  2. Users need not monitor the current state.
  3. SF gives full control in the sense - users can even suspend reclustering OR even remove the cluster key.
  4. It does not block DML operations while reclustering is done.
23
Q

Do you need to provide virtual WH for reclustering?

A

No need…as it is done by SF automatically dynamically.

24
Q

What privileges are needed to add clustering to the table?

A

USAGE/OWNERSHIP privileges on the database and schema of that table.

25
Q

Is automated reclustering enabled by default?

A

Yes, once you define tables with clustering keys it is enabled by default. You can suspend it using ALTER command when it is not required. You can also resume it later.

26
Q

Where do you see bills for AUTOMATIC CLUSTERING?

A

As an account admin, go to Account>Usage….
See service called AUTOMATIC_CLUSTERING.

Also you can see
AUTOMATIC_CLUSTERING_HISTORY table in info schema

AUTOMATIC_CLUSTERING_HISTORY view in Account usage schema

27
Q

Can resource monitor control the WH used for automated reclustering?

A

As it is done by SF directly, resource monitor cannot control that.

28
Q

Is manual reclustering available?

A

No this option was removed now.

29
Q

Is clustering depth the best way to check if table is well clustered?

A

Nope. Query performance is the best way. If query is performing badly, then it definitely says table is not well clustered. Clustering depth is just another additional metric to check.

30
Q

What are the system functions available to view or monitor clustering metadata?

A

SYSTEM$CLUSTERING_DEPTH

SYSTEM$CLUSTERING_INFORMATION (including clustering depth)