【 TiDB 使用环境】生产环境
【 TiDB 版本】6.5
【复现路径】
【遇到的问题:问题现象及影响】
模糊查询使用FIND_IN_SET需要建立FULLTEXT索引,但是tidb不支持这个索引,一个表只有9万条数据,但是模糊查询 limit 偏移量大了之后,就开始报慢查询(0.3s以上)
【资源配置】
【附件:截图/日志/监控】
SELECT
…
FROM
… ca
WHERE
ca.is_del = 0
AND ca.user_key LIKE CONCAT(‘%’, ‘abc’, ‘%’)
ORDER BY
ca.course_date DESC
LIMIT
35, 5;
不考虑LIMIT,符合条件的数量是多少条,如果太多0.3s以上很正常
查一个用户的条数才130条 我刚刚测试了一下 不limit 只要0.1s limit35,5就需要0.3-0.4s了 我感觉limit也比较耗时
你这个试试tiflash
可以发下执行计划,看看这里有大神能优化不
我设置了 tiflash 但是他判定不走
补充执行过程
id | task | estRows | operator info | actRows | execution info | memory | disk | |
---|---|---|---|---|---|---|---|---|
Projection_9 | root | 5 | xg_cloud.course_attendance.id, xg_cloud.course_attendance.start_time, xg_cloud.course_attendance.end_time, xg_cloud.course_attendance.class_room, xg_cloud.course_attendance.class_name, xg_cloud.course_attendance.jc, xg_cloud.course_attendance.zc, xg_cloud.course_attendance.course_name, date_format(cast(xg_cloud.course_attendance.course_date, datetime(6) BINARY), %m月%d日)->Column#31 | 5 | time:411ms, loops:2, Concurrency:OFF | 2.71 KB | N/A | |
└─Limit_14 | root | 5 | offset:35, count:5 | 5 | time:411ms, loops:2 | N/A | N/A | |
└─IndexLookUp_22 | root | 40 | 40 | time:411ms, loops:1, index_task: {total_time: 107.9ms, fetch_handle: 3.89ms, build: 10.4ms, wait: 93.6ms}, table_task: {total_time: 1.56s, num: 13, concurrency: 5} | 1.75 MB | N/A | ||
├─IndexFullScan_19(Build) | cop[tikv] | 50.03 | table:ca, index:index_course_date(course_date), keep order:true, desc | 87220 | time:937.2µs, loops:92, cop_task: {num: 1, max: 591.5µs, proc_keys: 0, rpc_num: 1, rpc_time: 578.7µs, copr_cache_hit_ratio: 1.00, distsql_concurrency: 15}, tikv_task:{time:43ms, loops:90} | N/A | N/A | |
└─Selection_21(Probe) | cop[tikv] | 40 | eq(xg_cloud.course_attendance.is_del, 0), eq(xg_cloud.course_attendance.is_submit, 1), like(xg_cloud.course_attendance.teacher_key, %20101065%, 92) | 82 | time:1.52s, loops:24, cop_task: {num: 15, max: 370.8ms, min: 668.2µs, avg: 94ms, p95: 370.8ms, max_proc_keys: 20480, p95_proc_keys: 20480, tot_proc: 1.35s, tot_wait: 2ms, rpc_num: 29, rpc_time: 2.82s, copr_cache_hit_ratio: 0.07, distsql_concurrency: 15}, tikv_task:{proc max:346ms, min:0s, avg: 89.1ms, p80:187ms, p95:346ms, iters:125, tasks:15}, scan_detail: {total_process_keys: 66486, total_process_keys_size: 21619275, total_keys: 66503, rocksdb: {key_skipped_count: 19, block: {cache_hit_count: 523836}}} | N/A | N/A | |
└─TableRowIDScan_20 | cop[tikv] | 50.03 | table:ca, keep order:false | 66742 | tikv_task:{proc max:330ms, min:0s, avg: 85.9ms, p80:178ms, p95:330ms, iters:125, tasks:15} | N/A | N/A |
试过前缀索引不?可以试试
没试过,可以指教下吗
eq(xg_cloud.course_attendance.is_del, 0),
eq(xg_cloud.course_attendance.is_submit, 1),
执行计划里面有这两个筛选,能筛选出来大概百分之多少,如果筛选出来的条数少试试加个is_del和.is_submit的联合索引,再看看
你试试tiflash