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

[Bug] inner join关联查询出现副表查询数量超限的问题 #769

Open
Michaelove opened this issue Oct 9, 2024 · 8 comments
Open

Comments

@Michaelove
Copy link

Michaelove commented Oct 9, 2024

APIJSON测试 api_json_get 2024-10-08 14_22_32.txt

@TommyLemon
Copy link
Collaborator

看起来是 JOIN 缓存未正确读取到导致重复执行 SQL,升级到 7.0.3 再试试

@gxmanito
Copy link

gxmanito commented Nov 6, 2024

使用的6.3.0版本,暂时无法升级版本,有其他方案解决吗(除了加大执行SQL数量限制,指标不治本),我改了一部分代码,驼峰转换,如下:
image

@gxmanito
Copy link

gxmanito commented Nov 6, 2024

#615 (comment)
这里处理后会有个n+1的问题,这里item里面还是驼峰的,但是on.getTargetKey()已经是蛇形了,所以不会走下面childMap.put(viceSql, curItem)缓存
image

image

目前想到的解决方案是改源码,item转为蛇形,不知道是否有其他方案

@gxmanito
Copy link

gxmanito commented Nov 7, 2024

又出现了另一个问题,我的查询需要控制数据权限,所以在verifyAccess将stationCode条件加进去,在join也加进去,但是副表的缓存还是不走,导致n+1查询
image
image

打断点是因为这里的SQL where条件顺序乱了
image

@TommyLemon
Copy link
Collaborator

#615 (comment) 这里处理后会有个n+1的问题,这里item里面还是驼峰的,但是on.getTargetKey()已经是蛇形了,所以不会走下面childMap.put(viceSql, curItem)缓存 image

image

目前想到的解决方案是改源码,item转为蛇形,不知道是否有其他方案

需要改源码处理下,判断 JSONResponse.IS_FORMAT_HYPHEN
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/JSONResponse.java#L25-L34

@TommyLemon
Copy link
Collaborator

@gxmanito 统一在 DemoObjectParser 重写 newSQLConfig 并 putWhere 试试

@gxmanito
Copy link

gxmanito commented Nov 8, 2024

#769 (comment)
在 DemoObjectParser 重写 newSQLConfig 并 putWhere还是不走缓存的,看断点是因为putWhere主表后就会到execute的viceConfig.putWhere(这时候join的where条件只是主表的),然后才是newSQLConfig的putWhere子表的条件(我权限赋值的)
image
image

当我加上join的putWhere时,又会导致顺序错乱,缓存还是读不到
image
image

@TommyLemon
Copy link
Collaborator

TommyLemon commented Nov 8, 2024

@gxmanito 试试 AbstractSQLConfig.getWhere 中判断不包含这个键值对则统一 put

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

No branches or pull requests

3 participants