Re: [PERFORM] two table join with order by on both tables attributes

2014-08-08 Thread Evgeniy Shishkin
> On 08 Aug 2014, at 16:29, Marti Raudsepp wrote: > > On Fri, Aug 8, 2014 at 4:05 AM, Evgeniy Shishkin wrote: >> select * from users join notifications on >> users.id=notifications.user_id ORDER BY users.priority desc >> ,notifications.priority desc limit 10; > > In my under

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-08 Thread Marti Raudsepp
On Fri, Aug 8, 2014 at 4:05 AM, Evgeniy Shishkin wrote: > select * from users join notifications on users.id=notifications.user_id > ORDER BY users.priority desc ,notifications.priority desc limit 10; In my understanding, i need to have two indexes on users(priority desc, id)

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-07 Thread Evgeniy Shishkin
> On 08 Aug 2014, at 03:43, Evgeniy Shishkin wrote: > select * from users join notifications on users.id=notifications.user_id ORDER BY users.priority desc ,notifications.priority desc limit 10; >> >>> In my understanding, i need to have two indexes >>> on users(priority desc, id) >

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-07 Thread Evgeniy Shishkin
>>> select * from users join notifications on users.id=notifications.user_id >>> ORDER BY users.priority desc ,notifications.priority desc limit 10; > >> In my understanding, i need to have two indexes >> on users(priority desc, id) >> and notifications(user_id, priority desc) >> then postgresql

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-07 Thread Tom Lane
Evgeniy Shishkin writes: >> select * from users join notifications on users.id=notifications.user_id >> ORDER BY users.priority desc ,notifications.priority desc limit 10; > In my understanding, i need to have two indexes > on users(priority desc, id) > and notifications(user_id, priority desc)

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-07 Thread Evgeniy Shishkin
My question was about that you can not have fast execution of this kind of query in postgresql. With any runtime configuration you just swith from seq scan and hash join to merge join, and then you have a sort node. In my understanding, i need to have two indexes on users(priority desc, id) and

Re: [PERFORM] two table join with order by on both tables attributes

2014-08-07 Thread David G Johnston
Evgeniy Shishkin wrote > 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.prior