Posts

SQL Server 2019 CU11 is out! ....and again on Scalar UDF Inlining

Image
Hi Guys, The SQL Server CU 11 is out.  Looking to the Microsoft changelog there aren't great imprevements from point of view of the performance, but from what i can see there is another update on the "Scalar UDF Inlining" saga! We talked about Scalar UDF inlining here: SQL Server, boost your UDFs! Yes i really think that UDF inlining (debut with SQL Server 2019 in order to increase performance) will became an important technology but what is happened unfortunately is a little different. Due to errors, at each CU Microsoft restricted the action and the functionality of the Inlining.. For example in the CU2 inlining is blocked if the UDF references built-in views (for example . OBJECT_ID) or when aggregate functions are passed as parameters to a scalar UDF. Again if the UDF references certain intrinsic functions (for example @@ROWCOUNT. Updating to the CU4 inlining is blocked if the UDF uses XML methods or contains a SELECT with ORDER BY without a "TOP 1" and eve...

How to change Sql Server name. A micro tips!

Image
Hello friends, Welcome back again! Last time we have a long post about Disassembling the SQL Server parser so today we have a very short post... Do you need to change the name of the instance of SQL Server? Easy! Let's step back Some days ago i was connected with a customer. I saw the name of the instance in the SSMS but if I execute a statement where the name of the server is explicited, like this: select * from [instancename]. [database]. [dbo]. [Table] I get the Error: Messaggio 7202, livello 11, stato 2, riga 10 Non è stato possibile trovare il server 'xxxxxx' in sys.servers. Verificare che sia stato specificato il nome corretto del server. Se necessario, eseguire la stored procedure sp_addlinkedserver per aggiungere il server a sys.servers. Where is the problem? If i execute the command  Select * from sys.sysservers The servaname columns return a name that's not equal to the name displayed by the SSMS   So, how to solve? As I sayd this is a very ...

Disassembling the SQL Server parser. The LGetToken procedure - part 1

Image
Happy Sunday my dear friends and welcome back to this blog! Today we will talk about the parser component of SQL Server. We keep disassemble the parser as we already done here: SQL Server, inside the parser: the Get_Gen_Lex procedure   SQL Server, A bit of reverse engineering inside the parser: the Parser and the GetChar procedure. (attention contains news published for the first time)   I don't think it has ever been done before and I don't even know if I will end up ...maybe I could probably write a book about it, who knows!  ...but today I want to show you a few interesting things. So start your management studio enter a simple select command, start a debugger like WINDBG ...and of course "happy reading"! The LGetToken procedure The LGetToken procedure is so defined: void LGetToken(uint **param_1,uint *param_2,ushort **param_3) The param_2 contain the pointer to the sql command. This procedure is called by the yylex procedure in order to parse the T-SQL commands...

SQL Server, speaking about ALIAS ...learn the rule

Image
Hello friends! Welcome back to this short post. We will speak about Alias and only two minute to learn some important things is really a big deal ! So think big and think that Share knowledge is the only way! Alias I think that everyone know what an alias is. We can have a table and call it with another name or we can have a field of a table and call it with another another name. SELECT CODE FROM ORDTES SELECT CODE as CODICE FROM ORDTES as ORDINI  Where 'as' is optional   Using alias if your statement represents a derived table then you can refer to it through the alias: SELECT * FROM ORTDES JOIN (SELECT CODE AS CODICE FROM ORDTES) AS ORDINI ON ORDINI.CODICE = ORDTES.CODE   Tips: You can see the Alias also int the execution plan   And then.. Suppose now to play with our usual ORDTES table. Suppose again you need to write a statement to get the max number of document. Using a not efficient way (i know) we could write: SELECT id FR...

Speaking to Sql Server, sniffing the TDS protocol

Image
Hello friends!  If yesterday you read my post and found it definitely boring (for the topic of course and not for how it was written to the author 😁) well today I promise you that the topic will be much more interesting! Let's talk about Sniffing , let's talk about going to see what happens when we "log in" or when we send a Query to SQL Server.  We will do this by taking a look to the little known tabular data stream (TDS) protocol built on top of the TCP/IP protocol. Ready! The TDS protocol What is the Tabular data stream (TDS) protocol?  The TDS is the protocol used by the SQL Server client Net-Library to communicates with SQL Server . TDS is specific to SQL Server and it is a low-level protocol that specifies both commands and data in a specific arrangement.  TDS encapsulate the TCP/IP protocol. Sniffing TDS packets you can read from the network the requests that your application do to the SQL Server and read the answer .   How to Sniff data from the ne...

Speaking to Sql Server, between Shared Memory, Named pipe and TCP/IP protocols

Image
Hi Friends, I hope you have had an Happy Easter! Have you ever wondered how your application or the SSMS itself talks to the database engine? Let's start today by talking about some basic concepts: Protocols GO!   Speaking to the database engine. You know already, from the previous posts, that SQL Server engine is a service . The database engine is a service   The question of today as sayd is: how do the applications speak to this service? How does he respond? Well, to talk to SQL Server there are three protocols that you can view by starting Sql Server Configuration Manager . These three protocols are named: Shared Memory Named Pipe TCP/IP Basically: With the Shared Memory protocol , the simplest protocol, you can only use it in a local connection . In this case the application and the SQL Server need to run on the same machine. The Named Pipe is used to connect inside a local area network (LAN)  With the TCP/IP protocol (the most used) you can have a remote or clien...

All about prepared statements. When to use them to go faster!

Image
Hello friends, Are you ready to learn about prepared statements ?  If you are a software developer you will have noticed that a T-SQL statement (a Query) can be prepared. Who knows exactly what that means? If I prepare a query then it runs faster? Today we will answer to all these questions and give some examples. We are interested in using them when they make us go faster! READY? A bit of theory, key concepts! Not only Microsoft SQL Server support prepared statement. Prepared statements is infact a feature of many DMBS like Oracle, DB2, MySQL and PostgreSQL. The main idea is to split the execution of a statement in two parts. During the first part called preparation the T-SQL will be parsed, analyzed and optimized. During the last part called execution parameters will be binded and the command will be executed. When is this feature useful? This feature is useful when the same command must be executed many times . There are unfortunately some limitations to consider. Some Limitatio...