Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 153C81337B6E for ; Thu, 13 Jan 2011 08:27:38 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 95609-07 for ; Thu, 13 Jan 2011 12:27:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by mail.postgresql.org (Postfix) with ESMTP id 6925D1337B5E for ; Thu, 13 Jan 2011 08:27:27 -0400 (AST) Received: from smadev.internal.net (localhost.internal.net [127.0.0.1]) by smadev.internal.net (8.14.2/8.14.2) with ESMTP id p0DCRQdO090935 for ; Thu, 13 Jan 2011 14:27:26 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.14.2/8.14.2/Submit) id p0DCRQXN090934 for pgsql-admin@postgresql.org; Thu, 13 Jan 2011 14:27:26 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-admin@postgresql.org Subject: Re: Postgresql 9.0.2 explain analyze very slow (10x), compared to actual query time Date: Thu, 13 Jan 2011 14:27:26 +0200 User-Agent: KMail/1.9.7 References: <201101111753.22602.achill@matrix.gatewaynet.com> <27365.1294850720@sss.pgh.pa.us> <201101131413.21757.achill@matrix.gatewaynet.com> In-Reply-To: <201101131413.21757.achill@matrix.gatewaynet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <201101131427.26399.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.451 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_BRBL_LASTEXT=1.449 X-Spam-Level: X-Archive-Number: 201101/68 X-Sequence-Number: 36508 =D3=F4=E9=F2 Thursday 13 January 2011 14:13:21 =EF/=E7 Achilleas Mantzios = =DD=E3=F1=E1=F8=E5: > SELECT distinct m.id,coalesce(m.givenname,''),coalesce(m.midname,''),m.su= rname from marinerstates ms,vessels vsl,mariner m=20 > where m.id=3Dms.marinerid and ms.vslid=3Dvsl.id and ms.state=3D'Active' a= nd coalesce(ms.endtime,now())::date >=3D '2006-07-15' and=20 > ms.starttime::date <=3D '2007-01-11' and m.marinertype=3D'Mariner' and = m.id not in=20 > (SELECT distinct mold.id from marinerstates msold,vessels vslold,marin= er mold where mold.id=3Dmsold.marinerid and msold.vslid=3Dvslold.id=20 > and msold.state=3D'Active' and coalesce(msold.endtime,now())::date = >=3D '2006-07-15' and msold.starttime::date <=3D '2007-01-11' and exists=20 > (select 1 from marinerstates msold2 where msold2.marinerid=3Dmso= ld.marinerid and msold2.state=3D'Active' and msold2.id <> msold.id and=20 > msold2.starttime order by m.surname,coalesce(m.givenname,''),coalesce(m.midname,'') Rewriting the query with NOT EXISTS (a practice quite common pre 8.3, IIRC)= as: SELECT distinct m.id,coalesce(m.givenname,''),coalesce(m.midname,''),m.surn= ame from marinerstates ms,vessels vsl,mariner m=20 where m.id=3Dms.marinerid and ms.vslid=3Dvsl.id and ms.state=3D'Active' and= coalesce(ms.endtime,now())::date >=3D '2006-07-15' and=20 ms.starttime::date <=3D '2007-01-11' and m.marinertype=3D'Mariner' and N= OT EXISTS=20 (SELECT distinct mold.id from marinerstates msold,vessels= vslold,mariner mold where mold.id=3Dmsold.marinerid and=20 msold.vslid=3Dvslold.id and msold.state=3D'Active' and co= alesce(msold.endtime,now())::date >=3D '2006-07-15' and=20 msold.starttime::date <=3D '2007-01-11' and exists=20 (select 1 from marinerstates msold2 where msold2.mari= nerid=3Dmsold.marinerid and=20 msold2.state=3D'Active' and msold2.id <> msold.id and= msold2.starttime