tidb执行计划未达到预期问题

tidb version 7.5.6

问题:线上业务一个多次自关联查询,执行的很慢,看执行计划发现没有达到预期,加上force index也是一样。

表结构如下

mysql> show create table files\G
*************************** 1. row ***************************
       Table: files
Create Table: CREATE TABLE `files` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `project` varchar(32) DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
  UNIQUE KEY `idx_unique_name_per_dir` (`project`,`parent_id`,`name`),
  UNIQUE KEY `uk_file_project` (`parent_id`,`name`,`project`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1980949695643624753
1 row in set (0.01 sec)

mysql>

业务sql如下,通过下面的执行计划可以知道f1表是走了全索引扫描,导致整个执行很慢,这个有点搞不明白为什么会走了全索引扫描。

mysql> DESC SELECT *
    -> FROM `files` f0
    -> LEFT JOIN `files` `f1`  force index(uk_file_project) ON `f0`.`id` = `f1`.`parent_id` AND `f1`.`name` = "bbbb"
    ->     LEFT JOIN `files` `f2`  force index(uk_file_project) ON `f1`.`id` = `f2`.`parent_id` AND `f2`.`name` = "xxxx"
    -> WHERE `f0`.`parent_id` = 0
    -> AND `f0`.`name` = "/"
    -> AND `f0`.`project` = "hhh";
+--------------------------------------+---------------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                   | estRows       | task      | access object                                                        | operator info                                                                                                                                                          |
+--------------------------------------+---------------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| HashJoin_12                          | 60.64         | root      |                                                                      | left outer join, equal:[eq(godepo_hz.files.id, godepo_hz.files.parent_id)]                                                                                             |
| ├─Point_Get_13(Build)                | 1.00          | root      | table:files, index:idx_unique_name_per_dir(project, parent_id, name) |                                                                                                                                                                        |
| └─IndexJoin_18(Probe)                | 60.64         | root      |                                                                      | left outer join, inner:IndexLookUp_17, outer key:godepo_hz.files.id, inner key:godepo_hz.files.parent_id, equal cond:eq(godepo_hz.files.id, godepo_hz.files.parent_id) |
|   ├─IndexLookUp_32(Build)            | 60.64         | root      |                                                                      |                                                                                                                                                                        |
|   │ ├─Selection_31(Build)            | 60.64         | cop[tikv] |                                                                      | eq(godepo_hz.files.name, "gph")                                                                                                                                        |
|   │ │ └─IndexFullScan_29             | 2661622282.00 | cop[tikv] | table:f1, index:uk_file_project(parent_id, name, project)            | keep order:false                                                                                                                                                       |
|   │ └─TableRowIDScan_30(Probe)       | 60.64         | cop[tikv] | table:f1                                                             | keep order:false                                                                                                                                                       |
|   └─IndexLookUp_17(Probe)            | 0.00          | root      |                                                                      |                                                                                                                                                                        |
|     ├─Selection_16(Build)            | 0.00          | cop[tikv] |                                                                      | not(isnull(godepo_hz.files.parent_id))                                                                                                                                 |
|     │ └─IndexRangeScan_14            | 0.00          | cop[tikv] | table:f2, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(godepo_hz.files.parent_id, godepo_hz.files.id) eq(godepo_hz.files.name, zq_smoke_stable_ios)], keep order:false                                  |
|     └─TableRowIDScan_15(Probe)       | 0.00          | cop[tikv] | table:f2                                                             | keep order:false                                                                                                                                                       |
+--------------------------------------+---------------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
11 rows in set (0.00 sec)

后来试了一下只做一次关联,发现执行计划是预期内的

mysql> DESC SELECT *
    -> FROM `files` f0
    -> LEFT JOIN `files` `f1`  force index(uk_file_project) ON `f0`.`id` = `f1`.`parent_id` AND `f1`.`name` = "bbbb"
    -> WHERE `f0`.`parent_id` = 0
    -> AND `f0`.`name` = "/"
    -> AND `f0`.`project` = "hhh";
+---------------------------------+---------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                              | estRows | task      | access object                                                        | operator info                                                                                                                                                          |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| IndexHashJoin_14                | 60.64   | root      |                                                                      | left outer join, inner:IndexLookUp_11, outer key:godepo_hz.files.id, inner key:godepo_hz.files.parent_id, equal cond:eq(godepo_hz.files.id, godepo_hz.files.parent_id) |
| ├─Point_Get_23(Build)           | 1.00    | root      | table:files, index:idx_unique_name_per_dir(project, parent_id, name) |                                                                                                                                                                        |
| └─IndexLookUp_11(Probe)         | 60.64   | root      |                                                                      |                                                                                                                                                                        |
|   ├─Selection_10(Build)         | 60.64   | cop[tikv] |                                                                      | not(isnull(godepo_hz.files.parent_id))                                                                                                                                 |
|   │ └─IndexRangeScan_8          | 60.64   | cop[tikv] | table:f1, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(godepo_hz.files.parent_id, godepo_hz.files.id) eq(godepo_hz.files.name, gph)], keep order:false                                                  |
|   └─TableRowIDScan_9(Probe)     | 60.64   | cop[tikv] | table:f1                                                             | keep order:false                                                                                                                                                       |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
6 rows in set (0.00 sec)

explain analyze SQL 看一下哈,主要 exec info 的信息看看具体执行计划。

第二个 force index 不加试试
或者用SELECT /*+ USE_INDEX(t, idx1) */ * FROM t 这种格式写

这个查不出来,太大了

统计信息收集过嘛? 如果统计信息不准确,可能会导致全文索引。


mysql> explain analyze SELECT * FROM `files` f0  LEFT JOIN `files` `f1`  force index(uk_file_project) ON `f0`.`id` = `f1`.`parent_id` AND `f1`.`name` = "ffff" LEFT JOIN `files` `f2`  force index(uk_file_project) ON `f1`.`id` = `f2`.`parent_id` AND `f2`.`name` = "bbbb" LEFT JOIN `files` `f3`  force index(uk_file_project) ON `f2`.`id` = `f3`.`parent_id` AND `f3`.`name` = "xxxx" WHERE `f0`.`parent_id` = 0 AND `f0`.`name` = "/" AND `f0`.`project` = "hhh";
+------------------------------------------+---------------+------------+-----------+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------+
| id                                       | estRows       | actRows    | task      | access object                                                        | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | operator info                                                                                                                                                                 | memory    | disk    |
+------------------------------------------+---------------+------------+-----------+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------+
| HashJoin_16                              | 60.64         | 1          | root      |                                                                      | time:8m12.4s, loops:2, RU:9627243.168347, build_hash_table:{total:1.41ms, fetch:1.4ms, build:4.59µs}, probe:{concurrency:5, total:41m2s, max:8m12.4s, probe:50.8µs, fetch:41m2s}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | left outer join, equal:[eq(godepo_hz.files.id, godepo_hz.files.parent_id)]                                                                                                    | 123.9 KB  | 0 Bytes |
| ├─Point_Get_17(Build)                    | 1.00          | 1          | root      | table:files, index:idx_unique_name_per_dir(project, parent_id, name) | time:1.29ms, loops:2, Get:{num_rpc:2, total_time:1.21ms}, total_process_time: 204.7µs, total_wait_time: 380.2µs, tikv_wall_time: 633.3µs, scan_detail: {total_process_keys: 2, total_process_keys_size: 284, total_keys: 2, get_snapshot_time: 322.9µs, rocksdb: {block: {cache_hit_count: 23}}}                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                               | N/A       | N/A     |
| └─HashJoin_18(Probe)                     | 60.64         | 128        | root      |                                                                      | time:8m12.4s, loops:2, build_hash_table:{total:8m12.2s, fetch:8m12.2s, build:7.78µs}, probe:{concurrency:5, total:41m1.9s, max:8m12.4s, probe:240.3µs, fetch:41m1.9s}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | left outer join, equal:[eq(godepo_hz.files.id, godepo_hz.files.parent_id)]                                                                                                    | 246.6 KB  | 0 Bytes |
|   ├─IndexJoin_28(Build)                  | 0.00          | 1          | root      |                                                                      | time:8m12.2s, loops:2, inner:{total:57.3ms, concurrency:5, task:1, construct:5.12µs, fetch:57.3ms, build:183ns}, probe:7.93µs                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | left outer join, inner:IndexLookUp_27, outer key:godepo_hz.files.id, inner key:godepo_hz.files.parent_id, equal cond:eq(godepo_hz.files.id, godepo_hz.files.parent_id)        | 123.5 KB  | N/A     |
|   │ ├─IndexLookUp_42(Build)              | 0.00          | 1          | root      |                                                                      | time:8m12.1s, loops:3, index_task: {total_time: 8m12.1s, fetch_handle: 8m12.1s, build: 684ns, wait: 2.18µs}, table_task: {total_time: 25.1ms, num: 1, concurrency: 5}, next: {wait_index: 8m12.1s, wait_table_lookup_build: 2.95ms, wait_table_lookup_resp: 22ms}                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                               | 13.1 KB   | N/A     |
|   │ │ ├─Selection_41(Build)              | 0.00          | 1          | cop[tikv] |                                                                      | time:8m12.1s, loops:3, cop_task: {num: 3588, max: 0s, min: 0s, avg: 2.05s, p95: 4.01s, tot_proc: 36m40.8s, tot_wait: 15.2s, copr_cache_hit_ratio: 0.01, build_task_duration: 5.14ms, max_distsql_concurrency: 15}, rpc_info:{Cop:{num_rpc:3588, total_time:2h2m50.1s}}, backoff{regionMiss: 2ms}, tikv_task:{proc max:0s, min:0s, avg: 2.06s, p80:3.35s, p95:4.01s, iters:2615691, tasks:3588}, scan_detail: {total_process_keys: 2643606632, total_process_keys_size: 267205223023, total_keys: 2761709282, get_snapshot_time: 6.45s, rocksdb: {delete_skipped_count: 2258280, key_skipped_count: 2763966105, block: {cache_hit_count: 3543713, read_count: 4444498, read_byte: 32.2 GB, read_time: 3m31.2s}}} | eq(godepo_hz.files.name, "xxxx")                                                                                                                               | N/A       | N/A     |
|   │ │ │ └─IndexFullScan_39               | 2661622282.00 | 2661846276 | cop[tikv] | table:f2, index:uk_file_project(parent_id, name, project)            | tikv_task:{proc max:0s, min:0s, avg: 1.99s, p80:3.26s, p95:3.92s, iters:2615691, tasks:3588}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | keep order:false                                                                                                                                                              | N/A       | N/A     |
|   │ │ └─TableRowIDScan_40(Probe)         | 0.00          | 1          | cop[tikv] | table:f2                                                             | time:22ms, loops:2, cop_task: {num: 1, max: 21.9ms, proc_keys: 1, tot_proc: 12.2ms, tot_wait: 625.5µs, copr_cache_hit_ratio: 0.00, build_task_duration: 20.3µs, max_distsql_concurrency: 1, max_extra_concurrency: 1}, rpc_info:{Cop:{num_rpc:1, total_time:21.9ms}}, tikv_task:{time:24ms, loops:1}, scan_detail: {total_process_keys: 1, total_process_keys_size: 197, total_keys: 1, get_snapshot_time: 615.4µs, rocksdb: {block: {cache_hit_count: 7, read_count: 5, read_byte: 592.8 KB, read_time: 11.5ms}}}                                                                                                                                                                                              | keep order:false                                                                                                                                                              | N/A       | N/A     |
|   │ └─IndexLookUp_27(Probe)              | 0.00          | 0          | root      |                                                                      | time:57.2ms, loops:1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                                                                                                                                                                               | 356 Bytes | N/A     |
|   │   ├─Selection_26(Build)              | 0.00          | 0          | cop[tikv] |                                                                      | time:57.2ms, loops:1, cop_task: {num: 1, max: 57.1ms, proc_keys: 0, tot_proc: 8.46ms, tot_wait: 48.3ms, copr_cache_hit_ratio: 0.00, build_task_duration: 19.3µs, max_distsql_concurrency: 1}, rpc_info:{Cop:{num_rpc:1, total_time:57.1ms}}, tikv_task:{time:8ms, loops:1}, scan_detail: {total_keys: 1, get_snapshot_time: 1.38ms, rocksdb: {block: {cache_hit_count: 11, read_count: 4, read_byte: 80.3 KB, read_time: 7.91ms}}}                                                                                                                                                                                                                                                                              | not(isnull(godepo_hz.files.parent_id))                                                                                                                                        | N/A       | N/A     |
|   │   │ └─IndexRangeScan_24              | 0.00          | 0          | cop[tikv] | table:f3, index:uk_file_project(parent_id, name, project)            | tikv_task:{time:8ms, loops:1}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | range: decided by [eq(godepo_hz.files.parent_id, godepo_hz.files.id) eq(godepo_hz.files.name, xxxx)], keep order:false | N/A       | N/A     |
|   │   └─TableRowIDScan_25(Probe)         | 0.00          | 0          | cop[tikv] | table:f3                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | keep order:false                                                                                                                                                              | N/A       | N/A     |
|   └─IndexLookUp_23(Probe)                | 60.64         | 128        | root      |                                                                      | time:8m12.4s, loops:2, index_task: {total_time: 8m12.1s, fetch_handle: 8m12.1s, build: 609ns, wait: 2.06µs}, table_task: {total_time: 320.8ms, num: 1, concurrency: 5}, next: {wait_index: 8m12.1s, wait_table_lookup_build: 3.02ms, wait_table_lookup_resp: 317.8ms}                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                               | 48.4 KB   | N/A     |
|     ├─Selection_22(Build)                | 60.64         | 128        | cop[tikv] |                                                                      | time:8m12.1s, loops:3, cop_task: {num: 3588, max: 0s, min: 0s, avg: 2.05s, p95: 4.01s, tot_proc: 36m44.1s, tot_wait: 15.6s, copr_cache_hit_ratio: 0.01, build_task_duration: 5.46ms, max_distsql_concurrency: 15}, rpc_info:{Cop:{num_rpc:3588, total_time:2h2m50.1s}}, backoff{regionMiss: 2ms}, tikv_task:{proc max:0s, min:0s, avg: 2.06s, p80:3.35s, p95:4s, iters:2615691, tasks:3588}, scan_detail: {total_process_keys: 2643606632, total_process_keys_size: 267205223023, total_keys: 2761709282, get_snapshot_time: 6.52s, rocksdb: {delete_skipped_count: 2258280, key_skipped_count: 2763966105, block: {cache_hit_count: 3528309, read_count: 4459909, read_byte: 32.3 GB, read_time: 3m32.8s}}}    | eq(godepo_hz.files.name, "dddd")                                                                                                                                               | N/A       | N/A     |
|     │ └─IndexFullScan_20                 | 2661622282.00 | 2661846276 | cop[tikv] | table:f1, index:uk_file_project(parent_id, name, project)            | tikv_task:{proc max:0s, min:0s, avg: 1.99s, p80:3.26s, p95:3.9s, iters:2615691, tasks:3588}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | keep order:false                                                                                                                                                              | N/A       | N/A     |
|     └─TableRowIDScan_21(Probe)           | 60.64         | 128        | cop[tikv] | table:f1                                                             | time:317.7ms, loops:2, cop_task: {num: 96, max: 299.5ms, min: 0s, avg: 21ms, p95: 179.5ms, max_proc_keys: 15, p95_proc_keys: 3, tot_proc: 3.37s, tot_wait: 3.15s, copr_cache_hit_ratio: 0.00, build_task_duration: 555.6µs, max_distsql_concurrency: 1, max_extra_concurrency: 8, store_batch_num: 76}, rpc_info:{Cop:{num_rpc:20, total_time:2.01s}}, tikv_task:{proc max:192ms, min:0s, avg: 43.1ms, p80:84ms, p95:176ms, iters:96, tasks:96}, scan_detail: {total_process_keys: 128, total_process_keys_size: 34059, total_keys: 128, get_snapshot_time: 2.44s, rocksdb: {block: {cache_hit_count: 1282, read_count: 454, read_byte: 203.1 MB, read_time: 3.2s}}}                                            | keep order:false                                                                                                                                                              | N/A       | N/A     |
+------------------------------------------+---------------+------------+-----------+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------+
16 rows in set (8 min 12.39 sec)

