Subject RE: [firebird-support] Speed optimization required for DELETE query
Author Vishal Tiwari
First of all thanks for replay.
Table Table_C contains near about 83 thousand records.
Table Table_A contains near about 18 thousand records.
Table Table_B contains near about 19 thousand records.
Sub query returns 8066 records withing 1 or 2 seconds.
The idea behind this DELETE query is to purge the data for given period, which is not required now, but with this we don't want to delete some employees data from given period.
I hope i explained proper background.

--- On Thu, 10/9/09, Rick Debay <rdebay@...> wrote:

From: Rick Debay <rdebay@...>
Subject: RE: [firebird-support] Speed optimization required for DELETE query
Date: Thursday, 10 September, 2009, 1:27 AM


How fast does it work as a select, e.g. "Delete from Table_C C where..."
and if that is slow, what's the plan? How many rows does it return?
Instead of extracting the year and month, can you filter < '2007-04-01'
(if the plan shows it doesn't use a date index, and it's a useful

-----Original Message-----
From: firebird-support@ yahoogroups. com
[mailto:firebird-support@ yahoogroups. com] On Behalf Of vishualsoft
Sent: Wednesday, September 09, 2009 11:08 AM
To: firebird-support@ yahoogroups. com
Subject: [firebird-support] Speed optimization required for DELETE query

Hi All,

I have one query that needs to delete certain records for the specified

Fields name and their respective data types:
1) dt_Date Date
2) var_EmpCode Varchar(15)
3) var_PGCode Varchar(10)
3) var_Status Varchar(1)
4) var_Resigned_ But_Not_Settled Varchar(1)
5) dt_AppliedDate Date

1) dt_Date is already indexed field in the table Table_C.
2) var_EmpCode and var_PGCode are indexed fields in
the table Table_A

i) Table Table_A contains unique employee ID and their
respective data i.e. one record per employee.

ii) Table Table_B contains the history of each employee
which are in table Table_A
i.e. it contains more than one record for
each emplyee which are in table Table_A.

iii) All the three table contains the fields var_EmpCode
and var_PGCode.

Query is taking much more time than expectation.

Thanks in Advance.

************ ********* ********* ********* *********
Query is as follows:

Delete from Table_C C
Extract(Year from C.dt_Date) <= '2007'
Extract(Month from C.dt_Date) <= '03'
Not In(
Select Distinct(A.var_ EmpCode)
from Table_A A Join Table_B B
A.var_EmpCode = B.var_EmpCode
A.var_PGCode = B.var_PGCode
(A.var_Status = 'I'
A.var_Resigned_ But_Not_Settled = 'Y')

Group By A.var_EmpCode
Having Max(B.dt_AppliedDat e) < '03/31/2007'

Even if we modifiy sub query as shown below,
it takes same amount of time.

Modified sub query:

Select Distinct(A.var_ EmpCode)
from Table_A A Join Table_B B
(A.var_EmpCode = B.var_EmpCode
A.var_PGCode = B.var_PGCode
(A.var_Status = 'I'
A.var_Resigned_ But_Not_Settled = 'Y')

Group By A.var_EmpCode
Having Max(B.dt_AppliedDat e) < '03/31/2007'

Disclaimer: This message (including attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change. RxStrategies, Inc. shall not be liable for the improper or incomplete transmission of the information contained in this communication or for any delay in its receipt or damage to your system. RxStrategies, Inc. does not guarantee that the integrity of this communication has been maintained nor that this communication is free from viruses, interceptions or interference.

See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz.

[Non-text portions of this message have been removed]