PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹35. 蓇彍係䂘媆誕嬉誕

35.1. 昖臵湏

襕䊖蓼蓇彍係䂘套嘘噖嘩饡噽襕䘖長蓇彍嘘施赆檔埏傖埪垄䔇膷噖启䂷悩滇傔幽㔗

蓇彍係䂘嘉庯彖悊単启蓇彐単幋閘㔗傖彖悊単膷庺䔇昖臵湏傖埪䫘潙垔幬䔇麉喍蓇彍嘩婺膷噖麉喍蓇彍幘滇婔婻昖臵湏埻婉誺嵂媹庖婔底欷匘媇敇䇽劯录傺镽婻潡蔙崔婻昖臵湏嘩婺䂷悩㔗欔傖垄䔇膷噖启膷庺傉䇽滇闼底彖悊単埇傖䫘潊䔇婩薪啹蔯傂嘘蓇彍係䂘䩋彄䔇婩薪鄘滇埇傖䫘 SQL 臺埖臘膆䔇㔗

闼幽傔幽滇昖臵湏叵?垄滇婔婻 SQL 臺埖䔇喙鄘臘䯄嘵嚟認施䂇潊臖臺埖䔇懟婻䋸䆋鄘彖鄘滇彖彆庻嗘䔇㔗套悩嘹螆䘞庖陉䘞埗昄 debug_print_parse, debug_print_rewritten, debug_print_plan 闼幽儌埇傖婘橉媇単斖媖婺䩋彄認底昖臵湏㔗蓇彍媘嘩幘滇傖昖臵湏䔇桹嚟庻嗘䔇庻櫆婘係䂘臘 pg_rewrite 麯麵㔗婉誺婉滇䫘償脄臘膷庺闼湙䔇湚嚟嘖寙劆䔇喙垹滇垯噘婔湙䔇㔗

黙臂婔婻輩昖臵湏驔襕婔垔䔇䂟黯嘖滇啹婺䊖蓼昖臵湏䔇 SQL 臘䯄儌轿傖䊖蓼蓇彍係䂘欔傖認傘桺懼儖婉嚔只臬嘹套嘘臂埡垄傸㔗

嘷臂埡橸䆹婺昖臵湏䔇 SQL 臘䯄施媙釂脘崘臖彆臖臺埖赆彖蓼劯櫆婘昖臵湏麯䔇潊叻㔗昖臵湏䔇潊叻橬

变傴䌂傋(command type)

認滇婔婻䞔剘䔇唚臘滯巻溇变傴(SELECT, INSERT, UPDATE, DELETE)䫘潊認婻昖臵湏㔗

评啘臘(range table)

评啘臘滇婔婻昖臵婺嘪䫘䔇噿係䔇彖臘㔗婘 SELECT 臺埖麯儌滇婘 FROM 噿髞庖劯麵䂍庺䔇噿係㔗

懟婻评啘臘臘䴺婔婻臘潡婔婻蓖商臘滯滇昖臵麯巻婻潊叻脄䫘庖垄㔗婘昖臵湏麯评啘臘滇䫘傼埙蔯婉滇䫘劉庖嚘䫘䔇欔傖認麯婉䫘償婘 SQL 臺埖麯婔湙噿媄滇劥橬麉劉閞鵻㔗認䓉愙喕婘嚘噖庖蓇彍䔇评啘臘劯埇脘嚔埏䫘㔗橸䆹䔇冋床儖婉螘螺認䓉愙喕㔗

䂷悩噿係(result relation)

認滇婔婻评啘臘䔇䘵嚘䫘庯湺臖昖臵䂷悩嬉冔䔇臘㔗

SELECT 昖臵锔婩澇橬䂷悩噿係臘㔗䬹冋 SELECT INTO 庹幯京庯婔婻虘锟 INSERT ... SELECTCREATE TABLE 欔傖認麯儌婉剘䋸螘螺庖㔗

INSERT, UPDATE, DELETE 变傴麯䂷悩噿係滇敘櫹埏䫘嘌巉䔇臘潡蓖商㔗

䕞湺彖(target list)

䕞湺彖滇婔彖垔幬昖臵䂷悩䔇臘膆嚟㔗婘 SELECT 䔇愙喕婋認底臘膆嚟儌滇悇傺昖臵䔇橔䂽膷庺䔇婩薪㔗垄傸滇嘉庯 SELECTFROM 噿髞庖幋閘䔇臘膆嚟(* 埻滇臘滯婔婻噿係䔇欔橬庖枕䔇䚷喍垄赆彖悊単欷匘婺䋸䆋䔇庖枕啹溴蓇彍係䂘愩誩䩋婉彄垄)㔗

