pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Davidson <mark@4each.co.uk>
To: Kevin Grittner <kgrittn@ymail.com>
Cc: Greg Williamson <gwilliamson39@yahoo.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: INDEX Performance Issue
Date: Sun, 7 Apr 2013 23:22:32 +0100
Message-ID: <CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com> (raw)
In-Reply-To: <1365347742.50505.YahooMailNeo@web162901.mail.bf1.yahoo.com>
References: <CAPpwVW1rja3ZSsAt1myg-Ptue6d_HRuSXBwMOmuBe_t4HyPgRg@mail.gmail.com>
	<1365179846.6562.YahooMailNeo@web162903.mail.bf1.yahoo.com>
	<CAPpwVW2ecnmDeqL6CTNCzDe0GwQfkCoZEKQy1rOuoR6FUSTshA@mail.gmail.com>
	<1365330080.67650.YahooMailNeo@web125903.mail.ne1.yahoo.com>
	<1365347742.50505.YahooMailNeo@web162901.mail.bf1.yahoo.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
>

view thread (18+ messages)  latest in thread

Message-ID: <CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com>
Permalink:  ../CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com/
Also on:    postgresql.org/message-id/CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mark@4each.co.uk, kgrittn@ymail.com, gwilliamson39@yahoo.com
  Subject: Re: INDEX Performance Issue
  In-Reply-To: <CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com>
  References: <CAPpwVW1rja3ZSsAt1myg-Ptue6d_HRuSXBwMOmuBe_t4HyPgRg@mail.gmail.com> <1365179846.6562.YahooMailNeo@web162903.mail.bf1.yahoo.com> <CAPpwVW2ecnmDeqL6CTNCzDe0GwQfkCoZEKQy1rOuoR6FUSTshA@mail.gmail.com> <1365330080.67650.YahooMailNeo@web125903.mail.ne1.yahoo.com> <1365347742.50505.YahooMailNeo@web162901.mail.bf1.yahoo.com> <CAPpwVW2T63n84zgGiF2P2aNOnrqt2kYLDYFKrr5hWG--Cyjphg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox