[英]Oracle - SQL query takes too much time
I have this tables: 我有这张桌子:
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: 我需要在自动机中获取每一行,其中:
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个额外的问题:
Any ideas? 有任何想法吗? I cannot figure out how to solve it without indexes.
我无法弄清楚如何解决没有索引的问题。
You have no join condition between automa and profil . 您在automa和profil之间没有连接条件。 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.