Views Flashcards

1
Q

What are secured views? Can it be applied on both materialized and non materialized views?

A

Secured views provides data privacy especially while data sharing to other users. It blocks the view DDL from the user, block underlying tables/functions used.

It can be applied to both view types materialized and non materialized views

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

How you will create secure vews?

A

CREATE OR REPLACE SECURE VIEW AS

select * from ……

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

Can you change or update the view definition anytime?

A

you can only create or replace. Cannot alter whether it is normal view or materialixed veew.

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

Changing table definition makes the view definition change automatically?

A

No…view should be manually recreated.

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

Does secure view impact query performance nnegatively?

A

Yes.
Query optimizer generally bypasses some optimizations used for normal views. So DE must be careful about creating security views.

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

How do you make normal view secure view? and can you do vice versa?

A

Yes. ALTER VIEW set SECURE or unset SECURE.

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

How do you identify if the view is secure or not?

A

IS_SECURE flag in information schema or account usage schema.views will provide this information

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

Are there any pitfalls in still exposing some data privacy while using secured views?

A

Yes. Ex: If a column is sequence number using auto increment, it will provide some picture to user. Best to use UUID_STRING for random identifiers there or not expose that sequence number columns.

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

Does SF gives size/byte information on amount of data scanned or total data in secured views?

A

No - SF does not give storage information on secured views. User might be able to guess based on run time though.

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

is CURRENT_ROLE or current_user function allowed in SF secured views that is shared to other accounts?

A

No because the person it was shared does not control role or user in the view.

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

What are materialized M views?

A

M view is a precomputed data set used for later use.
It is faster than normal queries.
So if users run some queries frequently on larger tables, M views can be a better option.

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

Which scenarios where M view very useful even though there are limitations?

A
  1. when data is in external tables. M view on external tables will improver performance.
  2. when query is so frequent/common and on larger tables.
  3. when query result is very small compared to bigger table
  4. when query takes very longer to run
  5. When query result change less frequently than usage of the view. kammi change but adhiga use.

Basically it offers a well performing reduced size table.

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

Are M views maintained by SF?

A

Yes M views are automatically maintained by SF whenever base table changes are done.
Data accessed thru M view is always current unless some delete or DDL changes happened in view. DML operations are all shown current in M view
But this takes some cost.

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

Is M view is faster than cached query results?

A

No…M view is not faster than caches q result but remember cached result stays active only for 24 hours and goes away when there is any table change.

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

Does regular view provide performance benefts?

A

Cant say like that. It provides security benefits.

M views are for performance and security benefits.

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

What is the role of query optimizer in M views?

A

Query optimizer can choose between M view and base table depending on what might be best and efficient.

ex: if base table is clustered by a field which is used in query, optimizer might go to table rather than M view.

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

How do you create/alter/drop/describe/show materialized views?

A

CREATE MATERIALIZED VIEW

ALTER MATERIALIZED VIEW

DROP MATERIALIZED VIEW

DESCRIBE MATERIALIZED VIEW

SHOW MATERIALIZED VIEWS

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

Can you do DML (insert/update/delete) on M views?

A

No. DML operations not allowed…even truncate.

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

Does creating M views need privilges?

A

Yes…it requires cost and so privileges are needed.

grant create materialized view on schema to role ;

20
Q

Does user for M view need access to all underlying objects?

A

No….if they get view level access thats it.

21
Q

Why M view might be required after clustering of the table?

A

Lets say if users are using some filters which are not part of the cluster key and performance is getting bad so M view might be a good option.

22
Q

If the name of the base table is not qualified, and the table or view is moved to a different schema, the reference becomes invalid. True?

A

Yes - always use fully qualified names for base tables in views.

23
Q

Does the initial creation of materialized view take significant time?

A

Yes, at first because it is similar to creating a table.

24
Q

What are the limitations of the M view?

A
  1. M view can be built on one table only.
  2. No joins including self joins allowed.
  3. M view cannot query another view or another M view or UDFs
  4. MDF cannot have lot of functions also like ORDER BY, HAVING, UDFS, GROUP BY etc.
25
Q

Ok, so what functions are allowed in M view?

A

Aggregate functions are allowed. Ex: MIN, MAX, AVG, SUM, count, stddev, variance etc.

26
Q

Can allowed aggregate functions be nested in M view?

A

nope….aggregate function used within some subquery is not allowed either.

27
Q

is over partition by (window functions allowed)?

A

Nope, not in M view

28
Q

is deterministic functions allowed in M view?

A

Nope. CURRENT_TIME or CURRENT_TIMESTAMP is not permitted.

29
Q

Is time travel be done on M views?

A

No not on M views. SF does not offer time travel on M views.

30
Q

Does INFORMATION_SCHEMA.VIEWS shows M views?

A

Nope….it is showing in INFORMATION_SCHEMA.TABLES, with table type M views.

31
Q

What are the major limitations in using M views?

A
  1. M view cannot time travel.
  2. Lot of functions like group by, ordering cannot be done.
  3. cannot point to more than 1 table, cannot point to view or other M view.
  4. Cannot be cloned alone….If there is schema or database level cloning it is included.
  5. Though it looks like table no DML operations are allowed like insert/update/delete…even truncate nothing is allowed.
  6. M views cannot monitored using resource monitors as well.
32
Q

Does column addition to base table suspend M view?

A

No it will not but at the same time it will not add to M view as well even if you do select *

33
Q

Does column changing or removal from base table suspend M view?

A

Yes column changed or removal will suspend M view.

34
Q

Can you RESUME M view?

A

No - it has to be create/replaced only

35
Q

Are there direct tools to estimate cost of M views?

A

No tools, but it is proportional to

  1. number of M views
  2. out of which how many are clustered

etc.

36
Q

How to find billing of M views?

A

Account-> usage or billing & usage. you should be M view maintenance.

Table/View wise
MATERIALIZED_VIEW_REFRESH_HISTORY table in info schema

MATERIALIZED_VIEW_REFRESH_HISTORY view in account usage

37
Q

Are resource monitors useful in terms of M views?

A

Nope, they cannot control credit usage in M views?

38
Q

Can you cluster base tables and M views?

Can you cluster them on different columns?

A

yes, can cluster tables and M views

and can cluster them on separate columns.

39
Q

If you are planning to cluster on both tables and M views - what does SF recommends to do first?

A

SF recommends M views over base tables first and then do the base tables later as needed,

40
Q

If you plan to create a table, load it, and create a clustered materialized view(s) on the table, then Snowflake recommends that you create the materialized views last (after loading as much data as possible) - is it true?

A

Yes - because it saves maintenance money.

41
Q

what are some best practices for maintaining M views? (DML operations)

A

Maintenance means DML operations.

BATCH the delete/insert/update DML operations.

  1. Delete less frequently if possible. As delete on base table means you have to maintain on M view also. So instead of deleting hourly, you can choose to delete daily.
  2. Batch insert/update/merge options also for same reason.
42
Q

what are some best practices for clustering M views and base tables?

A

If base table is not accessed frequently, then cluster M view.
If base table change frequently, then clustering on M view adds to the cost.
If you have to cluster on M view, consider removing clustering on base table as it will add to cost.

43
Q

Change to clustering of base table - will it require refresh of M view?

A

Yes eventually though may not be needed immediately.

44
Q

How will you suspend M view?

A

alter materialized view mv1 suspend;

45
Q

can you share M view using SF’s data sharing feature?

A

Yes.