Nov 28, 2018 21:06
Ah, I see from the image you’re partitioning on End. So use the extra predicate for partition elimination, if you can be sure that the rows you’re after are all from the last day (or two days or whatever).
Nov 28, 2018 20:39
The main thing in my answer is having a separate table of Sources, to leverage the proper index. But if you have Source in there too you could even use your current clustered index. My current question is about the partitioning.
 
Aug 29, 2017 10:06
The Seek Predicates - do they have a Prefix on OwnerId and then a Start and End too?
Aug 29, 2017 10:06
So it's not a Filter. It's simply requesting a single row from the Seek. Do you get the same behaviour if you add "AND LastOperationTime IS NOT NULL" to the ON clause of your query?
Aug 29, 2017 10:06
When you say it's "filtered", is this a Top operator, or an actual Filter operator? Or are there both?
Aug 29, 2017 10:06
What's the "Number of Executions" on each?
Aug 29, 2017 10:06
This Filter - is it a Top operator, or a Filter operator? If it's a Filter, is there a Startup Expression Predicate property? Also, what is the "Number of Executions" on each of the Seeks?
Aug 29, 2017 10:06
You said "So I run the query and request the actual execution plan and it has two index scans." But now you say they're Seeks?
Aug 29, 2017 10:06
I can't help thinking you're misdescribing something. Your Scans are only being asked for a single row (the largest, presumably - I expect the Scan is "BACKWARD" if you look in the properties window). This would make sense if it were on LastOperationTime followed by OwnerId rather than the other way round. It'll scan through the index looking for the first row which matches the Owner (is your Predicate really on the Time column?), knowing it'll be the largest value for that owner.
Aug 29, 2017 10:06
What's in those Filter operators? If they're Startup Expression Predicates, then it's only pulling data from one of the Scans each time.
 
Aug 29, 2017 09:21
No worries. Good luck. It's getting late here in Aus, so I'm not going to be around much longer. I'll check in later though.
Aug 29, 2017 09:21
I thought you didn't have a database. So what did you do to get something you could backup?
Aug 29, 2017 09:21
Then bring it online again. Ignore the errors. Then see if you can do a log backup.
Aug 29, 2017 09:21
Create a new database with the same name... Make sure it's in the full recovery model. Back it up so it knows it's in really in full. Then take it offline. Now rename the actual files, and swap in a copy of your file.
Aug 29, 2017 09:21
Ok. So how were you trying to back it up? There may be hope after all.
Aug 29, 2017 09:21
That is: was your old database definitely using simple?
Aug 29, 2017 09:21
Ok. How were you backing it up then?
Aug 29, 2017 09:21
Aha. Okay. Next question for you: Why did you say that your LDF contained all the transactions since the full backup?
Aug 29, 2017 09:21
Assuming you have a corrupt page, what kind of page is corrupt? If you don't know, use DBCC PAGE to see.
Aug 29, 2017 09:21
Wait though. Do you still have your database in some (albeit corrupt) form?
Aug 29, 2017 09:21
If you're in SIMPLE, the LDF is no use to you, because it would have been truncated every few moments.
Aug 29, 2017 09:21
Ok. In SIMPLE the only thing you can go back to is the last database backup. The log is no use. Let's talk about what you do have... For starters, what makes you say your database is corrupt?
 
Aug 29, 2017 07:34
Yes. Not always better. But also, not always worse.
Aug 29, 2017 07:34
I agree with Thomas on these points. Heaps and GUID PKs are over-villainised, and I certainly don't rate them as bad as many in the SQL community do.
 
May 4, 2016 22:32
....which was the reasoning behind my criticism of the suggesting to create a clustered index (which was what your initial answer described).
May 4, 2016 22:31
@srutzky When we look at the question around "my query is doing a table scan", adding a clustered index on SnapshotKey wouldn't make a difference. The significant thing is having a non-clustered index which includes the full list of columns required by the query. I agree that the non-clustered index could be a little smaller with a clustered index, but the clustered index itself doesn't improve the query plan.
Apr 28, 2016 06:01
I'm not sure the clustered index would help much. It's a data warehouse, therefore insert-only (hopefully). This is a scenario where heaps work just fine, and RID Lookups are much quicker than Key Lookups, so I'd be quite wary of creating a clustered index.
 

 The Heap™ – Consultancy ©®

General on- and off-site discussion for dba.stackexchange.com....
Feb 1, 2016 06:09
@PaulWhite Not about the points at all, I'm sure. Happy Birthday @AaronBertrand
 
Nov 16, 2015 20:45
Correct - I'm in Australia. My day will start later.
Nov 16, 2015 19:40
I'm just waking up, myself...