Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在我的查询中是否有改进的余地,以使其运行更快?_Sql_Oracle - Fatal编程技术网

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(用于连接条款)
请注意,索引将帮助您更快地执行select查询。但会减慢更新、插入和删除语句的速度

查看oracle物化视图是否能满足您的需要


您在投影中使用的别名“l”未在查询中定义。你可能想检查一下

至少没有执行计划是不可能帮助你的。@Zaratutra我不明白…你说的执行计划是什么意思?关于执行计划。请阅读手册:您还需要提供所有表和所有已定义索引的定义。请参见此处:在不了解性能的情况下,您认为如何提高性能?没有解决任何查询性能问题的灵丹妙药。您必须至少知道什么是统计数据以及如何使用统计数据,还必须知道如何创建执行计划并能够阅读。@Zaratutra感谢您的评论。