Postgres uses a ranking function to order full-text search results. Which of the following best describes how the ts_rank function ranks documents?
Think about how relevance is usually measured in search engines.
The ts_rank function ranks documents by how often and where the search terms appear, giving higher scores to documents where terms appear more frequently and earlier.
You want to create a full-text search index on the content column of a documents table. Which SQL command correctly creates a GIN index for this purpose?
Consider which index type supports fast full-text search queries.
GIN indexes are optimized for full-text search with to_tsvector. BTREE and HASH do not support this efficiently.
You have a Postgres database with a large articles table. You want to keep the full-text search index updated in real-time as new articles are inserted or updated. Which architecture is best?
Think about minimizing delay and keeping search fast.
Updating a tsvector column via triggers keeps the search vector current and indexed for fast queries. Materialized views and batch rebuilds cause delays.
You build a search feature using Postgres full-text search. Users enter search terms that are included in SQL queries. Which practice best prevents SQL injection attacks?
Think about how databases safely handle user input.
Parameterized queries ensure user input is treated as data, not code, preventing injection. Manual escaping or filtering is error-prone.
You have a Postgres table with millions of rows and a full-text search index on a tsvector column. Queries are slow during peak hours. Which approach best improves performance without sacrificing result accuracy?
Consider index maintenance and query speed trade-offs.
GIN indexes with fastupdate enabled speed up writes and keep reads fast. Regular vacuuming keeps statistics accurate for query planning.