3 ms·
Pretty cool! I can see this being really useful. Beware, however, that, while there are certain cases that mysql can utilize indexes in a group by clause if va
by pvnick 13y ago
Pretty cool! I can see this being really useful.
Beware, however, that, while there are certain cases that mysql can utilize indexes in a group by clause if values are constant [1], mysql definitely won't be able to use indexes with any of these functions (I'm not very familiar with postgres so somebody else would have to comment on that). If your load is relatively light or your table is small enough you'd probably be fine, otherwise I would either 1) set another column to the value you want when inserting the row or 2) have a cron run in the background to fill in values on another column, something like update tbl set creation_week = gd_week(creation_timestamp) where creation_week is null.
[1] http://dev.mysql.com/doc/refman/5.0/en/group-by-optimization.html http://dev.mysql.com/doc/refman/5.0/en/group-by-optimization...
- joevandyk 13y agoPostgres can use indexes with these functions. If the functions are marked stable or immutable, then the function bodies will be inlined directly into the query.