>  기사  >  데이터 베이스  >  状态值在数据库中的检索

状态值在数据库中的检索

WBOY
WBOY원래의
2016-06-07 15:28:431089검색

对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否) 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';
这种其实和第二种表很类似。只不过不同的是第二种表的维护需要人工来做,而这个视图系统可以维护。
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.