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

增加SQL解析缓存,以提升性能sql parse cache #777

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

qxo
Copy link
Contributor

@qxo qxo commented Nov 3, 2023

之前除SqlServerDialect外,其他Dialect之前没有sql解析缓存.

优化前项目中每次此plugin的SQL解析基本在7/8到几十毫秒之间,有时比sql本身数据库执行还慢时!

经分析这个慢原因是其依赖的jsqlparser本身解析就慢,且在4.5时有反向优化(采用线程池却没每次重新线程!)
`jad net.sf.jsqlparser.parser.CCJSqlParserUtil parseStatement` 

测试发现jsqlparser 4.7和pagehelper不兼容, 4.6 和4.5有同样的问题

增加SQL解析缓存后,重复访问的耗时基本0.5毫秒以下

*需要说明的这次重构目前只在mysql下测试,其他Dialect未经测试*

@abel533
Copy link
Collaborator

abel533 commented Nov 6, 2023

jsqlparser奇葩的地方是几乎每个版本都不兼容...

刚发布的6.0.0,如果4.7能解决问题,后续先考虑升级做兼容。

@qxo qxo force-pushed the feat-sql-parse-cache branch 3 times, most recently from 7832fea to 9f812de Compare November 10, 2023 12:00
@qxo qxo changed the title 增加SQL解析缓存,以提升性能Feat sql parse cache 增加SQL解析缓存,以提升性能sql parse cache Nov 10, 2023
@qxo
Copy link
Contributor Author

qxo commented Nov 10, 2023

jsqlparser奇葩的地方是几乎每个版本都不兼容...

刚发布的6.0.0,如果4.7能解决问题,后续先考虑升级做兼容。

据我分析 jsqlparser 4.7 还是一样的问题,一样的慢

我重新提交一下了:修复排序时缓存SQL的bug

@cysnb
Copy link

cysnb commented Nov 17, 2023

项目做性能测试时压出问题来了,也是这个原因导致的。不知道这个问题有没有处理计划?

@moonfruit
Copy link
Contributor

moonfruit commented Nov 17, 2023

jsqlparser奇葩的地方是几乎每个版本都不兼容...

刚发布的6.0.0,如果4.7能解决问题,后续先考虑升级做兼容。

@abel533 jsqlparser的兼容性问题可以通过将使用的版本内嵌到pagehelper解决,参见 #784

@pagehelper
Copy link
Owner

当前PR暂时不要做后续处理了,会先考虑和4.7做兼容(已经接近完成)。

@abel533
Copy link
Collaborator

abel533 commented Dec 27, 2023

新建了 https://github.com/pagehelper/pagehelper-sqlparser 模块,可以考虑在这个模块增加支持缓存的实现。

qxo added 2 commits April 27, 2024 15:34
之前除SqlServerDialect外,其他Dialect之前没有sql解析缓存.

优化前项目中每次此plugin的SQL解析基本在7/8到几十毫秒之间,有时比sql本身数据库执行还慢时!

经分析这个慢原因是其依赖的jsqlparser本身解析就慢,且在4.5时有反向优化(采用线程池却没每次重新线程!)
```
jad net.sf.jsqlparser.parser.CCJSqlParserUtil parseStatement
```

测试发现jsqlparser 4.7和pagehelper不兼容, 4.6 和4.5有同样的问题

增加SQL解析缓存后,重复访问的耗时基本0.5毫秒以下

*需要说明的这次重构目前只在mysql下测试,其他Dialect未经测试*
@qxo
Copy link
Contributor Author

qxo commented Apr 27, 2024

新建了 https://github.com/pagehelper/pagehelper-sqlparser 模块,可以考虑在这个模块增加支持缓存的实现。

没时间做代码结构调整, 有需要的请自取本PR吧:)

另外重新合并处理一下: 本PR已支持合并到当前最新master分支了
测试一下SQL解析缓存还是很有必要, 加不加相差10-20ms左右
同时验证了一下本项目和jsqlparser 4.9 也是兼容的

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

Successfully merging this pull request may close these issues.

None yet

5 participants