mysql - mysql查询与oracle查询相比的性能问题

标签 mysql oracle database-performance

我创建了一个复杂的 View ,它在 Oracle 10g DBMS 上在一秒钟内提供输出..但相同的 View 在 MYSQL DBMS 上需要 2.3 分钟..我已经在 View 中包含的所有字段上创建了索引定义并增加了 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 View 定义如下:

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 View 定义如下:

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)

最佳答案

某些版本的 MySQL 在 in 和子查询方面存在特殊问题,您在此 View 中会遇到这些问题:

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)

尝试将其更改为:

where exists (select 1
              from posting
              group by belt_no
              having belt_no = p.belt_no and p.st_date = max(st_date)
             )

当然,可能还有其他问题。至少,您可以格式化查询,以便它们可读并使用 ANSI 标准连接语法。能够读取查询将是提高其性能的第一步。然后你应该在 MySQL 中使用 explain 来查看查询计划是什么样的。

关于mysql - mysql查询与oracle查询相比的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17222284/

相关文章:

mysql - Lucene.NET索引实时更新

java - 通过 Payara 4 诊断与 Oracle 的 XA 连接

Mysql SELECT查询及性能

sql - 如何根据特定字段中的数据向查询添加行

oracle - 保存 PL/SQL 异常并稍后引发它?

database-design - 何时使用水平分区,何时使用数据库分片?

sql - Postgres 不使用索引,即使返回的行少于 5%

mysql - 如何在 SQL 中连接多个表,其对象将使用继承建模?

Mysql从与另一个字段中的多个值匹配的行中找到不同的值

mysql - 使用 MySQL 进行 Delphi DBGrid 格式化