From a433858d8ee94094f8a6312e025994634c920676 Mon Sep 17 00:00:00 2001
From: qxo <49526356@qq.com>
Date: Fri, 3 Nov 2023 22:02:34 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=20=E6=B7=BB=E5=8A=A0slf4j-api?=
=?UTF-8?q?=E4=BB=A5=E4=BE=BF=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97=EF=BC=8C?=
=?UTF-8?q?=20ie:=20=E8=A7=A3=E6=9E=90=E5=87=BA=E9=94=99=E6=97=B6=E7=BB=99?=
=?UTF-8?q?=E5=87=BA=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/pom.xml b/pom.xml
index 69b656d2..2676b7d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,11 @@
compile
true
+
+ org.slf4j
+ slf4j-api
+ 1.7.32
+
junit
From 379658a9ab8b6f4d0be7a3819687c3ecc9c06320 Mon Sep 17 00:00:00 2001
From: qxo <49526356@qq.com>
Date: Sat, 27 Apr 2024 15:31:04 +0800
Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=20=E5=A2=9E=E5=8A=A0SQL?=
=?UTF-8?q?=E8=A7=A3=E6=9E=90=E7=BC=93=E5=AD=98=EF=BC=8C=E4=BB=A5=E6=8F=90?=
=?UTF-8?q?=E5=8D=87=E6=80=A7=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
之前除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未经测试*
---
.../dialect/AbstractHelperDialect.java | 158 ++++++++++++++----
.../dialect/helper/AS400Dialect.java | 5 +
.../dialect/helper/CirroDataDialect.java | 4 +
.../pagehelper/dialect/helper/Db2Dialect.java | 4 +
.../dialect/helper/FirebirdDialect.java | 4 +
.../dialect/helper/HsqldbDialect.java | 12 ++
.../dialect/helper/Oracle9iDialect.java | 4 +
.../dialect/helper/OracleDialect.java | 4 +
.../dialect/helper/SqlServer2012Dialect.java | 4 +
.../dialect/helper/SqlServerDialect.java | 40 ++---
10 files changed, 187 insertions(+), 52 deletions(-)
diff --git a/src/main/java/com/github/pagehelper/dialect/AbstractHelperDialect.java b/src/main/java/com/github/pagehelper/dialect/AbstractHelperDialect.java
index fa30ad4c..c3e3fec3 100644
--- a/src/main/java/com/github/pagehelper/dialect/AbstractHelperDialect.java
+++ b/src/main/java/com/github/pagehelper/dialect/AbstractHelperDialect.java
@@ -24,10 +24,15 @@
package com.github.pagehelper.dialect;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.github.pagehelper.Constant;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageRowBounds;
+import com.github.pagehelper.cache.Cache;
+import com.github.pagehelper.cache.CacheFactory;
import com.github.pagehelper.util.ExecutorUtil;
import com.github.pagehelper.util.MetaObjectUtil;
import com.github.pagehelper.util.StringUtil;
@@ -48,6 +53,16 @@
* @since 2016-12-04 14:32
*/
public abstract class AbstractHelperDialect extends AbstractDialect implements Constant {
+ /**
+ * Logger for this class.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(AbstractHelperDialect.class);
+
+ protected Cache CACHE_COUNTSQL;
+ protected Cache CACHE_PAGESQL;
+
+ public static boolean cacheOnFlag = true;// 临时性开关,为了方便切换,以验证缓存前后对比.
+ public static boolean tracingOn = false;// 临时性开关
/**
* 获取分页参数
@@ -61,7 +76,7 @@ public Page getLocalPage() {
@Override
public final boolean skip(MappedStatement ms, Object parameterObject, RowBounds rowBounds) {
- //该方法不会被调用
+ // 该方法不会被调用
return true;
}
@@ -72,13 +87,48 @@ public boolean beforeCount(MappedStatement ms, Object parameterObject, RowBounds
}
@Override
- public String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey countKey) {
+ public String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds,
+ CacheKey countKey) {
+ final long startTime = tracingOn || logger.isDebugEnabled() ? System.nanoTime() : 0;
+ if (startTime > 0) {
+ logger.info("getCountSql start ...");
+ }
Page