pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@megafon.hr>
To: Scott Marlowe <scott.marlowe@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Forcing seq_scan off for large table joined with tiny table yeilds improved performance
Date: Mon, 06 Apr 2009 16:37:53 +0200
Message-ID: <49DA13C1.2030200@megafon.hr> (raw)
In-Reply-To: <dcc563d10904060658v621cbd3drbb75b6428d770b04@mail.gmail.com>
References: <49D0D237.7020308@megafon.hr>
	<3028.1238422571@sss.pgh.pa.us>
	<49D0E687.50605@megafon.hr>
	<dcc563d10903300925m88a73c7kf90084b5e088a445@mail.gmail.com>
	<49D9F39F.40106@megafon.hr>
	<dcc563d10904060658v621cbd3drbb75b6428d770b04@mail.gmail.com>

Scott Marlowe wrote:
> On Mon, Apr 6, 2009 at 6:20 AM, Mario Splivalo
> <mario.splivalo@megafon.hr> wrote:
>> Scott Marlowe wrote:
>>> It's not really solved, it's just a happy coincidence that the current
>>> plan runs well.  In order to keep the query planner making good
>>> choices you need to increase stats target for the field in the index
>>> above.  The easiest way to do so is to do this:
>>>
>>> alter database mydb set default_statistics_target=100;
>>>
>>> and run analyze again:
>>>
>>> analyze;
>> So, i removed the index on field_name, set default_default_statistics_target
>> to 100, analyzed, and the results are the same:
> 
> Why did you remove the index?
> 

Because I already have index on that column, index needed to enforce PK 
constraint. Here is the original DDL for the table:

CREATE TABLE photo_info_data
(
   photo_id integer NOT NULL,
   field_name character varying NOT NULL,
   field_value character varying,
   CONSTRAINT photo_info_data_pk PRIMARY KEY (user_id, field_name)
)

CREATE INDEX photo_info_data_ix_field_value
   ON user_info_data USING btree (field_value);

So, there is index on (user_id, field_name). Postgres is using index for 
user_id (...WHERE user_id = 12345) but not on field-name (...WHERE 
field_name = 'f-spot'). When I add extra index on field name:

CREATE INDEX photo_info_data_ix__field_name
   ON user_info_data USING btree (field_name);

Then that index is used.

	Mike



view thread (10+ messages)  latest in thread

Message-ID: <49DA13C1.2030200@megafon.hr>
Permalink:  ../49DA13C1.2030200@megafon.hr/
Also on:    postgresql.org/message-id/49DA13C1.2030200@megafon.hr

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mario.splivalo@megafon.hr, scott.marlowe@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Forcing seq_scan off for large table joined with tiny table yeilds improved performance
  In-Reply-To: <49DA13C1.2030200@megafon.hr>

* 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