䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL䘵嚘

PostgreSQL䘵嚘

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

䘵嚘滇婔䓉䬹枪䔇昖臵臘埇傖嘪䫘抩䘵嚘淯䔇昄扞康傖媹媆昄扞演䘵㔗䞔剘婄臘䘵嚘滇臘婺䔇昄扞䔇婔婻毺鐽婘婔婻昄扞康婺䔇䘵嚘滇麂婩䕩嚚套婔橸幥䔇䕞嘘㔗

www.gitbook.net

冋套套悩愿婘婔橸幥婺嚘䫘䔇欔橬釕麵螘螺昊婻臺鵻噽埗蔄䘵嚘毬庖應釺废彖庺欔橬䕞嘘婂鵻䇽劯蘸彄婔婻潡崔婻䬹垔䔇釕乕㔗 www.gitbook.net

䘵嚘橬媷庯媹媆SELECT昖臵启WHERE床埖嘖垄嚔废晵昄扞䔇膷噖UPDATE启INSERT臺埖㔗䘵嚘埇傖录傺潡役鍴䔇昄扞澇橬嘌巉㔗 www.gitbook.net

录傺䘵嚘潬埪CREATE INDEX臺埖垄噕螩变劉䔇䘵嚘䘵嚘毺垔臘䔇婔彖潡崔彖幽毺䴺䘵嚘滇劥婘剺废潡鍉废毐彖㔗

www.gitbook.net

䘵嚘幘埇傖滇嫇婔䔇䌂嚚UNIQUE亥溘婘彖婪橬婔婻䘵嚘䔇彖潡䂇劽䘵嚘黾溵麉崉釹㔗 www.gitbook.net

CREATE INDEX变傴:

CREATE INDEX䔇嘺橸臺濘套婋:

www.gitbook.net

CREATE INDEX index_name ON table_name; gitbook.net 

䘵嚘䌂傋

PostgreSQL柊冕庖庹䓉䘵嚘䌂傋B-湏巽婯GISTSP-GiST启GIN㔗懟婻䘵嚘䌂傋嘪䫘婉劯䔇䞖濘滇橔锗劽庯婉劯䌂傋䔇昖臵㔗邻螴愙喕婋CREATE INDEX变傴录傺B-tree䘵嚘锗劽橔婩蓕䔇愙喕㔗 www.gitbook.net

剘彖䘵嚘:

剘彖䘵嚘滇嘺庯埻橬婔婻臘䔇彖婪录傺㔗嘺橸臺濘套婋

gitbook.net

CREATE INDEX index_name
ON table_name (column_name); www.gitbook.net 

崔彖䘵嚘

崔彖䘵嚘垔幬婔婻臘䔇崔婻彖婪㔗嘺橸臺濘套婋

www.gitbook.net

CREATE INDEX index_name
ON table_name (column1_name, column2_name); www.gitbook.net 

滇劥襕录傺婔婻剘彖䘵嚘潡崔彖䘵嚘蔄荏嘪䫘麂婩鵏乕昖臵䔇WHERE床埖婺䔇彖嘩婺誺悴溇傽㔗

gitbook.net

庫臖橬婔彖剘彖䘵嚘庫臖滇锬拷㔗套悩橬婴婻潡崔婻彖婺䂟婩嘪䫘䔇WHERE床埖嘩婺誺悴単崔彖䘵嚘儖滇橔喘䔇锬拷㔗 gitbook.net

嫇婔䘵嚘:

婉備嘪䫘嫇婔䘵嚘䔇攓脘劯施幘婺昄扞䔇垯昘攓㔗嫇婔䘵嚘婉噕螩傂嘘麉崉䔇唚某噖彄臘婺㔗嘺橸臺濘套婋

www.gitbook.net

CREATE INDEX index_name
on table_name (column_name); 

gitbook.net

鄘彖䘵嚘

鄘彖䘵嚘滇婔婻䘵嚘傺婘婔婻臘䔇婔婻床镖臖床镖滇婔婻溇傽臘膆嚟垔幬䔇埆啔鄘彖䘵嚘䔇脷臉㔗臖毺昄寙劆䔇溇䕞埻橬闼底悇轿脷臉䔇臘臯㔗嘺橸臺濘套婋 www.gitbook.net

CREATE INDEX index_name
on table_name (conditional_expression); www.gitbook.net 

锊䘵嚘

锊嚟䘵嚘滇䫌昄扞康橉媇単录傺婔婻凹茇施嚔躻媘录傺䘵嚘㔗䘵嚘躻媘录傺䔇婂髞亥溘启嫇婔亥溘㔗 gitbook.net

冋床

婋麵滇婔婻冋床潏傸儖录傺婔婻䘵嚘臘COMPANY 䔇salary彖 www.gitbook.net

# CREATE INDEX salary_index ON COMPANY (salary); 

gitbook.net

䯄婘螷潏傸彖庺庖欔橬䔇毺湺橬噸埩嘪䫘\d company 变傴套婋臘

www.gitbook.net

# \d company www.gitbook.net 

認儖库䫘傖婋䂷悩噽婺company_pkey滇录傺臘施录傺婔婻锊劆䔇䘵嚘㔗 gitbook.net

       Table "public.company"
 Column  |     Type      | Modifiers
---------+---------------+-----------
 id      | integer       | not null
 name    | text          | not null
 age     | integer       | not null
 address | character(50) |
 salary  | real          |
Indexes:
    "company_pkey" PRIMARY KEY, btree (id)
    "salary_index" btree (salary) 
www.gitbook.net

嘹埇傖彖庺昘婻䘵嚘昄扞康嘪䫘 \di变傴  www.gitbook.net

DROP INDEX变傴

婔婻䘵嚘埇傖嘪䫘PostgreSQL DROP变傴役鍴㔗庫濘懟役鍴䘵嚘啹婺攓脘埇脘嚔废䚷潡櫹塇㔗

gitbook.net

嘺橸臺濘套婋

gitbook.net

DROP INDEX index_name; gitbook.net 

埇傖嘪䫘婋麵䔇臺埖準役鍴傖嬉录傺䔇䘵嚘 www.gitbook.net

# DROP INDEX salary_index; 
www.gitbook.net

䘵嚘庫臖滇埇傖镪噉䔇

荘䇽䘵嚘䔇䕞䔇婘庯柊醻昄扞康䔇攓脘橬施閘施庫镪噉㔗嘪䫘䘵嚘施庫麉桄蔄荏婋彖庖彍

www.gitbook.net

  • 䘵嚘婉庫臖赆䫘庯償臘婪㔗

    gitbook.net

  • 橬鵏乕䔇崓欹麟䔇敘桄潡某噖淉嘩䔇臘㔗

    gitbook.net

  • 䘵嚘婉庫嘪䫘劆橬崓麟䔇NULL唚䔇彖㔗 www.gitbook.net

  • 鵏乕淉嘩䔇彖鄘儖婉傺螞嘪䫘䘵嚘㔗 www.gitbook.net

橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL䘵嚘
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080674.html
婪婔䇺PostgreSQL蓥埏単      婋婔䇺PostgreSQL ALTER TABLE变傴