简体   繁体   English

Oracle-SQL查询花费太多时间

[英]Oracle - SQL query takes too much time

I have this tables: 我有这张桌子:

  • automa 自动机
  • accoun co
  • client 客户
  • profil 概况
  • market 市场

The biggest one is accoun, with almost 30 million rows. 最大的账户是accoun,拥有近3000万行。 There are like 20 thousand rows in client, and 30 thousand rows in automa. 客户端有2万行,自动机有3万行。

I need to get every row in automa, where: 我需要在自动机中获取每一行,其中:

  • mktcode matches mktcode from market mktcode与市场上的mktcode匹配
  • acccode matches acccode from accoun acccode匹配来自accoun的acccode
  • ccccode from accoun matches ccccode from client accoun的ccccode与客户端的ccccode匹配
  • clicode from client matches clicode from profil 客户端的客户端代码与配置文件中的客户端代码相匹配
  • procode from profil is 'ADMIN' profil中的procode为“ ADMIN”

This is my query: 这是我的查询:

SELECT au.acccode, au.oprcode, au.ctrcode, au.ctrdesc, au.mkcode
FROM automa au
JOIN profil pr ON pr.procode = 'ADMIN'
JOIN client cl ON cl.clicode = pr.clicode
JOIN market mk ON mk.mktcode = au.mkcode
JOIN accoun ac ON ac.ccccode = cl.ccccode AND ac.acccode = au.acccode
GROUP BY au.acccode, au.oprcode, au.ctrcode, au.ctrdesc, au.mkcode

It takes like 60 seconds. 大约需要60秒。

I have 2 extra problems: 我有2个额外的问题:

  • I cannot see the execution plan 我看不到执行计划
  • I cannot create indexes. 我无法创建索引。 If it's the only way, I could ask for them to be created, but that would take some time to be done. 如果这是唯一的方法,我可以要求创建它们,但这需要一些时间才能完成。

Any ideas? 有任何想法吗? I cannot figure out how to solve it without indexes. 我无法弄清楚如何解决没有索引的问题。

You have no join condition between automa and profil . 您在automaprofil之间没有连接条件。 If you try 如果你试试

SELECT au.acccode, au.oprcode, au.ctrcode, au.ctrdesc, au.mkcode
  FROM automa au
  JOIN profil pr ON pr.procode = 'ADMIN'

this query returns ALL rows from automa, without any filtering. 该查询从自动机返回所有行,而不进行任何过滤。 Firstly, add join condition. 首先,添加加入条件。

You can also try to rewrite this query. 您也可以尝试重写此查询。 Because you need data only from automa , try to use EXISTS. 因为您只需要来自automa的数据,请尝试使用EXISTS。 May be after that you will not need in grouping/distinct. 可能之后,您将不需要分组/区分。 Something like that: 像这样:

SELECT au.acccode, au.oprcode, au.ctrcode, au.ctrdesc, au.mkcode
  FROM automa au
 where exists (select null 
                from profil pr 
                JOIN client cl ON cl.clicode = pr.clicode and pr.procode = 'ADMIN'
                JOIN accoun ac ON ac.ccccode = cl.ccccode 
                              AND ac.acccode = au.acccode
                JOIN market mk ON mk.mktcode = au.mkcode
               )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM