MySQL Forums
Forum List  »  Newbie

Querying Using All Cores
Posted by: Chris Hughes
Date: July 13, 2015 02:43PM

I have created a very large table with around 150 million rows. Executing the following query takes 25 seconds and uses 12.5% CPU:

SELECT first_of_month, COUNT(*)
FROM table_1
WHERE first_of_month BETWEEN '2014-01-01' AND '2015-03-01'
GROUP BY first_of_month;

I would like to use more CPU and have the query run faster. So using something I found through Google I created this shell script:

#!/bin/bash

now=`date +"%Y-%m-%d" -d "01/01/2014"`
end=`date +"%Y-%m-%d" -d "03/01/2015"`

while [ "$now" != "$end" ] ;

do
sql="SELECT first_of_month, COUNT(*) FROM table_1 WHERE first_of_month = '$now'"
mysql -vvv -uuser -e "$sql" &
now=`date +"%Y-%m-%d" -d "$now + 1 month"`;
done

It takes just 5 seconds and uses over 70% CPU.

My question is, can I perform the same (ie. use more cores simultaneously to speed up query execution) in a stored procedure? Or maybe installing some kind of add-on?

I would prefer not to write shell scripts.

Many thanks

Chrisp

Options: ReplyQuote


Subject
Written By
Posted
Querying Using All Cores
July 13, 2015 02:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.