Optimizing a postgres similarity query (pg_trgm + gin index)
问题 I have defined the following index: CREATE INDEX users_search_idx ON auth_user USING gin( username gin_trgm_ops, first_name gin_trgm_ops, last_name gin_trgm_ops ); I am performing the following query: PREPARE user_search (TEXT, INT) AS SELECT username, email, first_name, last_name, ( -- would probably do per-field weightings here s_username + s_first_name + s_last_name ) rank FROM auth_user, similarity(username, $1) s_username, similarity(first_name, $1) s_first_name, similarity(last_name, $1