标签:character heap 不同 odi 记录 ring 基于 res 相同
假如我们有这样一个原始表。基于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)
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=#
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
t_girl=# select * from status_check where str1 in (‘10‘,‘23‘,‘33‘); is_yes | str1 | str2 --------+------+---------------------- t | 10 | d3d9446802a44259755d t | 23 | 37693cfc748049e45d87 f | 33 | 182be0c5cdcd5072bb18 (3 rows) Time: 0.690 ms
t_girl=# select is_yes,skeys(str1_str2),svals(str1_str2) from status_check_hstore where str1_str2 ?| array[‘10‘,‘23‘,‘33‘]; is_yes | skeys | svals --------+-------+---------------------- t | 10 | d3d9446802a44259755d t | 23 | 37693cfc748049e45d87 f | 33 | 182be0c5cdcd5072bb18 (3 rows) Time: 40.256 ms
QUERY PLAN ----------------------------------------------------------------------------------- Bitmap Heap Scan on status_check_hstore (cost=5.06..790.12 rows=100000 width=38) Recheck Cond: (str1_str2 ?| ‘{10,23,33}‘::text[]) -> Bitmap Index Scan on idx_str_str2_gist (cost=0.00..5.03 rows=100 width=0) Index Cond: (str1_str2 ?| ‘{10,23,33}‘::text[]) (4 rows) Time: 0.688 ms
t_girl=# create index idx_str1_str2_akeys on status_check_hstore using btree (array_to_string(akeys(str1_str2),‘,‘)); CREATE INDEX Time: 394.123 ms
t_girl=# select is_yes,skeys(str1_str2),svals(str1_str2) from status_check_hstore where array_to_string(akeys(str1_str2),‘,‘) in (‘10‘,‘23‘,‘33‘); is_yes | skeys | svals --------+-------+---------------------- t | 10 | d3d9446802a44259755d t | 23 | 37693cfc748049e45d87 f | 33 | 182be0c5cdcd5072bb18 (3 rows) Time: 0.727 ms
标签:character heap 不同 odi 记录 ring 基于 res 相同
原文地址:http://www.cnblogs.com/brucemengbm/p/6920211.html