状态值在数据库中的检索

WBOY
發布: 2016-06-07 15:28:43
原創
1112 人瀏覽過

对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否) t_girlcreate table rank_status (id integer not null, i_status varchar(3) not null); t_girlcreate table rank_status_extend (

对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否)
t_girl>create table rank_status (id integer not null, i_status varchar(3) not null);
登入後複製
t_girl>create table rank_status_extend (i_status varchar(3) not null, ids text);
t_girl> insert into rank_status values (222222,'yes'); Time: 4.397 ms t_girl>update rank_status_extend set ids = ids ||','||'222222' where i_status = 'yes'; Time: 43.725 ms
登入後複製
t_girl>delete from rank_status where i_status = 'yes' and id = 1; Time: 47.339 ms t_girl>update rank_status_extend set ids = replace(ids,',1,',',') where i_status = 'yes'; Time: 45.046 ms
登入後複製
t_girl>update rank_status set id = 1000 where i_status = 'yes' and id = 20; Time: 65.834 ms t_girl>update rank_status_extend set ids = replace(ids,',20,',',1000,') where i_status = 'yes'; Time: 85.974 ms
登入後複製
t_girl>select count(*) as total from rank_status where i_status = 'yes'; total ------- 99600 (1 row) Time: 86.563 ms t_girl>select length(ids) - length(replace(ids,',','')) + 1 as total from rank_status_extend where i_status = 'yes'; total ------- 99600 (1 row) Time: 35.762 ms t_girl>select string_agg(id::text,','),i_status from rank_status group by i_status; Time: 113.393 ms t_girl>select ids from rank_status_extend where i_status = 'yes'; Time: 2.447 ms
登入後複製
t_girl>create table rank_status_yes (id int not null); 3552 kB t_girl>create table rank_status_no(id int not null); 3584 kB
登入後複製
t_girl>create materialized view mv_rank_status_yes as select * from rank_status where i_status = 'yes';
登入後複製
这种其实和第二种表很类似。只不过不同的是第二种表的维护需要人工来做,而这个视图系统可以维护。
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!