Re: Performance Killer 'IN' ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Performance Killer 'IN' ?
Date
Msg-id 7641.1144073748@sss.pgh.pa.us
Whole thread Raw
In response to Re: Performance Killer 'IN' ?  (Kai Hessing <kai.hessing@hobsons.de>)
Responses Re: Performance Killer 'IN' ?  (Kai Hessing <kai.hessing@hobsons.de>)
List pgsql-general
Kai Hessing <kai.hessing@hobsons.de> writes:
> Yes... The 0 rows are there because I did the command before. Now I
> resetted the test database to a previous state and dopped the 'AND
> status>-1' in the SQL-syntax:

> Using the 'UPDATE xyz WHERE id IN ('xyz1', 'xyz2', other 2000
> values.....)' returns:
> ----------------------------
> Seq Scan on phon  (cost=0.00..1564960.67 rows=317227 width=148) (actual
> time=68.315..365621.761 rows=2522 loops=1)

>   Filter: (((phon)::text = '.....

Well, here's our problem it would seem: the planner is estimating the IN
clause to match 317227 rows, rather than the actual 2522.  That's
naturally going to bias it against choosing an indexscan.  You need to
get that estimate closer before there's going to be much chance of
choosing the right plan.

> What do you mean with larger statistics target?

See ALTER TABLE SET STATISTICS, or just change default_statistics_target
and re-ANALYZE.

            regards, tom lane

pgsql-general by date:

Previous
From: "Marko Kreen"
Date:
Subject: Re: Performance Killer 'IN' ?
Next
From: Ottavio Campana
Date:
Subject: database design questions