0
0
PostgreSQLquery~5 mins

Indexing JSONB with GIN in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using a GIN index on a JSONB column in PostgreSQL?
A GIN index on a JSONB column helps speed up searches for keys and values inside the JSON data, making queries faster when filtering or searching within JSON documents.
Click to reveal answer
beginner
How do you create a GIN index on a JSONB column named 'data' in a table called 'items'?
Use the SQL command:
CREATE INDEX idx_items_data ON items USING GIN (data);
This creates a GIN index on the 'data' JSONB column to speed up queries.
Click to reveal answer
intermediate
What kind of queries benefit most from a GIN index on JSONB?
Queries that use the containment operator @> to check if a JSONB column contains a specific key or value, or queries that search for existence of keys or values inside JSON documents.
Click to reveal answer
beginner
True or False: GIN indexes on JSONB columns can index nested keys and values inside the JSON structure.
True. GIN indexes can index nested keys and values, allowing efficient queries deep inside JSON documents.
Click to reveal answer
intermediate
What is a downside of using GIN indexes on JSONB columns?
GIN indexes can be slower to update when data changes, so write operations may be slower. Also, they use more disk space compared to regular indexes.
Click to reveal answer
Which SQL command creates a GIN index on a JSONB column named 'info' in table 'users'?
ACREATE INDEX idx_users_info ON users (info);
BCREATE INDEX idx_users_info ON users USING BTREE (info);
CCREATE INDEX idx_users_info ON users USING HASH (info);
DCREATE INDEX idx_users_info ON users USING GIN (info);
What operator is commonly used in queries that benefit from a GIN index on JSONB?
A<>
B=
C@>
DLIKE
True or False: GIN indexes on JSONB columns can speed up searches for nested keys.
ATrue
BFalse
COnly for top-level keys
DOnly for arrays
What is a common trade-off when using GIN indexes on JSONB columns?
AFaster writes but slower reads
BSlower writes but faster reads
CNo difference in performance
DSlower reads and writes
Which PostgreSQL data type is required to use GIN indexing for JSON data?
AJSONB
BTEXT
CJSON (plain)
DVARCHAR
Explain how a GIN index improves query performance on a JSONB column.
Think about how searching inside a big JSON document can be slow without an index.
You got /4 concepts.
    Describe the trade-offs of using a GIN index on JSONB data in PostgreSQL.
    Consider what happens when data changes and the index needs to be updated.
    You got /4 concepts.