2012-07-31 18 views

risposta

10

Prova questo semplice esempio

mysql> set profiling=1; 
mysql> select count(*) from comment; 
mysql> select count(*) from message; 
mysql> show profiles; 

+----------+------------+------------------------------+ 
| Query_ID | Duration | Query      | 
+----------+------------+------------------------------+ 
|  1 | 0.00012700 | select count(*) from comment | 
|  2 | 0.00014200 | select count(*) from message | 
+----------+------------+------------------------------+ 
2 rows in set (0.00 sec) 
2

è possibile scrivere la query all'interno di sub-query con COUNT di fare il trucco come:

SELECT COUNT(1) 
FROM (SELECT * FROM your_table WHERE ...) a 

Si può rallentare la query un po ', come si sta facendo anche COUNT ma penso che il suo trascurabile.

Per la misurazione delle prestazioni di query che si può accendere PROFILES in MySQL come:

SET profiling = 1; 

Per maggiori dettagli su PROFILES vedere here.

+0

Si dice "ERROR 1248 (42000): Ogni tabella derivata deve avere il proprio alias"? – TIMEX

+0

assegnare qualsiasi alias alla tabella derivata come ho dato 'a' alla fine – Omesh

0
$starttime = microtime(true); 

//Do your query and stuff here 

$endtime = microtime(true); 
$duration = $endtime - $starttime; //calculates total time taken 
Problemi correlati