database performacne Flashcards

1
Q

What is database performance?

A

Database performance refers to the effectiveness of database systems in managing data operations, measured by response time, throughput, and resource utilization.

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

Why is database tuning important?

A
  1. Improves user experience
  2. Optimizes resource usage
  3. Ensures consistency and reliability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is database design in the context of performance tuning?

A

Database design involves structuring the database to reduce redundancy, ensure data integrity, and enhance performance through optimal schema, table, column, relationship, and constraint management.

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

What are the consequences of bad database design?

A
  1. Redundancy
  2. Update anomalies
  3. Inefficiency
  4. Scalability issues
  5. Loss of flexibility
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is indexing?

A

Indexing is the process of creating a data structure to improve the speed of data retrieval operations on a database table at the cost of additional writes and storage space.

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

When should indexes be used?

A
  1. Columns frequently used in the WHERE clause
  2. Columns used in JOIN conditions
  3. Columns used for sorting data in ORDER BY clauses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is query optimization?

A

Query optimization involves rewriting queries, choosing efficient execution paths, and using database features like indexes and partitioning to reduce the time and resources required to execute SQL queries.

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

What are the principles of query optimization?

A
  1. Understanding execution plans
  2. Proper use of indexes
  3. Query rewriting
  4. Keeping statistics and cardinality estimates up to date
  5. Leveraging database features like partitioning and materialized views
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Provide an example of a simple optimization by filtering early.

A

Bad:
SELECT * FROM sales WHERE year = 2023;
Better:
SELECT customer_id, total FROM sales WHERE year = 2023;

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

What is the advantage of using SQL functions?

A

SQL functions encapsulate complex operations into reusable blocks of code, improving performance, ensuring consistency, and maintaining data integrity by centralizing logic within the database.

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

Provide an example of a SQL function to check order limits.

A

CREATE OR REPLACE FUNCTION check_order_limit()
RETURNS TRIGGER AS $$
DECLARE
total_orders_for_day NUMERIC;
BEGIN
SELECT SUM(amount) INTO total_orders_for_day
FROM orders
WHERE customer_id = NEW.customer_id AND
date_trunc(‘day’, order_date) = date_trunc(‘day’, NEW.order_date);

IF total_orders_for_day + NEW.amount > 5000 THEN
    RAISE EXCEPTION 'Total orders for the day exceed the £5,000 limit.';
END IF;

RETURN NEW; END; \$\$ LANGUAGE plpgsql;

CREATE TRIGGER check_order_before_insert
BEFORE INSERT OR UPDATE ON orders
FOR EACH ROW EXECUTE FUNCTION check_order_limit();

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

What is the importance of monitoring and continuous improvement in database performance tuning?

A

Continuous monitoring helps identify performance bottlenecks, inefficient queries, and data integrity issues, allowing for proactive issue resolution and maintaining optimal database performance.

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

What key areas should be monitored for database performance?

A
  1. Query performance
  2. Resource utilization (CPU, memory, disk I/O)
  3. Index usage and efficiency
  4. Errors and warnings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the continuous improvement cycle for database performance tuning?

A
  1. Assess
  2. Plan
  3. Implement
  4. Review
How well did you know this?
1
Not at all
2
3
4
5
Perfectly