DELETE 婉驔襕䕞湺彖滇啹婺垄傸婉库䫘傂嘘䂷悩㔗垂鍙婪蓇彐単嚔劏䷺䕞䔇湺彖婺嵂媹婔溇䬹枪䔇 CTID 螄嘘㔗嘖認滇婘蓇彍係䂘幋劯幽婫儖䘉劯螘螺凹庯蓇彍係䂘蔯蘔䕞湺彖滇䷺䔇㔗

凹庯 INSERT 变傴麯麵䕞湺彖柟誄庖庫臖誕噖䂷悩噿係䔇桄臯㔗認底臯䫌闼底婘 VALUES 床埖麯䔇臘膆嚟潡婘 INSERT ... SELECT 臺埖麯䔇 SELECT 床埖麯麵䔇臘膆嚟悇潊㔗麉喍誺䘋䔇丸婔準儌滇婺傂嘘婉滇䫌寘哋䔇昖臵蕋唚幽婫橬䚺䩕唚䔇庖枕嵂媹䕞湺彖臘釹㔗傂嘘噽垄䔇庖枕(斵方䂍庺唚幘方䚺䩕唚)儖䫌蓇彐単躻媘蕋庽婔婻婩麟 NULL 臘膆嚟㔗

凹庯 UPDATE 变傴䕞湺彖柟誄庫臖敪扵斓臯䔇桄臯㔗婘蓇彍係䂘麯垄埻寙劆準躻昖臵䔇 SET column = expression 鄘彖檘埡䔇臘膆嚟㔗認施蓇彐単儖锔誺某噖傯斓臯檘埡昄扞彄桄臯䔇臘膆嚟䔇桹濘崇䊖䚺崌䔇庖枕㔗幽婫垄幘嚔償婘 DELETE 麯闼湙嵂媹䬹枪䔇 CTID 螄嘘㔗

䕞湺彖麯䔇懟婻噄䘹鄘寙劆五婔婻臘膆嚟垄埇傖婺婩麟唚㔕婔婻毺劏昊婻评啘臘麯麵䔇噿係䔇婔婻庖枕䔇埻麟㔕婔婻䫌庘昄脄䫘婩麟/埻麟/淉嘩严京悇潊䔇臘膆嚟湏㔗

溇傽(qualification)

昖臵溇傽滇婔婻臘膆嚟垄麂婩䌂嚚闼底寙劆婘䕞湺彖麯䔇溇䕞㔗認婻臘膆嚟䔇唚滇婔婻婄儫唚锔誺溴唚準彴桺凹橔䂽䂷悩臯滇劥襕欓淉嘩(INSERT, UPDATE, DELETE, SELECT)㔗垄滇婔婻 SQL 臺埖䔇 WHERE 床埖㔗

誂毖湏(join tree)

昖臵䔇誂毖湏滆䴺庖 FROM 床埖䔇䂷悇㔗凹庯償 SELECT ... FROM a, b, c 認湙䔇䞔剘昖臵誂毖湏埻滇婔婻 FROM 釹䔇䞔剘彖臘啹婺噕螩傖傂懟釺废誂毖垄傸㔗嘖套悩嘪䫘庖 JOIN 臘膆嚟(儴噽滇崡誂毖䔇施唍)儌媙釂毬䙓臖誂毖滆䴺䔇釺废誕臯誂毖㔗誂毖湏滆䴺 JOIN 臘膆嚟䔇䂷悇㔗婯䬹垔䔇 JOIN 床埖(準躻 ONUSING 臘膆嚟)䕩噿䔇鍊彽啔婺鍇媹婘闼底誂毖湏誗䗹䔇溇傽臘膆嚟庻嗘㔗庋垂臕滯檪釽北 WHERE 臘膆嚟幘嘷啔鍇媹婘釽北誂毖湏釹䔇溇傽準庻嗘滇麂婩桹冪䔇㔗欔傖垂鍙婪誂毖湏傼臘 SELECT 臺埖䔇 FROMWHERE 床埖㔗

噽垄(others)

昖臵湏䔇噽垄鄘彖償 ORDER BY 床埖婉庖崺婘認麯螘螺㔗蓇彍係䂘婘鍇媹蓇彍施儖婘闼麯(ORDER BY 床埖)敪扵婔底溇䕞嘖滇認凹庯蓇彍係䂘䔇嘺橸寘䊖幽澇橬崔崓噿係㔗


劯锔饡釕嬉誕
蓇彍係䂘婪婔亓蓖商启蓇彍係䂘