Re: Size of IN list affects query plan

From: bricklen <bricklen(at)gmail(dot)com>
To: Jan Walter <john(at)commontongue(dot)com>
Cc: postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Size of IN list affects query plan
Date: 2013-11-08 14:31:49
Message-ID: CAGrpgQ9jQe+=LYdWps_VOSxaR-yrGegsB4QeDW1uf-Ev==YLzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Nov 8, 2013 at 6:04 AM, Jan Walter <john(at)commontongue(dot)com> wrote:

> Hi,
>
> I would like to know, how does the size of the IN list affect query
> planner.
> I have a query
>
> select distinct on (event_id, tag_id) et.id,
> e.id as event_id, t.id as tag_id, t.name,
> t.user_id, t.shared, t.color,
> case
> when ea.id <> e.id then true
> else false
> end as inherited
> from do_event e
> join do_event ea on (ea.tree_id = e.tree_id and ea.lft <= e.lft and
> ea.rght >= e.rght)
> join do_event_tags et on (et.event_id = ea.id)
> join do_tag t on (t.id = et.tag_id)
> where e.id in (LIST_OF_INTEGERS) and
> (t.user_id = 14 or t.shared)
> order by event_id, tag_id, inherited;
>

Looking at your EXPLAIN ANALYZE plan I was immediately reminded of this
article
http://www.datadoghq.com/2013/08/100x-faster-postgres-performance-by-changing-1-line/,
where changing the array to a VALUES() clause was a huge win for them.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2013-11-08 19:46:40 Re: Performance bug in prepared statement binding in 9.2?
Previous Message Tom Lane 2013-11-08 14:31:42 Re: Size of IN list affects query plan