MySQL高级-SQL优化-小结

文章目录

  • [1、insert 优化](#1、insert 优化)
  • 2、主键优化
  • [3、order by 优化](#3、order by 优化)
  • [4、group by 优化](#4、group by 优化)
  • [5、limit 优化](#5、limit 优化)
  • [6、count 优化](#6、count 优化)
  • [7、update 优化](#7、update 优化)

1、insert 优化

insert:批量插入、手动控制事务、主键顺序插入
大批量插入:load data local infile

2、主键优化

主键长度尽量短、顺序插入 auto_increment

3、order by 优化

using index:直接通过索引返回数据,性能高
using filesort:需要将返回的结果在排序缓冲区排序

4、group by 优化

索引,多字段分组满足最左前缀法则

5、limit 优化

覆盖索引 + 子查询

6、count 优化

性能:count(字段)< count(主键id)< count(1)约等于 count(*)

7、update 优化

尽量根据主键/索引字段进行数据更新

相关推荐
火柴就是我5 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
阿里云大数据AI技术6 小时前
用 SQL 调大模型?Hologres + 百炼,让数据开发直接“对话”AI
sql·llm
砖厂小工12 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心13 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心13 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker15 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴15 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95272 天前
Andorid Google 登录接入文档
android