r/SQLServer • • Aug 03 '20

Great video on things to avoid in SQL Server by Brent Ozar. Its kinda amazing how consistent SQL Server has been on what not to do.

https://www.brentozar.com/archive/2020/08/video-the-top-10-developer-mistakes-that-wont-scale-on-microsoft-sql-server/
62 Upvotes

19 comments sorted by

4

u/alinroc 4 Aug 03 '20 edited Aug 03 '20

This was a fun stream to watch live, unfortunately I only got to watch half of it then.

FYI, Brent is streaming live most Saturday & Sunday mornings, I think 7 AM 6AM Pacific, and usually goes about 2 hours. Twitch, Youtube, not sure where else he broadcasts it to. Worth checking out.

5

u/wind-raven Aug 03 '20

I love Brent and have been following him for a while. His blog posts were one of the first resources i would look for when I was learning how to be a dba.

1

u/embrex104 Aug 03 '20

Any specific things you would consider looking at? Right now we're a mixed SQL / Access backend and I am in the process of moving everything over to SQL. I will also be the DBA / DB Developer / etc

1

u/wind-raven Aug 03 '20

my top x of how to set up for success:

  1. Make sure every table has a clustered key and make sure the clustered key is small and always increasing (Identity, datetime etc) (there are some performance reasons behind this that get deep into the way sql server stores data)

  2. Make sure to watch out for Implicit Conversions, they can kill performance

  3. Watch the video since it covers almost everything else.

1

u/embrex104 Aug 03 '20

I watched a bit of it but I have to save the rest for later. The table variables comments made sense but I was really surprised by his comments about triggers. I always though their leverage was very powerful and I use quite a bit of them in some of my development. I work for a small shop so I know what data I am receiving for the most part so I think some of the arguments to be made are on a case by case basis, since I am the beginning middle and end of the database usage.

1

u/wind-raven Aug 03 '20

The idea is that triggers have some gotchas that can be worked around and use what is most likely the most expensive cpu cores (due to licensing) in the entire data center. They aren’t bad and I certainly use them in some places but I don’t default to them

So starting out on a new app, avoid them because they use sql CPU’s for processing and the gotchas need experience to avoid.

1

u/digitalnoise Aug 03 '20

Make sure every table has a clustered key and make sure the clustered key is small and always increasing (Identity, datetime etc) (there are some performance reasons behind this that get deep into the way sql server stores data)

Which completely kills BULK INSERT performance.

2

u/wind-raven Aug 03 '20

Most of the applications I have supported did very little bulk inserts and where they did, performance was not a huge concern (after hours bulk data loads, loading staging tables for later row by row processing etc). The larger concerns were page splits and object lookups for crud processing.

Every suggestion will always have a caveat that there are exceptions to the rule, but you follow the rule until you run smack into a performance wall.

I have some tables with out any keys and a clustered index, they are archive / historical tables where datetime is the clustered index and everything else could be duplicated. On those tables I don’t use an identity because sql will assign a uniquifier for me and most of the queries include the datetime as a query parameter.

0

u/[deleted] Aug 03 '20

[deleted]

0

u/sleepySQLgirl Aug 04 '20

Totally disagree with your assessment of the first point. If you’re doing ETL that’s insert only, then a monotonically increasing index is not a burden. If you’re doing merges/updates, then having a key to merge on improves performance and keeps SQL from creating forwarding records. Lastly, having a clustered index for table joins in views for BI is essential for performance.

1

u/[deleted] Aug 04 '20

As the other commenter said, you're never going to be doing a JOIN on a surrogate key. I tend to agree with the idea that OLAP should use a natural clustered index / primary key and OLTP should use a surrogate.

1

u/sleepySQLgirl Aug 04 '20

I wasn't referring to a surrogate key, but neither of our original comments specified that.

Most of my workload uses a natural key that's an increasing index, in which case I'm correct. The other commenter is correct when assuming a surrogate key.

1

u/[deleted] Aug 04 '20

What is a natural key with an increasing index? If you are creating new unique identifiers that really is a special use case that aligns more closely with the definition of a surrogate key. A natural key already exists in the data, you don't need to create it.

1

u/sleepySQLgirl Aug 04 '20

I’m saying that a natural key exists in the data that’s ever increasing (some are ints, some are character sequences that are not GUIDs) so that’s the clustered PK.

No surrogate keys in my comments.

0

u/[deleted] Aug 04 '20

[deleted]

1

u/sleepySQLgirl Aug 04 '20

Fair enough - I was thinking of my own personal situation where the natural key/clustered index is a monotonically increasing value.

12

u/BrentOzar Aug 03 '20

Yeah, I stream 6am-8am Pacific on Saturdays and Sundays until mid September at least. I have some classes after that, so my streaming schedule will be more in flux after that. Plus I do a lot of ad hot stuff just when I have time available - if you follow me on Twitch or YouTube, you'll get an email when I start streaming. Did a 3 hour one this morning in the First Responder Kit.

36

u/BrentOzar Aug 03 '20

Thanks, glad you enjoyed it.

1

u/[deleted] Aug 04 '20

DACPACS only drop and recreate the table if you are reordering columns. If you are adding a column to the end of the table it does not do that. As far as I know to change column order there is no other way, so it's really not that bad.

1

u/Randy_McKay Aug 04 '20

This guy is the best!

1

u/iametarq Aug 04 '20

Adding this to my watch list. I probably need to see if I'm doing any of these things.