PDA

View Full Version : SUMming values


Pykex
05-09-2009, 07:08 PM
I was just wondering: How fast is SUM? Let's say I have a table: ratings.
This table logs the user's IP and also their rating... and also the ID of the "post."

If there are over 2000 ratings (i.e. 2000+ entries) and there are at least 100 ratings for each post ID, how fast/slow will SUM be?

Also, will indexing the `ratings` column speed up the SUM functionality?

hthought
05-09-2009, 07:26 PM
Although i don't know for sure the SUM command just adds numbers so it should have O(n) complexity. This is a computer science notation meaning that the complexity is linear based on the additions. Most times this indicates quite fast operations, so i guess that it's pretty fast.

It will most probably be very fast for 2000 ratings and more.

And i think that indexing the column would most probably slower the execution rather than making it faster.

guelphdad
05-10-2009, 06:37 PM
an index on the column would have no effect on SUM(). an index is used for retrieval matching conditions so would increase speed when looking for values > 100 for instance.