Posts

The SQL Server Performance Challenge: The “Bandwidth Killer” Edition πŸ”₯

Image
The SQL Server Performance Challenge: The “Bandwidth Killer” Edition πŸ”₯ πŸ‘‰ If you missed my previous post:  SQL Server: Why Your Query Is Waiting (Top Wait Types Explained) πŸš€ Challenge: Can you fetch data using ZERO wasted bytes? ...your azure budget will be happy πŸ‘Œ Hi SQL Server Guys,  Let’s be honest : Most of your queries are "obese" .  They carry around metadata and columns you don't need, burning your Azure budget and choking your network. Today, I challenge YOU! πŸ“ The Scenario: You have a table Orders  with 50 columns.  This table has a column Customer  nvarchar(200)  that represent the name of the customer and a column Date Datetime. All the other columns are  nvarchar(200)  except  the last that is a heavy nvarchar(MAX). You need to check if at least one order exists for the "Customer_A"  in the year 2025 to trigger an Agentic AI workflow . πŸ”₯ THE CHALLENGE:  Write the most "Minim...

SQL Server: Why Your Query Is Waiting (Top Wait Types Explained) πŸ”₯πŸ”₯πŸ”₯

Image
SQL Server: Why Your Query Is Waiting (Top Wait Types Explained) πŸ”₯ πŸ‘‰ If you missed my previous post... well, you won't learn how to optimize your storage and modernize your data types  in case you can look here:   SQL Server: Stop Using DATETIME (Use DATETIME2 and Save Space) πŸ’£ The Hook Your query is slow, damn slow! CPU looks fine. IO looks fine. So… what’s happening? “SQL Server is always waiting. The question is: for what?” πŸ’‘ TL;DR ❌ Problem: Queries are slow but CPU/IO look normal ⚠️ Symptom: High wait times in SQL Server ✔️ Fix: Identify and eliminate dominant wait types (CPU, IO, locks, memory) Hi SQL Server Guys, Everything looks fine. Indexes are there. Execution plan looks decent. But your query is still slow. πŸ’£ That’s because you're not measuring the real bottleneck. πŸ‘‰ You’re not looking at WAIT STATS . 🧠 What Wait Stats REALLY Are SQL Server is a scheduler. Keep it in mind... Every query spends time doing wo...

SQL Server: Stop Using DATETIME (Use DATETIME2 and Save Space)

