⚡️ perf: fix slow delete file sql #4738
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
LobeChat Cloud 之前一段时间内存在几百次 504 的请求超时问题,主要问题出在删除文件上。
关键的影响字句是
await ctx.chunkModel.deleteOrphanChunks()
, 即删除 chunks 孤块📝 补充信息 | Additional Information
Gather (cost=20752.94..131022.90 rows=287250 width=16) (actual time=10773.043..11474.407 rows=282968 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Parallel Hash Anti Join (cost=19752.94..101297.90 rows=119688 width=16) (actual time=10734.384..11362.630 rows=94323 loops=3)
Hash Cond: (c.id = fc.chunk_id)
-> Parallel Index Only Scan using chunks_pkey on chunks c (cost=0.43..71699.93 rows=509132 width=16) (actual time=1.441..10287.412 rows=407322 loops=3)
Heap Fetches: 342362
-> Parallel Hash (cost=12982.45..12982.45 rows=389445 width=16) (actual time=299.098..299.100 rows=313000 loops=3)
Buckets: 262144 Batches: 8 Memory Usage: 7616kB
-> Parallel Seq Scan on file_chunks fc (cost=0.00..12982.45 rows=389445 width=16) (actual time=0.007..107.330 rows=313000 loops=3)
Planning Time: 1.529 ms
Execution Time: 11495.522 ms
能否解释下?我看不懂
让我帮您逐行解析这个执行计划:
主要性能问题: