【发布时间】:2014-10-28 05:13:09
【问题描述】:
我在正确执行查询时遇到问题。我有一个有 7000 万行的表。我正在尝试在 ip 表中搜索在特定日期之间分配给客户的不同 ip。这些日期由解除分配日期控制。
因此,
当解除分配日期为空或在一个月的 1 日和 31 日之间时,我正在尝试在表中搜索分配给客户的 ips。我的查询运行速度不是很快,也是我第一次使用或在同一行上运行它时,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'))
/
我也试过了,它只返回了 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'))
/
【问题讨论】:
-
查询计划是什么?创建了哪些索引?
-
我只是想让它返回正确的信息,我认为我的查询条件不适合我想要返回的内容。
-
如果您检查我刚刚发布的相关子查询,它仍然只返回释放日期为空的值。另外,如果您真的需要该信息,我会为您获取,但我现在还不知道。我只是想解决一个 ip 分配问题。