类 IllegalSQLInnerInterceptor
java.lang.Object
com.baomidou.mybatisplus.extension.parser.JsqlParserSupport
com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor
- 所有已实现的接口:
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
public class IllegalSQLInnerInterceptor
extends JsqlParserSupport
implements com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
由于开发人员水平参差不齐,即使订了开发规范很多人也不遵守
SQL是影响系统性能最重要的因素,所以拦截掉垃圾SQL语句
拦截SQL类型的场景
1.必须使用到索引,包含left join连接字段,符合索引最左原则
必须使用索引好处,
1.1 如果因为动态SQL,bug导致update的where条件没有带上,全表更新上万条数据
1.2 如果检查到使用了索引,SQL性能基本不会太差
2.SQL尽量单表执行,有查询left join的语句,必须在注释里面允许该SQL运行,否则会被拦截,有left join的语句,如果不能拆成单表执行的SQL,请leader商量在做
https://gaoxianglong.github.io/shark
SQL尽量单表执行的好处
2.1 查询条件简单、易于开理解和维护;
2.2 扩展性极强;(可为分库分表做准备)
2.3 缓存利用率高;
2.在字段上使用函数
3.where条件为空
4.where条件使用了 !=
5.where条件使用了 not 关键字
6.where条件使用了 or 关键字
7.where条件使用了 使用子查询
- 从以下版本开始:
- 3.4.0
- 作者:
- willenfoo
-
字段概要
从类继承的字段 com.baomidou.mybatisplus.extension.parser.JsqlParserSupport
logger -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidbeforePrepare(org.apache.ibatis.executor.statement.StatementHandler sh, Connection connection, Integer transactionTimeout) List<com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor.IndexInfo> getIndexInfos(String key, String dbName, String tableName, Connection conn) 得到表的索引信息List<com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor.IndexInfo> getIndexInfos(String dbName, String tableName, Connection conn) 得到表的索引信息protected voidprocessDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj) 删除protected voidprocessSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object obj) 查询protected voidprocessUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj) 更新从类继承的方法 com.baomidou.mybatisplus.extension.parser.JsqlParserSupport
parserMulti, parserSingle, processInsert, processParser从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
beforeGetBoundSql, beforeQuery, beforeUpdate, setProperties, willDoQuery, willDoUpdate
-
构造器详细资料
-
IllegalSQLInnerInterceptor
public IllegalSQLInnerInterceptor()
-
-
方法详细资料
-
beforePrepare
public void beforePrepare(org.apache.ibatis.executor.statement.StatementHandler sh, Connection connection, Integer transactionTimeout) - 指定者:
beforePrepare在接口中com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
-
processSelect
protected void processSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object obj) 从类复制的说明:JsqlParserSupport查询- 覆盖:
processSelect在类中JsqlParserSupport
-
processUpdate
protected void processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj) 从类复制的说明:JsqlParserSupport更新- 覆盖:
processUpdate在类中JsqlParserSupport
-
processDelete
protected void processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj) 从类复制的说明:JsqlParserSupport删除- 覆盖:
processDelete在类中JsqlParserSupport
-
getIndexInfos
public List<com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor.IndexInfo> getIndexInfos(String dbName, String tableName, Connection conn) 得到表的索引信息- 参数:
dbName- ignoretableName- ignoreconn- ignore- 返回:
- ignore
-
getIndexInfos
public List<com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor.IndexInfo> getIndexInfos(String key, String dbName, String tableName, Connection conn) 得到表的索引信息- 参数:
key- ignoredbName- ignoretableName- ignoreconn- ignore- 返回:
- ignore
-