小编Dio*_*lis的帖子

我可以通过分区或合并来加速大型 MySQL/MariaDB 连接吗?

我正在尝试将以下连接查询作为 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)

mysql mariadb join partitioning

3
推荐指数
1
解决办法
4148
查看次数

标签 统计

join ×1

mariadb ×1

mysql ×1

partitioning ×1