鐩綍
鏈珷鍖呭惈璁稿鍦ㄤ綘澶勭悊MySQL浠g爜鏃堕渶瑕佷簡瑙g殑浣犱簨鎯呫傚鏋滀綘鎯虫姇鍏ュ埌MySQL鐨勫紑鍙戜腑锛屾垨鎯宠鎺ヨЕ鍒版渶鏂扮殑涓棿鐗堟湰鐨勪唬鐮侊紝鎴栬呭氨鏄兂浜嗚В寮鍙戠殑杩涘害锛岃鍙傞槄2.8.3鑺傦紝鈥滀粠寮鍙戞簮浠g爜鏍戝畨瑁呪鐨勮鏄庛傚鏋滀綘瀵筂ySQL鐨勫唴閮ㄦ彃浠舵劅鍏磋叮锛屼綘涔熷彲浠ヨ闃呮垜浠殑鍐呴儴鎻掍欢閭欢鍒楄〃銆傝繖涓垪琛ㄧ殑娴侀噺鐩稿浣庝竴浜涖傛鐭ュ浣曡闃呯殑璇︽儏锛岃鍙傞槄1.7.1.1鑺傦紝鈥淢ySQL閭欢鍒楄〃鈥銆傚湪MySQL AB 鐨勬墍鏈夊紑鍙戜汉鍛橀兘鍦ㄥ唴閮ㄦ彃浠跺垪琛ㄩ噷锛 姝ゅ锛屾垜浠府鍔╅偅浜涙鍦ㄥ鐞哅ySQL浠g爜鐨勪汉銆傝闅忔剰浣跨敤杩欎釜閭欢鍒楄〃鏉ラ棶浠g爜鏈夊叧鐨勯棶棰橈紝涔熷彲鐢ㄥ畠鏉ュ彂閫佷綘鎯冲鐚粰MySQL椤圭洰鐨 琛ヤ竵锛
MySQL鏈嶅姟鍣ㄥ垱寤哄涓嬬嚎绋嬶細
TCP/IP 杩炴帴绾跨▼澶勭悊鎵鏈夎繛鎺ヨ姹傦紝骞朵负姣忎竴涓繛鎺ュ垱寤轰竴涓柊鐨勪笓鐢ㄧ嚎绋嬫潵澶勭悊璁よ瘉鍜孲QL鏌ヨ澶勭悊銆
Windows NT 骞冲彴涓婃湁涓涓悕涓虹閬撳鐞嗙▼搴忥紙pipe handler锛夌殑绾跨▼锛屽畠鍜屽悕涓虹閬撹繛鎺ヨ姹傦紙pipe connect requests锛夌殑TCP/IP杩炴帴绾跨▼鍋氬悓鏍风殑宸ヤ綔銆
淇″彿绾跨▼澶勭悊鎵鏈夌殑淇″彿锛岃繖涓嚎绋嬮氬父涔熷鐞嗘姤璀﹀拰璋冪敤process_alarm() 鍑芥暟鏉ュ己鍒朵娇寰楃┖闂叉椂闂村お闀跨殑杩炴帴瓒呮椂銆
鑻mysqld鏄笌DUSE_ALARM_THREAD绾跨▼涓璧风紪璇戠殑锛岃繖涓笓鐢ㄧ嚎绋嬫槸澶勭悊 鍒涘缓鐨勮鎶ョ殑銆傝繖涓嚎绋嬬敤鍦ㄤ竴浜泂igwait()鍑芥暟鏈夐棶棰樼殑绯荤粺涓婏紝鎴栬呯敤鍦ㄤ綘鎯冲湪搴旂敤绋嬪簭涓娇鐢╰hr_alarm()浠g爜鑰屼笉甯︿笓鐢ㄤ俊鍙峰鐞嗙嚎绋嬩箣鏃躲
鑻ユ兂浣跨敤flush_time=val閫夐」锛屼細鍒涘缓涓涓笓鐢ㄧ嚎绋嬩互缁欏畾鐨勬椂闂撮棿闅斿埛鏂版墍鏈夎〃鏍笺
姣忎釜杩炴帴閮芥湁瀹冭嚜宸辩殑绾跨▼銆
姣忎釜琚娇鐢↖NSERT DELAYED 鐨勪笉鍚岃〃鏍奸兘浼氭湁鑷繁鐨勭嚎绋嬨
鑻ヤ娇鐢ㄤ簡master-host, 鍒欎細鍒涘缓涓涓粠灞炵殑澶嶅埗绾跨▼浠庝富绾跨▼璇诲彇骞跺疄鏂芥洿鏂般
mysqladmin processlist 浠呮樉绀鸿繛鎺ワ紝INSERT DELAYED, 鍙婂鍒剁嚎绋
鍖呭惈鍦║nix婧愮爜鍜屼簩杩涘埗鍒嗗彂鐗堜腑鐨勬祴璇曠郴缁熷彲浠ヨ鐢ㄦ埛鍜屽紑鍙戜汉鍛樺MySQL浠g爜鏂借鍥炲綊娴嬭瘯銆傝繖浜涙祴璇曞彲浠ュ湪Unix涓婅繘琛岋紝鐩墠瀹冧滑杩樹笉鑳藉湪鍘熺敓鐨刉indows鐜涓嬭繘琛屻
褰撳墠鐨勬祴璇曟渚嬪浠朵笉鑳藉湪MySQL涓祴璇曟墍鏈変笢瑗匡紝浣嗘槸瀹冭兘鍙戠幇SQL澶勭悊浠g爜锛孫S/library鏂囦欢涓ぇ澶氭暟鏄庢樉鐨勭己闄凤紝骞朵笖鍦ㄦ祴璇曞浠舵柟闈篃鏄潪甯稿交搴曠殑銆傛垜浠殑缁堟瀬鐩爣鏄100%鐨勪唬鐮佽繘琛屾祴璇曘傛垜浠杩庡ぇ瀹剁粰鎴戜滑鐨勬祴璇曞浠舵坊鍔犲唴瀹广備綘鍙兘浼氱壒鍒兂璐$尞鍑洪偅浜涙鏌ヤ綘绯荤粺閲屽姛鑳芥у嵄鏈虹殑娴嬭瘯锛屽洜涓鸿繖灏嗙‘淇濇湭鏉ユ墍鏈夊彂琛岀増鐨凪ySQL浼氫笌浣犵殑搴旂敤绋嬪簭涓璧锋洿濂藉湴杩愯銆
娴嬭瘯绯荤粺鍖呮嫭涓涓祴璇曡瑷瑙i噴鍣(mysqltest)锛屼竴涓繍琛屾墍鏈夋祴璇曠殑澶栧3鑴氭湰(mysql-test-run)锛岀敤涓撶敤璇█缂栧啓鐨勬祴璇曟渚嬶紝浠ュ強瀹冧滑鐨勯鏈熺粨鏋溿傚湪绯荤粺涓婄紪璇戝ソ涔嬪悗锛屽湪婧愪唬鐮佺殑root涓嬮敭鍏make test 鎴杕ysql-test/mysql-test-run銆傚鏋滃畨瑁呬簡涓涓簩杩涘埗鍒嗗彂鐗堬紝 cd 鍒板畨瑁卹oot (濡 /usr/local/mysql), 鐒跺悗閿叆 scripts/mysql-test-run銆傛墍鏈夋祴璇曞簲璇ラ兘閫氳繃锛屽亣浣挎湁娌¢氳繃鐨勶紝鑻ユ槸涓涓狹ySQL閲岀殑缂洪櫡锛屼綘鍙互璇曠潃鎵炬壘鏄洜涓轰粈涔堬紝骞朵笖鎶ュ憡杩欎釜闂銆傝鍙傞槄27.1.2.3鑺傦紝鈥滃湪MySQL娴嬭瘯濂椾欢閲屾姤鍛婄己闄封銆
濡傛灉浣犳兂瑕佽繍琛屾祴璇曞浠剁殑鏈哄櫒涓婂凡缁忚繍琛屼簡涓涓 mysqld 锛屽彧瑕佸畠涓嶅崰鐢9306 鍜 9307绔彛锛屽氨涓嶇敤鍋滄帀瀹冦傚鏋滃崰鐢ㄤ簡鍏朵腑鐨勪竴涓紝浠ュ彲浠ョ紪杈mysql-test-run鎶婁富绔彛鍜岋紙鎴栵級浠庣鍙e彿鏀逛负鍏跺畠鍙敤鐨勩.
鍙娇鐢ㄤ笅闈㈡寚浠よ繍琛屽崟涓祴璇曟渚 mysql-test/mysql-test-run test_name.
鑻ヤ竴涓祴璇曟湭閫氳繃锛屼綘鍙互鐢--force閫夐」鏉ユ鏌ヨ繍琛岀潃鐨mysql-test-run鐪嬫槸鍚︽槸鍒殑娴嬭瘯鏈氳繃銆
浣犲彲浠ョ敤mysqltest 璇█缂栧啓浣犺嚜宸辩殑娴嬭瘯妗堜緥銆備笉骞稿湴鏄紝鎴戜滑杩樻病鏈夊啓瀹岀浉鍏虫柟闈㈠畬鏁村湴鏂囨。銆備絾鏄紝浣犲彲浠ユ煡鐪嬫垜浠幇鏈夌殑娴嬭瘯妗堜緥锛屽苟灏嗗畠浠綔涓鸿寖渚嬨備笅闈㈠嚑鐐瑰皢鏈夊姪浜庝綘鍏ユ墜锛
娴嬭瘯浣嶄簬 mysql-test/t/*.test
娴嬭瘯妗堜緥鍖呮嫭缁堟澹版槑锛屾祴璇曟渚嬬被浼间簬mysql鍛戒护琛屽鎴风鐨勮緭鍏ャ 榛樿鐨勫0鏄庢槸涓涓鍙戦佸埌MySQL鏈嶅姟鍣ㄧ殑鏌ヨ锛岄櫎闈炶繖涓0鏄庤璇嗗埆涓哄唴閮ㄥ懡浠わ紙濡 sleep锛夈
鎵鏈変骇鐢熺粨鏋滅殑鏌ヨ锛屼緥濡係ELECT, SHOW, EXPLAIN绛夛紝蹇呴』鍦 @/path/to/result/file涔嬪墠銆傞偅涓枃浠跺繀椤诲寘鍚湡鏈涚殑缁撴灉銆傜敓鎴愮粨鏋滄枃浠剁殑涓涓畝鍗曞姙娉曟槸鍦╩ysql-test鐩綍杩愯mysqltest -r < t/test-case-name.test 锛岀劧鍚庣紪杈戠敓鎴愮殑缁撴灉鏂囦欢锛屽鏋滈渶瑕侊紝鍙皢瀹冧滑璋冩暣鍒版兂瑕佺殑杈撳嚭绔傚湪閭g鎯呭喌涓嬶紝瑕佸皬蹇冮伩鍏嶆坊鍔犳垨鍒犻櫎浠讳綍涓嶅彲瑙佺殑瀛楃锛岀‘淇濆彧鏀瑰彉鏂囨湰鍜岋紙鎴栵級鍒犻櫎琛屻傚鏋滄彃鍏ヤ竴琛岋紝瑕佺‘淇濇彃鍏ョ殑鍖哄煙琚竴涓‖鏍囪瘑闅斿紑锛屼笖鍦ㄨ灏炬湁涓涓‖鏍囪瘑銆備綘鍙兘浼氭兂瑕佷娇鐢od -c鏉ョ‘淇濅綘鐨勬枃鏈紪杈戝櫒鍦ㄧ紪杈 姝ラ涓病鏈夋悶涔变换浣曚笢瑗裤傚綋浣犲彂鐜颁竴涓己闄疯屼笉寰椾笉缂栬緫mysqltest -r鐨勮緭鍑烘椂锛屾垜浠湡甯屾湜浣犱笉瑕佺紪杈戝畠銆
涓哄拰鎴戜滑鐨勮缃竴鑷达紝浣犲簲璇ユ妸浣犵殑缁撴灉鏂囦欢鏀惧湪mysql-test/r 鐩綍锛屽苟鍙栧悕涓簍est_name.result銆傚鏋滄祴璇曚骇鐢熶笉姝竴涓粨鏋滐紝浣犲簲璇ヤ娇鐢ㄨ濡 test_name.a.result锛宼est_name.b.result绛夎繖鏍风殑鍚嶅瓧銆
濡傛灉澹版槑杩斿洖涓涓敊璇紝浣犲彲浠ュ湪澹版槑鐨勫墠涓琛屼娇鐢--error error-number鏉ヨ缁嗚鏄庡畠銆傞敊璇彿鍙兘鏄敱鈥,鈥濆垎寮鐨勫彲鑳介敊璇彿鐨勫垪琛ㄣ
濡傛灉浣犳缂栧啓涓涓噸澶嶇殑娴嬭瘯妗堜緥锛屼綘搴旇鍦ㄦ祴璇曟枃浠剁殑绗竴琛屽啓锛歴ource include/master-slave.inc;銆傜敤connection master; 鍜 connection slave;鏉ュ垏鎹富妗堜緥鍜屼粠妗堜緥銆傚鏋滀綘闇瑕佸涓涓浛鎹㈢殑杩炴帴鍋氱偣浠涔堬紝瀵逛簬涓昏繛鎺ワ紝鐢╟onnection master1;锛屽浜庝粠杩炴帴锛岀敤connection slave1;銆
濡傛灉闇瑕佸湪涓涓惊鐜噷鍋氱偣浠涔堬紝鍙互鐢ㄤ簺杩欐牱鐨勫唴瀹癸細
let $1=1000; while ($1) { # do your queries here dec $1; }
鍦ㄦ煡璇箣闂翠紤鐪狅紝浣跨敤sleep鍛戒护銆傛鍛戒护鏀寔鍑犲垎涔嬪嚑绉掞紝鎵浠ワ紝渚嬪浣犳兂瑕佷紤鐪1.3绉掞紝浣犲彲浠ヤ娇鐢sleep 1.3; 鍛戒护銆
瀵逛綘鐨勬祴璇曟渚嬭杩愯甯﹂檮鍔犻夐」鐨勪粠妗堜緥锛屼互鍛戒护琛屾柟寮忔妸瀹冧滑鏀惧湪mysql-test/t/test_name-slave.opt銆傚浜庝富妗堜緥锛屾妸瀹冧滑鏀惧湪mysql-test/t/test_name-master.opt銆
濡傛灉瀵规祴璇曞浠舵湁闂锛屽拰鎯宠鐚嚭涓涓祴璇曟渚嬶紝鍙戦侀偖浠朵俊鎭埌MySQL 鍐呴儴鎻掍欢 閭欢鍒楄〃銆傝鍙傞槄1.7.1.1鑺傦紝鈥淢ySQL閭欢鍒楄〃鈥銆 铏界劧杩欎釜鍒楄〃涓嶆帴鍙楅檮浠讹紝浣犲彲浠ユ妸鐩稿叧鏂囦欢閫氳繃ftp涓婁紶鍒帮細ftp://ftp.mysql.com/pub/mysql/upload/
濡傛灉浣犵殑MySQL鐨勭増鏈病鏈夐氳繃娴嬭瘯濂椾欢锛屼綘鍙互閲囧彇濡備笅鎺柦锛
鍦ㄥ敖鍙兘澶氬湴鎵惧埌鍑洪敊涔嬫椂鐨勯敊璇箣鍓嶏紝涓嶈鍙戦佺己闄锋姤鍛娿傛煡鎵句箣鏃讹紝璇蜂娇鐢mysqlbug鑴氭湰姣斾究鎴戜滑鑳借幏鍙栦綘鐨勭郴缁熷拰MySQL鐗堟湰淇℃伅锛屽弬闃1.7.1.3鑺 锛屸滃浣曟姤鍛婄己闄锋垨闂鈥銆
纭繚鍖呭惈浜mysql-test-run鐨勮緭鍑猴紝浠ュ強 mysql-test/r鐩綍涓嬫墍鏈.reject鏂囦欢鐨勫唴瀹广
濡傛灉娴嬭瘯濂椾欢閲岀殑娴嬭瘯鏈氳繃锛岀敤濡備笅鍛戒护妫鏌ヤ竴涓嬬湅瀹冭嚜宸辫繍琛屾椂鏄惁閫氳繃娴嬭瘯锛
cd mysql-test mysql-test-run --local test-name
濡傛灉鏈兘閫氳繃锛屼綘搴旇鐢 --with-debug 閰嶇疆MySQL骞朵娇鐢--debug閫夐」鏉ヨ繍琛mysql-test-run銆傚鏋滆繖鏍蜂篃鏈兘閫氳繃锛岃鎶婅拷韪枃浠var/tmp/master.trace 涓婁紶鍒 ftp://ftp.mysql.com/pub/mysql/upload/ 浠ヤ究鎴戜滑鑳芥鏌ュ畠銆傝璁板緱涔熻鍖呭惈浣犵郴缁熺殑瀹屾暣鎻忚堪锛mysqld 浜岃繘鍒舵枃浠剁殑鐗堟湰锛屼互鍙婁綘鏄浣曠紪璇戝畠鐨勩
涔熻瘯鐫甯--force閫夐」杩愯涓涓mysql-test-run 锛岀湅鏄惁杩樻湁鍒殑娴嬭瘯鏈氳繃銆
濡傛灉浣犳槸鑷繁缂栬瘧鐨凪ySQL锛屾煡鐪嬫垜浠殑鎵嬪唽鐪嬬湅濡備綍鍦ㄤ綘鐨勫钩鍙颁笂缂栬瘧MySQL锛屾渶濂界敤涓涓湪http://dev.mysql.com/downloads/涓婃垜浠凡缁忎负浣犵紪璇戝ソ鐨勪簩杩涘埗鐗堟湰銆傛垜浠墍鏈夋爣鍑嗙殑浜岃繘鍒剁増鏈兘鑳介氳繃娴嬭瘯濂椾欢鐨勬祴璇曪紒
濡傛灉閿欒鏄疪esult length mismatch 鎴 Result content mismatch 锛岃繖鎰忓懗娴嬭瘯鐨勮緭鍑轰簬鏈熸湜鐨勮緭鍑轰笉鍖归厤锛岃繖鍙兘鏄湪MySQL鎴栦綘鐨mysqld 鐗堟湰閲岀殑缂洪櫡鍦ㄦ煇浜涚幆澧冧笅浜х敓绋嶆湁涓嶅悓鐨勭粨鏋溿
鏈氳繃鐨勬祴璇曠粨鏋滄斁鍦ㄥ拰缁撴灉鏂囦欢鍚屼富鍚嶄絾鎵╁睍鍚嶄负.reject鐨勬枃浠堕噷銆傚鏋滄祴璇曟渚嬫湭閫氳繃锛屼綘搴旇瀵逛袱涓枃浠跺仛diff鎿嶄綔銆傚鏋滀綘涓嶈兘鍙戠幇瀹冧滑鏄浣曚笉鍚岋紝鐢╫d -c 鍛戒护妫鏌ュ畠浠紝涔熸鏌ヤ竴涓嬫枃浠堕暱搴︺
濡傛灉娴嬭瘯瀹屽叏鏈氳繃锛屼綘搴旇妫鏌ysql-test/var/log鐩綍涓嬬殑鏃ュ織鏂囦欢浠ヨ幏寰楁湁鍏抽敊璇殑涓浜涙彁绀恒
濡傛灉浣犳槸涓鸿皟璇曡岀紪璇慚ySQL锛岃瘯涓涓嬪甫--gdb鍜岋紙鎴栵級--debug鍙傛暟杩愯mysql-test-run 銆傝鍙傞槄E.1.2鑺傦紝鈥滃垱寤鸿窡韪枃浠垛銆
濡傛灉浣犳病鏈変负璋冭瘯鑰岀紪璇慚ySQL锛岃繖搴旇鏄綘鍙兘鍘诲仛鐨勩傚彧瑕佸甫锛-with-debug鍙傛暟杩愯configure銆 璇峰弬闃2.8鑺傦紝鈥滀娇鐢ㄦ簮鐮佸垎鍙戠増瀹夎MySQL 鈥銆
鏈変袱涓斿緞鏉ヤ负MySQL娣诲姞鏂板嚱鏁帮細
浣犲彲浠ラ氳繃鑷鍖诲嚱鏁版帴鍙 (UDF)鏉ユ坊鍔犲嚱鏁般傝嚜瀹氫箟鍑芥暟琚紪璇戜负鐩爣鏂囦欢锛岀劧鍚庣敤CREATE FUNCTION 鍜孌ROP FUNCTION 澹版槑鍔ㄦ佸湴娣诲叆鍒版湇鍔″櫒涓強浠庢湇鍔″櫒涓Щ鍑恒傚弬闃27.2.2鑺傦紝鈥淐REATE FUNCTION/DROP FUNCTION 璇硶鈥銆
浣犲彲浠ュ皢鍑芥暟娣诲姞涓篗ySQL鍥烘湁锛堝唴寤猴級鍑芥暟銆傚浐鏈夊嚱鏁拌缂栬瘧杩mysqld鏈嶅姟鍣ㄤ腑锛屾垚涓烘案涔呭彲鐢ㄧ殑銆
姣忕閫斿緞閮芥湁鍏朵紭鐐瑰拰缂虹偣锛
濡傛灉浣犵紪鍐欒嚜瀹氫箟鍑芥暟锛屼綘闄や簡瀹夎鏈嶅姟鍣ㄦ湰韬箣澶栬繕瑕佸畨瑁呯洰鏍囨枃浠躲傚鏋滃皢浣犵殑鍑芥暟缂栬瘧杩涙湇鍔″櫒涓紝浣犲氨涓嶉渶瑕佽繖涔堝仛浜嗐
浣犲彲浠ョ粰浜岃繘鍒剁増鏈殑MySQL鍒嗗彂鐗堟坊鍔燯DF銆傚浐鏈夊嚱鏁伴渶瑕佷綘鍘讳慨姝f簮鐮佸垎鍙戠増銆.
濡傛灉浣犲崌绾т綘鐨凪ySQL鍒嗗彂鐗堬紝浣犲彲浠ョ户缁娇鐢ㄥ厛鍓嶅畨瑁呬簡鐨刄DF锛 闄ら潪浣犲崌绾у埌涓涓猆DF鎺ュ彛鏀瑰彉浜嗙殑鏂扮増鏈傚鍥烘湁鍑芥暟鑰岃█锛屾瘡娆″崌绾т綘閮藉繀椤婚噸澶嶄竴娆′慨姝c
鏃犺浣犱娇鐢ㄥ摢绉嶆柟娉曞幓娣诲姞鏂板嚱鏁帮紝瀹冧滑閮藉彲浠ヨSQL澹版槑璋冪敤锛屽氨鍍 ABS() 鎴 SOUNDEX()杩欐牱鐨勫浐鏈夊嚱鏁颁竴鏍枫
鍙︿竴涓坊鍔犲嚱鏁扮殑鏂规硶鏃跺垱寤哄瓨鍌ㄥ嚱鏁般傝繖浜涘嚱鏁版椂鐢⊿QL澹版槑缂栧啓鐨勶紝鑰屼笉鏄紪璇戠洰鏍囦唬鐮併傜紪鍐欏瓨鍌ㄥ嚱鏁扮殑璇硶鍦绗20绔狅細瀛樺偍绋嬪簭鍜屽嚱鏁 涓弿杩般
涓嬮潰鐨勫皬鑺傛弿杩癠DF鎺ュ彛鐨勭壒鎬э紝缁欏嚭缂栧啓UDF鐨勬寚浠わ紝骞惰璁篗ySQL涓洪槻姝DF琚鐢ㄨ岄噰鍙栫殑瀹夊叏棰勯槻鎺柦銆
缁欏嚭婧愪唬鐮佺殑渚嬪瓙鏉ヨ鏄庡浣曠紪鍐橴DF锛岀湅涓鐪婱ySQL婧愮爜鍒嗗彂鐗堜腑鎻愪緵鐨剆ql/udf_example.cc 鏂囦欢銆
MySQL鑷畾涔夊嚱鏁版帴鍙f湁濡備笅鐗规у拰鍔熻兘锛
鍑芥暟鑳藉垎梅杩斿洖瀛楃涓诧紝鏁存暟鎴栧疄鏁般
浣犲彲浠ュ畾涔変竴娆′綔鐢ㄤ簬涓琛岀殑绠鍗曞嚱鏁帮紝鎴栦綔鐢ㄤ簬澶氳鐨勭粍鐨勯泦鍚堝嚱鏁般
鎻愪緵缁欏嚱鏁扮殑淇℃伅浣垮緱鍑芥暟鍙互妫鏌ヤ紶閫掔粰瀹冧滑鐨勫弬閲忕殑鏁扮洰鍜岀被鍨嬨
浣犲彲浠ヨMySQL鍦ㄥ皢鏌愬弬閲忎紶閫掔粰鍑芥暟涔嬪墠寮哄埗鍏朵负鏌愪竴绫诲瀷銆
浣犲彲浠ヨ〃绀哄嚱鏁拌繑鍥濶ULL 鎴栧彂鐢熼敊璇
CREATE [AGGREGATE] FUNCTION function_name RETURNS {STRING|INTEGER|REAL} SONAME shared_library_name DROP FUNCTION function_name
涓涓嚜瀹氫箟鍑芥暟 (UDF)灏辨槸鐢ㄤ竴涓薄ABS() 鎴 CONCAT()杩欐牱鐨勫浐鏈夛紙鍐呭缓锛夊嚱鏁颁竴鏍蜂綔鐢ㄧ殑鏂板嚱鏁板幓鎵╁睍MySQL銆
function_name 鏄 鐢ㄥ湪SQL澹版槑涓互澶囪皟鐢ㄧ殑鍑芥暟鍚嶅瓧銆俁ETURNS 瀛愬彞璇存槑鍑芥暟杩斿洖鍊肩殑绫诲瀷銆 shared_library_name 鏄叡浜洰鏍囨枃浠剁殑鍩烘湰鍚嶏紝鍏变韩鐩爣鏂囦欢鍚湁瀹炵幇鍑芥暟鐨勪唬鐮併傝鏂囦欢蹇呴』浣嶄簬涓涓兘琚綘绯荤粺鐨勫姩鎬佽繛鎺ヨ呮悳绱㈢殑鐩綍閲屻
浣犲繀椤绘湁mysql 鏁版嵁搴撶殑INSERT 鏉冮檺鎵嶈兘鍒涘缓涓涓嚱鏁帮紝浣犲繀椤绘湁mysql 鏁版嵁搴撶殑DELETE鏉冮檺鎵嶈兘鎾ら攢涓涓嚱鏁般傝繖鏄洜涓篊REATE FUNCTION 寰璁板綍鍑芥暟鍚嶅瓧锛岀被鍨嬪拰鍏变韩鍚嶇殑mysql.func绯荤粺琛ㄩ噷娣诲姞浜嗕竴琛岋紝鑰孌ROP FUNCTION鍒欐槸浠庤〃涓垹鎺夎繖涓琛屻傚鏋滀綘娌℃湁杩欎釜绯荤粺琛紝浣犲簲璇ヨ繍琛mysql_fix_privilege_tables鑴氭湰鏉ュ垱寤轰竴涓傝鍙傞槄2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥銆
涓涓湁鏁堢殑鍑芥暟鏄竴涓敤CREATE FUNCTION鍔犺浇涓旀病鏈夌敤DROP FUNCTION绉婚櫎鐨勫嚱鏁般傛瘡娆℃湇鍔″櫒鍚姩鐨勬椂鍊欎細閲嶆柊鍔犺浇鎵鏈夋湁鏁堝嚱鏁帮紝闄ら潪浣犱娇鐢--skip-grant-tables鍙傛暟鍚姩mysqld銆傚湪杩欑鎯呭喌涓嬶紝 灏嗚烦杩嘦DF鐨勫垵濮嬪寲锛孶DF涓嶅彲鐢ㄣ
瑕佷簡瑙g紪鍐欒嚜瀹氫箟鍑芥暟鐨勮鏄庯紝璇峰弬闃27.2.3鑺傦紝鈥滄坊鍔犳柊鐨勮嚜瀹氫箟鍑芥暟鈥銆傝浣垮緱UDF鏈哄埗鑳藉璧蜂綔鐢紝蹇呴』浣跨敤C鎴栬匔++缂栧啓鍑芥暟锛屼綘鐨勭郴缁熷繀椤绘敮鎸佸姩鎬佸姞杞斤紝鑰屼笖浣犲繀椤绘槸鍔ㄦ佺紪璇戠殑mysqld锛堥潪闈欐侊級銆
涓涓狝GGREGATE鍑芥暟灏卞儚涓涓狹ySQL鍥烘湁鐨勯泦鍚堬紙鎬诲拰锛夊嚱鏁颁竴鏍疯捣浣滅敤锛屾瘮濡傦紝SUM鎴朇OUNT()鍑芥暟銆傝浣垮緱AGGREGATE 璧蜂綔鐢紝浣犵殑mysql.func琛ㄥ繀椤诲寘鎷竴涓猼ype鍒椼傚鏋滀綘鐨刴ysql.func琛ㄦ病鏈夎繖涓 鍒楋紝浣犲簲璇ヨ繍琛mysql_fix_privilege_tables鑴氭湰鏉ュ垱寤烘 鍒椼
瑕佷娇寰桿DF鏈哄埗鑳藉璧蜂綔鐢紝蹇呴』浣跨敤C鎴栬匔++缂栧啓鍑芥暟锛屼綘鐨勭郴缁熷繀椤绘敮鎸佸姩鎬佸姞杞姐侻ySQL 婧愮爜鍒嗗彂鐗堝寘鎷竴涓猻ql/udf_example.cc 鏂囦欢锛屾鏂囦欢瀹氫箟浜5涓柊鍑芥暟銆傚彲浠ュ弬鑰冭繖涓枃浠讹紝鐪婾DF鏄浣曡皟鐢ㄥ父瑙勫伐浣溿
涓轰簡鑳戒娇鐢║DF锛屼綘闇瑕佸姩鎬侀摼鎺mysqld銆備笉瑕侀厤缃甅ySQL浣跨敤--with-mysqld-ldflags=-all-static鍙傛暟銆傚鏋滀綘鎯充娇鐢ㄤ竴涓渶瑕佷粠mysqld 璁块棶绗﹀彿鐨刄DF锛堜緥濡傚湪浣跨敤default_charset_info鐨剆ql/udf_example.cc鏂囦欢涓殑metaphone鍑芥暟锛夛紝浣犲繀椤讳娇鐢-rdynamic鍙傛暟鏉ラ摼鎺ョ▼搴忥紙鍙傞槄man dlopen锛夈傚鏋滀綘璁″垝浣跨敤UDF, 涓涓粡楠屾硶鍒欏氨鏄紝鐢╳ith-mysqld-ldflags=-rdynamic璁惧畾MySQL锛岄櫎闈炰綘鏈夊緢濂界殑鐞嗙敱涓嶅幓杩欎箞鍋氥
濡傛灉浣犱娇鐢ㄧ殑鏄缂栬瘧鍒嗗彂鐗堢殑MySQL锛 璇蜂娇鐢∕ySQL-Max锛屽叾涓惈鏈変竴涓姩鎬侀摼鎺ヤ簡鐨勬湇鍔″櫒锛屽畠鍙互鏀寔鍔ㄦ佸姞杞姐
瀵逛簬姣忎釜浣犳兂瑕佷娇鐢ㄥ湪SQL澹版槑涓殑鍑芥暟锛屼綘搴旇瀹氫箟鐩稿簲鐨凜 锛堟垨 C++锛夊嚱鏁般傚湪涓嬮潰鐨勮璁轰腑锛寈xx鐢ㄦ潵琛ㄧず鑼冧緥鍑芥暟鐨勫悕瀛楋紝涓轰簡鍖哄垎浣跨敤SQL杩樻槸C/C++锛寈xx()(涓婃爣锛夎〃绀篠QL鍑芥暟璋冪敤锛寈xx()锛堜笅鏍囷級琛ㄧずC/C++鍑芥暟璋冪敤銆
浣犱负xxx()缂栧啓鏉ュ疄鐜版帴鍙g殑C/C++ 鍑芥暟濡備笅锛
xxx() (蹇呮湁)
涓诲嚱鏁般 杩欐槸鍑芥暟缁撴灉琚绠楃殑鍦版柟銆係QL鍑芥暟鏁版嵁绫诲瀷涓嶤/C++鍑芥暟杩斿洖绫诲瀷鐨勫搴斿叧绯诲涓嬶細
SQL 绫诲瀷 | C/C++ 绫诲瀷 |
STRING | char * |
INTEGER | long long |
REAL | double |
xxx_init() (鍙)
瀵箈xx()鐨勫垵濮嬪寲鍑芥暟銆傚畠鍙互琚敤鏉ワ細
妫鏌ヤ紶閫掔粰xxx()鐨勫弬閲忔暟鐩
妫鏌ュ弬閲忔槸鍚︿负蹇呴渶鐨勭被鍨嬶紝鎴栬咃紝闄ゆ涔嬪锛屽湪涓诲嚱鏁拌璋冪敤鐨勬椂鍊欏憡璇塎ySQL灏嗗弬閲忓己鍒朵负鎯宠鐨勭被鍨嬨
鍒嗛厤涓诲嚱鏁伴渶瑕佺殑鍐呭瓨銆
鎸囧畾缁撴灉鐨勬渶澶ч暱搴︺
鎸囧畾锛堝浜嶳EAL 鍑芥暟锛夊皬鏁扮殑鏈澶氫綅鏁般
鎸囧畾缁撴灉鏄惁鍙互涓 NULL銆
xxx_deinit() 锛堝彲閫夛級
瀵箈xx()鐨勫幓鍒濆鍖栧嚱鏁般傚畠閲婃斁鍒濆鍖栧嚱鏁板垎閰嶇殑鍐呭瓨銆
褰揝QL澹版槑璋冪敤XXX()鏃讹紝MySQL璋冪敤鍒濆鍖栧嚱鏁皒xx_init()锛岃瀹冩墽琛屽繀瑕佺殑璁剧疆锛屾瘮濡傦紝妫鏌 鍙傞噺鎴栧垎閰嶅唴瀛樸傚鏋渪xx_init() 杩斿洖涓涓敊璇紝SQL澹版槑浼氶鍑哄苟缁欏嚭閿欒淇℃伅锛岃屼富鍑芥暟鍜屽幓鍒濆鍖栧嚱鏁板苟娌℃湁琚皟鐢ㄣ 鍚﹀垯锛屼富鍑芥暟xxx() 瀵规瘡涓琛岄兘琚皟鐢ㄤ竴娆°傛墍鏈夎閮藉鐞嗗畬涔嬪悗锛岃皟鐢ㄥ幓鍒濆鍖栧嚱鏁皒xx_deinit() 鎵ц蹇呰鐨勬竻闄ゃ
瀵逛簬璞UM()涓鏍峰伐浣滅殑闆嗗悎鍑芥暟锛屼綘涔熷繀椤绘彁渚涘涓嬬殑鍑芥暟锛
xxx_clear() 锛堝湪5.1鑺備腑蹇呴』锛
瀵逛竴涓柊缁勯噸缃綋鍓嶉泦鍚堝间负鍒濊瘯闆嗗悎鍊硷紝浣嗕笉鎻掑叆浠讳綍鍙傞噺銆
xxx_add() 锛堝繀椤伙級
娣诲姞鍙傞噺鍒板綋鍓嶉泦鍚堝笺
MySQL 鎸変笅鍒楁搷浣滄潵澶勭悊闆嗗悎UDF锛
璋冪敤 xxx_init() 璁╅泦鍚堝嚱鏁板垎閰嶅畠闇瑕佺敤鏉ュ瓨鍌ㄧ粨鏋滅殑鍐呭瓨銆
鎸夌収GROUP BY琛ㄨ揪寮忔潵鎺掑簭琛ㄣ
涓烘瘡涓柊缁勪腑鐨勭涓琛岃皟鐢▁xx_clear()鍑芥暟銆
涓哄睘浜庡悓缁勭殑姣忎竴涓柊琛岃皟鐢▁xx_add()鍑芥暟銆
褰撶粍鏀瑰彉鏃舵垨姣忕粍鐨勬渶鍚庝竴琛岃澶勭悊瀹屼箣鍚庯紝璋冪敤xxx()鏉ヨ幏鍙栭泦鍚堢粨鏋溿
閲嶅锛屼互涓3-姝ョ洿鍒版墍鏈夎琚鐞嗗畬銆
璋冪敤xxx_deinit() 鍑芥暟鍘婚噴鏀綰DF鍒嗛厤鐨勫唴瀛樸.
鎵鏈夊嚱鏁板繀椤绘椂绾跨▼瀹夊叏鐨勶紝杩欎笉浠呭涓诲嚱鏁帮紝瀵瑰垵濮嬪寲鍜屽幓鍒濆鍖栧嚱鏁颁篃涓鏍凤紝涔熷寘鎷泦鍚堝嚱鏁拌姹傜殑闄勫姞鍑芥暟銆傝繖涓姹傜殑涓涓粨鏋滃氨鏄紝浣犱笉鑳藉垎閰嶄换浣曞彉鍖栫殑鍏ㄥ眬鎴栭潤鎬佸彉閲忋傚鏋滀綘闇瑕佸唴瀛橈紝浣犲彲浠ュ湪xxx_init()鍑芥暟鍒嗛厤鍐呭瓨锛岀劧鍚庡湪xxx_deinit()鍑芥暟閲婃斁鎺夈
涓嬮潰浠嬬粛鍒涘缓绠鍗昒DF鏃堕渶瑕佸畾涔夌殑涓嶅悓鍑芥暟銆27.2.3鑺傦紝鈥滄坊鍔犳柊鐨勮嚜瀹氫箟鍑芥暟鈥涓粙缁嶄簡MySQL璋冪敤杩欎簺鍑芥暟鐨勯『搴忋
濡傛湰鑺傛墍绀猴紝搴旇璇存槑涓诲嚱鏁皒xx()銆傛敞鎰忚繑鍥炲煎拰鍙傛暟浼氭湁鎵涓嶅悓锛岃繖鍙栧喅浜庝綘璇存槑鐨凷QL鍑芥暟xxx()鍦–REATE FUNCTION澹版槑涓繑鍥炵殑鏄疭TRING锛孖NTEGER绫诲瀷杩樻槸REAL绫诲瀷绀猴細
瀵逛簬STRING 鍨嬪嚱鏁帮細
char *xxx(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error);
瀵逛簬INTEGER鍨嬪嚱鏁帮細
long long xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
瀵逛簬REAL鍨嬪嚱鏁帮細
double xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
鍒濆鍖栧拰鍘诲垵濮嬪寲鍑芥暟濡備笅璇存槑锛
my_bool xxx_init(UDF_INIT *initid, UDF_ARGS *args, char *message); void xxx_deinit(UDF_INIT *initid);
initid 鍙傛暟琚紶閫掔粰鎵鏈夌殑涓変釜鍑芥暟銆傚畠鎸囧悜涓涓猆DF_INIT 缁撴瀯锛岃繖涓粨鏋勮鐢ㄦ潵鍦ㄥ嚱鏁颁箣闂翠氦鎹俊鎭俇DF_INIT 缁撴瀯椤硅窡闅忕潃銆傚垵濮嬪寲鍑芥暟搴旇缁欎换浣曞畠鎯宠鏀瑰彉鐨勯」璧嬪笺傦紙瑕佷娇鐢ㄩ」鐨勯粯璁ゅ硷紝灏辫瀹冧笉琚敼鍙橈級
my_bool maybe_null
濡傛灉xxx() 鑳借繑鍥濶ULL锛寈xx_init()搴攎aybe_null 涓 1 銆傚鏋滀换涓鍙傞噺琚鏄庝簡 maybe_null鍊硷紝鍏 榛樿鍊兼槸1 銆
unsigned int decimals
灏忔暟浣嶆暟銆傞粯璁ゅ兼槸浼犲埌涓诲嚱鏁扮殑鍙傞噺閲屽皬鏁扮殑鏈澶т綅鏁般傦紙渚嬪锛屽鏋滃嚱鏁颁紶閫 1.34, 1.345, 鍜1.3, 閭d箞榛樿鍊间负锛屽洜涓1.345 鏈3浣嶅皬鏁般
unsigned int max_length
缁撴灉鐨勬渶澶ч暱搴︺俶ax_length 鐨勯粯璁ゅ煎洜鍑芥暟鐨勭粨鏋滅被鍨嬭屽紓銆傚瀛楃涓插嚱鏁帮紝榛樿鍊兼槸鏈闀垮弬閲忕殑闀垮害銆傚鏁村瀷鍑芥暟锛岄粯璁ゆ槸21浣嶃傚瀹炲瀷鍑芥暟锛岄粯璁ゆ槸13鍐嶅姞涓奿nitid->decimals鎸囩ず鐨勫皬鏁颁綅鏁般傦紙瀵规暟瀛楀嚱鏁帮紝闀垮害鍖呭惈姝h礋鍙锋垨鑰呭皬鏁扮偣绗︼級銆
濡傛灉鎯宠繑鍥炲洟鍊硷紝浣犲彲浠ユ妸max_length 璁句负浠65KB鍒16MB銆傝繖涓唴瀛樹笉浼氳鍒嗛厤锛屼絾鏄鏋滄湁涓存椂鏁版嵁闇瑕佸瓨鍌紝杩欎釜璁剧疆浜嗙殑鍊艰鐢ㄦ潵鍐冲畾浣跨敤鍝 鍒楃殑绫诲瀷銆
char *ptr
鍑芥暟鍙互鐢ㄤ綔鏈韩鐩殑鐨勬寚閽堛傛瘮濡傦紝鍑芥暟鍙互鐢╥nitid->ptr 鏉ュ湪鍒嗛厤浜嗙殑鍐呭瓨鍐呴儴閫氳銆 xxx_init() 搴旇鍒嗛厤鍐呭瓨锛屽苟鎸囨淳缁欒繖涓寚閽堬細
initid->ptr = allocated_memory;
鍦 xxx() 鍜 xxx_deinit()涓紝鍊熺敤 initid->ptr 鏉ヤ娇鐢ㄦ垨鍒嗛厤鍐呭瓨銆
鏈妭浠嬬粛鍒涘缓闆嗗悎UDF涔嬫椂闇瑕佸畾涔夌殑涓嶅悓鍑芥暟銆27.2.3鑺傦紝鈥滄坊鍔犳柊鐨勮嚜瀹氫箟鍑芥暟鈥 浠嬬粛浜哅ySQL璋冪敤杩欎簺鍑芥暟鐨勯『搴忋
xxx_reset()
褰揗ySQL鍦ㄤ竴涓柊缁勪腑鍙戠幇绗竴琛屾椂璋冪敤杩欎釜鍑芥暟銆傚畠瀵硅繖涓粍閲嶇疆浠讳綍鍐呴儴鎬诲拰鍙橀噺锛岀劧鍚庝娇鐢ㄧ粰瀹氱殑UDF_ARGS鍙傞噺浣滀负鍐呴儴鎬诲拰鍊肩殑绗竴涓笺傚涓嬭鏄 xxx_reset() 鍑芥暟锛
char *xxx_reset(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
鍦∕ySQL5.1鐗堜腑UDF鎺ュ彛涓嶉渶瑕佹垨涓嶄娇鐢▁xx_reset()鍑芥暟锛岃屾槸浣跨敤xxx_clear()鍑芥暟浣滀负鏇夸唬銆備絾鏄鏋滀綘鎯宠UDF涔熻兘鍦ㄨ佺増鏈殑鏈嶅姟鍣ㄤ笂杩愯锛屼綘涔熷彲浠ュ畾涔 xxx_reset() 鍜 xxx_clear() 鍑芥暟銆傦紙濡傛灉浣犱娇鐢ㄤ簡杩欎袱涓嚱鏁帮紝xxx_reset()鍑芥暟鍦ㄥ緢澶氭儏鍐典笅鍙互閫氳繃璋冪敤鍑芥暟鏉ュ唴閮ㄥ疄鐜帮紝鍗宠皟鐢▁xx_clear()鍑芥暟閲嶇疆鎵鏈夊彉閲忥紝鐒跺悗娣诲姞UDF_ARGS鍙傞噺浣滀负缁勭殑绗竴涓笺傦級
xxx_clear()
褰揗ySQL闇瑕侀噸缃诲拰缁撴灉鏃惰皟鐢ㄦ鍑芥暟銆傚姣忎竴涓柊缁勶紝鍦ㄥ紑濮嬩箣鏃惰皟鐢ㄥ畠锛屼絾鏄畠涔熷彲浠ヨ璋冪敤鏉ヤ负涓涓病鏈夊尮閰嶈鍦ㄥ叾涓殑鏌ヨ閲嶇疆鍊笺傚涓嬭鏄巟xx_clear()锛
char *xxx_clear(UDF_INIT *initid, char *is_null, char *error);
鍦ㄨ皟鐢▁xx_clear()涔嬪墠is_null 琚缃寚鍚 CHAR(0) 銆
濡傛灉鍙戠敓閿欒锛屼綘鍙互瀛樺偍涓涓煎湪 error鍙傞噺鎸囧悜鐨勫彉閲忎腑銆俥rror鎸囧悜涓鍗曞瓧鑺傚彉閲忥紝鑰屼笉鏄竴涓瓧绗︿覆缂撳啿鍖恒
xxx_clear() 鏄疢ySQL 5.1蹇呴』鐨勩
xxx_add()
涓哄悓缁勯櫎浜嗙涓琛屼箣澶栵紝鎵鏈夌殑琛岃皟鐢ㄨ繖涓嚱鏁般備綘搴旇鐢ㄥ畠鍦║DF_ARGS鍙傞噺涓悜鍐呴儴鎬诲拰鍙橀噺鍔犲笺.
char *xxx_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
瀵归泦鍚圲DF鑰岃█xxx() 鍑芥暟搴旇鐢ㄤ笌闈為泦鍚圲DF涓鏍风殑鏂规硶鏉ヨ鏄庛傝鍙傞槄27.2.3.1鑺傦紝鈥淯DF璋冪敤绠鍗曞嚱鏁扮殑椤哄簭鈥銆
瀵逛竴涓泦鍚圲DF锛孧ySQL 鍦ㄧ粍鍐呮墍鏈夎琚鐞嗕箣鍚庤皟鐢▁xx()鍑芥暟銆傝繖閲屼綘搴旇涓鑸笉浼氭帴瑙﹀埌瀹冪殑UDF_ARGS鍙傞噺锛屼絾鏄彇鑰屼唬涔嬪湴鏍规嵁鍐呴儴鎬诲拰鍙橀噺杩斿洖缁欎綘鍊笺
鍦▁xx()涓鐞嗙殑杩斿洖鍊煎簲璇ョ敤涓庡闈為泦鍚圲DF涓鏍风殑鏂规硶鏉ユ搷浣溿傝鍙傞槄27.2.3.4鑺傦紝鈥淯DF杩斿洖鍊煎拰閿欒澶勭悊鈥銆
xxx_reset() 鍜 xxx_add() 鍑芥暟鐢ㄤ笌闈為泦鍚圲DF涓鏍风殑鏂规硶鏉ュ鐞嗗畠浠殑UDF_ARGS 鍙傞噺銆傝鍙傞槄27.2.3.3鑺傦紝鈥淯DF鍙傞噺澶勭悊鈥銆
鍒癷s_null鍜宔rror鐨勬寚閽 鍙傞噺鍜屾墍鏈夊埌xxx_reset(), xxx_clear(), xxx_add() 鍜 xxx()璋冪敤涓鏍枫備綘鍙互鐢ㄨ繖涓潵鎻愰啋浣犺幏鍙栦竴涓敊璇垨鏃犺xxx()鏄惁杩斿洖NULL鐨勪竴涓粨鏋溿備綘涓嶈兘鎶婁竴涓瓧绗︿覆瀛樺埌*error锛乪rror鎸囧悜鍗曞瓧鑺傚彉閲忚屼笉鏄瓧绗︿覆缂撳啿鍖恒
*is_null 瀵规瘡涓涓粍閮介噸缃紙璋冪敤xxx_clear()鍓嶏級锛 *error 浠庝笉閲嶇疆銆
濡傛灉 xxx()杩斿洖鏃讹紝*is_null 鎴 *error 琚缃紝MySQL杩斿洖 NULL浣滀负缁勫嚱鏁扮殑缁撴灉銆
args 鍙傛暟鎸囧悜鍒楃潃缁撴瀯鍏冪殑 UDF_ARGS 缁撴瀯锛
unsigned int arg_count
鍙傞噺涓暟銆傚鏋滀綘闇瑕佷綘鐨勫嚱鏁板甫鐫鏌愪釜鏁扮洰鐨勫弬閲忚璋冪敤锛屽湪鍒濆鍖栧嚱鏁版鏌ヨ繖涓硷紝渚嬪锛
if (args->arg_count != 2) { strcpy(message,"XXX() requires two arguments"); return 1; }
enum Item_result *arg_type
涓涓寚閽堬紝瀵规瘡涓弬閲忔寚鍚戝寘鍚被鍨嬬殑涓涓暟鍒椼傚彲鑳界殑绫诲瀷鍊兼槸STRING_RESULT, INT_RESULT 鍜 REAL_RESULT銆
瑕佺‘淇′竴涓弬閲忔槸缁欏畾绫诲瀷鐨勶紝骞朵笖濡傛灉涓嶆槸鐨勮瘽灏辫繑鍥炰竴涓敊璇紝璇锋鏌ュ垵濮嬪寲鍑芥暟涓殑arg_type鏁板垪銆傛瘮濡傦細
if (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != INT_RESULT) { strcpy(message,"XXX() requires a string and an integer"); return 1; }
瑕佹眰浣犲嚱鏁扮殑鍙傞噺鏄煇涓绫诲瀷鐨勫彟涓鏂规硶鏄紝浣跨敤鍒濆鍖栧嚱鏁拌缃產rg_type鍏冪礌涓轰綘鎯宠鐨勭被鍨嬨傚鎵鏈夊xxx()鐨勮皟鐢ㄨ岃█锛岃繖浼氬鑷碝ySQL寮哄埗鍙傞噺涓鸿繖浜涚被鍨嬨傛瘮濡傦紝瑕佹寚瀹氭姇涓や釜鍙傞噺寮哄埗鎴愬瓧绗︿覆鍜屾暣鏁帮紝鍦▁xx_init()涓垎鍒細
args->arg_type[0] = STRING_RESULT; args->arg_type[1] = INT_RESULT;
char **args
args->args 涓庡垵濮嬪寲鍑芥暟鍋氭湁鍏充紶鍒颁綘鍑芥暟鐨勫弬閲忕殑涓鑸儏鍐靛仛閫氳銆傚浜庡父鍙傞噺i锛宎rgs->args[i] 鎸囧悜鍙傞噺鍊笺傦紙鐪嬩笅闈㈢殑璇存槑浜嗚В濡備綍濡ュ杽鍦拌闂繖涓硷級銆傚闈烇紞甯稿弬閲忥紝args->args[i] 涓 0銆備竴涓父鍙傞噺涓轰粎浣跨敤鍙傞噺鐨勮〃杈惧紡锛屽 3 鎴 4*7-2 鎴 SIN(3.14)銆備竴涓潪甯 鍙傞噺鏄竴涓涓庤涓嶅悓鐨勮〃杈惧紡锛屽锛屽垪鍚嶆垨甯﹂潪锛嶅父鍙傞噺璋冪敤鐨勫嚱鏁般
瀵逛富鍑芥暟鐨勬瘡娆¤皟鐢紝args->args 鍖呭惈涓烘瘡涓綋鍓嶅鐞嗙殑琛屼紶閫掔殑瀹為檯鍙傞噺銆
濡備笅浣跨敤鍙傞噺i鐨勫嚱鏁帮細
缁欎竴涓猄TRING_RESULT 鍨嬬殑鍙傞噺浣滀负涓涓瓧绗︿覆鍔犱竴涓暱搴︼紝鍙互鍏佽鎵鏈変簩杩涘埗鏁版垨浠绘剰闀垮害鐨勬暟澶勭悊銆傚瓧绗︿覆鍐呭浣滀负args->args[i] 鑰屽瓧绗︿覆闀垮害涓篴rgs->lengths[i]銆備綘涓嶈兘閲囩敤null缁撳熬鐨勫瓧绗︿覆銆
瀵逛竴涓狪NT_RESULT鍨嬬殑鍙傞噺锛屼綘蹇呴』杞崲args->args[i] 涓轰竴涓猯ong long 鍊硷細
long long int_val; int_val = *((long long*) args->args[i]);
瀵逛竴涓猂EAL_RESULT鍨嬪弬閲忥紝浣犲繀椤昏浆鎹rgs->args[i]涓轰竴涓弻绮惧害鍊硷細
double real_val; real_val = *((double*) args->args[i]);
unsigned long *lengths
瀵瑰垵濮嬪寲鍑芥暟锛宭engths鏁板垪琛ㄧず瀵规瘡涓弬閲忕殑鏈澶у瓧绗︿覆闀垮害銆備綘涓嶈鏀瑰彉瀹冦傚涓诲嚱鏁扮殑姣忔璋冪敤锛宭engths鍖呭惈浜嗗褰撳墠澶勭悊琛屼紶閫掔殑浠讳綍瀛楃涓 鍙傞噺鐨勫疄闄呴暱搴︺傚浜嶪NT_RESULT 鎴 REAL_RESULT绫诲瀷鐨勫弬閲忥紝lengths 浠嶅寘鍚弬閲忕殑鏈澶ч暱搴︼紙瀵瑰垵濮嬪寲鍑芥暟锛夈
濡傛灉娌℃湁閿欒鍙戠敓锛屽垵濮嬪寲鍑芥暟搴旇杩斿洖0锛屽惁鍒欏氨杩斿洖1銆傚鏋滄湁閿欒鍙戠敓锛寈xx_init() 搴旇鍦╩essage 鍙傛暟瀛樺偍涓涓互null缁撳熬鐨勯敊璇秷鎭傝娑堟伅琚繑鍥炵粰瀹㈡埛绔傛秷鎭紦鍐插尯鏄 MYSQL_ERRMSG_SIZE 瀛楃闀垮害锛屼絾浣犲簲璇ヨ瘯鐫鎶婃秷鎭繚鎸佸湪灏戜簬80涓瓧绗︼紝浠ヤ究瀹冭兘閫傚悎鏍囧噯缁堢灞忓箷鐨勫搴︺
瀵逛簬long long 鍜 double 绫诲瀷鐨勫嚱鏁帮紝涓诲嚱鏁 xxx()鐨勮繑鍥炶繑鍥炲兼槸鍑芥暟鍊笺傚瓧绗﹀嚱鏁拌繑鍥炰竴涓寚鍚戠粨鏋滅殑鎸囬拡锛屽苟涓旇缃 *result 鍜 *length 涓鸿繑鍥炲肩殑鍐呭鍜岄暱搴︺備緥濡傦細
memcpy(result, "result string", 13); *length = 13;
琚紶缁 xxx() 鍑芥暟鐨勭粨鏋滅紦鍐插尯鏄 255 瀛楄妭闀裤傚鏋滀綘鐨勭粨鏋滈傚悎杩欎釜闀垮害锛屼綘灏变笉闇瑕佹媴蹇冨缁撴灉鐨勫唴瀛樺垎閰嶃
濡傛灉瀛楃涓插嚱鏁伴渶瑕佽繑鍥炰竴涓秴杩255瀛楄妭鐨勫瓧绗︿覆锛屼綘蹇呴』鐢 malloc() 鍦ㄤ綘鐨 xxx_init() 鍑芥暟鎴栬 xxx() 鍑芥暟閲屼负瀛楃涓插垎閰嶇┖闂达紝骞朵笖鍦 xxx_deinit() 鍑芥暟閲岄噴鏀炬绌洪棿銆備綘鍙互灏嗗凡鍒嗛厤鍐呭瓨瀛樺偍鍦 UDF_INIT 缁撴瀯閲岀殑 ptr 浣嶇疆浠ュ灏嗘潵 xxx() 璋冪敤銆傝鍙傞槄27.2.3.1鑺傦紝鈥淯DF 瀵圭畝鍗曞嚱鏁扮殑璋冪敤椤哄簭鈥銆
瑕佸湪涓诲嚱鏁颁腑鎸囨槑涓涓 NULL 鐨勮繑鍥炲硷紝璁剧疆 *is_null 涓 1 锛
*is_null = 1;
瑕佸湪涓诲嚱鏁颁腑鎸囨槑閿欒杩斿洖锛岃缃 *error 涓 1 锛
*error = 1;
濡傛灉 xxx() 瀵逛换鎰忚璁剧疆 *error 涓 1 锛屽浜庝换浣 XXX()琚皟鐢ㄧ殑璇彞澶勭悊鐨勫綋鍓嶈鍜岄殢鍚庣殑浠绘剰琛岋紝璇ュ嚱鏁板间负 NULL 锛堢敋鑷抽兘涓嶄负闅忓悗鐨勮璋冪敤 xxx()锛夈
瀹炵幇UDF鐨勬枃浠跺繀椤诲湪杩愯鏈嶅姟鍣ㄧ殑涓绘満涓婄紪璇戝拰瀹夎銆傝繖涓楠ゅ湪涓嬮潰浠嬬粛锛屼互鍖呭惈鍦∕ySQL婧愮爜鍒嗗彂鐗堥噷鐨刄DF鏂囦欢sql/udf_example.cc 涓轰緥銆
绱ф帴鐫涓嬮潰鐨勬寚浠ゆ槸瀵筓nix鐨勶紝瀵筗indows鐨勬寚浠ゅ湪鏈妭绋嶅悗缁欏嚭銆
udf_example.cc 鏂囦欢鍖呭惈涓嬪垪鍑芥暟锛
metaphon() 杩斿洖瀛楃涓插弬閲忕殑涓涓彉闊充綅(metaphon)瀛楃涓诧紝杩欐湁鐐硅薄涓涓帰娴嬫硶锛坰oundex锛夊瓧绗︿覆锛屼絾鏄畠鑻辫鏇村崗璋冦
myfunc_double()杩斿洖鍦ㄥ叾鍙傞噺涓墍鏈夊瓧绗︾殑ASCII鍊肩殑鍜岋紝闄や互鍏 鍙傞噺闀垮害涔嬪拰銆
myfunc_int()杩斿洖鍏跺弬閲忛暱搴︿箣鍜屻
sequence([const int]) 杩斿洖涓涓簭鍒楋紝浠庣粰瀹氭暟寮濮嬶紝鑻ユ病鏈夌粰瀹氭暟鍒欎粠1寮濮嬨
lookup() 杩斿洖瀵瑰簲涓绘満鍚嶇殑IP鏁般
reverse_lookup() 杩斿洖瀵瑰簲涓涓狪P鏁扮殑涓绘満鍚嶃傚嚱鏁板彲浠ュ甫'xxx.xxx.xxx.xxx'褰㈠紡鐨勪竴涓崟瀛楃涓 鍙傞噺璋冪敤锛岃涔堝甫4涓暟瀛楄皟鐢ㄣ
涓涓彲鍔ㄦ佸姞杞界殑鏂囦欢搴斾娇鐢ㄥ涓嬭繖鏍风殑鍛戒护缂栬瘧涓轰竴涓彲鍏变韩鐨勫璞℃枃浠讹細
shell> gcc -shared -o udf_example.so udf_example.cc
濡傛灉浣犱娇鐢gcc锛屼綘搴旇鑳界敤涓涓洿绠鍗曠殑鍛戒护鍒涘缓udf_example.so 锛
shell> make udf_example.so
閫氳繃杩愯MySQL婧愮爜鏍戜笅sql閲岀殑濡備笅鍛戒护锛屼綘鍙互瀹规槗鍦颁负浣犵殑绯荤粺鍐冲畾姝g‘鐨勭紪璇戝櫒閫夐」锛
shell> make udf_example.o
浣犲簲璇ヨ繍琛屼竴涓被浼间簬make鎵鏄剧ず閭f牱鐨勭紪璇戝懡浠わ紝闄や簡瑕佸湪琛屽熬闄勮繎鍒犻櫎-c閫夐」锛屽苟鍦ㄨ灏惧姞涓婂姞涓 -o udf_example.so銆傦紙鍦ㄦ煇浜涚郴缁熶笂锛屼綘鍙兘闇瑕佸湪鍛戒护琛岀暀鐫-c 閫夐」锛夈
缂栬瘧濂戒竴涓寘鍚湁UDF鐨勫叡浜洰鏍囧悗锛屼綘蹇呴』瀹夎瀹冨苟閫氱煡MySQL銆備粠udf_example.cc缂栬瘧涓涓叡浜洰鏍囨枃浠朵骇鐢熶竴涓悕瀛楃被浼间簬udf_example.so 鐨勬枃浠讹紙纭垏鍚嶅瓧鍙兘鍥犲钩鍙拌屽紓锛夈傛妸杩欎釜鏂囦欢澶嶅埗鍒 /usr/lib 杩欐牱琚綘绯荤粺鐨勫姩鎬侊紙杩愯鏃讹級閾炬帴鍣ㄦ悳绱㈠埌鐨勭洰褰曚笅锛屾垨鑰 鎶婁綘鏀惧叡浜洰鏍囨枃浠剁殑鐩綍娣诲姞鍒伴摼鎺ュ櫒閰嶇疆鏂囦欢锛堝锛/etc/ld.so.conf 锛夈
鍔ㄦ侀摼鎺ュ櫒鐨勫悕瀛楁椂绯荤粺鐗瑰畾鐨勶紙濡傦紝鍦‵reeBSD涓婃槸ld-elf.so.1 锛屽湪Linux涓婃槸 ld.so锛屽湪Mac OS X涓婃槸dyld 锛夈傛煡鐪嬩竴涓嬩綘绯荤粺鐨勬枃妗o紝鐪嬬湅閾炬帴鍣ㄧ殑鍚嶅瓧鏄粈涔堝強濡備綍閰嶇疆閾炬帴鍣ㄣ
鍦ㄨ澶氱郴缁熶笂锛屼綘涔熷彲浠ヨ缃幆澧冨彉閲廘D_LIBRARY 鎴 LD_LIBRARY_PATH 鎸囧悜浣犳斁UDF鐨勭洰褰曘俤lopen 鎵嬪唽浼氬憡璇変綘锛屽湪浣犵郴缁熶笂鐢ㄥ摢涓彉閲忓悕銆備綘鍙互鍦mysql.server 鎴 mysqld_safe 鍚姩鑴氭湰閲岃缃繖涓劧鍚庨噸鍚 mysqld銆
鍦ㄤ竴浜涚郴缁熶笂锛岄厤缃姩鎬侀摼鎺ュ櫒鐨ldconfig涓嶈兘璇嗗埆涓嶆槸浠lib鍋氬悕瀛楀紑澶寸殑鍏变韩鐩爣銆傚湪杩欑鎯呭喌涓嬶紝浣犲簲璇ユ妸udf_example.so 鏀瑰悕涓 libudf_example.so銆
鍦╓indows绯荤粺涓婏紝浣犲彲浠ラ氳繃涓嬪垪姝ラ缂栬瘧鑷畾涔夊嚱鏁帮細
浣犻渶瑕佽幏寰桞itKeeper source repository for MySQL 5.1銆 璇峰弬闃聽2.8.3鑺傦紝鈥滀粠寮鍙戞簮鏍戝畨瑁呪銆
鍦ㄦ簮鏁版嵁浠撻噷鐨刅C++Files/examples/udf_example鐩綍涓嬶紝鏈夊悕涓簎df_example.def, udf_example.dsp, 鍜 udf_example.dsw 鐨勬枃浠躲
鍦ㄦ暟鎹粨鐨剆ql鐩綍涓嬶紝澶嶅埗 udf_example.cc 鏂囦欢鍒 VC++Files/examples/udf_example 鐩綍锛屽苟鏀瑰叾鍚嶄负udf_example.cpp銆
Visual Studio VC++鐢ㄦ墦寮 udf_example.dsw 鏂囦欢锛岀敤瀹冩妸UDF缂栬瘧涓轰竴涓竴鑸」鐩
鍏变韩鐩爣鏂囦欢瀹夎瀹屼互鍚庯紝涓烘柊鍑芥暟淇℃伅淇敼 mysqld 锛屽仛濡備笅澹版槑锛
mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; mysql> CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so'; mysql> CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so'; mysql> CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so'; mysql> CREATE FUNCTION reverse_lookup -> RETURNS STRING SONAME 'udf_example.so'; mysql> CREATE AGGREGATE FUNCTION avgcost -> RETURNS REAL SONAME 'udf_example.so';
鍙互浣跨敤DROP FUNCTION鍒犻櫎鍑芥暟锛
mysql> DROP FUNCTION metaphon; mysql> DROP FUNCTION myfunc_double; mysql> DROP FUNCTION myfunc_int; mysql> DROP FUNCTION lookup; mysql> DROP FUNCTION reverse_lookup; mysql> DROP FUNCTION avgcost;
CREATE FUNCTION 鍜 DROP FUNCTION 澹版槑鏇存柊mysql 鏁版嵁搴撲腑鐨刦unc 绯荤粺琛ㄣ傚嚱鏁板悕锛岀被鍨嬪拰鍏变韩搴撳悕瀛樿繘琛ㄤ腑銆備綘蹇呴』鏈塵ysql 鏁版嵁搴撶殑INSERT 鍜孌ELETE 鏉冮檺鏉ュ垱寤哄拰绉婚櫎鍑芥暟銆
浣犱笉鑳戒娇鐢 CREATE FUNCTION 鍘荤敯闂翠竴涓厛鍓嶅凡缁忚鍒涘缓鐨勫嚱鏁般傚鏋滀綘闇瑕侀噸鏂板畨瑁呬竴涓嚱鏁帮紝浣犲彲浠ョ敤DROP FUNCTION绉婚櫎瀹冿紝鐒跺悗鍐嶇敤CREATE FUNCTION閲嶆柊瀹夎瀹冦備綘鍙兘浼氶渶瑕佽繖涔堝仛锛屾瘮濡備綘閲嶆柊缂栬瘧鏂扮増鏈殑鍑芥暟浠ヤ究mysqld寰楀埌杩欎釜鏂扮増鏈備笉鐒讹紝鏈嶅姟鍣ㄨ繕缁х画浣跨敤鏃х殑鐗堟湰銆
涓涓湁鏁堢▼搴忔槸宸茶 CREATE FUNCTION鍔犺浇涓旀病鏈夎DROP FUNCTION绉婚櫎鐨勫嚱鏁般傛墍鏈夋湁鏁堝嚱鏁板湪姣忔鏈嶅姟鍣ㄥ惎鍔ㄦ椂閲嶆柊鍔犺浇锛岄櫎闈炰綘浣跨敤--skip-grant-tables閫夐」鏉ュ惎鍔mysqld銆傝繖绉嶆儏鍐典笅锛孶DF鐨勫垵濮嬪寲灏嗚璺宠繃锛孶DF涓嶅彲鐢ㄣ
MySQL 閲囧彇涓嬪垪鎺柦鏉ラ槻姝㈣鐢ㄨ嚜瀹氫箟鍑芥暟銆
浣犲繀椤绘湁 INSERT 鏉冮檺鎵嶈兘浣跨敤 CREATE FUNCTION 鍙婃湁 DELETE 鏉冮檺鎵嶈兘浣跨敤 DROP FUNCTION銆傝繖鏄緢蹇呰鐨勶紝鍥犱负杩欎簺澹版槑鍦╩ysql.func琛ㄩ噷娣诲姞鍚堝垹闄よ銆
闄や簡瀵瑰簲涓 xxx()鍑芥暟鐨剎xx 绗﹀彿锛孶DF搴旇鑷冲皯瀹氫箟涓涓鍙枫傝繖浜涜緟鍔╃鍙峰搴 xxx_init(), xxx_deinit(), xxx_reset(), xxx_clear() 鍜 xxx_add() 鍑芥暟銆mysqld 涔熸敮鎸佷竴涓帶鍒朵粎鏈変竴涓獂xx绗﹀彿鐨刄DF鏄惁琚姞杞界殑--allow-suspicious-udfs銆傝繖涓夐」 榛樿鏄叧锛屼互闃叉浠庡叡浜洰鏍囨枃浠惰屼笉鏄粠杩欎簺宸插寘鍚殑鍚堟硶UDF鍔犺浇鐨勪紒鍥俱傚鏋滀綘鏈変粎鍚玿xx绗﹀彿鐨勮佺増鏈琔DF锛屼互鍙婁笉鑳介噸缂栬瘧鏉ュ寘鍚緟鍔╃鍙风殑鑰佺増鏈琔DF锛岄偅灏辨湁蹇呰閫--allow-suspicious-udfs 閫夐」銆傚惁鍒欙紝浣犲簲璇ラ伩鍏嶆墦寮杩欎釜閫夐」銆
UDF 鐩爣鏂囦欢涓嶈兘鏀惧湪浠绘剰鐩綍銆傚畠浠繀椤讳綅浜庡姩鎬侀摼鎺ュ櫒琚厤缃潵鎼滅储鍒扮殑涓浜涚郴缁熺洰褰曘備负寮哄埗鎵ц杩欎釜闄愬埗骞堕槻姝㈡寚瀹氳鍔ㄦ侀摼鎺ュ櫒鎼滅储鍒扮殑鐩綍涔嬪鐨勮矾寰勶紝MySQL鍦ㄥ姞杞藉嚱鏁扮殑鏃跺欐鏌ュ湪CREATE FUNCTION 涓寚瀹氱殑鍏变韩鐩爣鏂囦欢鍚嶏紝浠ュ強瀛樺湪mysql.func琛ㄤ腑鐨勬枃浠剁殑璺緞鍒嗛殧绗︺傝繖闃叉閫氳繃鐩存帴鎿嶄綔mysql.func琛ㄦ寚瀹氶潪娉曡矾寰勫悕銆傛湁鍏砋DF鍜岃繍琛屾椂閾炬帴鍣紝璇峰弬闃27.2.3.5鑺傦紝鈥滅紪璇戝拰瀹夎鑷畾涔夊嚱鏁扳銆
涓嬮潰浠嬬粛娣诲姞鏂板浐鏈夊嚱鏁扮殑姝ラ銆傝娉ㄦ剰浣犱笉鑳芥坊鍔犲浐鏈夊嚱鏁板埌浜岃繘鍒跺垎鍙戠増閲岋紝鍥犱负杩欎釜姝ラ鍖呭惈淇敼MySQL婧愪唬鐮併備綘蹇呴』浠庢簮鐮佸垎鍙戠増鑷繁缂栬瘧MySQL銆傚彟澶栬娉ㄦ剰锛屽鏋滀綘鎶奙ySQL绉绘鍒板彟涓涓増鏈紙姣斿鏂扮増鏈斁鍑烘潵鐨勬椂鍊欙級锛屼綘闇瑕佺敤鏂扮増鏈噸澶嶈繖涓坊鍔 姝ラ銆
閲囧彇涓嬪垪姝ラ鏉ユ坊鍔燤ySQL鏂扮殑鍥烘湁鍑芥暟锛
鍦ㄥ畾涔夊嚱鏁板悕鐨刲ex.h鏂囦欢涓殑sql_functions[]鏁板垪閲屾坊鍔犱竴琛屻
濡傛灉鍑芥暟鍘熷瀷鏄畝鍗曠殑锛堝彧鏈夐浂涓紝涓涓紝浜屼釜鎴栦笁涓弬閲忥級锛屼綘搴旇鍦╨ex.h涓寚瀹 SYM(FUNC_ARGN) 锛堝叾涓N 鏄弬閲忕殑涓暟锛変綔涓簊ql_functions[]鏁板垪涓殑绗簩涓 鍙傞噺锛屽苟娣诲姞涓涓湪item_create.cc涓垱寤哄嚱鏁扮洰鏍囩殑鍑芥暟銆傚彲浠ョ湅鐪 "ABS" 鍜 create_funcs_abs() 浣滀负涓句緥璇存槑銆
濡傛灉鍑芥暟鍘熷瀷鏄鏉傜殑锛堜妇渚嬶紝濡傛灉鍑芥暟鏈夊绉嶅弬閲忥級锛屼綘搴旇缁檚ql_yacc.yy娣诲姞涓よ銆備竴琛岃〃绀yacc搴旇瀹氫箟鐨勯澶勭悊绋嬪簭璁板彿锛岋紙杩欏簲璇ュ湪鏂囦欢鐨勫紑濮嬫坊鍔狅級銆傜劧鍚庡畾涔夊嚱鏁 鍙傛暟锛屽苟娣诲姞涓涓甫杩欎簺鍙傛暟鐨勯」鍒simple_expr鍒嗘瀽瑙勫垯涓備妇涓涓緥瀛愶紝浣犲彲浠ユ鏌 sql_yacc.yy 涓墍鏈夊嚭鐜扮殑ATAN 鐪嬬湅杩欎釜瀹氫箟鏄粈涔堟牱瀛愮殑銆
鍦 item_func.h涓鏄庝竴涓户鎵胯嚜Item_num_func 杩樻槸 Item_str_func鐨勭被锛屽彇鍐充簬浣犵殑鍑芥暟鏄繑鍥炰竴涓暟杩樻槸涓涓瓧绗︿覆銆
鍦 item_func.cc涓槸鍚︽坊鍔犱笅鍒楄鏄庝箣涓锛屽彇鍐充簬浣犳槸瀹氫箟涓涓暟瀛楀嚱鏁拌繕鏄瓧绗﹀嚱鏁帮細
double Item_func_newname::val() longlong Item_func_newname::val_int() String *Item_func_newname::Str(String *str)
濡傛灉浣犱粠浠讳綍鏍囧噯椤圭户鎵夸簡浣犵殑鐩爣锛堢被浼间簬Item_num_func锛夛紝浣犳垨璁稿彧瑕佸畾涔夎繖浜涘嚱鏁颁腑鐨勪竴涓紝鐒跺悗璁╃埗鐩爣鐓х鍒殑鍑芥暟銆傛瘮濡傦紝Item_str_func 绫诲畾涔変簡涓涓 val() 鍑芥暟锛屽畠杩欎釜鍑芥暟瀵::str()杩斿洖鐨勫艰繘琛 atof()鎿嶄綔銆
浣犳垨璁镐篃瀹氫箟浜嗕笅鍒楃洰鏍囧嚱鏁帮細
void Item_func_newname::fix_length_and_dec()
杩欎釜鍑芥暟鑷冲皯搴旇璁$畻鍩轰簬缁欏畾鍙傞噺鐨刴ax_length銆 max_length 鏄嚱鏁板彲鑳借繑鍥炲瓧绗︾殑鏈澶т釜鏁般傚鏋滀富鍑芥暟涓嶈兘杩斿洖 NULL鍊硷紝杩欎釜鍑芥暟涔熷簲璇ヨ缃 maybe_null = 0銆傚嚱鏁板彲浠ラ氳繃妫鏌ュ嚱鏁扮殑maybe_null鍊兼潵妫鏌ユ槸鍚︽湁鍑芥暟 鍙傞噺鑳借繑鍥濶ULL鍊笺備綘鍙互鐪嬩竴涓婭tem_func_mod::fix_length_and_dec 浣滀负鍏稿瀷鐨勪緥瀛愭潵璇存槑杩欎釜闂銆
鎵鏈夊嚱鏁伴兘蹇呴』鏄嚎绋嬪畨鍏ㄧ殑锛屾崲鍙ヨ瘽璇村氨鏄紝濡傛灉娌℃湁浜掓枼浣撲繚鎶わ紝涓嶈鍦ㄥ嚱鏁颁腑浣跨敤浠讳綍鍏ㄥ眬鎴栭潤鎬佸彉閲忋
濡傛灉浣犳兂瑕佷粠鍑芥暟::val(), ::val_int()鎴::str()杩斿洖NULL锛屼綘搴旇璁緉ull_value涓1,骞惰繑鍥0銆
瀵逛簬鐩爣鍑芥暟 ::str() 鏈変竴浜涢渶瑕佽屽鑰冭檻涔嬪锛:
瀛楃涓插弬閲*str 鎻愪緵涓涓瓧绗︿覆缂撳啿鍙互鐢ㄦ潵淇濇寔缁撴灉锛堟洿澶氬叧浜庡瓧绗︿覆绫诲瀷鐨勪俊鎭鍙傞槄 sql_string.h鏂囦欢锛夈
濡傛灉缁撴灉涓篘ULL锛::str() 鍑芥暟搴旇杩斿洖淇濇寔杩欎釜缁撴灉鐨勫瓧绗︿覆鎴(char*) 0銆
闄ら潪鏈夌粷瀵瑰湴闇瑕侊紝鎵鏈夊綋鍓嶇殑瀛楃涓插嚱鏁拌閬垮厤鍒嗛厤鍐呭瓨锛
鍦∕ySQL涓紝浣犲彲浠ョ敤C++瀹氫箟涓涓楠わ紝鍦ㄤ竴涓煡璇㈣鍙戦佸埌瀹㈡埛绔箣鍓嶈闂拰淇敼鍏朵腑鐨勬暟鎹備慨鏀瑰彲浠ヤ竴琛屾帴涓琛屽湴鍋氾紝鎴栬呮寜鐓х骇鍒垚缁勶紙GROUP锛夊湴鍋氥
鎴戜滑鍒涘缓涓涓寖渚嬫楠ゆ潵婕旂ず浣犲彲浠ュ仛鐨勩
姝ゅ锛屾垜浠帹鑽愪綘鐪嬩竴涓媘ylua銆傞氳繃瀹冧綘鍙互鐢 LUA璇█鎶婅繍琛屾椂閲岀殑涓涓 姝ラ鍔犺浇鍒mysqld涓
analyse([max_elements,[max_memory]])
杩欎釜姝ラ鍦╯ql/sql_analyse.cc瀹氫箟锛岃繖涓楠ゆ鏌ヤ綘鏌ヨ鐨勭粨鏋滐紝骞朵笖杩斿洖瀵规缁撴灉鐨勪竴涓垎鏋愶細
max_elements (榛樿鍊 256) 鏄痑nalyse娉ㄦ剰鍒版瘡 鍒椾笉鍚屽肩殑鏈楂樻暟鐩俛nalyse浣跨敤姝 鍙傛暟鏉ユ鏌ユ槸鍚︽渶浼樺寲鐨勫垪鐨勭被鍨嬫槸ENUM绫诲瀷銆
max_memory (榛樿鍊 8192) 鏄痑nalyse鍦ㄦ煡鎵炬墍鏈変笉鍚屽兼椂鍒嗛厤缁欐瘡 鍒楃殑鏈澶у唴瀛樻暟銆俰
SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max_elements,[max_memory]])
杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆 鍘熷鍙傝冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