From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Jonathan Vanasco <postgres(at)2xlp(dot)com>, Melvin Davidson <melvin6925(at)gmail(dot)com> |
Cc: | PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: newsfeed type query |
Date: | 2015-04-29 01:26:29 |
Message-ID: | 55403345.9060604@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 4/28/15 6:57 PM, Jonathan Vanasco wrote:
> The relevant structure is:
>
> posting:
> id
> timestamp_publish
> group_id__in
> user_id__author
> friends:
> user_id__a
> user_id__b
>
> memberships:
> user_id
> group_id
> role_id
Try this...
SELECT ...
, f.user_id__b IS NOT NULL AS in_friends
, m.user_id IS NOT NULL AS in_group
FROM posting p
LEFT JOIN friends f ON( f.user_id__b = p.user_id__author )
LEFT JOIN memberships m ON( m.group_id = p.group_id__in )
WHERE is_published AND timestamp_publish ...
AND (
f.user_id__a = 57
OR ( m.user_id = 57 AND m.group_id IN (1,2,3) )
)
I'm not sure how fast it'll be though. I suspect your best bet is to put
the UNION approach inside a set returning function; that way the ugly is
contained in one place.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
From | Date | Subject | |
---|---|---|---|
Next Message | Aaron Burnett | 2015-04-29 04:19:51 | Upgrading hot standbys |
Previous Message | Jim Nasby | 2015-04-29 01:14:32 | Re: BDR Selective Replication |