pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Kaijiang Chen <chenkaijiang@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14302: SQL with LIMIT degrades performance seriously
Date: Wed, 31 Aug 2016 18:41:06 +0100
Message-ID: <87inug4zvx.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CAAkGvS8nLbnCJ2+PpfubVKSoUHaOYd0yBDZ1-2DOVA_Gq+1Uhg@mail.gmail.com>
References: <20160830064858.15676.40929@wrigleys.postgresql.org>
	<CAMkU=1wpGXHZNJPA7XP711yDYMaHfDxtQgP-1wGSLuhD8Gmv3g@mail.gmail.com>
	<CAAkGvS8HTQ6mSNiRF4U5w8o_=PvL34tdsBp3kY6GLRrQit0WFQ@mail.gmail.com>
	<87zint4joz.fsf@news-spur.riddles.org.uk>
	<CAAkGvS8nLbnCJ2+PpfubVKSoUHaOYd0yBDZ1-2DOVA_Gq+1Uhg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "Kaijiang" == Kaijiang Chen <chenkaijiang@gmail.com> writes:

 Kaijiang> It couldn't solve the problem.
 Kaijiang> I've already created 2 btree indexes, one for parent_id, the
 Kaijiang> other for user_id.  Do you mean to create an multi-column
 Kaijiang> index on (parent_id, user_id)?

Yes. The 2 separate indexes are not sufficient, but you can omit the
index on parent_id alone if you create the multi-column index.

 Kaijiang> still couldn't solve the problem, since we still need index
 Kaijiang> for user_id (for other sql) and planner will turn to user_id
 Kaijiang> index.

The planner should not do that (if it does, it's a bug).

The plan you're looking for is:

Limit
-> MergeAppend
   -> Index scan on parent_id_user_id_idx
        Index Cond: (parent_id = ?)
   -> Index scan on parent_id_user_id_idx
        Index Cond: (parent_id = ?)
   ...

Note the use of Index Cond rather than Filter, this is important.

-- 
Andrew (irc:RhodiumToad)


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (10+ messages)  latest in thread

Message-ID: <87inug4zvx.fsf@news-spur.riddles.org.uk>
Permalink:  ../87inug4zvx.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87inug4zvx.fsf@news-spur.riddles.org.uk

 · 

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-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, chenkaijiang@gmail.com, jeff.janes@gmail.com
  Subject: Re: BUG #14302: SQL with LIMIT degrades performance seriously
  In-Reply-To: <87inug4zvx.fsf@news-spur.riddles.org.uk>
  References: <20160830064858.15676.40929@wrigleys.postgresql.org> <CAMkU=1wpGXHZNJPA7XP711yDYMaHfDxtQgP-1wGSLuhD8Gmv3g@mail.gmail.com> <CAAkGvS8HTQ6mSNiRF4U5w8o_=PvL34tdsBp3kY6GLRrQit0WFQ@mail.gmail.com> <87zint4joz.fsf@news-spur.riddles.org.uk> <CAAkGvS8nLbnCJ2+PpfubVKSoUHaOYd0yBDZ1-2DOVA_Gq+1Uhg@mail.gmail.com> <87inug4zvx.fsf@news-spur.riddles.org.uk>

* 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