Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOxz1-0002HN-1C for pgsql-performance@arkaria.postgresql.org; Sun, 07 Apr 2013 22:22:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UOxz0-0007tX-DJ for pgsql-performance@arkaria.postgresql.org; Sun, 07 Apr 2013 22:22:42 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOxyz-0007tS-CA for pgsql-performance@postgresql.org; Sun, 07 Apr 2013 22:22:41 +0000 Received: from mail-vb0-x229.google.com ([2607:f8b0:400c:c02::229]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UOxys-0002AM-Nn for pgsql-performance@postgresql.org; Sun, 07 Apr 2013 22:22:40 +0000 Received: by mail-vb0-f41.google.com with SMTP id f13so3383194vbg.28 for ; Sun, 07 Apr 2013 15:22:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=yQ/jsjWAMoV2EM4QaM+D4ANS1Df2Mt/rOnrYZKlqc/w=; b=n2rEaCiBzWpeFexpq5pZXKWbE6QWyb6C9gDl0NTSRRxvEuc2wrzI8i6xhMB5xBgz5W 8iTUxLxMljs05GapMmENDQhO+LQesT/I0zQCOrT3EmSDkMWvxTTqNAh0S6FzW9Z1htb5 TxgaGi0xGIpq5f0jQbV7fRgFLC4Ha1yCHRTwefMo/Fgvvpd2zficXPPyHJOsKJ1cY5DN I6Cvsj7IfmGqvwHc/796WNcPD8J/etF+f3sSYAmLOgx6p8AjEsL5sIxXZXoff12sNEjn cw5Mc8uo7imKHy/mjWhPgJCCeMzLcAFdAUYlWm/ovYOFC6EVc+uNQ8N/vKkxpVZrzDLA sbAg== MIME-Version: 1.0 X-Received: by 10.220.248.200 with SMTP id mh8mr14025495vcb.51.1365373352722; Sun, 07 Apr 2013 15:22:32 -0700 (PDT) Received: by 10.58.200.106 with HTTP; Sun, 7 Apr 2013 15:22:32 -0700 (PDT) X-Originating-IP: [86.132.175.152] In-Reply-To: <1365347742.50505.YahooMailNeo@web162901.mail.bf1.yahoo.com> References: <1365179846.6562.YahooMailNeo@web162903.mail.bf1.yahoo.com> <1365330080.67650.YahooMailNeo@web125903.mail.ne1.yahoo.com> <1365347742.50505.YahooMailNeo@web162901.mail.bf1.yahoo.com> Date: Sun, 7 Apr 2013 23:22:32 +0100 Message-ID: Subject: Re: INDEX Performance Issue From: Mark Davidson To: Kevin Grittner Cc: Greg Williamson , "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary=089e013c6864acd47704d9ccc19d X-Gm-Message-State: ALoCoQnxD0SwMLrrQzEAFjLiV1Y8i9KCdm23rIjFYo5TjNIMOul3Yc5jBJv/N0BDNF0Cony08N+5 X-Pg-Spam-Score: -1.9 (-) 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 --089e013c6864acd47704d9ccc19d Content-Type: text/plain; charset=ISO-8859-1 Takes a little longer with the INNER join unfortunately. Takes about ~3.5 minutes, here is the query plan http://explain.depesz.com/s/EgBl. With the JOIN there might not be a match if the data does not fall within one of the areas that is selected in the IN query. So if we have data id (10) that might fall in areas ( 1, 5, 8, 167 ) but the user might be querying areas ( 200 ... 500 ) so no match in area would be found just to be absolutely clear. Is it worth considering adding additional statistics on any of the columns? And / Or additional INDEXES or different types INDEX? Would it be worth restructuring the query starting with areas and working to join data to that? On 7 April 2013 16:15, Kevin Grittner wrote: > Greg Williamson wrote: > > >> Thanks for your response. I tried doing what you suggested so > >> that table now has a primary key of > >> ' CONSTRAINT data_area_pkey PRIMARY KEY(area_id , data_id ); ' > >> and I've added the INDEX of > >> 'CREATE INDEX data_area_data_id_index ON data_area USING btree (data_id > );' > > Yeah, that is what I was suggesting. > > >> unfortunately it hasn't resulted in an improvement of the query > >> performance. > > > Did you run analyze on the table after creating the index ? > > That probably isn't necessary. Statistics are normally on relations > and columns; there are only certain special cases where an ANALYZE > is needed after an index build, like if the index is on an > expression rather than a list of columns. > > Mark, what happens if you change that left join to a normal (inner) > join? Since you're doing an inner join to data_area and that has a > foreign key to area, there should always be a match anyway, right? > The optimizer doesn't recognize that, so it can't start from the > area and just match to the appropriate points. > > -- > Kevin Grittner > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > --089e013c6864acd47704d9ccc19d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Takes a little longer with the INNER join unfortunate= ly. Takes about ~3.5 minutes, here is the query plan http://explain.depesz.com/s/EgBl.

With t= he JOIN there might not be a match if the data does not fall within one of = the areas that is selected in the IN query.

So if we have data id (10) that might fall in areas ( 1, 5, = 8, 167 ) but the user might be querying areas ( 200 ... 500 ) so no match i= n area would be found just to be absolutely clear.

Is it worth considering adding additional statistics on any of the columns?= And / Or additional INDEXES or different types INDEX? Would it be worth re= structuring the query starting with areas and working to join data to that?=


On 7 Ap= ril 2013 16:15, Kevin Grittner <kgrittn@ymail.com> wrote:
Greg Williamson <gwilliamson39@yahoo.com> wrote:

>> Thanks for your response. I tried doing what you suggested so
>> that table now has a primary key of
>> ' CONSTRAINT data_area_pkey PRIMARY KEY(area_id , data_id ); &= #39;
>> and I've added the INDEX of
>> 'CREATE INDEX data_area_data_id_index ON data_area USING btree= (data_id );'

Yeah, that is what I was suggesting.

>> unfortunately it hasn't resulted in an improvement of the quer= y
>> performance.

> Did you run analyze on the table after creatin= g the index ?

That probably isn't necessary.=A0 Statistics are normally on rela= tions
and columns; there are only certain special cases where an ANALYZE
is needed after an index build, like if the index is on an
expression rather than a list of columns.

Mark, what happens if you change that left join to a normal (inner)
join?=A0 Since you're doing an inner join to data_area and that has a foreign key to area, there should always be a match anyway, right?
The optimizer doesn't recognize that, so it can't start from the area and just match to the appropriate points.

--
Kevin Grittner
EnterpriseDB: htt= p://www.enterprisedb.com
The Enterprise PostgreSQL Company

--089e013c6864acd47704d9ccc19d--