这个要部署来复现一下.

多次自关联查询中表f1 走全索引扫描,
尝试下:将多次关联拆分为分步查询,通过应用层组装结果,降低数据库端的关联开销:
或者:新增复合索引,覆盖关联和过滤字段,CREATE INDEX idx_self_join_opt ON files (project, parent_id, name, id);

1 个赞

我觉得可以收集一下表的统计信息看一下,我试了下在 v8.5.3 也是 IndexRageScan

mysql> DESC SELECT *
    -> FROM `files` f0
    -> LEFT JOIN `files` `f1`  force index(uk_file_project) ON `f0`.`id` = `f1`.`parent_id` AND `f1`.`name` = "bbbb"
    ->     LEFT JOIN `files` `f2`  force index(uk_file_project) ON `f1`.`id` = `f2`.`parent_id` AND `f2`.`name` = "xxxx"
    -> WHERE `f0`.`parent_id` = 0
    -> AND `f0`.`name` = "/"
    -> AND `f0`.`project` = "hhh";
+---------------------------------+---------+-----------+----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| id                              | estRows | task      | access object                                                        | operator info                                                                                                                                      |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| IndexJoin_14                    | 1.56    | root      |                                                                      | left outer join, inner:IndexReader_13, outer key:test.files.id, inner key:test.files.parent_id, equal cond:eq(test.files.id, test.files.parent_id) |
| ├─IndexHashJoin_29(Build)       | 1.25    | root      |                                                                      | left outer join, inner:IndexReader_26, outer key:test.files.id, inner key:test.files.parent_id, equal cond:eq(test.files.id, test.files.parent_id) |
| │ ├─Point_Get_37(Build)         | 1.00    | root      | table:files, index:idx_unique_name_per_dir(project, parent_id, name) |                                                                                                                                                    |
| │ └─IndexReader_26(Probe)       | 1.25    | root      |                                                                      | index:Selection_25                                                                                                                                 |
| │   └─Selection_25              | 1.25    | cop[tikv] |                                                                      | not(isnull(test.files.parent_id))                                                                                                                  |
| │     └─IndexRangeScan_24       | 1.25    | cop[tikv] | table:f1, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(test.files.parent_id, test.files.id) eq(test.files.name, bbbb)], keep order:false, stats:pseudo                              |
| └─IndexReader_13(Probe)         | 1.56    | root      |                                                                      | index:Selection_12                                                                                                                                 |
|   └─Selection_12                | 1.56    | cop[tikv] |                                                                      | not(isnull(test.files.parent_id))                                                                                                                  |
|     └─IndexRangeScan_11         | 1.56    | cop[tikv] | table:f2, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(test.files.parent_id, test.files.id) eq(test.files.name, xxxx)], keep order:false, stats:pseudo                              |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+---------------------------------------------------------------------------------------------
1 个赞

