pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Evgeniy Shishkin <itparanoia@gmail.com>
To: pgsql-performance@postgresql.org list <pgsql-performance@postgresql.org>
Subject: two table join with order by on both tables attributes
Date: Fri, 8 Aug 2014 02:21:51 +0300
Message-ID: <8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Hello,

suppose you have two very simple tables with fk dependency, by which we join them
and another attribute for sorting

like this
select * from users join  notifications on users.id=notifications.user_id ORDER BY users.priority desc ,notifications.priority desc limit 10;

Very typical web query.

No matter which composite indexes i try, postgresql can not make efficient nested loop plan using indexes.
It chooses all sorts of seq scans and hash joins or merge join and always a sort node and then a limit 10.

Neither plan provides acceptable performance. And tables tend to grow =\

Can anybody suggest something or explain this behavior?

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



view thread (8+ messages)  latest in thread

Message-ID: <8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com>
Permalink:  ../8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com/
Also on:    postgresql.org/message-id/8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com

 · 

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: itparanoia@gmail.com
  Subject: Re: two table join with order by on both tables attributes
  In-Reply-To: <8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com>

* 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