|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:16 PM
Points: 2,749,
Visits: 1,405
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, February 22, 2013 8:20 AM
Points: 59,
Visits: 276
|
|
Nice Article David, it certainly highlights a potential problem when using ORMs against SQL Databases (and dynamic SQL in general!).
I think many people though, especially junior developers/DBAs, could make more use of this article as a fine example of iterative problem solving - i.e. not taking a sledgehammer to the issue but working through it logically one step at a time.
This was both an enjoyable and interesting read for a Monday morning. Thanks.
James MCM [@TheSQLPimp]
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 10:56 AM
Points: 751,
Visits: 129
|
|
Good drills, thanks for the tips!
Glen Parker
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: 2 days ago @ 8:55 AM
Points: 863,
Visits: 1,020
|
|
In relation to the: "The answer lies in a bug in the cluster installer for SQL2008".
Does this bug exist in R2 aswell?
Carlton.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:19 PM
Points: 48,
Visits: 324
|
|
In my experience, use of so-called ORM (Object-Relational Management) tools create as many or more problems than they solve. There are many times we haven't got a choice because a shop's methods & tools team have drank the ORM Kool-Aid. However I always recommend against using ORM for one primary reason: Every SQL call deserves to be deliberately designed.
As most readers here know, when an ORM is used, code runs to dynamically generate SQL. This code is designed at the meta-level, so it is difficult if not impossible to optimize the SQL out of the box.
It remains my considered opinion that ORM tools are nothing but an OO developers excuse to not to have to deal with SQL specifically and the relational model in general. The wisest OO developers know that the very best domain models are compliant with, if not based upon, a fully-normalized relational database models.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, April 11, 2011 9:23 AM
Points: 121,
Visits: 46
|
|
Oh wow. I'd have never thought of checking the collation. Thanks for the article and the good reminder. Headed off now to check the collation on my prod. databases to make sure it's what I think it should be. :)
--Mitch
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 1:39 PM
Points: 71,
Visits: 696
|
|
Our developers use nHibernate here and we also use a collation of SQL_Latin1_General_CP1_CI_AS, so I was curious if I would be able to reproduce this same issue. We actually have a very similiar scenario, a table that holds person information with a non-clustered index on the LastName field, which is a dataype of nvarchar(100). Everytime I tried to reproduce your issue, it always did a clustered index seek, not a scan. This is good, however I was kind of hoping I would be able to reproduce it to convince our developers to move away from nvarchar :). I've tried clearing the query cache, dropping/recreating indexes, etc, and it always seems to perform a scan. We are using SQL Server 2005 - any ideas?
Adam
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:16 PM
Points: 2,749,
Visits: 1,405
|
|
If your field is an NVARCHAR and you use VARCHAR parameters you will get a seek because SQL is happier to turn a VARCHAR into an NVARCHAR than the other way around.
It's worth noting that anything that involved converting a string value into another value can also have the problem.
SQL Server can take a statement such as WHERE DateCreated BETWEEN '2011-04-01' and '2011-04-11' and get exactly the same type of implicit conversion.
LinkedIn Profile
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 1:39 PM
Points: 71,
Visits: 696
|
|
| Right - I was still getting the seek even when I explicity declare a parameter as a nvarchar and used that to query my nvarchar field, like he did in his article. I still received a seek even after I cleared out the query cache and rebuilt the non-clustered index.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 11:05 AM
Points: 6,
Visits: 105
|
|
Not a bug in SQL Server because you can choose a different collation when you are setting up SQL Server. It is more of a human bug for not checking how to do a proper setup.
To change a server collation: export all the data and script all the users. drop the databases and rebuild the master using the correct collation recreate the users and databases and import the data
Collations are hierarchical. By that I mean they can be easily over-ridden. A database collation can be set to operate differently from the server and a column can be set to operate differently from its database. A piece of code can be set to operate according to the collation of the object from which it is pulling data.
MS example: SELECT name FROM customer ORDER BY name COLLATE Latin1_General_CI_AS. (I changed the collation name from the MS example to make it more relevant)
The problem here was PBCK.DLL; not SQL Server.
Sorry to be bobby badnews but I would like to see articles that are consistent with MS documentation when it is correct and consistent with the behavior of SQL Server when it is administered correctly.
Don
|
|
|
|