# How to reduce the time taken ...... ?

**URL:** <https://forums.percona.com/t/how-to-reduce-the-time-taken/830>\
**Category:** Other MySQL® Questions\
**Created:** [July 7, 2008, 6:35am UTC](https://forums.percona.com/t/how-to-reduce-the-time-taken/830 "2008-07-07T06:35:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spocke](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spocke](https://forums.percona.com/u/spocke)\
**Post date:** [July 7, 2008, 6:35am UTC](https://forums.percona.com/t/how-to-reduce-the-time-taken/830/1 "2008-07-07T06:35:55Z")

</div>

Hi,

I have a table, wherein i am storing all attempts/access for every client. From this table, i would be populating another (report) table. From this report table, i would be populating a graph which shows the attempts/access form a particular client for last 7 days. To make the graph more readable, while populating i am grouping the access time by 4 hour slot i.e,

mysql\> select CONCAT(DATE(HOUR)," ",SEC\_TO\_TIME(CEIL(TIME\_TO\_SEC(HOUR)/14400)\*14400-1)) as ProcessedTIME,HOUR from Attempts\_Vs\_Client limit 1;  
±--------------------±--------------------+  
| ProcessedTIME | HOUR |  
±--------------------±--------------------+  
| 2008-07-01 11:59:59 | 2008-07-01 10:45:00 |  
±--------------------±--------------------+  
1 row in set (0.00 sec)

In production, this query is taking more time and below is an extract from slow query log file.

# Time: 080701 17:27:49

# [User&#64;Host](mailto:User&#64;Host): root[root] @ localhost [127.0.0.1]

# Query\_time: 39.437500 Lock\_time: 0.000000 Rows\_sent: 21 Rows\_examined: 40031

SET timestamp=1214913469;  
select (MIN(AVCT\_ID)-1) as attempt\_min, MAX(AVCT\_ID) as attempt\_max, RID as resid, CONCAT(DATE(HOUR)," ",SEC\_TO\_TIME(CEIL(TIME\_TO\_SEC(HOUR)/14400)\*14400-1)) as TIME from Attempt\_Vs\_Client where Attempt\_Vs\_Client.AVCT\_ID \<= 5143601 and Attempt\_Vs\_Client.AVCT\_ID \>4947183 group by RID,TIME order by NULL;

Additional Details :-

1. Table type → MyISAM
2. Indexed Columns :- AVCT\_ID(PK), HOUR, RID
3. MySQL :- 5.1
4. Total Rows :- ~ 5,00,000.

Below is the output of explain query,

mysql\> explain select (MIN(AVCT\_ID)-1) as Attempt\_min, MAX(AVCT\_ID) as Attempt\_max, RID as resid, CONCAT(DATE(HOUR)," ",SEC\_TO\_TIME(CEIL(TIME\_TO\_SEC(HOUR)/14400)\*14400-1)) as TIME from Attempt\_Vs\_Client where Attempt\_Vs\_Client.AVCT\_ID \<= 5143601 and Attempt\_Vs\_Client.AVCT\_ID \>4947183 group by RID,TIME order by NULL;  
±—±------------±--------------±------±--------------+ ---------±--------±-----±------±------------------------ -----+  
| id | select\_type | table | type | possible\_keys | key | key\_len | ref | rows | Extra |  
±—±------------±--------------±------±--------------+ ---------±--------±-----±------±------------------------ -----+  
| 1 | SIMPLE | Attempt\_Vs\_Client | range | PRIMARY | PRIMARY | 8 | NULL | 42202 | Using where; Using temporary |  
±—±------------±--------------±------±--------------+ ---------±--------±-----±------±------------------------ -----+  
1 row in set (0.00 sec)

Appreciate, if you guys can help me to reduce the amount of time consumed by this particular query ?

Thanks in advance,  
-S-
