Posts

Showing posts from December, 2021

SQL Server, Avoid that damn Table Spool!

Image
Hi guys, Welcome back for another post! A light one inspired from what i do during my work: many times I optimize queries rewriting them or adding index and i like it very much! Sometimes you need to use a little imagination, but everything you learn ... sooner or later it will come in handy! Enjoy the reading mates! Avoid the Table Spool, when you can A few days ago I came across a query whose execution time was very high ... or so it was for the client complaining about the problem. Before recreating it, let's create the structures and fill the tables with some data Create table PriceList (Id int identity (1,1) primary Key ,Code Varchar (20)) Insert into PriceList (code) select top 1000 right( '0000' + cast ( row_number () over ( order by id) as varchar (4)),4) from artico Insert into PriceList (code) select top 4000 right( '1000' + cast ( row_number () over ( order by id) as varchar (4)),4) from artico Create table OrdersList (Id int identity

SQL Server and the Adaptive Join feature: "Adaptive Join" Vs. "wrong cardinality estimate" and "Uneven data distribution"

Image
Hi Guys, I hope everything is fine for you!  It is Christmas and it's time for the wishes! So Merry Christmas and a happy new year filled of peace, health, love and new projects to start! I remember that some posts ago we talked about SQL Server 2019, Row Mode Memory Grant Feedback . On that occasion I presented the latest of the new feature that SQL Server 2019 had introduced.   Today i want to talk to you about another feature, this time introduced by SQL Server 2017. I will do it because it is important from a performance point of view! Today infact we will talk about Adaptive join . Enjoy the reading mate! Adaptive Join I know i have already used the image below but i like it because it is very clear for me. We have already talked during past posts of all the new feature (in green) introduced by SQL Server 2019.    Today we will talk about Adaptive Join that is a feature part of a family called " Adaptive Query Processing " (or "Adaptive QP") introduced by

SQL Server, Recover a corrupted database with Stellar Repair for MS SQL. The review!

Image
Hi Guys! The scary story of a corrupt database ... and the review of the Stellar Repair for MS SQL ! It is morning and you are just arriving at the office. You still have to take your invigorating coffee. Suddenly the phone rings: your most important customer is blocked! He is no longer able to enter the management system, production is stopped! Moments of silence that seem interminable! Suddenly you feel less craving for coffee and more thirsty and hot! A few seconds and you are already connected on your client's server.  Run the management studio and ... O.M.G ...Your customer database is in suspected state!   Now I have been working with SQL Server for 20 years (and before that with IBM Db2) and I have seen many of these problems. And so what to do in these situations and in case a recent backup is not available to restore in place of the corrupt database? Of course with the necessary competence and knowing the internal structures of SQL Server we can act manually but how can