0
0
PostgreSQLquery~20 mins

Why full-text search matters in PostgreSQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Full-Text Search Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Basic full-text search query output
Given a table articles with a content column, what is the output of this query?

SELECT id FROM articles WHERE to_tsvector('english', content) @@ to_tsquery('english', 'database & search');

Assume the table has:
- id=1, content='Database systems are essential for search functionality.'
- id=2, content='Database search engines use full-text search techniques.'
- id=3, content='Databases store data efficiently.'
A[1, 2]
B[1, 3]
C[2, 3]
D[1, 2, 3]
Attempts:
2 left
💡 Hint
Look for rows where both 'database' and 'search' appear in the content.
🧠 Conceptual
intermediate
1:30remaining
Why use full-text search over LIKE?
Which of the following is the main advantage of using full-text search instead of the LIKE operator for searching text in PostgreSQL?
ALIKE is faster for large text searches.
BFull-text search only works with exact word matches.
CFull-text search can find words regardless of their order and supports stemming.
DLIKE supports ranking results by relevance automatically.
Attempts:
2 left
💡 Hint
Think about how full-text search understands word forms and order.
📝 Syntax
advanced
2:00remaining
Correct syntax for creating a full-text index
Which option correctly creates a full-text search index on the content column of the documents table using the English dictionary?
ACREATE INDEX idx_ft_content ON documents USING btree(to_tsvector('english', content));
BCREATE INDEX idx_ft_content ON documents USING gin(to_tsvector('english', content));
CCREATE INDEX idx_ft_content ON documents USING hash(to_tsvector(content));
DCREATE INDEX idx_ft_content ON documents USING gin(to_tsquery('english', content));
Attempts:
2 left
💡 Hint
Full-text indexes use GIN and tsvector, not tsquery or btree.
optimization
advanced
1:30remaining
Improving full-text search performance
You notice your full-text search queries on a large articles table are slow. Which change will most improve query speed?
ACreate a GIN index on to_tsvector('english', content).
BSwitch to using LIKE '%word%' queries instead.
CRemove the full-text index to reduce overhead.
DUse a sequential scan instead of an index scan.
Attempts:
2 left
💡 Hint
Indexes help speed up searches on large tables.
🔧 Debug
expert
2:30remaining
Why does this full-text search query return no results?
Given the query:

SELECT * FROM posts WHERE to_tsvector('english', body) @@ to_tsquery('english', 'running & fast');

and the body contains 'Running fast is important', why does this query return no rows?
AThe language 'english' is not supported in to_tsquery.
BThe to_tsvector function does not tokenize the text properly.
CThe & operator means OR, so it should return rows with either word.
DThe query uses 'running' but the text contains 'running', and to_tsquery does not stem words automatically.
Attempts:
2 left
💡 Hint
Check how to_tsquery handles word forms and stemming.