当前位置:网站首页>为啥禁用外键约束
为啥禁用外键约束
2022-04-23 15:37:00 【dengk2013】
【阿里JAVA规范】 :不得使用外键与级联,一切外键概念必须在应用层解决
阿里巴巴为什么这么规定?
1.每次做DELETE 或者UPDATE都必须考虑外键约束,会导致开发的时候很痛苦,测试数据极为不方便,也就是说插入一条主记录的时候,这个时候主记录对应的外键,也必须删除或者更新,再比如一个测试员在做压力测试入库1000W数据,那么同时对应的外键记录表也要入库1000W,也就需要造2000W数据,增加工作量
2.性能问题:对于包含主键表的记录,需要入库2张表
3.并发问题:外键约束会启用行级锁 主表写入时会进入阻塞,比如订单明细表和订单总额表存在外键,当增加订单明细表的时候,但是订单总额表写操作没有完成就会导致明细表发生阻塞,线程一直积压导致mysql崩溃。
4.级联删除问题:多层级联删除会让数据变得不可控 ;触发器也严格被禁用
5.数据耦合:数据库层面数据关系产生耦合 数据迁移维护困难


6.如果mysql的数据达到100亿以上,此时需要数据迁移,比如迁移到hbase,由于hbase没有主外键的关系,程序中并没有主外键关系的检查,就不能保证迁移过程中保证数据一致性
版权声明
本文为[dengk2013]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u012222011/article/details/124340571
边栏推荐
- Cookie&Session
- kubernetes之常用Pod控制器的使用
- X509 certificate cer format to PEM format
- What is CNAs certification? What are the software evaluation centers recognized by CNAs?
- 怎么看基金是不是reits,通过银行购买基金安全吗
- PHP 的运算符
- Squid agent
- Knn,Kmeans和GMM
- 【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
- Basic concepts of website construction and management
猜你喜欢

Byte interview programming question: the minimum number of K

Today's sleep quality record 76 points

T2 icloud calendar cannot be synchronized

The wechat applet optimizes the native request through the promise of ES6

Sorting and replying to questions related to transformer

Cookie&Session

How to design a good API interface?

Sword finger offer (1) -- for Huawei

大厂技术实现 | 行业解决方案系列教程

一刷314-剑指 Offer 09. 用两个栈实现队列(e)
随机推荐
The El tree implementation only displays a certain level of check boxes and selects radio
Educational Codeforces Round 127 A-E题解
Go语言切片,范围,集合
My raspberry PI zero 2W toss notes to record some problems and solutions
kubernetes之常用Pod控制器的使用
字符串最后一个单词的长度
Mysql database explanation (IX)
自主作业智慧农场创新论坛
移动app测试如何进行?
Elk installation
PHP classes and objects
MySQL installation process (steps for successful installation)
Wechat applet customer service access to send and receive messages
shell脚本中的DATE日期计算
Special analysis of China's digital technology in 2022
Openstack theoretical knowledge
函数(第一部分)
Recommended search common evaluation indicators
What if the package cannot be found
CVPR 2022 优质论文分享