详解Spring AOP篇二

详解Spring AOP篇二

目录

Spring AOP核心概念

切点(Pointcut)

连接点(Join Point)

切点和连接点的关系

通知(Advice)

切面(Aspect)

通知类型

AspectDemo

TestControler

通知类型的执行顺序 

关于@Around表示的方法返回值问题

@Pointcut

切面优先级@Order

切点表达式

execution表达式

annotation表达式


Spring AOP核心概念
切点(Pointcut)

切点(Pointcut), 也称之为"切⼊点"。
Pointcut 的作⽤就是提供⼀组规则 (使⽤ AspectJ pointcut expression language 来描述), 告诉程序对哪些⽅法来进⾏功能增强.

上面的表达式 execution(* com.wmh.springaop.controller.*.*(..)) 就是 切点表达式。

连接点(Join Point)

满⾜切点表达式规则的⽅法, 就是连接点. 也就是可以被AOP控制的⽅法.

对于下面的代码,com.wmh.springaop.controller路径下所有类的所有方法,都是连接点。

切点和连接点的关系

连接点是满⾜切点表达式的元素. 切点可以看做是保存了众多连接点的⼀个集合。

通知(Advice)

通知就是具体要做的⼯作, 指哪些重复的逻辑,也就是共性功能(最终体现为⼀个⽅法)
⽐如上述代码中记录业务⽅法的耗时时间, 就是通知。

在AOP⾯向切⾯编程当中, 我们把这部分重复的代码逻辑抽取出来单独定义, 这部分代码就是通知的内容.

切面(Aspect)

切⾯(Aspect) = 切点(Pointcut) + 通知(Advice).
通过切⾯就能够描述当前AOP程序需要针对于哪些⽅法, 在什么时候执⾏什么样的操作.
切⾯既包含了通知逻辑的定义, 也包括了连接点的定义.

切⾯所在的类, 我们⼀般称为切⾯类(被@Aspect注解标识的类)。

通知类型

上⾯我们讲了什么是通知, 接下来学习通知的类型. @Around 就是其中⼀种通知类型, 表⽰环绕通知.
Spring中AOP的通知类型有以下⼏种:

• @Around: 环绕通知, 此注解标注的通知⽅法在⽬标⽅法前, 后都被执⾏
• @Before: 前置通知, 此注解标注的通知⽅法在⽬标⽅法前被执⾏
• @After: 后置通知, 此注解标注的通知⽅法在⽬标⽅法后被执⾏, ⽆论是否有异常都会执⾏
• @AfterReturning: 返回后通知, 此注解标注的通知⽅法在⽬标⽅法后被执⾏, 有异常不会执⾏
• @AfterThrowing: 异常后通知, 此注解标注的通知⽅法发⽣异常后执⾏

下面通过代码加深对上面通知类型的理解:

AspectDemo
package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo { @Before("execution(* com.wmh.springaop.controller..*(..))") public void doBefore(){ log.info("AspectDemo do before...."); } @After("execution(* com.wmh.springaop.controller..*(..))") public void doAfter(){ log.info("AspectDemo do after...."); } @Around("execution(* com.wmh.springaop.controller..*(..))") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { log.info("AspectDemo do around before...."); Object result = joinPoint.proceed(); log.info("AspectDemo do around after..."); return result; } @AfterReturning("execution(* com.wmh.springaop.controller..*(..))") public void doAfterReturning(){ log.info("AspectDemo do after returning...."); } @AfterThrowing("execution(* com.wmh.springaop.controller..*(..))") public void doAfterThrowing(){ log.info("AspectDemo do after throwing...."); } }
TestControler
package com.wmh.springaop.controller; import com.wmh.springaop.config.MyAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RequestMapping("/test") @RestController public class TestController { @RequestMapping("/t1") public String t1(){ log.info("执行t1方法..."); return "t1"; } @RequestMapping("/t2") public String t2(){ log.info("执行t2方法..."); int a = 10/0; return "t2"; } }
通知类型的执行顺序 

