我正在尝试将以下连接查询作为 MariaDB 10.1.26 上更复杂查询的一部分运行。
select distinct
project_commits.project_id,
date_format(created_at, '%x%v1') as week_commit
from project_commits
left join commits
on project_commits.commit_id = commits.id;
Run Code Online (Sandbox Code Playgroud)
两个连接字段都被索引。但是,连接涉及对 的完整扫描project_commits和索引查找commits。的输出证实了这一点EXPLAIN。
+------+-------------+-----------------+--------+---------------+---------+---------+-------------------------------------+------------+-----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-----------------+--------+---------------+---------+---------+-------------------------------------+------------+-----------------+
| 1 | SIMPLE | project_commits | ALL | NULL | NULL | NULL | NULL | 5417294109 | Using temporary |
| 1 | SIMPLE | commits | …Run Code Online (Sandbox Code Playgroud)