简体   繁体   English

Oracle 数据库查询调优

[英]Oracle database query tuning

I have a big sql query and its difficult to manage, what I need help ifI can do anything like -我有一个很大的 sql 查询,而且很难管理,如果我可以做任何事情,我需要什么帮助 -

store the inner queries in variables and use variable as reference in the outer queries example将内部查询存储在变量中,并在外部查询示例中使用变量作为参考

var1 = select * from customer
var2 = select * from product
var3= select custid from var1

and finally

select a.customername,b*,c* from var1 as a, var2 as b , var3 as c  where a.custid = c.c_id and     
a.custid = b.custid 

Note I am not a database person, I am a java programmer注意我不是数据库人,我是java程序员

You can use CTEs (Common Table Expressions) to simplify the main query.您可以使用 CTE(通用表表达式)来简化主查询。 For example, your query can be rephrased as:例如,您的查询可以改写为:

with
a as (
  -- big complex query #1 here
),
b as (
  -- big complex query #2 here
),
c as (
  -- big complex query #3 here
)
select a.customername, b.*, c.* -- the main query starts at this line
from a
join b on b.custid = a.custid
join c on c.c_id = a.custid

The main query can have references to any of the CTEs ( a , b , or c ).主查询可以引用任何 CTE( abc )。 Each CTE can alse have references to the previously defined CTEs;每个 CTE 还可以引用先前定义的 CTE; in your example, the third one will probably reference the first one.在您的示例中,第三个可能会引用第一个。

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

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