MySQL查询结果中Duration Time和Fetch Time的含义

一 查询

二 Duration和Fetch的含义

mysql duration and fetch time - Stack Overflow

MySQL :: Re: Getting the execution time of a query

Fetch time - measures how long transferring fetched results take, which has nothing to do with query execution. I would not consider it as sql query debugging/optimization option since fetch time depends on network connection, which itself does not have anything to do with query optimization. If fetch time is bottleneck then more likely there's some networking problem.

Note: fetch time may vary on each query execution.

Duration time - is the time that query needs to be executed. You should try to minimize it when optimizing performance of sql query.

翻译

1、fetch time 是传输获取结果所消耗的时间,与sql语句执行时间无关。由于fetch时间依赖网络连接的快慢,所以不能作为优化sql语句时间参考。如果fetch time过长,需要检查网络原因。

2、fetch time 每次执行都可能会变化。

3、duration time 是执行sql语句所消耗的时间,对sql语句优化就是减少这个时间。

### Spring Boot、Vue、Redis MySQL 的架构设计与集成方案 在现代的全栈应用开发中,Spring Boot 作为后端框架,Vue 作为前端框架,Redis 作为缓存数据库,MySQL 作为关系型数据库,它们的结合可以构建高性能、可扩展的应用系统。以下是关于这种架构设计与集成方案的详细说明。 #### 1. 系统架构概述 该架构通常采用分层设计模式,分为前端、后端数据库层。前端使用 Vue 构建单页面应用(SPA),通过 RESTful API 或 GraphQL 与后端交互;后端基于 Spring Boot 实现业务逻辑,并通过 Redis 提供缓存支持以优化性能,同时利用 MySQL 存储持久化数据[^1]。 #### 2. 技术栈集成方案 ##### 前端与后端通信 - 使用 Vue.js 构建前端界面,通过 Axios 或 Fetch API 发起 HTTP 请求与后端进行数据交互。 - 后端提供 RESTful API 接口,确保接口设计符合规范,便于前后端分离开发[^4]。 ##### 数据库集成 - **MySQL**:作为主要的数据存储组件,负责管理结构化数据。配置数据源时需指定驱动类名、URL、用户名密码等信息[^3]。 - **Redis**:用于缓存高频访问的数据,减少对 MySQL 的直接访问压力。例如,可以将用户会话信息或热点数据存储到 Redis 中[^2]。 ##### 配置示例 以下是一个典型的 Spring Boot 配置文件 `application.yml` 的片段: ```yaml spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test_db?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC username: root password: root redis: host: localhost port: 6379 ``` ##### 容器化部署 为了简化部署流程,可以使用 Docker Compose 将整个项目容器化。以下是一个多服务的 `docker-compose.yaml` 文件示例[^2]: ```yaml version: '3.8' services: mysql: image: mysql:8.0 container_name: mysql-container restart: always environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: test_db volumes: - mysql-data:/var/lib/mysql redis: image: redis:latest container_name: redis-container restart: always volumes: - redis-data:/data springboot: build: context: . dockerfile: Dockerfile container_name: springboot-container restart: always depends_on: - mysql - redis ports: - "8080:8080" volumes: mysql-data: redis-data: ``` #### 3. 缓存策略 Redis 在该架构中的作用至关重要,主要用于以下场景: - **会话管理**:存储用户登录状态,避免频繁查询数据库。 - **热点数据缓存**:将经常访问的数据(如商品信息、文章列表)缓存到 Redis 中,提升读取速度。 - **分布式锁**:实现高并发环境下的资源锁定机制[^5]。 #### 4. 部署注意事项 - 确保所有敏感信息(如数据库密码、Redis 密码)都存储在环境变量中,而不是直接写入代码或配置文件。 - 在生产环境中启用 HTTPS,保护数据传输安全。 - 定期备份 MySQL Redis 数据,防止因意外导致数据丢失[^2]。 #### 5. 示例代码 以下是一个简单的 Spring Boot 控制器代码片段,展示如何从 Redis MySQL 中获取数据: ```java @RestController @RequestMapping("/api") public class DemoController { @Autowired private StringRedisTemplate redisTemplate; @Autowired private UserService userService; @GetMapping("/user/{id}") public ResponseEntity<User> getUser(@PathVariable("id") Long id) { String key = "user:" + id; ValueOperations<String, String> ops = redisTemplate.opsForValue(); String userJson = ops.get(key); if (userJson != null) { return ResponseEntity.ok(JsonUtils.fromJson(userJson, User.class)); } Optional<User> optionalUser = userService.findById(id); if (optionalUser.isPresent()) { User user = optionalUser.get(); ops.set(key, JsonUtils.toJson(user), Duration.ofMinutes(30)); return ResponseEntity.ok(user); } return ResponseEntity.notFound().build(); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值