Re: INDEX Performance Issue - Mailing list pgsql-performance

From Mark Davidson
Subject Re: INDEX Performance Issue
Date
Msg-id CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com
Whole thread Raw
In response to Re: INDEX Performance Issue  (Kevin Grittner <kgrittn@ymail.com>)
Responses Re: INDEX Performance Issue  (Mark Davidson <mark@4each.co.uk>)
Re: INDEX Performance Issue  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-performance
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 <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 ); '
>> 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

pgsql-performance by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: INDEX Performance Issue
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: Find how much memory is postgres using