Skip to content

Instantly share code, notes, and snippets.

@kesha-antonov
Created November 4, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kesha-antonov/50bb1e473d3c03678aab to your computer and use it in GitHub Desktop.
Save kesha-antonov/50bb1e473d3c03678aab to your computer and use it in GitHub Desktop.
Article Load (331.8ms) SELECT "articles".* FROM "articles" INNER JOIN (SELECT "articles"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("articles"."text"::text, '')) || to_tsvector('simple', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_c81a66135b0eb97fa238c2::text, ''))), (to_tsquery('simple', ''' ' || 'rap2' || ' ''' || ':*')), 0)) AS rank FROM "articles" LEFT OUTER JOIN (SELECT "articles"."id" AS id, string_agg("users"."name"::text, ' ') AS pg_search_c81a66135b0eb97fa238c2 FROM "articles" INNER JOIN "users" ON "users"."id" = "articles"."user_id" GROUP BY "articles"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "articles"."id" WHERE (((to_tsvector('simple', coalesce("articles"."text"::text, '')) || to_tsvector('simple', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_c81a66135b0eb97fa238c2::text, ''))) @@ (to_tsquery('simple', ''' ' || 'rap2' || ' ''' || ':*'))))) pg_search_articles ON "articles"."id" = pg_search_articles.pg_search_id ORDER BY pg_search_articles.rank DESC, "articles"."id" ASC
=> EXPLAIN for: SELECT "articles".* FROM "articles" INNER JOIN (SELECT "articles"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("articles"."text"::text, '')) || to_tsvector('simple', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_c81a66135b0eb97fa238c2::text, ''))), (to_tsquery('simple', ''' ' || 'rap2' || ' ''' || ':*')), 0)) AS rank FROM "articles" LEFT OUTER JOIN (SELECT "articles"."id" AS id, string_agg("users"."name"::text, ' ') AS pg_search_c81a66135b0eb97fa238c2 FROM "articles" INNER JOIN "users" ON "users"."id" = "articles"."user_id" GROUP BY "articles"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "articles"."id" WHERE (((to_tsvector('simple', coalesce("articles"."text"::text, '')) || to_tsvector('simple', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_c81a66135b0eb97fa238c2::text, ''))) @@ (to_tsquery('simple', ''' ' || 'rap2' || ' ''' || ':*'))))) pg_search_articles ON "articles"."id" = pg_search_articles.pg_search_id ORDER BY pg_search_articles.rank DESC, "articles"."id" ASC
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=472.70..472.71 rows=5 width=2077)
Sort Key: (ts_rank((to_tsvector('simple'::regconfig, COALESCE(articles_1.text, ''::text)) || to_tsvector('simple'::regconfig, COALESCE((string_agg((users.name)::text, ' '::text)), ''::text))), '''rap2'':*'::tsquery, 0)), articles.id
-> Nested Loop (cost=414.63..472.64 rows=5 width=2077)
-> Hash Right Join (cost=414.35..468.10 rows=5 width=1040)
Hash Cond: (articles_2.id = articles_1.id)
Filter: ((to_tsvector('simple'::regconfig, COALESCE(articles_1.text, ''::text)) || to_tsvector('simple'::regconfig, COALESCE((string_agg((users.name)::text, ' '::text)), ''::text))) @@ '''rap2'':*'::tsquery)
-> GroupAggregate (cost=248.85..268.85 rows=1000 width=36)
Group Key: articles_2.id
-> Sort (cost=248.85..251.35 rows=1000 width=36)
Sort Key: articles_2.id
-> Hash Join (cost=32.27..199.03 rows=1000 width=36)
Hash Cond: (articles_2.user_id = users.id)
-> Seq Scan on articles articles_2 (cost=0.00..153.00 rows=1000 width=8)
-> Hash (cost=19.90..19.90 rows=990 width=36)
-> Seq Scan on users (cost=0.00..19.90 rows=990 width=36)
-> Hash (cost=153.00..153.00 rows=1000 width=1008)
-> Seq Scan on articles articles_1 (cost=0.00..153.00 rows=1000 width=1008)
-> Index Scan using articles_pkey on articles (cost=0.28..0.89 rows=1 width=1041)
Index Cond: (id = articles_1.id)
(19 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment