Following is the architecture of the table:
CREATE TABLE [dbo].[SMS_Campaign_Attempts]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID] [int] NULL, [OfferProduct] [varchar](50) NOT NULL, [MobileNumber] [numeric](18, 0) NOT NULL, [SMSMessage] [varchar](255) NOT NULL, [SendDate] [date] NOT NULL, [CustomerID] [varchar](max) NULL, CONSTRAINT [PK_SMS_Campaign_Attempts] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Now below are three update scripts which I need to run:
1.
UPDATE Atmpt SET SMSMessage=REPLACE(SMSMessage,'Customer',ISNULL(CASE WHEN LEN(ISNULL(FNAME,''))=10 THEN FNAME WHEN LEN(ISNULL(FNAME,''))>=4 AND LEN(ISNULL(FNAME,''))<10 AND (LEN(FNAME)+LEN(MNAME)>=10 OR LEN(FNAME)+LEN(MNAME) IS NULL)THEN FNAME WHEN LEN(ISNULL(FNAME,''))>=4 AND LEN(ISNULL(FNAME,''))<10 AND LEN(ISNULL(FNAME,''))+LEN(ISNULL(MNAME,''))<10 THEN FNAME+' '+MNAME WHEN LEN(ISNULL(FNAME,''))<4 AND LEN(ISNULL(LNAME,''))>=3 AND LEN(ISNULL(FNAME,''))+LEN(ISNULL(LNAME,''))<10 THEN FNAME+' '+LNAME WHEN LEN(ISNULL(FNAME,''))<4 AND LEN(ISNULL(MNAME,''))>=3 AND LEN(FNAME)+LEN(ISNULL(LNAME,''))<10 THEN FNAME+' '+MNAME WHEN LEN(ISNULL(FNAME,''))<3 AND LEN(ISNULL(MNAME,''))<3 AND LEN(ISNULL(LNAME,''))<=10 THEN LNAME WHEN LEN(ISNULL(FNAME,'')+ISNULL(MNAME,''))=10 AND LEN(ISNULL(LNAME,''))>10 THEN FNAME+MNAME WHEN LEN(ISNULL(FNAME,'')+ISNULL(MNAME,''))<10 THEN FNAME+' '+MNAME WHEN LEN(ISNULL(FNAME,'')+ISNULL(LNAME,''))<10 THEN FNAME+' '+LNAME ELSE 'Customer' END,'')) FROM SMS_Campaign_Attempts Atmpt WITH(NOLOCK) JOIN DM_CRM..Channel_SMS SMS WITH(NOLOCK)ON SMS.MobileNumber=Atmpt.MobileNumber JOIN DM_MKTANL.DM_BAFL.DBO.DimCustomer DimCust WITH(NOLOCK)ON DimCust.CustomerID=SMS.CustomerID WHERE OfferProduct IN ('SEPHL','SHL','SBS_LAP','SBS_PSBL','SBS_HL','SALPL','SALPL_LIVR') AND SendDate=CONVERT(DATE,GETDATE())
2.
UPDATE SMS_Campaign_Attempts SET SMSMessage=REPLACE(SMSMessage,'Dear ,','Dear Customer,') WHERE OfferProduct IN ('SEPHL','SHL','SBS_LAP','SBS_PSBL','SBS_HL') AND SendDate=CONVERT(DATE,GETDATE()) AND SMSMessage LIKE 'Dear ,%'
3.
UPDATE Atmpt SET SMSMessage=REPLACE(SMSMessage,'OfferAmount',CONVERT(INT,IC.OfferAmount)) FROM SMS_Campaign_Attempts Atmpt JOIN #InterimCampaign IC ON IC.OfferProduct=Atmpt.OfferProduct AND Atmpt.MobileNumber=IC.MobileNumber WHERE Atmpt.OfferProduct IN ('SBS_LAP','SBS_PSBL','SBS_HL') AND SendDate=CONVERT(DATE,GETDATE())
Now When I create estimated execution plan. I get three Missing Indexes as following respectively:
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON [dbo].[SMS_Campaign_Attempts] ([SendDate],[OfferProduct]) INCLUDE ([ID],[MobileNumber],[SMSMessage]) CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON [dbo].[SMS_Campaign_Attempts] ([SendDate],[OfferProduct],[SMSMessage]) INCLUDE ([ID]) CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON [dbo].[#InterimCampaign] ([OfferProduct]) INCLUDE ([MobileNumber],[OfferAmount]) GO
So my question is that I know I can't avoid the third index but is there any way where I can club first two indexes into one.
If any more details are needed please let me know.
Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real. The climb is all there is.