Test your MAXDOP – SQL Server max degree of parallelism

The default value of your SQL server is MAXDOP=0. It means there is no limit for parallelism. Your query can use all of your CPU core.

Scenario:
If your SQL Server is not used, than your CPU utilization is low,
your query can use all of the server’s resources.
I run a cross join query in a table which has 40.000 rows.
The server has 8 core.
I set hint for the query to simulate the MAXDOP server setting.

The query and the result:

So if your query use only 1 thread it run longer ( in the example 232 seconds), if it use 8 thread it run much more quicker ( 33 seconds).
So 232/33 ~= 7 . Ok the speed is not 8x , but almost 8. The operating system and other processes use system resources.

Should we use the maxdop value without limit? In the real life a lot of queries run at the same time, so if your query get all of the resource the other waiting the resources. So you try to figure out what is ideal value?
If you have no idea, or don’t have experience with the new databases , you can set the recommended value:
https://support.microsoft.com/en-us/help/2806535/recommendations-and-guidelines-for-the-max-degree-of-parallelism-confi

Server Propertis - MAXDOP
Server Propertis – MAXDOP

You can reduce the parallelism in your server with increasing the Cost Threshold for Parallelims.

You can set it for individually for every database:

Database settings
Database settings

Max DOP for you database and Max DOP For Secondary for your Always ON AG secondary replicas.

How to Check Index Fragmentation and Partitioned Table Index Fragmentation

I use two script. The firs one is for general purpose and run faster, the second one is good for partitioned table and get many details about partitioned index and table.

Detailed query for partitioned table:

SQL Server 2019 Administration Inside Out

SQL Server 2019 Administration Inside Out Paperback – release date: 2020 by Randolph West, Melody Zacharias, William Assaf, Sven Aelterman

sql server 2019 book

Conquer SQL Server 2019 administration–from the inside out

Dive into SQL Server 2019 administration–and really put your SQL Server DBA expertise to work. This supremely organized reference packs hundreds of time-saving solutions, tips, and workarounds–all you need to plan, implement, manage, and secure SQL Server 2019 in any production environment: on-premises, cloud, or hybrid. SQL Server experts offer a complete tour of DBA capabilities available in SQL Server 2019 Database Engine, SQL Server Data Tools, SQL Server Management Studio, and via PowerShell. Discover how experts tackle today’s essential tasks–and challenge yourself to new levels of mastery.

  • Install, customize, and use SQL Server 2019’s key administration and development tools
  • Manage memory, storage, clustering, virtualization, and other components
  • Architect and implement database infrastructure, including IaaS, Azure SQL, and hybrid cloud configurations
  • Provision SQL Server and Azure SQL databases
  • Secure SQL Server via encryption, row-level security, and data masking
  • Safeguard Azure SQL databases using platform threat protection, firewalling, and auditing
  • Establish SQL Server IaaS network security groups and user-defined routes
  • Administer SQL Server user security and permissions
  • Efficiently design tables using keys, data types, columns, partitioning, and views
  • Utilize BLOBs and external, temporal, and memory-optimized tables
  • Master powerful optimization techniques involving concurrency, indexing, parallelism, and execution plans
  • Plan, deploy, and perform disaster recovery in traditional, cloud, and hybrid environments

For Experienced SQL Server Administrators and Other Database Professionals

Adatbázis audit

DevOps környezetben vagy éles környezetben érdemes auditot beállítani. Saját érdekünkben érdemes tudni, hogy ki nyúlt bele és mit csinált!


Nem használt oszlopok – Empty columns

Default Null értékű oszlopok , ahol minden Null értékű:

 

Table size

Tábla méretek , használt tartalommal:

 

HEAP table is fragmented

Általában nem ajánlott HEAP tábla létrehozása (Table without Clustered Index) , egy esetben jöhet jól, ha nagyon gyors adatbetöltés szükséges.
A Heap tábla azonban töredezik, ennek oka, hogy minden Insert a tábla végére kerül és a Deleted sorok sem  kerülnek betöltésre.
Amíg a hagyományos indexeket egy index reorganizációval vagy újraépítéssel (rebuild) karbantarthajtuk és gyorssá tehetjük addig a Heap táblán nincs ilyen beépített karbantartás .
Teendő?

Continue reading “HEAP table is fragmented”

SQL Server Index Tuning

Egy több millió sorral rendelkező táblán már súlyos gondokat okozhat egy-egy index hiány.

5 Millió sor, paraméterezett select, a szerver túlterhelt:

CPU and Processor Queue Length - Performance Monitor
CPU and Processor Queue Length – Performance Monitor

11:20-kor 1 db index felrakása után látványosan csökken a CPU (kék) és CPU Queue (piros). Ellenpróba 13:35-kor az index letiltásakor ismét befullad a szerver (a határértéknek számító 80%-ról 95% átlagos cpu használatra ugrik). Ráadásul  a szerveren több mint 100 adatbázis van és mégis egy darab eljárás jelentősen beterhel.
Persze a valóság nem ilyen egyszerű, egy -egy index felrakásának hatását többnyire nem lehet performance monitor-ból kimutatni, a fenti példa egy rosszul tervezett gyakori futású kódra vonatkozik.

Index méretek

Index size

Az egyes indexek méretei. Az adott adatbázisra kell használni, szükség esetén szűrni.