Image
SQL Server: Stop Using DATETIME (Use DATETIME2 and Save Space) πŸ”₯ πŸ‘‰ If you missed my previous post: Why Your Index Is NOT Being Used (5 Hidden Reasons) πŸ’₯ The Hook You think DATETIME is “good enough”? It’s silently wasting space, reducing precision, and hurting performance. πŸ‘‰ In modern SQL Server, using DATETIME is a legacy mistake. TL;DR πŸ’£ Problem → Legacy DATETIME type wastes space and loses precision πŸ’£ Symptom → Larger tables, more IO, less accurate timestamps ✔️ Fix → Use DATETIME2 with proper precision (e.g. DATETIME2(2) or (7)) Hi SQL Server Guys, Everything is fine... until your system scales. You have: More rows. More IO. More memory pressure. πŸ’£ And suddenly… your “simple” DATETIME column becomes a problem. 🧠 What It Really Is DATETIME is a legacy data type designed decades ago. Low precision (3.33 ms) Fixed storage (8 bytes) Non-standard behavior πŸ‘‰ DATETIME2 fixes ALL of this. πŸ”₯ Precision Matters (More Than...

Agentic AI + SQL Server 2025: Why Your Database Is About to Become a Brain (Not Storage)

Image
πŸš€ Agentic AI + SQL Server 2025: Why Your Database Is About to Become a Brain (Not Storage) Hi SQL Server Guys, πŸ‘‰ If you think SQL Server is just a database, you are already behind. In 2026 doing prompts is obsolete and we are not managing data anymore. We are managing decisions, actions and real-world execution . πŸ’£ AI is no longer just generating text. It is executing operations . 🧠 Agentic AI: From Query to Action Old AI: πŸ‘‰ “Here is your answer.”  A model that simply interprets a request and returns an output. Its role ends the moment it produces an answer. It does not interact with systems, it does not alter the state of reality, and it assumes no operational responsibility. It is a support tool, useful for understanding, analyzing, and suggesting. But everything that happens next… still depends entirely on the human. New AI: πŸ‘‰ “I already solved it.”  A system that doesn’t stop at the answer, but continues until execution. It interpre...

SQL Server: Indexes Are NOT Your First Optimization Tool (Here’s What Is) πŸ”₯

Image
SQL Server: Indexes Are NOT Your First Optimization Tool (Here’s What Is) πŸ”₯ πŸ‘‰ If you missed my previous post: Why Your Index Is NOT Being Used (5 Hidden Reasons) πŸ’₯ The Hook You add an index… and the query is still slow. Or worse — everything else becomes slower. πŸ‘‰ What if indexes are NOT your real problem? TL;DR πŸ’£ Problem → Query is slow despite indexes πŸ’£ Symptom → High CPU, scans, unstable performance ✔️ Fix → Query rewrite + SARGability + Data model first (NOT indexes) Hi SQL Server Guys, Your query is slow. So you add an index. Sometimes it works. Most of the time… it doesn’t. πŸ’£ Because indexes are NOT the first optimization tool. 🧠 What It Really Is SQL Server performance is NOT about adding indexes. πŸ‘‰ It’s about how the engine can understand and execute your query efficiently . Query shape matters Predicate structure matters Data model matters πŸ’£ If these are wrong… indexes won’t save you. πŸ”₯ 1. Query Rewri...

SQL SERVER, Parameter Sniffing: The Bug That Isn’t a Bug (But Breaks Everything)

Image
SQL Server Parameter Sniffing: The Bug That Isn’t a Bug (But Breaks Everything) πŸ”₯ πŸ‘‰ If you missed my previous post: How to Find the Slowest Queries in SQL Server in 60 Seconds πŸ’ͺ

How to Find the Slowest Queries in SQL Server in 60 Seconds

Image
πŸ‘‰ How to Find the Slowest Queries in SQL Server in 60 Seconds πŸš€ Hi SQL SERVER Guys, You don’t need expensive tools. You don’t need hours of investigation. You just need to know WHERE to look . πŸ‘‰ Today I’ll show you how to find the slowest queries in less than 60 seconds. P.S. If you missed my previous post, check it out here: Why TempDB Is Slowing Down Your Entire Server πŸ”₯ 🧠 What Are DMVs? DMVs (Dynamic Management Views) are SQL Server internal views that expose a lot of internal information of SQL Server: Query performance CPU usage IO stats Execution metrics πŸ‘‰ Think of them as your real-time X-ray or the Blood Exam of your SQL SERVER  πŸ”₯ Find Slow Queries with DMVs SELECT TOP 10 qs.total_worker_time / qs.execution_count AS avg_cpu, qs.total_elapsed_time / qs.execution_count AS avg_duration, qs.total_logical_reads / qs.execution_count AS avg_reads, qs.execution_count, SUBSTRING(qt.text, qs.statement_start_offset/2, ...

Why TempDB Is Slowing Down Your Entire Server (And You Don’t Notice!) πŸ”₯

Image
πŸ‘‰ Why TempDB Is Slowing Down Your Entire Server (And You Don’t Notice) πŸ”₯ Hi SQL Server Guys, πŸ‘‰ If you missed my previous post, check it out here: Nested Loop vs Hash Join vs Merge Join – The Truth Nobody Explains The usual intro... Your server is slow. CPU looks fine. IO looks fine. Execution plan looks… acceptable. πŸ‘‰ So what’s killing performance? TempDB . And the worst part? πŸ‘‰ You often don’t even see it. 🧠 What is TempDB really? TempDB is a shared system database used by SQL Server for temporary operations. It is involved in a lot of aspects: Temporary tables (#temp) Table variables Sorting (ORDER BY) Hash operations (JOIN / AGG) Spills to disk Version Store (snapshot isolation) πŸ’£ TempDB is not optional :  It is involved in almost every complex query . ⚙️ When SQL Server Uses TempDB SQL Server uses TempDB whenever memory is not enough or when intermediate results are required . Large SORT operations Hash joins /...

Nested Loop vs Hash Join vs Merge Join – The Truth Nobody Explains

Image
πŸ”₯ Nested Loop vs Hash Join vs Merge Join – The Truth Nobody Explains Hi SQL Server Guys, Welcome to this news post! Today on the menu we have the JOIN OPERATORS. Ready to learn important things? πŸ‘‰ If you missed my previous posts, check these first: Execution Plans – Read in 10 Minutes | CPU vs IO – Hidden Bottlenecks 1️⃣ Understanding the Join Operators SQL Server has three main join operators you’ll encounter in execution plans: Nested Loop , Hash Join , and Merge Join . Each has strengths, weaknesses, and hidden trade-offs between CPU and IO. Things to know about: Nested Loop Join - Reads one row from the outer table and searches matching rows in the inner table. - Ideal for small datasets or when the inner table is indexed. - CPU light for small datasets but IO cost grows linearly as dataset size increases. Hash Join - Builds a hash table on the smaller input and probes it with the larger table. - Excellent for large, unindexed tables. - CPU heavy (has...

The SQL Server Setting That Can Make Your Query 10x Faster (Or Worse) πŸ”₯

Image
The SQL Server Setting That Can Make Your Query 10x Faster (Or Worse) πŸ”₯ Hi SQL Server Guys, πŸ‘‰ If you missed this my post: Why Your SQL Query Is Burning CPU (And You Don’t See It) πŸ”₯ πŸ’₯ When One Setting Has a Massive Impact Using the same schema of the previous posts... Your query is slow. Indexes are fine. Execution plan looks “okay”. So what’s the problem? πŸ‘‰ A single SQL Server setting. πŸ’£ Parallelism configuration. Most people ignore it. But it can: Make queries 10x faster πŸš€ Or completely destroy CPU ❌ 🧠 Parallel vs Serial Execution Mode Description Impact Serial Single-thread execution Low CPU, slower Parallel Multiple threads (multi-core) Faster, but CPU heavy πŸ’£ Parallelism is powerful… but dangerous if correctly configured! πŸ”₯ The 2 Settings That Control Everything 1. MAXDOP (Max Degree of Parallelism) Controls how many CPU cores a query can use Example: MAXDOP = 8 → up to 8 threads 2. Cost Threshold f...

SQL SERVER, Why Your Index Is NOT Being Used (5 Hidden Reasons) 😑

Image
Why Your Index Is NOT Being Used (5 Hidden Reasons) 😑 Hi SQL Server Guys, πŸ‘‰ If you missed my previous post, check it out here: Is Your Database Over-Indexed? Your Indexes Might Be Killing Performance πŸ”₯ You created the perfect index. You checked everything. And yet… πŸ‘‰ SQL Server is NOT using it. So what’s going on? In this post we expose the 5 hidden reasons why your index is ignored. πŸ’£ The important Truth An index not used is worse than no index: Consumes memory Slows down writes Adds maintenance cost πŸ‘‰ And gives you ZERO performance benefit. πŸ”₯ 1. Implicit Conversion (Silent Killer) SELECT * FROM Orders WHERE CustomerId = '123'; If CustomerId is INT and you compare it with a string: SQL Server converts the column Index becomes unusable Full scan happens πŸ’£ “Implicit conversions kill index usage silently.” ✔️ Fix: WHERE CustomerId = 123; πŸ”₯ 2. Functions on Columns SELECT * FROM Orders WHERE YEAR(...

SQL SERVER, Your Execution Plan Is Lying to You!

Image
😈 Your Execution Plan Is Lying to You ...And You Don’t Know It Hi SQL Server guys, Follow me to explore another performance issue. I’m sure this will happen to you at some point ...and to many of your colleagues as well. A customer tells you that your application is dramatically slow. You’ve already identified the problematic query and… Execution plan looks perfect … but your query is still slow . πŸ‘‰ Something is lying to you. And no… it's not SQL Server! ....it's the way you're reading the execution plan . πŸ‘‰ Previous Post If you missed the previous deep dive you can take a look to: SQL Server 2025 CU3 – Backup/Restore Performance Benchmark ⚠️ The Core Problem: Estimated vs Actual Rows Most developers look at execution plans and think: ✔️ Index Seek → good ✔️ Low cost → good ✔️ No warnings → perfect πŸ‘‰ “Looks perfect… ship it.” But the real problem is here: Estimated Rows ≠ Actual Rows πŸ§ͺ Example 1 – The Classic Trap SEL...