R
R
Roma2018-01-31 14:43:02
MySQL
Roma, 2018-01-31 14:43:02

Which mysql database queries can be considered fast and which are slow?

All the best!
I have two tables of categories and subcategories in my db.
Categories 255 entries. Each category has 30 subcategories. Subcategories 7650.
Subcategories are related to categories by a foreign key.
I execute the following query:
select * from `categories`, `subcategories` where `categories`.`id` = `subcategories`.`category_id`;
Execution time:
7650 rows in set (0.06 sec)
In the log, the time is:
Query_time: 0.056264 Lock_time: 0.000085 Rows_sent: 7650 Rows_examined: 7905
I am tormented by vague doubts about this (0.06 sec) information.
When the console shows 0.06 seconds - is it 6 hundredths of a second or 6 seconds?
And the second question: What requests can be considered normal in terms of time and which are unacceptably slow for a website?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Dart, 2018-01-31
@gobananas

1. This is 6 hundredths of a second
2. In general, anything less than 0.1 is ok, then you can worry, but if you have millions of records in the database, then 0.5 can be ok
It is possible to enable the slow query log in the mysql settings, set time limit, for example 1 second and all requests running longer than this value will be logged.

M
Melkij, 2018-01-31
@melkij

Which mysql database queries can be considered fast and which are slow?

Fast ones are those whose processing time does not interfere with the user / business / everyone_involved.
Slow ones are, respectively, those that interfere.
0.06 sec in the console is 6 hundredths of a second, of course.
For the web, the time it takes for the page to render to the user matters. A good result for the backend is 0.2 seconds per page generation. This includes all the time of accessing caches, databases and other page building logic.

I
InoMono, 2018-01-31
@InoMono

With a well-built database structure, competent indexes and a competent query, the actual execution of the query is carried out in a fraction of a second, yes.
But getting the selected data, and even more so sending this data, for example, to a browser on the other side of the world, takes a long time.
Therefore, in your particular request, there is still a lot to optimize for speed.
Well, tell me, please, why do you need SEVEN THOUSAND lines?
After all, most likely this is some kind of interactive interaction with the user, such as a website.
He will never flip through these 7000. It's good if he looks at the first 50.
Even if you want to please a meticulous user who scrolls to the last page, it is hardly advisable to extract more than 200-1500 records from the database.
So why would you torture the server with data that you will never show anyone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question