Re: Nested query performance issue

From: Glenn Maynard <glennfmaynard(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Nested query performance issue
Date: 2009-04-14 10:04:22
Message-ID: d18085b50904140304h3bde652fkdcf0c452e1f68e15@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Apr 14, 2009 at 5:33 AM, Matthew Wakeling <matthew(at)flymine(dot)org> wrote:
>> It's about 10% faster for me.  I'm surprised the planner can't figure
>> out that this join is redundant.
>
> Because the join isn't redundant? You're making the assumption that for
> every score.game_id there is exactly one game.id that matches. Of course,
> you may have a unique constraint and foreign key/trigger that ensures this.

That's the definition of the tables I gave.

CREATE TABLE game (id SERIAL NOT NULL PRIMARY KEY); -- pk implies unique
CREATE TABLE score (id SERIAL NOT NULL PRIMARY KEY, score REAL,
game_id INTEGER REFERENCES game (id));

(I don't think it makes any difference to whether this can be
optimized, but adding NOT NULL back to game_id doesn't change it,
either.)

--
Glenn Maynard

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Nikolas Everett 2009-04-14 12:56:01 Re: difficulties with time based queries
Previous Message Matthew Wakeling 2009-04-14 09:39:22 Re: Shouldn't the planner have a higher cost for reverse index scans?