Recall & Review
beginner
What is a GIN index in PostgreSQL?
A GIN (Generalized Inverted Index) index helps speed up searches on columns containing complex data types like arrays and JSONB by indexing their individual elements.
Click to reveal answer
beginner
Why use a GIN index for JSONB columns?
Because JSONB stores nested data, a GIN index allows fast searching inside the JSON structure, like finding keys or values without scanning the whole table.
Click to reveal answer
beginner
How do you create a GIN index on a JSONB column named 'data' in a table 'items'?
Use the SQL command: <br>
CREATE INDEX idx_gin_data ON items USING GIN (data);Click to reveal answer
intermediate
What types of queries benefit most from GIN indexes on arrays or JSONB?
Queries that check if an array contains a value or if JSONB contains a key or value, for example using operators like
@> or ?.Click to reveal answer
beginner
Can GIN indexes be used on regular text columns?
No, GIN indexes are designed for complex data types like arrays, JSONB, and full-text search, not for simple text columns.
Click to reveal answer
What does GIN stand for in PostgreSQL indexing?
✗ Incorrect
GIN stands for Generalized Inverted Index, which is used for indexing complex data types.
Which PostgreSQL data type commonly uses GIN indexes for faster queries?
✗ Incorrect
JSONB columns benefit from GIN indexes because they store nested data structures.
Which SQL command creates a GIN index on a column named 'tags' in table 'products'?
✗ Incorrect
The correct syntax is: CREATE INDEX index_name ON table_name USING GIN (column_name);
Which operator is commonly used with GIN indexes on JSONB to check if one JSON contains another?
✗ Incorrect
The '@>' operator checks if the left JSONB contains the right JSONB, and works efficiently with GIN indexes.
What is a key benefit of using GIN indexes on arrays?
✗ Incorrect
GIN indexes speed up searches for specific elements inside arrays by indexing each element.
Explain how a GIN index improves query performance on JSONB columns.
Think about how searching inside nested data can be slow without indexing.
You got /4 concepts.
Describe the steps to create and use a GIN index on an array column in PostgreSQL.
Focus on syntax and query patterns that use the index.
You got /4 concepts.