上面代码正常情况下的运行结果:

由此我们知道,正常情况下通知类型的执行顺序是:

发生异常时的运行结果:

由此我们知道,发生异常的情况下通知类型的执行顺序是: 

比较正常情况下和发生异常的情况下的运行结果:

从上面我们可以看到,当发生异常时@AfterReturning表示的通知方法不会执行了,@AfterThrowing表示的通知方法执行了。

而且,当@Around环绕通知中原始方法调用时有异常,通知中的环绕后的代码逻辑就不会执行了,因为原始方法调用出异常了。

关于@Around表示的方法返回值问题

当@Around标识的方法有返回值且类型为Object时:

AspectDemo

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo { @Around("execution(* com.wmh.springaop.controller..*(..))") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { log.info("AspectDemo do around before...."); Object result = joinPoint.proceed(); log.info("AspectDemo do around after..."); return result; } }

TestController

package com.wmh.springaop.controller; import com.wmh.springaop.config.MyAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RequestMapping("/test") @RestController public class TestController { @RequestMapping("/t1") public String t1(){ log.info("执行t1方法..."); return "t1"; } }

运行结果:

当@Around表示的方法没有返回值时:

AspectDemo

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo { @Around("execution(* com.wmh.springaop.controller..*(..))") public void doAround(ProceedingJoinPoint joinPoint) throws Throwable { log.info("AspectDemo do around before...."); Object result = joinPoint.proceed(); log.info("AspectDemo do around after..."); } }

注意事项

• @Around 环绕通知需要调⽤ ProceedingJoinPoint.proceed() 来让原始⽅法执⾏, 其他
通知不需要考虑⽬标⽅法执⾏.
• @Around 环绕通知⽅法的返回值, 必须指定为Object, 来接收原始⽅法的返回值, 否则原始⽅法执⾏完毕, 是获取不到返回值的.
• ⼀个切⾯类可以有多个切点.
@Pointcut

上⾯代码存在⼀个问题, 就是存在⼤量重复的切点表达式 execution(* com.wmh.springaop.controller..*(..)) , Spring提供了 @PointCut 注解, 把公共的切点
表达式提取出来, 需要⽤到时引⽤该切⼊点表达式即可.

上述代码就可以修改为: 

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo { @Pointcut("execution(* com.wmh.springaop.controller..*(..))") public void pt(){}; @Before("pt()") public void doBefore(){ log.info("AspectDemo do before...."); } @After("pt()") public void doAfter(){ log.info("AspectDemo do after...."); } @Around("pt()") public void doAround(ProceedingJoinPoint joinPoint) throws Throwable { log.info("AspectDemo do around before...."); Object result = joinPoint.proceed(); log.info("AspectDemo do around after..."); } @AfterReturning("pt()") public void doAfterReturning(){ log.info("AspectDemo do after returning...."); } @AfterThrowing("pt()") public void doAfterThrowing(){ log.info("AspectDemo do after throwing...."); } }

当切点定义使⽤private修饰时, 仅能在当前切⾯类中使⽤, 当其他切⾯类也要使⽤当前切点定义时, 就需要把private改为public. 引⽤⽅式为: 全限定类名.⽅法名()

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; @Order(1) @Slf4j @Component @Aspect public class AspectDemo2 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo2 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo2 do after...."); } }
切面优先级@Order

当我们在⼀个项⽬中, 定义了多个切⾯类时, 并且这些切⾯类的多个切⼊点都匹配到了同⼀个⽬标⽅法.当⽬标⽅法运⾏的时候, 这些切⾯类中的通知⽅法都会执⾏, 那么这⼏个通知⽅法的执⾏顺序是什么样的呢?
我们还是通过程序来求证:
定义多个切⾯类:
为简单化, 只写了 @Before 和 @After 两个通知.

AspectDemo2

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo2 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo2 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo2 do after...."); } }

AspectDemo3

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo3 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo3 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo3 do after...."); } }

 AspectDemo4

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class AspectDemo4 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo4 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo4 do after...."); } }

TestController

package com.wmh.springaop.controller; import com.wmh.springaop.config.MyAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RequestMapping("/test") @RestController public class TestController { @RequestMapping("/t1") public String t1(){ log.info("执行t1方法..."); return "t1"; } }

运行结果:

通过上述程序的运⾏结果, 可以看出:
存在多个切⾯类时, 默认按照切⾯类的类名字⺟排序:

• @Before 通知:字⺟排名靠前的先执⾏
• @After 通知:字⺟排名靠前的后执⾏

但这种⽅式不⽅便管理, 我们的类名更多还是具备⼀定含义的.
Spring 给我们提供了⼀个新的注解, 来控制这些切⾯通知的执⾏顺序: @Order
修改上面的代码:

AspectDemo2

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @Order(1) @Slf4j @Component @Aspect public class AspectDemo2 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo2 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo2 do after...."); } }

AspectDemo3

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @Order(100) @Slf4j @Component @Aspect public class AspectDemo3 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo3 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo3 do after...."); } }

AspectDemo4

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @Order(25) @Slf4j @Component @Aspect public class AspectDemo4 { @Before("com.wmh.springaop.aspect.AspectDemo.pt()") public void doBefore(){ log.info("AspectDemo4 do before...."); } @After("com.wmh.springaop.aspect.AspectDemo.pt()") public void doAfter(){ log.info("AspectDemo4 do after...."); } }

运行结果:

通过上述程序的运⾏结果, 得出结论:
@Order 注解标识的切⾯类, 执⾏顺序如下:

• @Before 通知:数字越⼩先执⾏
• @After 通知:数字越⼤先执⾏

@Order 控制切⾯的优先级, 先执⾏优先级较⾼的切⾯, 再执⾏优先级较低的切⾯, 最终执⾏⽬标⽅法. 

切点表达式

上⾯的代码中, 我们⼀直在使⽤切点表达式来描述切点. 下⾯我们来介绍⼀下切点表达式的语法.
切点表达式常⻅有两种表达⽅式:

1. execution(RR):根据⽅法的签名来匹配
2. @annotation(RR) :根据注解匹配
execution表达式

execution() 是最常⽤的切点表达式, ⽤来匹配⽅法, 语法为: 

execution(<访问修饰符> <返回类型> <包名.类名.⽅法(⽅法参数)> <异常>)

其中: 访问修饰符和异常可以省略。

切点表达式⽀持通配符表达:

1. * :匹配任意字符,只匹配⼀个元素(返回类型, 包, 类名, ⽅法或者⽅法参数)
        a. 包名使⽤ * 表⽰任意包(⼀层包使⽤⼀个*)
        b. 类名使⽤ * 表⽰任意类
        c. 返回值使⽤ * 表⽰任意返回值类型
        d. ⽅法名使⽤ * 表⽰任意⽅法
        e. 参数使⽤ * 表⽰⼀个任意类型的参数
2. .. :匹配多个连续的任意符号, 可以通配任意层级的包, 或任意类型, 任意个数的参数
        a. 使⽤ .. 配置包名,标识此包以及此包下的所有⼦包
        b. 可以使⽤ .. 配置参数,任意个任意类型的参数

切点表达式示例

TestController 下的 public修饰, 返回类型为String ⽅法名为t1, ⽆参⽅法

execution(public String com.example.demo.controller.TestController.t1()) 

省略访问修饰符

execution(String com.example.demo.controller.TestController.t1()) 

匹配所有返回类型

execution(* com.example.demo.controller.TestController.t1())

匹配TestController 下的所有⽆参⽅法

 execution(* com.example.demo.controller.TestController.*()) 

匹配TestController 下的所有⽅法

execution(* com.example.demo.controller.TestController.*(..)) 

匹配controller包下所有的类的所有⽅法

execution(* com.example.demo.controller.*.*(..)) 

匹配所有包下⾯的TestController

execution(* com..TestController.*(..)) 

匹配com.example.demo包下, ⼦包下的所有类的所有⽅法 

execution(* com.example.demo..*(..))
annotation表达式

execution表达式更适⽤有规则的, 如果我们要匹配多个⽆规则的⽅法呢, ⽐如:TestController中的t1()和UserController中的u1()这两个⽅法.
这个时候我们使⽤execution这种切点表达式来描述就不是很⽅便了.
我们可以借助⾃定义注解的⽅式以及另⼀种切点表达式 @annotation 来描述这⼀类的切点。

实现步骤:

1. 编写⾃定义注解
2. 使⽤ @annotation 表达式来描述切点
3. 在连接点的⽅法上添加⾃定义注解 

自定义注解@MyAspect

package com.wmh.springaop.config; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAspect { }

说明

1.@Target 标识了 Annotation 所修饰的对象范围, 即该注解可以⽤在什么地⽅.
常⽤取值:
        ElementType.TYPE: ⽤于描述类、接⼝(包括注解类型) 或enum声明
        ElementType.METHOD: 描述⽅法
        ElementType.PARAMETER: 描述参数
        ElementType.TYPE_USE: 可以标注任意类型
2. @Retention 指Annotation被保留的时间⻓短, 标明注解的⽣命周期
@Retention 的取值有三种:
        1. RetentionPolicy.SOURCE:表⽰注解仅存在于源代码中, 编译成字节码后会被丢弃. 这意味着在运⾏时⽆法获取到该注解的信息, 只能在编译时使⽤. ⽐如 @SuppressWarnings , 以及lombok提供的注解 @Data , @Slf4j
        2. RetentionPolicy.CLASS:编译时注解. 表⽰注解存在于源代码和字节码中, 但在运⾏时会被丢弃. 这意味着在编译时和字节码中可以通过反射获取到该注解的信息, 但在实际运⾏时⽆法获取. 通常⽤于⼀些框架和⼯具的注解.
        3. RetentionPolicy.RUNTIME:运⾏时注解. 表⽰注解存在于源代码, 字节码和运⾏时中. 这意味着在编译时, 字节码中和实际运⾏时都可以通过反射获取到该注解的信息. 通常⽤于⼀些需要在运⾏时处理的注解, 如Spring的 @Controller @ResponseBody 

切面类

使⽤ @annotation 切点表达式定义切点, 只对 @MyAspect ⽣效
切⾯类代码如下: 

package com.wmh.springaop.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Slf4j @Component @Aspect public class MyAspectDemo { @Around("@annotation(com.wmh.springaop.config.MyAspect)") public Object doAround(ProceedingJoinPoint joinPoint){ log.info("do around before..."); Object o = null; try { o = joinPoint.proceed(); } catch (Throwable e) { log.error("发生异常,e:", e); } log.info("do around after..."); return o; } }

添加自定义注解

TestController

package com.wmh.springaop.controller; import com.wmh.springaop.config.MyAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RequestMapping("/test") @RestController public class TestController { @MyAspect @RequestMapping("/t1") public String t1(){ log.info("执行t1方法..."); return "t1"; } @RequestMapping("/t2") public String t2(){ log.info("执行t2方法..."); int a = 10/0; return "t2"; } }

UserController

package com.wmh.springaop.controller; import com.wmh.springaop.config.MyAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RequestMapping("/user") @RestController public class UserController { @RequestMapping("/u1") public String u1(){ log.info("执行u1方法..."); return "u1"; } @MyAspect @RequestMapping("/u2") public String u2(){ log.info("执行u2方法..."); return "u2"; } }

 访问test/t1运行结果:

访问user/u2运行结果:

Read more

MySQL 总结|MySQL 从入门到高级

MySQL 总结|MySQL 从入门到高级

