Re: pg, mysql comparison with "group by" clause

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: pg, mysql comparison with "group by" clause
Дата
Msg-id 87oe5uyrfs.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: pg, mysql comparison with "group by" clause  ("Anthony Molinaro" <amolinaro@wgen.net>)
Ответы Re: pg, mysql comparison with "group by" clause
Re: pg, mysql comparison with "group by" clause
Список pgsql-sql
"Anthony Molinaro" <amolinaro@wgen.net> writes:

> Greg,
>   You'll have to pardon me...
>  
> I saw this comment:
> 
> "I don't see why you think people stumble on this by accident. 
> I think it's actually an extremely common need."
> 
> Which, if referring to the ability to have items in the select that do not
> need to be included in the group, (excluding constants and the like) is just
> silly.

Well the "constants and the like" are precisely the point. There are plenty of
cases where adding the column to the GROUP BY is unnecessary and since
Postgres makes no attempt to prune them out, inefficient. And constants aren't
the only such case. The most common case is columns that are coming from a
table where the primary key is already included in the GROUP BY list.

In the case of columns coming from a table where the primary key is already in
the GROUP BY list it's possible for the database to deduce that it's
unnecessary to group on that column. 

But it's also possible to have cases where the programmer has out of band
knowledge that it's unnecessary but the database doesn't have that knowledge.
The most obvious case that comes to mind is a denormalized data model that
includes a redundant column.
 select dept_id, dept_name, count(*) from employee_list

For example if dept_name is guaranteed to be the same for all records with the
same dept_id. Of course that's generally considered poor design but it doesn't
mean there aren't thousands of databases out there with data models like that.

-- 
greg



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

Предыдущее
От: "Anthony Molinaro"
Дата:
Сообщение: Re: pg, mysql comparison with "group by" clause
Следующее
От: Ferindo Middleton Jr
Дата:
Сообщение: UPDATE Trigger on multiple tables