WebFaction
Community site: login faq

Hello all,

I am trying to average a group of values with a single WHERE clause. The tables has about 2 million values. What I don't understand is why the query takes ~3.4 seconds while to average all the values takes ~.9 seconds and the WHERE clause alone takes ~.005 seconds. The breakdown is below:

SELECT AVG(models_value.value) FROM models_value WHERE (models_value.parameter_id = 15 )

3.4 seconds

SELECT AVG(models_value.value) FROM models_value

.9 seconds

SELECT (models_value.value) FROM models_value WHERE (models_value.parameter_id = 15 )

.001 seconds

Does anyone have a solution on how to make this faster or at least explain why it takes so long?

Thanks, Eric

asked 08 Dec '11, 13:59

Eric Walter
114
accept rate: 0%


Try profiling the queries.

permanent link

answered 08 Dec '11, 18:00

johns
5.3k212
accept rate: 23%

Hey, For the AVG queries 98%+ is in the sending data stage. For the simple select all "Sending Data" is 25% and "Statistics" is 60%. So I guess I'm looking to decrease the "sending data" time ?

(09 Dec '11, 11:04) Eric Walter

Right. You can also use DESCRIBE to get more information about the query. You may also be able to benefit from an index.

(09 Dec '11, 17:23) johns
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×26
×9

question asked: 08 Dec '11, 13:59

question was seen: 2,102 times

last updated: 09 Dec '11, 17:23

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM