PostgreSQL 支援hstore 來存放KEY->VALUE這類資料, 其實也類似於ARRAY或者JSON類型。 要高效的使用這類資料,當然離不開高效的索引。我們今天就來看看兩類不同的索引對於同一種檢索請求的效能問題。
假如我們有這樣一個原始表,基於str1欄位有一個BTREE索引。
t_girl=# \d status_check;
Table "ytt.status_check"
Column | Type | Modifiers
--------+-----------------------+-----------
is_yes | boolean | not null
str1 | character varying(20) | not null
str2 | character varying(20) | not null
Indexes:
"index_status_check_str1" btree (str1)
裡面有10W條記錄。 資料大概如下,
t_girl=# select * from status_check limit 2;
is_yes | str1 | str2
--------+------+----------------------
f | 0 | cfcd208495d565ef66e7
t | 1 | c4ca4238a0b923820dcc
(2 rows)
Time: 0.617 ms
t_girl=#
存放hstore類型的status_check_hstore 表結構,基於str1_str2欄位有一個GIST索引。
Table "ytt.status_check_hstore"
Column | Type | Modifiers
-----------+---------+-----------
is_yes | boolean |
str1_str2 | hstore |
Indexes:
"idx_str_str2_gist" gist (str1_str2)
t_girl=# select * from status_check_hstore limit 2;
is_yes | str1_str2
--------+-----------------------------
f | "0"=>"cfcd208495d565ef66e7"
t | "1"=>"c4ca4238a0b923820dcc"
(2 rows)
Time: 39.874 ms
更多詳情見請繼續閱讀下一頁的精彩內容:
------------------------------------華麗麗的分割線------------------------------------
CentOS 6.3環境下yum安裝PostgreSQL 9.3
PostgreSQL緩衝詳述
Windows平台編譯 PostgreSQL
Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)環境的配置與安裝
Ubuntu上的phppgAdmin安裝及配置
CentOS平台下安裝PostgreSQL9.3
PostgreSQL配置Streaming Replication叢集
------------------------------------華麗麗的分割線------------------------------------
PostgreSQL 的詳細介紹:請點這裡
PostgreSQL 的:請點這裡