From: | Brian Wipf <brian(at)clickspace(dot)com> |
---|---|
To: | PFC <lists(at)peufeu(dot)com> |
Cc: | Vivek Khera <vivek(at)khera(dot)org>, Bill Moseley <moseley(at)hank(dot)org>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Performance issues of one vs. two split tables. |
Date: | 2007-05-16 22:15:55 |
Message-ID: | E7539702-B4E0-49C8-A6D0-8231DE3712E6@clickspace.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 16-May-07, at 4:05 PM, PFC wrote:
> This makes queries hard to optimize. Consider the table (user_id,
> item_id) meaning user selected this item as favourite.
> If you want to know which users did select both items 1 and 2, you
> have to do a self-join, something like :
>
> SELECT... FROM favourites a, favourites b WHERE a.user_id =
> b.user_id AND a.item_id=1 AND b.item_id = 2
You could get users who have selected both items 1 and 2 without
doing a self-join with a query like the following:
select user_id from favourite where item_id = 1 or item_id = 2 group
by user_id having count(*) = 2;
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2007-05-16 22:38:48 | Re: Constructing a SELECT statement in pl/pgsql |
Previous Message | PFC | 2007-05-16 22:05:42 | Re: Performance issues of one vs. two split tables. |