two table join with order by on both tables attributes

From: Evgeniy Shishkin <itparanoia(at)gmail(dot)com>
To: "pgsql-performance(at)postgresql(dot)org list" <pgsql-performance(at)postgresql(dot)org>
Subject: two table join with order by on both tables attributes
Date: 2014-08-07 23:21:51
Message-ID: 8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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?

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message David G Johnston 2014-08-07 23:42:45 Re: two table join with order by on both tables attributes
Previous Message Kevin Grittner 2014-08-06 14:04:32 Re: Query performing very bad and sometimes good