Day+15+ +Course+Slides
Day+15+ +Course+Slides
User management
Assign
✓ SELECT,
✓ INSERT,
Assign
✓ UPDATE,
Create new roles role ✓ DELETE,
✓ TRUNCATE,
✓ USAGE
User management
Assign
Assign ✓ SELECT,
Create new roles Analyst ✓ USAGE
CREATE USER
GRANT privilege
ON database_object
TO USER | ROLE | PUBLIC
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE,
✓ DELETE, Priviliges
✓ TRUNCATE,
✓ USAGE,
✓ ALL
GRANT SELECT
ON customer
TO nikolai
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE, TABLES
✓ DELETE,
✓ TRUNCATE,
✓ USAGE,
✓ ALL
GRANT SELECT
ON customer
TO nikolai
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE, TABLES
✓ DELETE,
✓ TRUNCATE,
✓ USAGE,
✓ ALL
GRANT SELECT
ON ALL TABLES IN SCHEMA schema_name
TO nikolai
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE, TABLES
✓ DELETE,
✓ TRUNCATE,
✓ USAGE,
✓ ALL
GRANT ALL
ON ALL TABLES IN SCHEMA schema_name
TO nikolai
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE, TABLES
✓ DELETE,
✓ TRUNCATE,
✓ USAGE,
✓ ALL
superuser
GRANT ALL
ON ALL TABLES IN SCHEMA schema_name
TO nikolai
owner
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE, TABLES
✓ DELETE,
✓ TRUNCATE,
✓ USAGE,
✓ ALL
superuser
GRANT SELECT
ON ALL TABLES IN SCHEMA schema_name
TO nikolai WITH GRANT OPTION
owner
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE,
✓ DELETE, Priviliges
✓ TRUNCATE,
✓ USAGE,
✓ ALL
REVOKE privilege
ON database_object
FROM USER | ROLE | PUBLIC
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE,
✓ DELETE, Priviliges
✓ TRUNCATE,
✓ USAGE,
✓ ALL
REVOKE privilege
ON database_object
FROM USER | ROLE | PUBLIC
GRANTED BY USER | ROLE
Privileges
✓ SELECT,
✓ INSERT,
✓ UPDATE,
✓ DELETE, Priviliges
✓ TRUNCATE,
✓ USAGE,
✓ ALL
DELETE TABLE
TRUNCATE TABLE
CONNECT DATABASE
USAGE SCHEMA
Privileges
How to grant acces?
Typical statements
CREATE USER
GRANT ALL
ON ALL TABLES IN SCHEMA public
TO amar ;
GRANT ALL
ON DATABASE greencycles
TO amar ;
Privileges
How to grant acces?
Typical statements
GRANT createdb
REVOKE ROLE
GRANT SELECT
ON ALL TABLES IN SCHEMA
<schema_name>
TO nikolai
Privileges
USAGE Users
Priveleges Users
Users
Users
Roles
✓
✓
SELECT,
INSERT,
CREATE ROLE <user_name>
✓ UPDATE, WITH LOGIN PASSWORD 'pwd123'
✓ DELETE,
✓ TRUNCATE,
✓ USAGE
Using indexes
Read Write
operations operations
Using indexes
Read Write
operations operations
Understanding Types of
Guidelines Demo
indexes indexes
Using indexes
SELECT
product_id
FROM sales
WHERE customer_id = 5
3, P0625, 5, visa
Table scan
4, P0432, 8, mastercard 6, P0058, 5, mastercard
SELECT
product_id
FROM sales
WHERE customer_id = 5
Location Value
1, P0494, 4, visa 2, P0221, 5, visa
1 4
6, P0058, 5, mastercard 4, P0432, 8, mastercard
2 5
3, P0625, 5, visa
5 8
✓ Indexes help to make data reads faster!
❖ Additional storage
SELECT
product_id
FROM sales
WHERE customer_id = 5
Location Value
1, P0494, 4, visa 2, P0221, 5, visa
1 4
6, P0058, 5, mastercard 4, P0432, 8, mastercard
2 5
3, P0625, 5, visa
5 8
Using indexes
Location Value ✓ Different types of indexes
1 4 for different situations
2 5
1
20 ✓ Breaks data down into pages or blocks
AB AD
1 AE
AC ✓ Should be used for high-cardinality
(unique) columns
1 ABA… 15
ABB… ✓ Not entire table (costy in terms of storage)
…
ACA…
ACB…
❖ Bitmap index
1 visa 11100
Good for many repeating values
4 mastercard 00011
(dimensionality)
❖ Bitmap index
✓ Particularily good for dataware houses
Value 1 2 3 4 5 6 7 8
Good for many repeating values
mastercard x x
(dimensionality)
visa x x x
Guidelines