Query time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Query time

Post by GeXus »

How do you find out how long it takes for a query to run?
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

stopwatch :twisted:
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Query time

Post by califdon »

GeXus wrote:How do you find out how long it takes for a query to run?
If you're using MySQL from the command line, it displays the time in seconds at the end of the results. What are you trying to do, optimize a query? If you are, I'd suggest that you check into the available tools for optimizing. There are lots of little 'gotchas' that won't necessarily be obvious just from the raw time it takes to run. For example, are there other concurrent users of the database? I'd have to research it myself, but I'm pretty sure there are built-in environment variables that hold the query time of the most recent query.

Now, in case you're not using MySQL, or even if you are, an option would be to write a test PHP script that saves the timestamp just prior to running the query, then immediately getting another timestamp and subtracting the two.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you want to do this with PHP, have a look at the example code on the microtime() manual page.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Thanks everyone, I installed mysql administrator which has query browser and that shows the execution time.. it seems to do the job for now..
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

phpMyAdmin does as well, though the DB tools usually show it a tad more accurately.
Post Reply