Posts

Showing posts with the label performance

JSON Vs. XML! The wrong choice can influence the success or the fail of your project!

Image
SQL Server Performance: JSON vs XML – Which One Is Faster? SQL Server Performance Series – JSON vs XML Hi SQL Server Guys, In performance discussions, usually a very important question came up: Should we use JSON or XML in SQL Server? At first glance this may look like a simple design decision. But in real production systems the choice between JSON and XML can have a significant impact on performance, scalability, and maintainability . In many projects, choosing the wrong format can introduce unnecessary overhead and slow down critical queries . In other words, the decision between JSON and XML can directly influence the success of the system we are building. That is exactly why this comparison is so important. Let’s look at what happens when we compare JSON and XML in SQL Server. JSON vs XML Performance Test By doing internal tests comparing JSON and XML processing, the results i got were quite interesting. When parsing and retrieving values f...

SQL SERVER! SARGability: the One Concept You Absolutely Must Understand!

Image
Hi SQL SERVER Guys, Welcome back to this series about the most important concepts about performance! If you care about SQL Server performance, you cannot miss this post becuase there is one concept you absolutely must understand: SARGability . In a previous post I showed how dangerous some SQL queries can be for performance: The Most Dangerous SQL Server Query Today we look at one of the most important techniques to write faster queries: the SARGable way . What does SARGable mean? SARGable stands for Search ARGument ABLE . It means SQL Server can use an index efficiently to find rows. When a predicate is SARGable SQL Server can perform an: Index Seek (fast) When it is not SARGable SQL Server often performs an: Index Scan (slow) A classic NON-SARGable query SELECT * FROM Orders WHERE YEAR(OrderDate) = 2024; This query looks simple, but it hides a performance problem. Because the column is wrapped in the function YEAR() , SQL Serve...

JSON vs XML Indexing in SQL Server - The Ultimate Performance Showdown! (Benchmark Inside)

Image
JSON vs XML Indexing in SQL Server – The Ultimate Performance Showdown (Real Benchmarks Inside) SQL Server Performance Series – Advanced Indexing Deep Dive Related article in this series: SQL Server Performance Series – Engine-Level Optimization Deep Dive Hi SQL SERVER guys, today we will answer to a question that keeps coming back in modern SQL Server workloads: Should you index XML… or JSON? Which one performs better? Which one scales? Which one burns your CPU? As you usually do let’s benchmark it properly. Why This Matters Modern applications store semi-structured data everywhere: Microservices payloads Audit logs Dynamic attributes External API responses SQL Server supports both XML and JSON standards, but indexing strategies are completely different. How XML Indexing Works XML supports the following types of indexes: Primary XML Index Secondary PATH index Secondary VALUE index Secondary PROPERTY index It shreds XML into inte...

Fastest way to perform an "Insert if not exists" operation

Image
Hi guys, As many of you know this blog was born with the main intent of talking about optimizations and performance . Today we see what is the fastest way to perform an operation that in reality often happens to perform. Let’s talk about "Insert if not exists" or insert new records in a table only if they are not already present. Ready to measure with your stopwatch in hand? Enjoy the reading!     The "Insert if not exists" operation Suppose you have a table which contains a list of all the products in our store whos name is  Products Suppose you have another table NewProducts , with the same structure, which also contains a list of products. What we want to do is to insert in the Products table all the products found in the NewProducts table that do not exist in the Products table . This is the structure of the two tables: CREATE TABLE PRODUCTS (ID INT IDENTITY (1,1), CODE VARCHAR (20) PRIMARY KEY CLUSTERED ([ID] ASC )) CREATE TABLE NEWPRODUCTS (ID INT IDENTITY (...

SQL Server, statistics, performance and the Ascending key problem

Image
Hi guys, September is coming and it is time for our editorial staff to reopen its doors. I hope you have recharged your batteries to 100%. Today we will talk about statistics and performance . Yes, we have talked about it many times before but today we will focus on an issue that could lead to a poor performance situation .  Maybe your query is poor performing due to this issue? Ready? Go! Statististics and the Ascending Key Problem Statistics need to be updated because they help SQL server create a good execution plan. I like to do an example by making a parallel between extracting data from the database and a trip: if i have to go to work and my office is near me it is better to take a bicycle. If my work is far from me it is better take the car or the train. Likewise, if I need to extract a few records, the optimizer can implement a JOIN by choosing a nested loop. Otherwise it would be better to use other operators such as merge or hash. This is why statistics are important. Be...