当前位置:网站首页>如果某个表有近千万数据,CRUD比较慢,如何优化
如果某个表有近千万数据,CRUD比较慢,如何优化
2022-07-27 22:27:00 【橘子ꦿ.๓】
1.数据库优化,表结构优化
.数据类型选择:选用合适的数据结构。什么叫做"合适的数据结构",比如性别字段,M表示男F表示女,那么一个 char(1) 就足够了,如果存储人的年龄,那么就没有必要使用 INT 这么大范围的字段了;
.适当拆分:不要把所有的字段放在一个表中,会影响性能,一张表的字段不超过30个
.适当的冗余:如果一些常用的字段,可能会用在不同的维度,那么我们可以把这些字段设计在多张表中,因为这样可能会减少表关联;
.字段尽量设置not Null,带有默认值
2.SQL语句优化
。尽量使用索引,尽量避免全表扫描,提高查询速度
查询语句当中包含有 MAX (), MIN () 和 ORDERBY 这些命令的时候,性能提高更为明显。
索引应建立在那些将用于 JOIN, WHERE 判断和 ORDER BY 排序的字段上。
尽量不要对数据库中某个含有大量重复的值的字段建立索引。
。不能建立多个索引,维护索引也会影响查询速度,降低数据库性能
。SQL语句的不规范也会使索引失效
。条件多的时候,不使用in和not in
。查询的时候,使用具体字段代替*
。不要再where语句对字段进行Null判断
3.减少数据库的访问
。可以通过本地缓存或分布式缓存的方式,将热点数据储存到缓存中,减少数据库访问
4.读写分离
。主库用于写,从库用于读,将读写分散在不同的数据库上,利用多台机器的资源,提高数据库的可用性和性能
边栏推荐
猜你喜欢

Buildforge materials

Branch and loop sentence exercises

激活最大化
![[BuildRelease Management]Parabuild](/img/80/11c2b539c217ecd6ba55668d3e71e9.png)
[BuildRelease Management]Parabuild

The most detailed summary of common English terms in the chip industry (quick grasp of graphics and text)

Map set
![Jerry, if you turn on Bluetooth again, one for two. When the mobile phone is connected to the prototype, it will appear and cannot be connected [chapter]](/img/6c/d4a45981a7fc87f6a82a91017f8ce8.png)
Jerry, if you turn on Bluetooth again, one for two. When the mobile phone is connected to the prototype, it will appear and cannot be connected [chapter]

iperf安装与使用

Postman download and use tutorial

红队大杀器 Behinder_v4.0(冰蝎4.0)
随机推荐
推荐系统-模型:wide&deep 模型
[BuildRelease Management]Parabuild
Jmeter在性能测试中的应用实践样例
Network equipment hard core technology insider firewall and security gateway (11) secrets of zero contact office
Jointly create a new chapter in cultural tourism | xinqidian signs a strategic cooperation agreement with Guohua cultural tourism
Basic operations of MySQL database (3) --- Based on fields
芯片行业常用英文术语最详细总结(图文快速掌握)
0-1背包问题
Ddt+yaml implementation of data driven mechanism based on unittest
MySQL中的运算符
MySQL limit usage and large paging problem solving
网络设备硬核技术内幕 防火墙与安全网关篇 (十二) 零接触办公的奥秘 下
Recurrence of fastjson historical vulnerabilities
Can TSMC Samsung build a production line without American equipment for Huawei?
Volkswagen China invested 8billion yuan and became the largest shareholder of GuoXuan high tech
估值360亿美元!即将进行首次载人发射的SpaceX筹资3.46亿美元
Jerry Zhi doesn't play hidden audio files [article]
加拿大法院认定孟晚舟“双重犯罪”成立,引渡程序将继续进行!
数组相关知识
Process and process scheduling