notebook
  • coding
    • 2016/11/03_sql optimization principle
    • 2017/08/19_docker for gitlab install
    • 2018/02/15_dotnet core
    • 2018/06/16_vs key
    • 2018/09/12_network protocol
    • 2018/10/23_Distributed service framework
    • 2018/10/24_knowledge
    • 2018/11/03_environment deployment
    • 2018/11/23_release nuget package
    • 2018/12/04_free https
    • 2020/04/29_EFmigrationCmdLine
    • 2020/12/18_push docker image to aws
    • 2022/12/16_HttpClient-multipart
    • 2023/02/17_postgresSql-function
    • 2023/03/09_dockerImages_deploy
    • 2023/04/08_word-helper
    • 2023/11/08_tableAndRowLock
  • living
  • playing
Powered by GitBook
On this page

Was this helpful?

  1. coding

2016/11/03_sql optimization principle

表设计时的优化

  • 字段设计时使用not null

  • 大表按业务需求拆分成小表 比如说时间

  • 字段尽量设计为定长

索引优化

  • 经常在where子句使用的列,设置索引

  • 多个列where或者order by子句的,建立复合索引

  • 可以限制数据量最小的索引,放在where条件的最左边

  • 当子查询比较耗时或数据量大时,为了减少扫描数据,建议把母查询的条件为赋予子查询

语句优化(慢查询优化)

  • 使用explain和profile分析查询语句

  • 查看慢查询日志

  • 千万级分页时使用limit

  • 不要select *

  • 多表连接时 小表join大表

  • 经常使用的查询,可以开启缓存

  • 不要使用not in和<>操作

PreviouscodingNext2017/08/19_docker for gitlab install

Last updated 1 year ago

Was this helpful?