鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛

Posted Golang鍦ㄥ彂鍏?/a>

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛相关的知识,希望对你有一定的参考价值。

鐐瑰嚮鈥?/span>Golang鍦ㄥ彂鍏?/span>鈥濓紝閫夋嫨鈥滄槦鏍囸煍濃€?/span>

鐐瑰嚮鏂囨湯鈥?/span>闃呰鍘熸枃鈥濊В閿佽祫鏂欙紒




鐢变簬椤圭洰闇€瑕佸瓨鍌ㄤ竴浜涙棤缁撴瀯鐨勬暟鎹? 杩欎簺鏁版嵁涓昏浠ユ枃鏈负涓? 鍚屾椂杩橀渶鏀寔涓€浜涙枃鏈垎鏋? 鍜嬩竴鍚技涔嶦S鏄竴涓笉閿欑殑閫夋嫨, 浣嗘槸杩欎簺鏃犵粨鏋勭殑鏁版嵁鍚屾椂涔熼渶瑕佽绠$悊, 涔熷氨鏄繖浜涙暟鎹彲鑳界粡甯稿彉鏇? 琛¢噺鍐嶄笁, 鏈€鍚庤繕鏄€夋嫨浜哅ongo, 姣曠珶鐜伴樁娈垫槸浠ユ暟鎹殑瀛樺偍鍜岀鐞嗕负涓? 鍒嗘瀽骞舵病鏈夐偅涔堝己鐨勯渶姹傘€傛暣绡囨枃绔犱互澶ф暟鎹瓨鍌ㄩ棶棰樹负寮? 涓€姝ユ寮曞嚭NoSQL棰嗗煙鏂囨。鏁版嵁鐨勪唬琛∕ongoDB銆?/p>


 1   澶ф暟鎹瓨鍌ㄩ棶棰?/span>


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

  • mysql

  • 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>

  • 鏈€缁堜竴鑷存槸涓嶇洿瑙傜殑绋嬪簭


 2   鏁版嵁妯″瀷


瀵逛簬鏁版嵁鏈韩鑰岃█, 鎴戜滑寰€寰€灏嗗叾鍒嗕负缁撴瀯鍖栨暟鎹? 鍗婄粨鏋勫寲鏁版嵁, 浠ュ強闈炵粨鏋勫寲鏁版嵁, 浣嗘槸瀵逛簬鍌ㄥ瓨鏃舵暟鎹殑缁勭粐鎴戜滑鎵嶇О鍏朵负鏁版嵁妯″瀷, 甯歌鐨勬暟鎹ā鍨嬫湁: 鍏崇郴妯″瀷, 鏂囨。妯″瀷, 鍋ュ€兼ā鍨? 浠ュ強鍒楀紡妯″紡銆?/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>


 3   CAP瀹氱悊


鍦ㄨ绠楁満绉戝涓? 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鐐圭殑鍒嗗竷寮忕郴缁熸槸涓嶅瓨鍦ㄧ殑


蹇犲憡锛氭灦鏋勫笀涓嶈灏嗙簿鍔涙氮璐瑰湪濡備綍璁捐鑳芥弧瓒充笁鑰呯殑瀹岀編鍒嗗竷寮忕郴缁燂紝鑰屾槸搴旇杩涜鍙栬垗銆?/p>

3.1 CAP涓庢暟鎹簱

RDBMS婊¤冻鐨勬槸ACID瑙勫垯, 鑰孉CID瑙勫垯婊¤冻鐨勫氨鏄疌AP閲岄潰鐨?code class="mq-191">CA, 鍥犳鎵╁睍鎬т笉寮?
NewSQL/NoSQL婊¤冻鐨勬槸BASE瑙勫垯, 鑰孊ASE瑙勫垯灏辨槸闄嶄綆涓€鑷存€ф垨鑰呭彲鐢ㄦ€ф潵鎻愬崌绯荤粺鎬ц兘, 灏辨槸CAP閲岄潰鐨?code class="mq-192">CP/AP

 4   鍙傝€?/span>


MongoDB Architecture瀹樻柟涓枃浠嬬粛
elasticsearch(lucene)鍙互浠f浛NoSQL(mongodb)鍚楋紵



寰€鏈熷師鍒涙枃绔犳帹鑽?/p>



以上是关于鏁版嵁搴撳垎绫讳互鍙奛oSQL浠嬬粛的主要内容,如果未能解决你的问题,请参考以下文章

鏁版嵁搴撳垎鐗?Sharding)

JMeter 涔嬫暟鎹簱鎿嶄綔鍙婂弬鏁板寲

Mysql鏁版嵁搴撳熀纭€鐭ヨ瘑

鏁版嵁搴撳涔犲綊绾虫€荤粨

Qt 鏁版嵁搴撳熀鏈娇鐢?-QSQLITE

Oracle鏁版嵁搴撳父鐢ㄧ殑Sql璇彞鏁寸悊