• KTD (9/6/2013)


    Your version of the query ran in 30 seconds without any high disk latencies observed.

    Good to know, thanks. Just for a bit of fun (and because other people might wonder) you might find the following performs even better:

    SELECT Result.*

    FROM

    (

    -- Top 10,000 keys over all partitions

    SELECT TOP (10000)

    AllPartitions.ClaimID,

    AllPartitions.RecordDate

    FROM

    (

    -- Top 10,000 keys per partition

    SELECT

    TopPerPartition.ClaimID,

    TopPerPartition.RecordDate

    FROM

    (

    -- Partition ID list

    VALUES

    (01),(02),(03),(04),(05),(06),(07),(08),(09),(10),

    (11),(12),(13),(14),(15),(16),(17),(18),(19),(20),

    (21),(22),(23),(24),(25),(26),(27),(28),(29),(30),

    (31),(32),(33),(34),(35),(36),(37),(38),(39),(40),

    (41),(42),(43),(44),(45),(46),(47),(48),(49),(50),

    (51)

    ) AS PartitionIDs (ID)

    CROSS APPLY

    (

    -- Per-partition query

    SELECT TOP (10000)

    C.ClaimID,

    C.RecordDate

    FROM dbo.Claims AS C

    WHERE $PARTITION.PF(C.ClaimID) = PartitionIDs.ID

    AND PartitionIDs.ID >= $PARTITION.PF(100781325)

    AND C.ClaimID > 100781325

    ORDER BY C.RecordDate ASC

    ) AS TopPerPartition

    ) AS AllPartitions

    ORDER BY

    AllPartitions.RecordDate ASC

    ) AS TopKeys

    CROSS APPLY

    (

    -- Add extra columns

    SELECT C.*

    FROM dbo.Claims AS C

    WHERE C.ClaimID = TopKeys.ClaimID

    AND C.RecordDate = TopKeys.RecordDate

    ) AS Result

    ORDER BY

    Result.RecordDate ASC;