PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹11. 䘵嚘媆誕嬉誕

11.1. 傋䂉

啺螆橬償婋麵認湙婔婻臘

CREATE TABLE test1 (
    id integer,
    content varchar
);

驔襕崓麟嘪䫘婋麵認湙䔇臺埖誕臯昖臵

SELECT content FROM test1 WHERE id = constant;

锔婩昄扞康係䂘婉冖婉婔臯婔臯婄欆柟昘婻 test1 臘傖凂欆欔橬对陉䔇螄嘘㔗套悩婘 test1 麯麵橬螩崔臯嘖滇埻誫啂儏昄庹臯(埇脘滇镽臯潡婔臯)闼幽婪麵認婻桹濘埇儌冽噞媾庖㔗套悩潏傸螷昄扞康係䂘婘 id 彖婪䂘檴婔婻䘵嚘䫘庯垔嘉对陉䔇臯㔗認湙昄扞康係䂘埻驔襕婘抩䘵湏婺蕄儏昄䔇庹北儌埇傖欆彄对陉臯㔗

婘崓崔昄麂償臘䔇幥䌉麯麵鄘嘪䫘庖䌂嚚認湙䔇桹濘婘幥䔇脯劯櫽镖五臂蔙嚔䂟婩昖欆䔇橇臺启楗媕䔇䘵嚘幽毬䙓庖應釺废毐彖㔗橬噘轼䔇臂蔙埇傖媆锘婄欆柟臖䘵嚘幽婫彺扵彄劽锗䔇釕啹溴婉䫘黙臂昘橸幥儌脘昖欆彄懘噘轼䔇嘉䘞㔗嘩蔙䔇傂媇幋婔儌滇鵇螇巻底釹滇臂蔙橔驔襕昖欆䔇婩薪婯幋䌂嚚鵇螇巻底䘵嚘埇傖婥準冪彷幘滇昄扞康䘋废叻䔇傂媇㔗

婋麵䔇变傴埇傖䫘庯婘 id 彖婪录傺嬉麵螘螺誺䔇䘵嚘

CREATE INDEX test1_id_index ON test1 (id);

䘵嚘劉庖 test1_id_index 埇傖躻䫌锬拷嘖滇庫臖锬闼底䘉劯埇傖螷嘹啂媖蕙䘵嚘劆幬䔇劉庖㔗

襕役鍴婔婻䘵嚘嘪䫘 DROP INDEX 变傴㔗嘹埇傖婘傂嘘施唍劏臘麯嵂媹䘵嚘潡蔙傯臘婺役鍴䘵嚘㔗

婔斥嘹录傺庖䘵嚘闼幽儌婉驔襕敘崔幾潬庖嘷係䂘螴婺䫘䘵嚘懫釺废䔇臘欆柟媆䔇施唍垄儌嚔嘪䫘䘵嚘㔗婉誺嘹埇脘媙釂䂟婩攓婄誊臯 ANALYZE 变傴傖敘桄䂘螇媇敇喘螷昖臵蓇彐単脘崘啔庺橬螺䂄橬䘹䔇彴桺㔗埗蓕䆹13诙埡噿庯套嘘诙䘖滇劥嘪䫘庖䘵嚘䔇媇敇傖埪婘傔幽施唍㔕傔幽寘啹婋蓇彐単嚔喿垔嘪䫘䘵嚘㔗

䘵嚘凹婥抩䘵溇傽䔇 UPDATEDELETE 变傴幘橬喘崇㔗䘵嚘敘埇傖䫘庯臘誂毖昖臵㔗啹溴套悩嘹垔幬庖䘵嚘䔇彖滇誂毖溇傽䔇婔鄘彖闼幽垄埇傖滆菖柊醻誂毖䔇昖臵锘庥㔗

婘婔婻噘崓䔇臘婪录傺䘵嚘埇脘嚔潽蔖崓麟䔇施閘㔗䚺䩕施PostgreSQL 噕螩婘录傺䘵嚘䔇劯施臂埡臘(select)嘖滇喍噖臘(insert, update, delete)䔇媘嘩儖赆黂凂彄䘵嚘录傺垯懘㔗婘䫘库䯇嵄婋認䓉黂凂锔婩滇婉埇毖埖䔇啹溴幘噕螩婘录傺䘵嚘䔇劯施喍噖臘嘖滇橬婔底躥只驔襕濘懟敘崔媇敇埗蓕幽臯录傺䘵嚘

录傺䘵嚘幋劯垄媙釂启臘媺毕劯準㔗認底淉嘩嵂媹庖昄扞淉嘩䔇蘘艙㔗啹溴潏傸庫臖檪闼底麂噿髞潡蔙湹橸䫘婉婪䔇䘵嚘役鍴毬㔗


劯锔饡釕嬉誕
䘵嚘婪婔亓䘵嚘䌂傋