在 SET PROFILING=1 之后,我运行了一个多连接查询(多个左连接,每个左连接内部都是来自多个相同表的子查询)。运行两次此查询后,请参阅下面的每个状态所花费的时间:
mysql> SHOW PROFILE SOURCE FOR QUERY 6;
+--------------------------------+----------+-----------------------+--------------+-------------+
| Status | Duration | Source_function | Source_file | Source_line |
+--------------------------------+----------+-----------------------+--------------+-------------+
| starting | 0.000046 | NULL | NULL | NULL |
| Waiting for query cache lock | 0.000010 | try_lock | sql_cache.cc | 454 |
| checking query cache for query | 0.000035 | send_result_to_client | sql_cache.cc | 1561 |
| checking privileges on cached | 0.000009 | send_result_to_client | sql_cache.cc | 1652 |
| checking permissions | 0.000012 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000009 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000008 | check_access | sql_parse.cc | 4751 |
| checking permissions | 0.000009 | check_access | sql_parse.cc | 4751 |
| sending cached result to clien | 0.000094 | send_result_to_client | sql_cache.cc | 1749 |
| logging slow query | 0.000009 | log_slow_statement | sql_parse.cc | 1461 |
| cleaning up | 0.000010 | dispatch_command | sql_parse.cc | 1417 |
+--------------------------------+----------+-----------------------+--------------+-------------+
31 rows in set (0.00 sec)
我想知道为什么我有这么多“检查权限”。查询结果没有问题,查询的基本结构是:
select field1, field2, etc
from A
inner join B on (A.id = B.bid)
inner join C on (...)
...
left join
(select some fields
from A
inner join B on (A.id = B.bid)
inner join C on (...)
...
where ...
group by ...) as tbl_new1 on (...)
left join
(select some fields
from A
inner join B on (A.id = B.bid)
inner join C on (...)
...
where ...
group by ...) as tbl_new2 on (...)
left join
(select some fields
from A
inner join B on (A.id = B.bid)
inner join C on (...)
...
where ...
group by ...) as tbl_new3 on (...)
where ...
GROUP BY ... ;
谢谢。