Search Postgresql Archives

Re: Why doesn't Postgres apply limit on groups when retrieving N results per group using WHERE IN + ORDER BY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 5, 2024 at 7:23 AM Sean v <sean@xxxxxxxxxxxxxx> wrote:
This is related to a question I asked on dbs.stackexchange.comhttps://dba.stackexchange.com/questions/335501/why-doesnt-postgres-apply-limit-on-groups-when-retrieving-n-results-per-group

But to reiterate - I have a query like this:

SELECT "orders".* 

FROM "orders" 

WHERE (user_id IN ?, ?, ?) 

ORDER BY "orders"."created_at" LIMIT 50

[snip] 
So my question is twofold: 
- why doesn't Postgres use the composite index, and then retrieve only the minimum necessary amount of rows (50 per user) using the query I posted above?


But your query does not list the first 50 rows per user.  It only returns the first 50 rows of:

SELECT "orders".* 

FROM "orders" 

WHERE (user_id IN ?, ?, ?) 

ORDER BY "orders"."created_at"


Who knows which users are going to be in that list???


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux