Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bRkHS-0005PM-Jl for pgsql-performance@arkaria.postgresql.org; Mon, 25 Jul 2016 18:07:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bRkHR-0005qu-Io for pgsql-performance@arkaria.postgresql.org; Mon, 25 Jul 2016 18:07:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bRkHR-0005qd-0X for pgsql-performance@postgresql.org; Mon, 25 Jul 2016 18:07:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bRkHO-0001Fz-1O for pgsql-performance@postgresql.org; Mon, 25 Jul 2016 18:07:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u6PI6vQM004249; Mon, 25 Jul 2016 14:06:57 -0400 From: Tom Lane To: Abadie Lana cc: "pgsql-performance@postgresql.org" Subject: Re: Very slow query (3-4mn) on a table with 25millions rows In-reply-to: References: Comments: In-reply-to Abadie Lana message dated "Mon, 25 Jul 2016 15:26:46 -0000" Date: Mon, 25 Jul 2016 14:06:57 -0400 Message-ID: <4248.1469470017@sss.pgh.pa.us> X-Pg-Spam-Score: -3.2 (---) 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 Abadie Lana writes: > I'm having a problem with a slow query - I tried several things to optimize the queries but didn't really help. The output of explain analyse shows sequential scan on a table of 25 million rows. Even though it is indexed and (I put a multi-column index on the fields used in the query), the explain utility shows no usage of the scan... That index looks pretty useless judging from the rowcounts, so I'm not surprised that the planner didn't use it. You might have better luck with an index on the split_part expression split_part(split_part((s.attvalue)::text, ' '::text, 1), '.'::text, 1) since it's the join of that to e.name that seems to be actually selective. (The planner doesn't appear to realize that it is, but ANALYZE'ing after creating the index should fix that.) regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance