November 6, 2008 at 9:42 pm
Hi,
I have a table when I run a select statements it is taking lot of time and returning 17000 row.
Please find the table structure here.
CREATE TABLE [ContractHistory] (
[ContractNo] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Branch] [tinyint] NOT NULL ,
[CcyCode] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[WHCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[StartDate] [smalldatetime] NOT NULL ,
[MaturityDate] [smalldatetime] NOT NULL ,
[DealDate] [smalldatetime] NOT NULL ,
[DealTime] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EODDate] [smalldatetime] NOT NULL ,
[Action] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SubProductId] [smallint] NULL ,
[Asset] [bit] NULL ,
[BaseNo] [bigint] NULL ,
[CustomerName] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DealerCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Principal] [numeric](28, 16) NULL ,
[IssueDate] [smalldatetime] NULL ,
[FirstStartDate] [smalldatetime] NULL ,
[FinalMaturityDate] [smalldatetime] NULL ,
[DealRate] [float] NULL ,
[CoverRate] [float] NULL ,
[InterestType] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[InterestSchedule] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[InterestMethod] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AmortisationSchedule] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AmortisationAmount] [numeric](28, 16) NULL ,
[RateCurveId] [tinyint] NULL ,
[ContractType] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AccruedDays] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CouponRate] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AuthorizeDate] [smalldatetime] NULL ,
[DailyAccrual] [numeric](28, 16) NULL ,
[ToDateAccrual] [numeric](28, 16) NULL ,
[ProjectedDailyAccrual] [numeric](28, 16) NULL ,
[InterestAmount] [numeric](28, 16) NULL ,
[LastUpdatedOn] [smalldatetime] NULL ,
[BondType] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
CONSTRAINT [PK_ContractHistory] PRIMARY KEY CLUSTERED
(
[ContractNo],
[Branch],
[CcyCode],
[WHCode],
[StartDate],
[MaturityDate],
[EODDate],
[Action]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
//Constraint
ALTER TABLE [dbo].[ContractHistory] ADD CONSTRAINT [PK_ContractHistory] PRIMARY KEY CLUSTERED
(
[ContractNo],
[Branch],
[CcyCode],
[WHCode],
[StartDate],
[MaturityDate],
[EODDate],
[Action]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
//Index
CREATE INDEX [IX_ContractHistory] ON [dbo].[ContractHistory]([ContractNo], [Branch], [CcyCode], [WHCode], [EODDate] DESC , [Action], [RateCurveId]) ON [PRIMARY]
GO
//select stament
select * from dbo.ContractHistory where eoddate between '20080902'
and '20080903' and (action='delete' or action='')
Please help us to Increase the performance. because this table used in other SP and that SP's performance is very poor.
Thanx
Kiran
November 7, 2008 at 1:37 am
Why create a second index almost identical as your composite primary key?
N 56°04'39.16"
E 12°55'05.25"
November 7, 2008 at 5:08 am
Please ignore that part
November 7, 2008 at 5:13 am
Hi Kiran
How many records are there in this table that you have created? have u got an execution plan for his query??
Cheers
🙂
November 7, 2008 at 5:24 am
there are 3lakh files.
select cost 6%
cintracthistory cost 94%
November 7, 2008 at 5:40 am
try like:
select * from dbo.ContractHistory with (nolock) (index = IX_ContractHistory)
where eoddate between '20080902' and '20080903' and
(action = 'delete' or isnull (action, '') = '')
November 7, 2008 at 5:59 am
CREATE INDEXIX_ContractHistory ON dbo.ContractHistory
(
EODDate DESC,
Action,
ContractNo,
Branch,
CcyCode,
WHCode,
RateCurveID
) ON [PRIMARY]
SELECT*
FROMdbo.ContractHistory
WHEREeodDate >= '20080902'
AND eodDate < '20080903'
AND (Action = 'delete' OR Action = '')
N 56°04'39.16"
E 12°55'05.25"
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply