Re: Odd query plan for view



(JayCallas@xxxxxxxxxxx) writes:
So, a Clustered Index Scan is as bad as a Table Scan? In this case,
what is it actually checking? The LoadDate is not even used in the
query so I am not sure what it is scanning for. Is it just using the
scan to look up the rest of the row?

Let's say that you need to look up Michael Richardson in the telephone
book. Of course you open the book on R and quickly find him. You are seeking
the clustered index.

But say now that you are looking for someone whose first name is Jake,
and that he lives on Smallstreet, and you really need to find him. What
do you do? You read the phone book from start to end, that is you scan
the clustred index. The LastName, which is the key in the index is not
part of the search, but that is irrelevant.

As I already knew that the particular WHERE clause was bad, was I just
lucky all this time that the response time was good?

Bad is a little too strong a word. Problematic is more accurate.

The problem with a non-clustered index, is that if you get many hits,
and you for every hit you need to access the data page, you will do more
reads that you do, if you just scan the table from left to right.

Do query plans survive server reboots or restarting SQL?

No. The plan is in cache only, and could also disappear during run-time,
if the plan is aged out.



--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: dbcc checkdb
    ... You can search on the string 8946 in Books Online. ... the only way to repair is restore from a ... But a user who hits this broken page may ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: What is Your Strategy for Upgrade an Access db to SQL Server 2000?
    ... exact phrase I filled in "upsizing wizard" and for author I specified ... and I opted to get 100 hits per page. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Transform/transfer 50Gb - how to do it fast?
    ... I'm also plan to make newtable partioned. ... If new the table will have the same clustered index as the old table, ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Getting list of recently added IDENTITY items
    ... CREATE TABLE hits (hit_datetime DATETIME ip_address VARCHAR(15), ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Sql Server Performance
    ... cause SQL Server to create a cached execution plan. ... SQL server caches plans for stored procedures as well as ... The performance hit there could be for using a view, ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)