• ChrisM@Work (3/19/2013)


    DDL for the table and all indexes, and the actual plans for both queries, would help diagnosis.

    An index on sessionid including status and rsn may solve the problem.

    Apologies for the delay,

    CREATE TABLE [dbo].[orderha](

    [rsn] [bigint] IDENTITY(1,1) NOT NULL,

    [sessionid] [nvarchar](50) NOT NULL,

    [orderha] [int] NOT NULL,

    [perc] [decimal](18, 8) NOT NULL,

    [userid] [bigint] NOT NULL,

    [hashtotal] [decimal](18, 2) NOT NULL,

    [dateadded] [datetime] NOT NULL,

    [shipped] [tinyint] NOT NULL,

    [status] [int] NOT NULL,

    [suspectorder] [tinyint] NOT NULL,

    [shippingweight] [decimal](18, 2) NOT NULL,

    [discount] [decimal](18, 2) NOT NULL,

    [shiptotal] [decimal](18, 2) NOT NULL,

    [shipopt] [int] NOT NULL,

    [rd] [tinyint] NOT NULL,

    [giftwrap] [tinyint] NOT NULL,

    [bay] [int] NOT NULL,

    [instock] [tinyint] NOT NULL,

    [beenupdated] [tinyint] NOT NULL,

    [shipdate] [datetime] NULL,

    [vatamount] [decimal](18, 2) NOT NULL,

    [prodname] [nvarchar](250) NOT NULL,

    [source] [char](2) NOT NULL,

    [externalsessionid] [nvarchar](70) NOT NULL,

    [postalrsn] [bigint] NOT NULL,

    [printref] [nvarchar](50) NOT NULL,

    [sdref] [nvarchar](20) NOT NULL,

    [oos] [tinyint] NOT NULL,

    [sdreflabel] [nvarchar](20) NOT NULL,

    [bin] [nvarchar](20) NOT NULL,

    CONSTRAINT [PK_orderha] PRIMARY KEY CLUSTERED

    (

    [rsn] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    ) ON [PRIMARY]

    /****** Object: Index [IX_dateadded] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_dateadded] ON [dbo].[orderha]

    (

    [dateadded] ASC

    )

    INCLUDE ( [shiptotal]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_gw] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_gw] ON [dbo].[orderha]

    (

    [giftwrap] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_oh] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_oh] ON [dbo].[orderha]

    (

    [orderha] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_printeref] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_printeref] ON [dbo].[orderha]

    (

    [printref] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    GO

    /****** Object: Index [IX_rd] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_rd] ON [dbo].[orderha]

    (

    [rd] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_sessionid] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_sessionid] ON [dbo].[orderha]

    (

    [sessionid] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_shipopt] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_shipopt] ON [dbo].[orderha]

    (

    [shipopt] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    GO

    /****** Object: Index [IX_shipopt_suspect_status_rsn_dateadded] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_shipopt_suspect_status_rsn_dateadded] ON [dbo].[orderha]

    (

    [shipopt] ASC,

    [suspectorder] ASC,

    [status] ASC,

    [rsn] ASC,

    [dateadded] ASC

    )

    INCLUDE ( [sessionid]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_shipopt_suspect_status_rsn_dateadded_oos] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_shipopt_suspect_status_rsn_dateadded_oos] ON [dbo].[orderha]

    (

    [suspectorder] ASC,

    [status] ASC,

    [shipopt] ASC,

    [oos] ASC,

    [dateadded] ASC,

    [rsn] ASC

    )

    INCLUDE ( [sessionid],

    [shippingweight],

    [rd]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO

    /****** Object: Index [IX_status] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_status] ON [dbo].[orderha]

    (

    [status] ASC

    )

    INCLUDE ( [printref]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    GO

    /****** Object: Index [IX_suspect] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_suspect] ON [dbo].[orderha]

    (

    [suspectorder] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    GO

    /****** Object: Index [IX_suspect_status_rsn_shipopt] Script Date: 03/20/2013 11:38:13 ******/

    CREATE NONCLUSTERED INDEX [IX_suspect_status_rsn_shipopt] ON [dbo].[orderha]

    (

    [suspectorder] ASC,

    [status] ASC,

    [rsn] ASC,

    [shipopt] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    GO