bitsCN.com
RDBMS之父Codd于1970年代初提出范式,其出发点是为了减少数据库中数据冗余,增进数据的一致性。但冗余是奢侈的,因为那个年代的存储空间极其昂贵。理解完这一背景并对范式的持续深入后,目的是为了能更好地利用及打破规范和标准。毕竟范式带来了一些问题:
● 紧耦合,表之间表现为强依赖,在业务高速增长后,将导致拆分的老大难问题
深谙范式招数之后,必然是发现招数的局限性,要么忘掉招数,要么自创招数,这就有了反范式
如果说优化器为大脑,存储引擎为手脚,MySQL的大脑目前弱了点,当遇到一些子查询或较为复杂的Join时,很容易头脑短路,表现为错误的驱动表、槽糕的执行计划...等。范式化设计的Schema的缺点如上所述,是通常需要Join成本,而反范式化的Schema因为所有数据都在一张表中,可以很好地避免Join。那么,要减少Join最直接有效的方式就是通过表字段的冗余来实现。而冗余具体该如何实现呢?下面给出几种实现方式:
① 基于静态数据的冗余
基于谓词的冗余
基于聚会函数的冗余
基于排序的冗余
但是增加冗余,必然会牺牲部分数据的一致性。我们有必要对数据一致性问题区分优先级。对用户伤害不大,用户并不是太关心的数据,这是可容忍的。而那些致命又敏感的数据,我们需要在应用层处理,比如作二次校验,定期抽样检查,至于这会不会是个问题,需要权衡写查询的频率与读查询频率。
反范式设计的第二个优势是,因为相关列都位于同一张表里,这也能更有效地制定健壮的索引策略,也就是,在反范式中,更强调索引,而弱化外键。假设有个影视娱乐网站,现想查看最近发布的10部美国大片,范式化后查询也许是这样的:
mysql > SELECT title,actor_name -> FROM film -> INNER JOIN actor ON film.actor_id=actor.id -> WHERE actor.area='AMERICA' -> ORDER BY film.published DESC LIMIT 10;
mysql > SELECT title,actor_name -> FROM actor_film -> WHERE area='AMERICA' -> ORDER BY film.published DESC LIMIT 10;
By 迦叶
2014-1-14
Good Luck!
bitsCN.com
MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
