QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=1165968.90..1165993.90 rows=10000 width=111) (actual time=40086.155..40088.965 rows=10000 loops=1) CTE lang_with -> Seq Scan on coded_value_map (cost=0.00..15.79 rows=1 width=4) (actual time=0.166..0.222 rows=1 loops=1) Filter: ((ctype = 'item_lang'::text) AND (code = 'eng'::text)) Rows Removed by Filter: 652 -> Sort (cost=1165953.10..1166756.63 rows=321412 width=111) (actual time=40086.152..40087.249 rows=10000 loops=1) Sort Key: ((1.0 / (avg(1) + ((1 * COALESCE(((NULLIF(first((mrv.vlist @> ARRAY[lang_with.id])), false))::integer * 5), 1)))::numeric))), (first(pubdate_t.value)) Sort Method: top-N heapsort Memory: 2175kB -> HashAggregate (cost=1126921.29..1142991.89 rows=321412 width=111) (actual time=39995.780..40064.105 rows=25061 loops=1) -> Nested Loop (cost=700793.98..881844.64 rows=321412 width=111) (actual time=26659.816..39692.847 rows=25466 loops=1) -> CTE Scan on lang_with (cost=0.00..0.02 rows=1 width=4) (actual time=0.172..0.231 rows=1 loops=1) -> Hash Left Join (cost=700793.98..878630.50 rows=321412 width=107) (actual time=26659.630..39681.779 rows=25466 loops=1) Hash Cond: (m.source = pubdate_t.source) Filter: COALESCE(((pubdate_t.value >= '2015'::text) AND (pubdate_t.value <= '2015'::text)), false) Rows Removed by Filter: 1871082 -> Hash Join (cost=528346.12..592903.44 rows=642823 width=92) (actual time=19510.217..29081.349 rows=1896548 loops=1) Hash Cond: (m.source = mrv.source) -> Seq Scan on metarecord_source_map m (cost=0.00..31612.67 rows=1928467 width=8) (actual time=0.003..656.819 rows=1928509 loops=1) -> Hash (cost=520774.76..520774.76 rows=605709 width=92) (actual time=19509.752..19509.752 rows=1807030 loops=1) Buckets: 65536 Batches: 1 Memory Usage: 228039kB -> Seq Scan on record_attr_vector_list mrv (cost=0.00..520774.76 rows=605709 width=92) (actual time=1.244..11038.227 rows=1807030 loops=1) Filter: query_int_wrapper(vlist, '(544|61|311|472|11)'::text) Rows Removed by Filter: 10043 -> Hash (cost=149680.33..149680.33 rows=1821403 width=23) (actual time=7107.504..7107.504 rows=1819302 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 85280kB -> Seq Scan on record_sorter pubdate_t (cost=0.00..149680.33 rows=1821403 width=23) (actual time=0.033..2058.799 rows=1819302 loops=1) Filter: (attr = 'pubdate'::text) Rows Removed by Filter: 3439455 Total runtime: 40167.226 ms (29 rows)