2014-10-27 67 views
0

我遇到的問題讓我的查詢正常執行。我有一張7000萬行的桌子。我試圖在ip表中搜索特定日期之間分配給客戶的不同ip地址。這些日期由一個釋放日期控制。Oracle查詢或聲明問題以及性能調優

因此,

我試圖尋找分配給客戶的IPS表時的釋放日期爲空或每月的1日和31日之間。我的查詢不能很快運行,也是我第一次在deallocation_date爲空的同一行上運行它,它返回每一行。

這是我第一次運行它的方法,它返回了每個客戶,而不僅僅是我正在尋找的客戶,花了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')) 
/

我也嘗試過,並與空重僅返回值:

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')) 
/
+1

哪些查詢計劃?已創建了哪些索引? – 2014-10-27 19:50:59

+0

我只是想讓它返回正確的信息,我不認爲我的查詢條件適合我試圖返回的內容。 – 2014-10-27 19:56:37

+0

如果您檢查我剛發佈的相關子查詢,它仍然只返回值爲deallocation date null。此外,如果你真的需要這些信息,我會爲你解決這個問題,但是現在我還不知道它。我只是試圖運行一個ip分配問題。 – 2014-10-27 19:57:30

回答

0
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')) 
/