优化一个4表相关的oracle查询
我需要优化以下查询,但不知道如何优化。
select distinct v.codvia,
v.codproine,
v.codmunine,
tv.SIMBOLO as SIMBOLO_TIPO_VIA,
tv.NOMBRE as TIPO_VIA,
c.nombrevia as NOMBRE_VIA,
v.cp,
m.nombre as NOMBRE_MUNICIPIO ,
pr.nombre as NOMBRE_PROVINCIA
from tdinumvias v, tdimunicipio m, tdivia c, cditipovia tv, tdiprovincia pr
where (pr.codine = v.codproine) and
(m.codproine = v.codproine and m.codine = v.codmunine) and
(c.codproine = v.codproine and c.codmunine = v.codmunine and
c.codvia=v.codvia and tv.idtipovia=c.idtipovia)
为以下对象创建了索引: v.鳕鱼肽, v.科德维亚, v.科德穆宁, c.考德穆宁, 可待因原, 米可待因, c.鳕鱼肽, 伊迪波维亚 和 c.idtipovia
在它的对应表中,但性能仍然很糟糕。
从评论中添加: 桌子尺寸为 11M in tdinumvias, tdimunicipio 10K, 970K 的 tdivia 其他的只有几行。
它需要不到一秒的时间,我想知道是否有可能将其达到 100 - 200 英里。
更新:
最后我们创建了一个新的中间表,其中 cp、codproine 和 codmunie 预先计算并编译为视图,然后使第一个查询从该视图中获取数据,这样可以得到大约 300-400 条查询米利斯.它没有我们想要的那么好,但没关系。
谢谢
I need to optimize the following query but 'm not able to wonder how.
select distinct v.codvia,
v.codproine,
v.codmunine,
tv.SIMBOLO as SIMBOLO_TIPO_VIA,
tv.NOMBRE as TIPO_VIA,
c.nombrevia as NOMBRE_VIA,
v.cp,
m.nombre as NOMBRE_MUNICIPIO ,
pr.nombre as NOMBRE_PROVINCIA
from tdinumvias v, tdimunicipio m, tdivia c, cditipovia tv, tdiprovincia pr
where (pr.codine = v.codproine) and
(m.codproine = v.codproine and m.codine = v.codmunine) and
(c.codproine = v.codproine and c.codmunine = v.codmunine and
c.codvia=v.codvia and tv.idtipovia=c.idtipovia)
there are indexes created for:
v.codproine,
v.codvia,
v.codmunine,
c.codmunine,
pr.codine,
m.codine,
c.codproine,
v.idtipovia
and c.idtipovia
In it's correspondent tables but the performance is still really bad.
Added from comments :
Table sizes are
11M in tdinumvias,
10K in tdimunicipio,
970K in tdivia
the others only have a few rows.
It takes a bit less than a second and i was wondering if it was possible to get it to 100 - 200 milis.
Update:
Finally we have created a new intermediate table with cp, codproine and codmunie precalculated and compiled as a view, then make the first query get data from this view, this gets the query in about 300-400 Millis . it's not as good as we wanted but it's okay.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 ANSI-92 语法重新编写,除了可读性之外,它不会提供任何性能优势:
检查您的 JOIN - 它们正是创建 DISTINCT 需求的原因。至少需要将一个 JOIN 转换为 IN 或 EXISTS 子句以消除重复项。
I re-wrote using ANSI-92 syntax, which won't provide any performance benefit aside from readability:
Review your JOINs - they are what is creating the need for the DISTINCT. At least one JOIN needs to be converted into an IN or EXISTS clause to get rid of the duplicates.