Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Query performance -

I have the following Mysql query

explain SELECT count(*) as assetCount 
          FROM MdhRawAsset m 
         where sysCreationDate > date_add(now(), INTERVAL -1 DAY) 
           AND sysCreationDate <= now() 
           AND itemType = 'TS';

Results :

| id | select_type | table | type |possible_keys                                                    
|  1 | SIMPLE      | m     | range | MdhRawAsset_on_sysCreationDate, MdhRawAsset_itemType            
---------------------------------------------------------------------
|Key                          |Key_len  | ref  | rows  | Extra       |  
MdhRawAsset_on_sysCreationDate| 8       | NULL | 53269 | Using where |

Questions :

  1. How will I know the execution time of this query ?
  2. The table MdhRawAsset contains 37.5 million of data, is there a better way to write this query ?
like image 797
user476554 Avatar asked Jun 18 '26 15:06

user476554


1 Answers

  1. The execution time of a query depends on too many issues to determine how long it will take. The load on the server, the number of rows, etc. The best you can do is run it in a typical load and see how long it takes.

  2. You seem to have the correct indexes set up, so I do not see a better way to optimize, but someone else may know better than I do.

like image 132
Alan Geleynse Avatar answered Jun 20 '26 05:06

Alan Geleynse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!