Good afternoon,
I'm hoping someone here in this forum can assist with my issue.
I have an Event table with 13.3mm rows. The primary key is EventID (int), and contains StudentID (int) and Comments (TEXT - not varchar - the vendor has not yet converted their tables away from this datatype). We need to retrieve comments from the Comments (text) field quickly. There is a nonclustered index with studentid, and cmeventid. The EventIDs that I'm interested in vary from 500,000 to 1.7mm (several different iterations of the process with slightly different criteria). I will then concatenate the Comments, grouping by StudentID and sorting the EventIDs in descending order (this part is not the issue).
I have tried a variety of ways of constructing the sql query to initially retrieve the rows. The Execution Plan for each method is using an index seek on the nonclustered index but the retrieval process is slow. I have the EventIDs for my population contained in a Temp table and use that in the main query. The waits that I'm seeing are CxPacket and I've read up on what the possibilities could be on this. Of course, once the query runs to completion, it's cached and runs in seconds vs many minutes.
A couple (of about 6 different queries) I've tried are below. I've checked into the READTEXT process but since that is going away, I'd rather not go that way. Also, the examples of READTEXT that I've seen have only been able to process records one at a time and I have a large record set to process and would rather have one execution against the database.
SELECT #Event11.EventID, #Event11.StudentID, #Event11.DateAdded, SUBSTRING(Comments,1,1000) FROM Event WITH (NOLOCK) INNER JOIN #Event11 ON Event.StudentID = #Event11.StudentID AND Event.EventID = #Event11.EventID AND SELECT Event.CmEventID, Event.SyStudentID, Event.DateAdded, SUBSTRING(Comments,1,1000) FROM Event WITH (NOLOCK) WHERE Event.EventID IN (SELECT EventID FROM #Event11)
I don't have control of the table structure, just want to make sure I'm doing everything I can otherwise (indexes, efficient code, etc). Thanks for your time.