鍒嗗簱鍒嗚〃
缃戜笂鍒嗗簱鍒嗚〃鐨勮祫鏂欏緢澶氾紝杩欓噷涓昏鏄噸鏂版暣鐞嗗拰姊崇悊涓€涓嬨€傚鏈夊拰鍏朵粬鏂囩珷绫讳技鐗囨鎴栬В鍐虫柟妗堬紝绾睘鍓嶄汉鎬荤粨鎴栬€呬笟鍐呮爣鍑嗐€?/p>
涓轰粈涔堣鍒嗚〃鍒嗗簱
鍒嗚〃鍒嗗簱涓€鑸細鍦ㄤ互涓嬫儏鍐典笅鍑虹幇锛?/p>
涓€銆佹暟鎹簱鏈韩鐨勬€ц兘鐡堕
- 鍗曟満鏁版嵁搴撶殑瀛樺偍瀹归噺闄愬埗
- 鍗曟満鏁版嵁搴撶殑杩炴帴鏁伴檺鍒?/li>
- 鍗曞紶琛ㄧ殑鎬ц兘鐡堕
- 鍗曞紶琛ㄦ€ц兘鐡堕锛?/li>
- 鍗曚釜鏁版嵁搴撴€ц兘鐡堕锛?/li>
浜屻€佺壒娈婂満鏅渶姹?/strong>
- SasS 鐗瑰畾鍦烘櫙涓嬬殑鏁版嵁闅旂闇€瑕侊紱
鏁版嵁搴撶摱棰?/h2>
涓嶇鏄?IO 鐡堕锛岃繕鏄?CPU 鐡堕锛屾渶缁堥兘浼氬鑷存暟鎹簱鐨勬煡璇㈢紦鎱㈢敋鑷虫棤娉曟煡璇€傝繘鑰屽鑷翠笟鍔℃湇鍔$殑闅句互鎻愰珮骞跺彂閲忋€佸悶鍚愰噺銆傛暟鎹簱鐡堕涔熶細瀵艰嚧鏌ヨ缂撴參銆佸ぇ閲忕殑瓒呮椂鎯呭喌杩涜€屽鑷寸▼搴忔棤娉曚娇鐢ㄦ垨鑰呭穿婧冪殑鎯呭喌
IO 鐡堕
绗竴绉嶏細纾佺洏璇?IO 鐡堕锛屾暟鎹お澶氾紝鏁版嵁搴撶紦瀛樻斁涓嶄笅锛屾瘡娆℃煡璇㈡椂浼氫骇鐢熷ぇ閲忕殑 IO锛岄檷浣庢煡璇㈤€熷害 -> 鍒嗗簱鍜屽瀭鐩村垎琛?/p>
绗簩绉嶏細缃戠粶 IO 鐡堕锛岃姹傜殑鏁版嵁澶锛岀綉缁滃甫瀹戒笉澶?-> 鍒嗗簱
CPU 鐡堕
绗竴绉嶏細SQL 闂锛屽 SQL 涓寘鍚?join锛実roup by锛宱rder by锛岄潪绱㈠紩瀛楁鏉′欢鏌ヨ绛夛紝澧炲姞 CPU 杩愮畻鐨勬搷浣?-> SQL 浼樺寲锛屽缓绔嬪悎閫傜殑绱㈠紩锛屽湪涓氬姟 Service 灞傝繘琛屼笟鍔¤绠椼€?/p>
绗簩绉嶏細鍗曡〃鏁版嵁閲忓お澶э紝鏌ヨ鏃舵壂鎻忕殑琛屽お澶氾紝SQL 鏁堢巼浣庯紝CPU 鐜囧厛鍑虹幇鐡堕 -> 姘村钩鍒嗚〃銆?/p>
缃戜笂涔熸祦浼犵潃涓€浜涙洿閫氫織鍏蜂綋鐨勮娉曟瘮濡傦細褰撳崟琛ㄧ殑鏁版嵁閲忚揪鍒?000W鎴?00G浠ュ悗銆傛洿閫氫織鐨勮璇濆氨鏄暟鎹簱宸茬粡鏃犳硶婊¤冻鎬ц兘闇€姹備簡銆傝嚦浜庝粈涔堟儏鍐典笉鑳芥弧瓒虫€ц兘闇€姹傦紝杩樻槸瑕佹牴鎹叿浣撶殑鍦烘櫙鏉ョ‘瀹氱殑锛屽苟娌℃湁浠€涔堥噾绉戠帀寰嬨€?/p>
鐗规畩鍦烘櫙闇€姹?/h2>
杩欎釜灏辨病鏈夊姙娉曚簡锛岀洿鎺ユ帴鍙楀惂 馃槒馃ぃ馃槀馃槄馃槩馃槬馃槳馃槗馃槹馃槶
鍒嗚〃鍒嗗簱鍓嶆垜浠彲浠ュ仛鍝簺灏濊瘯
閲岄潰娑夊強鐨勫叿浣撳疄鐜颁互 Java 涓轰富锛屽叾浠栬瑷€浣跨敤鑰呰嚜琛岃剳琛?/p>
鏁版嵁搴撴湰韬殑鎬ц兘鐡堕鏄棤娉曢伩鍏嶏紝浣嗘垜浠彲浠ユ兂娉曞噺杞绘暟鎹簱鐨勫帇鍔涳紝鍑忚交鏁版嵁搴撶摱棰堟湰韬甫鏉ョ殑褰卞搷銆?/p>
缂撳瓨
缂撳瓨鍙互绉扮殑涓婃彁渚涙€ц兘鍑忓皯鏁版嵁搴撴煡璇㈢殑涓€涓竾閲戞补鏂规锛屽叾铏界劧涓嶈兘瀹岀編鐨勶紝浣嗕竴瀹氭槸鏈€鍏堟兂鍒扮殑銆?/p>
涓€鑸彲浠ヤ娇鐢ㄨ繘绋嬪唴缂撳瓨鍜屽垎甯冨紡缂撳瓨涓ょ鏂规鐩哥粨鍚堢殑鏂规銆傚浜庝竴鑷存€ц姹備笉楂橈紝鐢氳嚦鍏佽涓€瀹氭椂闂村唴鍙互鏈夋暟鎹樊寮傜殑鍔熻兘锛屽彲浠ョ洿鎺ラ噰鐢ㄨ繘绋嬪唴缂撳瓨鏉ュ疄鐜帮紝杩欑鏂规鏇撮珮鏁堬紝涓嶈繃鍏跺拰绋嬪簭鏈韩鍗犵敤鍚屼竴涓繘绋嬶紝闇€瑕佽€冭檻杩涚▼鍐呯紦瀛樼殑瀹归噺闂锛屽叿浣撴柟妗堝彲浠ヤ娇鐢?Google Guava銆丆affeine 浠ュ強 Spring Cache 绛夛紱濡傛灉瀵逛簬涓€鑷存€ц姹傞珮锛屽苟涓斾笉鎯崇紦瀛樺崰鐢ㄦ洿澶氱殑杩涚▼鍐呭瓨锛屽垯鍙互浣跨敤鍒嗗竷寮忕紦瀛橈紝鍏堕€氳繃涓€涓珮鎬ц兘澶栭儴鐨?Server 鏉ュ瓨鍌ㄤ竴浜涢渶瑕佺紦瀛樼殑鏁版嵁锛屾湇鍔¢€氳繃缃戠粶閫氫俊鏉ヨ幏鍙栧閮?Server 鐨勭紦瀛樻暟鎹紝鍏跺鍔犱簡涓€閮ㄥ垎缃戠粶寮€閿€锛屼絾涓嶇敤鍐嶅崰鐢ㄤ笟鍔℃湇鍔$殑杩涚▼鍐呭瓨銆?/p>
鏂规瀵规瘮 | 杩涚▼鍐呯紦瀛橈紙鏈湴缂撳瓨锛?/th> | 鍒嗗竷寮忕紦瀛?/th> |
---|---|---|
瀹归噺瀵规瘮 | 缂撳瓨鏁版嵁鍜屾湇鍔¤繘绋嬪叡鐢ㄥ唴瀛橈紝鍙楀崟鏈哄唴瀛橀檺鍒?/td> | 缂撳瓨鏁版嵁鍗曠嫭鍦ㄩ珮鎬ц兘鏈嶅姟涓婏紝涓庢湇鍔¤繘琛屾棤鍏筹紝鍏跺彈鍏蜂綋鐨勯珮鎬ц兘鏈嶅姟鍣ㄩ檺鍒躲€傚彲浠ラ€氳繃闆嗙兢鐨勬柟寮忔彁楂樺閲?/td> |
鎬ц兘瀵规瘮 | 鏈湴杩涚▼鍐呭瓨鏌ユ壘锛屾€ц兘楂樻晥 | 瀛樺湪缃戠粶寮€閿€锛屽彈缃戠粶鐜鐨勫奖鍝?/td> |
鍏蜂綋鎶€鏈柟妗?/td> | Map銆丒hcache銆丟oogle Guava銆丆affeine 浠ュ強 Spring Cache 绛?/td> | Memcached銆丷edis銆丼pring Cache |
绌洪棿鎹熻€?/td> | 鎹熻€楀ぇ锛屽洜涓虹紦瀛樻暟鎹拰鏈嶅姟杩涚▼鍐呭瓨涓€璧峰瓨鍌紝鏃犳硶鍏变韩銆傚垯姣忎釜鏈嶅姟杩涜閮戒細鏈変竴浠斤紝鍙兘鍖呮崲澶氫唤閲嶅鏁版嵁銆?/td> | 鎹熻€楀皬 |
鏁版嵁搴撹鍐欏垎绂?/h2>
璇诲啓鍒嗙涔熸槸涓€绉嶆湁鏁堥檷浣庢暟鎹簱鍘嬪姏鐨勬柟妗堬紝閫氳繃鏁版嵁搴撲富浠庣粨鏋勶紝涓昏妭鐐硅礋璐h鍐欙紝浠庤妭鐐硅礋璐h銆傝繖鏍锋垜浠彲浠ラ€氳繃灏嗕竴浜涜璇锋眰鍒嗘暎鍒颁粠鑺傜偣锛屾潵鍑忚交涓昏妭鐐圭殑鍘嬪姏銆傛瘮濡備竴浜涙姤琛ㄣ€佸垎鏋愩€佺粺璁$殑鍔熻兘妯″潡鍙厑璁稿叾璁块棶浠庡簱锛屽彲浠ュ湪涓€瀹氱殑鏉′欢涓嬫彁鍗囨暣浣撴€ц兘
鍏充簬涓€浜涘父瑙佺殑鏁版嵁搴撴灦鏋勭殑妯″紡锛岃繖閲屼笉鍦ㄥ彊杩帮紝杩欏拰鏈枃鏃犲叧锛屽叿浣撴ā寮忎互鍚庡彲鑳戒細鍐嶅啓涓€绡囪繘琛岃ˉ鍏呫€?/p>
浼樺寲鏁版嵁搴撶粨鏋勫拰鏌ヨ璇彞
- 瀵逛竴浜涙煡璇㈡潯浠跺姞绱㈠紩
- 瀵逛竴涓〃涓笉缁忓父琚煡璇㈢殑鏁版嵁鍒囧壊鍒颁竴涓瓙琛ㄤ腑锛屼繚璇佷富琛ㄧ殑鏌ヨ鎬ц兘
- 閫傚綋鐨勪紭鍖栬〃缁撴瀯绛夌瓑
褰撶劧 SQL 浼樺寲涓嶆槸鏈枃鐨勯噸鐐癸紝浣嗚繖涔熸槸涓€涓紭鍖栫殑鏂瑰悜锛屽ソ鐨?SQL 鍜岃〃缁撴瀯瀵瑰簲鎬ц兘杩樻槸鏈夊緢澶у奖鍝嶇殑銆?/p>
鍏朵粬娣峰悎鏂规
鎴戜滑涔熷彲浠ラ€氳繃娣峰悎鍏朵粬瀛樺偍鏂规鏉ュ噺杞绘暟鎹簱鐨勫帇鍔涳紝姣斿 MongoDB銆丒lasticSearch銆傞€氳繃娣峰悎浣跨敤涓€浜涙洿楂樻€ц兘鐨勬妧鏈柟妗堟潵鎻愰珮鏁翠綋鎬ц兘銆?/p>
鍒嗚〃鍒嗗簱鐨勫父瑙佹柟妗堝拰灞€闄愭€?/h2>
鏃㈢劧鍒颁簡杩欓噷锛岄偅涔堣偗瀹氬氨瑕佸垎搴撳垎琛紝鎴戠涓€娆℃帴瑙﹀垎琛ㄧ殑鏃跺€欐槸 16 骞村ぇ涓夌殑鏃跺€欙紝鍒扮幇鍦ㄥ凡鏈?4 骞村锛屼絾璁板繂鐘规柊銆傛帴涓嬫潵绠€鍗曠殑璇翠竴涓嬪綋鏃剁殑鎯呭喌銆?/p>
绗竴娆″垎琛ㄧ殑缁忓巻
褰撴椂杩樺湪涓婂ぇ涓夛紝褰撴椂鏈変釜涓€涓」鐩紝閲岄潰鏈変釜 2 涓ā鍧楋紝涓€涓槸璁㈠崟锛屼竴涓槸鐢ㄦ埛鐨勬搷浣滆褰曪紝杩欎袱涓兘鏄暟鎹噺姣旇緝澶х殑妯″潡锛屽洜涓鸿鍗曠殑瀹炴椂鎬ф瘮杈冮珮锛屾棤娉曞仛缂撳瓨澶勭悊锛岀敤鎴风殑鎿嶄綔璁板綍鏁版嵁閲忔瘮杈冨ぇ锛屽仛缂撳瓨涔熸病鏈夊お澶х殑蹇呰锛屽悓鏃跺叕鍙搁噰鐢ㄧ殑浜戞暟鎹簱锛岃繕绠楁瘮杈冭吹锛屽張鍥犱负鍏朵粬琛ㄧ殑鏁版嵁閲忛兘姣旇緝灏忥紝娌″繀瑕佷负浜嗚繖涓や釜澶ц〃鏉ュ鍔犳暟鎹簱锛岃繖閲屽氨鑰冭檻浜嗙洿鎺ヤ笉澧炲姞鏁版嵁搴撳疄渚嬬殑鎯呭喌涓嬶紝鍙仛鍒嗚〃鎿嶄綔銆?/p>
閽堝鐢ㄦ埛鎿嶄綔璁板綍鐨勫鐞?/h3>
鐢ㄦ埛鎿嶄綔璁板綍鏄褰曠敤鎴峰湪鎴戜滑椤圭洰涓殑涓€绯诲垪琛屼负锛屾湰韬笉鑳藉湪閫氳繃鎷嗗垎瀛愯〃鐨勫舰寮忛檷浣庤〃鐨勫ぇ灏忥紝杩欓噷浣跨敤姘村钩鍒嗚〃銆傛牴鎹煡璇㈡儏鍐碉紝鐢ㄦ埛涓€鑸槸鏌ヨ鏈€杩戝嚑澶╃殑璁板綍锛屽鍑犱釜鏈堝墠鐨勫巻鍙茶褰曞緢灏戞煡璇紝鎵€浠ヨ繖閲屾寜鏈堜唤瀵规棩蹇楄〃杩涜姘村钩鎷嗗垎銆?/p>
鍘熸暟鎹〃鍚嶇О锛歶ser_action_record_log
鏂版暟鎹〃鍚嶇О锛歶ser_action_record_log_201607銆乽ser_action_record_log_201608銆乽ser_action_record_log_201609銆乽ser_action_record_log_201610 ...
灏嗚涓烘棩蹇楁寜鏈堜唤鎷嗗垎锛岃〃鍚嶅鍔犲搴旂殑鏈堜唤鍚庣紑
瀵规彃鍏ョ殑褰卞搷锛?/strong> 鎻掑叆鏁版嵁鏃讹紝闇€瑕佹牴鎹椂闂村姩鎬佹嫾鎺ヨ〃鍚?/p>
瀵规煡璇㈢殑褰卞搷锛?/strong> 鍥犱负鎸夌収鏃堕棿杩涜鎷嗗垎锛屽湪鏌ヨ鐨勬椂鍊欓渶瑕佽姹傜敤鎴锋寚瀹氭椂闂存锛屽綋鐒惰繖涓湰韬奖鍝嶄笉澶э紝濡傛灉鐢ㄦ埛涓嶉€夋嫨鏃堕棿锛屽垯榛樿鍙煡褰撳墠鏈堬紝鍚勭鎯呭喌濡備笅锛?/p>
閫氳繃杩欑鏂瑰紡灏嗕竴涓ぇ琛紝鎸夋湀浠藉彉鎴愪簡澶氫釜灏忚〃銆?/p>
璁㈠崟琛ㄦ湰韬瓧娈佃繕鏄尯澶氱殑锛屽寘鍚拱瀹朵俊鎭€佸崠瀹朵俊鎭€佸晢鍝佷俊鎭瓑锛屽湪鍋氭煡璇㈡椂锛屾湁寰堝瀛楁鏃笉杩涜鏄剧ず鍙堜笉鍙備笌鏌ヨ鏉′欢锛岃繖鏍峰彲浠ュ厛杩涜鍨傜洿鎷嗗垎锛屽皢璁㈠崟琛ㄨ繖涓ぇ琛ㄦ媶鍒嗘垚涓€涓富琛ㄤ竴涓瓙琛紝涓昏〃璐熻矗瀛樺偍涓€涓富瑕佺殑鏃㈠弬涓庢煡璇㈠張鍙備笌澶ч儴鍒嗕笟鍔″睍绀洪€昏緫鐨勫瓧娈碉紝瀛愯〃璐熻矗瀛樺偍澶ч儴鍒嗕笟鍔¢兘涓嶉渶瑕佺敤鍒扮殑瀛楁锛屼竴鑸彧鏈夌偣鍒拌鎯呬篃鎵嶉渶瑕佺殑鏁版嵁銆?/p>
鍘熸暟鎹〃鍚嶇О锛歰rder 鏂版暟鎹簱鍚嶇О锛歰rder_pri, order_sub 杩欐牱澶ч儴鍒嗘煡璇㈠彲浠ラ€氳繃 鍘熸暟鎹〃鍚嶇О锛歰rder_pri, order_sub 鏂版暟鎹簱鍚嶇О锛歰rder_pri_201607, order_pri_201608, order_sub_201607, order_sub_201608 瀵规彃鍏ョ殑褰卞搷锛?/strong> 鎻掑叆鏁版嵁鏃讹紝闇€瑕佹牴鎹椂闂村姩鎬佹嫾鎺ヨ〃鍚?/p>
瀵规煡璇㈢殑褰卞搷锛?/strong> 鍥犱负鎸夌収鍒涘缓鏃堕棿杩涜鎷嗗垎锛屽湪鏌ヨ鐨勬椂鍊欓渶瑕佽姹傜敤鎴锋寚瀹氭椂闂存锛屽綋鐒惰繖涓湰韬奖鍝嶄笉澶э紝濡傛灉鐢ㄦ埛涓嶉€夋嫨鏃堕棿锛屽垯榛樿鍙煡褰撳墠鏈堬紝鍚勭鎯呭喌濡備笅锛?/p>
閫氳繃杩欑鏂瑰紡灏嗕竴涓ぇ琛紝鎸夋湀浠藉彉鎴愪簡澶氫釜灏忚〃銆?/p>
瀵逛慨鏀圭殑褰卞搷锛?/strong>鍓嶇鍦ㄤ慨鏀规煇鏉¤褰曟椂鏃㈣浼犲叆id, 鍙堣浼犲叆杩欎釜璁㈠崟鐨勫垱寤烘椂闂达紝涓昏涓轰簡瀹氫綅鍒版槸鍝釜鏈堜唤鐨勮〃锛屽綋鐒朵篃鍙互鍋氫釜鏄犲皠琛ㄦ潵瑙e喅杩欎釜闂锛屾垜浠病鍋?/p>
杩欐牱鐨勭郴缁熷叾瀹炲凡缁忓彲浠ヤ娇鐢ㄤ簡锛屾煡璇㈢殑閫熷害涔熸彁楂樹簡寰堝锛屽熀鏈笂鍙互寰堝ソ鐨勮繍琛屼簡銆傞毦閬撹繖灏卞畬浜嗭紝鍙笉鏄繖鏍风殑锛屾垜浠彲鏄竴涓簿鐩婃眰绮剧殑鍥㈤槦銆?/p>
棣栧厛鐪嬩竴涓嬭鍗曠殑鐘舵€佸拰鍚勭鐘舵€佺殑鍚箟锛?/p>
璁㈠崟鐘舵€佷富瑕佹湁寰呬粯娆俱€佸緟鍙戣揣銆佸緟鏀惰揣銆佸緟璇勪环銆佸凡鍏抽棴銆佷互鍙婇€€娆句腑銆?/p>
鍥犱负鎴戜滑鍋氱殑鏄樋閲屽反宸寸殑绗笁鏂瑰簲鐢紝鎵€浠ユ垜浠殑璁㈠崟缁撴瀯鍜岄樋閲屽反宸寸殑鎯婁汉鐨勭浉浼硷紝鎴戜滑椤圭洰涓昏鏈嶅姟浜庨樋閲屽反宸翠笂鐨勫晢瀹惰€屼笉鏄敤鎴凤紝鍦ㄦ垜浠殑绯荤粺涓晢瀹舵洿鍏冲績鐨勬槸寰呬粯娆俱€佸緟鍙戣揣鐨勮鍗曪紝寰呬粯娆剧殑闇€瑕佽繘琛屽偓鍗曘€佸緟鍙戣揣鐨勯渶瑕佸晢瀹惰刀绱у彂璐с€佸叾浣欑姸鎬佺殑璁㈠崟鏇村鐨勬槸鍋氱粺璁★紝鑰屼笉鏄疄鏃舵搷浣滐紝閽堝鎴戜滑鐨勮繖绉嶄笟鍔″満鏅紝鎴戜滑鍙戠幇濡傛灉鏍规嵁璁㈠崟鐨勭姸鎬佽繘琛屽垎琛ㄨ€屼笉鏄牴鎹垱寤烘椂闂村垎琛紝浼间箮鏇村姞鐨勫悎鐞嗭紝鍚屾椂鎴戜滑灏嗙郴缁熺殑鍔熻兘杩涜浼樺寲锛屽皢闈?寰呬粯娆俱€佸緟鍙戣揣 鐨勮鍗曞崟鐙仛涓〉闈笓闂ㄥ仛鏁版嵁鏌ヨ锛屽 寰呬粯娆俱€佸緟鍙戣揣 鐨勮鍗曡繘琛屼紭鍖栧鐞嗭紝鍥犱负杩欑鐘舵€佺殑璁㈠崟涓€鑸緢蹇氨浼氳鍟嗗澶勭悊锛屽彉鎴愬叾浠栫姸鎬侊紝杩欐牱杩欑鐘舵€佺殑鏁版嵁鏈韩灏变笉澶氾紝鏇撮€傚悎瀹炴椂鏌ヨ锛屽闈?strong>寰呬粯娆俱€佸緟鍙戣揣 棣栧厛灏?strong>寰呬粯娆俱€佸緟鍙戣揣銆佸緟鏀惰揣銆佸緟璇勪环銆佸凡鍏抽棴銆佷互鍙婇€€娆句腑 鏍规嵁涓氬姟鎯呭喌鏈畬鎴?/strong>鍒嗙被鐨勬暟鎹瘮杈冨皯锛屼竴鑸负 7 澶╁唴鏁版嵁锛屼笉闇€瑕佽繘涓€姝ユ媶鍒嗭紱宸插畬鎴?/strong>鍒嗙被鐨勬暟鎹緝澶氾紝闇€瑕佽繘涓€姝ユ媶鍒嗭紝杩欓噷缁х画鏍规嵁鏈堜唤杩涜鎷嗗垎锛?strong>閫€娆?/strong>鍒嗙被鐨勬暟鎹篃姣旇緝灏戯紝澶ч儴鍒嗙敤鎴烽兘涓嶄細閫€娆撅紝涓嶉渶瑕佽繘涓€姝ユ媶鍒嗐€?/p>
鏍规嵁鎯呭喌鏈€缁堢殑鍒嗚〃鎯呭喌濡備笅锛?/p>
鏈€缁堥渶瑕佹牴鎹笉鍚岀殑鐘舵€佷娇鐢ㄤ笉鍚岀殑鏌ヨ鏂瑰紡锛屽洜涓虹儹鐐规暟鎹兘鍦? 鍦ㄤ笂闈㈢殑琛ㄦ媶鍒嗕腑涔熼渶瑕佹敞鎰忎互涓嬪嚑绉嶆儏鍐碉細 浠ュ瓧娈典负渚濇嵁锛屾寜鐓т竴瀹氱瓥鐣ワ紙hash銆乺ange 绛夛級锛屽皢涓€涓〃涓殑鏁版嵁鎷嗗垎鍒板涓〃涓€?/p>
鍦ㄨ繖绉嶅垎琛ㄧ瓥鐣ヤ腑锛?/p>
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝灏?user_action_record_log 鎸夌収鏈堜唤杩涜鎷嗗垎灏卞睘浜庢按骞冲垎琛ㄣ€?/p>
浠ュ瓧娈典负渚濇嵁锛屾寜鐓у瓧娈电殑娲昏穬鎬э紝灏嗚〃涓瓧娈垫媶鍒颁笉鍚岀殑琛紙涓昏〃鍜屾墿灞曡〃锛変腑銆?/p>
鍦ㄨ繖绉嶅垎琛ㄧ瓥鐣ヤ腑锛?/p>
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝灏?order 琛ㄥ垎涓?order_pri, order_sub 灏卞睘浜庡瀭鐩村垎琛?/p>
鍒嗚〃鏄拡瀵逛簬鍗曚釜鏁版嵁搴撳疄渚嬭繕娌″埌鐡堕鐨勬儏鍐典笅锛屽彧鏄崟琛ㄥ洜涓烘暟鎹噺澶у凡缁忚揪鍒扮摱棰?/p>
浠ュ瓧娈典负渚濇嵁锛屾寜鐓т竴瀹氱瓥鐣ワ紙hash銆乺ange 绛夛級锛屽皢涓€涓〃涓殑鏁版嵁鎷嗗垎鍒板涓〃涓€?/p>
鍦ㄨ繖绉嶆媶鍒嗙瓥鐣ヤ腑锛?/p>
杩欎釜鏄湅涓婂幓鍜屾按骞冲垎琛ㄥ緢鍍忥紝鍙笉杩囨槸閫氳繃绛栫暐鍒嗗埌浜嗕笉鍚岀殑搴撱€?/p>
浠ヨ〃涓轰緷鎹紝鎸夌収涓氬姟褰掑睘涓嶅悓锛屽皢涓嶅悓鐨勮〃鎷嗗垎鍒颁笉鍚岀殑搴撲腑銆?/p>
鍦ㄨ繖绉嶆媶鍒嗙瓥鐣ヤ腑锛?/p>
鍦ㄥ垎搴撴槸涓€涓瘮杈冮夯鐑︾殑鎿嶄綔锛屽洜涓哄垎搴撲細瀵艰嚧浜嬪姟澶勭悊楹荤儲銆佽法搴撹仛鍚堟暟鎹夯鐑︺€佹棤娉曡法搴?join 闂锛屽湪閫夋嫨鍒嗗簱绛栫暐鐨勬椂鍊欎竴瀹氳鑰冭檻瀹為檯闇€瑕併€傚鏋滃彲浠ュ垎琛ㄨВ鍐崇殑锛岄偅灏卞厛灏濊瘯鍒嗚〃锛岃€屼笉鏄洿鎺ュ垎搴撱€傚綋鐒跺鏋滀笉闇€瑕佽€冭檻浜嬪姟銆乯oin 绛夐棶棰橈紝閫変粈涔堟柟妗堥兘鏄彲浠ョ殑銆?/p>
鏈€绠€鍗曠殑鏂规硶鏄鍞竴id 杩涜 hash 鍙栨ā璁$畻锛屾瘮濡傛垜浠鍒?2 涓〃锛屽氨鍙互鐩存帴 hash(id) % 2, 杩欐牱灏卞彲浠ユ妸鏁版嵁鍒嗘垚 2 浠姐€?/p>
寤鸿锛氫娇鐢ㄨ繖绉嶅彇妯$殑鏂瑰紡锛屾帹鑽愬皢琛ㄥ垎涓?2 鐨勬鏂逛釜锛屾柟渚垮悗缁殑鎵╁ 鏌ヨ鍜屼慨鏀归兘鍙互閫氳繃 hash 鍙栨ā鐨勬柟娉曟煡鍒板搴旂殑琛ㄦ垨鑰呭簱銆?/p>
鎵╁鏂瑰紡锛?/p>
姣斿璁″垝鍒?2 涓〃锛屼絾鍥犱负鍚庣画鏁伴噺婵€澧烇紝2 涓〃涓嶅湪婊¤冻锛屽彲浠ョ洿鎺ュ皢鍒嗗尯涓暟缈诲€嶏紝鍙樻垚 4 涓〃锛屽垯鐜板湪閫昏緫涓?hash(id) % 4, 浠庡浘涓彲浠ョ湅鍑哄鏋滃垎鍖烘暟鏄?2 鐨勬鏂癸紝鍒欐瘡娆℃墿瀹癸紝鍙渶瑕佸涓婁竴娆¤〃鍦ㄨ繘琛屽搴?hash 鍙栨ā锛屽氨鑳藉啀娆″钩鍧囧垎閰嶏紝鍦ㄩ噸鏂板垎閰嶇殑杩囩▼涓紝鍐椾綑鐨勬暟鎹负 1/2 鏍规嵁鏌愪釜鏃堕棿娈垫潵鍒嗚〃涔熸槸涓€绉嶅彲琛岀殑鏂规锛屾椂闂村垎琛ㄤ笉瀛樺湪鎵╁鏃堕渶瑕佹竻娲楁暟鎹殑闂锛屼絾鏄渶瑕佹瘡闅斾竴娈垫椂闂村鍔犱竴涓垎鍖?/p>
鍙互鍒跺畾涓€涓浐瀹氱殑璺敱琛ㄨ繘琛屽垎鍖?/p>
涓嶇浣跨敤浣曠鏂瑰紡鍘诲垎搴撳垎琛紝鏁版嵁濡備綍褰掓。銆佹暟鎹綊妗e悗濡備綍淇濊瘉鐢ㄦ埛鑳芥煡璇㈠埌銆佸浣曚繚璇佷竴鑷存€х瓑绛夐兘闇€瑕佸幓鑰冭檻瑙e喅銆?/p>
鍥犱负灏嗘暟鎹垏鍒嗗埌浜嗕笉鍚岀殑琛ㄥ拰搴撲腑锛孧ySQL 鏈韩鐨勮嚜澧?id 灏变笉鑳戒繚璇佸敮涓€鎬т簡锛岃繖鏃跺€欓渶瑕佸叾浠栨柟妗堟潵淇濊瘉銆?/p>
鏂规寰堝锛岃嚜琛屽弬鑰冿紝淇濊瘉鍞竴鍗冲彲 灏嗘暟鎹媶鍒嗗埌涓嶅悓鐨勬暟鎹簱瀹炰緥鐨勬儏鍐碉紝灏变細鍑虹幇鍒嗗竷寮忎簨鍔¢棶棰橈紝鍒嗗竷寮忎簨鍔$殑鍑虹幇涔熶細褰卞搷鎬ц兘銆傚父瑙佺殑鍒嗗竷寮忎簨鍔$殑鏂规鏈夛細 鍏朵腑鍙互浣跨敤 Alibaba Seata 绛?/p>
璺ㄦ暟鎹簱鑺傜偣 join 鏈韩灏辨瘮杈冮夯鐑︼紝鐢氳嚦涓嶆敮鎸侊紝鍙互閫氳繃鍐椾綑鏁版嵁鐨勬柟寮忔潵鍑忓皯鍜岄伩鍏?join 鐨勬儏鍐碉紝鎴栬€呴€氳繃涓氬姟閫昏緫鏉ヨ繘琛宩oin 鎿嶄綔鑰屼笉鏄暟鎹簱 join 鍥犱负鏁版嵁鏈韩鍒嗗竷鍦ㄤ笉鍚岀殑鑺傜偣涓婏紝鎵€鏈夌殑鑺傜偣鏁版嵁鎵嶆槸鍏ㄩ泦锛屽鏁版嵁杩涜鎺掑簭鍜屽垎椤典篃鏄竴涓毦鐐归棶棰橈紝鏁版嵁閲忓皯鐨勬儏鍐典笅鍙互杩涜涓氬姟鏈嶅姟杩涜鍐呭瓨鍒嗛〉锛屾暟鎹噺澶х殑鏃跺€欏氨娌″姙娉曚娇鐢ㄤ簡銆?/p>
涓€浜涙暟鎹毦浠ョ粺璁★紝鍙兘闇€瑕佸叾浠栫殑涓夋柟缁熻鏂瑰紡锛屾垨鑰呴€氳繃涓€浜涘垎鏋愬紩鎿庢潵鍋氥€?/p>
鍥犱负鏁版嵁鍒嗗尯鏄牴鎹垎鐗囬敭鏉ュ尯鍒嗙殑锛屽鏋滄煡璇㈡潯浠朵腑瀛樺湪鍒嗙墖閿垯寰堝鏄撶殑瀹氫綅鍒版寚瀹氱殑鍒嗙墖锛屽鏋滄煡璇㈡潯浠朵腑涓嶅瓨鍦ㄥ垎鐗囩殑閿紝灏遍渶瑕佸叾浠栨柟寮忔煡璇細 涓婇潰鐨勪緥瀛愪腑涔熸湁鎻愬埌锛屽鏋滈浼扮殑鍒嗗尯涓嶅鐨勬儏鍐碉紝杩樿杩涜鎵╁鎿嶄綔锛屾柟妗堜腑涔熻灏嗚繖閮ㄥ垎鑰冭檻杩涘幓銆?/p>
鐩墠鍒嗗簱鍒嗚〃涓€浜涙垚鐔熺殑寮€婧愯В鍐虫柟妗堬細
select * from user_action_record_log_201610
union all
杩涜杩炴帴鏌ヨ锛屼緥濡?select * from user_action_record_log_201609 union all select * from user_action_record_log_201610
,褰撶劧鏈堜唤璺ㄥ害瓒婂ぇ union 瓒婂.閽堝璁㈠崟琛ㄧ殑澶勭悊
select * from order_pri where ...
鏉ュ畬鎴愶紝灏忛儴鍒嗛€氳繃 select op.*, os.* from order_pri op join order_sub os on os.parent_id = op.id where ...
鏉ュ畬鎴愶紝杩欐牱绯荤粺涔熺ǔ瀹氳繍琛屼簡涓€娈垫椂闂淬€傚洜涓鸿鍗曡〃鏈韩澧為暱杩樻槸鎸哄揩鐨勶紝杩欑鏂规杩囦簡涓€娈垫椂闂村氨涓嶈浜嗐€傝繖鏃跺€欐兂浜嗕竴涓嬭兘涓嶈兘浣跨敤鏃ュ織鐨勬柟妗堝憿锛屽洜涓哄晢瀹舵洿澶氬叧娉ㄧ殑鏄繎鏈熺殑璁㈠崟锛岃€屼笉鏄巻鍙茬殑璁㈠崟锛屽啀瀵硅繖閲岄潰杩涜姘村钩鍒嗚〃锛屾寜鐓у垱寤烘椂闂村垎锛佽骞插氨骞层€?/p>
select * from order_pri_201608
union all
杩涜杩炴帴鏌ヨ锛屼緥濡?select * from order_pri_201608 union all select * from order_pri_201609
,褰撶劧鏈堜唤璺ㄥ害瓒婂ぇ union 瓒婂.
澶у垎绫?/th>
鏈畬鎴愶紙uncompleted锛?/th>
宸插畬鎴愶紙completed锛?/th>
閫€娆撅紙refund锛?/th>
鍖呭惈灏忓垎绫?/td>
寰呬粯娆俱€佸緟鍙戣揣銆佸緟鏀惰揣
寰呮敹璐с€佸緟璇勪环銆佸凡鍏抽棴
閫€娆句腑
鏁版嵁閲?/td>
鏈€澶?7 澶╁唴鏁版嵁锛岄噺灏?/td>
鎵€鏈夌殑鏁版嵁锛岄噺澶?/td>
閫€娆炬湰韬鐜囧皬锛岄噺灏?/td>
order_pri_uncompleted
琛ㄤ腑锛屽垯鍙互浣跨敤姝e父鐨勬煡璇㈣鍙ワ紝鍚屾椂鍥犱负閲忕浉瀵瑰皯锛屼篃涓嶄細浜х敓鐡堕锛涘浜庢墍鏈夌殑鏁版嵁宸插畬鎴愶紙completed锛?/strong>鍥犱负鏈韩閲忓ぇ锛岃繕闇€璺ㄨ〃鏌ヨ銆傞€氳繃涓嶅悓鐘舵€侊紝涓嶅悓鏈堜唤鐨勬帶鍒舵渶缁堣揪鍒颁簡瀵逛簬涓氬姟鏉ヨ鐩稿浼樺寲鐨勬柟妗堛€?/p>
甯歌鐨勫嚑绉嶆蹇?/h2>
姘村钩鍒嗚〃
鍨傜洿鍒嗚〃
姘村钩鍒嗗簱
鍨傜洿鍒嗗簱
鍒嗗尯姝ラ
鍒嗗尯閿殑閫夊彇鍜屾柟娉曠ず渚?/h2>
鍞竴 ID
鏃堕棿鍒嗚〃
浣跨敤鍥哄畾鐨勮矾鐢辫〃
鍒嗗簱鍒嗚〃瑕侀潰涓寸殑闂
ID 闂
鍒嗗竷寮忎簨鍔?/h2>
璺ㄨ妭鐐规煡璇㈤棶棰?/h2>
join 闂
鎺掑簭鍜屽垎椤?/h3>
缁熻鍑芥暟
闈炲垎鐗囬敭涓婄殑鏌ヨ
鏁版嵁杩佺Щ鍜屾墿瀹?/h3>
鏀寔鍒嗗簱鍒嗚〃涓棿浠?/h2>