Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reasonable time for a mysql-query?

Tags:

mysql

Well, over the time I have seen queries that takes time like 0.0003 seconds (in phpmyadmin), and then there are also queries that takes 60 seconds or more.

I was wondering what the mysql gurus think here, beyond what time I should start worrying that my mysql query is not optimized enough, what's the reasonable time here?

Cheers.

like image 869
Jeremy Roy Avatar asked Apr 20 '11 09:04

Jeremy Roy


People also ask

How long should a SQL query take?

The query takes 20 to 500 ms (or sometimes more) depending on the system and the amount of data. The performance of the database or the database server has a significant influence on the speed.

What is considered a slow query in MySQL?

The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined. The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization.

Why does MySQL query take so long?

There are a number of things that may cause a query to take longer time to execute: Inefficient query – Use non-indexed columns while lookup or joining, thus MySQL takes longer time to match the condition. Table lock – The table is locked, by global lock or explicit table lock when the query is trying to access it.

What is the maximum length of MySQL query?

The maximum length of a VARCHAR in MySQL is subject to the maximum row size of 65,535 bytes, which is shared among all columns except TEXT/BLOB columns and the character set used. It means the total column should not be more than 65535 bytes.


2 Answers

It really depends on the nature of the query, if its something that is done in the back end without no user interaction then it can take tens of minutes in a large DB. e.g. data manipulation, data migration etc...

But if it is to retrieve data for real time user interaction such as showing a website or getting details to show to the user than its how long your user is willing to wait for. Personally i try to keep my total query for all actions at a given time under 1-3 seconds(for serious data crunching stuff) usually start to optimise at 1 second mark.

like image 128
Michal Ciechan Avatar answered Sep 27 '22 16:09

Michal Ciechan


You should start worrying when the query takes so long that usability suffers. For queries that are initiated by a website request, this time is short (the user wants to see the page quickly); for a non-critical batch update, this time is long (should be finished before the next batch update arrives).

On the other hand, you should know what the MySQL Reference Manual says about Optimization to recognize potential for improvement.

like image 24
Oswald Avatar answered Sep 27 '22 18:09

Oswald