Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id ED1CE311512 for ; Wed, 14 Dec 2011 13:48:38 -0400 (AST) Received: from smtp-sofia.digsys.bg ([193.68.3.230]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RaswW-0003KX-1o for pgsql-performance@postgresql.org; Wed, 14 Dec 2011 17:48:38 +0000 Received: from luke.digsys.bg (luke.digsys.bg [193.68.6.22]) by smtp-sofia.digsys.bg (8.14.4/8.14.4) with ESMTP id pBEHm7dA095821 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Dec 2011 19:48:13 +0200 (EET) (envelope-from kaloyan@digsys.bg) Message-ID: <4EE8E161.1090702@digsys.bg> Date: Wed, 14 Dec 2011 19:48:17 +0200 From: Kaloyan Iliev Iliev Reply-To: kaloyan@digsys.bg Organization: Register.BG Ltd. User-Agent: Thunderbird 2.0.0.24 (X11/20100614) MIME-Version: 1.0 To: Mark Kirkwood , pgsql-performance@postgresql.org Subject: Re: Slow query after upgrade from 8.2 to 8.4 References: <4EE0F3F4.8040909@digsys.bg> <14557.1323401295@sss.pgh.pa.us> <4EE1FDC7.70601@digsys.bg> <27472.1323444617@sss.pgh.pa.us> <4EE7CDEF.1040709@catalyst.net.nz> In-Reply-To: <4EE7CDEF.1040709@catalyst.net.nz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.4 (----) X-Archive-Number: 201112/119 X-Sequence-Number: 45918 Hi, Thanks for Replay. Actually I finally find a solution. If I rewrite the query in this way: explain analyze select 1 from acc_clients AC, acc_debts AD, debts_desc DD, config CF where AC.ino = 204627 AND CF.id = (select id from config where confid=CF.confid AND office = 18 ORDER BY archived_at DESC LIMIT 1) AND AD.transact_no = AC.transact_no AND AD.debtid = DD.debtid AND DD.refid = CF.confid LIMIT 1; the plan and execution time really approves. http://explain.depesz.com/s/Nkj And for comparison I will repost the old way the query was written. explain analyze select 1 from acc_clients AC, acc_debts AD, debts_desc DD, config CF where AC.ino = 1200000 AND CF.id = (select id from config where confid=CF.confid ORDER BY archived_at DESC LIMIT 1) AND AD.transact_no = AC.transact_no AND AD.debtid = DD.debtid AND CF.office = 18 AND DD.refid = CF.confid LIMIT 1; This is the query plan of the upper query. http://explain.depesz.com/s/ATN When we have 8.4.9 installed I will try the query and post the result. Best regards, Kaloyan Iliev Mark Kirkwood wrote: > On 10/12/11 04:30, Tom Lane wrote: >> However, it's not apparent to me why you would see any difference >> between 8.2 and 8.4 on this type of query. I tried a query analogous >> to this one on both, and got identical plans. I'm guessing that your >> slowdown is due to not having updated statistics on the new >> installation, or perhaps failing to duplicate some relevant settings. > > I notice he has 8.4.*8*... I wonder if he's running into the poor > estimation bug for sub-selects/semi joins that was fixed in 8.4.9. > > Kaloyan, can you try the query in 8.4.9? > > regards > > Mark >