Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【联表查询速度极慢】 #718

Open
efwevg opened this issue May 13, 2024 · 4 comments
Open

【联表查询速度极慢】 #718

efwevg opened this issue May 13, 2024 · 4 comments

Comments

@efwevg
Copy link

efwevg commented May 13, 2024

Description

apijson版本:6.2.0
数据库:mysql 8.0.21
JDK/基础库: 1.8.0_17
OS/系统:win11
问题描述:
两表数据都在1600条左右、结果也是1600条左右,一对一关系,且增加redis对联表查询的速度差不多,求大佬解惑
附图:
微信图片_20240513155336

@efwevg
Copy link
Author

efwevg commented May 13, 2024

image
但是将redis去除之后反而快很多
image

@TommyLemon
Copy link
Collaborator

TommyLemon commented May 18, 2024

APIJSON 性能是有测试过的,包括在腾讯的项目中实际表现也很好:
https://github.com/Tencent/APIJSON/releases/tag/5.1.5

Redis 如果没部署(连接耗时,超时才有结果),或者不在本机部署(网络耗时),光连 Redis 查询就会很耗时。

你现在这种写法
1.首先引用赋值(外键关联)写法就错了
"id>": "/Srctions/router_id"
对应
WHERE id > '/Srctions/router_id'
结果可能是扫全表然后查不到值

应该改成
"id@": "/Srctions/router_id"

可以加 @Explain: true 或者在控制台日志查看生成和执行的 SQL。

建议多看看 通用文档测试用例

2.其次如果写对了,那也是 N+1 次查询,大数据量下性能确实差,需要改成 JOIN,可以试试 APP JOIN 和 LEFT/INNER JOIN
#374

3.最后 Log.DEBUG = true(默认 false) 时,打印日志对性能会有明显影响,可以关掉后再测试

@efwevg
Copy link
Author

efwevg commented May 28, 2024

1.如果写法改为"id@": "/Srctions/router_id" sql会执行多次,会和数据量无限叠加,速度更慢

@TommyLemon
Copy link
Collaborator

用 JOIN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants