Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNI7v-0003GH-L7 for pgsql-admin@postgresql.org; Sun, 14 Oct 2012 06:56:43 +0000 Received: from col0-omc1-s7.col0.hotmail.com ([65.55.34.17]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNI7o-00008V-Va for pgsql-admin@postgresql.org; Sun, 14 Oct 2012 06:56:43 +0000 Received: from COL104-W26 ([65.55.34.9]) by col0-omc1-s7.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Sat, 13 Oct 2012 23:56:33 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_4811cda2-712c-4bb0-a654-5277f8fa6a24_" X-Originating-IP: [80.61.220.165] From: henk de wit To: "pgsql-admin@postgresql.org" Subject: Query with limit takes hours Date: Sun, 14 Oct 2012 08:56:33 +0200 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 14 Oct 2012 06:56:33.0998 (UTC) FILETIME=[0C1F2EE0:01CDA9D9] X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201210/41 X-Sequence-Number: 40157 --_4811cda2-712c-4bb0-a654-5277f8fa6a24_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On PG 9.1 and 9.2 I'm running the following query: SELECT *FROM stream_store JOIN ( SELECT UNNES= T(stream_store_ids) AS id FROM stream_store_version_inde= x WHERE stream_id =3D 607106 AND version =3D= 11 ) AS records USING (id)ORDER BY id DESC This takes several (10 to 20) milliseconds at most. When I add a LIMIT 1 to the end of the query=2C the query time goes to seve= ral hours(!). The full version String of PG 9.1 is "PostgreSQL 9.1.5 on x86_64-unknown-li= nux-gnu=2C compiled by gcc-4.4.real (Debian 4.4.5-8) 4.4.5=2C 64-bit". The = 9.1 machine is a socket 771 dual quad core at 3.16Ghz with 64GB memory and = 10 Intel x25M SSDs in a RAID5 setup on 2 ARECA 1680 RAID controllers. The "= stream_store" table has 122 million rows and is partitioned. The array that= 's being unnested for the join has 27 entries. Any idea? = --_4811cda2-712c-4bb0-a654-5277f8fa6a24_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
On PG 9.1 and 9.2 I'm running the following query:

SELECT =3B
 =3B  =3B *
FROM =3B
 =3B  =3B stream_store =3B
JOIN
&n= bsp=3B  =3B (
 =3B  =3B  =3B  =3B SELECT = =3B
 =3B  =3B  =3B  =3B  =3B  =3B UNNEST(= stream_store_ids) AS id
 =3B  =3B  =3B  =3B FROM&= nbsp=3B
 =3B  =3B  =3B  =3B  =3B  =3B str= eam_store_version_index =3B
 =3B  =3B  =3B  = =3B WHERE =3B
 =3B  =3B  =3B  =3B  =3B &n= bsp=3B stream_id =3D 607106 AND
 =3B  =3B  =3B  = =3B  =3B  =3B version =3D 11
 =3B  =3B ) AS recor= ds USING (id)
ORDER BY =3B
 =3B  =3B id DES= C

This takes several (10 to 20) milliseconds at mo= st.

When I add a LIMIT 1 to the end of the query= =2C the query time goes to several hours(!).

The f= ull version String of PG 9.1 is "PostgreSQL 9.1.5 on x86_64-unknown-linux-g= nu=2C compiled by gcc-4.4.real (Debian 4.4.5-8) 4.4.5=2C 64-bit". The 9.1 m= achine is a socket 771 dual quad core at 3.16Ghz with 64GB memory and 10 In= tel x25M SSDs in a RAID5 setup on 2 ARECA 1680 RAID controllers. The "strea= m_store" table has 122 million rows and is partitioned. The array that's be= ing unnested for the join has 27 entries.

Any idea= ?
= --_4811cda2-712c-4bb0-a654-5277f8fa6a24_--