Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uf23S-00074S-U5 for pgsql-performance@arkaria.postgresql.org; Wed, 22 May 2013 05:57:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uf23S-00052V-85 for pgsql-performance@arkaria.postgresql.org; Wed, 22 May 2013 05:57:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uf23R-00052L-5t; Wed, 22 May 2013 05:57:41 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uf23M-0006j4-Bv; Wed, 22 May 2013 05:57:40 +0000 Received: from 172.24.2.119 (EHLO szxeml211-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BCM73235; Wed, 22 May 2013 13:57:26 +0800 (CST) Received: from SZXEML452-HUB.china.huawei.com (10.82.67.195) by szxeml211-edg.china.huawei.com (172.24.2.182) with Microsoft SMTP Server (TLS) id 14.1.323.7; Wed, 22 May 2013 13:57:25 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml452-hub.china.huawei.com (10.82.67.195) with Microsoft SMTP Server id 14.1.323.7; Wed, 22 May 2013 13:57:21 +0800 From: Amit Kapila To: , CC: References: <20130521145345.5a830134ae84016b0174832fdc1a3173.0082853132.wbe@email11.secureserver.net> In-Reply-To: <20130521145345.5a830134ae84016b0174832fdc1a3173.0082853132.wbe@email11.secureserver.net> Subject: Re: Very slow inner join query Unacceptable latency. Date: Wed, 22 May 2013 11:27:19 +0530 Message-ID: <007501ce56b1$397ce690$ac76b3b0$@kapila@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac5WbdeqV33xQS+zSeShEyHX4BZmTgAQqlJQ Content-Language: en-us x-cr-hashedpuzzle: Aw8z D+xa EbBA EmpY Fbxo GBeV HlBr JNf9 QcII V+Je XTa7 ZGNv a5bW baKF er1C jQtq; 3; ZgBiAHUAcgBnAGUAcwBzAEAAcgBhAGQAaQBhAG4AdABiAGwAdQBlAC4AYwBvAG0AOwBwAGcAcwBxAGwALQBnAGUAbgBlAHIAYQBsAEAAcABvAHMAdABnAHIAZQBzAHEAbAAuAG8AcgBnADsAcABnAHMAcQBsAC0AcABlAHIAZgBvAHIAbQBhAG4AYwBlAEAAcABvAHMAdABnAHIAZQBzAHEAbAAuAG8AcgBnAA==; Sosha1_v1; 7; {A11995B6-3241-44B8-9D3C-BF9B9995B3A9}; YQBtAGkAdAAuAGsAYQBwAGkAbABhAEAAaAB1AGEAdwBlAGkALgBjAG8AbQA=; Wed, 22 May 2013 05:57:06 GMT; UgBFADoAIABbAFAARQBSAEYATwBSAE0AXQAgAFYAZQByAHkAIABzAGwAbwB3ACAAaQBuAG4AZQByACAAagBvAGkAbgAgAHEAdQBlAHIAeQAgAFUAbgBhAGMAYwBlAHAAdABhAGIAbABlACAAbABhAHQAZQBuAGMAeQAuAA== x-cr-puzzleid: {A11995B6-3241-44B8-9D3C-BF9B9995B3A9} X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected 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 Wednesday, May 22, 2013 3:24 AM fburgess wrote: > The SARS_ACTS table currently has 37,115,515 rows > we have indexed: idx_sars_acts_acts_run_id ON SARS_ACTS USING btree (sars= _run_id) > we have pk constraint on the SARS_ACTS_RUN table; sars_acts_run_pkey PRIM= ARY KEY (id ) > serverdb=3D# explain select count(*) as y0_ from SARS_ACTS this_ inner jo= in SARS_ACTS_RUN tr1_ on this_.SARS_RUN_ID=3Dtr1_.ID where tr1_.ALGORITHM= =3D'SMAT'; > QUERY PLAN > -------------------------------------------------------------------------= ------------------------------------------------- > Aggregate (cost=3D4213952.17..4213952.18 rows=3D1 width=3D0) > -> Hash Join (cost=3D230573.06..4213943.93 rows=3D3296 width=3D0) > Hash Cond: (this_.SARS_RUN_ID=3Dtr1_.ID) > -> Seq Scan om sars_acts this_ (cost=3D0.00..3844241.84 rows=3D37= 092284 width=3D8) > -> Hash (cost=3D230565.81..230565.81 rows=3D580 width=3D8) > -> Seq Scan on sars_acts_run tr1_ (cost=3D0.00..230565.81 r= ows=3D580 width=3D8) > Filter: ((algorithm)::text =3D 'SMAT'::text) > (7 rows) > This query executes in approximately 5.3 minutes to complete, very very s= low, our users are not happy. > I did add an index on SARS_ACTS_RUN.ALGORITHM column but it didn't improv= e the run time.=20 > The planner just changed the "Filter:" to an "Index Scan:" improving the = cost of the Seq Scan=20 > on the sars_acts_run table, but the overall run time remained the same. I= t seems like the bottleneck=20 > is in the Seq Scan on the sars_acts table. > -> Seq Scan on sars_acts_run tr1_ (cost=3D0.00..230565.81 r= ows=3D580 width=3D8) > Filter: ((algorithm)::text =3D 'SMAT'::text) > Does anyone have suggestions about how to speed it up? Could you please once trying Analyzing both tables and then run the query t= o check which plan it uses: Analyze SARS_ACTS; Analyze SARS_ACTS_RUN; With Regards, Amit Kapila. --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance