PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 8 - RDBMS Concepts
Lesson Content Link:Database Index
Current Quiz Count:30
Progress
0%
Q1
True / False

In PostgreSQL, indexes are used to speed up the retrieval of rows from a table.

Q2
True / False

In PostgreSQL, creating an index automatically ensures that the data in the table is unique.

Q3
True / False

In PostgreSQL, indexes can be created on one or more columns of a table.

Q4
True / False

In PostgreSQL, a B-tree index is the default type of index.

Q5
True / False

In PostgreSQL, creating too many indexes can slow down data modification operations.

Q6
True / False

In PostgreSQL, the ANALYZE command updates the statistics of indexes as well as tables.

Q7
True / False

In PostgreSQL, partial indexes are indexes that only cover a subset of the rows in a table.

Q8
True / False

In PostgreSQL, GiST indexes are suitable for full-text search.

Q9
True / False

In PostgreSQL, expression indexes can be used to index the result of a function or expression.

Q10
True / False

In PostgreSQL, using the REINDEX command can help fix corrupted indexes and improve database performance.

Q11
Single Choice

What is the primary purpose of an index in PostgreSQL?

Q12
Single Choice

Which SQL command is used to create an index in PostgreSQL?

Q13
Single Choice

Which type of index is automatically created on primary key columns in PostgreSQL?

Q14
Single Choice

Consider the following SQL command in PostgreSQL:

SQL Code
CREATE INDEX idx_employee_name ON employees(name);
What does this index do?
Q15
Single Choice

How can you check the indexes on a table named orders in PostgreSQL?

Q16
Single Choice

In PostgreSQL, which of the following can be indexed?

Q17
Single Choice

Given the following SQL command, what type of index is being created in PostgreSQL?

SQL Code
CREATE INDEX idx_fulltext ON documents USING GIN(to_tsvector('english', content));
Q18
Single Choice

Which of the following is a disadvantage of using too many indexes in a PostgreSQL database?

Q19
Single Choice

Consider the following SQL command in PostgreSQL:

SQL Code
CREATE INDEX idx_partial ON sales(amount) WHERE amount > 1000;
What is the purpose of this partial index?
Q20
Single Choice

Which of the following statements is true about index-only scans in PostgreSQL?

Q21
Multiple Choice

What is the primary purpose of a Database Index in PostgreSQL?

SQL Code
Consider a 'customers' table with columns 'customer_id', 'first_name', 'last_name', and 'email'. Create an index on the 'email' column to speed up searches based on email addresses.

```sql
CREATE INDEX idx_email ON customers(email);
```
Q22
Multiple Choice

In which scenarios would you choose to create a composite index in PostgreSQL?

SQL Code
Given a 'orders' table with columns 'order_id', 'customer_id', 'order_date', and 'order_status', create a composite index on 'customer_id' and 'order_date' to optimize queries that filter on both columns.

```sql
CREATE INDEX idx_customer_order_date ON orders(customer_id, order_date);
```
Q23
Multiple Choice

What are the potential downsides of using too many indexes on a PostgreSQL table?

SQL Code
Consider a 'products' table with columns 'product_id', 'product_name', 'category_id', and 'price'. Discuss the impact of creating multiple indexes on 'product_name', 'category_id', and 'price'.

```sql
CREATE INDEX idx_product_name ON products(product_name);
CREATE INDEX idx_category_id ON products(category_id);
CREATE INDEX idx_price ON products(price);
```
Q24
Multiple Choice

How does a unique index differ from a regular index in PostgreSQL?

SQL Code
Create a unique index on the 'username' column of a 'users' table to enforce uniqueness and speed up lookups.

```sql
CREATE UNIQUE INDEX idx_unique_username ON users(username);
```
Q25
Multiple Choice

When should you consider using a partial index in PostgreSQL?

SQL Code
Create a partial index on the 'orders' table to index only the rows where 'order_status' is 'shipped'.

```sql
CREATE INDEX idx_partial_shipped ON orders(order_date) WHERE order_status = 'shipped';
```
Q26
Multiple Choice

What is the impact of using a GIN index on JSONB columns in PostgreSQL?

SQL Code
Given a 'logs' table with a JSONB column 'log_data', create a GIN index to optimize searches within the JSONB data.

```sql
CREATE INDEX idx_gin_log_data ON logs USING GIN(log_data);
```
Q27
Multiple Choice

How do BRIN indexes differ from B-tree indexes in PostgreSQL?

SQL Code
Create a BRIN index on the 'created_at' column of a large 'events' table to optimize range queries.

```sql
CREATE INDEX idx_brin_created_at ON events USING BRIN(created_at);
```
Q28
Multiple Choice

What factors should be considered when choosing columns to index in PostgreSQL?

SQL Code
Given a 'sales' table with columns 'sale_id', 'customer_id', 'product_id', and 'sale_date', discuss the factors to consider when deciding whether to index the 'customer_id' and 'sale_date' columns.

```sql
CREATE INDEX idx_customer_sale_date ON sales(customer_id, sale_date);
```
Q29
Multiple Choice

How do covering indexes improve query performance in PostgreSQL?

SQL Code
Create a covering index on the 'orders' table that includes the 'customer_id' and 'order_total' columns to optimize queries that select these columns.

```sql
CREATE INDEX idx_covering_customer_total ON orders(customer_id) INCLUDE(order_total);
```
Q30
Multiple Choice

What are the benefits and trade-offs of using a clustered index in PostgreSQL?

SQL Code
Discuss the benefits and trade-offs of clustering a 'orders' table on the 'order_date' column. Implement clustering in PostgreSQL.

```sql
CLUSTER orders USING idx_order_date;
```