摘要:本文全面系统地讲解了 MySQL 从基础操作到高级特性的核心知识,内容涵盖数据库基础概念、SQL 核心语法、索引与性能优化、事务与锁机制、InnoDB 引擎原理、主从复制等关键技术。 1. MySQL 概述 1.1 数据库相关概念 本部分将讲解三个核心概念:数据库、数据库管理系统、SQL。 名称全称简称数据库存储数据的仓库,数据是有组织的进行存储DataBase数据库管理系统操纵和管理数据库的大型软件DataBase Management System SQL操作关系型数据库的编程语言,定义了一套操作关系型数据库统一标准Structured Query Language  2. SQL语句 全称 Structured Query Language(结构化查询语言),是操作关系型数据库的编程语言,定义了一套操作关系型数据库的统一标准。无论使用 Oracle、SQL Server 还是 MySQL 等关系型数据库,均可以通过 SQL 语言进行统一操作,因此掌握

By Ne0inhk
Spring 事务和事务传播机制

Spring 事务和事务传播机制

1. 事务的回顾 在 MySQL 学习阶段,已经了解到了事务是一组操作的集合,也就是把所有的操作作为一个整体,一起向数据库提交或者撤销操作,要么同时成功,要么同时失败 一个事务的操作流程包括了,开启事务,执行事务操作,提交事务或回滚事务,对于回滚事务来说,如果程序在执行过程中出现了错误,那么此时就需要执行回滚事务 2. 事务的实现方式 2.1. 编程式事务 Spring 手动操作事务和 MySQL 操作事务类似,也是分为开启事务,提交事务,回滚事务等三个操作,需要用到 DataSourceTransactionManager (事务管理器)来进行上述事务的操作,还需要用到 TransactionDefinition(事务的属性,获取事务时需要把这个类的对象传进去) @RestController @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @Autowired

By Ne0inhk
必收藏!小白也能懂:Agent、Skills、MCP和A2A大模型架构完全指南

必收藏!小白也能懂:Agent、Skills、MCP和A2A大模型架构完全指南

文章详解AI Agent四大核心概念:Agent作为智能决策主体,Skills提供原子化能力封装,MCP实现标准化工具调用,A2A支持Agent间协作。这些技术共同构建了从单Agent自主执行到多Agent协同工作的完整技术栈,解决了智能体的自主性、模块化能力、工具调用和互操作等核心问题,助力开发者快速构建专业级AI应用。 一、Agent、Skills、MCP和A2A的核心概念总览 1、Agent (代理/智能体):自主决策与执行的“大脑”。 AI Agent是2026年AI生态的核心概念,是基于人工智能技术构建的、具备感知环境、理解信息、自主推理决策、自主规划与执行动作并持续与环境/其他主体交互,以自主达成预设或动态生成目标的数字智能实体。2026年的智能体不是在回答问题,而是在完成任务。其突破了传统问答式、生成式AI的能力边界,可像人类员工一样独立处理复杂综合性任务。它以大模型为核心引擎,整合规划、记忆、工具调用与行动执行四大能力,形成「感知 - 认知 - 决策 - 执行 - 反馈」的完整智能闭环,

By Ne0inhk
别再手动调优了!KingbaseES连接条件下推自动拯救慢 SQL

别再手动调优了!KingbaseES连接条件下推自动拯救慢 SQL

告别SQL性能焦虑:金仓数据库“连接条件下推”的性能魔法 你是否遇到过这样的场景:一个看似复杂的SQL,在测试环境运行飞快,一到生产环境就“卡死”,一查执行计划,发现子查询生成了一个巨大的中间结果集,导致后续操作全部陷入性能泥潭? 如果你正被此类场景困扰,那么,是时候认识一项改变游戏规则的技术:金仓数据库(KingbaseES)「基于代价的连接条件下推」。它不仅是技术优化,更是应对复杂业务查询的“性能终结者”。 一、 为什么你的复杂SQL会“爆内存”? 在金融、政务等复杂业务系统中,为了逻辑清晰,SQL常常被写成这样: SELECT * FROM (SELECT DISTINCT * FROM 巨表_A) AS 子查询结果, 筛选表_B WHERE 子查询结果.关键ID = 筛选表_B.关键ID AND 筛选表_B.过滤字段 = '

By Ne0inhk