在 v7.5.6 测试也没有问题

mysql> CREATE TABLE `files` (
    ->   `id` bigint(20) NOT NULL AUTO_INCREMENT,
    ->   `project` varchar(32) DEFAULT NULL,
    ->   `parent_id` bigint(20) DEFAULT NULL,
    ->   `name` varchar(255) DEFAULT NULL,
    ->   PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
    ->   UNIQUE KEY `idx_unique_name_per_dir` (`project`,`parent_id`,`name`),
    ->   UNIQUE KEY `uk_file_project` (`parent_id`,`name`,`project`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1980949695643624753;
Query OK, 0 rows affected (0.09 sec)

mysql> DESC SELECT *
    -> FROM `files` f0
    -> LEFT JOIN `files` `f1`  force index(uk_file_project) ON `f0`.`id` = `f1`.`parent_id` AND `f1`.`name` = "bbbb"
    ->     LEFT JOIN `files` `f2`  force index(uk_file_project) ON `f1`.`id` = `f2`.`parent_id` AND `f2`.`name` = "xxxx"
    -> WHERE `f0`.`parent_id` = 0
    -> AND `f0`.`name` = "/"
    -> AND `f0`.`project` = "hhh";
+---------------------------------+---------+-----------+----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| id                              | estRows | task      | access object                                                        | operator info                                                                                                                                      |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| IndexJoin_14                    | 1.56    | root      |                                                                      | left outer join, inner:IndexReader_13, outer key:test.files.id, inner key:test.files.parent_id, equal cond:eq(test.files.id, test.files.parent_id) |
| ├─IndexHashJoin_29(Build)       | 1.25    | root      |                                                                      | left outer join, inner:IndexReader_26, outer key:test.files.id, inner key:test.files.parent_id, equal cond:eq(test.files.id, test.files.parent_id) |
| │ ├─Point_Get_37(Build)         | 1.00    | root      | table:files, index:idx_unique_name_per_dir(project, parent_id, name) |                                                                                                                                                    |
| │ └─IndexReader_26(Probe)       | 1.25    | root      |                                                                      | index:Selection_25                                                                                                                                 |
| │   └─Selection_25              | 1.25    | cop[tikv] |                                                                      | not(isnull(test.files.parent_id))                                                                                                                  |
| │     └─IndexRangeScan_24       | 1.25    | cop[tikv] | table:f1, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(test.files.parent_id, test.files.id) eq(test.files.name, bbbb)], keep order:false, stats:pseudo                              |
| └─IndexReader_13(Probe)         | 1.56    | root      |                                                                      | index:Selection_12                                                                                                                                 |
|   └─Selection_12                | 1.56    | cop[tikv] |                                                                      | not(isnull(test.files.parent_id))                                                                                                                  |
|     └─IndexRangeScan_11         | 1.56    | cop[tikv] | table:f2, index:uk_file_project(parent_id, name, project)            | range: decided by [eq(test.files.parent_id, test.files.id) eq(test.files.name, xxxx)], keep order:false, stats:pseudo                              |
+---------------------------------+---------+-----------+----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
9 rows in set (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v7.5.6

先执行统计分析,再看看执行计划

查不出来啊

预期,需要慢调

降低预期

调优是个技术活

1 个赞

auto explain

trace the explain.

show me the explain result.

嗯,绝对是技术活~

the goal is a practice