D
D
DrunkMaster2016-07-29 07:37:30
MySQL
DrunkMaster, 2016-07-29 07:37:30

How to understand how sql query works?

SELECT `group_id` FROM `vkgroups` WHERE `group_id` 
IN (SELECT * FROM (SELECT `group_id` FROM `vkmembers` ORDER BY `members` DESC LIMIT 0,20) temp_tab)

The first request is executed for 3 seconds, if it is repeated then 0.0001 Then we change LIMIT for example to 20.20 or 40.20 everything repeats - the first request is 2-3 seconds, the rest are very fast.
EXPLAIN:
a3d28256d390407da94ab88087d85aeb.png
Profiling results:
60141529025a4076a23e85a708d04b66.jpg3eafa4c554154573ab11bf5d6f9f6467.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-07-29
@DrunkMaster

Requests are cached

mysql> show variables like 'query_cache%';
+------------------------------+----------+
| Variable_name                | Value    |
+------------------------------+----------+
| query_cache_limit            | 10485760 |
| query_cache_min_res_unit     | 4096     |
| query_cache_size             | 52428800 |
| query_cache_type             | ON       |
| query_cache_wlock_invalidate | OFF      |
+------------------------------+----------+
5 rows in set (0.20 sec)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question