我创建了一个复杂的视图,它在一秒钟内给我在 Oracle 10g DBMS 上的输出。但在 MYSQL DBMS 上,相同的视图需要 2.3 分钟。我已经在视图定义中包含的所有字段上创建了索引,并且增加了query_cache_size
但仍然未能在更短的时间内得到答案。我的查询如下
select * from results where beltno<1000;
而我的观点是:
create view results as select person_biodata.*,current_rank.*,current_posting.* from person_biodata,current_rank,current_posting where person_biodata.belt_no=current_rank.belt_no and person_biodata.belt_no=current_posting.belt_no ;
current_posting
视图定义如下:
select p.belt_no belt_no,ps.ps_name police_station,pl.pl_name posting_as,p.st_date from p_posting p,post_list pl,police_station ps where p.ps_id=ps.ps_id and p.pl_id=pl.pl_id and (p.belt_no,p.st_date) IN(select belt_no,max(st_date) from p_posting group by belt_no);
current_rank
视图定义如下:
select p.belt_no belt_no,r.r_name from p_rank p,rank r where p.r_id=r.r_id and (p.belt_no,p.st_date) IN (select belt_no,max(st_date) from p_rank group by belt_no)