• Welsh Corgi (11/25/2015)


    I thought that since I was partition by BeginDate I had to include that in the Clustered Index?

    If you think about partitioning by [BeginDate] you should have at least an index on it.

    For a start...

    It's better to have it as a clustered index, but it's only if you're closed for the long weekend and you can afford a downtime for reconstructing the table with all its indexes.

    For now - create an simple 1 column non-clustered index on [BeginDate] and try these 2 queries:

    SET STATISTICS IO ON

    SET STATISTICS TIME ON

    SELECT TOP 2000 * from dbo.xactControlPoint T (NOLOCK)

    WHERE beginDate BETWEEN '2014-11-01' AND '2014-12-01' -- = '45409114'

    SELECT TOP 2000 *

    FROM dbo.xactControlPoint T

    INNER JOIN (

    SELECT MIN(xactControlPointID) FromID, MAX(xactControlPointID) ToID

    FROM dbo.xactControlPoint WITH (INDEX ([IX_xactControlPoint_beginDate]))

    WHERE beginDate BETWEEN '2014-11-01' AND '2014-12-01'

    ) F ON T.xactControlPointID BETWEEN F.FromID AND F.ToID

    WHERE beginDate BETWEEN '2014-11-01' AND '2014-12-01'

    SET STATISTICS IO OFF

    SET STATISTICS TIME OFF

    I used (nolock) on the first query not to put you into a trouble for making the table inaccessible for others.

    You surely won't need (nolock) for the second one.

    _____________
    Code for TallyGenerator