QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1450082.59..1450107.59 rows=10000 width=111) (actual time=57409.001..57411.967 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.172..0.202 rows=1 loops=1) Filter: ((ctype = 'item_lang'::text) AND (code = 'eng'::text)) Rows Removed by Filter: 652 -> Sort (cost=1450066.79..1451673.85 rows=642823 width=111) (actual time=57408.999..57410.296 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=1372003.29..1404144.44 rows=642823 width=111) (actual time=50859.952..56054.336 rows=1518559 loops=1) -> Nested Loop (cost=700793.98..881850.76 rows=642823 width=111) (actual time=18743.579..31876.575 rows=1671050 loops=1) -> CTE Scan on lang_with (cost=0.00..0.02 rows=1 width=4) (actual time=0.176..0.208 rows=1 loops=1) -> Hash Left Join (cost=700793.98..875422.51 rows=642823 width=107) (actual time=18743.394..31288.360 rows=1671050 loops=1) Hash Cond: (m.source = pubdate_t.source) -> Hash Join (cost=528346.12..592903.44 rows=642823 width=92) (actual time=14839.610..23861.569 rows=1671050 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.004..1054.407 rows=1928507 loops=1) -> Hash (cost=520774.76..520774.76 rows=605709 width=92) (actual time=14839.156..14839.156 rows=1580565 loops=1) Buckets: 65536 Batches: 1 Memory Usage: 200940kB -> Seq Scan on record_attr_vector_list mrv (cost=0.00..520774.76 rows=605709 width=92) (actual time=0.055..8905.962 rows=1580565 loops=1) Filter: query_int_wrapper(vlist, '(61|311)'::text) Rows Removed by Filter: 236507 -> Hash (cost=149680.33..149680.33 rows=1821403 width=23) (actual time=3902.182..3902.182 rows=1819299 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.008..1544.962 rows=1819299 loops=1) Filter: (attr = 'pubdate'::text) Rows Removed by Filter: 3439450 Total runtime: 57509.754 ms (27 rows)