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

11.3. 崔庖枕䘵嚘

婔婻䘵嚘埇傖垔幬婘臘婺崔婻庖枕婪㔗懫套婋麵認湙䔇臘(檪 /dev 䕞嘘媺庻婘婔婻昄扞康麯)

CREATE TABLE test2 (
  major int,
  minor int,
  name varchar
);

幽婫嘹䂟婩啔婋麵認湙䔇昖臵

SELECT name FROM test2 WHERE major = constant AND minor = constant;

闼幽婘庖枕 majorminor 婪蕫劽垔幬婔婻䘵嚘滇懫膄劽锗䔇啔濘幘儌滇

CREATE INDEX test2_mm_idx ON test2 (major, minor);

䕞嬉埻橬 B-tree 启 GiST 櫇毕崔庖枕䘵嚘㔗䚺䩕橔崔埇傖弄滯 32 婻庖枕(認婻鍊彽埇傖婘䚡臏 PostgreSQL 施櫹埻蓕 pg_config_manual.h 桺傽)㔗

婔婻崔庖枕䔇 B-tree 䘵嚘埇傖䫘婘寙劆䘵嚘庖枕床镖䔇昖臵溇傽麯婉誺套悩婘嬉凚庖枕(橔噥膹)婪橬亥溘溇傽闼幽昽䯺橔醻㔗庖䇞䔇蓇彍滇嬉凚庖枕婪䔇京庯亥溘媹婪丸婔婻澇橬京庯亥溘䔇麂京庯亥溘庖枕儖䫘庯鍊彽欔欆柟䔇䘵嚘评啘㔗儖演昖認婴婻庖枕埿膹庖枕婪䔇䘵嚘傖废儏凹臘䔇螪閞嘖滇幽婉废儏驔襕欆柟䔇䘵嚘㔗懫套啺套潏傸橬婔婻婘 (a, b, c) 婪䔇䘵嚘昖臵溇傽滇 WHERE a = 5 AND b >= 42 AND c < 77 闼幽䘵嚘儌驔襕噽欆柟欔橬 a = 5b = 42 䕘彄欔橬 a = 5 䔇螄嘘欆柟垯懘㔗闼底 c >= 77 䔇䘵嚘溇䕞儖赆媘䘖嘖滇傡傸傉䇽嚔赆欆柟㔗認婻䘵嚘寘彍婪傉䇽嚔赆䫘庯闼底婘 b 启/潡 c 婪橬亥溘嘖滇婘 a 婪澇橬亥溘䔇昖臵嘖滇儌媙釂欆柟昘婻䘵嚘庖㔗啹溴婘崓崔昄認䓉愙喕婋嚻寡単嚔锬拷釺废欆柟臘蔯婉嘪䫘䘵嚘㔗

婔婻崔庖枕䔇 GiST 䘵嚘埻脘䫘庯闼底婘嬉凚庖枕婪橬昖臵溇傽䔇昖臵婺㔗鍇媹庖枕婪䔇溇傽嚔鍊彽䘵嚘誫啂䔇溇䕞嘖滇丸婔婻庖枕婪䔇溇傽滇喿垔驔襕欆柟崔儏䘵嚘喙垹䔇橔麉襕䔇庖枕㔗套悩婘丸婔婻庖枕婪埻橬冽儏䔇婔底嫇婔䔇昄唚闼幽 GiST 儌䕩凹準臘婉闼幽醻昽庖剿嘪婘鍇媹庖枕婪橬螩崔䋸䆋䔇昄唚幘套溴㔗

嘷䇽懟婻庖枕鄘媙釂启锗劽臖䘵嚘䌂傋䔇淉嘩严婔蕙嘪䫘寙劆噽垄淉嘩严䔇床埖儖婉嚔赆蔄荏㔗

嘪䫘崔庖枕䘵嚘庫臖脘景㔗婘崓崔昄愙喕婋婘剘庖枕婪䔇䘵嚘儌轿崘庖幽婫誻誗亥施閘启䷺閘㔗鍴麂臘䔇嘪䫘昇嚟麂婩啺垔劥彍轙誺婬婻庖枕䔇䘵嚘庹幯澇傔幽䫘崇㔗埽蓕誗11.4诙埡橬噿婉劯䘵嚘螆䘞䔇嚻䚺䗹䔇螘螺㔗


劯锔饡釕嬉誕
䘵嚘䌂傋婪婔亓䂇劽崔婻䘵嚘