Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtZtL-0007Y3-Jl for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 08:23:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtZtK-0008VO-Ct for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 08:23:06 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtZtJ-0008Uy-BY for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 08:23:05 +0000 Received: from mx3.wp.pl ([212.77.101.7]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtZtH-0000f0-2t for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 08:23:05 +0000 Received: (wp-smtpd smtp.wp.pl 26929 invoked from network); 11 Jan 2013 09:23:02 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1357892582; bh=j9eaLdVxP2DXPR3f3EaaDzCWyeVrtmeoujlFsBcjUBI=; h=From:To:CC:Subject; b=a8RoGpeFp9BimKzEGd39DwMcuauM+SqxFGGrjIuXNJ43rsK+dbRN+Z67Q1zXgz3e+ izaRmPh5JxEpm/uFGXTakMadP0kK9jlS2vinO9pZht7yTMZKO3STD878xDlAP0+slP tS6pQiip33n1JWgBNfl4vkCaf6yx2LPDbfQ/BLEU= Received: from 89-73-238-104.dynamic.chello.pl (HELO [192.168.0.13]) (zawadaa@[89.73.238.104]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with CAMELLIA256-SHA encrypted SMTP for ; 11 Jan 2013 09:23:02 +0100 Message-ID: <50EFCBE5.1080506@wp.pl> Date: Fri, 11 Jan 2013 09:23:01 +0100 From: Andrzej Zawadzki User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Icedove/17.0.2 MIME-Version: 1.0 To: Matheus de Oliveira CC: pgsql-performance@postgresql.org Subject: Re: Slow query after upgrade from 9.0 to 9.2 References: <50EEC2D5.3050602@wp.pl> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [sRLd] X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 10.01.2013 19:48, Matheus de Oliveira wrote: > > > On Thu, Jan 10, 2013 at 11:32 AM, Andrzej Zawadzki > wrote: > > Hi! > > Small query run on 9.0 very fast: > > SELECT * from sygma_arrear sar where sar.arrear_import_id = ( > select sa.arrear_import_id from sygma_arrear sa, > arrear_import ai > where sa.arrear_flag_id = 2 > AND sa.arrear_import_id = ai.id > AND ai.import_type_id = 1 > order by report_date desc limit 1) > AND sar.arrear_flag_id = 2 > AND sar.credit_id = 3102309 > > "Index Scan using sygma_arrear_credit_id on sygma_arrear sar > (cost=0.66..362.03 rows=1 width=265)" > " Index Cond: (credit_id = 3102309 )" > " Filter: ((arrear_import_id = $0) AND (arrear_flag_id = 2))" > " InitPlan 1 (returns $0)" > " -> Limit (cost=0.00..0.66 rows=1 width=8)" > " -> Nested Loop (cost=0.00..3270923.14 rows=4930923 > width=8)" > " -> Index Scan Backward using report_date_bank_id_key > on arrear_import ai (cost=0.00..936.87 rows=444 width=8)" > " Filter: (import_type_id = 1)" > *" -> Index Scan using > sygma_arrear_arrear_import_id_idx > on sygma_arrear sa (cost=0.00..6971.15 rows=31495 width=4)"** > **" Index Cond: (sa.arrear_import_id = ai.id > )"** > **" Filter: (sa.arrear_flag_id = 2)"** > * > Engine uses index - great. > > On 9.2 > > "Index Scan using sygma_arrear_credit_id on sygma_arrear sar > (cost=11.05..381.12 rows=1 width=265)" > " Index Cond: (credit_id = 3102309 )" > " Filter: ((arrear_import_id = $0) AND (arrear_flag_id = 2))" > " InitPlan 1 (returns $0)" > " -> Limit (cost=0.00..11.05 rows=1 width=8)" > " -> Nested Loop (cost=0.00..54731485.84 rows=4953899 > width=8)" > " Join Filter: (sa.arrear_import_id = ai.id > )" > " -> Index Scan Backward using report_date_bank_id_key > on arrear_import ai (cost=0.00..62.81 rows=469 width=8)" > " Filter: (import_type_id = 1)" > *" -> Materialize (cost=0.00..447641.42 rows=6126357 > width=4)"** > **" -> Seq Scan on sygma_arrear sa > (cost=0.00..393077.64 rows=6126357 width=4)"** > **" Filter: (arrear_flag_id = 2)"** > * > Seq scan... slooow. > > Why that's happens? All configurations are identical. Only engine is > different. > > > > How did you do the upgrade? pg_upgrade and I think that this is source of problem. I have test database from dump/restore process and works properly. > Have you tried to run a VACUUM ANALYZE on sygma_arrear? Yes I did - after upgrade all databases was vacuumed. vacuumdb -azv I'll try reindex all indexes at weekend -- Andrzej Zawadzki -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance