鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛
Posted Golang鍦ㄥ彂鍏?/a>
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛相关的知识,希望对你有一定的参考价值。
鐐瑰嚮鈥?/span>Golang鍦ㄥ彂鍏?/span>鈥濓紝閫夋嫨鈥滄槦鏍囸煍濃€?/span>
鐐瑰嚮鏂囨湯鈥?/span>闃呰鍘熸枃鈥濊В閿佽祫鏂欙紒
鐢变簬椤圭洰闇€瑕佸瓨鍌ㄤ竴浜涙棤缁撴瀯鐨勬暟鎹? 杩欎簺鏁版嵁涓昏浠ユ枃鏈负涓? 鍚屾椂杩橀渶鏀寔涓€浜涙枃鏈垎鏋? 鍜嬩竴鍚技涔嶦S鏄竴涓笉閿欑殑閫夋嫨, 浣嗘槸杩欎簺鏃犵粨鏋勭殑鏁版嵁鍚屾椂涔熼渶瑕佽绠$悊, 涔熷氨鏄繖浜涙暟鎹彲鑳界粡甯稿彉鏇? 琛¢噺鍐嶄笁, 鏈€鍚庤繕鏄€夋嫨浜哅ongo, 姣曠珶鐜伴樁娈垫槸浠ユ暟鎹殑瀛樺偍鍜岀鐞嗕负涓? 鍒嗘瀽骞舵病鏈夐偅涔堝己鐨勯渶姹傘€傛暣绡囨枃绔犱互澶ф暟鎹瓨鍌ㄩ棶棰樹负寮? 涓€姝ユ寮曞嚭NoSQL棰嗗煙鏂囨。鏁版嵁鐨勪唬琛∕ongoDB銆?/p>
E.F.Codd鍦?970骞撮娆℃彁鍑轰簡鏁版嵁搴撶郴缁熺殑鍏崇郴妯″瀷锛屼粠姝ゅ紑鍒涗簡鏁版嵁搴撳叧绯绘柟娉曞拰鍏崇郴鏁版嵁鐞嗚鐨勭爺绌讹紝涓烘暟鎹簱鎶€鏈瀹氫簡鐞嗚鍩虹锛屾暟鎹簱鎶€鏈篃寮€濮嬭摤鍕冨彂灞曘€傝€岄殢鐫€鍑犲ぇ鏁版嵁搴撳巶鍟嗛檰缁彂甯冪殑鍟嗕笟鏁版嵁搴撶鐞嗙郴缁熷嚑涔庨兘鏀寔鍏崇郴鏁版嵁妯″瀷锛屾暟鎹簱鎶€鏈€愭笎缁熶竴鍒颁互鍏崇郴鍨嬫暟鎹簱涓轰富瀵笺€傚叧绯绘ā鍨嬫湁鎵庡疄鐨勬暟瀛︾悊璁哄仛鍩虹, 骞朵笖缁忚繃闀挎椂闂寸殑瀹炶返, 浣垮緱鍏跺湪鏁版嵁瀛樺偍涓庣鐞嗛鍩熷崰鎹粺娌诲湴浣嶃€?/p>
2001骞村悗锛屼簰鑱旂綉鎶€鏈繀閫熷彂灞曪紝鏁版嵁閲忚繀閫熻啫鑳€骞跺苟澶э紝浜虹被閫愭杩涘叆澶ф暟鎹椂浠c€傚ぇ鏁版嵁缁欎紶缁熺殑鏁版嵁绠$悊鏂瑰紡甯︽潵浜嗕弗宄荤殑鎸戞垬锛屽叧绯诲瀷鏁版嵁搴撳湪瀹归噺锛屾€ц兘锛屾垚鏈瓑澶氭柟闈㈤兘闅句互婊¤冻澶ф暟鎹鐞嗙殑闇€姹傘€侼oSQL鏁版嵁搴撻€氳繃鎶樹腑鍏崇郴鍨嬫暟鎹簱涓ユ牸鐨勬暟鎹竴鑷存€х鐞嗭紝鍦ㄥ彲鎵╁睍鎬с€佹ā鍨嬬伒娲绘€с€佺粡娴庢€у拰璁块棶鎬х瓑鏂归潰鑾峰緱浜嗗緢澶х殑浼樺娍锛屽彲浠ユ洿濂藉湴閫傚簲澶ф暟鎹簲鐢ㄧ殑闇€姹傦紝鎴愪负澶ф暟鎹椂浠f渶閲嶈鐨勬暟鎹鐞嗘妧鏈€?/p>
鍥寸粫澶ф暟鎹殑瀛樺偍闂, 鎴戜滑渚濇璁ㄨ涓嬫暟鎹簱鐨勫嚑澶у垎绫? RDBMS, NewSQL, NoSQL銆?/p>
1.1 RDBMS
鍦ㄧ幇浠g殑璁$畻绯荤粺涓婃瘡澶╃綉缁滀笂閮戒細浜х敓搴炲ぇ鐨勬暟鎹噺銆傝繖浜涙暟鎹湁寰堝ぇ涓€閮ㄥ垎鏄敱鍏崇郴鏁版嵁搴撶鐞嗙郴缁?RDMBSs)鏉ュ鐞嗐€?970骞?E.F.Codd鈥檚鎻愬嚭鐨勫叧绯绘ā鍨嬬殑璁烘枃 鈥淎 relational model of data for large shared data banks鈥濓紝杩欎娇寰楁暟鎹缓妯″拰搴旂敤绋嬪簭缂栫▼鏇村姞绠€鍗曘€?br>閫氳繃搴旂敤瀹炶返璇佹槑锛屽叧绯绘ā鍨嬫槸闈炲父閫傚悎浜庡鎴锋湇鍔″櫒缂栫▼锛岃繙杩滆秴鍑洪鏈熺殑鍒╃泭锛屼粖澶╁畠鏄粨鏋勫寲鏁版嵁瀛樺偍鍦ㄧ綉缁滃拰鍟嗗姟搴旂敤鐨勪富瀵兼妧鏈€?/p>
浠€涔堟槸RDBMS锛?/strong>
RDBMS鍏ㄧО鏄?code class="mq-30">Relational Database Management System, 鍙婂叧绯诲瀷鏁版嵁绠$悊绯荤粺, 浠栭噰鐢ㄥ叧绯绘ā鍨嬫潵瀛樺偍鏁版嵁,鍏崇郴妯″瀷鏄妸澶嶆潅鐨勬暟鎹粨鏋勫綊缁撲负绠€鍗曠殑浜屽厓鍏崇郴(鍗充簩缁磋〃鏍煎舰寮?, 鍦ㄥ叧绯诲瀷鏁版嵁搴撲腑锛屽鏁版嵁鐨勬搷浣滃嚑涔庡叏閮ㄥ缓绔嬪湪涓€涓垨澶氫釜鍏崇郴琛ㄦ牸涓婏紝閫氳繃瀵硅繖浜涘叧鑱旂殑琛ㄦ牸鍒嗙被銆佸悎骞躲€佽繛鎺ユ垨閫夊彇绛夎繍绠楁潵瀹炵幇鏁版嵁搴撶殑绠$悊銆?/p>
鍏崇郴鍨嬫暟鎹殑鐗圭偣(ACID)
鍏崇郴鍨嬫暟鎹簱閬靛惊ACID瑙勫垯, 涔熷氨鏄垜浠父璇寸殑浜嬬墿妯″瀷(transaction), 浜嬬墿杩欎釜姒傚康鍜岀幇瀹炰笘鐣屼腑鐨勪氦鏄撳緢绫讳技, 瀹冩湁濡備笅4涓壒鎬?
A(Atomicity)
鍘熷瓙鎬у緢瀹规槗鐞嗚В锛屼篃灏辨槸璇翠簨鍔¢噷鐨勬墍鏈夋搷浣滆涔堝叏閮ㄥ仛瀹岋紝瑕佷箞閮戒笉鍋氾紝浜嬪姟鎴愬姛鐨勬潯浠舵槸浜嬪姟閲岀殑鎵€鏈夋搷浣滈兘鎴愬姛锛屽彧瑕佹湁涓€涓搷浣滃け璐ワ紝鏁翠釜浜嬪姟灏卞け璐ワ紝闇€瑕佸洖婊氥€?br>姣斿閾惰杞处锛屼粠A璐︽埛杞?00鍏冭嚦B璐︽埛锛屽垎涓轰袱涓楠わ細1锛変粠A璐︽埛鍙?00鍏冿紱2锛夊瓨鍏?00鍏冭嚦B璐︽埛銆傝繖涓ゆ瑕佷箞涓€璧峰畬鎴愶紝瑕佷箞涓€璧蜂笉瀹屾垚锛屽鏋滃彧瀹屾垚绗竴姝ワ紝绗簩姝ュけ璐ワ紝閽变細鑾悕鍏跺灏戜簡100鍏冦€?/p>C(Consistency)
涓€鑷存€т篃姣旇緝瀹规槗鐞嗚В锛屼篃灏辨槸璇存暟鎹簱瑕佷竴鐩村浜庝竴鑷寸殑鐘舵€侊紝浜嬪姟鐨勮繍琛屼笉浼氭敼鍙樻暟鎹簱鍘熸湰鐨勪竴鑷存€х害鏉熴€?br>渚嬪鐜版湁瀹屾暣鎬х害鏉焌+b=10锛屽鏋滀竴涓簨鍔℃敼鍙樹簡a锛岄偅涔堝繀椤诲緱鏀瑰彉b锛屼娇寰椾簨鍔$粨鏉熷悗渚濈劧婊¤冻a+b=10锛屽惁鍒欎簨鍔″け璐ャ€?/p>I(Isolation)
鎵€璋撶殑鐙珛鎬ф槸鎸囧苟鍙戠殑浜嬪姟涔嬮棿涓嶄細浜掔浉褰卞搷锛屽鏋滀竴涓簨鍔¤璁块棶鐨勬暟鎹鍦ㄨ鍙﹀涓€涓簨鍔′慨鏀癸紝鍙鍙﹀涓€涓簨鍔℃湭鎻愪氦锛屽畠鎵€璁块棶鐨勬暟鎹氨涓嶅彈鏈彁浜や簨鍔$殑褰卞搷銆?br>姣斿鐜版湁鏈変釜浜ゆ槗鏄粠A璐︽埛杞?00鍏冭嚦B璐︽埛锛屽湪杩欎釜浜ゆ槗杩樻湭瀹屾垚鐨勬儏鍐典笅锛屽鏋滄鏃禕鏌ヨ鑷繁鐨勮处鎴凤紝鏄湅涓嶅埌鏂板鍔犵殑100鍏冪殑銆?/p>D(Durability)
鎸佷箙鎬ф槸鎸囦竴鏃︿簨鍔℃彁浜ゅ悗锛屽畠鎵€鍋氱殑淇敼灏嗕細姘镐箙鐨勪繚瀛樺湪鏁版嵁搴撲笂锛屽嵆浣垮嚭鐜板畷鏈轰篃涓嶄細涓㈠け銆?br>姣斿A璐︽埛鏀跺埌浜?00鍏冨埌璐? 鍙鍒拌处杩欎釜浜嬬墿瀹屾垚, 鏁版嵁灏卞凡缁忓埌鏁版嵁搴撻噷闈簡, 鍗充娇姝ゆ椂瀹曟満瀵笰鐢ㄦ埛鐨勮祫浜т篃娌℃湁褰卞搷銆?/p>
鍏稿瀷鐨勪骇鍝?/strong>
鍏崇郴鍨嬫暟鎹簱璇炵敓40澶氬勾浜嗭紝浠庣悊璁轰骇鐢熷彂灞曞埌鐜板疄浜у搧, RDBMS寰堝浜у搧搴旇閮芥槸鑰崇啛鑳借鐨?
Oracle
PostgreSQL
SQLServer
澶ф暟鎹瓨鍌ㄦ椂闈复鐨勯棶棰?/strong>
鍏崇郴鍨嬫暟鎹簱涓ユ牸ACID鍘熷垯, 鍥犳鍦ㄦ墿灞曟€т笂琛ㄧ幇涓嶆槸鐗瑰埆濂? 闈㈠澶ц妯$殑鏁版嵁鏃? 鍦ㄨ鍜屽啓涓婇潰浼氬嚭鐜颁弗閲嶇摱棰堛€傛兂瑕佹彁鍗囧叾鎬ц兘, 寰€寰€闇€瑕佷粠涓氬姟灞傝繘琛屽鐞? 杩涜鏁版嵁鐨凷harding銆?br>sharding鏈?涓淮搴? 姘村钩鍒囧垎鍜屽瀭鐩村垏鍒?
姘村钩鍒囧垎: 鏍规嵁琛ㄤ腑鐨勬暟鎹殑閫昏緫鍏崇郴锛屽皢鍚屼竴寮犺〃鐨勬暟鎹紝鎸夌収鏌愮鏉′欢鍒囧垎鍒颁笉鍚岀殑鏁版嵁搴撲富鏈轰笂
鍨傜洿鍒囧垎: 鎸夌収涓嶅悓鐨勮〃鎴栬€卻chema锛屾潵鍒囧垎鍒颁笉鍚岀殑鏁版嵁搴撲富鏈轰笂
鍒囩墖(sharding)浼氬鍔犳暣涓郴缁熺殑澶嶆潅鎬э紝鑰屼笖鍒囩墖鏈韩涔熸槸涓€涓緢澶嶆潅鐨勮繃绋嬶紝涓庡簲鐢ㄦ湰韬湁杩欏瘑鍒囩殑鍏崇郴锛屾墍浠ュ浜庝笉浣嗗澶х殑鏁版嵁鑰岃█锛屽垏鐗囧苟涓嶈兘浠庢牴鏈笂瑙e喅澶ф暟鎹瓨鍌ㄩ棶棰樸€?/p>
1.2 NewSQL
浼犵粺鐨勫叧绯诲瀷鏁版嵁鎯宠鍋氬埌楂樻墿灞? 楂樻€ц兘, 楂樺彲闈犳€ф槸寰堝鏉傜殑, 浣嗘槸褰撲綘鐨勭‘鎯宠涓€绉嶈繖绉嶆牱鐨勬暟鎹簱鏃? NewSQL鍙兘鏄綘涓€绉嶄笉閿欑殑閫夋嫨銆?/p>
浠€涔堟槸NewSQL锛?/strong>
杩欐槸涓€涓腑闂翠骇鐗? 鏄竴绉嶅畬鍏ㄤ笉鍚岀殑鏁版嵁搴撴灦鏋? NewSQL鏈鏈€鏃╁湪2011骞寸敱Matthew Aslett鍒涢€? NewSQL鐨勮璁$珛瓒充簬浼犵粺鐨勫叧绯诲瀷鏁版嵁搴擄紝浣嗘槸鍚屾椂涔熷紩杩涗竴浜涙柊鎶€鏈紝浠庤€岃揪鍒板彲鎵╁睍鍜岄珮鎬ц兘鐨勭洰鐨? 鑰岀己鐐规槸娌℃湁鎻愪緵寮轰竴鑷存€? 瀹冧滑涓嶅彲浠ヨ浣跨敤鍦ㄥ己涓€鑷存€х幆澧冧笅銆?br>NewSQL鍏锋湁NoSQL鐨勬捣閲忔暟鎹瓨鍌ㄧ鐞嗚兘鍔?鍚屾椂杩樻敮鎸佷紶缁熸暟鎹簱鐨凙CID鍜孲QL鑳藉姏(鍗曚釜鑺傜偣涓婄殑ACID鑳藉姏), 浣嗘槸鍦ㄧ幇瀹炰娇鐢ㄤ腑杩樻病鏅強寮€鏉? 杩樻病琚ぇ瑙勬ā浣跨敤銆?/p>
NewSQL鐨勭壒鐐?/span>
NewSQL鍏蜂綋鍜孯DBMS涓€鏍风殑鍗曚釜鑺傜偣涓婄殑ACID鑳藉姏, 鍚屾椂鍙堝叿鏈塏oSQL涓€鏍风殑寰堝己鐨勬墿灞曡兘鍔?瀹冨湪鏁翠釜闆嗙兢涓婇伒寰狟ASE瑙勫垯, 鍏充簬BASE鍦ㄥ悗闈oSQL涓啀鍋氫粙缁?銆?/p>
鍏稿瀷鐨凬ewSQL浜у搧
鎴戣縿浠婁篃娌℃湁浣跨敤杩嘚ewSQL浜у搧, 浠ヤ笅鏄垜鎵€鐭ョ殑鍏充簬NewSQL鐨勭粡鍏镐骇鍝?
Google spanner: Google鐨勫叏鐞冪骇鐨勫垎甯冨紡鏁版嵁搴?Globally-Distributed Database)
CockroachDB: 鍙傝€僄oole spanner瀹炵幇鐨勫紑婧愮増
濡備綍瑙e喅澶ф暟鎹瓨鍌ㄩ棶棰橈紵
NewSQL鍩轰簬NoSQL鐨凚ASE鍘熷垯, 鏋勫缓鍙互妯悜鎵╁睍鐨勫垎甯冨紡绯荤粺鏉ヨВ鍐冲ぇ鏁版嵁鐨勫瓨鍌ㄥ拰绠$悊闂銆?/p>
1.3 NoSQL
浠婂ぉ鎴戜滑鍙互閫氳繃绗笁鏂瑰钩鍙?濡傦細Google,Facebook绛?, 鍙互寰堝鏄撶殑璁块棶鍜屾姄鍙栨暟鎹€傜敤鎴风殑涓汉淇℃伅锛岀ぞ浜ょ綉缁滐紝鍦扮悊浣嶇疆锛岀敤鎴风敓鎴愮殑鏁版嵁鍜岀敤鎴锋搷浣滄棩蹇楀凡缁忔垚鍊嶇殑澧炲姞銆傛垜浠鏋滆瀵硅繖浜涚敤鎴锋暟鎹繘琛屾寲鎺橈紝閭QL鏁版嵁搴撳凡缁忎笉閫傚悎杩欎簺搴旂敤浜? NoSQL鏁版嵁搴撶殑鍙戝睍涔熷嵈鑳藉緢濂界殑澶勭悊杩欎簺澶х殑鏁版嵁銆?/p>
浠€涔堟槸NoSQL锛?/strong>
NoSQL(NoSQL = Not Only SQL)锛屾剰鍗斥€滀笉浠呬粎鏄疭QL鈥濓紝鏄竴椤瑰叏鏂扮殑鏁版嵁搴撻潻鍛芥€ц繍鍔紝鏃╂湡灏辨湁浜烘彁鍑猴紝鍙戝睍鑷?009骞磋秼鍔胯秺鍙戦珮娑ㄣ€侼oSQL鐨勬嫢鎶よ€呬滑鎻愬€¤繍鐢ㄩ潪鍏崇郴鍨嬬殑鏁版嵁瀛樺偍锛岀浉瀵逛簬閾哄ぉ鐩栧湴鐨勫叧绯诲瀷鏁版嵁搴撹繍鐢紝杩欎竴姒傚康鏃犵枒鏄竴绉嶅叏鏂扮殑鎬濈淮鐨勬敞鍏?/p>
NoSQL鐨勭壒鐐?BASE)
BASE鐨勫叏绉版槸Basically Available, Soft-state, Eventually Consistent銆傜敱Eric Brewer
瀹氫箟銆侫CID寮鸿皟寮轰竴鑷存€?CAP涓殑C), 鑰孊ASE鍒欏己璋冨熀鏈彲鐢ㄦ€?CAP涓殑A锛夛紝鍦˙ASE鎬濇兂鐨勬墿灞曚笅锛屽氨鍑虹幇浜哊oSQL銆?br>BASE鏄疦oSQL鏁版嵁搴撻€氬父瀵瑰彲鐢ㄦ€у強涓€鑷存€х殑寮辫姹傚師鍒?
Basically Availble: 鍩烘湰鍙敤
Soft-state: 杞姸鎬?鏌旀€т簨鍔°€傗€淪oft state鈥?鍙互鐞嗚В涓衡€濇棤杩炴帴鈥濈殑, 鑰?鈥淗ard state鈥?鏄€濋潰鍚戣繛鎺モ€濈殑
Eventual Consistency: 鏈€缁堜竴鑷存€?鏈€缁堜竴鑷存€э紝 涔熸槸鏄?ACID 鐨勬渶缁堢洰鐨勩€?/p>
BASE鏄浉瀵笰CID鑰岃█鐨? 涓嬮潰鏄姣旇〃:
鍏稿瀷鐨凬oSQL浜у搧
NoSQL鏄疄鐜版柟寮忓悇涓嶇浉鍚岋紝涓嬮潰涓昏浠嬬粛 涓绘祦鐨凬oSQL娴佹淳, 鎯宠浜嗚В鏇村叿浣撶殑淇℃伅璇风偣鍑诲叧浜庢墍鏈塏oSQL浠嬬粛鐨勪竴涓綉绔?
鍒楀紡鏁版嵁妯″瀷
鏁版嵁妯″瀷锛氱湅鍒颁篃鏄〃, 浣嗘槸涓嶆敮鎸侀摼鎺ユ煡璇? 鍥犱负鏁版嵁瀛樺偍浠ュ垪涓哄崟浣?column), 鑰屽叧绯绘暟鎹簱鏄互琛屼负瀛樺偍鍗曚綅鐨?br>搴旂敤鍦烘櫙锛氬湪鍒嗗竷寮忔枃浠剁郴缁熶箣涓婃彁渚涙敮鎸侀殢鏈鸿鍐欑殑鍒嗗竷寮忔暟鎹瓨鍌?br>鍏稿瀷浜у搧锛欻base銆?Hypertable銆?Bigtable銆?Cassandra
浼樼偣锛氬揩閫熸煡璇€?楂樻墿灞曟€с€佹槗浜庡疄鐜板垎甯冨紡鎵╁睍鏂囨。鏁版嵁妯″瀷 锛?br>鏁版嵁妯″瀷锛氫粙浜庨敭鍊煎瓨鍌╧v)鍜屽叧绯诲瀷瀛樺偍(row),姣忎竴琛屾暟鎹粍缁囦负涓€涓枃妗? 浠ユ枃妗d负瀛樺偍鍗曚綅
搴旂敤鍦烘櫙锛氶潪寮轰簨鐗╅渶姹傜殑web搴旂敤
鍏稿瀷浜у搧锛歁ongoDB銆?ElasticSearch(寮规€ф悳绱紝瀛樺偍web鏃ュ織)
浼樼偣锛氥€€鏁版嵁妯″瀷鏃犻渶浜嬪厛瀹氫箟閿€兼暟鎹ā鍨?锛?br>鏁版嵁妯″瀷锛氭ā鍨嬬畝鍗? 鏄撲簬瀹炵幇, 鎿嶄綔绠€鍗?get set del)
搴旂敤鍦烘櫙锛氬唴瀹圭紦瀛? 鐢ㄤ簬澶ч噺骞惰鏁版嵁璁块棶, 楂樿礋杞藉満鏅?br>搴旂敤浜у搧锛欴ynamoDB, Riak, Redis
浼樼偣锛歨ash鐨勪紭鐐癸紝 鏌ヨ杩呴€?/p>鍥惧紡鏁版嵁妯″瀷 锛?br>鏁版嵁妯″瀷锛氬浘寮忕粨鏋?br>搴旂敤鍦烘櫙锛氱ぞ浜ょ綉缁溿€?鎺ㄨ崘绯荤粺銆?鍏崇郴鍥捐氨
鍏稿瀷浜у搧锛歂eo4J
浼樼偣锛氶€傜敤浜庡浘寮忔妧鏈満鏅?/p>
濡備綍瑙e喅澶ф暟鎹瓨鍌ㄩ棶棰橈紵
閫氳繃鍒嗗竷寮忚В鍐?/p>
1.4 RDBMS vs NoSQL
RDBMS鐨勭壒鐐?
楂樺害缁勭粐鍖栫粨鏋勫寲鏁版嵁
缁撴瀯鍖栨煡璇㈣瑷€
鏁版嵁鍜屽叧绯婚兘瀛樺偍鍦ㄥ崟鐙殑琛ㄤ腑銆?/p>
鏁版嵁鎿嶇旱璇█锛屾暟鎹畾涔夎瑷€
涓ユ牸鐨勪竴鑷存€?/p>
鍩轰簬浜嬪姟
NoSQL鐨勭壒鐐?
浠h〃鐫€涓嶄粎浠呮槸SQL
娌℃湁澹版槑鎬ф煡璇㈣瑷€
娌℃湁棰勫畾涔夌殑妯″紡, 鏋舵瀯鐨勭伒娲绘€э紝鏀寔鍗婄粨鏋勫寲鏁版嵁
閿€煎瀛樺偍锛屽垪瀛樺偍锛屾枃妗e瓨鍌紝鍥惧舰鏁版嵁搴?/p>
鏈€缁堜竴鑷存€э紝鑰岄潪ACID灞炴€?/p>
闈炵粨鏋勫寲鍜屼笉鍙鐭ョ殑鏁版嵁
鍒嗗竷寮忚绠? CAP瀹氱悊
楂樻€ц兘锛岄珮鍙敤鎬у拰鍙几缂╂€? 楂樻按骞虫墿灞曡兘鍔涘拰浣庢垚鏈殑浣庣纭欢闆嗙兢
鍔熻兘鐩稿绠€鍗? 娌℃湁缁熶竴鐨勬煡璇㈣瑷€, 鏈夐檺鐨勬煡璇㈠姛鑳?/p>
鏈€缁堜竴鑷存槸涓嶇洿瑙傜殑绋嬪簭
瀵逛簬鏁版嵁鏈韩鑰岃█, 鎴戜滑寰€寰€灏嗗叾鍒嗕负缁撴瀯鍖栨暟鎹? 鍗婄粨鏋勫寲鏁版嵁, 浠ュ強闈炵粨鏋勫寲鏁版嵁, 浣嗘槸瀵逛簬鍌ㄥ瓨鏃舵暟鎹殑缁勭粐鎴戜滑鎵嶇О鍏朵负鏁版嵁妯″瀷, 甯歌鐨勬暟鎹ā鍨嬫湁: 鍏崇郴妯″瀷, 鏂囨。妯″瀷, 鍋ュ€兼ā鍨? 浠ュ強鍒楀紡妯″紡銆?/p>
2.1 鐢ㄦ埛渚ф暟鎹?/h3>
闅忕潃缃戠粶鎶€鏈殑鍙戝睍锛岀壒鍒槸Internet鍜孖ntranet鎶€鏈殑椋炲揩鍙戝睍锛屼娇寰楅潪缁撴瀯鍖栨暟鎹殑鏁伴噺鏃ヨ秼澧炲ぇ銆傝繖鏃讹紝涓昏鐢ㄤ簬绠$悊缁撴瀯鍖栨暟鎹殑鍏崇郴鏁版嵁搴撶殑灞€闄愭€ф毚闇插湴瓒婃潵瓒婃槑鏄俱€傚洜鑰岋紝鏁版嵁搴撴妧鏈浉搴斿湴杩涘叆浜嗏€滃悗鍏崇郴鏁版嵁搴撴椂浠b€濓紝鍙戝睍杩涘叆鍩轰簬缃戠粶搴旂敤鐨勯潪缁撴瀯鍖栨暟鎹簱鏃朵唬銆?/p>
缁撴瀯鍖栨暟鎹?structured data)
缁撴瀯鍖栨暟鎹? 鍗宠鏁版嵁,瀛樺偍鍦ㄦ暟鎹簱閲?鍙互鐢ㄤ簩缁磋〃缁撴瀯鏉ラ€昏緫琛ㄨ揪瀹炵幇鐨勬暟鎹€?br>缁撴瀯鍖栨暟鎹? 鍏堢煡缁撴瀯, 鍐嶆湁鏁版嵁
銆傛垜浠牴鎹暟鎹殑缁撴瀯棰勫厛寤虹珛濂戒簩缁磋〃, 绛夋暟鎹潵鐨勬椂鍊? 濉叆鍗冲彲銆傚洜姝ょ粨鏋勫寲鐨勬暟鎹線寰€鏄彲寤烘ā, 鏍囧噯鍖栫殑鏁版嵁,缁撴瀯鍖栫殑鏁版嵁寰堟柟渚跨▼搴忎娇鐢? 鍥犱负缁撴瀯宸茬煡銆?/p>
缁撴瀯鍖栨暟鎹渶澶х殑闂, 灏卞綋鏁版嵁鐨勭粨鏋勫彂鐢熷彉鍖栨椂, 鎴戜滑闇€瑕佽皟鏁存暟鎹殑缁撴瀯, 涓€鑸氨鎰忓懗鐫€鏁版嵁搴撹〃缁撴瀯鐨勯渶瑕佸彉鍔ㄣ€傝繖浣垮緱鏁版嵁鍦ㄥ瓨鍌ㄦ椂鏈変弗鏍肩殑瑕佹眰(闇€瑕佸畾涔塻chema)銆?br>缁撴瀯鍖栨暟鎹? 鍙互琚彁鍓嶅缓妯$殑鏁版嵁(瀹氫箟schema)
鍗婄粨鏋勫寲鏁版嵁(semi-structured data)
鎵€璋撳崐缁撴瀯鍖栨暟鎹紝灏辨槸浠嬩簬瀹屽叏缁撴瀯鍖栨暟鎹?濡傚叧绯诲瀷鏁版嵁搴撱€侀潰鍚戝璞℃暟鎹簱涓殑鏁版嵁)鍜屽畬鍏ㄦ棤缁撴瀯鐨勬暟鎹?濡傚0闊炽€佸浘鍍忔枃浠剁瓑)涔嬮棿鐨勬暟鎹紝HTML鏂囨。灏卞睘浜庡崐缁撴瀯鍖栨暟鎹€傚畠涓€鑸槸鑷弿杩扮殑锛屾暟鎹殑缁撴瀯鍜屽唴瀹规贩鍦ㄤ竴璧凤紝娌℃湁鏄庢樉鐨勫尯鍒嗐€?br>鎵€浠ュ浜庡崐缁撴瀯鍖栫殑鏁版嵁, 鏁版嵁鐨勭粨鏋勮绛夋暟鎹幏寰楀悗鎵嶇煡閬? 涔熷氨鏄?code class="mq-144">鍏堟湁鏁版嵁, 鍚庣煡缁撴瀯銆傛暣涓簰鑱旂綉涓婅繖绫绘暟鎹槸寰堝鐨? 鍥犱负html灏辨槸鍗婄粨鏋勫寲鐨勬暟鎹€?/p>
鐩稿浜庣粨鏋勫寲鐨勬暟鎹? 鍗婄粨鏋勫寲鏁版嵁鏃犻渶瀹氫箟鏁版嵁鐨勭粨鏋?schema free), 浣垮緱鍏跺湪瀛樺偍涓婅〃鐜板嚭寮哄ぇ鐨勭伒娲绘€с€?br>鍗婄粨鏋勫寲鏁版嵁: html, JSON, XML
闈炵粨鏋勫寲鏁版嵁(unstructured data)
鐩稿浜庣粨鏋勫寲鏁版嵁鑰岃█锛屼笉鏂逛究鐢ㄦ暟鎹簱浜岀淮閫昏緫琛ㄦ潵琛ㄧ幇鐨勬暟鎹嵆绉颁负闈炵粨鏋勫寲鏁版嵁銆?br>闈炵粨鏋勫寲鏁版嵁搴撴槸鎸囧叾瀛楁闀垮害鍙彉锛屽苟涓旀瘡涓瓧娈电殑璁板綍鍙堝彲浠ョ敱鍙噸澶嶆垨涓嶅彲閲嶅鐨勫瓙瀛楁鏋勬垚鐨勬暟鎹簱锛岀敤瀹冧笉浠呭彲浠ュ鐞嗙粨鏋勫寲鏁版嵁(濡傛暟瀛椼€佺鍙风瓑淇℃伅), 鑰屼笖鏇撮€傚悎澶勭悊闈炵粨鏋勫寲鏁版嵁锛堝叏鏂囨枃鏈€佸浘璞°€佸0闊炽€佸奖瑙嗐€佽秴濯掍綋绛変俊鎭?銆?/p>
闈炵粨鏋勫寲WEB鏁版嵁搴撲富瑕佹槸閽堝闈炵粨鏋勫寲鏁版嵁鑰屼骇鐢熺殑锛屼笌浠ュ線娴佽鐨勫叧绯绘暟鎹簱鐩告瘮锛屽叾鏈€澶у尯鍒湪浜庡畠绐佺牬浜嗗叧绯绘暟鎹簱缁撴瀯瀹氫箟涓嶆槗鏀瑰彉鍜屾暟鎹畾闀跨殑闄愬埗锛屾敮鎸侀噸澶嶅瓧娈点€佸瓙瀛楁浠ュ強鍙橀暱瀛楁骞跺疄鐜颁簡瀵瑰彉闀挎暟鎹拰閲嶅瀛楁杩涜澶勭悊鍜屾暟鎹」鐨勫彉闀垮瓨鍌ㄧ鐞嗭紝鍦ㄥ鐞嗚繛缁俊鎭紙鍖呮嫭鍏ㄦ枃淇℃伅锛夊拰闈炵粨鏋勫寲淇℃伅锛堝寘鎷悇绉嶅濯掍綋淇℃伅锛変腑鏈夌潃浼犵粺鍏崇郴鍨嬫暟鎹簱鎵€鏃犳硶姣旀嫙鐨勪紭鍔裤€?br>闈炵粨鏋勫寲鏁版嵁: 鎵€鏈夋牸寮忕殑鍔炲叕鏂囨。銆佹枃鏈€佸浘鐗囥€乆ML銆丠TML銆佸悇绫绘姤琛ㄣ€佸浘鍍忓拰闊抽/瑙嗛淇℃伅绛夌瓑銆?/p>
2.2 瀛樺偍鏃舵暟鎹?/h3>
鏁版嵁瀛樺偍妯″瀷鍊兼暟鎹瓨鍌ㄦ椂濡備綍缁勭粐
2.2.1 鍏崇郴妯″瀷
鍏崇郴妯″瀷: 鏂板畾涔夊垪, 鐒跺悗閫氳繃琛岀殑鏂瑰紡瀵规暟鎹繘琛屽瓨鍌? 浠ヤ簩缁磋〃鏉ヨ〃绀哄疄浣撲笌瀹炰綋涔嬮棿鐨勮仈绯伙紝鍦ㄦ暟鎹缓妯℃椂闇€瑕佸鏁版嵁瀵硅薄杩涜鎷嗗垎锛屽啀灏嗗悇鑷殑淇℃伅瀛樺埌瀵瑰簲鐨勮〃閲岋紝鍦ㄩ渶瑕佹椂鍐嶅皢鍚勪釜琛ㄨ繛鎺ヨ捣鏉ャ€?/p>
鍦ㄥ叧绯绘ā鍨嬪綋涓紝澶氫釜琛ㄤ腑鐨勪笉鍚岃褰曠粡甯糕€滀氦閿欒繛鎺モ€濓紝涓€浜涙暟鎹細琚鏉¤褰曞叡浜€傝繖鏍风殑濂藉灏辨槸鍑忓皯浜嗛噸澶嶆暟鎹殑鍑虹幇锛屼絾鏄繖鏍蜂笉濂界殑鍦版柟灏辨槸涓€鏃﹀叾涓煇涓€鏉¢摼鎺ョ殑璁板綍鍙戠敓鏀瑰彉锛岄偅涔堜笌鍏剁浉鍏崇殑璁板綍鍜岃〃閮戒細琚攣浣忎互闃叉闈炰竴鑷存€х殑鍑虹幇銆侫CID浜嬪姟鍦ㄥ叧绯诲瀷鏁版嵁搴撲腑鏄緢澶嶆潅鐨勶紝鍥犱负鏁版嵁浼氭墿鏁c€傚嵆渚挎槸鍗曚竴鏉¤褰曪紝杩欏鏉傜殑鍏变韩鏁版嵁鍐呴儴鍏崇郴缃戠殑瀛樺湪锛屼篃浣垮緱鍏崇郴鍨嬫暟鎹湪澶氫釜鏈嶅姟鍣ㄤ箣闂寸殑浼犻€掑彉寰楀鏉傝€岀紦鎱紝鍚屾椂璁╄鍜屽啓鎿嶄綔鐨勬€ц兘鍙樺樊銆?/p>
褰撳瓨鍌ㄧ┖闂存槀璐靛張绋€灏戞椂锛屾姌涓殑鏉冭 鏂规鏄緢蹇呰鐨勩€傜劧鑰岋紝濡備粖瀛樺偍绌洪棿鐨勪环鏍艰窡40骞村墠鐩告瘮宸茬粡澶уぇ鐨勪笅闄嶄簡锛屽緢澶氭椂鍊欒绠楁姌涓柟妗堝凡缁忓畬鍏ㄦ病鏈夊繀瑕併€備娇鐢ㄦ洿澶氱殑瀛樺偍绌洪棿鏉ユ崲鍙栨洿濂界殑鎿嶄綔鎬ц兘锛屾垨鑰呮槸灏嗗伐浣滆礋杞藉垎閰嶅埌澶氬彴鏈哄櫒涓婏紝杩欐墠鏄浠婂簲鐢ㄤ笂鏇村ソ鐨勮В鍐虫柟妗堛€?/p>
2.2.2 鏂囨。妯″瀷
鏂囨。鏁版嵁: 灏嗕竴涓暟鎹褰?record鎴栬€卹ow)浣滀负鍗曚綅杩涜瀛樺偍, 鏃犻渶瀹氫箟琛屻€備篃鍙互璁や负涓€涓枃妗e氨鏄叧绯绘暟鎹簱鐨勪竴琛屻€?/p>
浣跨敤鈥滄枃妗b€濊繖涓瘝浼间箮璁╀汉瑙夊緱濂囨€紝浣嗘槸鍏跺疄鈥濇枃妗e瀷鏁版嵁妯″瀷鈥濈湡鐨勫拰浼犵粺鎰忎箟鐨勬枃瀛椻€濇枃妗b€濇病鏈変粈涔堝叧绯汇€備粬涓嶆槸涔︺€佷俊鎴栬€呮枃绔狅紝杩欓噷璇寸殑鈥濇枃妗b€濆叾瀹炴槸涓€涓暟鎹褰? 杩欎釜璁板綍鑳藉瀵瑰寘鍚殑鏁版嵁绫诲瀷鍜屽唴瀹硅繘琛屸€滆嚜鎴戞弿杩扳€濄€俋ML鏂囨。銆丠TML鏂囨。鍜孞SON 鏂囨。灏卞睘浜庤繖涓€绫? 鍥犳鎴戜滑鍙互璁や负鎵€鏈夊崐缁撴瀯鍖栫殑鏁版嵁閮藉睘浜庢枃妗f暟鎹? 鑰岀幇鍦ㄤ富瑕佺殑鏂囨。鏁版嵁搴撹繕鏄互Json浣滀负鏂囨。涓轰富.
鍙互鐪嬪埌锛屾暟鎹槸涓嶈鍒欑殑锛屾瘡涓€鏉¤褰曞寘鍚簡鎵€鏈夌殑鏈夊叧璇ヨ褰曠殑淇℃伅鑰屾病鏈変换浣曞閮ㄧ殑寮曠敤, 杩欐潯璁板綍灏辨槸鈥滆嚜鍖呭惈鈥濈殑銆傝繖灏变娇寰楄褰曞緢瀹规槗瀹屽叏绉诲姩鍒板叾浠栨湇鍔″櫒, 鍥犱负杩欐潯璁板綍鐨勬墍鏈変俊鎭兘鍖呭惈鍦ㄩ噷闈簡, 涓嶉渶瑕佽€冭檻杩樻湁淇℃伅鍦ㄥ埆鐨勮〃娌℃湁涓€璧疯縼绉昏蛋銆傚悓鏃讹紝鍥犱负鍦ㄧЩ鍔ㄨ繃绋嬩腑锛屽彧鏈夎绉诲姩鐨勯偅涓€鏉¤褰?/p>
闇€瑕佹搷浣滆€屼笉鍍忓叧绯诲瀷涓瘡涓湁鑱旂郴鐨勮〃閮介渶瑕侀攣浣忔潵淇濊瘉涓€鑷存€э紝杩欐牱涓€鏉CID鐨勪繚璇佸氨浼氬彉寰楁洿蹇€? 璇诲啓鐨勯€熷害涔熶細鏈夊緢澶х殑鎻愬崌銆?/p>
2.2.3 鍋ュ€兼ā鍨?/h4>
鍋ュ€兼ā鍨? 瀹冪殑鏁版嵁鎸夌収閿€煎鐨勫舰寮忚繘琛岀粍缁?绱㈠紩鍜屽瓨鍌ㄣ€侹V瀛樺偍闈炲父閫傚悎涓嶆秹鍙婅繃澶氭暟鎹叧绯讳笟鍔″叧绯荤殑涓氬姟鏁版嵁锛屽悓鏃惰兘鏈夋晥鍑忓皯璇诲啓纾佺洏鐨勬鏁帮紝姣擲QL鏁版嵁搴撳瓨鍌ㄦ嫢鏈夋洿濂界殑璇诲啓鎬ц兘銆?/p>
2.2.4 鍒楀紡妯″瀷
鍒楀紡瀛樺偍: 浠ュ垪鐩稿叧瀛樺偍鏋舵瀯杩涜鏁版嵁瀛樺偍銆傚垪寮忓瓨鍌ㄤ互娴佺殑鏂瑰紡鍦ㄥ垪涓瓨鍌ㄦ墍鏈夌殑鏁版嵁锛屼富瑕侀€傚悎涓庢壒閲忔暟鎹鐞嗗拰鍗冲腑鏌ヨ銆?/p>
鐢变簬鏌ヨ闇€瑕佽鍙栫殑blocks灏? 鎵€浠ユ煡璇㈠揩, 鍥犱负鍚屼竴绫诲瀷鐨勫垪瀛樺偍鍦ㄤ竴璧? 鎵€浠ユ暟鎹帇缂╂瘮楂? Load蹇€傚畠绠€鍖栨暟鎹缓妯$殑澶嶆潅鎬с€備絾鏄彃鍏ユ洿鏂版參锛屼笉澶€傚悎鏁版嵁鑰佹槸鍙樺寲锛屽畠鏄寜鍒楀瓨鍌ㄧ殑銆傚垪寮忓瓨鍌ㄥ緢閫傚悎鍋氭暟鎹粨搴擄紝瀹冧笉閫傚悎OLTP銆?/p>
鍦ㄨ绠楁満绉戝涓? CAP瀹氱悊(CAP theorem)
, 鍙堣绉颁綔甯冮瞾灏斿畾鐞?Brewer's theorem)
, 瀹冩寚鍑哄浜庝竴涓垎甯冨紡璁$畻绯荤粺鏉ヨ锛屼笉鍙兘鍚屾椂婊¤冻浠ヤ笅涓夌偣:
涓€鑷存€?Consistency) (鎵€鏈夎妭鐐瑰湪鍚屼竴鏃堕棿鍏锋湁鐩稿悓鐨勬暟鎹?
鍙敤鎬?Availability) (淇濊瘉姣忎釜璇锋眰涓嶇鎴愬姛鎴栬€呭け璐ラ兘鏈夊搷搴?
鍒嗛殧瀹瑰繊(Partition tolerance) (绯荤粺涓换鎰忎俊鎭殑涓㈠け鎴栧け璐ヤ笉浼氬奖鍝嶇郴缁熺殑缁х画杩愪綔)
CAP鐞嗚鐨勬牳蹇冩槸锛氫竴涓垎甯冨紡绯荤粺涓嶅彲鑳藉悓鏃跺緢濂界殑婊¤冻涓€鑷存€э紝鍙敤鎬у拰鍒嗗尯瀹归敊鎬ц繖涓変釜闇€姹傦紝鏈€澶氬彧鑳藉悓鏃惰緝濂界殑婊¤冻涓や釜銆?br>鍥犳锛屾牴鎹瓹AP鍘熺悊灏哊oSQL鏁版嵁搴撳垎鎴愪簡婊¤冻CA鍘熷垯銆佹弧瓒矯P鍘熷垯鍜屾弧瓒矨P鍘熷垯涓?澶х被锛?/p>
CA 鍗曠偣闆嗙兢锛屾弧瓒充竴鑷存€э紝鍙敤鎬х殑绯荤粺锛岄€氬父鍦ㄥ彲鎵╁睍鎬т笂涓嶅お寮哄ぇ銆?/p>
CP 婊¤冻涓€鑷存€э紝鍒嗗尯瀹瑰繊鎬х殑绯荤粺锛岄€氬父鎬ц兘涓嶆槸鐗瑰埆楂樸€?/p>
AP 婊¤冻鍙敤鎬э紝鍒嗗尯瀹瑰繊鎬х殑绯荤粺锛岄€氬父鍙兘瀵逛竴鑷存€ц姹備綆涓€浜涖€?/p>
瀹氱悊: 浠讳綍鍒嗗竷寮忕郴缁熸渶澶氬彧鑳藉悓鏃舵椂婊¤冻3鐐?Consistency, Availability, Partition tolerance)涓殑2鐐? 鍚屾椂婊¤冻3鐐圭殑鍒嗗竷寮忕郴缁熸槸涓嶅瓨鍦ㄧ殑
RDBMS婊¤冻鐨勬槸ACID瑙勫垯, 鑰孉CID瑙勫垯婊¤冻鐨勫氨鏄疌AP閲岄潰鐨?code class="mq-191">CA, 鍥犳鎵╁睍鎬т笉寮? MongoDB Architecture瀹樻柟涓枃浠嬬粛 寰€鏈熷師鍒涙枃绔犳帹鑽?/p>
以上是关于鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛的主要内容,如果未能解决你的问题,请参考以下文章
蹇犲憡锛氭灦鏋勫笀涓嶈灏嗙簿鍔涙氮璐瑰湪濡備綍璁捐鑳芥弧瓒充笁鑰呯殑瀹岀編鍒嗗竷寮忕郴缁燂紝鑰屾槸搴旇杩涜鍙栬垗銆?/p>
3.1 CAP涓庢暟鎹簱
NewSQL/NoSQL婊¤冻鐨勬槸BASE瑙勫垯, 鑰孊ASE瑙勫垯灏辨槸闄嶄綆涓€鑷存€ф垨鑰呭彲鐢ㄦ€ф潵鎻愬崌绯荤粺鎬ц兘, 灏辨槸CAP閲岄潰鐨?code class="mq-192">CP/AP
elasticsearch(lucene)鍙互浠f浛NoSQL(mongodb)鍚楋紵