From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-performance@lists.postgresql.org
Subject: Re: Optimizing `WHERE x IN` query
Date: Sun, 7 Jul 2019 16:33:00 +0200
Message-ID: <86b8a755-2fa4-f7c2-8b0b-3290773feb97@gmx.net> (raw)
In-Reply-To: <DM5PR18MB1051CD296F9F94AE0D67FD84DFF70@DM5PR18MB1051.namprd18.prod.outlook.com>
References: <DM5PR18MB1051CD296F9F94AE0D67FD84DFF70@DM5PR18MB1051.namprd18.prod.outlook.com>
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?
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: spam_eater@gmx.net, pgsql-performance@lists.postgresql.org
Subject: Re: Optimizing `WHERE x IN` query
In-Reply-To: <86b8a755-2fa4-f7c2-8b0b-3290773feb97@gmx.net>
* 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