当前位置:网站首页>数据库优化方面的经验
数据库优化方面的经验
2022-06-09 21:57:00 【全能学长】
数据库优化方面的经验
1、 用PreparedStatement 一般来说比Statement性能高,而且可以防止SQL注入攻击
2、有外键约束会影响插入和删除性能,如果程序能够保证数据的完整性,那在设计数据库时就去掉外键。在大型电商中尽量使用单表
3、表中允许适当冗余,利用空间换时间,提高查询效率
4、用户名和密码单独从用户表中独立出来。 在登录业务中只需要查询用户名和密码。
5、使用索引。 select尽量不用*,即使查询全部字段也要尽量全部写出来 能用连接查询绝不用子查询,因为子查询的的底层就是连接查询
合理使用索引提升效率(索引的本质是提高效率的机制,本质上是一棵树) 为经常出现在where子句中的列创建索引 为经常出现在order
by,distinct中的字段建立索引
不要经常在DML(检索或修改)的表上建立索引(容易造成索引不准, 解决方法为rebuild重新建立,任何
DML操作都是更新index,这是代价)
不要在小表上简历索引(索引简历和维护也是要消耗资源的,小表上建立 索引会造成索引的维护时间大于数据查询时间)
限制表上的索引数目,索引并不是越多越好(索引会占用表空间,还要额 外的维护) 删除很少被使用的,不合理的索引
4、数据库数据量过大,数据库接近崩溃的时候怎么办?
1、索引优化和SQL语句优化是必须的,避免模糊查询和非索引查询,删改操作根据聚集索引进行,删改操作太频繁的话还是需要考虑分表
2、看需求,如果需求不限制,那就分表
3、一般都是把历史数据定期转存其他表(一样的表名后加年月例如TABLE201205)归档。这样该表本年度的查询的压力也小点(90%查询量集中在本年度),即使查询历史数据也不影响性能,强力推荐!
4结合你的业务去优化表结构。有时候可以考虑用空间去换时间。
边栏推荐
- 从内核代码了解SQL如何解析
- 中金证券开户怎么样?安全吗?开户
- 时间序列预测中使用类EMD方法时的信息泄露和计算量问题
- NFT及OpenSea交易背后的技术分享
- Metauniverse may replace the Internet as the mainstream lifestyle in the next decade or even two
- Gamefi's new departure, aquanee will log in to gate and bitmart on June 9
- [the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
- Rotation of AVL tree
- Bonner visual lens lcf08lk1f
- 【图像重建】基于正则化的图像超分辨重建附matlab代码
猜你喜欢

什么是“大安全”产业?数字化赋能大安全产业发展

化工企业双重预防体系数字化综合管理系统

lua学习笔记(4)-- 搭建mobdebug 远程开发环境

Rotation of AVL tree

Find my technology | in the era of Internet of things, apple find my realizes real intelligent loss prevention

房贷利率下调 现在是买房的时机吗?

Industrial Internet + Digital Integrated Management cloud platform for hazardous chemical safety production
![[filter] speech denoising based on time-varying Wiener filter, including Matlab source code](/img/77/de7c144ceece11cd2a799936287318.png)
[filter] speech denoising based on time-varying Wiener filter, including Matlab source code

汛期建筑施工现场安全生产风险智能防控

Actions before purchasing memory modules
随机推荐
The fourth paradigm chenyuqiang: the next generation technology of enterprise intelligent decision-making "reinforcement learning + environmental learning"
Digital integrated management system of double prevention system in chemical enterprises
Find My技术|物联网时代,苹果Find My实现真正的智能防丢
后疫情时代裸辞后面试软件测试工程师被拒,写下一些感悟和面试心得
C语言试题168之获取矩阵的最大值及其下标
Chez scheme environment setup
经典面试题:如何快速求解根号2?
【图像加密解密】基于混沌序列结合DWT+SVD实现图像加密解密(含相关性检验)含Matlab源码
ERC20协议API接口规范
Intelligent prevention and control of safety production risk at construction site in flood season
Digital supervision of construction sites and the wisdom of scientific warfare
使用addr2line分析Native Crash
sparksql源码系列 | 最全的logical plan优化规则整理(spark2.3)
Pi of C language test question 162
Industrial Internet + Digital Integrated Management cloud platform for hazardous chemical safety production
「ClickHouse系列」ClickHouse的优化之Block+LSM
Technology sharing behind NFT and opensea transactions
M-Arch(雅特力M4)【AT-START-F425测评】No.06 驱动段码LCD
Integer reverse output of C language test question 166
npm和yarn