Friday, October 30, 2009

Group by in custom query in drupal

We should Keep in mind the followings when we use group by in custom queries.

ex: SELECT pname, MIN(price) FROM products GROUP BY pname;

1. The column that you GROUP BY must also be in your SELECT statement.
2. Remember to group by the column you want information about and not the one you are applying the aggregate function on. In our above example we wanted information on the pname and the aggregate function was applied to the price column.

More Mysql Indexes affect performance on heavy traffic site

I want to share about index on table columns. Indexes are something extra that you can enable on your MySQL tables to increase performance, but they do have some downsides. When you create a new index MySQL builds a separate block of information that needs to be updated every time there are changes made to the table. This means that if you are constantly updating, inserting and removing entries in your table this could have a negative impact on performance. So avoid using index unnecessarily. That will affect the performance.