mysql jdbc查询慢 spring_[求助] 一个 SpringBoot+Mysql 项目的性能优化问题

数据库开启了慢查询,long_query_time设为0.1s,能记录到一些100ms左右的慢查询,但没有大于1秒的慢查询记录。

A表查询语句:

select f1,f2,f3 from A where code= ? and latest = 1;

A表上为code和latest 创建了联合索引,explain显示使用了索引,其中f1,f2,f3要查的为业务字段;latest字段取值只有0和1,explain结果如下:

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

| 1 | SIMPLE | A | NULL | ref | index_code_latest | index_code_latest | 1023 | const | 1 | 10.00 | Using where |

B表查询语句 :

select id,f1,f2,...,f15 from B where match(f1) against (?) and latest = 1

B表f1是字段是一个text字段,在上面建立了全文索引,B表一共查询了15个字段;latest字段取值只有0和1;explain结果如下:

| id | select_type | table | partitions | type | possible_keys | key

| key_len | ref | rows | filtered | Extra |

| 1 | SIMPLE | B| NULL | fulltext | ft_f1 | ft_f1 | 0 | const | 1 | 10.00 | Using where; Ft_hints: sorted |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于搭建一个使用Spring Boot、Spring Batch、MyBatis和MySQL项目,您可以按照以下步骤进行操作: 1. 创建一个Spring Boot项目:您可以使用Spring Initializr(https://start.spring.io/)或者在IDE中创建一个新的Spring Boot项目。 2. 添加所需的依赖:在项目的pom.xml文件中添加以下依赖: ```xml <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Batch --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-batch</artifactId> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <!-- MySQL Connector --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> ``` 3. 配置数据源:在application.properties或application.yaml文件中配置MySQL数据库连接信息,例如: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/mydatabase username: your-username password: your-password ``` 4. 创建数据库表:使用MySQL客户端或其他工具创建您需要的数据库表。 5. 创建实体类和Mapper接口:根据您的数据表结构创建对应的Java实体类,并使用MyBatis的注解或XML配置文件创建Mapper接口。 6. 创建Spring Batch的Job配置:创建一个继承自org.springframework.batch.core.configuration.annotation.JobConfiguration的配置类,在其中定义Batch Job的步骤和任务。 7. 编写Batch Job的业务逻辑:根据需求在Batch Job的步骤中编写相应的业务逻辑,例如读取数据、处理数据、写入数据等。 8. 运行Batch Job:在应用程序中启动Batch Job,可以通过命令行、定时任务或其他方式触发。 以上是一个简单的搭建步骤,您可以根据具体需求进行更详细的配置和开发。希望能对您有所帮助!如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值