Sql 在我的查询中是否有改进的余地,以使其运行更快?
我不熟悉编写查询,想知道是否可以加快查询的执行速度Sql 在我的查询中是否有改进的余地,以使其运行更快?,sql,oracle,Sql,Oracle,我不熟悉编写查询,想知道是否可以加快查询的执行速度 select p.attr_value product, m.attr_value model, u.attr_value usage, t4.attr_value location from table1 t1 join table2 t2 on t1.e_subid = t2.e_subid join table4 t4 on t4.loc_id = t1.loc_id
select
p.attr_value product,
m.attr_value model,
u.attr_value usage,
t4.attr_value location
from table1 t1 join table2 t2 on t1.e_subid = t2.e_subid
join table4 t4 on t4.loc_id = t1.loc_id
join table3 p on t2.e_cid = p.e_cid
join table3 m on t2.e_cid = m.e_cid
join table3 u on t2.e_cid = u.e_cid
Where
t4.attr_name = 'Location'
and p.attr_name = 'Product'
and m.attr_name = 'Model'
and u.attr_name = 'Usage'
order by product,location;
一种提高性能的强力方法是创建连接中使用的列的索引,where子句和order by 在您的情况下,在下面的列上创建索引
- 表4.attr_名称(用于where子句)
- 表3.attr_名称(用于where子句)
- 表1.e_子ID(用于连接条款)
- 表2.e_子ID(用于连接条款)
- 表4.loc_id(用于连接条款)
您在投影中使用的别名“l”未在查询中定义。你可能想检查一下至少没有执行计划是不可能帮助你的。@Zaratutra我不明白…你说的执行计划是什么意思?关于执行计划。请阅读手册:您还需要提供所有表和所有已定义索引的定义。请参见此处:在不了解性能的情况下,您认为如何提高性能?没有解决任何查询性能问题的灵丹妙药。您必须至少知道什么是统计数据以及如何使用统计数据,还必须知道如何创建执行计划并能够阅读。@Zaratutra感谢您的评论。