Query Question (one group by vs two separate)

Поиск
Список
Период
Сортировка
От Jonathon Suggs
Тема Query Question (one group by vs two separate)
Дата
Msg-id ec7191c70812101112r6b38231cn253e5abde02e76@mail.gmail.com
обсуждение исходный текст
Ответы Re: Query Question (one group by vs two separate)
Список pgsql-general
I'm asking this as a more general question on which will perform better.  I'm trying to get a set of comments and their score/rankings from two tables.

comments
cid (integer, primary key)
title
body

comment_ratings
cid (integer, primary key)
uid (integer, primary key)
score

Option 1 (Single group by query)
select c.cid,c.title,c.body,coalsece(sum(r.score),0) as score
from comments c left outer join comment_ratings r on c.cid = r.cid
group by c.cid,c.title,c.body;

Option 2 (Two simple queries)
select cid,title,body from comments;
select cid,sum(score) from comment_ratings;

I know that in general you always want to keep the number of queries to a minimum and that Option 1 is the most logical/preferred way to proceed.  However, I've greatly simplified Option 1.  In practice I'm going to be pulling a lot more columns and will be inner joining to additional tables.  So my real question is whether having a lot of items in the group by clause will have an adverse effect on performance.

Thanks in advance,
Jonathon

В списке pgsql-general по дате отправления:

Предыдущее
От: Jason Long
Дата:
Сообщение: Multi-table CHECK constraint
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: Data Replication