Thread: unexpected external sort Disk

unexpected external sort Disk

From
Manuel Kniep
Date:
Hello,

I have table with 37 million entries the whole table has a size of  2.3 GB

Although I have set the work_mem to 10 GB

I see the an unexpected external sort Disk in Explain Analyze for around 650MB of data

 EXPLAIN ANALYZE  SELECT application_id, price_tier FROM application_prices order by application_id, created_at;

                                                               QUERY PLAN

----------------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=5284625.89..5378196.50 rows=37428244 width=8) (actual time=36972.658..40618.161 rows=37428244 loops=1)
   Sort Key: application_id, created_at
   Sort Method: external sort  Disk: 658568kB
   ->  Seq Scan on application_prices  (cost=0.00..576597.44 rows=37428244 width=8) (actual time=0.012..6259.923
rows=37428244loops=1) 
 Total runtime: 42999.882 ms
(5 rows)

Has anyone an idea what I'm missing ?

Thanks

Manuel



Re: unexpected external sort Disk

From
Jeff Janes
Date:
On Thu, Jun 20, 2013 at 6:12 AM, Manuel Kniep <rapimo@adeven.com> wrote:
Hello,

I have table with 37 million entries the whole table has a size of  2.3 GB

Although I have set the work_mem to 10 GB


There is one piece of memory used in in-memory sorting that (currently) has to be a single contiguous allocation, and that piece is limited to 1GB.  This means you can't always use the entire amount of work_mem declared, especially when sorting a very large number of very short rows, as you seem to be doing.

There is another "rounding" issue that means sometimes as little as 512MB of that 1GB is actually used.  This part is probably fixed for 9.3.


Cheers,

Jeff