Tidb数据库统计信息和表连接方式

:fire: TiDB 支持的 Join 算法

:one: Index Nested Loop Join(INLJ) :white_check_mark:

:point_right: 类似 MySQL 5.7

  • 适合:小表驱动大表 + 有索引
  • 最常见

:two: Hash Join :white_check_mark:(重点)

:point_right: TiDB 默认最常用

  • 构建 hash 表(build side)
  • 探测匹配(probe side)

:point_right: 适合:

  • 大表 join
  • 无索引场景

Hash Join: build hash on smaller table, then probe with larger tableHash Join: build hash on smaller table, then probe with larger table


:three: Merge Join(Sort Merge Join) :white_check_mark:(有限支持)

:point_right: 条件:

  • 两边数据 已经有序

否则:

  • TiDB 一般不会主动做排序再 merge(成本高)

:bar_chart: 对比一下 MySQL 5.7

能力 MySQL 5.7 TiDB
Nested Loop Join :white_check_mark: :white_check_mark:
Hash Join :x: :white_check_mark:
Merge Join :x: :white_check_mark:(有限)
分布式 Join :x: :white_check_mark:
2 个赞