Re: Optimizing `WHERE x IN` query

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

 



Omar Roth schrieb am 07.07.2019 um 15:43:
Currently, the query I'm using to generate a user's feed is:

```
SELECT * FROM channel_videos WHERE ucid IN (SELECT unnest(subscriptions) FROM
users WHERE email = $1) ORDER BY published DESC;
```

You could try an EXISTS query without unnest:

select cv.*
from channel_videos cv
where exists ucid (select *
                   from users u
                   where cv.ucid = any(u.subscriptions)
                     and u.email = $1);

Did you try if a properly normalized model performs better?







[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux