Subject | RE: [firebird-support] Possible to have an index across 2 tables? |
---|---|
Author | Maya Opperman |
Post date | 2008-11-04T10:39:36Z |
Helen's Query:
select
i.CustomerID,
(select cus.Customer_name from Customers cus
where cus.CustomerID = i.CustomerID) as Customer,
max(c.xDate) Last_Comm_Date
from Incidents i
join Comms.c
on c.IncidentID = i.Incident_id
group by 1,2
----------------
As it looks for my DB:
select
i.CustomerID,
(select cus.companyname from Customers cus
where cus.ID = i.CustomerID) as Customer,
max(c.communicationdate) Last_Comm_Date
from customerincidents i
join customercommunications c
on c.IncidentID = i.id
where (i.customerid = :ICustomerID)
group by 1,2
----------------
My current query I'm using:
select first 1 * /*Note * just here for test
purposes - will be replacing)
from customerincidents ci
left outer join customercommunications cc
on cc.incidentid = ci.id
where (ci.customerID = :ICustomerID)
order by cc.communicationdate desc, cc.id desc
----------------
Using IBExpert's performance analysis tool, both queries are reading
through all comms and all incidents for my selected customer.
I'm using one of my more talkative customers, who have 329 incidents and
2458 comms and it's pretty quick 782 mille-seconds). I'm just worried
that I'm going to cause speed issues sooner or later by reading through
so many records.
If I had the customer id in the comms table, this query could be reduced
to only reading one record.
PS. I'm using FB 1.5. AFAIK using FB 2 won't affect index use at all
(because there's still no index FB2 can use either)
select
i.CustomerID,
(select cus.Customer_name from Customers cus
where cus.CustomerID = i.CustomerID) as Customer,
max(c.xDate) Last_Comm_Date
from Incidents i
join Comms.c
on c.IncidentID = i.Incident_id
group by 1,2
----------------
As it looks for my DB:
select
i.CustomerID,
(select cus.companyname from Customers cus
where cus.ID = i.CustomerID) as Customer,
max(c.communicationdate) Last_Comm_Date
from customerincidents i
join customercommunications c
on c.IncidentID = i.id
where (i.customerid = :ICustomerID)
group by 1,2
----------------
My current query I'm using:
select first 1 * /*Note * just here for test
purposes - will be replacing)
from customerincidents ci
left outer join customercommunications cc
on cc.incidentid = ci.id
where (ci.customerID = :ICustomerID)
order by cc.communicationdate desc, cc.id desc
----------------
Using IBExpert's performance analysis tool, both queries are reading
through all comms and all incidents for my selected customer.
I'm using one of my more talkative customers, who have 329 incidents and
2458 comms and it's pretty quick 782 mille-seconds). I'm just worried
that I'm going to cause speed issues sooner or later by reading through
so many records.
If I had the customer id in the comms table, this query could be reduced
to only reading one record.
PS. I'm using FB 1.5. AFAIK using FB 2 won't affect index use at all
(because there's still no index FB2 can use either)