簡體   English   中英

Oracle查詢或語句問題以及性能調整

[英]Oracle Query or statement issue, and performance tuning

我在讓查詢正確執行時遇到問題。 我有一個有七千萬行的表。 我正在嘗試在ip表中搜索在特定日期之間分配給客戶的不同ip。 這些日期由解除分配日期控制。

從而,

我正在嘗試在表中搜索當取消分配日期為空或一個月的1號到31號之間時分配給客戶的ips。 我的查詢運行得不是很快,同樣,當我第一次使用Deallocation_date為null或在同一行運行它時,它返回每一行。

這是我運行查詢的第一種方式,它不僅向我搜索的客戶返回了每個客戶,而且還花費了1分鍾才能開始執行。

select distinct e.ip_address, 
a.customer_name,
c.vm_id, 
d.allocation_date, 
d.deallocation_date
from customers a, 
vm_groups b, 
vms c, 
vm_ip_address_histories d, 
ip_addresses e 
where a.customer_id=30
and a.customer_id = b.customer_id
and b.vm_group_id = c.vm_group_id
and c.vm_id = d.vm_id
and d.ip_address_id = e.ip_address_id
and d.deallocation_date is null or trunc(d.deallocation_Date) between to_date('1-oct-14') and to_date('31-oct-14')
/

我運行它的第二種方法,但15分鍾后仍未返回

select distinct e.ip_address, 
a.customer_name,
c.vm_id, 
d.allocation_date, 
d.deallocation_date
from customers a, 
vm_groups b, 
vms c, 
vm_ip_address_histories d, 
ip_addresses e 
where a.customer_id=30
and a.customer_id = b.customer_id
and b.vm_group_id = c.vm_group_id
and c.vm_id = d.vm_id
and d.ip_address_id = e.ip_address_id
and d.deallocation_date is null 
or trunc(d.deallocation_Date) between to_date('1-oct-14') and to_date('31-oct-14')
/

我以為這種方式沒有解決問題,但沒有返回帶有取消分配日期的值。

select distinct e.ip_address, 
a.customer_name,
c.vm_id, 
d.allocation_date, 
d.deallocation_date
from customers a, 
vm_groups b, 
vms c, 
vm_ip_address_histories d, 
ip_addresses e 
where a.customer_id=30
and a.customer_id = b.customer_id
and b.vm_group_id = c.vm_group_id
and c.vm_id = d.vm_id
and d.ip_address_id = e.ip_address_id
and (d.deallocation_date is null or trunc(d.deallocation_Date) between to_date('1-oct-14') and to_date('31-oct-14'))
/

我也嘗試過,它只再次返回了null值:

select distinct e.ip_address, 
a.customer_name,
c.vm_id, 
d.allocation_date, 
d.deallocation_date
from customers a, 
vm_groups b, 
vms c, 
vm_ip_address_histories d, 
ip_addresses e 
where a.customer_id=30
and a.customer_id = b.customer_id
and b.vm_group_id = c.vm_group_id
and c.vm_id = d.vm_id
and d.ip_address_id = e.ip_address_id
and exists (select * from vm_ip_address_histories 
         where d.deallocation_date is null 
         or trunc(d.deallocation_Date) between to_date('1-oct-14') and last_day('1-oct-14'))
/
select distinct e.ip_address, 
a.customer_name,
c.vm_id, 
d.allocation_date, 
d.deallocation_date
from customers a, 
vm_groups b, 
vms c, 
vm_ip_address_histories d, 
ip_addresses e 
where a.customer_id=30
and a.customer_id = b.customer_id
and b.vm_group_id = c.vm_group_id
and c.vm_id = d.vm_id
and d.ip_address_id = e.ip_address_id
and (d.deallocation_date is null or d.deallocation_date between to_date('01-10-2014', 'DD-MM-YYYY') and to_date('31-10-2014 23:59:59', 'DD-MM-YYYY HH24:MI:SS'))
/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM