Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 061809FBDE6 for ; Fri, 12 Oct 2007 17:42:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 51057-05 for ; Fri, 12 Oct 2007 17:41:54 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from bay0-omc2-s6.bay0.hotmail.com (bay0-omc2-s6.bay0.hotmail.com [65.54.246.142]) by postgresql.org (Postfix) with ESMTP id BB5199FBDDF for ; Fri, 12 Oct 2007 17:41:57 -0300 (ADT) Received: from BAY124-W50 ([207.46.11.213]) by bay0-omc2-s6.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 12 Oct 2007 13:41:56 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_690d3132-f779-4ef2-bbad-de4168b804d8_" X-Originating-IP: [86.81.58.36] From: henk de wit To: "pgsql-performance@postgresql.org" Subject: How to speed up min/max(id) in 50M rows table? Date: Fri, 12 Oct 2007 22:41:56 +0200 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 12 Oct 2007 20:41:56.0694 (UTC) FILETIME=[546A2760:01C80D10] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/150 X-Sequence-Number: 27172 --_690d3132-f779-4ef2-bbad-de4168b804d8_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I have a table with some 50 millions rows in PG 8.2. The table has indexes = on relevant columns. My problem is that most everything I do with this tabl= e (which are actually very basic selects) is unbearable slow. For example: select max(payment_id) from transactions This takes 161 seconds. The plan looks like this: "Result (cost=3D0.37..0.38 rows=3D1 width=3D0) (actual time=3D184231.636..= 184231.638 rows=3D1 loops=3D1)" " InitPlan" " -> Limit (cost=3D0.00..0.37 rows=3D1 width=3D8) (actual time=3D18423= 1.620..184231.622 rows=3D1 loops=3D1)" " -> Index Scan Backward using trans_payment_id_index on transact= ions (cost=3D0.00..19144690.58 rows=3D51122691 width=3D8) (actual time=3D1= 84231.613..184231.613 rows=3D1 loops=3D1)" " Filter: (payment_id IS NOT NULL)" "Total runtime: 184231.755 ms" As shown, in the plan, the index on the requested column "payment_id" is be= ing used, but the query still takes quite a lot of time. If I use a where c= lause in a similar query, the query seemingly runs forever, e.g. select min(time) from transactions where payment_id =3D 67 There are indexes on both the time (a timestamp with time zone) and payment= _id (a bigint) columns. About 1 million rows satisfy the condition payment_= id =3D 67. This query takes a totally unrealistic amount of time for execut= ion (I have it running for >30 minutes now on a machine with 8GB and 4 core= s@2.66Ghz, and it still isn't finished). With mpstat it becomes clear that = the query is totally IO bound (what is expected of course). The machine I'm= running this on has a fast RAID that can do about 320 MB/s. Are these normal execution times for these amount of rows and this hardware= ? Is there anything I can do to speed up these kind of simple queries on hu= ge tables? Thanks in advance for all suggestions _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/= --_690d3132-f779-4ef2-bbad-de4168b804d8_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,

I hav= e a table with some 50 millions rows in PG 8.2. The table has indexes on re= levant columns. My problem is that most everything I do with this table (wh= ich are actually very basic selects) is unbearable slow. For example:
select max(payment_id) from transactions

This takes 161 seconds.
The plan looks like this:

"Result  (cost=3D0.37..0.38 row= s=3D1 width=3D0) (actual time=3D184231.636..184231.638 rows=3D1 loops=3D1)"=
"  InitPlan"
"    ->  Limit  (cost= =3D0.00..0.37 rows=3D1 width=3D8) (actual time=3D184231.620..184231.622 row= s=3D1 loops=3D1)"
"         = ; ->  Index Scan Backward using trans_payment_id_index on transacti= ons  (cost=3D0.00..19144690.58 rows=3D51122691 width=3D8) (actual time= =3D184231.613..184231.613 rows=3D1 loops=3D1)"
"    =             Filter: = (payment_id IS NOT NULL)"
"Total runtime: 184231.755 ms"

As shown= , in the plan, the index on the requested column "payment_id" is being used= , but the query still takes quite a lot of time. If I use a where clause in= a similar query, the query seemingly runs forever, e.g.

select min(= time) from transactions where payment_id =3D 67

There are indexes on= both the time (a timestamp with time zone) and payment_id (a bigint) colum= ns. About 1 million rows satisfy the condition payment_id =3D 67. This quer= y takes a totally unrealistic amount of time for execution (I have it runni= ng for >30 minutes now on a machine with 8GB and 4 cores@2.66Ghz, and it= still isn't finished). With mpstat it becomes clear that the query is tota= lly IO bound (what is expected of course). The machine I'm running this on = has a fast RAID that can do about 320 MB/s.

Are these normal executi= on times for these amount of rows and this hardware? Is there anything I ca= n do to speed up these kind of simple queries on huge tables?

Thanks= in advance for all suggestions


Express yourself insta= ntly with MSN Messenger! MSN Messenger = --_690d3132-f779-4ef2-bbad-de4168b804d8_--