Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

An nHibernate Head Scratcher Expand / Collapse
Author
Message
Posted Sunday, April 10, 2011 10:39 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:36 AM
Points: 2,907, Visits: 1,832
Comments posted to this topic are about the item An nHibernate Head Scratcher

LinkedIn Profile
Newbie on www.simple-talk.com
Post #1091229
Posted Monday, April 11, 2011 2:30 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, May 14, 2014 7:57 AM
Points: 76, Visits: 342
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]
Post #1091280
Posted Monday, April 11, 2011 2:51 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Saturday, March 29, 2014 11:41 AM
Points: 753, Visits: 133
Good drills, thanks for the tips!

Glen Parker
Post #1091285
Posted Monday, April 11, 2011 5:53 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:54 AM
Points: 868, Visits: 1,140
In relation to the: "The answer lies in a bug in the cluster installer for SQL2008".

Does this bug exist in R2 aswell?

Carlton.
Post #1091361
Posted Monday, April 11, 2011 7:58 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 17, 2014 8:47 AM
Points: 54, Visits: 428
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.
Post #1091437
Posted Monday, April 11, 2011 8:21 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1091457
Posted Monday, April 11, 2011 9:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, September 26, 2014 10:08 AM
Points: 79, Visits: 743
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
Post #1091520
Posted Monday, April 11, 2011 9:36 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:36 AM
Points: 2,907, Visits: 1,832
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
Newbie on www.simple-talk.com
Post #1091538
Posted Monday, April 11, 2011 9:39 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, September 26, 2014 10:08 AM
Points: 79, Visits: 743
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.
Post #1091543
Posted Monday, April 11, 2011 9:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 22, 2014 7:47 AM
Points: 9, Visits: 151
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
Post #1091553
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse